package calendar

  1. Overview
  2. Docs

Module CalendarLib.TimeSource

Time implementation in which seconds are integers.

include Time_sig.S with type second = int

Datatypes

Sourcetype t

Type of a time.

Sourcetype field = [
  1. | `Hour
  2. | `Minute
  3. | `Second
]

The different fields of a time.

Second

Sourcetype second = int

Type of a second.

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

Second implementation

Constructors

Sourceval make : int -> int -> second -> t

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

Sourceval lmake : ?hour:int -> ?minute:int -> ?second:second -> unit -> t

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

  • since 1.05
Sourceval now : unit -> t

The current time based on Time_Zone.current ().

Sourceval midnight : unit -> t

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

Sourceval 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

Sourceval convert : t -> Time_Zone.t -> Time_Zone.t -> t

convert t t1 t2 converts the time t expressed in the time zone t1 to the same time expressed in the time zone t2. @example convert (make 20 0 0) (Time_Zone.GMT_Plus 2) (Time_Zone.GMT_Plus 4) returns the time 22-0-0.

Sourceval from_gmt : t -> t

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

Sourceval to_gmt : t -> t

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

Sourceval normalize : t -> t * int

normalize t returns t such that hour t belongs to [0; 24[. The second component of the result is the number of days needed by the modification. @example normalize (make 22 0 0) returns the time 22-0-0 and 0, normalize (make 73 0 0) returns the time 1-0-0 and 3 and normalize (make (-73) 0 0) returns the time 23-0-0 and (-4).

Getters

Sourceval hour : t -> int

Hour. @example hour (make 20 0 0) returns 20.

Sourceval minute : t -> int

Minute. @example minute (make 20 10 0) returns 10.

Sourceval second : t -> second

Second. @example second (make 20 10 5) returns 5.

Sourceval to_seconds : t -> second

Number of seconds of a time. @example to_seconds (make 1 2 3) returns 3600 + 120 + 3 = 3723.

Sourceval to_minutes : t -> float

Number of minutes of a time. The resulting fractional part represents seconds. @example to_minutes (make 1 2 3) returns 60+2+0.05 = 62.05.

Sourceval to_hours : t -> float

Number of hours of a time. The resulting fractional part represents minutes and seconds. @example to_hours (make 1 3 0) returns 1 + 0.05 = 1.05.

Times are comparable

Sourceval equal : t -> t -> bool

Equality function between two times.

  • since 1.09.0
Sourceval compare : t -> t -> int

Comparison function between two times.

Sourceval hash : t -> int

Hash function for times.

  • since 2.0

Boolean operations on times

Sourceval is_pm : t -> bool

Return true is the time is before midday in the current time zone; false otherwise. @example both is_pm (make 10 0 0) and is_pm (make 34 0 0) return true.

Sourceval is_am : t -> bool

Return true is the time is after midday in the current time zone; false otherwise. @example both is_am (make 20 0 0) and is_am (make 44 0 0) return true.

Coercions

Sourceval from_seconds : second -> t

Inverse of to_seconds.

Sourceval from_minutes : float -> t

Inverse of to_minutes.

Sourceval from_hours : float -> t

Inverse of to_hours.

Period

Sourcemodule Period : sig ... end

A period is the number of seconds between two times.

Arithmetic operations on times and periods

Sourceval add : t -> 'a Period.period -> t

app t p returns t + p. @example add (make 20 0 0) (Period.minute 70) returns the time 21:10:0.

Sourceval sub : t -> t -> 'a Period.period

sub t1 t2 returns the period between t1 and t2.

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

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

Sourceval next : t -> field -> t

next t f returns the time corresponding to the next specified field. @example next (make 20 3 31) `Minute returns the time 20:04:31. (i.e. one minute later).

Sourceval prev : t -> field -> t

prev t f returns the time corresponding to the previous specified field. @example prev (make 20 3 31) `Second returns the time 20:03:30 (i.e. one second ago).

OCaml

Innovation. Community. Security.