forked from damiengarbarino/dojo-calendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimeBase.js
45 lines (42 loc) · 889 Bytes
/
TimeBase.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
define([
"dcl/dcl",
"deliteful/TimeBase"
], function (
dcl,
TimeBase
) {
/**
* Mixin with time methods.
* Extension of deliteful/TimeBase to add `floorDate()` method.
*/
return dcl(TimeBase, {
floorDate: function (date, unit, steps) {
// summary:
// floors the date to the unit.
// date: DateTime
// The date/time to floor.
// unit: String
// The unit. Valid values are "minute", "hour", "day", "week".
// steps: Integer
// For "day" or "week" only 1 is valid.
// returns: DateTime
var d = date.startOf("day");
switch (unit) {
case "week":
return this.floorToWeek(d);
case "minute":
d = d.set({
hour: date.hour,
minute: Math.floor(date.minute / steps) * steps
});
break;
case "hour":
d = d.set({
hour: Math.floor(date.hour / steps) * steps
});
break;
}
return d;
}
});
});