-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
83 lines (60 loc) · 1.45 KB
/
index.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
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
'use strict';
var DateTime = require('./src/datetime');
var TimedNumber = require('./src/timednumber');
var TimedState = require('./src/timedstate');
// global offsets for datetime
var offsets = {
days: 0,
hours: 0
};
// global default format
var globalDefaultFormat = null;
exports.setOffsetInDays = function (d) {
if (isNaN(d)) {
throw new Error('invalidOffset');
}
offsets.days = d;
};
exports.setOffsetInHours = function (h) {
if (isNaN(h)) {
throw new Error('invalidOffset');
}
offsets.hours = h;
};
exports.setDefaultFormat = function (format) {
globalDefaultFormat = format;
};
exports.setWeekNames = function (list) {
DateTime.setWeekNames(list);
};
exports.setShortWeekNames = function (list) {
DateTime.setShortWeekNames(list);
};
exports.setMonthName = function (list) {
DateTime.setMonthName(list);
};
exports.setShortMonthNames = function (list) {
DateTime.setShortMonthName(list);
};
exports.setPeriod = function (list) {
DateTime.setPeriod(list);
};
exports.create = function (now, defaultFormat) {
if (!defaultFormat && globalDefaultFormat) {
defaultFormat = globalDefaultFormat;
}
var d = new DateTime(now, defaultFormat);
if (offsets.days !== 0) {
d.offsetInDays(offsets.days);
}
if (offsets.hours !== 0) {
d.offsetInHours(offsets.hours);
}
return d;
};
exports.createTimedNumber = function (conf) {
return new TimedNumber(conf);
};
exports.createTimedState = function (conf) {
return new TimedState(conf);
};