Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/meir017/ts-timespan

TimeSpan library inspired by C#'s TimeSpan
https://github.com/meir017/ts-timespan

node timespan typescript

Last synced: about 2 months ago
JSON representation

TimeSpan library inspired by C#'s TimeSpan

Awesome Lists containing this project

README

        

# ts-timespan

[![Node.js CI](https://github.com/Meir017/ts-timespan/actions/workflows/test.yml/badge.svg)](https://github.com/Meir017/ts-timespan/actions/workflows/test.yml)
[![CodeQL](https://github.com/Meir017/ts-timespan/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/Meir017/ts-timespan/actions/workflows/codeql-analysis.yml)
[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]

TimeSpan library inspired by C#'s TimeSpan

## install

```bash
npm install ts-timespan
```

## usage
```js
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 https://github.com/Microsoft/TypeScript/issues/27532

[npm-image]: https://img.shields.io/npm/v/ts-timespan.svg
[npm-url]: https://npmjs.org/package/ts-timespan
[downloads-image]: https://img.shields.io/npm/dm/ts-timespan.svg
[downloads-url]: https://npmjs.org/package/ts-timespan