This Package is not production ready yet.
Datetime
Transformations
Convert dates from one representation to another.
;
Arithmetic calculations
All calculations are immutable and can be either called in singular or plural (eg. addSecond, addSeconds). They take the amound to be added/subtracted as the first argument and an ISO-8601 string as the second argument.
; // => '2000-01-01T00:00:01'
All arithmetic calculations are curried which enables intermediate functions to be defined easily. If you're writing a lecture scheduling system where one lecture lasts 1.5 hours you can easily define your own addLectureHour function.
const addLectureHour = ;; // => '2000-01-01T01:50:00'
As all calculations are curried, so that functional composition is also possible.
; const addLectureHour = ; ; // => '2000-01-01T01:50:00'
Public Functions
;
Round/Ceil/Floor
Zeitgeist allows you to round/ceil/floor dates.
; // => '2000-01-01T11:00:00'
Public Functions
;
Getters
Getting specific units out of an ISO-8601 string works as well. It accepts an ISO-8601 date string as first argument.
; // => 2000
Public Functions
;
Comparison
Compare takes two ISO-8601 date strings. They accept two ISO-8601 date strings as their arguments.
; // => true; // => true
Public Functions
;
Time-Between
Knowing how much time there is between two given dates might be needed in your application.
; // => 1; // => 1 // Dates between includes the first and last date.; // => ['2000-01-01', '2000-01-02']
Public functions
;
Date normalisation
; ; // => '2001-01-01'
Durations
An immutable duration library based on the ISO-8601 format for durations.
Usage
Calculations
Note: Due to JavaScripts floating point precision issue milliseconds and microseconds can't be handled correctly by this library. In the futurethere will be a high precision mode which will require decimal.js orany other arbitrary-precision decimal library.
Public API
Finders
All finders accept an ISO-8601 duration string and respond a number. eg.: `findSeconds('PT1S') // => 1``
;
Calculations
All calculations accept an ISO-8601 duration string and respond an ISO-8601 duration string. eg.: addSeconds(1, 'PT0S') // => 'PT1S'
;
Conversions
All conversions accept an ISO-8601 duration string and respond a number. eg.: asSeconds(1, 'PT1M1S') // => 61
;
Transformations
Transformations are used to convert an ISO string to an object and the other way round.
; // { ..., hours: 0, seconds: 1, ... }
; // 'PT1S'
Wrapper
The wrapper object is an immutable convenience object which makes multiple calculations on the same object easier.
const duration = ; // => 'PT1S';
const duration = ; // => 'PT1S';
Pomeranian is completely immutable.
const duration1 = ;const duration2 = duration1; console; // => false
Precision Issues
Because date components (years, months, weeks, days) can't be converted to other unites without date and timezone information, pomeranian-durations
doesn't support them yet. To do precise arithmetic operations it is recommended to avoid years, months, weeks and days completely when using durations.
For more information have a look at http://www.ostyn.com/standards/scorm/samples/ISOTimeForSCORM.htm
Contributions
There is still lot to do and fix in order to get to the 0.0.1 milestone. Contributions are very welcome. Just ping me on twitter @webpapaya or comment in one of the open tickets you want to work on.