elm-lang/core/5.0.0

NOTE: this package moved to elm/core

NOTE: this package is not compatible with Elm 0.19.1

Time

Library for working with time.

Time

type alias Time =
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) -> 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

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 -> Float
inSeconds : Time -> Float
inMinutes : Time -> Float
inHours : Time -> Float