-
Notifications
You must be signed in to change notification settings - Fork 191
Home
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.
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.
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.
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 0The 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.
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.
🌠 - - - - - spacetime.how