Parse Interval
Parse time intervals of the form DD.HH:MM:SS.FFFFFFFFF
The days and fractional second fields are optional. Fractional seconds can range from 1 to 9 digit accuracy.
Installation
$ npm install parse-interval
Usage
pi = require 'parse-interval' ti = piparse "1.02:03:04.123456789"consolelog "Days: "consolelog "Hours: "consolelog "Minutes: "consolelog "Seconds: "consolelog "Milliseconds: "consolelog "Nanoseconds: " # use totalMilliseconds() to help set intervals setInterval -> consolelog "hello world"titotalMilliseconds
Other totals available:
titotalHourstitotalMinutestitotalSecondstitotalNanoseconds
Parse-interval also has .toString()
functionality. toString()
is intelligent and will yield the correct string for overflowing time places.
ti = picreate # create a blank time interval object ti.days = 1ti.hours = 2ti.minutes = 3ti.seconds = 4ti.milliseconds = 123titoString #> "1.02:03:04.123" ti = picreateti.seconds = 93784titoString #> "1.02:03:04.123"
Uptime
parse-interval conveniently provides the system uptime as a time interval:
pi = require 'parse-interval'up = piuptimeuptoString#> '2.06:17:46'
Testing
$ npm test