All contributions

spencermountain/spacetime

spacetime

A lightweight JavaScript library for working with dates and time zones.

Language
JavaScript
GitHub stars
4,104
Merged changes
3
Project site
spacetime.how

What we changed

Setting an hour of 24 or more now clamps to 23 instead of breaking the date, whereIts() returns zone names in the same casing as timezone().name, and the library exposes the tzdb version as spacetime.tzdbVersion.

What this work shows

  • IANA time zones and tzdb
  • Off-by-one range errors
  • Build-time generated data
  • TypeScript typings for a JS library
What was broken

hour(24) broke the whole date

The hour() setter clamped values of 24 and above to 24, an hour that does not exist. walkTo() rejected it and set epoch to null, so the object became invalid and format('iso') returned an empty string.

How we fixed it

Clamped to 23

The upper bound in hours() is now 23, so hour(24), hour(25) and hour(100) give 23:00 on the same day, just as date(40) and month(13) clamp to the last valid value. A test in set.test.js also checks that negative hours still give 0.

#467

What was broken

whereIts() returned lowercase names

whereIts() returned the raw data keys, such as antarctica/mawson, while timezone().name gave the same zones in proper IANA casing. The output of one could not be compared directly with the other.

How we fixed it

A shared titleCase function

We moved titleCase into its own file and both functions use it, so whereIts() returns names such as Antarctica/Mawson and America/Port-au-Prince. A test compares every returned name with timezone().name.

#474

What was broken

No time zone database version in the API

The library did not say which IANA tzdb release its zone data came from. Anyone who wanted to store that version next to their dates, in case the zones changed later, had nowhere to read it from.

How we fixed it

A new spacetime.tzdbVersion field

The script that generates the zone data writes the tzdata version into the generated file, pack.js carries it through, and the library exposes it as spacetime.tzdbVersion, for example 2026c. We also added the type in constructors.d.ts and a test.

#473

Merged changes 3

  1. #474 Return titlecased timezone names from whereIts Merged 15 October 2026
  2. #473 Expose the tzdb version as spacetime.tzdbVersion Merged 15 October 2026
  3. #467 Fix hour() setter clamping to an invalid hour (24) Merged 8 September 2026

What it taught us

A date library breaks at three levels at once: a range boundary in a setter, IANA zone names in the public API, and the script that generates zone data. We fixed all three, so the tzdb version reaches the code and the typings.

More about this technology: TypeScript, React and Node

Other projects we write code for

Describe your project.

A free quote comes back within an hour during working hours.