moment-query.js
7.43 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
(function() {
var momentTypeSuffixes = {
'ambiguously-timed': '',
'ambiguously-zoned': 'T00:30:00',
timed: 'T00:30:00-0500'
};
describe('isSame', function() {
describe('when no units provided', function() {
it('returns false when the dates are different', function() {
var m1 = $.fullCalendar.moment.parseZone('2014-08-25T06:00:00');
var m2 = $.fullCalendar.moment.parseZone('2014-08-25T07:00:00');
expect(m1.isSame(m2)).toBe(false);
});
it('returns false when the dates are the same, but different zone-ambiguation', function() {
var m1 = $.fullCalendar.moment.parseZone('2014-08-25T06:00:00');
var m2 = $.fullCalendar.moment.parseZone('2014-08-25T06:00:00+00:00');
expect(m1.isSame(m2)).toBe(false);
});
it('returns false when the dates are the same, but different hasTime', function() {
var m1 = $.fullCalendar.moment.parseZone('2014-08-25');
var m2 = $.fullCalendar.moment.parseZone('2014-08-25T06:00:00');
expect(m1.isSame(m2)).toBe(false);
});
it('returns true when the dates are exactly the same', function() {
var m1 = $.fullCalendar.moment.parseZone('2014-08-25');
var m2 = $.fullCalendar.moment.parseZone('2014-08-25');
expect(m1.isSame(m2)).toBe(true);
m1 = $.fullCalendar.moment.parseZone('2014-08-25T06:00:00');
m2 = $.fullCalendar.moment.parseZone('2014-08-25T06:00:00');
expect(m1.isSame(m2)).toBe(true);
m1 = $.fullCalendar.moment.parseZone('2014-08-25T06:00:00+05:00');
m2 = $.fullCalendar.moment.parseZone('2014-08-25T06:00:00+05:00');
expect(m1.isSame(m2)).toBe(true);
});
describe('when called on a native moment', function() {
it('returns true when the dates are the same, but different zone-ambiguation', function() {
var m1 = moment.parseZone('2014-08-25T06:00:00+00:00');
var m2 = $.fullCalendar.moment.parseZone('2014-08-25T06:00:00');
expect(m1.isSame(m2)).toBe(true);
});
});
});
describe('when units are provided', function() {
it('returns true when dates are the same day but different zone-ambiguation', function() {
var m1 = $.fullCalendar.moment.parseZone('2014-08-25T06:00:00');
var m2 = $.fullCalendar.moment.parseZone('2014-08-25T06:00:00-11:00');
expect(m1.isSame(m2, 'day')).toBe(true);
});
it('returns true when dates are the same day but different hasTime', function() {
var m1 = $.fullCalendar.moment.parseZone('2014-08-25');
var m2 = $.fullCalendar.moment.parseZone('2014-08-25T06:00:00-11:00');
expect(m1.isSame(m2, 'day')).toBe(true);
});
it('returns false when dates are a different day', function() {
var m1 = $.fullCalendar.moment.parseZone('2014-08-24T00:00:00');
var m2 = $.fullCalendar.moment.parseZone('2014-08-25T06:00:00');
expect(m1.isSame(m2, 'day')).toBe(false);
});
});
});
describe('isWithin', function() {
$.each(momentTypeSuffixes, function(thisType, thisSuffix) {
describe('when the moment is ' + thisType, function() {
$.each(momentTypeSuffixes, function(otherType, otherSuffix) {
describe('and other moments are ' + otherType, function() {
it('is clearly within', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-15' + thisSuffix);
var other1 = $.fullCalendar.moment.parseZone('2014-06-01' + otherSuffix);
var other2 = $.fullCalendar.moment.parseZone('2014-07-01' + otherSuffix);
var res = mom.isWithin(other1, other2);
expect(res).toBe(true);
});
it('is clearly not within', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-15' + thisSuffix);
var other1 = $.fullCalendar.moment.parseZone('2014-09-01' + otherSuffix);
var other2 = $.fullCalendar.moment.parseZone('2014-10-01' + otherSuffix);
var res = mom.isWithin(other1, other2);
expect(res).toBe(false);
});
it('is within when equal to start', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-15' + thisSuffix);
var other1 = $.fullCalendar.moment.parseZone('2014-06-15' + otherSuffix);
var other2 = $.fullCalendar.moment.parseZone('2014-07-01' + otherSuffix);
var res = mom.isWithin(other1, other2);
expect(res).toBe(true);
});
it('is not within when equal to end', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-15' + thisSuffix);
var other1 = $.fullCalendar.moment.parseZone('2014-06-01' + otherSuffix);
var other2 = $.fullCalendar.moment.parseZone('2014-06-15' + otherSuffix);
var res = mom.isWithin(other1, other2);
expect(res).toBe(false);
});
});
});
});
});
});
describe('isBefore', function() {
$.each(momentTypeSuffixes, function(thisType, thisSuffix) {
describe('when the moment is ' + thisType, function() {
$.each(momentTypeSuffixes, function(otherType, otherSuffix) {
describe('and other moment is ' + otherType, function() {
it('is clearly before', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-15' + thisSuffix);
var other = $.fullCalendar.moment.parseZone('2015-01-01' + otherSuffix);
var res = mom.isBefore(other);
expect(res).toBe(true);
});
it('is clearly not before', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-15' + thisSuffix);
var other = $.fullCalendar.moment.parseZone('2013-01-01' + otherSuffix);
var res = mom.isBefore(other);
expect(res).toBe(false);
});
it('is equal', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-15' + thisSuffix);
var other = $.fullCalendar.moment.parseZone('2014-06-15' + otherSuffix);
var res = mom.isBefore(other);
expect(res).toBe(false);
});
});
});
});
});
});
describe('isAfter', function() {
$.each(momentTypeSuffixes, function(thisType, thisSuffix) {
describe('when the moment is ' + thisType, function() {
$.each(momentTypeSuffixes, function(otherType, otherSuffix) {
describe('and other moment is ' + otherType, function() {
it('is clearly after', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-15' + thisSuffix);
var other = $.fullCalendar.moment.parseZone('2013-01-01' + otherSuffix);
var res = mom.isAfter(other);
expect(res).toBe(true);
});
it('is clearly not after', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-15' + thisSuffix);
var other = $.fullCalendar.moment.parseZone('2015-01-01' + otherSuffix);
var res = mom.isAfter(other);
expect(res).toBe(false);
});
it('is equal', function() {
var mom = $.fullCalendar.moment.parseZone('2014-06-15' + thisSuffix);
var other = $.fullCalendar.moment.parseZone('2014-06-15' + otherSuffix);
var res = mom.isAfter(other);
expect(res).toBe(false);
});
});
});
});
});
it('returns false when on same ambiguous day', function() {
var mom = $.fullCalendar.moment.parseZone('2014-11-11T12:00:00+00:00');
var other = $.fullCalendar.moment.parseZone('2014-11-11');
var res = mom.isAfter(other);
expect(res).toBe(false);
});
describe('when called on a native moment', function() {
it('returns true, even when an ambiguous day would make it false', function() {
var mom = moment.parseZone('2014-11-11T12:00:00+00:00');
var other = $.fullCalendar.moment.parseZone('2014-11-11');
var res = mom.isAfter(other);
expect(res).toBe(true);
});
});
});
})();