on master help sign in
Convert Time docs
commit6fda891f816ff7a6d735f20d1cf74216704c9b06 authorJustin Leitgeb <justin@stackbuilders.com> dateMon 9 Sep 2013, 22:43 (13 years ago) parent2edcced
1 file changed+40−28
libraries/Time.elm+40−28
libraries/Time.elm+40−28
@@ -1,17 +1,25 @@
1−-- Library for working with time. Type `Time` represents some number of milliseconds.
21module Time where
32
3+{-| Library for working with time. Type `Time` represents some number of
4+milliseconds.
5+
6+# Type and Constructors
7+@docs Time, millisecond, fps, fpsWhen, every, since, timestamp, delay
8+
9+-}
10+
411import open Basics
512import Native.Time
613import Signal (Signal)
714
8−-- 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.
15+{-| Type alias to make it clearer when you are working with time values.
16+Using the `Time` constants instead of raw numbers is very highly recommended.
17+-}
1018type Time = Float
1119
12−-- Units of time, making it easier to specify things like a
13−-- half-second `(500 * milliseconds)` without remembering Elm&rsquo;s
14−-- underlying units of time.
20+{-| Units of time, making it easier to specify things like a half-second
21+`(500 * milliseconds)` without remembering Elm&rsquo;s underlying units of time.
22+-}
1523millisecond : Time
1624millisecond = 1
1725
@@ -36,42 +44,46 @@ inMinutes t = t / minute
3644inHours : Time -> Float
3745inHours t = t / hour
3846
39−-- 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
41−-- the desired FPS. A time delta is the time between the last frame and the
42−-- current frame.
47+{-| Takes desired number of frames per second (fps). The resulting signal
48+gives a sequence of time deltas as quickly as possible until it reaches
49+the desired FPS. A time delta is the time between the last frame and the
50+current frame.
51+-}
4352fps : number -> Signal Time
4453fps = Native.Time.fps
4554
46−-- 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.
48−-- 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
50−-- of time that the output signal has been running.
55+{-| Same as the fps function, but you can turn it on and off. Allows you
56+to do brief animations based on user input without major inefficiencies.
57+The first time delta after a pause is always zero, no matter how long
58+the pause was. This way summing the deltas will actually give the amount
59+of time that the output signal has been running.
60+-}
5161fpsWhen : number -> Signal Bool -> Signal Time
5262fpsWhen = Native.Time.fpsWhen
5363
54−-- Takes a time interval t. The resulting signal is the current time,
55−-- updated every t.
64+{-| Takes a time interval t. The resulting signal is the current time, updated
65+every t.
66+-}
5667every : Time -> Signal Time
5768every = Native.Time.every
5869
59−-- Takes a time `t` and any signal. The resulting boolean signal
60−-- is true for time `t` after every event on the input signal.
61−-- So ``(second `since` Mouse.clicks)`` would result in a signal
62−-- that is true for one second after each mouse click and false
63−-- otherwise.
70+{-| Takes a time `t` and any signal. The resulting boolean signal is true for
71+time `t` after every event on the input signal. So ``(second `since`
72+Mouse.clicks)`` would result in a signal that is true for one second after
73+each mouse click and false otherwise.
74+-}
6475since : Time -> Signal a -> Signal Bool
6576since = Native.Time.since
6677
67−-- 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
69−-- always have the same timestamp because they both rely on the same
70−-- underlying event.
78+{-| Add a timestamp to any signal. Timestamps increase monotonically. Each
79+timestamp is related to a specfic event, so `Mouse.x` and `Mouse.y` will always
80+have the same timestamp because they both rely on the same underlying event.
81+-}
7182timestamp : Signal a -> Signal (Time, a)
7283timestamp = Native.Time.timestamp
7384
74−-- Delay a signal by a certain amount of time. So `(delay second Mouse.clicks)`
75−-- will update one second later than any mouse click.
85+{-| Delay a signal by a certain amount of time. So `(delay second Mouse.clicks)`
86+will update one second later than any mouse click.
87+-}
7688delay : Time -> Signal a -> Signal a
7789delay = Native.Time.delay