on 294fdfd help sign in
elk/libraries/Time.elm
62 lines 1.8 kB history raw
1-- Library for working with time. Type `Time` represents some number of milliseconds.
2module Time where
4import Native.Time as T
6type Time = Float
8-- Units of time, making it easier to specify things like a
9-- half-second `(second / 2)`.
11ms : Time
12ms = 1
14second : Time
15second = 1000 * ms
17minute : Time
18minute = 60 * second
20hour : Time
21hour = 60 * minute
23inMss : Time -> Float
24inMss t = t
26inSeconds : Time -> Float
27inSeconds t = t / second
29inMinutes : Time -> Float
30inMinutes t = t / minute
32inHours : Time -> Float
33inHours t = t / hour
35-- Takes desired number of frames per second (fps). The resulting signal
36-- gives a sequence of time deltas as quickly as possible until it reaches
37-- the desired FPS. A time delta is the time between the last frame and the
38-- current frame.
39fps : Number -> Signal Time
41-- Same as the fps function, but you can turn it on and off. Allows you
42-- to do brief animations based on user input without major ineffeciencies.
43-- The first time delta after a pause is always zero, no matter how long
44-- the pause was. This way summing the deltas will actually give the amount
45-- of time that the output signal has been running.
46fpsWhen : Number -> Signal Bool -> Signal Time
48-- Takes a time interval t. The resulting signal is the current time,
49-- updated every t.
50every : Time -> Signal Time
52-- Takes a time `t` and any signal. The resulting boolean signal
53-- is true for time `t` after every event on the input signal.
54-- So ``(second `since` Mouse.clicks)`` would result in a signal
55-- that is true for one second after each mouse click and false
56-- otherwise.
57since : Time -> Signal a -> Signal Bool
59{-- TODO: Only found in docs
60 , ("timeOf", "Signal a -> Signal Time", [markdown|
61 Same as `timestamp` but it throws out the incoming value. So `(timeOf == lift fst . timestamp)`.|])
62--}