Time

lib/Time.gob

Dates and times. Each type has a module of its own, imported under the type's name: import Time.Date as Date (Date) gives Date.new and the bare type, and likewise Time.DateTime, Time.Instant, Time.Duration, Time.Period and the rest. This module is what they share.

What the date and time types have in common, as classes, so that one function serves every type that supports it and a type that does not is a missing instance where it is used: hour of a Date, or shift of an instant, fails to type-check.

Each class has the fewest methods its instances must write, and everything else is written once below in terms of them. The instances live here rather than beside each type so that the types' modules need not import the classes, which keeps the module graph a tree.

Timeout is how a function that waits takes its limit: one function with [Timeout t], which a caller gives a Duration or a Deadline, rather than a pair of one taking a Duration and an ...Until taking a Deadline. A wait without a limit is a function of its own, named for it.

class HasDate a

Has a calendar date.

fun date : [HasDate a] fun(a) -> Date
class HasTime a

Has a wall-clock time.

fun timeOfDay : [HasTime a] fun(a) -> TimeOfDay
class Shift a

Moves by calendar amounts, keeping its wall-clock time.

fun shift : [Shift a] fun(a, Period) -> a
class Timeline a

A point on the global timeline, which moves by elapsed time.

fun instant : [Timeline a] fun(a) -> Instant
fun after : [Timeline a] fun(a, Duration) -> a
class Timeout t

A limit on how long something may wait: a Duration, which starts when the wait is asked for, or a Deadline made earlier, so that one limit covers several steps. A function that waits takes [Timeout t], and a caller passes seconds(10) or the deadline it already has.

There is deliberately no instance for Option. With one, a None read from configuration would make a wait unbounded without the code saying so, and some waits hold a thread for as long as they last (a lookup in getaddrinfo does). A wait without a limit is a function of its own, named for it (Net.lookupUnbounded), so that the caller who wants one writes it, in the arm of a match on the Option if it comes from there.

fun deadline : [Timeout t] fun(t) -> Deadline
fun year : [HasDate a] fun(a) -> Int
fun month : [HasDate a] fun(a) -> Month
fun day : [HasDate a] fun(a) -> Int
fun weekday : [HasDate a] fun(a) -> Weekday
fun dayOfYear : [HasDate a] fun(a) -> Int
fun hour : [HasTime a] fun(a) -> Int
fun minute : [HasTime a] fun(a) -> Int
fun second : [HasTime a] fun(a) -> Int
fun nanosecond : [HasTime a] fun(a) -> Int
fun before : [Timeline a] fun(a, Duration) -> a
fun elapsed : [Timeline a, Timeline b] fun(a, b) -> Duration

The time from from to to, negative if to is earlier. The two need not be the same type: only their instants matter.

instance HasDate Date
instance HasDate PlainDateTime
instance HasDate DateTime
instance HasTime TimeOfDay
instance HasTime PlainDateTime
instance HasTime DateTime
instance Shift Date
instance Shift PlainDateTime
instance Shift DateTime
instance Timeline Instant
instance Timeline DateTime
instance Timeout Duration
instance Timeout Deadline