v4.0.0 #3889
Unanswered
kossnocorp
asked this question in
General
v4.0.0
#3889
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have great news! First, ten years after its release, date-fns finally gets first-class time zone support.
Another great news is that there aren't many breaking changes in this release. All of them are type-related and will affect only those explicitly using internal date-fns types. Finally, it has been less than a year since the last major release, which is an improvement over the previous four years between v2 and v3. I plan on keeping the pace and minimizing breaking changes moving forward.
Read more about the release in the announcement blog post.
- Sasha @kossnocorp
Added
Added time zones support via
@date-fns/tz
'sTZDate
class andtz
helper function. See its README for the details about the API.All relevant functions now accept the context
in
option, which allows to specify the time zone to make the calculations in. If the function also returns a date, it will be in the specified time zone:In the example,
addDays
will get the current date and time in Singapore and add 5 days to it.startOfDay
will inherit the date type and return the start of the day in Singapore.Changed
The function arguments, as well as
Interval
'sstart
andend
, now can be of different types, allowing you to mixUTCDate
,TZDate
,Date
, and other extensions, as well as primitives (strings and numbers).The functions will normalize these values, make calculations, and return the result in the same type, preventing any bugs caused by the discrepancy. If passed, the type will be inferred from the context
in
option or the first encountered argument object type. TheInterval
'sstart
andend
will be considered separately, starting fromstart
.In the given example, the result will be in the
TZDate
as the first argument is a number, and thestart
takes precedence over theend
.BREAKING: This release contains a bunch of types changes that should not affect the library's expected usage. The changes are primarily internal and nuanced, so rather than listing them here, I recommend you run the type checker after the upgrade. If there are unfixable problems, please open an issue.
BREAKING: The package is now ESM-first. CommonJS is still supported, and it should not affect most users, but it might break in certain environments. If you encounter any issues, please report them.
Fixed
$
by properly wrapping the code in an IIFE.This discussion was created from the release v4.0.0.
Beta Was this translation helpful? Give feedback.
All reactions