Skip to content

provide addInTimeZone function#225

Open
dr-skot wants to merge 1 commit intomarnusw:masterfrom
dr-skot:master
Open

provide addInTimeZone function#225
dr-skot wants to merge 1 commit intomarnusw:masterfrom
dr-skot:master

Conversation

@dr-skot
Copy link

@dr-skot dr-skot commented Feb 5, 2023

Love this library. One feature it's missing that I've needed from time to time is a timezone-aware version of the date-fns add function.

Time zones matter in date arithmetic because of daylight savings. If your base time is 2022-11-05T06:00Z, for example, and you want to add one day,

in LA it's
11pm Nov 4 + 1 day === 11pm Nov 5 === +24 hrs

but in Halifax it's
3am Nov 5 + 1 day === 3am Nov 6 === +25 hrs

because the clocks fall back 1 hr (in both places) at 2am Nov 6.

So here's a proposed addInTimeZone function to handle that. Plus some tests.

I tried yarn build to generate the typings files but no joy. I guess some more configuration twiddling is needed to make that work.

Hope you find it useful!

timezone-aware version of date-fns.add
@marnusw
Copy link
Owner

marnusw commented Feb 6, 2023

Thank you @dr-skot, I'll take a look in the near future.

@myftija
Copy link

myftija commented May 20, 2024

Hi @marnusw, could you please take a look at this PR from @dr-skot?
It would be very useful to have in date-fns-tz.

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.

3 participants