Fix video timestamps (#4979)

* Fix video timestamps

* Update week logic
This commit is contained in:
Jason 2024-04-19 02:02:26 +00:00 committed by GitHub
parent b753b7fdd9
commit d65ae6eaae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 6 deletions

View File

@ -666,7 +666,7 @@ export default defineComponent({
this.uploadedTime = new Date(this.data.published).toLocaleDateString([this.currentLocale, 'en'])
} else {
// Use 30 days per month, just like calculatePublishedDate
this.uploadedTime = getRelativeTimeFromDate(new Date(this.data.published).toDateString(), false)
this.uploadedTime = getRelativeTimeFromDate(new Date(this.data.published), false)
}
}

View File

@ -729,9 +729,7 @@ export function getRelativeTimeFromDate(date, hideSeconds = false, useThirtyDayM
const now = new Date().getTime()
// Convert from ms to second
// For easier code interpretation the value is made to be positive
// `comparisonDate` is sometimes a string
const comparisonDate = Date.parse(date)
let timeDiffFromNow = ((now - comparisonDate) / 1000)
let timeDiffFromNow = ((now - date) / 1000)
let timeUnit = 'second'
if (timeDiffFromNow < 60 && hideSeconds) {
@ -753,12 +751,18 @@ export function getRelativeTimeFromDate(date, hideSeconds = false, useThirtyDayM
timeUnit = 'day'
}
const timeDiffFromNowDays = timeDiffFromNow
if (timeUnit === 'day' && timeDiffFromNow >= 7) {
timeDiffFromNow /= 7
timeUnit = 'week'
}
/* Different months might have a different number of days.
In some contexts, to ensure the display is fine, we use 31.
In other contexts, like when working with calculatePublishedDate, we use 30. */
const daysInMonth = useThirtyDayMonths ? 30 : 31
if (timeUnit === 'day' && timeDiffFromNow >= daysInMonth) {
timeDiffFromNow /= daysInMonth
if (timeUnit === 'week' && timeDiffFromNowDays >= daysInMonth) {
timeDiffFromNow = timeDiffFromNowDays / daysInMonth
timeUnit = 'month'
}