Add now
and lots of time conversions to time library
This commit is contained in:
parent
ede839f787
commit
b5df47f6f6
1 changed files with 26 additions and 1 deletions
|
@ -1,4 +1,10 @@
|
|||
Elm.Time = function() {
|
||||
var now = function(t) {
|
||||
var clock = Elm.Signal.constant((new Date()).getTime());
|
||||
function tellTime() { Dispatcher.notify(clock.id, (new Date()).getTime()); }
|
||||
setInterval(tellTime, t);
|
||||
return clock;
|
||||
};
|
||||
var every = function(t) {
|
||||
t *= 1000;
|
||||
var clock = Elm.Signal.constant(0);
|
||||
|
@ -21,5 +27,24 @@ Elm.Time = function() {
|
|||
setTimeout(function() { Dispatcher.notify(thread.id, false); }, t);
|
||||
return thread;
|
||||
};
|
||||
return {every:every,after:after,before:before};
|
||||
function read(s) {
|
||||
var t = Date.parse(s);
|
||||
return isNaN(t) ? Nothing : Just(s);
|
||||
}
|
||||
return {now:now,
|
||||
every:every,
|
||||
after:after,
|
||||
before:before,
|
||||
hours : function(n) { return n * 3600000; },
|
||||
minutes : function(n) { return n * 60000; },
|
||||
seconds : function(n) { return n * 1000; },
|
||||
millis : function(n) { return n; },
|
||||
inHours : function(t) { return ~~(t / 3600000); },
|
||||
inMinutes : function(t) { return ~~(t / 60000); },
|
||||
inSeconds : function(t) { return ~~(t / 1000); },
|
||||
inMillis : function(t) { return t; },
|
||||
toDate : function(t) { return new Date(t); },
|
||||
read : read
|
||||
};
|
||||
|
||||
}();
|
Loading…
Reference in a new issue