Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/soundtrackyourbrand/exduration
Elixir duration helpers
https://github.com/soundtrackyourbrand/exduration
Last synced: about 1 month ago
JSON representation
Elixir duration helpers
- Host: GitHub
- URL: https://github.com/soundtrackyourbrand/exduration
- Owner: soundtrackyourbrand
- Created: 2019-03-18T08:19:19.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-10T11:45:51.000Z (almost 6 years ago)
- Last Synced: 2024-04-24T07:23:02.016Z (9 months ago)
- Language: Elixir
- Size: 9.77 KB
- Stars: 3
- Watchers: 9
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ExDuration
Formatting durations like _12h3m_, _45μs_, _67ms_ and _8.9s_.
## Usage
```elixir
# Format a duration
@interval_ms 6000
Logger.info("doing work every #{ExDuration.format(@interval_ms, :millisecond)}")# Format the duration since a timestamp
start = :os.system_time(:millisecond)
_ = work()
Logger.info("work took #{ExDuration.since(start, :millisecond)}")# Format the duration between two DateTime's
Logger.info("A and B are #{ExDuration.between(dt1, dt2)} apart")# Parse a duration string
{:ok, millis} = ExDuration.parse("5m", :millisecond)
millis = ExDuration.parse!("5m", :millisecond)
```## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `exduration` to your list of dependencies in `mix.exs`:```elixir
def deps do
[
{:exduration, "~> 0.1.0"}
]
end
```Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/exduration](https://hexdocs.pm/exduration).