New helpers, timezone fixes and a big thank-you to @bardrop π
β¨ New
relative(date, { base?, locale?, numeric?, style?, unit? }): "5 minutes ago", "yesterday", "in 3 weeks", "dans 3 ans". A thin layer overIntl.RelativeTimeFormatthat picks the unit for you. Hours use the wall clock, days count calendar dates (so DST and skipped midnights don't shift them), and months/years are completed units likediffMonths/diffYears. Amounts are truncated toward zero; zero keeps its direction ("0 seconds ago"). (#7, #108)weekNumber(date?, startOfWeekDay = 1, firstWeekContainsDate = 4): week of the year, ISO 8601 by default (2024-12-30β 1).weekNumber(d, 0, 1)gives US-style Sunday weeks. (#44, #105)isBefore(null, date)/isAfter(null, date)type-check ("is now beforeβ¦?"), matchingisEqual. (#56, #107)
π Fixes
tzDateuses the target zone's offset at the target time, so wall times around DST changes convert correctly (e.g. local timestamps around Berlin's switch). (#96 by @bardrop, fixes #74)format(β¦, "Z")withouttzprints the offset of the actual instant. For the first hours after each DST change it printed the previous offset (03:30 -05:00instead of-04:00in New York), and historical second-precision offsets lost their seconds (Detroit 1904-05:32:11), so format β parse round-trips were off by 11s. (#67, #106)diffMonths/diffYears: on a clamped month-end anniversary (Jan 31 β Feb 28) the time of day is now respected.Jan 31 23:00 β Feb 28 01:00is 0 months (was 1). (#108)
β οΈ Behavior changes
- The
diffMonths/diffYearsmonth-end fix above changes results only in that exact case (374 of 200,000 random pairs). formatdevice offsets now differ from 1.4.0 only where 1.4.0 was wrong (checked againstIntlevery ~4h from 1990β2030 in 5 zones).