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

Skip superfluous conversion to Date in ft-list-video #5123

Merged
merged 1 commit into from
May 19, 2024

Conversation

absidue
Copy link
Member

@absidue absidue commented May 17, 2024

Skip superfluous conversion to Date in ft-list-video

Pull Request Type

  • Bugfix

Description

Inside ft-list-video we create a Date object from the published timestamp number before passing it to getRelativeTimeFromDate but in that function it only gets used in some arithmetic, so gets immediately converted back into a number by JavaScript (the date variable):

export function getRelativeTimeFromDate(date, hideSeconds = false, useThirtyDayMonths = true) {
if (!date) {
return ''
}
const now = new Date().getTime()
// Convert from ms to second
// For easier code interpretation the value is made to be positive
let timeDiffFromNow = ((now - date) / 1000)

We also know that it will always be a number because it's typechecked just a few lines above:

} else if (typeof this.data.published === 'number' && !this.isLive) {
this.published = this.data.published
if (this.inHistory) {
this.uploadedTime = new Date(this.data.published).toLocaleDateString([this.currentLocale, 'en'])
} else {
// Use 30 days per month, just like calculatePublishedDate
this.uploadedTime = getRelativeTimeFromDate(new Date(this.data.published), false)
}

TL;DR it's a number and we use it as a number, so we don't need the conversion to a Date object and back.

Testing

Open a video list e.g. the subscriptions and check that the relative published dates show up correctly.

Desktop

  • OS: Windows
  • OS Version: 10
  • FreeTube version: b9d5778

@FreeTubeBot FreeTubeBot enabled auto-merge (squash) May 17, 2024 22:54
@github-actions github-actions bot added the PR: waiting for review For PRs that are complete, tested, and ready for review label May 17, 2024
@FreeTubeBot FreeTubeBot merged commit 8c37aba into FreeTubeApp:development May 19, 2024
5 checks passed
@github-actions github-actions bot removed the PR: waiting for review For PRs that are complete, tested, and ready for review label May 19, 2024
@absidue absidue deleted the avoid-date-conversion branch May 19, 2024 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants