birl/duration

Types

pub type Duration {
  Duration(Int)
}

Constructors

  • Duration(Int)
pub type Unit {
  MicroSecond
  MilliSecond
  Second
  Minute
  Hour
  Day
  Week
  Month
  Year
}

Constructors

  • MicroSecond
  • MilliSecond
  • Second
  • Minute
  • Hour
  • Day
  • Week
  • Month
  • Year

Functions

pub fn accurate_decompose(
  duration: Duration,
) -> List(#(Int, Unit))

Use this if you need very long durations where small inaccuracies could lead to large errors

pub fn accurate_new(values: List(#(Int, Unit))) -> Duration

Use this if you need very long durations where small inaccuracies could lead to large errors

pub fn add(a: Duration, b: Duration) -> Duration
pub fn blur(duration: Duration) -> #(Int, Unit)

approximates the duration by a value in a single unit

pub fn days(value: Int) -> Duration
pub fn decompose(duration: Duration) -> List(#(Int, Unit))

Use this if you need short durations where a year just means 365 days and a month just means 30 days

pub fn hours(value: Int) -> Duration
pub fn minutes(value: Int) -> Duration
pub fn months(value: Int) -> Duration
pub fn new(values: List(#(Int, Unit))) -> Duration

Use this if you need short durations where a year just means 365 days and a month just means 30 days

pub fn parse(expression: String) -> Result(Duration, Nil)

You can use this function to create a new duration using expressions like:

"accurate: 1 Year - 2days + 152M -1h + 25 years + 25secs"

where the units are:

Year:         y, Y, YEAR, years, Years, ...

Month:        mon, Month, mONths, ...

Week:         w, W, Week, weeks, ...

Day:          d, D, day, Days, ...

Hour:         h, H, Hour, Hours, ...

Minute:       m, M, Min, minute, Minutes, ...

Second:       s, S, sec, Secs, second, Seconds, ...

MilliSecond:  ms, Msec, mSecs, milliSecond, MilliSecond, ...

Numbers with no unit are considered as microseconds. Specifying accurate: is equivalent to using accurate_new.

pub fn seconds(value: Int) -> Duration
pub fn weeks(value: Int) -> Duration
pub fn years(value: Int) -> Duration
Search Document