Skip to content

Commit

Permalink
Use Date.now() and Date.parse() when a millisecond value is needed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue authored Jan 8, 2025
1 parent ef1ad75 commit 85cec5c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/renderer/helpers/subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,14 @@ export async function parseYouTubeRSSFeed(rssString, channelId) {
*/
async function parseRSSEntry(entry, channelId, channelName) {
// doesn't need to be asynchronous, but doing it allows us to do the relatively slow DOM querying in parallel
const published = new Date(entry.querySelector('published').textContent)

return {
authorId: channelId,
author: channelName,
// querySelector doesn't support xml namespaces so we have to use getElementsByTagName here
videoId: entry.getElementsByTagName('yt:videoId')[0].textContent,
title: entry.querySelector('title').textContent,
published: published.getTime(),
published: Date.parse(entry.querySelector('published').textContent),
viewCount: entry.getElementsByTagName('media:statistics')[0]?.getAttribute('views') || null,
type: 'video',
lengthSeconds: '0:00',
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ export function getIconForSortPreference(sortPreference) {
* @param {Date|undefined} premiereDate
*/
export function calculatePublishedDate(publishedText, isLive = false, isUpcoming = false, premiereDate = undefined) {
const date = new Date()
const now = Date.now()

if (isLive) {
return date.getTime()
return now
} else if (isUpcoming) {
if (premiereDate) {
return premiereDate.getTime()
} else {
// should never happen but just to be sure that we always return a number
return date.getTime()
return now
}
}

Expand Down Expand Up @@ -97,7 +97,7 @@ export function calculatePublishedDate(publishedText, isLive = false, isUpcoming
timeSpan = timeAmount * 31556952000
}

return date.getTime() - timeSpan
return now - timeSpan
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/views/Watch/Watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,10 @@ export default defineComponent({

if (result.page[0].microformat?.publish_date) {
// `result.page[0].microformat.publish_date` example value: `2023-08-12T08:59:59-07:00`
this.videoPublished = new Date(result.page[0].microformat.publish_date).getTime()
this.videoPublished = Date.parse(result.page[0].microformat.publish_date)
} else {
// text date Jan 1, 2000, not as accurate but better than nothing
this.videoPublished = new Date(result.primary_info.published).getTime()
this.videoPublished = Date.parse(result.primary_info.published)
}

if (result.secondary_info?.description.runs) {
Expand Down

0 comments on commit 85cec5c

Please sign in to comment.