birl/duration
Types
An alias for gleam_time’s Duration type, representing a span of time in nanoseconds.
pub type Duration =
duration.Duration
Values
pub fn accurate_decompose(
duration: 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.Duration
use this if you need very long durations where small inaccuracies could lead to large errors
pub fn add(
a: duration.Duration,
b: duration.Duration,
) -> duration.Duration
pub fn blur(duration: duration.Duration) -> #(Int, Unit)
approximates the duration by a value in a single unit
pub fn blur_to(duration: duration.Duration, unit: Unit) -> Int
approximates the duration by only the given unit
if the duration is not an integer multiple of the unit, the remainder will be disgarded if it’s less than two thirds of the unit, otherwise a single unit will be added to the multiplier.
blur_to(days(16), Month)->0blur_to(days(20), Month)->1
pub fn compare(
a: duration.Duration,
b: duration.Duration,
) -> order.Order
pub fn days(value: Int) -> duration.Duration
pub fn decompose(
duration: 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 from_gleam_duration(
d: duration.Duration,
) -> duration.Duration
Deprecated: Duration is now gleam_time's Duration type. This function is a no-op.
Convert gleam_time Duration to birl Duration.
Deprecated: Duration is the same type as gleam_time Duration. This function exists for backward compatibility and is a no-op.
pub fn hours(value: Int) -> duration.Duration
pub fn micro_seconds(value: Int) -> duration.Duration
pub fn milli_seconds(value: Int) -> duration.Duration
pub fn minutes(value: Int) -> duration.Duration
pub fn months(value: Int) -> duration.Duration
pub fn nano_seconds(value: Int) -> duration.Duration
pub fn new(values: List(#(Int, Unit))) -> duration.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.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 nanoseconds.
specifying accurate: is equivalent to using accurate_new.
pub fn scale_down(
value: duration.Duration,
factor: Int,
) -> duration.Duration
pub fn scale_up(
value: duration.Duration,
factor: Int,
) -> duration.Duration
pub fn seconds(value: Int) -> duration.Duration
pub fn subtract(
a: duration.Duration,
b: duration.Duration,
) -> duration.Duration
pub fn to_gleam_duration(
d: duration.Duration,
) -> duration.Duration
Deprecated: Duration is now gleam_time's Duration type. This function is a no-op.
Convert birl Duration to gleam_time Duration.
Deprecated: Duration is the same type as gleam_time Duration. This function exists for backward compatibility and is a no-op.
pub fn weeks(value: Int) -> duration.Duration
pub fn years(value: Int) -> duration.Duration