Gizra / elm-compat-019 / Time018

In Elm 0.19, the Time module was moved to a separate package elm-time, with a significantly modified API. This implements the old API.

Time


type alias Time =
Basics.Float

Type alias to make it clearer when you are working with time values. Using the Time helpers like second and inSeconds instead of raw numbers is very highly recommended.

now : Task x Time

Get the Time at the moment when this task is run.

every : Time -> (Time -> msg) -> Platform.Sub.Sub msg

Subscribe to the current time. First you provide an interval describing how frequently you want updates. Second, you give a tagger that turns a time into a message for your update function. So if you want to hear about the current time every second, you would say something like this:

type Msg = Tick Time | ...

subscriptions model =
  every second Tick

Check out the Elm Architecture Tutorial for more info on how subscriptions work.

Note: this function is not for animation! You need to use something based on requestAnimationFrame to get smooth animations. This is based on setInterval which is better for recurring tasks like “check on something every 30 seconds”.

Units

millisecond : Time

Units of time, making it easier to specify things like a half-second (500 * millisecond) without remembering Elm’s underlying units of time.

second : Time

minute : Time

hour : Time

inMilliseconds : Time -> Basics.Float

inSeconds : Time -> Basics.Float

inMinutes : Time -> Basics.Float

inHours : Time -> Basics.Float