@@ -1,17 +1,25 @@
1−-- Library for working with time. Type `Time` represents some number of milliseconds.
2module Time where
1module Time where
3+{-| Library for working with time. Type `Time` represents some number of
6+# Type and Constructors
7+@docs Time, millisecond, fps, fpsWhen, every, since, timestamp, delay
4import open Basics
11import open Basics
5import Native.Time
12import Native.Time
6import Signal (Signal)
13import Signal (Signal)
8−-- Type alias to make it clearer when you are working with time values.
15+{-| Type alias to make it clearer when you are working with time values.
9−-- Using the `Time` constants instead of raw numbers is very highly recommended.
16+Using the `Time` constants instead of raw numbers is very highly recommended.
10type Time = Float
18type Time = Float
12−-- Units of time, making it easier to specify things like a
20+{-| Units of time, making it easier to specify things like a half-second
13−-- half-second `(500 * milliseconds)` without remembering Elm’s
21+`(500 * milliseconds)` without remembering Elm’s underlying units of time.
14−-- underlying units of time.
22+-}
15millisecond : Time
23millisecond : Time
16millisecond = 1
24millisecond = 1
@@ -36,42 +44,46 @@ inMinutes t = t / minute
36inHours : Time -> Float
44inHours : Time -> Float
37inHours t = t / hour
45inHours t = t / hour
39−-- Takes desired number of frames per second (fps). The resulting signal
47+{-| Takes desired number of frames per second (fps). The resulting signal
40−-- gives a sequence of time deltas as quickly as possible until it reaches
48+gives a sequence of time deltas as quickly as possible until it reaches
41−-- the desired FPS. A time delta is the time between the last frame and the
49+the desired FPS. A time delta is the time between the last frame and the
42−-- current frame.
50+current frame.
43fps : number -> Signal Time
52fps : number -> Signal Time
44fps = Native.Time.fps
53fps = Native.Time.fps
46−-- Same as the fps function, but you can turn it on and off. Allows you
55+{-| Same as the fps function, but you can turn it on and off. Allows you
47−-- to do brief animations based on user input without major inefficiencies.
56+to do brief animations based on user input without major inefficiencies.
48−-- The first time delta after a pause is always zero, no matter how long
57+The first time delta after a pause is always zero, no matter how long
49−-- the pause was. This way summing the deltas will actually give the amount
58+the pause was. This way summing the deltas will actually give the amount
50−-- of time that the output signal has been running.
59+of time that the output signal has been running.
51fpsWhen : number -> Signal Bool -> Signal Time
61fpsWhen : number -> Signal Bool -> Signal Time
52fpsWhen = Native.Time.fpsWhen
62fpsWhen = Native.Time.fpsWhen
54−-- Takes a time interval t. The resulting signal is the current time,
64+{-| Takes a time interval t. The resulting signal is the current time, updated
55−-- updated every t.
65+every t.
56every : Time -> Signal Time
67every : Time -> Signal Time
57every = Native.Time.every
68every = Native.Time.every
59−-- Takes a time `t` and any signal. The resulting boolean signal
70+{-| Takes a time `t` and any signal. The resulting boolean signal is true for
60−-- is true for time `t` after every event on the input signal.
71+time `t` after every event on the input signal. So ``(second `since`
61−-- So ``(second `since` Mouse.clicks)`` would result in a signal
72+Mouse.clicks)`` would result in a signal that is true for one second after
62−-- that is true for one second after each mouse click and false
73+each mouse click and false otherwise.
64since : Time -> Signal a -> Signal Bool
75since : Time -> Signal a -> Signal Bool
65since = Native.Time.since
76since = Native.Time.since
67−-- Add a timestamp to any signal. Timestamps increase monotonically. Each
78+{-| Add a timestamp to any signal. Timestamps increase monotonically. Each
68−-- timestamp is related to a specfic event, so `Mouse.x` and `Mouse.y` will
79+timestamp is related to a specfic event, so `Mouse.x` and `Mouse.y` will always
69−-- always have the same timestamp because they both rely on the same
80+have the same timestamp because they both rely on the same underlying event.
70−-- underlying event.
81+-}
71timestamp : Signal a -> Signal (Time, a)
82timestamp : Signal a -> Signal (Time, a)
72timestamp = Native.Time.timestamp
83timestamp = Native.Time.timestamp
74−-- Delay a signal by a certain amount of time. So `(delay second Mouse.clicks)`
85+{-| Delay a signal by a certain amount of time. So `(delay second Mouse.clicks)`
75−-- will update one second later than any mouse click.
86+will update one second later than any mouse click.
76delay : Time -> Signal a -> Signal a
88delay : Time -> Signal a -> Signal a
77delay = Native.Time.delay
89delay = Native.Time.delay