moment-ambig.js
5.7 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
describe('ambiguously-zoned moment', function() {
it('has a false hasZone', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-08T10:00:00');
expect(mom.hasZone()).toBe(false);
});
it('has a true hasTime', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-08T10:00:00');
expect(mom.hasTime()).toBe(true);
});
it('has a zero zone', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-08T10:00:00');
expect(mom.zone()).toBe(0);
});
it('formats without a zone part', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-08T10:00:00');
expect(mom.format()).toBe('2014-06-08T10:00:00');
});
it('formats via toISOString without a zone part', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-08T10:00:00');
expect(mom.toISOString()).toBe('2014-06-08T10:00:00');
});
it('is correctly cloned', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-08T10:00:00');
var clone = mom.clone();
expect(clone.hasZone()).toBe(false);
expect(clone.format()).toBe('2014-06-08T10:00:00');
expect(clone).not.toBe(mom);
clone.add(1, 'months');
expect(+clone).not.toBe(+mom);
});
it('can be given a zone via utc', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-08T10:00:00');
expect(mom.hasTime()).toBe(true);
expect(mom.hasZone()).toBe(false);
expect(mom.zone()).toBe(0);
mom.utc();
expect(mom.hasTime()).toBe(true);
expect(mom.hasZone()).toBe(true);
expect(mom.zone()).toBe(0);
});
it('can be given a zone via local', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-08T10:00:00');
var equivDate = new Date(Date.UTC(2014, 5, 8, 10, 0, 0));
expect(mom.toArray()).toEqual([ 2014, 5, 8, 10, 0, 0, 0 ]);
expect(mom.hasTime()).toBe(true);
expect(mom.hasZone()).toBe(false);
expect(mom.zone()).toBe(0);
mom.local();
expect(mom.toArray()).toEqual([ 2014, 5, 8, 10, 0, 0, 0 ]);
expect(mom.hasTime()).toBe(true);
expect(mom.hasZone()).toBe(true);
expect(mom.zone()).toBe(equivDate.getTimezoneOffset());
});
it('can be given a zone via zone', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-08T10:00:00');
expect(mom.hasTime()).toBe(true);
expect(mom.hasZone()).toBe(false);
expect(mom.zone()).toBe(0);
mom.zone(-420);
expect(mom.hasTime()).toBe(true);
expect(mom.hasZone()).toBe(true);
expect(mom.zone()).toBe(-420);
});
});
describe('ambiguously-timed moment', function() {
it('has a false hasTime', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-08');
expect(mom.hasTime()).toBe(false);
});
it('has a false hasZone', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-08');
expect(mom.hasZone()).toBe(false);
});
it('has a zero time', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-08');
var time = mom.time();
expect(+time).toBe(0);
});
it('formats without a zone part', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-08');
expect(mom.format()).toBe('2014-06-08');
});
it('formats via toISOString without a time part', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-08');
expect(mom.toISOString()).toBe('2014-06-08');
});
it('is correctly cloned', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-08');
var clone = mom.clone();
expect(clone.hasTime()).toBe(false);
expect(clone.format()).toBe('2014-06-08');
expect(clone).not.toBe(mom);
clone.add(1, 'months');
expect(+clone).not.toBe(+mom);
});
it('can be given a time', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-08');
expect(mom.hasTime()).toBe(false);
var time = moment.duration({ hours: 1, minutes: 25 });
mom.time(time);
expect(mom.hasTime()).toBe(true);
expect(+mom.time()).toBe(+time);
});
it('can be given a time and zone via utc', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-08');
expect(mom.hasTime()).toBe(false);
expect(mom.hasZone()).toBe(false);
expect(mom.zone()).toBe(0);
mom.utc();
expect(mom.hasTime()).toBe(true);
expect(mom.hasZone()).toBe(true);
expect(mom.zone()).toBe(0);
});
it('can be given a time and zone via local', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-08');
var equivDate = new Date(2014, 5, 8, 10, 0, 0);
expect(mom.toArray()).toEqual([ 2014, 5, 8, 0, 0, 0, 0 ]);
expect(mom.hasTime()).toBe(false);
expect(mom.hasZone()).toBe(false);
expect(mom.zone()).toBe(0);
mom.local();
expect(mom.toArray()).toEqual([ 2014, 5, 8, 0, 0, 0, 0 ]);
expect(mom.hasTime()).toBe(true);
expect(mom.hasZone()).toBe(true);
expect(mom.zone()).toBe(equivDate.getTimezoneOffset());
});
it('can be given a time and zone via zone', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-08');
expect(mom.hasTime()).toBe(false);
expect(mom.hasZone()).toBe(false);
expect(mom.zone()).toBe(0);
mom.zone(-420);
expect(mom.hasTime()).toBe(true);
expect(mom.hasZone()).toBe(true);
expect(mom.zone()).toBe(-420);
});
});
describe('unambiguous moment', function() {
it('can be made ambiguously-zoned via stripZone', function() {
var mom = $.fullCalendar.moment.utc('2014-06-08T10:00:00-0000');
expect(mom.hasZone()).toBe(true);
expect(mom.hasTime()).toBe(true);
mom.stripZone();
expect(mom.format()).toBe('2014-06-08T10:00:00');
expect(mom.hasZone()).toBe(false);
expect(mom.hasTime()).toBe(true);
});
it('can be made ambigously-timed via stripTime', function() {
var mom = $.fullCalendar.moment.utc('2014-06-08T10:00:00-0000');
expect(mom.hasTime()).toBe(true);
expect(mom.hasZone()).toBe(true);
mom.stripTime();
expect(mom.format()).toBe('2014-06-08');
expect(mom.hasTime()).toBe(false);
expect(mom.hasZone()).toBe(false);
});
});