Fix premieres on the subscription page (#3240)

* Fix premieres on the subscription page

* Fix date when restoring from subscription cache
This commit is contained in:
absidue 2023-03-05 20:29:00 +01:00 committed by GitHub
parent 43eefb458f
commit 667ee83130
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -417,7 +417,13 @@ export default defineComponent({
this.viewCount = this.data.viewCount
if (typeof this.data.premiereDate !== 'undefined') {
this.publishedText = this.data.premiereDate.toLocaleString()
let premiereDate = this.data.premiereDate
// premiereDate will be a string when the subscriptions are restored from the cache
if (typeof premiereDate === 'string') {
premiereDate = new Date(premiereDate)
}
this.publishedText = premiereDate.toLocaleString()
} else if (typeof (this.data.premiereTimestamp) !== 'undefined') {
this.publishedText = new Date(this.data.premiereTimestamp * 1000).toLocaleString()
} else {
@ -463,7 +469,7 @@ export default defineComponent({
// Using `Math.ceil` so that -1.x days ago displayed as 1 day ago
// Notice that the value is turned to negative to be displayed as "ago"
this.uploadedTime = new Intl.RelativeTimeFormat(this.currentLocale).format(Math.ceil(-timeDiffFromNow), timeUnit)
} else if (typeof (this.data.publishedText) !== 'undefined' && this.data.publishedText !== null && !this.isLive) {
} else if (this.publishedText && !this.isLive) {
// produces a string according to the template in the locales string
this.uploadedTime = toLocalePublicationString({
publishText: this.publishedText,

View File

@ -282,6 +282,8 @@ export default defineComponent({
videos.map(video => {
if (video.liveNow) {
video.publishedDate = new Date().getTime()
} else if (video.isUpcoming) {
video.publishedDate = video.premiereDate
} else {
video.publishedDate = calculatePublishedDate(video.publishedText)
}