ts-timespan

TimeSpan library inspired by C#'s TimeSpan

Usage no npm install needed!

<script type="module">
  import tsTimespan from 'https://cdn.skypack.dev/ts-timespan';
</script>

README

ts-timespan

CircleCI NPM Version NPM Downloads

TimeSpan library inspired by C#'s TimeSpan

install

npm install ts-timespan

usage

const { TimeSpan } = require('ts-timespan');

const time1 = new TimeSpan(5643132 /* ticks */);
const time2 = new TimeSpan([8,30,1] /* [hours, minutes, seconds] */);
const time3 = new TimeSpan([12,8,30,1] /* [days, hours, minutes, seconds] */);
const time4 = new TimeSpan([12,8,30,1, 250] /* [days, hours, minutes, seconds, milliseconds] */);

const time5 = TimeSpan.fromDays(4);
const time6 = TimeSpan.fromHours(4);
const time7 = TimeSpan.fromMinutes(4);
const time8 = TimeSpan.fromSeconds(4);
const time9 = TimeSpan.fromMilliseconds(4);

console.info(time1.ticks); // 5643132
console.info(time3.days); // 12
console.info(time2.hours); // 8
console.info(time4.minutes); // 30
console.info(time4.seconds); // 1
console.info(time4.milliseconds); // 250

console.info(time4.toString()); // 12:08:30:01.250