Skip to content

TimeSpan library inspired by C#'s TimeSpan

License

Notifications You must be signed in to change notification settings

rtmann/better-ts-timespan

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

remarks

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

About

TimeSpan library inspired by C#'s TimeSpan

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%