Skip to content

feat: add support for timezone with seconds offset#47

Merged
kossnocorp merged 2 commits intodate-fns:mainfrom
GianlucaWassermeyer:support-for-timezones-with-seconds-offset
Aug 12, 2025
Merged

feat: add support for timezone with seconds offset#47
kossnocorp merged 2 commits intodate-fns:mainfrom
GianlucaWassermeyer:support-for-timezones-with-seconds-offset

Conversation

@GianlucaWassermeyer
Copy link
Copy Markdown
Contributor

@GianlucaWassermeyer GianlucaWassermeyer commented Mar 11, 2025

Why

Issue 46
I encountered an issue with the TZDate class when handling dates before the implementation of the GMT system in 1883. The TZDate class appears to only consider the hour and minute of the timezone, but not the seconds, leading to inconsistencies.
Example

Additional Information: The issue seems to stem from TZDate only considering the hour and minute of the timezone, but not the seconds. This discrepancy becomes apparent for dates before 1883, when the GMT system was implemented. The offset GMT-07:52:58 (America/Los_Angelos, GMT-08:00) causes the inconsistency.

Proposed Fix

The offsetStr in tzOffset already contains the timezone data for hours, minutes, and seconds. The tzOffset function returns the offset in minutes. To avoid breaking changes, I added the seconds offset as a decimal number.

In mini.js, we need to adjust the date to the system timezone. The native JavaScript Date object's .getTimezoneOffset method returns only the minutes and no seconds. To circumvent this, I create a new date and set the UTCSeconds to 0. With this, the seconds are the timezone offset of the system timezone. We then add this together with our tzOffset seconds to get the correct date.

If you don´t like any part of this PR, please tell me and I can try to find a different solution.

@GianlucaWassermeyer GianlucaWassermeyer marked this pull request as ready for review March 11, 2025 08:56
@kossnocorp kossnocorp added this to Main Aug 1, 2025
@github-project-automation github-project-automation bot moved this to Inbox in Main Aug 1, 2025
@kossnocorp kossnocorp moved this from Inbox to Must in Main Aug 1, 2025
@kossnocorp kossnocorp added the 🌟 Enhancement Improves existing functionality label Aug 2, 2025
@kossnocorp kossnocorp force-pushed the support-for-timezones-with-seconds-offset branch from e52afce to 1ef8067 Compare August 12, 2025 07:33
Copy link
Copy Markdown
Member

@kossnocorp kossnocorp left a comment

Choose a reason for hiding this comment

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

🙌 It is looking good. There were some issues with tests, but after adjusting everything seems to pass.

@github-project-automation github-project-automation bot moved this from Must to WIP in Main Aug 12, 2025
@kossnocorp
Copy link
Copy Markdown
Member

Thank you a lot for your PR and patience. You did an incredible job!

I verified indeed that tests are correct and fixes actually make them green. I'm going to merge it and ship a new major version soon.

@kossnocorp kossnocorp merged commit 6194054 into date-fns:main Aug 12, 2025
@github-project-automation github-project-automation bot moved this from WIP to Done in Main Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🌟 Enhancement Improves existing functionality

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants