exduration

Formatting function for durations


License
MIT

Documentation

ExDuration

Formatting durations like 12h3m, 45μs, 67ms and 8.9s.

Usage

# 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, the package can be installed by adding exduration to your list of dependencies in mix.exs:

def deps do
  [
    {:exduration, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/exduration.