Permalink
Browse files

add time.ofDay

  • Loading branch information...
marcuswestin committed May 22, 2013
1 parent 82c6713 commit ab832691e1294d8a98972c04541d3ca8d3e69e68
Showing with 9 additions and 1 deletion.
  1. +9 −1 time.js
View
10 time.js
@@ -18,6 +18,7 @@ function timeWithBase(base) {
var time = {
now: now,
ago: ago,
+ ofDay: ofDay,
// for creating instances of time in a different base
inMilliseconds: inMilliseconds,
inSeconds: inSeconds,
@@ -39,7 +40,8 @@ function timeWithBase(base) {
function getLocalTime(utcTime, utcOffset) { return utcTime + utcOffset * time.minutes }
function getLocalDay(utcTime, utcOffset) { return Math.floor(getLocalTime(utcTime, utcOffset) / time.day) }
function getLocalHourOfDay(utcTime, utcOffset) { return Math.floor(getLocalTime(utcTime, utcOffset) / time.hour) % 24 }
-
+ function getLocalMinute(utcTime, utcOffset) { return Math.floor(getLocalTime(utcTime, utcOffset) / time.minute) % 60 }
+
time.millisecond = time.milliseconds = 1 / base
time.second = time.seconds = 1000 * time.millisecond
time.minute = time.minutes = 60 * time.second
@@ -49,6 +51,12 @@ function timeWithBase(base) {
function now(_base) { return Math.round(new Date().getTime() / (_base || base)) }
+ function ofDay(utcTime, utcOffset) {
+ return _pad(getLocalHourOfDay(utcTime, utcOffset)+1)+':'+_pad(getLocalMinute(utcTime, utcOffset))
+ }
+
+ function _pad(num) { return num < 10 ? '0'+num : num }
+
function ago(ts, yield) { return ago.stepFunction(ts, yield) }
ago.stepFunction = _stepFunction(
10 * time.second, 'just now', null,

0 comments on commit ab83269

Please sign in to comment.