JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 659
  • Score
    100M100P100Q106373F
  • License ISC

An immutable duration library based on the ISO-8601 format for durations.

Package Exports

  • pomeranian-durations

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pomeranian-durations) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Pomeranian Durations

An immutable duration library based on the ISO-8601 format for durations.

Usage

npm install pomeranian-durations

Public API

Finders

All finders accept an ISO-8601 duration string and respond a number. eg.: `findSeconds('PT1S') // => 1``

export {
  findSeconds,
  findMinutes,
  findHours,
  findDays,
  findWeeks,
  findMonths,
  findYears,
};

Calculations

All calculations accept an ISO-8601 duration string and respond an ISO-8601 duration string. eg.: addSeconds('PT0S', 1) // => 'PT1S'

export {
  addMicroseconds,
  addMilliseconds,
  addSeconds,
  addMinutes,
  addHours,
  addDays,
  addWeeks,
  addMonths,
  addYears,

  subtractMilliseconds,
  subtractMicroseconds,
  subtractSeconds,
  subtractMinutes,
  subtractHours,
  subtractDays,
  subtractWeeks,
  subtractMonths,
  subtractYears,
};

Conversions

All conversions accept an ISO-8601 duration string and respond a number. eg.: asSeconds('PT1M1S', 1) // => 61

export {
  asMicroseconds,
  asMilliseconds,
  asSeconds,
  asMinutes,
  asHours,
  // NOTE: other conversions are not possible see: Precision Issues
};

Transformations

Transformations are used to convert an ISO string to an object and the other way round.

import { toFragments } from 'pomeranian-durations';

toFragments('PT1S') // { ..., hours: 0, seconds: 1, ... }
import { toIso } from 'pomeranian-durations';

toIso({ seconds: 1 }) // 'PT1S'

toIso({ seconds: 0 }) // 'P'
toIso({ seconds: 0 }, { includeZeroValues: false } ) // 'P'
toIso({ seconds: 0 }, { includeZeroValues: true } ) // 'PT0S'

Wrapper

The wrapper object is an immutable convenience object which makes multiple calculations on the same object easier.

import { addSeconds } from 'pomeranian-duration'

const duration = addSeconds('PT0S', 1); // => 'PT1S';
import { fromIso } from 'pomeranian-duration'

const duration = fromIso('PT0S').addSeconds(1).toIso(); // => 'PT1S';

Pomeranian is completely immutable.

import { fromFragments } from 'pomeranian-duration'

const duration1 = fromFragments({ seconds: 0 });
const duration2 = duration1.addSeconds(1);

console.log(duration1 === duration2); // => 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