github formkit/tempo v1.5.0

42 minutes ago

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 over Intl.RelativeTimeFormat that 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 like diffMonths/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…?"), matching isEqual. (#56, #107)

🐞 Fixes

  • tzDate uses 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") without tz prints the offset of the actual instant. For the first hours after each DST change it printed the previous offset (03:30 -05:00 instead of -04:00 in 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:00 is 0 months (was 1). (#108)

⚠️ Behavior changes

  • The diffMonths/diffYears month-end fix above changes results only in that exact case (374 of 200,000 random pairs).
  • format device offsets now differ from 1.4.0 only where 1.4.0 was wrong (checked against Intl every ~4h from 1990–2030 in 5 zones).

Don't miss a new tempo release

NewReleases is sending notifications on new releases.