Skip to content

Commit 85cec5c

Browse files
authored
Use Date.now() and Date.parse() when a millisecond value is needed (#6518)
1 parent ef1ad75 commit 85cec5c

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

src/renderer/helpers/subscriptions.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,14 @@ export async function parseYouTubeRSSFeed(rssString, channelId) {
106106
*/
107107
async function parseRSSEntry(entry, channelId, channelName) {
108108
// doesn't need to be asynchronous, but doing it allows us to do the relatively slow DOM querying in parallel
109-
const published = new Date(entry.querySelector('published').textContent)
110109

111110
return {
112111
authorId: channelId,
113112
author: channelName,
114113
// querySelector doesn't support xml namespaces so we have to use getElementsByTagName here
115114
videoId: entry.getElementsByTagName('yt:videoId')[0].textContent,
116115
title: entry.querySelector('title').textContent,
117-
published: published.getTime(),
116+
published: Date.parse(entry.querySelector('published').textContent),
118117
viewCount: entry.getElementsByTagName('media:statistics')[0]?.getAttribute('views') || null,
119118
type: 'video',
120119
lengthSeconds: '0:00',

src/renderer/helpers/utils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ export function getIconForSortPreference(sortPreference) {
5656
* @param {Date|undefined} premiereDate
5757
*/
5858
export function calculatePublishedDate(publishedText, isLive = false, isUpcoming = false, premiereDate = undefined) {
59-
const date = new Date()
59+
const now = Date.now()
6060

6161
if (isLive) {
62-
return date.getTime()
62+
return now
6363
} else if (isUpcoming) {
6464
if (premiereDate) {
6565
return premiereDate.getTime()
6666
} else {
6767
// should never happen but just to be sure that we always return a number
68-
return date.getTime()
68+
return now
6969
}
7070
}
7171

@@ -97,7 +97,7 @@ export function calculatePublishedDate(publishedText, isLive = false, isUpcoming
9797
timeSpan = timeAmount * 31556952000
9898
}
9999

100-
return date.getTime() - timeSpan
100+
return now - timeSpan
101101
}
102102

103103
/**

src/renderer/views/Watch/Watch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,10 @@ export default defineComponent({
397397

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

406406
if (result.secondary_info?.description.runs) {

0 commit comments

Comments
 (0)