Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/meir017/ts-timespan
- Owner: Meir017
- License: mit
- Created: 2018-10-03T17:46:44.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-05-24T13:18:39.000Z (over 2 years ago)
- Last Synced: 2024-11-10T13:49:47.704Z (about 2 months ago)
- Topics: node, timespan, typescript
- Language: TypeScript
- Homepage:
- Size: 22.5 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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); // 250console.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