Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update subscriptions view to display video publish time in relative form even fetched via RSS #3216

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/renderer/components/ft-list-video/ft-list-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ export default defineComponent({

return this.historyCache[historyIndex].lastViewedPlaylistId
},

currentLocale: function () {
return this.$i18n.locale.replace('_', '-')
},
},
mounted: function () {
this.parseVideoData()
Expand Down Expand Up @@ -420,7 +424,25 @@ export default defineComponent({
this.publishedText = this.data.publishedText
}

if (typeof (this.data.publishedText) !== 'undefined' && this.data.publishedText !== null && !this.isLive) {
if (this.data.isRSS && this.data.publishedDate != null && !this.isLive) {
const now = new Date()
// Convert from ms to second to minute
let timeDiffFromNow = ((now - this.data.publishedDate) / 1000) / 60
let timeUnit = 'minute'

if (timeDiffFromNow > 60) {
timeDiffFromNow /= 60
timeUnit = 'hour'
}

if (timeUnit === 'hour' && timeDiffFromNow > 24) {
timeDiffFromNow /= 24
timeUnit = 'day'
}
Copy link
Member

@absidue absidue Feb 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add support for seconds (it's rare but happens) as well as months and years?

I'm subscribed to one channel that hasn't uploaded in 3 years but i'm subscribed to keep it easily accessible.


// Using `Math.ceil` so that -1.x days ago displayed as 1 day 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) {
// produces a string according to the template in the locales string
this.uploadedTime = toLocalePublicationString({
publishText: this.publishedText,
Expand Down