timestamp-range
An object representing 2 timestamps - i.e. a 'gap' in time
installation
$ npm install timestamp-range
usage
Give a start and end date and get back an object with some useful functions:
var timestamprange = ; // took a coupla mins to make some teavar make_cuppa_tea = // took a coupla years to write a bookvar write_book = // 'minute'var tea_res = make_cuppa_tearesolution // the number of minutes to make some tea (float)var tea_len = make_cuppa_tealength // the number of milliseconds to make some tea (int)var tea_ms = make_cuppa_teams // 'year'var book_res = write_bookresolution // the number of minutes to make write a book (float)var book_len = write_booklength // the number of milliseconds to write a book (int)var book_ms = write_bookms
api
var range = timestamprange(startdate, enddate);
create a new timestamp-range.
startdate and enddate can be Dates or timestamps
// create with date objectsvar range = // create with timestampsvar range =
var resolution = range.resolution
get a string that describes the resolution of the range.
this is decided by if there is more than 1 of the given amount.
So - 59 seconds is resolution 'minute' and length 59
66 seconds is resolution 'minute' and length 1.1
The resolution is a string one of:
- millisecond
- second
- minute
- hour
- day
Month and years are not consistent when it comes to length and so its best to not make things complicated and just leave them out.
var length = range.length
the float that is the number of 'resolution' in the gap.
So - a gap of 90 seconds would be resolution 'minute' and length 1.5
var ms = range.ms
the number of milliseconds in a given range
license
MIT