Time

The built-in type Time represents the time of day to millisecond precision.

Time::components : Time -> Time::Components

Returns the components of the time value. The returned data type has the following definition:

module Time {
  type Components {
    hour : Int,
    minute : Int,
    second : Int,
    millisecond : Int
  }
}

The hour field is in the range [0 .. 23], the minute and second fields are in the range [0 .. 59], and the millisecond field is in the range [0 .. 999].

Examples

val a = Time::components (Time::from 12 13 14 15)
//    = Time::Components { hour = 12, minute = 13, second = 14, millisecond = 15 }

Time::fromComponents : Time::Components -> Time

Constructs a Time value from its components.

The function is partial and fails if any of the input components are outside their valid ranges. See Time::components for details.

Examples

val a = Time::fromComponents Time::Components { hour = 12, minute = 13, second = 14, millisecond = 999 }
//    = Time::from 12 13 14 999

Time::from : Int -> Int -> Int -> Int -> Time

Convenience wrapper for Time::fromComponents which takes the components as positional arguments. The order of arguments is

  1. hour

  2. minute

  3. second

  4. millisecond

The function is partial and fails if any of the input components are outside their valid ranges. See Time::components for details.

Time::addDuration : Duration -> Time -> Time

Adds a duration to a given time.

The function is total. If the resulting time value exceeds the valid range it simply wraps around.

Examples

// Add 10 minutes, 5 seconds and 200 milliseconds to 12:37:00.000
val a = Time::addDuration (Duration::from 605 200) (Time::from 12 37 0 0)
//    = Time::from 12 47 5 200 // 12:47:05.200

// Demonstrate overflow behavior. Adding 2 minutes to 23:59:59.500
val b = Time::addDuration (Duration::from 120 0) (Time::from 23 59 59 500)
//    = Time::from 0 1 59 500 // 00:01:59.500