Module CalendarLib.Time

include Time_sig.S with type second = int

Datatypes

type t

Type of a time.

type field = [
| `Hour
| `Minute
| `Second
]

The different fields of a time.

Second

type second = int

Type of a second.

since
2.0 (was an integer in previous versions).
module Second : Time_sig.Second with type t = second

Second implementation

Constructors

val make : int -> int -> second -> t

make hour minute second makes the time hour-minute-second.

val lmake : ?⁠hour:int -> ?⁠minute:int -> ?⁠second:second -> unit -> t

Labelled version of make. The default value is 0 for each argument.

since
1.05
val now : unit -> t

The current time based on Time_Zone.current ().

val midnight : unit -> t

midnight () is midnight (expressed in the current time zone). So, it has always the same behaviour as make 0 0 0.

val midday : unit -> t

midday () is midday (expressed in the current time zone). So, it has always the same behaviour as make 12 0 0.

Conversions

val convert : t -> Time_Zone.t -> Time_Zone.t -> t
val from_gmt : t -> t

from_gmt t is equivalent to convert t Time_Zone.GMT (Time_Zone.current ()).

val to_gmt : t -> t

to_gmt t is equivalent to convert t (Time_Zone.current ()) Time_Zone.GMT.

val normalize : t -> t * int

Getters

val hour : t -> int
val minute : t -> int
val second : t -> second
val to_seconds : t -> second
val to_minutes : t -> float
val to_hours : t -> float

Times are comparable

val equal : t -> t -> bool

Equality function between two times.

see Utils.Comparable.html#VALequal

Utils.Comparable.equal.

since
1.09.0
val compare : t -> t -> int

Comparison function between two times.

see Utils.Comparable.html#VALcompare

Utils.Comparable.compare.

val hash : t -> int

Hash function for times.

see Utils.Comparable.html#VALhash

Utils.Comparable.hash.

since
2.0

Boolean operations on times

val is_pm : t -> bool
val is_am : t -> bool

Coercions

val from_seconds : second -> t

Inverse of to_seconds.

val from_minutes : float -> t

Inverse of to_minutes.

val from_hours : float -> t

Inverse of to_hours.

Period

module Period : sig ... end

A period is the number of seconds between two times.

Arithmetic operations on times and periods

val add : t -> 'a Period.period -> t
val sub : t -> t -> 'a Period.period

sub t1 t2 returns the period between t1 and t2.

val rem : t -> 'a Period.period -> t

rem t p is equivalent to add t (Period.opp p).

val next : t -> field -> t
val prev : t -> field -> t