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

Add context function #10

Open
kossnocorp opened this issue Aug 18, 2024 · 0 comments
Open

Add context function #10

kossnocorp opened this issue Aug 18, 2024 · 0 comments

Comments

@kossnocorp
Copy link
Member

kossnocorp commented Aug 18, 2024

The next date-fns version will ship a feature that will allow using the specified context function to normalize the arguments and/or the result, enabling explicit time zones support:

import { tz } from "@date-fns/tz";
import { isSameDay } from "date-fns";

const date1 = "2024-04-10T07:00:00Z"; // Wed Apr 10 2024 00:00:00 GMT-0700 (Pacific Daylight Time)
const date2 = "2024-04-10T15:00:00Z"; // Wed Apr 10 2024 08:00:00 GMT-0700 (Pacific Daylight Time)
const date3 = "2024-04-11T07:00:00Z"; // Thu Apr 11 2024 00:00:00 GMT-0700 (Pacific Daylight Time)

isSameDay(date1, date2, { in: tz("America/Los_Angeles") })
//=> true
isSameDay(date1, date3, { in: tz("America/Los_Angeles") })
//=> false

It makes sense to add this feature to @date-fns/utc as well, so devs can use UTC the same way:

import { utc } from "@date-fns/utc";
import { isSameDay } from "date-fns";

const date1 = "2024-04-10T07:00:00Z";
const date2 = "2024-04-10T15:00:00Z";
const date3 = "2024-04-11T07:00:00Z";

isSameDay(date1, date2, { in: utc })
//=> true
isSameDay(date1, date3, { in: utc })
//=> false
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

No branches or pull requests

1 participant