Skip to content

Add context function #10

Open
Open
@kossnocorp

Description

@kossnocorp

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions