ExMs
A tiny library to parse human readable formats into milliseconds.
Inspired by ms.js and meant for making date/time duration configuration easier, this tiny library will parse simple duration/time based
Installation
Add :ex_ms to your project's mix.exs:
def deps do
[
{:ex_ms, "~> 0.1.0"}
]
endUsage
Since this takes inspiration from ms.js, the basic usage also applies:
import Millisecond, only: [ms!: 1, ms: 1]
ms!("2 days")
172800000
ms!("1d")
86400000
ms!("10h")
36000000
ms!("2.5 hrs")
9.0e6
ms!("2h")
7200000
ms!("1m")
60000
ms!("5s")
5000
ms!("1y")
31557600000
ms!("100")
100
ms!("-3 days")
-259200000
ms!("-1h")
-3600000
ms!("-200")
-200Unlike the inspiration, it does not support millisecond to string. It does support multiple units delimited by spaces but must be ordered:
ms!("1h 1m 1s")
86400000
ms!("1days 12 hours")
129600000
ms("12 hours 1days")
:error