Skip to content

Native timezone support vs. date-fns-tz #3904

Answered by kossnocorp
yss14 asked this question in General
Discussion options

You must be logged in to vote

Hey!

I think you missed it, but the date-fns functions do return the date in the same type as you pass inside:

const date = startOfMinute(endOfDay(new TZDate(from, timezone)));

date.toString();
//=> 'Sun Dec 01 2024 23:59:00 GMT+0100 (GMT+01:00)'

date instanceof TZDate;
//=> true

Additionally, I don't think the code does what you think it should. In the @date-fns/tz calling withTimeZone and passing "UTC" does nothing but convert the time zone without changing the timestamp, while fromZonedTime and toZonedTime do change it:

const timezone = "CET";
const from = parseISO("2024-11-30T23:00:00.000Z");
//=> '2024-11-30T23:00:00.000Z'

const zonedFrom = toZonedTime(from, timezone);
//=> '2024-…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@yss14
Comment options

@liby
Comment options

Answer selected by yss14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants