Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dolegi/ms
Converts time strings to and from number of milliseconds
https://github.com/dolegi/ms
golang ms time
Last synced: 7 days ago
JSON representation
Converts time strings to and from number of milliseconds
- Host: GitHub
- URL: https://github.com/dolegi/ms
- Owner: dolegi
- License: mit
- Created: 2019-03-06T17:52:54.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-06T21:47:59.000Z (almost 6 years ago)
- Last Synced: 2024-12-06T22:39:47.297Z (27 days ago)
- Topics: golang, ms, time
- Language: Go
- Size: 3.91 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ms
[![Build Status](https://travis-ci.org/dolegi/ms.svg?branch=master)](https://travis-ci.org/dolegi/ms)Golang has support for this built in. Check out [ParseDuration](https://golang.org/pkg/time/#ParseDuration)
Converts time strings to and from number of milliseconds
This is a rewrite of [zeit/ms](https://github.com/zeit/ms) in golang
Documentation [godoc](https://godoc.org/github.com/dolegi/ms)
## Examples
```go
ms.Parse('2 days') // 172800000
ms.Parse('1d') // 86400000
ms.Parse('10h') // 36000000
ms.Parse('2.5 hrs') // 9000000
ms.Parse('2h') // 7200000
ms.Parse('1m') // 60000
ms.Parse('5s') // 5000
ms.Parse('1y') // 31557600000
ms.Parse('100') // 100
ms.Parse('-3 days') // -259200000
ms.Parse('-1h') // -3600000
ms.Parse('-200') // -200
```### Convert from Milliseconds
```go
ms.Fmt(60000) // "1m"
ms.Fmt(2 * 60000) // "2m"
ms.Fmt(-3 * 60000) // "-3m"
ms.Fmt(ms('10 hours')) // "10h"
```### Time Format Written-Out
```go
ms.FmtLong(60000) // "1 minute"
ms.FmtLong(2 * 60000) // "2 minutes"
ms.FmtLong(-3 * 60000) // "-3 minutes"
ms.FmtLong(ms.Parse('10 hours')) // "10 hours"
```## Tests
Tests can be run with `go test`