https://github.com/coderosh/string-time
Convert time string into seconds, minutes, hour, array or object
https://github.com/coderosh/string-time
Last synced: 7 months ago
JSON representation
Convert time string into seconds, minutes, hour, array or object
- Host: GitHub
- URL: https://github.com/coderosh/string-time
- Owner: coderosh
- License: mit
- Created: 2021-06-20T02:48:26.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-10-30T08:06:50.000Z (about 4 years ago)
- Last Synced: 2025-06-21T20:06:56.647Z (7 months ago)
- Language: TypeScript
- Homepage: https://npm.im/@coderosh/string-time
- Size: 90.8 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# string-time
Convert time string into seconds, minutes, hour, array or object and vice versa.
## Installation
Install via npm
```sh
npm install @coderosh/string-time
```
Or via yarn
```sh
yarn add @coderosh/string-time
```
## Usage
```js
import stringTime, { reverse } from '@coderosh/string-time'
```
### stringTime
```js
const time = stringTime('1:59:60')
time.array // [ 2, 0, 0 ]
time.string // 02:00:00
time.object // { hour: 2, minute: 0, second: 0 }
time.totalHours // 2
time.totalMinutes // 120
time.totalSeconds // 7200
stringTime('').string // 00:00:00
stringTime(':1:').string // 00:01:00
stringTime('1').string // 01:00:00
stringTime('::1').string // 00:00:01
```
### reverse
```js
reverse({ second: 7200 }) // 02:00:00
reverse({ hour: 2 }) // 02:00:00
reverse({ minute: 120 }) // 02:00:00
reverse({ hour: 2, minute: 1, second: 0 }) // 02:01:00
reverse([2, 0, 1]) // 02:00:01
```