UtilitiesDurationUsage

Usage

Simple usage

index.ts
// Import the module
import { Duration } from "@aezen/duration";

// You can either use a string pattern or millesconds directly to the Duration class.
const converted = new Duration("an hour and 66 seconds");

console.log(converted.ms) // 3666000
console.log(converted.verbose()) // 1 hour 1 minute 6 seconds
console.log(converted.colon()) // 01:01:06 (HH:MM:SS format)
console.log(converted.compact()) // 1h  1m  6s
console.log(converted.elegant()) //  1 hour, 1 minute and 6 seconds
console.log(converted.binary()) // 111001010010
console.log(converted.scientific()) // 3.666e+6
console.log(converted.object()) // The JSON object below
{
  "terayear": "0",
  "gigayear": "0",
  "megayear": "0",
  "millennium": "0",
  "century": "0",
  "decade": "0",
  "year": "0",
  "month": "0",
  "week": "0",
  "day": "0",
  "hour": "1",
  "minute": "1",
  "second": "6",
  "millisecond": "0",
  "microsecond": "0",
  "nanosecond": "0"
}

Last updated on

On this page