mirror of https://github.com/FreeTubeApp/FreeTube
Fix video timestamps (#4979)
* Fix video timestamps * Update week logic
This commit is contained in:
parent
b753b7fdd9
commit
d65ae6eaae
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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'
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue