package duration

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module DurationSource

Duration - conversions to various time units

A duration is represented in nanoseconds as an unsigned 64 bit integer. This has a range of up to 584 years, or 213503 days, or 5124095 hours, or 307445734 minutes, or 18446744073 seconds, or 18446744073709 milliseconds, or 18446744073709549 microseconds.

All functions converting to t raise Invalid_argument on out of bound or negative input.

v0.3.1 - homepage

Sourcetype t = int64

The type for a duration (in nanoseconds), exposed as an int64 to provide interoperability.

Sourceval pp : Format.formatter -> t -> unit

pp ppf t prints the duration in a concise way.

Sourceval of_us : int -> t

of_us us are the microseconds in nanoseconds.

Sourceval of_us_64 : int64 -> t

of_us_64 us are the microseconds in nanoseconds.

Sourceval of_ms : int -> t

of_ms ms are the milliseconds in nanoseconds.

Sourceval of_ms_64 : int64 -> t

of_ms_64 ms are the milliseconds in nanoseconds.

Sourceval of_sec : int -> t

of_sec s are the seconds in nanoseconds.

Sourceval of_sec_64 : int64 -> t

of_sec_64 s are the seconds in nanoseconds.

Sourceval of_min : int -> t

of_min m are the minutes in nanoseconds.

Sourceval of_hour : int -> t

of_hour h are the hours in nanoseconds.

Sourceval of_day : int -> t

of_day d are the days in nanoseconds.

Sourceval of_year : int -> t

of_year y are the years in nanoseconds.

Sourceval of_f : float -> t

of_f f is the floating point seconds in nanoseconds.

Sourceval to_us : t -> int

to_us t are the microseconds of t.

Sourceval to_us_64 : t -> int64

to_us_64 t are the microseconds of t.

Sourceval to_ms : t -> int

to_ms t are the milliseconds of t.

Sourceval to_ms_64 : t -> int64

to_ms_64 t are the milliseconds of t.

Sourceval to_sec : t -> int

to_sec t are the seconds of t.

Sourceval to_sec_64 : t -> int64

to_sec_64 t are the seconds of t.

Sourceval to_min : t -> int

to_min t are the minutes of t.

Sourceval to_hour : t -> int

to_hour t are the hours of t.

Sourceval to_day : t -> int

to_day t are the days of t.

Sourceval to_year : t -> int

to_year t are the years of t.

Sourceval to_f : t -> float

to_f t is the floating point representation of t.

Sourceval of_string_exn : string -> t

of_string_exn str tries to parse str and calculate a duration. The user can specify a duration via metrics:

  • 1ns for one nanoseconds
  • 1us, 1μs or 1µs for one microsecond
  • 1ms for one milliseconds
  • 1s for one second
  • 1m for one minute
  • 1h for one hour
  • 1d for one day
  • 1y/1a for one year

The user can use multiple metrics but they can be used only once. 1d1d is invalid (you can use 2d) but 1d1y is valid and correspond to 1 year plus 1 day.

Sourceval of_string : string -> (t, [> `Msg of string ]) result

of_string is of_string_exn but it returns a result instead of raising an exception.