Meir017 / ts-timespan

TimeSpan library inspired by C#'s TimeSpan

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ts-timespan

Node.js CI CodeQL 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

remarks

right now when calling the ctor and using more than a single number it must be inside an array, this is because of microsoft/TypeScript#27532

About

TimeSpan library inspired by C#'s TimeSpan

License:MIT License


Languages

Language:TypeScript 100.0%