2Library for working with time. Type `Time` represents some number of
10 /** hour, minute, second, ms : Time
11 Units of time, making it easier to specify things like a
12 half-second `(second / 2)`.
15 function timeNow() { return (new window.Date).getTime(); }
19 /** fps : Number -> Signal Time
20 Takes desired number of frames per second (fps). The resulting signal
21 gives a sequence of time deltas as quickly as possible until it reaches
22 the desired FPS. A time delta is the time between the last frame and the
26 /** fpsWhen : Number -> Signal Bool -> Signal Time
27 Same as the fps function, but you can turn it on and off. Allows you
28 to do brief animations based on user input without major ineffeciencies.
29 The first time delta after a pause is always zero, no matter how long
30 the pause was. This way summing the deltas will actually give the amount
31 of time that the output signal has been running.
33 function fpsWhen(desiredFPS) { return function (isOn) {
34 var msPerFrame = 1000 / desiredFPS;
35 var prev = timeNow(), curr = prev, diff = 0, wasOn = true;
36 var ticker = Elm.Signal.constant(diff);
37 function tick(zero) { return function() {
39 diff = zero ? 0 : curr - prev;
41 Dispatcher.notify(ticker.id, diff);
45 function f(isOn) { return function(t) {
47 timeoutID = setTimeout(tick(!wasOn && isOn), msPerFrame);
49 clearTimeout(timeoutID);
55 return Elm.Signal.lift2(f)(isOn)(ticker);
59 /** every : Time -> Signal Time
60 Takes a time interval t. The resulting signal is the current time,
63 function everyWhen(isOn) { return function(t) {
64 var clock = Elm.Signal.constant(timeNow());
65 function tellTime() { Dispatcher.notify(clock.id, timeNow()); }
66 setInterval(tellTime, t);
71 function since(t) { return function(s) {
72 function cmp(a) { return function(b) { return !Value.eq(a,b); }; }
73 var dcount = Elm.Signal.count(Elm.Signal.delay(t)(s));
74 return Elm.Signal.lift2(cmp)(Elm.Signal.count(s))(dcount);
79 var thread = Elm.Signal.constant(false);
80 setTimeout(function() { Dispatcher.notify(thread.id, true); }, t);
85 var thread = Elm.Signal.constant(true);
86 setTimeout(function() { Dispatcher.notify(thread.id, false); }, t);
90 var t = window.Date.parse(s);
91 return isNaN(t) ? ["Nothing"] : ["Just",t];
93 return {fpsWhen : fpsWhen,
94 fps : function(t) { return fpsWhen(t)(Elm.Signal.constant(true)); },
95 every : everyWhen(Elm.Signal.constant(true)),
96 delay : Elm.Signal.delay,
104 inHours : function(t) { return t / 3600000; },
105 inMinutes : function(t) { return t / 60000; },
106 inSeconds : function(t) { return t / 1000; },
107 inMss : function(t) { return t; },
108 toDate : function(t) { return new window.Date(t); },
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list