Skip to content

Commit

Permalink
* Update subscriptions view to display video publish time in relative…
Browse files Browse the repository at this point in the history
… form even fetched via RSS
  • Loading branch information
PikachuEXE committed Feb 24, 2023
1 parent 69bec40 commit d07a1e3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"autolinker": "^4.0.0",
"browserify": "^17.0.0",
"browserify-zlib": "^0.2.0",
"dayjs": "^1.11.7",
"electron-context-menu": "^3.6.1",
"lodash.debounce": "^4.0.8",
"marked": "^4.2.12",
Expand Down
20 changes: 16 additions & 4 deletions src/renderer/helpers/utils.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import fs from 'fs/promises'
import dayjs from 'dayjs'
import customParseFormat from 'dayjs/plugin/customParseFormat'
import relativeTime from 'dayjs/plugin/relativeTime'

import { IpcChannels } from '../../constants'
import FtToastEvents from '../components/ft-toast/ft-toast-events'
import i18n from '../i18n/index'
import router from '../router/index'

dayjs.extend(customParseFormat).extend(relativeTime)

export function calculatePublishedDate(publishedText) {
const date = new Date()
if (publishedText === 'Live') {
Expand Down Expand Up @@ -43,13 +48,20 @@ export function calculatePublishedDate(publishedText) {
export function toLocalePublicationString ({ publishText, isLive = false, isUpcoming = false, isRSS = false }) {
if (isLive) {
return '0' + i18n.t('Video.Watching')
} else if (isUpcoming || publishText === null) {
}
if (isUpcoming || publishText === null) {
// the check for null is currently just an inferring of knowledge, because there is no other possibility left
return `${i18n.t('Video.Published.Upcoming')}: ${publishText}`
} else if (isRSS) {
return publishText
}
const strings = publishText.split(' ')

let relativeTimeStr = publishText
if (isRSS) {
// Parse with custom format and output "time from now" string
// https://day.js.org/docs/en/parse/string-format
// https://day.js.org/docs/en/display/from-now
relativeTimeStr = dayjs(publishText, 'DD/MM/YYYY, HH:mm:ss').fromNow()
}
const strings = relativeTimeStr.split(' ')
// filters out the streamed x hours ago and removes the streamed in order to keep the rest of the code working
if (strings[0].toLowerCase() === 'streamed') {
strings.shift()
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3169,6 +3169,11 @@ dashdash@^1.12.0:
dependencies:
assert-plus "^1.0.0"

dayjs@^1.11.7:
version "1.11.7"
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.7.tgz#4b296922642f70999544d1144a2c25730fce63e2"
integrity sha512-+Yw9U6YO5TQohxLcIkrXBeY73WP3ejHWVvx8XCk3gxvQDCTEmS48ZrSZCKciI7Bhl/uCMyxYtE9UqRILmFphkQ==

[email protected], debug@^2.6.8:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
Expand Down

0 comments on commit d07a1e3

Please sign in to comment.