Spacetime 🌌🕟
A lightweight way to manipulate, traverse, compare, and format dates and times across planet Earth
- Get/set dates and times in remote timezones
- Global support for Daylight Savings Time, leap years + seconds, and hemispheres
- Orient by quarter, season, month, and week
- Remote date comparison
- Written in ES2015 JS, published as ES5, tested for Node and the browser
- Weighs in at just 35KB (12KB compressed)
- Well tested, Apache 2.0 licensed
- Made by your friendly friends at Begin
Install
npm install spacetime --save
Testing
In Node:
npm test
More information
API
var spacetime=require('spacetime')
s = spacetime.now()
s = spacetime.today()
s = spacetime.tomorrow()
s = spacetime(1489520157)
s = spacetime([2017, 5, 2])
s = spacetime('July 2, 2017 5:01:00')
s = spacetime(1489520157, 'Canada/Pacific')
s.date()
s.year()
s.season()
s.hour(5)
s.date(15)
s.day('monday')
s.month('march')
s.quarter(2)
s.add(1, 'week')
s.add(3, 'quarters')
s.subtract(2, 'months').add(1,'day')
s.timezone().name
s.timezone().hemisphere
s.timezone().current.offset
s.timezone().current.isDst
let d = spacetime([2017, 5, 2])
s.isAfter(d)
s.isEqual(d)
s.isBefore(d)
s.isSame(d, 'year')
s.isSame(d, 'date')
s.diff(d, 'day')
s.diff(d, 'month')
s.format('time')
s.format('numeric-uk')
s.format('month')
s.format('month-short')
s.startOf('day')
s.startOf('month')
s.endOf('quarter')
s.progress().month = 0.23
s.progress().day = 0.48
s.progress().hour = 0.99
s.goto('Australia/Brisbane')
s.clone()
s.isValid()
Image courtesy NASA 💕🚀🌌