| 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102 | 2×
2×
2×
2×
2×
2×
65×
65×
65×
65×
37960×
303680×
303680×
303680×
303160×
303680×
65×
65×
37895×
1105×
65×
2×
342×
41×
41×
41×
49×
49×
48×
1×
1×
1×
1×
1×
49×
49×
48×
1×
1×
1×
65×
1206×
1206×
1206×
1206×
1×
1×
64×
64×
64×
2×
| var CourseStore, TimeHelper, TimeStore, _, moment, tzdetect,
slice = [].slice;
moment = require('moment-timezone');
_ = require('underscore');
TimeStore = require('../flux/time').TimeStore;
CourseStore = require('../flux/course').CourseStore;
tzdetect = {
names: moment.tz.names(),
matches: function(base) {
var lockey, makekey, now, results;
results = [];
now = Date.now();
makekey = function(id) {
return [0, 4, 8, -5 * 12, 4 - 5 * 12, 8 - 5 * 12, 4 - 2 * 12, 8 - 2 * 12].map(function(months) {
var m;
m = moment(now + months * 30 * 24 * 60 * 60 * 1000);
if (id) {
m.tz(id);
}
return m.format('DDHHmm');
}).join(' ');
};
lockey = makekey(base);
tzdetect.names.forEach(function(id) {
if (makekey(id) === lockey) {
return results.push(id);
}
});
return results;
}
};
TimeHelper = {
PropTypes: {
moment: function(props, propName, componentName) {
Iif (!moment.isMoment(props[propName])) {
return new Error(propName + " should be a moment for " + componentName);
}
}
},
getCurrentLocales: function() {
var currentLocale;
currentLocale = moment.localeData();
return {
abbr: currentLocale._abbr,
week: currentLocale._week,
weekdaysMin: currentLocale._weekdaysMin
};
},
syncCourseTimezone: function(courseId) {
var courseTimezone, zonedMoment;
if (this.isCourseTimezone(courseId)) {
return;
}
courseTimezone = CourseStore.getTimezone(courseId);
Eif (this._local == null) {
this._local = _.first(this.getLocalTimezone());
}
zonedMoment = moment.fn.tz(courseTimezone);
return zonedMoment;
},
unsyncCourseTimezone: function() {
var unzonedMoment;
if (this._local == null) {
return;
}
unzonedMoment = moment.fn.tz(this._local);
this.unsetLocal();
return unzonedMoment;
},
getLocalTimezone: function() {
return tzdetect.matches();
},
getMomentPreserveDate: function() {
var args, value;
value = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
Iif (this._local) {
return moment.apply(null, [value].concat(slice.call(args))).tz(this._local).hour(12);
}
return moment.apply(null, [value].concat(slice.call(args))).hour(12);
},
getLocal: function() {
return this._local;
},
unsetLocal: function() {
return this._local = null;
},
isCourseTimezone: function(courseId) {
var courseTimezone;
courseTimezone = CourseStore.getTimezone(courseId);
return TimeHelper.getLocalTimezone().indexOf(courseTimezone) > -1;
}
};
module.exports = TimeHelper;
|