1 | 'use strict';
|
2 |
|
3 | var DateTime = require('./src/datetime');
|
4 | var TimedNumber = require('./src/timednumber');
|
5 | var TimedState = require('./src/timedstate');
|
6 |
|
7 |
|
8 | var offsets = {
|
9 | days: 0,
|
10 | hours: 0
|
11 | };
|
12 |
|
13 |
|
14 | var globalDefaultFormat = null;
|
15 |
|
16 | exports.setOffsetInDays = function (d) {
|
17 |
|
18 | if (isNaN(d)) {
|
19 | throw new Error('invalidOffset');
|
20 | }
|
21 |
|
22 | offsets.days = d;
|
23 | };
|
24 |
|
25 | exports.setOffsetInHours = function (h) {
|
26 |
|
27 | if (isNaN(h)) {
|
28 | throw new Error('invalidOffset');
|
29 | }
|
30 |
|
31 | offsets.hours = h;
|
32 | };
|
33 |
|
34 | exports.setDefaultFormat = function (format) {
|
35 | globalDefaultFormat = format;
|
36 | };
|
37 |
|
38 | exports.setWeekNames = function (list) {
|
39 | DateTime.setWeekNames(list);
|
40 | };
|
41 |
|
42 | exports.setShortWeekNames = function (list) {
|
43 | DateTime.setShortWeekNames(list);
|
44 | };
|
45 |
|
46 | exports.setMonthName = function (list) {
|
47 | DateTime.setMonthName(list);
|
48 | };
|
49 |
|
50 | exports.setShortMonthNames = function (list) {
|
51 | DateTime.setShortMonthName(list);
|
52 | };
|
53 |
|
54 | exports.setPeriod = function (list) {
|
55 | DateTime.setPeriod(list);
|
56 | };
|
57 |
|
58 | exports.create = function (now, defaultFormat) {
|
59 |
|
60 | if (!defaultFormat && globalDefaultFormat) {
|
61 | defaultFormat = globalDefaultFormat;
|
62 | }
|
63 |
|
64 | var d = new DateTime(now, defaultFormat);
|
65 |
|
66 | if (offsets.days !== 0) {
|
67 | d.offsetInDays(offsets.days);
|
68 | }
|
69 |
|
70 | if (offsets.hours !== 0) {
|
71 | d.offsetInHours(offsets.hours);
|
72 | }
|
73 |
|
74 | return d;
|
75 | };
|
76 |
|
77 | exports.createTimedNumber = function (conf) {
|
78 | return new TimedNumber(conf);
|
79 | };
|
80 |
|
81 | exports.createTimedState = function (conf) {
|
82 | return new TimedState(conf);
|
83 | };
|