Skip to content

Commit c784841

Browse files
Aiz0PikachuEXE
andauthored
Display time remaining until video goes live (#2501)
* display time left until video premiers: * video premiere display time left with time units Displays time left in seconds, minutes, hours, and days. This depends on how much time is left. * premiere time left, display time in singular if needed also simplified the big if block * premiere time left, display time unit in lowercase * Add Starting Soon string to locale file * apply fixes reported by linter * premiere time left, add suggested changes Better temp variable scoping, flatten nested code, rename temp variables, use string intepolation Co-authored-by: PikachuEXE <[email protected]> * replace tabs with spaces tabs where used in some places in the suggested code * display time left, remove "starting soon" string Since upcomingTimeStamp will be null when the time has passed the scheduled timestamp it doesn't make sense to use something that will rarely be displayed. e.g. a user has to click on the video with less than a second remaing until it goes live for it to be displayed it would also be displayed as "Premieres in Starting soon" which doesn't make sense * display 'less than a minute' instead of exactly how many seconds remain Looks better and works for values less than 0 Co-authored-by: PikachuEXE <[email protected]>
1 parent 1418603 commit c784841

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

src/renderer/views/Watch/Watch.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export default Vue.extend({
4949
isLiveContent: false,
5050
isUpcoming: false,
5151
upcomingTimestamp: null,
52+
upcomingTimeLeft: null,
5253
activeFormat: 'legacy',
5354
thumbnail: '',
5455
videoId: '',
@@ -395,8 +396,43 @@ export default Vue.extend({
395396
if (typeof startTimestamp !== 'undefined') {
396397
const upcomingTimestamp = new Date(result.videoDetails.liveBroadcastDetails.startTimestamp)
397398
this.upcomingTimestamp = upcomingTimestamp.toLocaleString()
399+
400+
let upcomingTimeLeft = upcomingTimestamp - new Date()
401+
402+
// Convert from ms to second to minute
403+
upcomingTimeLeft = (upcomingTimeLeft / 1000) / 60
404+
let timeUnitI18nPartialKey = 'Minute'
405+
406+
// Youtube switches to showing time left in minutes at 120 minutes remaining
407+
if (upcomingTimeLeft > 120) {
408+
upcomingTimeLeft = upcomingTimeLeft / 60
409+
timeUnitI18nPartialKey = 'Hour'
410+
}
411+
412+
if (timeUnitI18nPartialKey === 'Hour' && upcomingTimeLeft > 24) {
413+
upcomingTimeLeft = upcomingTimeLeft / 24
414+
timeUnitI18nPartialKey = 'Day'
415+
}
416+
417+
// Value after decimal not to be displayed
418+
// e.g. > 2 days = display as `2 days`
419+
upcomingTimeLeft = Math.floor(upcomingTimeLeft)
420+
if (upcomingTimeLeft !== 1) {
421+
timeUnitI18nPartialKey = timeUnitI18nPartialKey + 's'
422+
}
423+
const timeUnitTranslated = this.$t(`Video.Published.${timeUnitI18nPartialKey}`).toLowerCase()
424+
425+
// Displays when less than a minute remains
426+
// Looks better than `Premieres in x seconds`
427+
if (upcomingTimeLeft < 1) {
428+
this.upcomingTimeLeft = this.$t('Video.Published.Less than a minute').toLowerCase()
429+
} else {
430+
// TODO a I18n entry for time format might be needed here
431+
this.upcomingTimeLeft = `${upcomingTimeLeft} ${timeUnitTranslated}`
432+
}
398433
} else {
399434
this.upcomingTimestamp = null
435+
this.upcomingTimeLeft = null
400436
}
401437
} else {
402438
this.videoLengthSeconds = parseInt(result.videoDetails.lengthSeconds)

src/renderer/views/Watch/Watch.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
v-if="upcomingTimestamp !== null"
5555
class="premiereText"
5656
>
57-
{{ $t("Video.Premieres on") }}:
57+
{{ $t("Video.Premieres in") }} {{ upcomingTimeLeft }}
5858
<br>
5959
{{ upcomingTimestamp }}
6060
</p>

static/locales/en-US.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ Video:
542542
the page to check again
543543
# As in a Live Video
544544
Premieres on: Premieres on
545+
Premieres in: Premieres in
545546
Live: Live
546547
Live Now: Live Now
547548
Live Chat: Live Chat
@@ -592,6 +593,7 @@ Video:
592593
Years: Years
593594
Ago: Ago
594595
Upcoming: Premieres on
596+
Less than a minute: Less than a minute
595597
Published on: Published on
596598
Streamed on: Streamed on
597599
Started streaming on: Started streaming on

0 commit comments

Comments
 (0)