Skip to content
spencer kelly edited this page Apr 24, 2017 · 12 revisions

Spacetime is a small-and-punchy dateTime library, which hopes to make it easier to work with remote timezones in javascript on both client-and-serverside.

It is based, with love, on moment-timezone.

Considerations:

Historical timezone changes

Spacetime ignores the fact that timezones change.

Timezone details are political, historically-complex, and certain to change. Spacetime ignores that America/Dawsons_Creek may have had a different timekeeping system in the 1600's, and that it may change timekeeping rules in future centuries or decades. If you need support for historical timezones, we recommend moment-timezone.

International date line

If you're in London, and you set the timezone to be in Paris, it is intuitive that you travel 1 hour 'to the right'.

But if you're in Pacific/Fiji (right side of the map), and you goto Pacific/Midway (left side of the map), .goto() will subtract a tonne of hours, instead of just adding one. The .goto() method will never pass the international date line, because the method will always respect the idea of 'now over-there', instead of some kind of geographical-movement.

Greediness

when it comes to setting new values, some commands are destructive to smaller values, like seconds, and others are not. For example:

s= spacetime([2017,5,25])
s.seconds(5)
s.year(2025)
s.seconds()//still 5

//but this method 0's-out things:
s.quarter('q2')
s.seconds()//now 0

The destructive methods include week(), quarter(), season(), time().

month() and year() methods are sometimes destructive - if it's March 30th and you do .month('february'), it becomes the last day of February, because there is no February 30th.

Likewise, if it's february 29th, and you move to a non-leap year, it becomes feb 28th.

Browser-sensitivity

spacetime doesn't depend on, but works better with the Internationalization API, which has high-support now among browsers.

Something this tricky is going to have bugs 🐛. If you are scheduling heart-surguries, or landing spacecraft, please use a library with more institutional hardening.

Clone this wiki locally