]> git.ipfire.org Git - thirdparty/moment.git/blame - min/tests.js
Build 2.24.0
[thirdparty/moment.git] / min / tests.js
CommitLineData
516f5f67 1
c74a101d
IC
2;(function (global, factory) {
3 typeof exports === 'object' && typeof module !== 'undefined'
4 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
5 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
6 factory(global.moment)
73f3c911 7}(this, (function (moment) { 'use strict';
516f5f67 8
db71a655
KM
9 function each(array, callback) {
10 var i;
11 for (i = 0; i < array.length; i++) {
12 callback(array[i], i, array);
13 }
b135bf1a
IC
14 }
15
c58511b9
KM
16 function setupDeprecationHandler(test, moment$$1, scope) {
17 test._expectedDeprecations = null;
18 test._observedDeprecations = null;
19 test._oldSupress = moment$$1.suppressDeprecationWarnings;
20 moment$$1.suppressDeprecationWarnings = true;
21 test.expectedDeprecations = function () {
22 test._expectedDeprecations = arguments;
23 test._observedDeprecations = [];
24 };
25 moment$$1.deprecationHandler = function (name, msg) {
26 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
27 if (deprecationId === -1) {
28 throw new Error('Unexpected deprecation thrown name=' +
29 name + ' msg=' + msg);
30 }
31 test._observedDeprecations[deprecationId] = 1;
32 };
33 }
34
35 function teardownDeprecationHandler(test, moment$$1, scope) {
36 moment$$1.suppressDeprecationWarnings = test._oldSupress;
37
38 if (test._expectedDeprecations != null) {
39 var missedDeprecations = [];
40 each(test._expectedDeprecations, function (deprecationPattern, id) {
41 if (test._observedDeprecations[id] !== 1) {
42 missedDeprecations.push(deprecationPattern);
43 }
44 });
45 if (missedDeprecations.length !== 0) {
46 throw new Error('Expected deprecation warnings did not happen: ' +
47 missedDeprecations.join(' '));
48 }
49 }
50 }
51
52 function matchedDeprecation(name, msg, deprecations) {
53 if (deprecations == null) {
54 return -1;
55 }
56 for (var i = 0; i < deprecations.length; ++i) {
57 if (name != null && name === deprecations[i]) {
58 return i;
59 }
60 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
61 return i;
62 }
63 }
64 return -1;
65 }
66
67 /*global QUnit:false*/
68
69 var test = QUnit.test;
70
db71a655
KM
71 function objectKeys(obj) {
72 if (Object.keys) {
73 return Object.keys(obj);
74 } else {
75 // IE8
76 var res = [], i;
77 for (i in obj) {
78 if (obj.hasOwnProperty(i)) {
79 res.push(i);
80 }
b135bf1a 81 }
db71a655 82 return res;
b135bf1a 83 }
b135bf1a
IC
84 }
85
db71a655 86 // Pick the first defined of two or three arguments.
b135bf1a 87
db71a655
KM
88 function defineCommonLocaleTests(locale, options) {
89 test('lenient day of month ordinal parsing', function (assert) {
90 var i, ordinalStr, testMoment;
91 for (i = 1; i <= 31; ++i) {
92 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
93 testMoment = moment(ordinalStr, 'YYYY MM Do');
94 assert.equal(testMoment.year(), 2014,
95 'lenient day of month ordinal parsing ' + i + ' year check');
96 assert.equal(testMoment.month(), 0,
97 'lenient day of month ordinal parsing ' + i + ' month check');
98 assert.equal(testMoment.date(), i,
99 'lenient day of month ordinal parsing ' + i + ' date check');
100 }
101 });
b135bf1a 102
db71a655
KM
103 test('lenient day of month ordinal parsing of number', function (assert) {
104 var i, testMoment;
105 for (i = 1; i <= 31; ++i) {
106 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
107 assert.equal(testMoment.year(), 2014,
108 'lenient day of month ordinal parsing of number ' + i + ' year check');
109 assert.equal(testMoment.month(), 0,
110 'lenient day of month ordinal parsing of number ' + i + ' month check');
111 assert.equal(testMoment.date(), i,
112 'lenient day of month ordinal parsing of number ' + i + ' date check');
113 }
114 });
b135bf1a 115
db71a655
KM
116 test('strict day of month ordinal parsing', function (assert) {
117 var i, ordinalStr, testMoment;
118 for (i = 1; i <= 31; ++i) {
119 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
120 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
121 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
122 }
123 });
b135bf1a 124
db71a655
KM
125 test('meridiem invariant', function (assert) {
126 var h, m, t1, t2;
127 for (h = 0; h < 24; ++h) {
128 for (m = 0; m < 60; m += 15) {
129 t1 = moment.utc([2000, 0, 1, h, m]);
130 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
131 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
132 'meridiem at ' + t1.format('HH:mm'));
133 }
134 }
135 });
136
137 test('date format correctness', function (assert) {
138 var data, tokens;
139 data = moment.localeData()._longDateFormat;
140 tokens = objectKeys(data);
141 each(tokens, function (srchToken) {
142 // Check each format string to make sure it does not contain any
143 // tokens that need to be expanded.
144 each(tokens, function (baseToken) {
145 // strip escaped sequences
146 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
147 assert.equal(false, !!~format.indexOf(srchToken),
148 'contains ' + srchToken + ' in ' + baseToken);
149 });
b135bf1a
IC
150 });
151 });
d6651c21 152
db71a655
KM
153 test('month parsing correctness', function (assert) {
154 var i, m;
155
156 if (locale === 'tr') {
157 // I can't fix it :(
c58511b9 158 assert.expect(0);
db71a655
KM
159 return;
160 }
161 function tester(format) {
162 var r;
163 r = moment(m.format(format), format);
164 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
165 if (locale !== 'ka') {
166 r = moment(m.format(format).toLocaleUpperCase(), format);
167 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
168 }
db71a655
KM
169 r = moment(m.format(format).toLocaleLowerCase(), format);
170 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
171
172 r = moment(m.format(format), format, true);
173 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
174 if (locale !== 'ka') {
175 r = moment(m.format(format).toLocaleUpperCase(), format, true);
176 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
177 }
db71a655
KM
178 r = moment(m.format(format).toLocaleLowerCase(), format, true);
179 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
180 }
181
182 for (i = 0; i < 12; ++i) {
183 m = moment([2015, i, 15, 18]);
184 tester('MMM');
185 tester('MMM.');
186 tester('MMMM');
187 tester('MMMM.');
188 }
189 });
d6651c21 190
db71a655
KM
191 test('weekday parsing correctness', function (assert) {
192 var i, m;
193
96d0d679 194 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
195 // tr, az: There is a lower-case letter (ı), that converted to
196 // upper then lower changes to i
197 // ro: there is the letter ț which behaves weird under IE8
198 // mt: letter Ħ
96d0d679 199 // ga: month with spaces
c58511b9 200 assert.expect(0);
db71a655
KM
201 return;
202 }
203 function tester(format) {
204 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
205 r = moment(m.format(format), format);
206 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
207 if (locale !== 'ka') {
208 r = moment(m.format(format).toLocaleUpperCase(), format);
209 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
210 }
db71a655
KM
211 r = moment(m.format(format).toLocaleLowerCase(), format);
212 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
213 r = moment(m.format(format), format, true);
214 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
215 if (locale !== 'ka') {
216 r = moment(m.format(format).toLocaleUpperCase(), format, true);
217 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
218 }
db71a655
KM
219 r = moment(m.format(format).toLocaleLowerCase(), format, true);
220 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
221 }
222
223 for (i = 0; i < 7; ++i) {
224 m = moment.utc([2015, 0, i + 1, 18]);
225 tester('dd');
226 tester('ddd');
227 tester('dddd');
228 }
229 });
d6651c21 230
db71a655
KM
231 test('valid localeData', function (assert) {
232 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
233 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
234 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
235 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
236 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
237 });
96d0d679
KM
238
239 test('localeData weekdays can localeSort', function (assert) {
240 var weekdays = moment().localeData().weekdays();
241 var weekdaysShort = moment().localeData().weekdaysShort();
242 var weekdaysMin = moment().localeData().weekdaysMin();
243 var shift = moment().localeData()._week.dow;
244 assert.deepEqual(
245 moment().localeData().weekdays(true),
246 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
247 'weekdays should localeSort');
248 assert.deepEqual(
249 moment().localeData().weekdaysShort(true),
250 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
251 'weekdaysShort should localeSort');
252 assert.deepEqual(
253 moment().localeData().weekdaysMin(true),
254 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
255 'weekdaysMin should localeSort');
256 });
db71a655 257 }
d6651c21 258
db71a655
KM
259 /*global QUnit:false*/
260
db71a655
KM
261 function localeModule (name, lifecycle) {
262 QUnit.module('locale:' + name, {
c58511b9 263 beforeEach : function () {
db71a655
KM
264 moment.locale(name);
265 moment.createFromInputFallback = function (config) {
266 throw new Error('input not handled by moment: ' + config._i);
267 };
268 setupDeprecationHandler(test, moment, 'locale');
269 if (lifecycle && lifecycle.setup) {
270 lifecycle.setup();
271 }
272 },
c58511b9 273 afterEach : function () {
db71a655
KM
274 moment.locale('en');
275 teardownDeprecationHandler(test, moment, 'locale');
276 if (lifecycle && lifecycle.teardown) {
277 lifecycle.teardown();
278 }
516f5f67
IC
279 }
280 });
db71a655
KM
281 defineCommonLocaleTests(name, -1, -1);
282 }
283
284 localeModule('af');
285
286 test('parse', function (assert) {
287 var tests = 'Januarie Jan_Februarie Feb_Maart Mrt_April Apr_Mei Mei_Junie Jun_Julie Jul_Augustus Aug_September Sep_Oktober Okt_November Nov_Desember Des'.split('_'), i;
288 function equalTest(input, mmm, i) {
289 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
290 }
291 for (i = 0; i < 12; i++) {
292 tests[i] = tests[i].split(' ');
293 equalTest(tests[i][0], 'MMM', i);
294 equalTest(tests[i][1], 'MMM', i);
295 equalTest(tests[i][0], 'MMMM', i);
296 equalTest(tests[i][1], 'MMMM', i);
297 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
298 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
299 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
300 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
301 }
302 });
303
304 test('format', function (assert) {
305 var a = [
306 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Sondag, Februarie 14de 2010, 3:25:50 nm'],
307 ['ddd, hA', 'Son, 3NM'],
308 ['M Mo MM MMMM MMM', '2 2de 02 Februarie Feb'],
309 ['YYYY YY', '2010 10'],
310 ['D Do DD', '14 14de 14'],
311 ['d do dddd ddd dd', '0 0de Sondag Son So'],
312 ['DDD DDDo DDDD', '45 45ste 045'],
313 ['w wo ww', '6 6de 06'],
314 ['h hh', '3 03'],
315 ['H HH', '15 15'],
316 ['m mm', '25 25'],
317 ['s ss', '50 50'],
318 ['a A', 'nm NM'],
319 ['[the] DDDo [day of the year]', 'the 45ste day of the year'],
320 ['LT', '15:25'],
321 ['LTS', '15:25:50'],
322 ['L', '14/02/2010'],
323 ['LL', '14 Februarie 2010'],
324 ['LLL', '14 Februarie 2010 15:25'],
325 ['LLLL', 'Sondag, 14 Februarie 2010 15:25'],
326 ['l', '14/2/2010'],
327 ['ll', '14 Feb 2010'],
328 ['lll', '14 Feb 2010 15:25'],
329 ['llll', 'Son, 14 Feb 2010 15:25']
330 ],
331 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
332 i;
333 for (i = 0; i < a.length; i++) {
334 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
335 }
336 });
337
338 test('format ordinal', function (assert) {
339 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1ste', '1ste');
340 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2de', '2de');
341 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3de', '3de');
342 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4de', '4de');
343 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5de', '5de');
344 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6de', '6de');
345 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7de', '7de');
346 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8ste', '8ste');
347 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9de', '9de');
348 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10de', '10de');
349
350 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11de', '11de');
351 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12de', '12de');
352 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13de', '13de');
353 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14de', '14de');
354 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15de', '15de');
355 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16de', '16de');
356 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17de', '17de');
357 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18de', '18de');
358 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19de', '19de');
359 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20ste', '20ste');
360
361 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21ste', '21ste');
362 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22ste', '22ste');
363 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23ste', '23ste');
364 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24ste', '24ste');
365 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25ste', '25ste');
366 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26ste', '26ste');
367 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27ste', '27ste');
368 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28ste', '28ste');
369 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29ste', '29ste');
370 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30ste', '30ste');
371
372 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31ste', '31ste');
373 });
374
375 test('format month', function (assert) {
376 var expected = 'Januarie Jan_Februarie Feb_Maart Mrt_April Apr_Mei Mei_Junie Jun_Julie Jul_Augustus Aug_September Sep_Oktober Okt_November Nov_Desember Des'.split('_'), i;
377 for (i = 0; i < expected.length; i++) {
378 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
379 }
380 });
381
382 test('format week', function (assert) {
383 var expected = 'Sondag Son So_Maandag Maa Ma_Dinsdag Din Di_Woensdag Woe Wo_Donderdag Don Do_Vrydag Vry Vr_Saterdag Sat Sa'.split('_'), i;
384 for (i = 0; i < expected.length; i++) {
385 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
386 }
387 });
388
389 test('from', function (assert) {
390 var start = moment([2007, 1, 28]);
391 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), '\'n paar sekondes', '44 seconds = a few seconds');
392 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '\'n minuut', '45 seconds = a minute');
393 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '\'n minuut', '89 seconds = a minute');
394 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minute', '90 seconds = 2 minutes');
395 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minute', '44 minutes = 44 minutes');
396 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '\'n uur', '45 minutes = an hour');
397 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '\'n uur', '89 minutes = an hour');
398 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ure', '90 minutes = 2 hours');
399 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ure', '5 hours = 5 hours');
400 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ure', '21 hours = 21 hours');
401 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '\'n dag', '22 hours = a day');
402 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '\'n dag', '35 hours = a day');
403 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dae', '36 hours = 2 days');
404 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '\'n dag', '1 day = a day');
405 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dae', '5 days = 5 days');
406 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dae', '25 days = 25 days');
407 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '\'n maand', '26 days = a month');
408 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '\'n maand', '30 days = a month');
409 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '\'n maand', '43 days = a month');
410 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 maande', '46 days = 2 months');
411 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 maande', '75 days = 2 months');
412 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 maande', '76 days = 3 months');
413 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '\'n maand', '1 month = a month');
414 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 maande', '5 months = 5 months');
415 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '\'n jaar', '345 days = a year');
416 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 jaar', '548 days = 2 years');
417 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '\'n jaar', '1 year = a year');
418 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 jaar', '5 years = 5 years');
419 });
420
421 test('suffix', function (assert) {
422 assert.equal(moment(30000).from(0), 'oor \'n paar sekondes', 'prefix');
423 assert.equal(moment(0).from(30000), '\'n paar sekondes gelede', 'suffix');
424 });
425
426 test('now from now', function (assert) {
427 assert.equal(moment().fromNow(), '\'n paar sekondes gelede', 'now from now should display as in the past');
428 });
429
430 test('fromNow', function (assert) {
431 assert.equal(moment().add({s: 30}).fromNow(), 'oor \'n paar sekondes', 'in a few seconds');
432 assert.equal(moment().add({d: 5}).fromNow(), 'oor 5 dae', 'in 5 days');
433 });
434
435 test('calendar day', function (assert) {
436 var a = moment().hours(12).minutes(0).seconds(0);
437
438 assert.equal(moment(a).calendar(), 'Vandag om 12:00', 'today at the same time');
439 assert.equal(moment(a).add({m: 25}).calendar(), 'Vandag om 12:25', 'Now plus 25 min');
440 assert.equal(moment(a).add({h: 1}).calendar(), 'Vandag om 13:00', 'Now plus 1 hour');
441 assert.equal(moment(a).add({d: 1}).calendar(), 'Môre om 12:00', 'tomorrow at the same time');
442 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Vandag om 11:00', 'Now minus 1 hour');
443 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Gister om 12:00', 'yesterday at the same time');
444 });
445
446 test('calendar next week', function (assert) {
447 var i, m;
448 for (i = 2; i < 7; i++) {
449 m = moment().add({d: i});
450 assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days current time');
451 m.hours(0).minutes(0).seconds(0).milliseconds(0);
452 assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days beginning of day');
453 m.hours(23).minutes(59).seconds(59).milliseconds(999);
454 assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days end of day');
73f3c911 455 }
db71a655 456 });
516f5f67 457
db71a655
KM
458 test('calendar last week', function (assert) {
459 var i, m;
460 for (i = 2; i < 7; i++) {
461 m = moment().subtract({d: i});
462 assert.equal(m.calendar(), m.format('[Laas] dddd [om] LT'), 'Today - ' + i + ' days current time');
463 m.hours(0).minutes(0).seconds(0).milliseconds(0);
464 assert.equal(m.calendar(), m.format('[Laas] dddd [om] LT'), 'Today - ' + i + ' days beginning of day');
465 m.hours(23).minutes(59).seconds(59).milliseconds(999);
466 assert.equal(m.calendar(), m.format('[Laas] dddd [om] LT'), 'Today - ' + i + ' days end of day');
516f5f67 467 }
db71a655 468 });
516f5f67 469
db71a655
KM
470 test('calendar all else', function (assert) {
471 var weeksAgo = moment().subtract({w: 1}),
472 weeksFromNow = moment().add({w: 1});
516f5f67 473
db71a655
KM
474 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
475 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 476
db71a655
KM
477 weeksAgo = moment().subtract({w: 2});
478 weeksFromNow = moment().add({w: 2});
516f5f67 479
db71a655
KM
480 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
481 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
482 });
483
484 test('weeks year starting sunday formatted', function (assert) {
485 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52ste', 'Jan 1 2012 should be week 52');
486 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1ste', 'Jan 2 2012 should be week 1');
487 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1ste', 'Jan 8 2012 should be week 1');
488 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2de', 'Jan 9 2012 should be week 2');
489 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2de', 'Jan 15 2012 should be week 2');
490 });
73f3c911
IC
491
492})));
493
516f5f67 494
c74a101d
IC
495;(function (global, factory) {
496 typeof exports === 'object' && typeof module !== 'undefined'
497 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
498 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
499 factory(global.moment)
73f3c911 500}(this, (function (moment) { 'use strict';
516f5f67 501
db71a655
KM
502 function each(array, callback) {
503 var i;
504 for (i = 0; i < array.length; i++) {
505 callback(array[i], i, array);
506 }
b135bf1a
IC
507 }
508
c58511b9
KM
509 function setupDeprecationHandler(test, moment$$1, scope) {
510 test._expectedDeprecations = null;
511 test._observedDeprecations = null;
512 test._oldSupress = moment$$1.suppressDeprecationWarnings;
513 moment$$1.suppressDeprecationWarnings = true;
514 test.expectedDeprecations = function () {
515 test._expectedDeprecations = arguments;
516 test._observedDeprecations = [];
517 };
518 moment$$1.deprecationHandler = function (name, msg) {
519 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
520 if (deprecationId === -1) {
521 throw new Error('Unexpected deprecation thrown name=' +
522 name + ' msg=' + msg);
523 }
524 test._observedDeprecations[deprecationId] = 1;
525 };
526 }
527
528 function teardownDeprecationHandler(test, moment$$1, scope) {
529 moment$$1.suppressDeprecationWarnings = test._oldSupress;
530
531 if (test._expectedDeprecations != null) {
532 var missedDeprecations = [];
533 each(test._expectedDeprecations, function (deprecationPattern, id) {
534 if (test._observedDeprecations[id] !== 1) {
535 missedDeprecations.push(deprecationPattern);
536 }
537 });
538 if (missedDeprecations.length !== 0) {
539 throw new Error('Expected deprecation warnings did not happen: ' +
540 missedDeprecations.join(' '));
541 }
542 }
543 }
544
545 function matchedDeprecation(name, msg, deprecations) {
546 if (deprecations == null) {
547 return -1;
548 }
549 for (var i = 0; i < deprecations.length; ++i) {
550 if (name != null && name === deprecations[i]) {
551 return i;
552 }
553 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
554 return i;
555 }
556 }
557 return -1;
558 }
559
560 /*global QUnit:false*/
561
562 var test = QUnit.test;
563
db71a655
KM
564 function objectKeys(obj) {
565 if (Object.keys) {
566 return Object.keys(obj);
567 } else {
568 // IE8
569 var res = [], i;
570 for (i in obj) {
571 if (obj.hasOwnProperty(i)) {
572 res.push(i);
573 }
b135bf1a 574 }
db71a655 575 return res;
b135bf1a 576 }
b135bf1a
IC
577 }
578
db71a655 579 // Pick the first defined of two or three arguments.
b135bf1a 580
db71a655
KM
581 function defineCommonLocaleTests(locale, options) {
582 test('lenient day of month ordinal parsing', function (assert) {
583 var i, ordinalStr, testMoment;
584 for (i = 1; i <= 31; ++i) {
585 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
586 testMoment = moment(ordinalStr, 'YYYY MM Do');
587 assert.equal(testMoment.year(), 2014,
588 'lenient day of month ordinal parsing ' + i + ' year check');
589 assert.equal(testMoment.month(), 0,
590 'lenient day of month ordinal parsing ' + i + ' month check');
591 assert.equal(testMoment.date(), i,
592 'lenient day of month ordinal parsing ' + i + ' date check');
593 }
594 });
b135bf1a 595
db71a655
KM
596 test('lenient day of month ordinal parsing of number', function (assert) {
597 var i, testMoment;
598 for (i = 1; i <= 31; ++i) {
599 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
600 assert.equal(testMoment.year(), 2014,
601 'lenient day of month ordinal parsing of number ' + i + ' year check');
602 assert.equal(testMoment.month(), 0,
603 'lenient day of month ordinal parsing of number ' + i + ' month check');
604 assert.equal(testMoment.date(), i,
605 'lenient day of month ordinal parsing of number ' + i + ' date check');
606 }
607 });
b135bf1a 608
db71a655
KM
609 test('strict day of month ordinal parsing', function (assert) {
610 var i, ordinalStr, testMoment;
611 for (i = 1; i <= 31; ++i) {
612 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
613 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
614 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
615 }
616 });
b135bf1a 617
db71a655
KM
618 test('meridiem invariant', function (assert) {
619 var h, m, t1, t2;
620 for (h = 0; h < 24; ++h) {
621 for (m = 0; m < 60; m += 15) {
622 t1 = moment.utc([2000, 0, 1, h, m]);
623 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
624 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
625 'meridiem at ' + t1.format('HH:mm'));
626 }
627 }
628 });
629
630 test('date format correctness', function (assert) {
631 var data, tokens;
632 data = moment.localeData()._longDateFormat;
633 tokens = objectKeys(data);
634 each(tokens, function (srchToken) {
635 // Check each format string to make sure it does not contain any
636 // tokens that need to be expanded.
637 each(tokens, function (baseToken) {
638 // strip escaped sequences
639 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
640 assert.equal(false, !!~format.indexOf(srchToken),
641 'contains ' + srchToken + ' in ' + baseToken);
642 });
b135bf1a
IC
643 });
644 });
d6651c21 645
db71a655
KM
646 test('month parsing correctness', function (assert) {
647 var i, m;
648
649 if (locale === 'tr') {
650 // I can't fix it :(
c58511b9 651 assert.expect(0);
db71a655
KM
652 return;
653 }
654 function tester(format) {
655 var r;
656 r = moment(m.format(format), format);
657 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
658 if (locale !== 'ka') {
659 r = moment(m.format(format).toLocaleUpperCase(), format);
660 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
661 }
db71a655
KM
662 r = moment(m.format(format).toLocaleLowerCase(), format);
663 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
664
665 r = moment(m.format(format), format, true);
666 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
667 if (locale !== 'ka') {
668 r = moment(m.format(format).toLocaleUpperCase(), format, true);
669 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
670 }
db71a655
KM
671 r = moment(m.format(format).toLocaleLowerCase(), format, true);
672 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
673 }
674
675 for (i = 0; i < 12; ++i) {
676 m = moment([2015, i, 15, 18]);
677 tester('MMM');
678 tester('MMM.');
679 tester('MMMM');
680 tester('MMMM.');
681 }
682 });
d6651c21 683
db71a655
KM
684 test('weekday parsing correctness', function (assert) {
685 var i, m;
686
96d0d679 687 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
688 // tr, az: There is a lower-case letter (ı), that converted to
689 // upper then lower changes to i
690 // ro: there is the letter ț which behaves weird under IE8
691 // mt: letter Ħ
96d0d679 692 // ga: month with spaces
c58511b9 693 assert.expect(0);
db71a655
KM
694 return;
695 }
696 function tester(format) {
697 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
698 r = moment(m.format(format), format);
699 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
700 if (locale !== 'ka') {
701 r = moment(m.format(format).toLocaleUpperCase(), format);
702 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
703 }
db71a655
KM
704 r = moment(m.format(format).toLocaleLowerCase(), format);
705 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
706 r = moment(m.format(format), format, true);
707 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
708 if (locale !== 'ka') {
709 r = moment(m.format(format).toLocaleUpperCase(), format, true);
710 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
711 }
db71a655
KM
712 r = moment(m.format(format).toLocaleLowerCase(), format, true);
713 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
714 }
715
716 for (i = 0; i < 7; ++i) {
717 m = moment.utc([2015, 0, i + 1, 18]);
718 tester('dd');
719 tester('ddd');
720 tester('dddd');
721 }
722 });
d6651c21 723
db71a655
KM
724 test('valid localeData', function (assert) {
725 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
726 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
727 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
728 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
729 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
730 });
96d0d679
KM
731
732 test('localeData weekdays can localeSort', function (assert) {
733 var weekdays = moment().localeData().weekdays();
734 var weekdaysShort = moment().localeData().weekdaysShort();
735 var weekdaysMin = moment().localeData().weekdaysMin();
736 var shift = moment().localeData()._week.dow;
737 assert.deepEqual(
738 moment().localeData().weekdays(true),
739 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
740 'weekdays should localeSort');
741 assert.deepEqual(
742 moment().localeData().weekdaysShort(true),
743 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
744 'weekdaysShort should localeSort');
745 assert.deepEqual(
746 moment().localeData().weekdaysMin(true),
747 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
748 'weekdaysMin should localeSort');
749 });
db71a655 750 }
d6651c21 751
db71a655 752 /*global QUnit:false*/
516f5f67 753
db71a655
KM
754 function localeModule (name, lifecycle) {
755 QUnit.module('locale:' + name, {
c58511b9 756 beforeEach : function () {
db71a655
KM
757 moment.locale(name);
758 moment.createFromInputFallback = function (config) {
759 throw new Error('input not handled by moment: ' + config._i);
760 };
761 setupDeprecationHandler(test, moment, 'locale');
762 if (lifecycle && lifecycle.setup) {
763 lifecycle.setup();
764 }
765 },
c58511b9 766 afterEach : function () {
db71a655
KM
767 moment.locale('en');
768 teardownDeprecationHandler(test, moment, 'locale');
769 if (lifecycle && lifecycle.teardown) {
770 lifecycle.teardown();
771 }
516f5f67
IC
772 }
773 });
db71a655
KM
774 defineCommonLocaleTests(name, -1, -1);
775 }
776
777 localeModule('ar-dz');
778
779 test('parse', function (assert) {
780 var tests = 'جانفي:جانفي_فيفري:فيفري_مارس:مارس_أفريل:أفريل_ماي:ماي_جوان:جوان_جويلية:جويلية_أوت:أوت_سبتمبر:سبتمبر_أكتوبر:أكتوبر_نوفمبر:نوفمبر_ديسمبر:ديسمبر'.split('_'), i;
781 function equalTest(input, mmm, i) {
782 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
783 }
784 for (i = 0; i < 12; i++) {
785 tests[i] = tests[i].split(':');
786 equalTest(tests[i][0], 'MMM', i);
787 equalTest(tests[i][1], 'MMM', i);
788 equalTest(tests[i][0], 'MMMM', i);
789 equalTest(tests[i][1], 'MMMM', i);
790 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
791 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
792 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
793 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
794 }
795 });
796
797 test('format', function (assert) {
798 var a = [
799 ['dddd, MMMM Do YYYY, h:mm:ss a', 'الأحد, فيفري 14 2010, 3:25:50 pm'],
800 ['ddd, hA', 'احد, 3PM'],
801 ['M Mo MM MMMM MMM', '2 2 02 فيفري فيفري'],
802 ['YYYY YY', '2010 10'],
803 ['D Do DD', '14 14 14'],
804 ['d do dddd ddd dd', '0 0 الأحد احد أح'],
805 ['DDD DDDo DDDD', '45 45 045'],
806 ['w wo ww', '7 7 07'],
807 ['h hh', '3 03'],
808 ['H HH', '15 15'],
809 ['m mm', '25 25'],
810 ['s ss', '50 50'],
811 ['a A', 'pm PM'],
812 ['[the] DDDo [day of the year]', 'the 45 day of the year'],
813 ['LT', '15:25'],
814 ['LTS', '15:25:50'],
815 ['L', '14/02/2010'],
816 ['LL', '14 فيفري 2010'],
817 ['LLL', '14 فيفري 2010 15:25'],
818 ['LLLL', 'الأحد 14 فيفري 2010 15:25'],
819 ['l', '14/2/2010'],
820 ['ll', '14 فيفري 2010'],
821 ['lll', '14 فيفري 2010 15:25'],
822 ['llll', 'احد 14 فيفري 2010 15:25']
823 ],
824 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
825 i;
826 for (i = 0; i < a.length; i++) {
827 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
828 }
829 });
830
831 test('format ordinal', function (assert) {
832 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
833 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
834 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
835 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
836 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
837 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
838 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
839 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
840 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
841 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
842
843 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
844 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
845 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
846 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
847 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
848 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
849 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
850 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
851 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
852 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
853
854 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
855 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
856 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
857 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
858 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
859 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
860 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
861 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
862 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
863 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
864
865 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
866 });
867
868 test('format month', function (assert) {
869 var expected = 'جانفي جانفي_فيفري فيفري_مارس مارس_أفريل أفريل_ماي ماي_جوان جوان_جويلية جويلية_أوت أوت_سبتمبر سبتمبر_أكتوبر أكتوبر_نوفمبر نوفمبر_ديسمبر ديسمبر'.split('_'), i;
870 for (i = 0; i < expected.length; i++) {
871 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
872 }
873 });
874
875 test('format week', function (assert) {
876 var expected = 'الأحد احد أح_الإثنين اثنين إث_الثلاثاء ثلاثاء ثلا_الأربعاء اربعاء أر_الخميس خميس خم_الجمعة جمعة جم_السبت سبت سب'.split('_'), i;
877 for (i = 0; i < expected.length; i++) {
878 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
879 }
880 });
881
882 test('from', function (assert) {
883 var start = moment([2007, 1, 28]);
884 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ثوان', '44 seconds = a few seconds');
885 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'دقيقة', '45 seconds = a minute');
886 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'دقيقة', '89 seconds = a minute');
887 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 دقائق', '90 seconds = 2 minutes');
888 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 دقائق', '44 minutes = 44 minutes');
889 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ساعة', '45 minutes = an hour');
890 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ساعة', '89 minutes = an hour');
891 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ساعات', '90 minutes = 2 hours');
892 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ساعات', '5 hours = 5 hours');
893 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ساعات', '21 hours = 21 hours');
894 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'يوم', '22 hours = a day');
895 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'يوم', '35 hours = a day');
896 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 أيام', '36 hours = 2 days');
897 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'يوم', '1 day = a day');
898 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 أيام', '5 days = 5 days');
899 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 أيام', '25 days = 25 days');
900 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'شهر', '26 days = a month');
901 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'شهر', '30 days = a month');
902 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'شهر', '43 days = a month');
903 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 أشهر', '46 days = 2 months');
904 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 أشهر', '75 days = 2 months');
905 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 أشهر', '76 days = 3 months');
906 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'شهر', '1 month = a month');
907 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 أشهر', '5 months = 5 months');
908 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'سنة', '345 days = a year');
909 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 سنوات', '548 days = 2 years');
910 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'سنة', '1 year = a year');
911 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 سنوات', '5 years = 5 years');
912 });
913
914 test('suffix', function (assert) {
915 assert.equal(moment(30000).from(0), 'في ثوان', 'prefix');
916 assert.equal(moment(0).from(30000), 'منذ ثوان', 'suffix');
917 });
918
919 test('now from now', function (assert) {
920 assert.equal(moment().fromNow(), 'منذ ثوان', 'now from now should display as in the past');
921 });
922
923 test('fromNow', function (assert) {
924 assert.equal(moment().add({s: 30}).fromNow(), 'في ثوان', 'in a few seconds');
925 assert.equal(moment().add({d: 5}).fromNow(), 'في 5 أيام', 'in 5 days');
926 });
927
928 test('calendar day', function (assert) {
929 var a = moment().hours(12).minutes(0).seconds(0);
930
931 assert.equal(moment(a).calendar(), 'اليوم على الساعة 12:00', 'today at the same time');
932 assert.equal(moment(a).add({m: 25}).calendar(), 'اليوم على الساعة 12:25', 'Now plus 25 min');
933 assert.equal(moment(a).add({h: 1}).calendar(), 'اليوم على الساعة 13:00', 'Now plus 1 hour');
934 assert.equal(moment(a).add({d: 1}).calendar(), 'غدا على الساعة 12:00', 'tomorrow at the same time');
935 assert.equal(moment(a).subtract({h: 1}).calendar(), 'اليوم على الساعة 11:00', 'Now minus 1 hour');
936 assert.equal(moment(a).subtract({d: 1}).calendar(), 'أمس على الساعة 12:00', 'yesterday at the same time');
937 });
938
939 test('calendar next week', function (assert) {
940 var i, m;
941 for (i = 2; i < 7; i++) {
942 m = moment().add({d: i});
943 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days current time');
944 m.hours(0).minutes(0).seconds(0).milliseconds(0);
945 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days beginning of day');
946 m.hours(23).minutes(59).seconds(59).milliseconds(999);
947 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days end of day');
73f3c911 948 }
db71a655 949 });
516f5f67 950
db71a655
KM
951 test('calendar last week', function (assert) {
952 var i, m;
953 for (i = 2; i < 7; i++) {
954 m = moment().subtract({d: i});
955 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days current time');
956 m.hours(0).minutes(0).seconds(0).milliseconds(0);
957 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days beginning of day');
958 m.hours(23).minutes(59).seconds(59).milliseconds(999);
959 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days end of day');
516f5f67 960 }
db71a655 961 });
516f5f67 962
db71a655
KM
963 test('calendar all else', function (assert) {
964 var weeksAgo = moment().subtract({w: 1}),
965 weeksFromNow = moment().add({w: 1});
516f5f67 966
db71a655
KM
967 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
968 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 969
db71a655
KM
970 weeksAgo = moment().subtract({w: 2});
971 weeksFromNow = moment().add({w: 2});
516f5f67 972
db71a655
KM
973 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
974 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
975 });
976
977 test('weeks year starting sunday formatted', function (assert) {
978 assert.equal(moment([2016, 1, 4]).format('w ww wo'), '5 05 5', 'Feb 4 2016 should be week 5');
979 assert.equal(moment([2016, 0, 6]).format('w ww wo'), '1 01 1', 'Jan 6 2016 should be week 1');
980 assert.equal(moment([2016, 0, 7]).format('w ww wo'), '1 01 1', 'Jan 7 2016 should be week 1');
981 assert.equal(moment([2016, 0, 13]).format('w ww wo'), '2 02 2', 'Jan 13 2016 should be week 2');
982 assert.equal(moment([2016, 0, 14]).format('w ww wo'), '2 02 2', 'Jan 14 2016 should be week 2');
983 });
73f3c911
IC
984
985})));
c587bf00 986
516f5f67 987
c74a101d
IC
988;(function (global, factory) {
989 typeof exports === 'object' && typeof module !== 'undefined'
990 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
991 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
992 factory(global.moment)
73f3c911 993}(this, (function (moment) { 'use strict';
516f5f67 994
db71a655
KM
995 function each(array, callback) {
996 var i;
997 for (i = 0; i < array.length; i++) {
998 callback(array[i], i, array);
999 }
b135bf1a
IC
1000 }
1001
c58511b9
KM
1002 function setupDeprecationHandler(test, moment$$1, scope) {
1003 test._expectedDeprecations = null;
1004 test._observedDeprecations = null;
1005 test._oldSupress = moment$$1.suppressDeprecationWarnings;
1006 moment$$1.suppressDeprecationWarnings = true;
1007 test.expectedDeprecations = function () {
1008 test._expectedDeprecations = arguments;
1009 test._observedDeprecations = [];
1010 };
1011 moment$$1.deprecationHandler = function (name, msg) {
1012 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
1013 if (deprecationId === -1) {
1014 throw new Error('Unexpected deprecation thrown name=' +
1015 name + ' msg=' + msg);
1016 }
1017 test._observedDeprecations[deprecationId] = 1;
1018 };
1019 }
1020
1021 function teardownDeprecationHandler(test, moment$$1, scope) {
1022 moment$$1.suppressDeprecationWarnings = test._oldSupress;
1023
1024 if (test._expectedDeprecations != null) {
1025 var missedDeprecations = [];
1026 each(test._expectedDeprecations, function (deprecationPattern, id) {
1027 if (test._observedDeprecations[id] !== 1) {
1028 missedDeprecations.push(deprecationPattern);
1029 }
1030 });
1031 if (missedDeprecations.length !== 0) {
1032 throw new Error('Expected deprecation warnings did not happen: ' +
1033 missedDeprecations.join(' '));
1034 }
1035 }
1036 }
1037
1038 function matchedDeprecation(name, msg, deprecations) {
1039 if (deprecations == null) {
1040 return -1;
1041 }
1042 for (var i = 0; i < deprecations.length; ++i) {
1043 if (name != null && name === deprecations[i]) {
1044 return i;
1045 }
1046 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
1047 return i;
1048 }
1049 }
1050 return -1;
1051 }
1052
1053 /*global QUnit:false*/
1054
1055 var test = QUnit.test;
1056
db71a655
KM
1057 function objectKeys(obj) {
1058 if (Object.keys) {
1059 return Object.keys(obj);
1060 } else {
1061 // IE8
1062 var res = [], i;
1063 for (i in obj) {
1064 if (obj.hasOwnProperty(i)) {
1065 res.push(i);
1066 }
b135bf1a 1067 }
db71a655 1068 return res;
b135bf1a 1069 }
b135bf1a
IC
1070 }
1071
db71a655 1072 // Pick the first defined of two or three arguments.
b135bf1a 1073
db71a655
KM
1074 function defineCommonLocaleTests(locale, options) {
1075 test('lenient day of month ordinal parsing', function (assert) {
1076 var i, ordinalStr, testMoment;
1077 for (i = 1; i <= 31; ++i) {
1078 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
1079 testMoment = moment(ordinalStr, 'YYYY MM Do');
1080 assert.equal(testMoment.year(), 2014,
1081 'lenient day of month ordinal parsing ' + i + ' year check');
1082 assert.equal(testMoment.month(), 0,
1083 'lenient day of month ordinal parsing ' + i + ' month check');
1084 assert.equal(testMoment.date(), i,
1085 'lenient day of month ordinal parsing ' + i + ' date check');
1086 }
1087 });
b135bf1a 1088
db71a655
KM
1089 test('lenient day of month ordinal parsing of number', function (assert) {
1090 var i, testMoment;
1091 for (i = 1; i <= 31; ++i) {
1092 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
1093 assert.equal(testMoment.year(), 2014,
1094 'lenient day of month ordinal parsing of number ' + i + ' year check');
1095 assert.equal(testMoment.month(), 0,
1096 'lenient day of month ordinal parsing of number ' + i + ' month check');
1097 assert.equal(testMoment.date(), i,
1098 'lenient day of month ordinal parsing of number ' + i + ' date check');
1099 }
1100 });
b135bf1a 1101
db71a655
KM
1102 test('strict day of month ordinal parsing', function (assert) {
1103 var i, ordinalStr, testMoment;
1104 for (i = 1; i <= 31; ++i) {
1105 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
1106 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
1107 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
1108 }
1109 });
d6651c21 1110
db71a655
KM
1111 test('meridiem invariant', function (assert) {
1112 var h, m, t1, t2;
1113 for (h = 0; h < 24; ++h) {
1114 for (m = 0; m < 60; m += 15) {
1115 t1 = moment.utc([2000, 0, 1, h, m]);
1116 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
1117 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
1118 'meridiem at ' + t1.format('HH:mm'));
1119 }
1120 }
1121 });
1122
1123 test('date format correctness', function (assert) {
1124 var data, tokens;
1125 data = moment.localeData()._longDateFormat;
1126 tokens = objectKeys(data);
1127 each(tokens, function (srchToken) {
1128 // Check each format string to make sure it does not contain any
1129 // tokens that need to be expanded.
1130 each(tokens, function (baseToken) {
1131 // strip escaped sequences
1132 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
1133 assert.equal(false, !!~format.indexOf(srchToken),
1134 'contains ' + srchToken + ' in ' + baseToken);
1135 });
73f3c911 1136 });
d6651c21
IC
1137 });
1138
db71a655
KM
1139 test('month parsing correctness', function (assert) {
1140 var i, m;
1141
1142 if (locale === 'tr') {
1143 // I can't fix it :(
c58511b9 1144 assert.expect(0);
db71a655
KM
1145 return;
1146 }
1147 function tester(format) {
1148 var r;
1149 r = moment(m.format(format), format);
1150 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
1151 if (locale !== 'ka') {
1152 r = moment(m.format(format).toLocaleUpperCase(), format);
1153 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
1154 }
db71a655
KM
1155 r = moment(m.format(format).toLocaleLowerCase(), format);
1156 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
1157
1158 r = moment(m.format(format), format, true);
1159 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
1160 if (locale !== 'ka') {
1161 r = moment(m.format(format).toLocaleUpperCase(), format, true);
1162 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
1163 }
db71a655
KM
1164 r = moment(m.format(format).toLocaleLowerCase(), format, true);
1165 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
1166 }
1167
1168 for (i = 0; i < 12; ++i) {
1169 m = moment([2015, i, 15, 18]);
1170 tester('MMM');
1171 tester('MMM.');
1172 tester('MMMM');
1173 tester('MMMM.');
1174 }
1175 });
d6651c21 1176
db71a655
KM
1177 test('weekday parsing correctness', function (assert) {
1178 var i, m;
1179
96d0d679 1180 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
1181 // tr, az: There is a lower-case letter (ı), that converted to
1182 // upper then lower changes to i
1183 // ro: there is the letter ț which behaves weird under IE8
1184 // mt: letter Ħ
96d0d679 1185 // ga: month with spaces
c58511b9 1186 assert.expect(0);
db71a655
KM
1187 return;
1188 }
1189 function tester(format) {
1190 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
1191 r = moment(m.format(format), format);
1192 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
1193 if (locale !== 'ka') {
1194 r = moment(m.format(format).toLocaleUpperCase(), format);
1195 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
1196 }
db71a655
KM
1197 r = moment(m.format(format).toLocaleLowerCase(), format);
1198 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
1199 r = moment(m.format(format), format, true);
1200 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
1201 if (locale !== 'ka') {
1202 r = moment(m.format(format).toLocaleUpperCase(), format, true);
1203 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
1204 }
db71a655
KM
1205 r = moment(m.format(format).toLocaleLowerCase(), format, true);
1206 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
1207 }
1208
1209 for (i = 0; i < 7; ++i) {
1210 m = moment.utc([2015, 0, i + 1, 18]);
1211 tester('dd');
1212 tester('ddd');
1213 tester('dddd');
1214 }
1215 });
d6651c21 1216
db71a655
KM
1217 test('valid localeData', function (assert) {
1218 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
1219 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
1220 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
1221 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
1222 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
1223 });
96d0d679
KM
1224
1225 test('localeData weekdays can localeSort', function (assert) {
1226 var weekdays = moment().localeData().weekdays();
1227 var weekdaysShort = moment().localeData().weekdaysShort();
1228 var weekdaysMin = moment().localeData().weekdaysMin();
1229 var shift = moment().localeData()._week.dow;
1230 assert.deepEqual(
1231 moment().localeData().weekdays(true),
1232 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
1233 'weekdays should localeSort');
1234 assert.deepEqual(
1235 moment().localeData().weekdaysShort(true),
1236 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
1237 'weekdaysShort should localeSort');
1238 assert.deepEqual(
1239 moment().localeData().weekdaysMin(true),
1240 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
1241 'weekdaysMin should localeSort');
1242 });
db71a655 1243 }
d6651c21 1244
db71a655 1245 /*global QUnit:false*/
c74a101d 1246
db71a655
KM
1247 function localeModule (name, lifecycle) {
1248 QUnit.module('locale:' + name, {
c58511b9 1249 beforeEach : function () {
db71a655
KM
1250 moment.locale(name);
1251 moment.createFromInputFallback = function (config) {
1252 throw new Error('input not handled by moment: ' + config._i);
1253 };
1254 setupDeprecationHandler(test, moment, 'locale');
1255 if (lifecycle && lifecycle.setup) {
1256 lifecycle.setup();
1257 }
1258 },
c58511b9 1259 afterEach : function () {
db71a655
KM
1260 moment.locale('en');
1261 teardownDeprecationHandler(test, moment, 'locale');
1262 if (lifecycle && lifecycle.teardown) {
1263 lifecycle.teardown();
1264 }
516f5f67
IC
1265 }
1266 });
db71a655
KM
1267 defineCommonLocaleTests(name, -1, -1);
1268 }
1269
1270 localeModule('ar-kw');
1271
1272 test('parse', function (assert) {
1273 var tests = 'يناير:يناير_فبراير:فبراير_مارس:مارس_أبريل:أبريل_ماي:ماي_يونيو:يونيو_يوليوز:يوليوز_غشت:غشت_شتنبر:شتنبر_أكتوبر:أكتوبر_نونبر:نونبر_دجنبر:دجنبر'.split('_'), i;
1274 function equalTest(input, mmm, i) {
1275 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
1276 }
1277 for (i = 0; i < 12; i++) {
1278 tests[i] = tests[i].split(':');
1279 equalTest(tests[i][0], 'MMM', i);
1280 equalTest(tests[i][1], 'MMM', i);
1281 equalTest(tests[i][0], 'MMMM', i);
1282 equalTest(tests[i][1], 'MMMM', i);
1283 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
1284 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
1285 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
1286 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
1287 }
1288 });
1289
1290 test('format', function (assert) {
1291 var a = [
1292 ['dddd, MMMM Do YYYY, h:mm:ss a', 'الأحد, فبراير 14 2010, 3:25:50 pm'],
1293 ['ddd, hA', 'احد, 3PM'],
1294 ['M Mo MM MMMM MMM', '2 2 02 فبراير فبراير'],
1295 ['YYYY YY', '2010 10'],
1296 ['D Do DD', '14 14 14'],
1297 ['d do dddd ddd dd', '0 0 الأحد احد ح'],
1298 ['DDD DDDo DDDD', '45 45 045'],
1299 ['w wo ww', '9 9 09'],
1300 ['h hh', '3 03'],
1301 ['H HH', '15 15'],
1302 ['m mm', '25 25'],
1303 ['s ss', '50 50'],
1304 ['a A', 'pm PM'],
1305 ['[the] DDDo [day of the year]', 'the 45 day of the year'],
1306 ['LT', '15:25'],
1307 ['LTS', '15:25:50'],
1308 ['L', '14/02/2010'],
1309 ['LL', '14 فبراير 2010'],
1310 ['LLL', '14 فبراير 2010 15:25'],
1311 ['LLLL', 'الأحد 14 فبراير 2010 15:25'],
1312 ['l', '14/2/2010'],
1313 ['ll', '14 فبراير 2010'],
1314 ['lll', '14 فبراير 2010 15:25'],
1315 ['llll', 'احد 14 فبراير 2010 15:25']
1316 ],
1317 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
1318 i;
1319 for (i = 0; i < a.length; i++) {
1320 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
1321 }
1322 });
1323
1324 test('format ordinal', function (assert) {
1325 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
1326 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
1327 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
1328 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
1329 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
1330 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
1331 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
1332 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
1333 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
1334 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
1335
1336 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
1337 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
1338 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
1339 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
1340 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
1341 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
1342 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
1343 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
1344 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
1345 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
1346
1347 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
1348 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
1349 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
1350 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
1351 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
1352 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
1353 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
1354 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
1355 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
1356 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
1357
1358 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
1359 });
1360
1361 test('format month', function (assert) {
1362 var expected = 'يناير يناير_فبراير فبراير_مارس مارس_أبريل أبريل_ماي ماي_يونيو يونيو_يوليوز يوليوز_غشت غشت_شتنبر شتنبر_أكتوبر أكتوبر_نونبر نونبر_دجنبر دجنبر'.split('_'), i;
1363 for (i = 0; i < expected.length; i++) {
1364 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
1365 }
1366 });
1367
1368 test('format week', function (assert) {
1369 var expected = 'الأحد احد ح_الإتنين اتنين ن_الثلاثاء ثلاثاء ث_الأربعاء اربعاء ر_الخميس خميس خ_الجمعة جمعة ج_السبت سبت س'.split('_'), i;
1370 for (i = 0; i < expected.length; i++) {
1371 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
1372 }
1373 });
1374
1375 test('from', function (assert) {
1376 var start = moment([2007, 1, 28]);
1377 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ثوان', '44 seconds = a few seconds');
1378 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'دقيقة', '45 seconds = a minute');
1379 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'دقيقة', '89 seconds = a minute');
1380 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 دقائق', '90 seconds = 2 minutes');
1381 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 دقائق', '44 minutes = 44 minutes');
1382 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ساعة', '45 minutes = an hour');
1383 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ساعة', '89 minutes = an hour');
1384 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ساعات', '90 minutes = 2 hours');
1385 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ساعات', '5 hours = 5 hours');
1386 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ساعات', '21 hours = 21 hours');
1387 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'يوم', '22 hours = a day');
1388 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'يوم', '35 hours = a day');
1389 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 أيام', '36 hours = 2 days');
1390 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'يوم', '1 day = a day');
1391 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 أيام', '5 days = 5 days');
1392 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 أيام', '25 days = 25 days');
1393 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'شهر', '26 days = a month');
1394 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'شهر', '30 days = a month');
1395 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'شهر', '43 days = a month');
1396 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 أشهر', '46 days = 2 months');
1397 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 أشهر', '75 days = 2 months');
1398 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 أشهر', '76 days = 3 months');
1399 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'شهر', '1 month = a month');
1400 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 أشهر', '5 months = 5 months');
1401 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'سنة', '345 days = a year');
1402 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 سنوات', '548 days = 2 years');
1403 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'سنة', '1 year = a year');
1404 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 سنوات', '5 years = 5 years');
1405 });
1406
1407 test('suffix', function (assert) {
1408 assert.equal(moment(30000).from(0), 'في ثوان', 'prefix');
1409 assert.equal(moment(0).from(30000), 'منذ ثوان', 'suffix');
1410 });
1411
1412 test('now from now', function (assert) {
1413 assert.equal(moment().fromNow(), 'منذ ثوان', 'now from now should display as in the past');
1414 });
1415
1416 test('fromNow', function (assert) {
1417 assert.equal(moment().add({s: 30}).fromNow(), 'في ثوان', 'in a few seconds');
1418 assert.equal(moment().add({d: 5}).fromNow(), 'في 5 أيام', 'in 5 days');
1419 });
1420
1421 test('calendar day', function (assert) {
1422 var a = moment().hours(12).minutes(0).seconds(0);
1423
1424 assert.equal(moment(a).calendar(), 'اليوم على الساعة 12:00', 'today at the same time');
1425 assert.equal(moment(a).add({m: 25}).calendar(), 'اليوم على الساعة 12:25', 'Now plus 25 min');
1426 assert.equal(moment(a).add({h: 1}).calendar(), 'اليوم على الساعة 13:00', 'Now plus 1 hour');
1427 assert.equal(moment(a).add({d: 1}).calendar(), 'غدا على الساعة 12:00', 'tomorrow at the same time');
1428 assert.equal(moment(a).subtract({h: 1}).calendar(), 'اليوم على الساعة 11:00', 'Now minus 1 hour');
1429 assert.equal(moment(a).subtract({d: 1}).calendar(), 'أمس على الساعة 12:00', 'yesterday at the same time');
1430 });
1431
1432 test('calendar next week', function (assert) {
1433 var i, m;
1434 for (i = 2; i < 7; i++) {
1435 m = moment().add({d: i});
1436 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days current time');
1437 m.hours(0).minutes(0).seconds(0).milliseconds(0);
1438 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days beginning of day');
1439 m.hours(23).minutes(59).seconds(59).milliseconds(999);
1440 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days end of day');
73f3c911 1441 }
db71a655 1442 });
516f5f67 1443
db71a655
KM
1444 test('calendar last week', function (assert) {
1445 var i, m;
1446 for (i = 2; i < 7; i++) {
1447 m = moment().subtract({d: i});
1448 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days current time');
1449 m.hours(0).minutes(0).seconds(0).milliseconds(0);
1450 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days beginning of day');
1451 m.hours(23).minutes(59).seconds(59).milliseconds(999);
1452 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days end of day');
516f5f67 1453 }
db71a655 1454 });
516f5f67 1455
db71a655
KM
1456 test('calendar all else', function (assert) {
1457 var weeksAgo = moment().subtract({w: 1}),
1458 weeksFromNow = moment().add({w: 1});
516f5f67 1459
db71a655
KM
1460 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
1461 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 1462
db71a655
KM
1463 weeksAgo = moment().subtract({w: 2});
1464 weeksFromNow = moment().add({w: 2});
516f5f67 1465
db71a655
KM
1466 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
1467 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
1468 });
1469
1470 test('weeks year starting sunday formatted', function (assert) {
1471 assert.equal(moment([2011, 11, 31]).format('w ww wo'), '1 01 1', 'Dec 31 2011 should be week 1');
1472 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '2 02 2', 'Jan 1 2012 should be week 2');
1473 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '3 03 3', 'Jan 8 2012 should be week 3');
1474 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '3 03 3', 'Jan 14 2012 should be week 3');
1475 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '4 04 4', 'Jan 15 2012 should be week 4');
1476 });
73f3c911
IC
1477
1478})));
1479
516f5f67 1480
c74a101d
IC
1481;(function (global, factory) {
1482 typeof exports === 'object' && typeof module !== 'undefined'
1483 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
1484 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
1485 factory(global.moment)
73f3c911 1486}(this, (function (moment) { 'use strict';
516f5f67 1487
db71a655
KM
1488 function each(array, callback) {
1489 var i;
1490 for (i = 0; i < array.length; i++) {
1491 callback(array[i], i, array);
1492 }
b135bf1a
IC
1493 }
1494
c58511b9
KM
1495 function setupDeprecationHandler(test, moment$$1, scope) {
1496 test._expectedDeprecations = null;
1497 test._observedDeprecations = null;
1498 test._oldSupress = moment$$1.suppressDeprecationWarnings;
1499 moment$$1.suppressDeprecationWarnings = true;
1500 test.expectedDeprecations = function () {
1501 test._expectedDeprecations = arguments;
1502 test._observedDeprecations = [];
1503 };
1504 moment$$1.deprecationHandler = function (name, msg) {
1505 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
1506 if (deprecationId === -1) {
1507 throw new Error('Unexpected deprecation thrown name=' +
1508 name + ' msg=' + msg);
1509 }
1510 test._observedDeprecations[deprecationId] = 1;
1511 };
1512 }
1513
1514 function teardownDeprecationHandler(test, moment$$1, scope) {
1515 moment$$1.suppressDeprecationWarnings = test._oldSupress;
1516
1517 if (test._expectedDeprecations != null) {
1518 var missedDeprecations = [];
1519 each(test._expectedDeprecations, function (deprecationPattern, id) {
1520 if (test._observedDeprecations[id] !== 1) {
1521 missedDeprecations.push(deprecationPattern);
1522 }
1523 });
1524 if (missedDeprecations.length !== 0) {
1525 throw new Error('Expected deprecation warnings did not happen: ' +
1526 missedDeprecations.join(' '));
1527 }
1528 }
1529 }
1530
1531 function matchedDeprecation(name, msg, deprecations) {
1532 if (deprecations == null) {
1533 return -1;
1534 }
1535 for (var i = 0; i < deprecations.length; ++i) {
1536 if (name != null && name === deprecations[i]) {
1537 return i;
1538 }
1539 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
1540 return i;
1541 }
1542 }
1543 return -1;
1544 }
1545
1546 /*global QUnit:false*/
1547
1548 var test = QUnit.test;
1549
db71a655
KM
1550 function objectKeys(obj) {
1551 if (Object.keys) {
1552 return Object.keys(obj);
1553 } else {
1554 // IE8
1555 var res = [], i;
1556 for (i in obj) {
1557 if (obj.hasOwnProperty(i)) {
1558 res.push(i);
1559 }
b135bf1a 1560 }
db71a655 1561 return res;
b135bf1a 1562 }
b135bf1a
IC
1563 }
1564
db71a655 1565 // Pick the first defined of two or three arguments.
b135bf1a 1566
db71a655
KM
1567 function defineCommonLocaleTests(locale, options) {
1568 test('lenient day of month ordinal parsing', function (assert) {
1569 var i, ordinalStr, testMoment;
1570 for (i = 1; i <= 31; ++i) {
1571 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
1572 testMoment = moment(ordinalStr, 'YYYY MM Do');
1573 assert.equal(testMoment.year(), 2014,
1574 'lenient day of month ordinal parsing ' + i + ' year check');
1575 assert.equal(testMoment.month(), 0,
1576 'lenient day of month ordinal parsing ' + i + ' month check');
1577 assert.equal(testMoment.date(), i,
1578 'lenient day of month ordinal parsing ' + i + ' date check');
1579 }
1580 });
b135bf1a 1581
db71a655
KM
1582 test('lenient day of month ordinal parsing of number', function (assert) {
1583 var i, testMoment;
1584 for (i = 1; i <= 31; ++i) {
1585 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
1586 assert.equal(testMoment.year(), 2014,
1587 'lenient day of month ordinal parsing of number ' + i + ' year check');
1588 assert.equal(testMoment.month(), 0,
1589 'lenient day of month ordinal parsing of number ' + i + ' month check');
1590 assert.equal(testMoment.date(), i,
1591 'lenient day of month ordinal parsing of number ' + i + ' date check');
1592 }
1593 });
b135bf1a 1594
db71a655
KM
1595 test('strict day of month ordinal parsing', function (assert) {
1596 var i, ordinalStr, testMoment;
1597 for (i = 1; i <= 31; ++i) {
1598 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
1599 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
1600 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
1601 }
1602 });
b135bf1a 1603
db71a655
KM
1604 test('meridiem invariant', function (assert) {
1605 var h, m, t1, t2;
1606 for (h = 0; h < 24; ++h) {
1607 for (m = 0; m < 60; m += 15) {
1608 t1 = moment.utc([2000, 0, 1, h, m]);
1609 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
1610 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
1611 'meridiem at ' + t1.format('HH:mm'));
1612 }
1613 }
1614 });
1615
1616 test('date format correctness', function (assert) {
1617 var data, tokens;
1618 data = moment.localeData()._longDateFormat;
1619 tokens = objectKeys(data);
1620 each(tokens, function (srchToken) {
1621 // Check each format string to make sure it does not contain any
1622 // tokens that need to be expanded.
1623 each(tokens, function (baseToken) {
1624 // strip escaped sequences
1625 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
1626 assert.equal(false, !!~format.indexOf(srchToken),
1627 'contains ' + srchToken + ' in ' + baseToken);
1628 });
b135bf1a
IC
1629 });
1630 });
d6651c21 1631
db71a655
KM
1632 test('month parsing correctness', function (assert) {
1633 var i, m;
1634
1635 if (locale === 'tr') {
1636 // I can't fix it :(
c58511b9 1637 assert.expect(0);
db71a655
KM
1638 return;
1639 }
1640 function tester(format) {
1641 var r;
1642 r = moment(m.format(format), format);
1643 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
1644 if (locale !== 'ka') {
1645 r = moment(m.format(format).toLocaleUpperCase(), format);
1646 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
1647 }
db71a655
KM
1648 r = moment(m.format(format).toLocaleLowerCase(), format);
1649 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
1650
1651 r = moment(m.format(format), format, true);
1652 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
1653 if (locale !== 'ka') {
1654 r = moment(m.format(format).toLocaleUpperCase(), format, true);
1655 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
1656 }
db71a655
KM
1657 r = moment(m.format(format).toLocaleLowerCase(), format, true);
1658 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
1659 }
1660
1661 for (i = 0; i < 12; ++i) {
1662 m = moment([2015, i, 15, 18]);
1663 tester('MMM');
1664 tester('MMM.');
1665 tester('MMMM');
1666 tester('MMMM.');
1667 }
1668 });
d6651c21 1669
db71a655
KM
1670 test('weekday parsing correctness', function (assert) {
1671 var i, m;
1672
96d0d679 1673 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
1674 // tr, az: There is a lower-case letter (ı), that converted to
1675 // upper then lower changes to i
1676 // ro: there is the letter ț which behaves weird under IE8
1677 // mt: letter Ħ
96d0d679 1678 // ga: month with spaces
c58511b9 1679 assert.expect(0);
db71a655
KM
1680 return;
1681 }
1682 function tester(format) {
1683 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
1684 r = moment(m.format(format), format);
1685 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
1686 if (locale !== 'ka') {
1687 r = moment(m.format(format).toLocaleUpperCase(), format);
1688 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
1689 }
db71a655
KM
1690 r = moment(m.format(format).toLocaleLowerCase(), format);
1691 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
1692 r = moment(m.format(format), format, true);
1693 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
1694 if (locale !== 'ka') {
1695 r = moment(m.format(format).toLocaleUpperCase(), format, true);
1696 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
1697 }
db71a655
KM
1698 r = moment(m.format(format).toLocaleLowerCase(), format, true);
1699 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
1700 }
1701
1702 for (i = 0; i < 7; ++i) {
1703 m = moment.utc([2015, 0, i + 1, 18]);
1704 tester('dd');
1705 tester('ddd');
1706 tester('dddd');
1707 }
1708 });
d6651c21 1709
db71a655
KM
1710 test('valid localeData', function (assert) {
1711 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
1712 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
1713 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
1714 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
1715 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
1716 });
96d0d679
KM
1717
1718 test('localeData weekdays can localeSort', function (assert) {
1719 var weekdays = moment().localeData().weekdays();
1720 var weekdaysShort = moment().localeData().weekdaysShort();
1721 var weekdaysMin = moment().localeData().weekdaysMin();
1722 var shift = moment().localeData()._week.dow;
1723 assert.deepEqual(
1724 moment().localeData().weekdays(true),
1725 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
1726 'weekdays should localeSort');
1727 assert.deepEqual(
1728 moment().localeData().weekdaysShort(true),
1729 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
1730 'weekdaysShort should localeSort');
1731 assert.deepEqual(
1732 moment().localeData().weekdaysMin(true),
1733 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
1734 'weekdaysMin should localeSort');
1735 });
db71a655 1736 }
d6651c21 1737
db71a655 1738 /*global QUnit:false*/
516f5f67 1739
db71a655
KM
1740 function localeModule (name, lifecycle) {
1741 QUnit.module('locale:' + name, {
c58511b9 1742 beforeEach : function () {
db71a655
KM
1743 moment.locale(name);
1744 moment.createFromInputFallback = function (config) {
1745 throw new Error('input not handled by moment: ' + config._i);
1746 };
1747 setupDeprecationHandler(test, moment, 'locale');
1748 if (lifecycle && lifecycle.setup) {
1749 lifecycle.setup();
1750 }
1751 },
c58511b9 1752 afterEach : function () {
db71a655
KM
1753 moment.locale('en');
1754 teardownDeprecationHandler(test, moment, 'locale');
1755 if (lifecycle && lifecycle.teardown) {
1756 lifecycle.teardown();
1757 }
516f5f67
IC
1758 }
1759 });
db71a655
KM
1760 defineCommonLocaleTests(name, -1, -1);
1761 }
1762
1763 localeModule('ar-ly');
1764
1765 var months = [
1766 'يناير',
1767 'فبراير',
1768 'مارس',
1769 'أبريل',
1770 'مايو',
1771 'يونيو',
1772 'يوليو',
1773 'أغسطس',
1774 'سبتمبر',
1775 'أكتوبر',
1776 'نوفمبر',
1777 'ديسمبر'
1778 ];
516f5f67 1779
db71a655
KM
1780 test('parse', function (assert) {
1781 var tests = months, i;
1782 function equalTest(input, mmm, i) {
1783 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1) + ' instead is month ' + moment(input, mmm).month());
1784 }
1785 for (i = 0; i < 12; i++) {
1786 equalTest(tests[i], 'MMM', i);
1787 equalTest(tests[i], 'MMM', i);
1788 equalTest(tests[i], 'MMMM', i);
1789 equalTest(tests[i], 'MMMM', i);
1790 equalTest(tests[i].toLocaleLowerCase(), 'MMMM', i);
1791 equalTest(tests[i].toLocaleLowerCase(), 'MMMM', i);
1792 equalTest(tests[i].toLocaleUpperCase(), 'MMMM', i);
1793 equalTest(tests[i].toLocaleUpperCase(), 'MMMM', i);
1794 }
1795 });
1796
1797 test('format', function (assert) {
1798 var a = [
1799 ['dddd, MMMM Do YYYY, h:mm:ss a', 'الأحد، فبراير 14 2010، 3:25:50 م'],
1800 ['ddd, hA', 'أحد، 3م'],
1801 ['M Mo MM MMMM MMM', '2 2 02 فبراير فبراير'],
1802 ['YYYY YY', '2010 10'],
1803 ['D Do DD', '14 14 14'],
1804 ['d do dddd ddd dd', '0 0 الأحد أحد ح'],
1805 ['DDD DDDo DDDD', '45 45 045'],
1806 ['w wo ww', '8 8 08'],
1807 ['h hh', '3 03'],
1808 ['H HH', '15 15'],
1809 ['m mm', '25 25'],
1810 ['s ss', '50 50'],
1811 ['a A', 'م م'],
1812 ['[the] DDDo [day of the year]', 'the 45 day of the year'],
1813 ['LT', '15:25'],
1814 ['LTS', '15:25:50'],
1815 ['L', '14/\u200f2/\u200f2010'],
1816 ['LL', '14 فبراير 2010'],
1817 ['LLL', '14 فبراير 2010 15:25'],
1818 ['LLLL', 'الأحد 14 فبراير 2010 15:25'],
1819 ['l', '14/\u200f2/\u200f2010'],
1820 ['ll', '14 فبراير 2010'],
1821 ['lll', '14 فبراير 2010 15:25'],
1822 ['llll', 'أحد 14 فبراير 2010 15:25']
1823 ],
1824 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
1825 i;
1826 for (i = 0; i < a.length; i++) {
1827 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
1828 }
1829 });
1830
1831 test('format ordinal', function (assert) {
1832 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
1833 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
1834 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
1835 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
1836 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
1837 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
1838 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
1839 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
1840 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
1841 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
1842
1843 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
1844 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
1845 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
1846 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
1847 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
1848 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
1849 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
1850 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
1851 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
1852 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
1853
1854 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
1855 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
1856 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
1857 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
1858 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
1859 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
1860 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
1861 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
1862 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
1863 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
1864
1865 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
1866 });
1867
1868 test('format month', function (assert) {
1869 var expected = months, i;
1870 for (i = 0; i < expected.length; i++) {
1871 assert.equal(moment([2011, i, 1]).format('MMMM'), expected[i], expected[i]);
1872 assert.equal(moment([2011, i, 1]).format('MMM'), expected[i], expected[i]);
1873 }
1874 });
1875
1876 test('format week', function (assert) {
1877 var expected = 'الأحد أحد ح_الإثنين إثنين ن_الثلاثاء ثلاثاء ث_الأربعاء أربعاء ر_الخميس خميس خ_الجمعة جمعة ج_السبت سبت س'.split('_'), i;
1878 for (i = 0; i < expected.length; i++) {
1879 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
1880 }
1881 });
1882
1883 test('from', function (assert) {
1884 var start = moment([2007, 1, 28]);
1885 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), '44 ثانية', '44 seconds = a few seconds');
1886 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'دقيقة واحدة', '45 seconds = a minute');
1887 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'دقيقة واحدة', '89 seconds = a minute');
1888 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), 'دقيقتان', '90 seconds = 2 minutes');
1889 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 دقيقة', '44 minutes = 44 minutes');
1890 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ساعة واحدة', '45 minutes = an hour');
1891 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ساعة واحدة', '89 minutes = an hour');
1892 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), 'ساعتان', '90 minutes = 2 hours');
1893 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ساعات', '5 hours = 5 hours');
1894 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ساعة', '21 hours = 21 hours');
1895 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'يوم واحد', '22 hours = a day');
1896 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'يوم واحد', '35 hours = a day');
1897 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), 'يومان', '36 hours = 2 days');
1898 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'يوم واحد', '1 day = a day');
1899 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 أيام', '5 days = 5 days');
1900 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 يومًا', '25 days = 25 days');
1901 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'شهر واحد', '26 days = a month');
1902 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'شهر واحد', '30 days = a month');
1903 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'شهر واحد', '43 days = a month');
1904 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), 'شهران', '46 days = 2 months');
1905 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), 'شهران', '75 days = 2 months');
1906 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 أشهر', '76 days = 3 months');
1907 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'شهر واحد', '1 month = a month');
1908 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 أشهر', '5 months = 5 months');
1909 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'عام واحد', '345 days = a year');
1910 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), 'عامان', '548 days = 2 years');
1911 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'عام واحد', '1 year = a year');
1912 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 أعوام', '5 years = 5 years');
1913 });
1914
1915 test('suffix', function (assert) {
1916 assert.equal(moment(30000).from(0), 'بعد 30 ثانية', 'prefix');
1917 assert.equal(moment(0).from(30000), 'منذ 30 ثانية', 'suffix');
1918 });
1919
1920 test('now from now', function (assert) {
1921 assert.equal(moment().fromNow(), 'منذ ثانية واحدة', 'now from now should display as in the past');
1922 });
1923
1924 test('fromNow', function (assert) {
1925 assert.equal(moment().add({s: 30}).fromNow(), 'بعد 30 ثانية', 'in a few seconds');
1926 assert.equal(moment().add({d: 5}).fromNow(), 'بعد 5 أيام', 'in 5 days');
1927 });
1928
1929 test('calendar day', function (assert) {
1930 var a = moment().hours(12).minutes(0).seconds(0);
1931
1932 assert.equal(moment(a).calendar(), 'اليوم عند الساعة 12:00', 'today at the same time');
1933 assert.equal(moment(a).add({m: 25}).calendar(), 'اليوم عند الساعة 12:25', 'Now plus 25 min');
1934 assert.equal(moment(a).add({h: 1}).calendar(), 'اليوم عند الساعة 13:00', 'Now plus 1 hour');
1935 assert.equal(moment(a).add({d: 1}).calendar(), 'غدًا عند الساعة 12:00', 'tomorrow at the same time');
1936 assert.equal(moment(a).subtract({h: 1}).calendar(), 'اليوم عند الساعة 11:00', 'Now minus 1 hour');
1937 assert.equal(moment(a).subtract({d: 1}).calendar(), 'أمس عند الساعة 12:00', 'yesterday at the same time');
1938 });
1939
1940 test('calendar next week', function (assert) {
1941 var i, m;
1942 for (i = 2; i < 7; i++) {
1943 m = moment().add({d: i});
1944 assert.equal(m.calendar(), m.format('dddd [عند الساعة] LT'), 'Today + ' + i + ' days current time');
1945 m.hours(0).minutes(0).seconds(0).milliseconds(0);
1946 assert.equal(m.calendar(), m.format('dddd [عند الساعة] LT'), 'Today + ' + i + ' days beginning of day');
1947 m.hours(23).minutes(59).seconds(59).milliseconds(999);
1948 assert.equal(m.calendar(), m.format('dddd [عند الساعة] LT'), 'Today + ' + i + ' days end of day');
516f5f67 1949 }
db71a655
KM
1950 });
1951
1952 test('calendar last week', function (assert) {
1953 var i, m;
1954 for (i = 2; i < 7; i++) {
1955 m = moment().subtract({d: i});
1956 assert.equal(m.calendar(), m.format('dddd [عند الساعة] LT'), 'Today - ' + i + ' days current time');
1957 m.hours(0).minutes(0).seconds(0).milliseconds(0);
1958 assert.equal(m.calendar(), m.format('dddd [عند الساعة] LT'), 'Today - ' + i + ' days beginning of day');
1959 m.hours(23).minutes(59).seconds(59).milliseconds(999);
1960 assert.equal(m.calendar(), m.format('dddd [عند الساعة] LT'), 'Today - ' + i + ' days end of day');
516f5f67 1961 }
db71a655 1962 });
516f5f67 1963
db71a655
KM
1964 test('calendar all else', function (assert) {
1965 var weeksAgo = moment().subtract({w: 1}),
1966 weeksFromNow = moment().add({w: 1});
516f5f67 1967
db71a655
KM
1968 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
1969 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 1970
db71a655
KM
1971 weeksAgo = moment().subtract({w: 2});
1972 weeksFromNow = moment().add({w: 2});
516f5f67 1973
db71a655
KM
1974 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
1975 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
1976 });
1977
1978 test('weeks year starting wednesday custom', function (assert) {
1979 assert.equal(moment('2003 1 6', 'gggg w d').format('YYYY-MM-DD'), '2002-12-28', 'Week 1 of 2003 should be Dec 28 2002');
1980 assert.equal(moment('2003 1 0', 'gggg w e').format('YYYY-MM-DD'), '2002-12-28', 'Week 1 of 2003 should be Dec 28 2002');
1981 assert.equal(moment('2003 1 6', 'gggg w d').format('gggg w d'), '2003 1 6', 'Saturday of week 1 of 2003 parsed should be formatted as 2003 1 6');
1982 assert.equal(moment('2003 1 0', 'gggg w e').format('gggg w e'), '2003 1 0', '1st day of week 1 of 2003 parsed should be formatted as 2003 1 0');
1983 });
1984
1985 test('weeks year starting sunday formatted', function (assert) {
1986 assert.equal(moment([2011, 11, 31]).format('w ww wo'), '1 01 1', 'Dec 31 2011 should be week 1');
1987 assert.equal(moment([2012, 0, 6]).format('w ww wo'), '1 01 1', 'Jan 6 2012 should be week 1');
1988 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '2 02 2', 'Jan 7 2012 should be week 2');
1989 assert.equal(moment([2012, 0, 13]).format('w ww wo'), '2 02 2', 'Jan 13 2012 should be week 2');
1990 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '3 03 3', 'Jan 14 2012 should be week 3');
1991 });
1992
1993 test('no leading zeros in long date formats', function (assert) {
1994 var i, j, longDateStr, shortDateStr;
1995 for (i = 1; i <= 9; ++i) {
1996 for (j = 1; j <= 9; ++j) {
1997 longDateStr = moment([2014, i, j]).format('L');
1998 shortDateStr = moment([2014, i, j]).format('l');
1999 assert.equal(longDateStr, shortDateStr, 'should not have leading zeros in month or day');
73f3c911 2000 }
db71a655
KM
2001 }
2002 });
2003
2004 // locale-specific
2005 test('ar-ly strict mode parsing works', function (assert) {
2006 var m, formattedDate;
2007 m = moment().locale('ar-ly');
2008 formattedDate = m.format('l');
2009 assert.equal(moment.utc(formattedDate, 'l', 'ar-ly', false).isValid(), true, 'Non-strict parsing works');
2010 assert.equal(moment.utc(formattedDate, 'l', 'ar-ly', true).isValid(), true,'Strict parsing must work');
2011 });
9483e2a4 2012
73f3c911 2013})));
516f5f67 2014
516f5f67 2015
c74a101d
IC
2016;(function (global, factory) {
2017 typeof exports === 'object' && typeof module !== 'undefined'
2018 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
2019 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
2020 factory(global.moment)
73f3c911 2021}(this, (function (moment) { 'use strict';
516f5f67 2022
db71a655
KM
2023 function each(array, callback) {
2024 var i;
2025 for (i = 0; i < array.length; i++) {
2026 callback(array[i], i, array);
2027 }
b135bf1a
IC
2028 }
2029
c58511b9
KM
2030 function setupDeprecationHandler(test, moment$$1, scope) {
2031 test._expectedDeprecations = null;
2032 test._observedDeprecations = null;
2033 test._oldSupress = moment$$1.suppressDeprecationWarnings;
2034 moment$$1.suppressDeprecationWarnings = true;
2035 test.expectedDeprecations = function () {
2036 test._expectedDeprecations = arguments;
2037 test._observedDeprecations = [];
2038 };
2039 moment$$1.deprecationHandler = function (name, msg) {
2040 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
2041 if (deprecationId === -1) {
2042 throw new Error('Unexpected deprecation thrown name=' +
2043 name + ' msg=' + msg);
2044 }
2045 test._observedDeprecations[deprecationId] = 1;
2046 };
2047 }
2048
2049 function teardownDeprecationHandler(test, moment$$1, scope) {
2050 moment$$1.suppressDeprecationWarnings = test._oldSupress;
2051
2052 if (test._expectedDeprecations != null) {
2053 var missedDeprecations = [];
2054 each(test._expectedDeprecations, function (deprecationPattern, id) {
2055 if (test._observedDeprecations[id] !== 1) {
2056 missedDeprecations.push(deprecationPattern);
2057 }
2058 });
2059 if (missedDeprecations.length !== 0) {
2060 throw new Error('Expected deprecation warnings did not happen: ' +
2061 missedDeprecations.join(' '));
2062 }
2063 }
2064 }
2065
2066 function matchedDeprecation(name, msg, deprecations) {
2067 if (deprecations == null) {
2068 return -1;
2069 }
2070 for (var i = 0; i < deprecations.length; ++i) {
2071 if (name != null && name === deprecations[i]) {
2072 return i;
2073 }
2074 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
2075 return i;
2076 }
2077 }
2078 return -1;
2079 }
2080
2081 /*global QUnit:false*/
2082
2083 var test = QUnit.test;
2084
db71a655
KM
2085 function objectKeys(obj) {
2086 if (Object.keys) {
2087 return Object.keys(obj);
2088 } else {
2089 // IE8
2090 var res = [], i;
2091 for (i in obj) {
2092 if (obj.hasOwnProperty(i)) {
2093 res.push(i);
2094 }
b135bf1a 2095 }
db71a655 2096 return res;
b135bf1a
IC
2097 }
2098 }
2099
db71a655 2100 // Pick the first defined of two or three arguments.
73f3c911 2101
db71a655
KM
2102 function defineCommonLocaleTests(locale, options) {
2103 test('lenient day of month ordinal parsing', function (assert) {
2104 var i, ordinalStr, testMoment;
2105 for (i = 1; i <= 31; ++i) {
2106 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
2107 testMoment = moment(ordinalStr, 'YYYY MM Do');
2108 assert.equal(testMoment.year(), 2014,
2109 'lenient day of month ordinal parsing ' + i + ' year check');
2110 assert.equal(testMoment.month(), 0,
2111 'lenient day of month ordinal parsing ' + i + ' month check');
2112 assert.equal(testMoment.date(), i,
2113 'lenient day of month ordinal parsing ' + i + ' date check');
2114 }
2115 });
73f3c911 2116
db71a655
KM
2117 test('lenient day of month ordinal parsing of number', function (assert) {
2118 var i, testMoment;
2119 for (i = 1; i <= 31; ++i) {
2120 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
2121 assert.equal(testMoment.year(), 2014,
2122 'lenient day of month ordinal parsing of number ' + i + ' year check');
2123 assert.equal(testMoment.month(), 0,
2124 'lenient day of month ordinal parsing of number ' + i + ' month check');
2125 assert.equal(testMoment.date(), i,
2126 'lenient day of month ordinal parsing of number ' + i + ' date check');
2127 }
2128 });
b135bf1a 2129
db71a655
KM
2130 test('strict day of month ordinal parsing', function (assert) {
2131 var i, ordinalStr, testMoment;
2132 for (i = 1; i <= 31; ++i) {
2133 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
2134 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
2135 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
2136 }
2137 });
b135bf1a 2138
db71a655
KM
2139 test('meridiem invariant', function (assert) {
2140 var h, m, t1, t2;
2141 for (h = 0; h < 24; ++h) {
2142 for (m = 0; m < 60; m += 15) {
2143 t1 = moment.utc([2000, 0, 1, h, m]);
2144 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
2145 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
2146 'meridiem at ' + t1.format('HH:mm'));
2147 }
2148 }
2149 });
2150
2151 test('date format correctness', function (assert) {
2152 var data, tokens;
2153 data = moment.localeData()._longDateFormat;
2154 tokens = objectKeys(data);
2155 each(tokens, function (srchToken) {
2156 // Check each format string to make sure it does not contain any
2157 // tokens that need to be expanded.
2158 each(tokens, function (baseToken) {
2159 // strip escaped sequences
2160 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
2161 assert.equal(false, !!~format.indexOf(srchToken),
2162 'contains ' + srchToken + ' in ' + baseToken);
2163 });
b135bf1a
IC
2164 });
2165 });
d6651c21 2166
db71a655
KM
2167 test('month parsing correctness', function (assert) {
2168 var i, m;
2169
2170 if (locale === 'tr') {
2171 // I can't fix it :(
c58511b9 2172 assert.expect(0);
db71a655
KM
2173 return;
2174 }
2175 function tester(format) {
2176 var r;
2177 r = moment(m.format(format), format);
2178 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
2179 if (locale !== 'ka') {
2180 r = moment(m.format(format).toLocaleUpperCase(), format);
2181 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
2182 }
db71a655
KM
2183 r = moment(m.format(format).toLocaleLowerCase(), format);
2184 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
2185
2186 r = moment(m.format(format), format, true);
2187 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
2188 if (locale !== 'ka') {
2189 r = moment(m.format(format).toLocaleUpperCase(), format, true);
2190 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
2191 }
db71a655
KM
2192 r = moment(m.format(format).toLocaleLowerCase(), format, true);
2193 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
2194 }
2195
2196 for (i = 0; i < 12; ++i) {
2197 m = moment([2015, i, 15, 18]);
2198 tester('MMM');
2199 tester('MMM.');
2200 tester('MMMM');
2201 tester('MMMM.');
2202 }
2203 });
c587bf00 2204
db71a655
KM
2205 test('weekday parsing correctness', function (assert) {
2206 var i, m;
2207
96d0d679 2208 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
2209 // tr, az: There is a lower-case letter (ı), that converted to
2210 // upper then lower changes to i
2211 // ro: there is the letter ț which behaves weird under IE8
2212 // mt: letter Ħ
96d0d679 2213 // ga: month with spaces
c58511b9 2214 assert.expect(0);
db71a655
KM
2215 return;
2216 }
2217 function tester(format) {
2218 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
2219 r = moment(m.format(format), format);
2220 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
2221 if (locale !== 'ka') {
2222 r = moment(m.format(format).toLocaleUpperCase(), format);
2223 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
2224 }
db71a655
KM
2225 r = moment(m.format(format).toLocaleLowerCase(), format);
2226 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
2227 r = moment(m.format(format), format, true);
2228 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
2229 if (locale !== 'ka') {
2230 r = moment(m.format(format).toLocaleUpperCase(), format, true);
2231 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
2232 }
db71a655
KM
2233 r = moment(m.format(format).toLocaleLowerCase(), format, true);
2234 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
2235 }
2236
2237 for (i = 0; i < 7; ++i) {
2238 m = moment.utc([2015, 0, i + 1, 18]);
2239 tester('dd');
2240 tester('ddd');
2241 tester('dddd');
2242 }
2243 });
c587bf00 2244
db71a655
KM
2245 test('valid localeData', function (assert) {
2246 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
2247 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
2248 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
2249 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
2250 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
2251 });
96d0d679
KM
2252
2253 test('localeData weekdays can localeSort', function (assert) {
2254 var weekdays = moment().localeData().weekdays();
2255 var weekdaysShort = moment().localeData().weekdaysShort();
2256 var weekdaysMin = moment().localeData().weekdaysMin();
2257 var shift = moment().localeData()._week.dow;
2258 assert.deepEqual(
2259 moment().localeData().weekdays(true),
2260 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
2261 'weekdays should localeSort');
2262 assert.deepEqual(
2263 moment().localeData().weekdaysShort(true),
2264 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
2265 'weekdaysShort should localeSort');
2266 assert.deepEqual(
2267 moment().localeData().weekdaysMin(true),
2268 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
2269 'weekdaysMin should localeSort');
2270 });
db71a655 2271 }
c587bf00 2272
db71a655
KM
2273 /*global QUnit:false*/
2274
db71a655
KM
2275 function localeModule (name, lifecycle) {
2276 QUnit.module('locale:' + name, {
c58511b9 2277 beforeEach : function () {
db71a655
KM
2278 moment.locale(name);
2279 moment.createFromInputFallback = function (config) {
2280 throw new Error('input not handled by moment: ' + config._i);
2281 };
2282 setupDeprecationHandler(test, moment, 'locale');
2283 if (lifecycle && lifecycle.setup) {
2284 lifecycle.setup();
2285 }
2286 },
c58511b9 2287 afterEach : function () {
db71a655
KM
2288 moment.locale('en');
2289 teardownDeprecationHandler(test, moment, 'locale');
2290 if (lifecycle && lifecycle.teardown) {
2291 lifecycle.teardown();
2292 }
f2af24d5
IC
2293 }
2294 });
db71a655
KM
2295 defineCommonLocaleTests(name, -1, -1);
2296 }
2297
2298 localeModule('ar-ma');
2299
2300 test('parse', function (assert) {
2301 var tests = 'يناير:يناير_فبراير:فبراير_مارس:مارس_أبريل:أبريل_ماي:ماي_يونيو:يونيو_يوليوز:يوليوز_غشت:غشت_شتنبر:شتنبر_أكتوبر:أكتوبر_نونبر:نونبر_دجنبر:دجنبر'.split('_'), i;
2302 function equalTest(input, mmm, i) {
2303 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
2304 }
2305 for (i = 0; i < 12; i++) {
2306 tests[i] = tests[i].split(':');
2307 equalTest(tests[i][0], 'MMM', i);
2308 equalTest(tests[i][1], 'MMM', i);
2309 equalTest(tests[i][0], 'MMMM', i);
2310 equalTest(tests[i][1], 'MMMM', i);
2311 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
2312 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
2313 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
2314 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
2315 }
2316 });
2317
2318 test('format', function (assert) {
2319 var a = [
2320 ['dddd, MMMM Do YYYY, h:mm:ss a', 'الأحد, فبراير 14 2010, 3:25:50 pm'],
2321 ['ddd, hA', 'احد, 3PM'],
2322 ['M Mo MM MMMM MMM', '2 2 02 فبراير فبراير'],
2323 ['YYYY YY', '2010 10'],
2324 ['D Do DD', '14 14 14'],
2325 ['d do dddd ddd dd', '0 0 الأحد احد ح'],
2326 ['DDD DDDo DDDD', '45 45 045'],
2327 ['w wo ww', '8 8 08'],
2328 ['h hh', '3 03'],
2329 ['H HH', '15 15'],
2330 ['m mm', '25 25'],
2331 ['s ss', '50 50'],
2332 ['a A', 'pm PM'],
2333 ['[the] DDDo [day of the year]', 'the 45 day of the year'],
2334 ['LT', '15:25'],
2335 ['LTS', '15:25:50'],
2336 ['L', '14/02/2010'],
2337 ['LL', '14 فبراير 2010'],
2338 ['LLL', '14 فبراير 2010 15:25'],
2339 ['LLLL', 'الأحد 14 فبراير 2010 15:25'],
2340 ['l', '14/2/2010'],
2341 ['ll', '14 فبراير 2010'],
2342 ['lll', '14 فبراير 2010 15:25'],
2343 ['llll', 'احد 14 فبراير 2010 15:25']
2344 ],
2345 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
2346 i;
2347 for (i = 0; i < a.length; i++) {
2348 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
2349 }
2350 });
2351
2352 test('format ordinal', function (assert) {
2353 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
2354 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
2355 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
2356 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
2357 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
2358 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
2359 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
2360 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
2361 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
2362 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
2363
2364 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
2365 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
2366 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
2367 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
2368 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
2369 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
2370 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
2371 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
2372 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
2373 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
2374
2375 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
2376 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
2377 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
2378 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
2379 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
2380 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
2381 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
2382 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
2383 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
2384 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
2385
2386 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
2387 });
2388
2389 test('format month', function (assert) {
2390 var expected = 'يناير يناير_فبراير فبراير_مارس مارس_أبريل أبريل_ماي ماي_يونيو يونيو_يوليوز يوليوز_غشت غشت_شتنبر شتنبر_أكتوبر أكتوبر_نونبر نونبر_دجنبر دجنبر'.split('_'), i;
2391 for (i = 0; i < expected.length; i++) {
2392 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
2393 }
2394 });
2395
2396 test('format week', function (assert) {
2397 var expected = 'الأحد احد ح_الإتنين اتنين ن_الثلاثاء ثلاثاء ث_الأربعاء اربعاء ر_الخميس خميس خ_الجمعة جمعة ج_السبت سبت س'.split('_'), i;
2398 for (i = 0; i < expected.length; i++) {
2399 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
2400 }
2401 });
2402
2403 test('from', function (assert) {
2404 var start = moment([2007, 1, 28]);
2405 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ثوان', '44 seconds = a few seconds');
2406 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'دقيقة', '45 seconds = a minute');
2407 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'دقيقة', '89 seconds = a minute');
2408 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 دقائق', '90 seconds = 2 minutes');
2409 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 دقائق', '44 minutes = 44 minutes');
2410 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ساعة', '45 minutes = an hour');
2411 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ساعة', '89 minutes = an hour');
2412 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ساعات', '90 minutes = 2 hours');
2413 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ساعات', '5 hours = 5 hours');
2414 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ساعات', '21 hours = 21 hours');
2415 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'يوم', '22 hours = a day');
2416 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'يوم', '35 hours = a day');
2417 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 أيام', '36 hours = 2 days');
2418 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'يوم', '1 day = a day');
2419 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 أيام', '5 days = 5 days');
2420 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 أيام', '25 days = 25 days');
2421 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'شهر', '26 days = a month');
2422 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'شهر', '30 days = a month');
2423 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'شهر', '43 days = a month');
2424 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 أشهر', '46 days = 2 months');
2425 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 أشهر', '75 days = 2 months');
2426 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 أشهر', '76 days = 3 months');
2427 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'شهر', '1 month = a month');
2428 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 أشهر', '5 months = 5 months');
2429 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'سنة', '345 days = a year');
2430 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 سنوات', '548 days = 2 years');
2431 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'سنة', '1 year = a year');
2432 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 سنوات', '5 years = 5 years');
2433 });
2434
2435 test('suffix', function (assert) {
2436 assert.equal(moment(30000).from(0), 'في ثوان', 'prefix');
2437 assert.equal(moment(0).from(30000), 'منذ ثوان', 'suffix');
2438 });
2439
2440 test('now from now', function (assert) {
2441 assert.equal(moment().fromNow(), 'منذ ثوان', 'now from now should display as in the past');
2442 });
2443
2444 test('fromNow', function (assert) {
2445 assert.equal(moment().add({s: 30}).fromNow(), 'في ثوان', 'in a few seconds');
2446 assert.equal(moment().add({d: 5}).fromNow(), 'في 5 أيام', 'in 5 days');
2447 });
2448
2449 test('calendar day', function (assert) {
2450 var a = moment().hours(12).minutes(0).seconds(0);
2451
2452 assert.equal(moment(a).calendar(), 'اليوم على الساعة 12:00', 'today at the same time');
2453 assert.equal(moment(a).add({m: 25}).calendar(), 'اليوم على الساعة 12:25', 'Now plus 25 min');
2454 assert.equal(moment(a).add({h: 1}).calendar(), 'اليوم على الساعة 13:00', 'Now plus 1 hour');
2455 assert.equal(moment(a).add({d: 1}).calendar(), 'غدا على الساعة 12:00', 'tomorrow at the same time');
2456 assert.equal(moment(a).subtract({h: 1}).calendar(), 'اليوم على الساعة 11:00', 'Now minus 1 hour');
2457 assert.equal(moment(a).subtract({d: 1}).calendar(), 'أمس على الساعة 12:00', 'yesterday at the same time');
2458 });
2459
2460 test('calendar next week', function (assert) {
2461 var i, m;
2462 for (i = 2; i < 7; i++) {
2463 m = moment().add({d: i});
2464 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days current time');
2465 m.hours(0).minutes(0).seconds(0).milliseconds(0);
2466 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days beginning of day');
2467 m.hours(23).minutes(59).seconds(59).milliseconds(999);
2468 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days end of day');
f2af24d5 2469 }
db71a655 2470 });
f2af24d5 2471
db71a655
KM
2472 test('calendar last week', function (assert) {
2473 var i, m;
2474 for (i = 2; i < 7; i++) {
2475 m = moment().subtract({d: i});
2476 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days current time');
2477 m.hours(0).minutes(0).seconds(0).milliseconds(0);
2478 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days beginning of day');
2479 m.hours(23).minutes(59).seconds(59).milliseconds(999);
2480 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days end of day');
f2af24d5 2481 }
db71a655 2482 });
f2af24d5 2483
db71a655
KM
2484 test('calendar all else', function (assert) {
2485 var weeksAgo = moment().subtract({w: 1}),
2486 weeksFromNow = moment().add({w: 1});
f2af24d5 2487
db71a655
KM
2488 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
2489 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
f2af24d5 2490
db71a655
KM
2491 weeksAgo = moment().subtract({w: 2});
2492 weeksFromNow = moment().add({w: 2});
f2af24d5 2493
db71a655
KM
2494 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
2495 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
2496 });
2497
2498 test('weeks year starting sunday formatted', function (assert) {
2499 assert.equal(moment([2011, 11, 31]).format('w ww wo'), '1 01 1', 'Dec 31 2011 should be week 1');
2500 assert.equal(moment([2012, 0, 6]).format('w ww wo'), '1 01 1', 'Jan 6 2012 should be week 1');
2501 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '2 02 2', 'Jan 7 2012 should be week 2');
2502 assert.equal(moment([2012, 0, 13]).format('w ww wo'), '2 02 2', 'Jan 13 2012 should be week 2');
2503 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '3 03 3', 'Jan 14 2012 should be week 3');
2504 });
f2af24d5
IC
2505
2506})));
2507
2508
2509;(function (global, factory) {
2510 typeof exports === 'object' && typeof module !== 'undefined'
2511 && typeof require === 'function' ? factory(require('../../moment')) :
2512 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
2513 factory(global.moment)
2514}(this, (function (moment) { 'use strict';
2515
db71a655
KM
2516 function each(array, callback) {
2517 var i;
2518 for (i = 0; i < array.length; i++) {
2519 callback(array[i], i, array);
2520 }
f2af24d5 2521 }
f2af24d5 2522
c58511b9
KM
2523 function setupDeprecationHandler(test, moment$$1, scope) {
2524 test._expectedDeprecations = null;
2525 test._observedDeprecations = null;
2526 test._oldSupress = moment$$1.suppressDeprecationWarnings;
2527 moment$$1.suppressDeprecationWarnings = true;
2528 test.expectedDeprecations = function () {
2529 test._expectedDeprecations = arguments;
2530 test._observedDeprecations = [];
2531 };
2532 moment$$1.deprecationHandler = function (name, msg) {
2533 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
2534 if (deprecationId === -1) {
2535 throw new Error('Unexpected deprecation thrown name=' +
2536 name + ' msg=' + msg);
2537 }
2538 test._observedDeprecations[deprecationId] = 1;
2539 };
2540 }
2541
2542 function teardownDeprecationHandler(test, moment$$1, scope) {
2543 moment$$1.suppressDeprecationWarnings = test._oldSupress;
2544
2545 if (test._expectedDeprecations != null) {
2546 var missedDeprecations = [];
2547 each(test._expectedDeprecations, function (deprecationPattern, id) {
2548 if (test._observedDeprecations[id] !== 1) {
2549 missedDeprecations.push(deprecationPattern);
2550 }
2551 });
2552 if (missedDeprecations.length !== 0) {
2553 throw new Error('Expected deprecation warnings did not happen: ' +
2554 missedDeprecations.join(' '));
2555 }
2556 }
2557 }
2558
2559 function matchedDeprecation(name, msg, deprecations) {
2560 if (deprecations == null) {
2561 return -1;
2562 }
2563 for (var i = 0; i < deprecations.length; ++i) {
2564 if (name != null && name === deprecations[i]) {
2565 return i;
2566 }
2567 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
2568 return i;
2569 }
2570 }
2571 return -1;
2572 }
2573
2574 /*global QUnit:false*/
2575
2576 var test = QUnit.test;
2577
db71a655
KM
2578 function objectKeys(obj) {
2579 if (Object.keys) {
2580 return Object.keys(obj);
2581 } else {
2582 // IE8
2583 var res = [], i;
2584 for (i in obj) {
2585 if (obj.hasOwnProperty(i)) {
2586 res.push(i);
2587 }
f2af24d5 2588 }
db71a655 2589 return res;
f2af24d5 2590 }
f2af24d5 2591 }
f2af24d5 2592
db71a655 2593 // Pick the first defined of two or three arguments.
f2af24d5 2594
db71a655
KM
2595 function defineCommonLocaleTests(locale, options) {
2596 test('lenient day of month ordinal parsing', function (assert) {
2597 var i, ordinalStr, testMoment;
2598 for (i = 1; i <= 31; ++i) {
2599 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
2600 testMoment = moment(ordinalStr, 'YYYY MM Do');
2601 assert.equal(testMoment.year(), 2014,
2602 'lenient day of month ordinal parsing ' + i + ' year check');
2603 assert.equal(testMoment.month(), 0,
2604 'lenient day of month ordinal parsing ' + i + ' month check');
2605 assert.equal(testMoment.date(), i,
2606 'lenient day of month ordinal parsing ' + i + ' date check');
2607 }
2608 });
f2af24d5 2609
db71a655
KM
2610 test('lenient day of month ordinal parsing of number', function (assert) {
2611 var i, testMoment;
2612 for (i = 1; i <= 31; ++i) {
2613 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
2614 assert.equal(testMoment.year(), 2014,
2615 'lenient day of month ordinal parsing of number ' + i + ' year check');
2616 assert.equal(testMoment.month(), 0,
2617 'lenient day of month ordinal parsing of number ' + i + ' month check');
2618 assert.equal(testMoment.date(), i,
2619 'lenient day of month ordinal parsing of number ' + i + ' date check');
2620 }
2621 });
f2af24d5 2622
db71a655
KM
2623 test('strict day of month ordinal parsing', function (assert) {
2624 var i, ordinalStr, testMoment;
2625 for (i = 1; i <= 31; ++i) {
2626 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
2627 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
2628 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
2629 }
2630 });
f2af24d5 2631
db71a655
KM
2632 test('meridiem invariant', function (assert) {
2633 var h, m, t1, t2;
2634 for (h = 0; h < 24; ++h) {
2635 for (m = 0; m < 60; m += 15) {
2636 t1 = moment.utc([2000, 0, 1, h, m]);
2637 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
2638 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
2639 'meridiem at ' + t1.format('HH:mm'));
2640 }
2641 }
2642 });
2643
2644 test('date format correctness', function (assert) {
2645 var data, tokens;
2646 data = moment.localeData()._longDateFormat;
2647 tokens = objectKeys(data);
2648 each(tokens, function (srchToken) {
2649 // Check each format string to make sure it does not contain any
2650 // tokens that need to be expanded.
2651 each(tokens, function (baseToken) {
2652 // strip escaped sequences
2653 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
2654 assert.equal(false, !!~format.indexOf(srchToken),
2655 'contains ' + srchToken + ' in ' + baseToken);
2656 });
f2af24d5
IC
2657 });
2658 });
f2af24d5 2659
db71a655
KM
2660 test('month parsing correctness', function (assert) {
2661 var i, m;
2662
2663 if (locale === 'tr') {
2664 // I can't fix it :(
c58511b9 2665 assert.expect(0);
db71a655
KM
2666 return;
2667 }
2668 function tester(format) {
2669 var r;
2670 r = moment(m.format(format), format);
2671 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
2672 if (locale !== 'ka') {
2673 r = moment(m.format(format).toLocaleUpperCase(), format);
2674 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
2675 }
db71a655
KM
2676 r = moment(m.format(format).toLocaleLowerCase(), format);
2677 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
2678
2679 r = moment(m.format(format), format, true);
2680 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
2681 if (locale !== 'ka') {
2682 r = moment(m.format(format).toLocaleUpperCase(), format, true);
2683 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
2684 }
db71a655
KM
2685 r = moment(m.format(format).toLocaleLowerCase(), format, true);
2686 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
2687 }
2688
2689 for (i = 0; i < 12; ++i) {
2690 m = moment([2015, i, 15, 18]);
2691 tester('MMM');
2692 tester('MMM.');
2693 tester('MMMM');
2694 tester('MMMM.');
2695 }
2696 });
f2af24d5 2697
db71a655
KM
2698 test('weekday parsing correctness', function (assert) {
2699 var i, m;
2700
96d0d679 2701 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
2702 // tr, az: There is a lower-case letter (ı), that converted to
2703 // upper then lower changes to i
2704 // ro: there is the letter ț which behaves weird under IE8
2705 // mt: letter Ħ
96d0d679 2706 // ga: month with spaces
c58511b9 2707 assert.expect(0);
db71a655
KM
2708 return;
2709 }
2710 function tester(format) {
2711 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
2712 r = moment(m.format(format), format);
2713 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
2714 if (locale !== 'ka') {
2715 r = moment(m.format(format).toLocaleUpperCase(), format);
2716 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
2717 }
db71a655
KM
2718 r = moment(m.format(format).toLocaleLowerCase(), format);
2719 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
2720 r = moment(m.format(format), format, true);
2721 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
2722 if (locale !== 'ka') {
2723 r = moment(m.format(format).toLocaleUpperCase(), format, true);
2724 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
2725 }
db71a655
KM
2726 r = moment(m.format(format).toLocaleLowerCase(), format, true);
2727 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
2728 }
2729
2730 for (i = 0; i < 7; ++i) {
2731 m = moment.utc([2015, 0, i + 1, 18]);
2732 tester('dd');
2733 tester('ddd');
2734 tester('dddd');
2735 }
2736 });
f2af24d5 2737
db71a655
KM
2738 test('valid localeData', function (assert) {
2739 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
2740 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
2741 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
2742 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
2743 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
2744 });
96d0d679
KM
2745
2746 test('localeData weekdays can localeSort', function (assert) {
2747 var weekdays = moment().localeData().weekdays();
2748 var weekdaysShort = moment().localeData().weekdaysShort();
2749 var weekdaysMin = moment().localeData().weekdaysMin();
2750 var shift = moment().localeData()._week.dow;
2751 assert.deepEqual(
2752 moment().localeData().weekdays(true),
2753 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
2754 'weekdays should localeSort');
2755 assert.deepEqual(
2756 moment().localeData().weekdaysShort(true),
2757 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
2758 'weekdaysShort should localeSort');
2759 assert.deepEqual(
2760 moment().localeData().weekdaysMin(true),
2761 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
2762 'weekdaysMin should localeSort');
2763 });
db71a655 2764 }
f2af24d5 2765
db71a655 2766 /*global QUnit:false*/
c587bf00 2767
db71a655
KM
2768 function localeModule (name, lifecycle) {
2769 QUnit.module('locale:' + name, {
c58511b9 2770 beforeEach : function () {
db71a655
KM
2771 moment.locale(name);
2772 moment.createFromInputFallback = function (config) {
2773 throw new Error('input not handled by moment: ' + config._i);
2774 };
2775 setupDeprecationHandler(test, moment, 'locale');
2776 if (lifecycle && lifecycle.setup) {
2777 lifecycle.setup();
2778 }
2779 },
c58511b9 2780 afterEach : function () {
db71a655
KM
2781 moment.locale('en');
2782 teardownDeprecationHandler(test, moment, 'locale');
2783 if (lifecycle && lifecycle.teardown) {
2784 lifecycle.teardown();
2785 }
c587bf00
IC
2786 }
2787 });
db71a655
KM
2788 defineCommonLocaleTests(name, -1, -1);
2789 }
2790
2791 localeModule('ar-sa');
2792
2793 test('parse', function (assert) {
2794 var tests = 'يناير:يناير_فبراير:فبراير_مارس:مارس_أبريل:أبريل_مايو:مايو_يونيو:يونيو_يوليو:يوليو_أغسطس:أغسطس_سبتمبر:سبتمبر_أكتوبر:أكتوبر_نوفمبر:نوفمبر_ديسمبر:ديسمبر'.split('_'), i;
2795 function equalTest(input, mmm, i) {
2796 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1) + ' instead is month ' + moment(input, mmm).month());
2797 }
2798 for (i = 0; i < 12; i++) {
2799 tests[i] = tests[i].split(':');
2800 equalTest(tests[i][0], 'MMM', i);
2801 equalTest(tests[i][1], 'MMM', i);
2802 equalTest(tests[i][0], 'MMMM', i);
2803 equalTest(tests[i][1], 'MMMM', i);
2804 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
2805 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
2806 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
2807 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
2808 }
2809 });
2810
2811 test('format', function (assert) {
2812 var a = [
2813 ['dddd, MMMM Do YYYY, h:mm:ss a', 'الأحد، فبراير ١٤ ٢٠١٠، ٣:٢٥:٥٠ م'],
2814 ['ddd, hA', 'أحد، ٣م'],
2815 ['M Mo MM MMMM MMM', '٢ ٢ ٠٢ فبراير فبراير'],
2816 ['YYYY YY', '٢٠١٠ ١٠'],
2817 ['D Do DD', '١٤ ١٤ ١٤'],
2818 ['d do dddd ddd dd', '٠ ٠ الأحد أحد ح'],
2819 ['DDD DDDo DDDD', '٤٥ ٤٥ ٠٤٥'],
2820 ['w wo ww', '٨ ٨ ٠٨'],
2821 ['h hh', '٣ ٠٣'],
2822 ['H HH', '١٥ ١٥'],
2823 ['m mm', '٢٥ ٢٥'],
2824 ['s ss', '٥٠ ٥٠'],
2825 ['a A', 'م م'],
2826 ['[the] DDDo [day of the year]', 'the ٤٥ day of the year'],
2827 ['LT', '١٥:٢٥'],
2828 ['LTS', '١٥:٢٥:٥٠'],
2829 ['L', '١٤/٠٢/٢٠١٠'],
2830 ['LL', '١٤ فبراير ٢٠١٠'],
2831 ['LLL', '١٤ فبراير ٢٠١٠ ١٥:٢٥'],
2832 ['LLLL', 'الأحد ١٤ فبراير ٢٠١٠ ١٥:٢٥'],
2833 ['l', '١٤/٢/٢٠١٠'],
2834 ['ll', '١٤ فبراير ٢٠١٠'],
2835 ['lll', '١٤ فبراير ٢٠١٠ ١٥:٢٥'],
2836 ['llll', 'أحد ١٤ فبراير ٢٠١٠ ١٥:٢٥']
2837 ],
2838 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
2839 i;
2840 for (i = 0; i < a.length; i++) {
2841 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
2842 }
2843 });
2844
2845 test('format ordinal', function (assert) {
2846 assert.equal(moment([2011, 0, 1]).format('DDDo'), '١', '1');
2847 assert.equal(moment([2011, 0, 2]).format('DDDo'), '٢', '2');
2848 assert.equal(moment([2011, 0, 3]).format('DDDo'), '٣', '3');
2849 assert.equal(moment([2011, 0, 4]).format('DDDo'), '٤', '4');
2850 assert.equal(moment([2011, 0, 5]).format('DDDo'), '٥', '5');
2851 assert.equal(moment([2011, 0, 6]).format('DDDo'), '٦', '6');
2852 assert.equal(moment([2011, 0, 7]).format('DDDo'), '٧', '7');
2853 assert.equal(moment([2011, 0, 8]).format('DDDo'), '٨', '8');
2854 assert.equal(moment([2011, 0, 9]).format('DDDo'), '٩', '9');
2855 assert.equal(moment([2011, 0, 10]).format('DDDo'), '١٠', '10');
2856
2857 assert.equal(moment([2011, 0, 11]).format('DDDo'), '١١', '11');
2858 assert.equal(moment([2011, 0, 12]).format('DDDo'), '١٢', '12');
2859 assert.equal(moment([2011, 0, 13]).format('DDDo'), '١٣', '13');
2860 assert.equal(moment([2011, 0, 14]).format('DDDo'), '١٤', '14');
2861 assert.equal(moment([2011, 0, 15]).format('DDDo'), '١٥', '15');
2862 assert.equal(moment([2011, 0, 16]).format('DDDo'), '١٦', '16');
2863 assert.equal(moment([2011, 0, 17]).format('DDDo'), '١٧', '17');
2864 assert.equal(moment([2011, 0, 18]).format('DDDo'), '١٨', '18');
2865 assert.equal(moment([2011, 0, 19]).format('DDDo'), '١٩', '19');
2866 assert.equal(moment([2011, 0, 20]).format('DDDo'), '٢٠', '20');
2867
2868 assert.equal(moment([2011, 0, 21]).format('DDDo'), '٢١', '21');
2869 assert.equal(moment([2011, 0, 22]).format('DDDo'), '٢٢', '22');
2870 assert.equal(moment([2011, 0, 23]).format('DDDo'), '٢٣', '23');
2871 assert.equal(moment([2011, 0, 24]).format('DDDo'), '٢٤', '24');
2872 assert.equal(moment([2011, 0, 25]).format('DDDo'), '٢٥', '25');
2873 assert.equal(moment([2011, 0, 26]).format('DDDo'), '٢٦', '26');
2874 assert.equal(moment([2011, 0, 27]).format('DDDo'), '٢٧', '27');
2875 assert.equal(moment([2011, 0, 28]).format('DDDo'), '٢٨', '28');
2876 assert.equal(moment([2011, 0, 29]).format('DDDo'), '٢٩', '29');
2877 assert.equal(moment([2011, 0, 30]).format('DDDo'), '٣٠', '30');
2878
2879 assert.equal(moment([2011, 0, 31]).format('DDDo'), '٣١', '31');
2880 });
2881
2882 test('format month', function (assert) {
2883 var expected = 'يناير يناير_فبراير فبراير_مارس مارس_أبريل أبريل_مايو مايو_يونيو يونيو_يوليو يوليو_أغسطس أغسطس_سبتمبر سبتمبر_أكتوبر أكتوبر_نوفمبر نوفمبر_ديسمبر ديسمبر'.split('_'), i;
2884 for (i = 0; i < expected.length; i++) {
2885 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
2886 }
2887 });
2888
2889 test('format week', function (assert) {
2890 var expected = 'الأحد أحد ح_الإثنين إثنين ن_الثلاثاء ثلاثاء ث_الأربعاء أربعاء ر_الخميس خميس خ_الجمعة جمعة ج_السبت سبت س'.split('_'), i;
2891 for (i = 0; i < expected.length; i++) {
2892 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
2893 }
2894 });
2895
2896 test('from', function (assert) {
2897 var start = moment([2007, 1, 28]);
2898 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ثوان', '44 seconds = a few seconds');
2899 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'دقيقة', '45 seconds = a minute');
2900 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'دقيقة', '89 seconds = a minute');
2901 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '٢ دقائق', '90 seconds = 2 minutes');
2902 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '٤٤ دقائق', '44 minutes = 44 minutes');
2903 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ساعة', '45 minutes = an hour');
2904 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ساعة', '89 minutes = an hour');
2905 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '٢ ساعات', '90 minutes = 2 hours');
2906 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '٥ ساعات', '5 hours = 5 hours');
2907 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '٢١ ساعات', '21 hours = 21 hours');
2908 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'يوم', '22 hours = a day');
2909 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'يوم', '35 hours = a day');
2910 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '٢ أيام', '36 hours = 2 days');
2911 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'يوم', '1 day = a day');
2912 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '٥ أيام', '5 days = 5 days');
2913 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '٢٥ أيام', '25 days = 25 days');
2914 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'شهر', '26 days = a month');
2915 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'شهر', '30 days = a month');
2916 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'شهر', '43 days = a month');
2917 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '٢ أشهر', '46 days = 2 months');
2918 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '٢ أشهر', '75 days = 2 months');
2919 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '٣ أشهر', '76 days = 3 months');
2920 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'شهر', '1 month = a month');
2921 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '٥ أشهر', '5 months = 5 months');
2922 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'سنة', '345 days = a year');
2923 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '٢ سنوات', '548 days = 2 years');
2924 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'سنة', '1 year = a year');
2925 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '٥ سنوات', '5 years = 5 years');
2926 });
2927
2928 test('suffix', function (assert) {
2929 assert.equal(moment(30000).from(0), 'في ثوان', 'prefix');
2930 assert.equal(moment(0).from(30000), 'منذ ثوان', 'suffix');
2931 });
2932
2933 test('now from now', function (assert) {
2934 assert.equal(moment().fromNow(), 'منذ ثوان', 'now from now should display as in the past');
2935 });
2936
2937 test('fromNow', function (assert) {
2938 assert.equal(moment().add({s: 30}).fromNow(), 'في ثوان', 'in a few seconds');
2939 assert.equal(moment().add({d: 5}).fromNow(), 'في ٥ أيام', 'in 5 days');
2940 });
2941
2942 test('calendar day', function (assert) {
2943 var a = moment().hours(12).minutes(0).seconds(0);
2944
2945 assert.equal(moment(a).calendar(), 'اليوم على الساعة ١٢:٠٠', 'today at the same time');
2946 assert.equal(moment(a).add({m: 25}).calendar(), 'اليوم على الساعة ١٢:٢٥', 'Now plus 25 min');
2947 assert.equal(moment(a).add({h: 1}).calendar(), 'اليوم على الساعة ١٣:٠٠', 'Now plus 1 hour');
2948 assert.equal(moment(a).add({d: 1}).calendar(), 'غدا على الساعة ١٢:٠٠', 'tomorrow at the same time');
2949 assert.equal(moment(a).subtract({h: 1}).calendar(), 'اليوم على الساعة ١١:٠٠', 'Now minus 1 hour');
2950 assert.equal(moment(a).subtract({d: 1}).calendar(), 'أمس على الساعة ١٢:٠٠', 'yesterday at the same time');
2951 });
2952
2953 test('calendar next week', function (assert) {
2954 var i, m;
2955 for (i = 2; i < 7; i++) {
2956 m = moment().add({d: i});
2957 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days current time');
2958 m.hours(0).minutes(0).seconds(0).milliseconds(0);
2959 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days beginning of day');
2960 m.hours(23).minutes(59).seconds(59).milliseconds(999);
2961 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days end of day');
73f3c911 2962 }
db71a655 2963 });
c587bf00 2964
db71a655
KM
2965 test('calendar last week', function (assert) {
2966 var i, m;
2967 for (i = 2; i < 7; i++) {
2968 m = moment().subtract({d: i});
2969 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days current time');
2970 m.hours(0).minutes(0).seconds(0).milliseconds(0);
2971 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days beginning of day');
2972 m.hours(23).minutes(59).seconds(59).milliseconds(999);
2973 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days end of day');
c587bf00 2974 }
db71a655 2975 });
c587bf00 2976
db71a655
KM
2977 test('calendar all else', function (assert) {
2978 var weeksAgo = moment().subtract({w: 1}),
2979 weeksFromNow = moment().add({w: 1});
c587bf00 2980
db71a655
KM
2981 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
2982 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
c587bf00 2983
db71a655
KM
2984 weeksAgo = moment().subtract({w: 2});
2985 weeksFromNow = moment().add({w: 2});
c587bf00 2986
db71a655
KM
2987 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
2988 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
2989 });
2990
2991 test('weeks year starting wednesday custom', function (assert) {
2992 assert.equal(moment('2003 1 6', 'gggg w d').format('YYYY-MM-DD'), '٢٠٠٣-٠١-٠٤', '2003 1 6 : gggg w d');
2993 assert.equal(moment('2003 1 0', 'gggg w e').format('YYYY-MM-DD'), '٢٠٠٢-١٢-٢٩', '2003 1 0 : gggg w e');
2994 assert.equal(moment('2003 1 6', 'gggg w d').format('gggg w d'), '٢٠٠٣ ١ ٦', '2003 1 6 : gggg w d');
2995 assert.equal(moment('2003 1 0', 'gggg w e').format('gggg w e'), '٢٠٠٣ ١ ٠', '2003 1 0 : gggg w e');
2996 });
2997
2998 test('weeks year starting sunday formatted', function (assert) {
2999 assert.equal(moment([2011, 11, 31]).format('w ww wo'), '٥٣ ٥٣ ٥٣', '2011 11 31');
3000 assert.equal(moment([2012, 0, 6]).format('w ww wo'), '١ ٠١ ١', '2012 0 6');
3001 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '١ ٠١ ١', '2012 0 7');
3002 assert.equal(moment([2012, 0, 13]).format('w ww wo'), '٢ ٠٢ ٢', '2012 0 13');
3003 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '٢ ٠٢ ٢', '2012 0 14');
3004 });
73f3c911
IC
3005
3006})));
3007
c587bf00
IC
3008
3009;(function (global, factory) {
3010 typeof exports === 'object' && typeof module !== 'undefined'
3011 && typeof require === 'function' ? factory(require('../../moment')) :
3012 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
3013 factory(global.moment)
73f3c911 3014}(this, (function (moment) { 'use strict';
c587bf00 3015
db71a655
KM
3016 function each(array, callback) {
3017 var i;
3018 for (i = 0; i < array.length; i++) {
3019 callback(array[i], i, array);
3020 }
c587bf00
IC
3021 }
3022
c58511b9
KM
3023 function setupDeprecationHandler(test, moment$$1, scope) {
3024 test._expectedDeprecations = null;
3025 test._observedDeprecations = null;
3026 test._oldSupress = moment$$1.suppressDeprecationWarnings;
3027 moment$$1.suppressDeprecationWarnings = true;
3028 test.expectedDeprecations = function () {
3029 test._expectedDeprecations = arguments;
3030 test._observedDeprecations = [];
3031 };
3032 moment$$1.deprecationHandler = function (name, msg) {
3033 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
3034 if (deprecationId === -1) {
3035 throw new Error('Unexpected deprecation thrown name=' +
3036 name + ' msg=' + msg);
3037 }
3038 test._observedDeprecations[deprecationId] = 1;
3039 };
3040 }
3041
3042 function teardownDeprecationHandler(test, moment$$1, scope) {
3043 moment$$1.suppressDeprecationWarnings = test._oldSupress;
3044
3045 if (test._expectedDeprecations != null) {
3046 var missedDeprecations = [];
3047 each(test._expectedDeprecations, function (deprecationPattern, id) {
3048 if (test._observedDeprecations[id] !== 1) {
3049 missedDeprecations.push(deprecationPattern);
3050 }
3051 });
3052 if (missedDeprecations.length !== 0) {
3053 throw new Error('Expected deprecation warnings did not happen: ' +
3054 missedDeprecations.join(' '));
3055 }
3056 }
3057 }
3058
3059 function matchedDeprecation(name, msg, deprecations) {
3060 if (deprecations == null) {
3061 return -1;
3062 }
3063 for (var i = 0; i < deprecations.length; ++i) {
3064 if (name != null && name === deprecations[i]) {
3065 return i;
3066 }
3067 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
3068 return i;
3069 }
3070 }
3071 return -1;
3072 }
3073
3074 /*global QUnit:false*/
3075
3076 var test = QUnit.test;
3077
db71a655
KM
3078 function objectKeys(obj) {
3079 if (Object.keys) {
3080 return Object.keys(obj);
3081 } else {
3082 // IE8
3083 var res = [], i;
3084 for (i in obj) {
3085 if (obj.hasOwnProperty(i)) {
3086 res.push(i);
3087 }
c587bf00 3088 }
db71a655 3089 return res;
c587bf00
IC
3090 }
3091 }
73f3c911 3092
db71a655 3093 // Pick the first defined of two or three arguments.
c587bf00 3094
db71a655
KM
3095 function defineCommonLocaleTests(locale, options) {
3096 test('lenient day of month ordinal parsing', function (assert) {
3097 var i, ordinalStr, testMoment;
3098 for (i = 1; i <= 31; ++i) {
3099 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
3100 testMoment = moment(ordinalStr, 'YYYY MM Do');
3101 assert.equal(testMoment.year(), 2014,
3102 'lenient day of month ordinal parsing ' + i + ' year check');
3103 assert.equal(testMoment.month(), 0,
3104 'lenient day of month ordinal parsing ' + i + ' month check');
3105 assert.equal(testMoment.date(), i,
3106 'lenient day of month ordinal parsing ' + i + ' date check');
3107 }
3108 });
c587bf00 3109
db71a655
KM
3110 test('lenient day of month ordinal parsing of number', function (assert) {
3111 var i, testMoment;
3112 for (i = 1; i <= 31; ++i) {
3113 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
3114 assert.equal(testMoment.year(), 2014,
3115 'lenient day of month ordinal parsing of number ' + i + ' year check');
3116 assert.equal(testMoment.month(), 0,
3117 'lenient day of month ordinal parsing of number ' + i + ' month check');
3118 assert.equal(testMoment.date(), i,
3119 'lenient day of month ordinal parsing of number ' + i + ' date check');
3120 }
c587bf00
IC
3121 });
3122
db71a655
KM
3123 test('strict day of month ordinal parsing', function (assert) {
3124 var i, ordinalStr, testMoment;
3125 for (i = 1; i <= 31; ++i) {
3126 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
3127 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
3128 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
3129 }
3130 });
c587bf00 3131
db71a655
KM
3132 test('meridiem invariant', function (assert) {
3133 var h, m, t1, t2;
3134 for (h = 0; h < 24; ++h) {
3135 for (m = 0; m < 60; m += 15) {
3136 t1 = moment.utc([2000, 0, 1, h, m]);
3137 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
3138 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
3139 'meridiem at ' + t1.format('HH:mm'));
3140 }
3141 }
3142 });
c587bf00 3143
db71a655
KM
3144 test('date format correctness', function (assert) {
3145 var data, tokens;
3146 data = moment.localeData()._longDateFormat;
3147 tokens = objectKeys(data);
3148 each(tokens, function (srchToken) {
3149 // Check each format string to make sure it does not contain any
3150 // tokens that need to be expanded.
3151 each(tokens, function (baseToken) {
3152 // strip escaped sequences
3153 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
3154 assert.equal(false, !!~format.indexOf(srchToken),
3155 'contains ' + srchToken + ' in ' + baseToken);
3156 });
3157 });
3158 });
c587bf00 3159
db71a655
KM
3160 test('month parsing correctness', function (assert) {
3161 var i, m;
3162
3163 if (locale === 'tr') {
3164 // I can't fix it :(
c58511b9 3165 assert.expect(0);
db71a655
KM
3166 return;
3167 }
3168 function tester(format) {
3169 var r;
3170 r = moment(m.format(format), format);
3171 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
3172 if (locale !== 'ka') {
3173 r = moment(m.format(format).toLocaleUpperCase(), format);
3174 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
3175 }
db71a655
KM
3176 r = moment(m.format(format).toLocaleLowerCase(), format);
3177 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
3178
3179 r = moment(m.format(format), format, true);
3180 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
3181 if (locale !== 'ka') {
3182 r = moment(m.format(format).toLocaleUpperCase(), format, true);
3183 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
3184 }
db71a655
KM
3185 r = moment(m.format(format).toLocaleLowerCase(), format, true);
3186 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
3187 }
3188
3189 for (i = 0; i < 12; ++i) {
3190 m = moment([2015, i, 15, 18]);
3191 tester('MMM');
3192 tester('MMM.');
3193 tester('MMMM');
3194 tester('MMMM.');
3195 }
3196 });
c587bf00 3197
db71a655
KM
3198 test('weekday parsing correctness', function (assert) {
3199 var i, m;
3200
96d0d679 3201 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
3202 // tr, az: There is a lower-case letter (ı), that converted to
3203 // upper then lower changes to i
3204 // ro: there is the letter ț which behaves weird under IE8
3205 // mt: letter Ħ
96d0d679 3206 // ga: month with spaces
c58511b9 3207 assert.expect(0);
db71a655
KM
3208 return;
3209 }
3210 function tester(format) {
3211 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
3212 r = moment(m.format(format), format);
3213 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
3214 if (locale !== 'ka') {
3215 r = moment(m.format(format).toLocaleUpperCase(), format);
3216 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
3217 }
db71a655
KM
3218 r = moment(m.format(format).toLocaleLowerCase(), format);
3219 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
3220 r = moment(m.format(format), format, true);
3221 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
3222 if (locale !== 'ka') {
3223 r = moment(m.format(format).toLocaleUpperCase(), format, true);
3224 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
3225 }
db71a655
KM
3226 r = moment(m.format(format).toLocaleLowerCase(), format, true);
3227 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
3228 }
3229
3230 for (i = 0; i < 7; ++i) {
3231 m = moment.utc([2015, 0, i + 1, 18]);
3232 tester('dd');
3233 tester('ddd');
3234 tester('dddd');
3235 }
3236 });
d6651c21 3237
db71a655
KM
3238 test('valid localeData', function (assert) {
3239 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
3240 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
3241 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
3242 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
3243 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
3244 });
96d0d679
KM
3245
3246 test('localeData weekdays can localeSort', function (assert) {
3247 var weekdays = moment().localeData().weekdays();
3248 var weekdaysShort = moment().localeData().weekdaysShort();
3249 var weekdaysMin = moment().localeData().weekdaysMin();
3250 var shift = moment().localeData()._week.dow;
3251 assert.deepEqual(
3252 moment().localeData().weekdays(true),
3253 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
3254 'weekdays should localeSort');
3255 assert.deepEqual(
3256 moment().localeData().weekdaysShort(true),
3257 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
3258 'weekdaysShort should localeSort');
3259 assert.deepEqual(
3260 moment().localeData().weekdaysMin(true),
3261 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
3262 'weekdaysMin should localeSort');
3263 });
db71a655 3264 }
d6651c21 3265
db71a655 3266 /*global QUnit:false*/
516f5f67 3267
db71a655
KM
3268 function localeModule (name, lifecycle) {
3269 QUnit.module('locale:' + name, {
c58511b9 3270 beforeEach : function () {
db71a655
KM
3271 moment.locale(name);
3272 moment.createFromInputFallback = function (config) {
3273 throw new Error('input not handled by moment: ' + config._i);
3274 };
3275 setupDeprecationHandler(test, moment, 'locale');
3276 if (lifecycle && lifecycle.setup) {
3277 lifecycle.setup();
3278 }
3279 },
c58511b9 3280 afterEach : function () {
db71a655
KM
3281 moment.locale('en');
3282 teardownDeprecationHandler(test, moment, 'locale');
3283 if (lifecycle && lifecycle.teardown) {
3284 lifecycle.teardown();
3285 }
73f3c911 3286 }
db71a655
KM
3287 });
3288 defineCommonLocaleTests(name, -1, -1);
3289 }
3290
3291 localeModule('ar-tn');
3292
3293 test('parse', function (assert) {
3294 var tests = 'جانفي:جانفي_فيفري:فيفري_مارس:مارس_أفريل:أفريل_ماي:ماي_جوان:جوان_جويلية:جويلية_أوت:أوت_سبتمبر:سبتمبر_أكتوبر:أكتوبر_نوفمبر:نوفمبر_ديسمبر:ديسمبر'.split('_'),
3295 i;
3296
3297 function equalTest(input, mmm, i) {
3298 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
3299 }
3300 for (i = 0; i < 12; i++) {
3301 tests[i] = tests[i].split(':');
3302 equalTest(tests[i][0], 'MMM', i);
3303 equalTest(tests[i][1], 'MMM', i);
3304 equalTest(tests[i][0], 'MMMM', i);
3305 equalTest(tests[i][1], 'MMMM', i);
3306 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
3307 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
3308 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
3309 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
3310 }
3311 });
3312
3313 test('format', function (assert) {
3314 var a = [
3315 ['dddd, MMMM Do YYYY, h:mm:ss a', 'الأحد, فيفري 14 2010, 3:25:50 pm'],
3316 ['ddd, hA', 'أحد, 3PM'],
3317 ['M Mo MM MMMM MMM', '2 2 02 فيفري فيفري'],
3318 ['YYYY YY', '2010 10'],
3319 ['D Do DD', '14 14 14'],
3320 ['d do dddd ddd dd', '0 0 الأحد أحد ح'],
3321 ['DDD DDDo DDDD', '45 45 045'],
3322 ['w wo ww', '6 6 06'],
3323 ['h hh', '3 03'],
3324 ['H HH', '15 15'],
3325 ['m mm', '25 25'],
3326 ['s ss', '50 50'],
3327 ['a A', 'pm PM'],
3328 ['[the] DDDo [day of the year]', 'the 45 day of the year'],
3329 ['LT', '15:25'],
3330 ['LTS', '15:25:50'],
3331 ['L', '14/02/2010'],
3332 ['LL', '14 فيفري 2010'],
3333 ['LLL', '14 فيفري 2010 15:25'],
3334 ['LLLL', 'الأحد 14 فيفري 2010 15:25'],
3335 ['l', '14/2/2010'],
3336 ['ll', '14 فيفري 2010'],
3337 ['lll', '14 فيفري 2010 15:25'],
3338 ['llll', 'أحد 14 فيفري 2010 15:25']
3339 ],
3340 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
3341 i;
3342 for (i = 0; i < a.length; i++) {
3343 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
3344 }
3345 });
3346
3347 test('format ordinal', function (assert) {
3348 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
3349 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
3350 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
3351 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
3352 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
3353 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
3354 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
3355 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
3356 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
3357 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
3358
3359 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
3360 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
3361 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
3362 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
3363 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
3364 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
3365 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
3366 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
3367 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
3368 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
3369
3370 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
3371 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
3372 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
3373 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
3374 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
3375 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
3376 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
3377 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
3378 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
3379 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
3380
3381 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
3382 });
3383
3384 test('format month', function (assert) {
3385 var expected = 'جانفي جانفي_فيفري فيفري_مارس مارس_أفريل أفريل_ماي ماي_جوان جوان_جويلية جويلية_أوت أوت_سبتمبر سبتمبر_أكتوبر أكتوبر_نوفمبر نوفمبر_ديسمبر ديسمبر'.split('_'),
3386 i;
3387 for (i = 0; i < expected.length; i++) {
3388 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
3389 }
3390 });
3391
3392 test('format week', function (assert) {
3393 var expected = 'الأحد أحد ح_الإثنين إثنين ن_الثلاثاء ثلاثاء ث_الأربعاء أربعاء ر_الخميس خميس خ_الجمعة جمعة ج_السبت سبت س'.split('_'),
3394 i;
3395 for (i = 0; i < expected.length; i++) {
3396 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
3397 }
3398 });
3399
3400 test('from', function (assert) {
3401 var start = moment([2007, 1, 28]);
3402 assert.equal(start.from(moment([2007, 1, 28]).add({
3403 s: 44
3404 }), true), 'ثوان', '44 seconds = a few seconds');
3405 assert.equal(start.from(moment([2007, 1, 28]).add({
3406 s: 45
3407 }), true), 'دقيقة', '45 seconds = a minute');
3408 assert.equal(start.from(moment([2007, 1, 28]).add({
3409 s: 89
3410 }), true), 'دقيقة', '89 seconds = a minute');
3411 assert.equal(start.from(moment([2007, 1, 28]).add({
3412 s: 90
3413 }), true), '2 دقائق', '90 seconds = 2 minutes');
3414 assert.equal(start.from(moment([2007, 1, 28]).add({
3415 m: 44
3416 }), true), '44 دقائق', '44 minutes = 44 minutes');
3417 assert.equal(start.from(moment([2007, 1, 28]).add({
3418 m: 45
3419 }), true), 'ساعة', '45 minutes = an hour');
3420 assert.equal(start.from(moment([2007, 1, 28]).add({
3421 m: 89
3422 }), true), 'ساعة', '89 minutes = an hour');
3423 assert.equal(start.from(moment([2007, 1, 28]).add({
3424 m: 90
3425 }), true), '2 ساعات', '90 minutes = 2 hours');
3426 assert.equal(start.from(moment([2007, 1, 28]).add({
3427 h: 5
3428 }), true), '5 ساعات', '5 hours = 5 hours');
3429 assert.equal(start.from(moment([2007, 1, 28]).add({
3430 h: 21
3431 }), true), '21 ساعات', '21 hours = 21 hours');
3432 assert.equal(start.from(moment([2007, 1, 28]).add({
3433 h: 22
3434 }), true), 'يوم', '22 hours = a day');
3435 assert.equal(start.from(moment([2007, 1, 28]).add({
3436 h: 35
3437 }), true), 'يوم', '35 hours = a day');
3438 assert.equal(start.from(moment([2007, 1, 28]).add({
3439 h: 36
3440 }), true), '2 أيام', '36 hours = 2 days');
3441 assert.equal(start.from(moment([2007, 1, 28]).add({
3442 d: 1
3443 }), true), 'يوم', '1 day = a day');
3444 assert.equal(start.from(moment([2007, 1, 28]).add({
3445 d: 5
3446 }), true), '5 أيام', '5 days = 5 days');
3447 assert.equal(start.from(moment([2007, 1, 28]).add({
3448 d: 25
3449 }), true), '25 أيام', '25 days = 25 days');
3450 assert.equal(start.from(moment([2007, 1, 28]).add({
3451 d: 26
3452 }), true), 'شهر', '26 days = a month');
3453 assert.equal(start.from(moment([2007, 1, 28]).add({
3454 d: 30
3455 }), true), 'شهر', '30 days = a month');
3456 assert.equal(start.from(moment([2007, 1, 28]).add({
3457 d: 43
3458 }), true), 'شهر', '43 days = a month');
3459 assert.equal(start.from(moment([2007, 1, 28]).add({
3460 d: 46
3461 }), true), '2 أشهر', '46 days = 2 months');
3462 assert.equal(start.from(moment([2007, 1, 28]).add({
3463 d: 74
3464 }), true), '2 أشهر', '75 days = 2 months');
3465 assert.equal(start.from(moment([2007, 1, 28]).add({
3466 d: 76
3467 }), true), '3 أشهر', '76 days = 3 months');
3468 assert.equal(start.from(moment([2007, 1, 28]).add({
3469 M: 1
3470 }), true), 'شهر', '1 month = a month');
3471 assert.equal(start.from(moment([2007, 1, 28]).add({
3472 M: 5
3473 }), true), '5 أشهر', '5 months = 5 months');
3474 assert.equal(start.from(moment([2007, 1, 28]).add({
3475 d: 345
3476 }), true), 'سنة', '345 days = a year');
3477 assert.equal(start.from(moment([2007, 1, 28]).add({
3478 d: 548
3479 }), true), '2 سنوات', '548 days = 2 years');
3480 assert.equal(start.from(moment([2007, 1, 28]).add({
3481 y: 1
3482 }), true), 'سنة', '1 year = a year');
3483 assert.equal(start.from(moment([2007, 1, 28]).add({
3484 y: 5
3485 }), true), '5 سنوات', '5 years = 5 years');
3486 });
3487
3488 test('suffix', function (assert) {
3489 assert.equal(moment(30000).from(0), 'في ثوان', 'prefix');
3490 assert.equal(moment(0).from(30000), 'منذ ثوان', 'suffix');
3491 });
3492
3493 test('now from now', function (assert) {
3494 assert.equal(moment().fromNow(), 'منذ ثوان', 'now from now should display as in the past');
3495 });
3496
3497 test('fromNow', function (assert) {
3498 assert.equal(moment().add({
3499 s: 30
3500 }).fromNow(), 'في ثوان', 'in a few seconds');
3501 assert.equal(moment().add({
3502 d: 5
3503 }).fromNow(), 'في 5 أيام', 'in 5 days');
3504 });
3505
3506 test('calendar day', function (assert) {
3507 var a = moment().hours(12).minutes(0).seconds(0);
3508
3509 assert.equal(moment(a).calendar(), 'اليوم على الساعة 12:00', 'today at the same time');
3510 assert.equal(moment(a).add({m: 25}).calendar(), 'اليوم على الساعة 12:25', 'Now plus 25 min');
3511 assert.equal(moment(a).add({h: 1}).calendar(), 'اليوم على الساعة 13:00', 'Now plus 1 hour');
3512 assert.equal(moment(a).add({d: 1}).calendar(), 'غدا على الساعة 12:00', 'tomorrow at the same time');
3513 assert.equal(moment(a).subtract({h: 1}).calendar(), 'اليوم على الساعة 11:00', 'Now minus 1 hour');
3514 assert.equal(moment(a).subtract({d: 1}).calendar(), 'أمس على الساعة 12:00', 'yesterday at the same time');
3515 });
3516
3517 test('calendar next week', function (assert) {
3518 var i, m;
3519 for (i = 2; i < 7; i++) {
3520 m = moment().add({
3521 d: i
3522 });
3523 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days current time');
3524 m.hours(0).minutes(0).seconds(0).milliseconds(0);
3525 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days beginning of day');
3526 m.hours(23).minutes(59).seconds(59).milliseconds(999);
3527 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days end of day');
516f5f67
IC
3528 }
3529 });
3530
db71a655
KM
3531 test('calendar last week', function (assert) {
3532 var i, m;
3533 for (i = 2; i < 7; i++) {
3534 m = moment().subtract({
3535 d: i
3536 });
3537 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days current time');
3538 m.hours(0).minutes(0).seconds(0).milliseconds(0);
3539 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days beginning of day');
3540 m.hours(23).minutes(59).seconds(59).milliseconds(999);
3541 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days end of day');
3542 }
3543 });
516f5f67 3544
db71a655
KM
3545 test('calendar all else', function (assert) {
3546 var weeksAgo = moment().subtract({
3547 w: 1
3548 }),
3549 weeksFromNow = moment().add({
3550 w: 1
3551 });
516f5f67 3552
db71a655
KM
3553 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
3554 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 3555
db71a655
KM
3556 weeksAgo = moment().subtract({
3557 w: 2
3558 });
73f3c911 3559 weeksFromNow = moment().add({
db71a655 3560 w: 2
73f3c911 3561 });
516f5f67 3562
db71a655
KM
3563 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
3564 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
516f5f67 3565 });
73f3c911 3566
db71a655
KM
3567 test('weeks year starting sunday formatted', function (assert) {
3568 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52', 'Jan 1 2012 should be week 52');
3569 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1', 'Jan 2 2012 should be week 1');
3570 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1', 'Jan 8 2012 should be week 1');
3571 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2', 'Jan 9 2012 should be week 2');
3572 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2', 'Jan 15 2012 should be week 2');
3573 });
73f3c911
IC
3574
3575})));
25cc720f 3576
516f5f67 3577
c74a101d
IC
3578;(function (global, factory) {
3579 typeof exports === 'object' && typeof module !== 'undefined'
3580 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
3581 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
3582 factory(global.moment)
73f3c911 3583}(this, (function (moment) { 'use strict';
516f5f67 3584
db71a655
KM
3585 function each(array, callback) {
3586 var i;
3587 for (i = 0; i < array.length; i++) {
3588 callback(array[i], i, array);
3589 }
b135bf1a
IC
3590 }
3591
c58511b9
KM
3592 function setupDeprecationHandler(test, moment$$1, scope) {
3593 test._expectedDeprecations = null;
3594 test._observedDeprecations = null;
3595 test._oldSupress = moment$$1.suppressDeprecationWarnings;
3596 moment$$1.suppressDeprecationWarnings = true;
3597 test.expectedDeprecations = function () {
3598 test._expectedDeprecations = arguments;
3599 test._observedDeprecations = [];
3600 };
3601 moment$$1.deprecationHandler = function (name, msg) {
3602 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
3603 if (deprecationId === -1) {
3604 throw new Error('Unexpected deprecation thrown name=' +
3605 name + ' msg=' + msg);
3606 }
3607 test._observedDeprecations[deprecationId] = 1;
3608 };
3609 }
3610
3611 function teardownDeprecationHandler(test, moment$$1, scope) {
3612 moment$$1.suppressDeprecationWarnings = test._oldSupress;
3613
3614 if (test._expectedDeprecations != null) {
3615 var missedDeprecations = [];
3616 each(test._expectedDeprecations, function (deprecationPattern, id) {
3617 if (test._observedDeprecations[id] !== 1) {
3618 missedDeprecations.push(deprecationPattern);
3619 }
3620 });
3621 if (missedDeprecations.length !== 0) {
3622 throw new Error('Expected deprecation warnings did not happen: ' +
3623 missedDeprecations.join(' '));
3624 }
3625 }
3626 }
3627
3628 function matchedDeprecation(name, msg, deprecations) {
3629 if (deprecations == null) {
3630 return -1;
3631 }
3632 for (var i = 0; i < deprecations.length; ++i) {
3633 if (name != null && name === deprecations[i]) {
3634 return i;
3635 }
3636 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
3637 return i;
3638 }
3639 }
3640 return -1;
3641 }
3642
3643 /*global QUnit:false*/
3644
3645 var test = QUnit.test;
3646
db71a655
KM
3647 function objectKeys(obj) {
3648 if (Object.keys) {
3649 return Object.keys(obj);
3650 } else {
3651 // IE8
3652 var res = [], i;
3653 for (i in obj) {
3654 if (obj.hasOwnProperty(i)) {
3655 res.push(i);
3656 }
b135bf1a 3657 }
db71a655 3658 return res;
b135bf1a 3659 }
b135bf1a
IC
3660 }
3661
db71a655 3662 // Pick the first defined of two or three arguments.
b135bf1a 3663
db71a655
KM
3664 function defineCommonLocaleTests(locale, options) {
3665 test('lenient day of month ordinal parsing', function (assert) {
3666 var i, ordinalStr, testMoment;
3667 for (i = 1; i <= 31; ++i) {
3668 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
3669 testMoment = moment(ordinalStr, 'YYYY MM Do');
3670 assert.equal(testMoment.year(), 2014,
3671 'lenient day of month ordinal parsing ' + i + ' year check');
3672 assert.equal(testMoment.month(), 0,
3673 'lenient day of month ordinal parsing ' + i + ' month check');
3674 assert.equal(testMoment.date(), i,
3675 'lenient day of month ordinal parsing ' + i + ' date check');
3676 }
3677 });
b135bf1a 3678
db71a655
KM
3679 test('lenient day of month ordinal parsing of number', function (assert) {
3680 var i, testMoment;
3681 for (i = 1; i <= 31; ++i) {
3682 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
3683 assert.equal(testMoment.year(), 2014,
3684 'lenient day of month ordinal parsing of number ' + i + ' year check');
3685 assert.equal(testMoment.month(), 0,
3686 'lenient day of month ordinal parsing of number ' + i + ' month check');
3687 assert.equal(testMoment.date(), i,
3688 'lenient day of month ordinal parsing of number ' + i + ' date check');
3689 }
3690 });
b135bf1a 3691
db71a655
KM
3692 test('strict day of month ordinal parsing', function (assert) {
3693 var i, ordinalStr, testMoment;
3694 for (i = 1; i <= 31; ++i) {
3695 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
3696 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
3697 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
3698 }
3699 });
b135bf1a 3700
db71a655
KM
3701 test('meridiem invariant', function (assert) {
3702 var h, m, t1, t2;
3703 for (h = 0; h < 24; ++h) {
3704 for (m = 0; m < 60; m += 15) {
3705 t1 = moment.utc([2000, 0, 1, h, m]);
3706 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
3707 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
3708 'meridiem at ' + t1.format('HH:mm'));
3709 }
3710 }
3711 });
3712
3713 test('date format correctness', function (assert) {
3714 var data, tokens;
3715 data = moment.localeData()._longDateFormat;
3716 tokens = objectKeys(data);
3717 each(tokens, function (srchToken) {
3718 // Check each format string to make sure it does not contain any
3719 // tokens that need to be expanded.
3720 each(tokens, function (baseToken) {
3721 // strip escaped sequences
3722 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
3723 assert.equal(false, !!~format.indexOf(srchToken),
3724 'contains ' + srchToken + ' in ' + baseToken);
3725 });
b135bf1a
IC
3726 });
3727 });
d6651c21 3728
db71a655
KM
3729 test('month parsing correctness', function (assert) {
3730 var i, m;
3731
3732 if (locale === 'tr') {
3733 // I can't fix it :(
c58511b9 3734 assert.expect(0);
db71a655
KM
3735 return;
3736 }
3737 function tester(format) {
3738 var r;
3739 r = moment(m.format(format), format);
3740 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
3741 if (locale !== 'ka') {
3742 r = moment(m.format(format).toLocaleUpperCase(), format);
3743 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
3744 }
db71a655
KM
3745 r = moment(m.format(format).toLocaleLowerCase(), format);
3746 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
3747
3748 r = moment(m.format(format), format, true);
3749 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
3750 if (locale !== 'ka') {
3751 r = moment(m.format(format).toLocaleUpperCase(), format, true);
3752 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
3753 }
db71a655
KM
3754 r = moment(m.format(format).toLocaleLowerCase(), format, true);
3755 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
3756 }
3757
3758 for (i = 0; i < 12; ++i) {
3759 m = moment([2015, i, 15, 18]);
3760 tester('MMM');
3761 tester('MMM.');
3762 tester('MMMM');
3763 tester('MMMM.');
3764 }
3765 });
d6651c21 3766
db71a655
KM
3767 test('weekday parsing correctness', function (assert) {
3768 var i, m;
3769
96d0d679 3770 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
3771 // tr, az: There is a lower-case letter (ı), that converted to
3772 // upper then lower changes to i
3773 // ro: there is the letter ț which behaves weird under IE8
3774 // mt: letter Ħ
96d0d679 3775 // ga: month with spaces
c58511b9 3776 assert.expect(0);
db71a655
KM
3777 return;
3778 }
3779 function tester(format) {
3780 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
3781 r = moment(m.format(format), format);
3782 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
3783 if (locale !== 'ka') {
3784 r = moment(m.format(format).toLocaleUpperCase(), format);
3785 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
3786 }
db71a655
KM
3787 r = moment(m.format(format).toLocaleLowerCase(), format);
3788 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
3789 r = moment(m.format(format), format, true);
3790 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
3791 if (locale !== 'ka') {
3792 r = moment(m.format(format).toLocaleUpperCase(), format, true);
3793 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
3794 }
db71a655
KM
3795 r = moment(m.format(format).toLocaleLowerCase(), format, true);
3796 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
3797 }
3798
3799 for (i = 0; i < 7; ++i) {
3800 m = moment.utc([2015, 0, i + 1, 18]);
3801 tester('dd');
3802 tester('ddd');
3803 tester('dddd');
3804 }
3805 });
d6651c21 3806
db71a655
KM
3807 test('valid localeData', function (assert) {
3808 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
3809 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
3810 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
3811 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
3812 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
3813 });
96d0d679
KM
3814
3815 test('localeData weekdays can localeSort', function (assert) {
3816 var weekdays = moment().localeData().weekdays();
3817 var weekdaysShort = moment().localeData().weekdaysShort();
3818 var weekdaysMin = moment().localeData().weekdaysMin();
3819 var shift = moment().localeData()._week.dow;
3820 assert.deepEqual(
3821 moment().localeData().weekdays(true),
3822 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
3823 'weekdays should localeSort');
3824 assert.deepEqual(
3825 moment().localeData().weekdaysShort(true),
3826 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
3827 'weekdaysShort should localeSort');
3828 assert.deepEqual(
3829 moment().localeData().weekdaysMin(true),
3830 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
3831 'weekdaysMin should localeSort');
3832 });
db71a655 3833 }
d6651c21 3834
db71a655 3835 /*global QUnit:false*/
516f5f67 3836
db71a655
KM
3837 function localeModule (name, lifecycle) {
3838 QUnit.module('locale:' + name, {
c58511b9 3839 beforeEach : function () {
db71a655
KM
3840 moment.locale(name);
3841 moment.createFromInputFallback = function (config) {
3842 throw new Error('input not handled by moment: ' + config._i);
3843 };
3844 setupDeprecationHandler(test, moment, 'locale');
3845 if (lifecycle && lifecycle.setup) {
3846 lifecycle.setup();
3847 }
3848 },
c58511b9 3849 afterEach : function () {
db71a655
KM
3850 moment.locale('en');
3851 teardownDeprecationHandler(test, moment, 'locale');
3852 if (lifecycle && lifecycle.teardown) {
3853 lifecycle.teardown();
3854 }
516f5f67
IC
3855 }
3856 });
db71a655
KM
3857 defineCommonLocaleTests(name, -1, -1);
3858 }
3859
3860 localeModule('ar');
3861
3862 var months = [
3863 'يناير',
3864 'فبراير',
3865 'مارس',
3866 'أبريل',
3867 'مايو',
3868 'يونيو',
3869 'يوليو',
3870 'أغسطس',
3871 'سبتمبر',
3872 'أكتوبر',
3873 'نوفمبر',
3874 'ديسمبر'
3875 ];
516f5f67 3876
db71a655
KM
3877 test('parse', function (assert) {
3878 var tests = months, i;
3879 function equalTest(input, mmm, i) {
3880 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1) + ' instead is month ' + moment(input, mmm).month());
3881 }
3882 for (i = 0; i < 12; i++) {
3883 equalTest(tests[i], 'MMM', i);
3884 equalTest(tests[i], 'MMM', i);
3885 equalTest(tests[i], 'MMMM', i);
3886 equalTest(tests[i], 'MMMM', i);
3887 equalTest(tests[i].toLocaleLowerCase(), 'MMMM', i);
3888 equalTest(tests[i].toLocaleLowerCase(), 'MMMM', i);
3889 equalTest(tests[i].toLocaleUpperCase(), 'MMMM', i);
3890 equalTest(tests[i].toLocaleUpperCase(), 'MMMM', i);
3891 }
3892 });
3893
3894 test('format', function (assert) {
3895 var a = [
3896 ['dddd, MMMM Do YYYY, h:mm:ss a', 'الأحد، فبراير ١٤ ٢٠١٠، ٣:٢٥:٥٠ م'],
3897 ['ddd, hA', 'أحد، ٣م'],
3898 ['M Mo MM MMMM MMM', '٢ ٢ ٠٢ فبراير فبراير'],
3899 ['YYYY YY', '٢٠١٠ ١٠'],
3900 ['D Do DD', '١٤ ١٤ ١٤'],
3901 ['d do dddd ddd dd', '٠ ٠ الأحد أحد ح'],
3902 ['DDD DDDo DDDD', '٤٥ ٤٥ ٠٤٥'],
3903 ['w wo ww', '٨ ٨ ٠٨'],
3904 ['h hh', '٣ ٠٣'],
3905 ['H HH', '١٥ ١٥'],
3906 ['m mm', '٢٥ ٢٥'],
3907 ['s ss', '٥٠ ٥٠'],
3908 ['a A', 'م م'],
3909 ['[the] DDDo [day of the year]', 'the ٤٥ day of the year'],
3910 ['LT', '١٥:٢٥'],
3911 ['LTS', '١٥:٢٥:٥٠'],
3912 ['L', '١٤/\u200f٢/\u200f٢٠١٠'],
3913 ['LL', '١٤ فبراير ٢٠١٠'],
3914 ['LLL', '١٤ فبراير ٢٠١٠ ١٥:٢٥'],
3915 ['LLLL', 'الأحد ١٤ فبراير ٢٠١٠ ١٥:٢٥'],
3916 ['l', '١٤/\u200f٢/\u200f٢٠١٠'],
3917 ['ll', '١٤ فبراير ٢٠١٠'],
3918 ['lll', '١٤ فبراير ٢٠١٠ ١٥:٢٥'],
3919 ['llll', 'أحد ١٤ فبراير ٢٠١٠ ١٥:٢٥']
3920 ],
3921 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
3922 i;
3923 for (i = 0; i < a.length; i++) {
3924 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
3925 }
3926 });
3927
3928 test('format ordinal', function (assert) {
3929 assert.equal(moment([2011, 0, 1]).format('DDDo'), '١', '1');
3930 assert.equal(moment([2011, 0, 2]).format('DDDo'), '٢', '2');
3931 assert.equal(moment([2011, 0, 3]).format('DDDo'), '٣', '3');
3932 assert.equal(moment([2011, 0, 4]).format('DDDo'), '٤', '4');
3933 assert.equal(moment([2011, 0, 5]).format('DDDo'), '٥', '5');
3934 assert.equal(moment([2011, 0, 6]).format('DDDo'), '٦', '6');
3935 assert.equal(moment([2011, 0, 7]).format('DDDo'), '٧', '7');
3936 assert.equal(moment([2011, 0, 8]).format('DDDo'), '٨', '8');
3937 assert.equal(moment([2011, 0, 9]).format('DDDo'), '٩', '9');
3938 assert.equal(moment([2011, 0, 10]).format('DDDo'), '١٠', '10');
3939
3940 assert.equal(moment([2011, 0, 11]).format('DDDo'), '١١', '11');
3941 assert.equal(moment([2011, 0, 12]).format('DDDo'), '١٢', '12');
3942 assert.equal(moment([2011, 0, 13]).format('DDDo'), '١٣', '13');
3943 assert.equal(moment([2011, 0, 14]).format('DDDo'), '١٤', '14');
3944 assert.equal(moment([2011, 0, 15]).format('DDDo'), '١٥', '15');
3945 assert.equal(moment([2011, 0, 16]).format('DDDo'), '١٦', '16');
3946 assert.equal(moment([2011, 0, 17]).format('DDDo'), '١٧', '17');
3947 assert.equal(moment([2011, 0, 18]).format('DDDo'), '١٨', '18');
3948 assert.equal(moment([2011, 0, 19]).format('DDDo'), '١٩', '19');
3949 assert.equal(moment([2011, 0, 20]).format('DDDo'), '٢٠', '20');
3950
3951 assert.equal(moment([2011, 0, 21]).format('DDDo'), '٢١', '21');
3952 assert.equal(moment([2011, 0, 22]).format('DDDo'), '٢٢', '22');
3953 assert.equal(moment([2011, 0, 23]).format('DDDo'), '٢٣', '23');
3954 assert.equal(moment([2011, 0, 24]).format('DDDo'), '٢٤', '24');
3955 assert.equal(moment([2011, 0, 25]).format('DDDo'), '٢٥', '25');
3956 assert.equal(moment([2011, 0, 26]).format('DDDo'), '٢٦', '26');
3957 assert.equal(moment([2011, 0, 27]).format('DDDo'), '٢٧', '27');
3958 assert.equal(moment([2011, 0, 28]).format('DDDo'), '٢٨', '28');
3959 assert.equal(moment([2011, 0, 29]).format('DDDo'), '٢٩', '29');
3960 assert.equal(moment([2011, 0, 30]).format('DDDo'), '٣٠', '30');
3961
3962 assert.equal(moment([2011, 0, 31]).format('DDDo'), '٣١', '31');
3963 });
3964
3965 test('format month', function (assert) {
3966 var expected = months, i;
3967 for (i = 0; i < expected.length; i++) {
3968 assert.equal(moment([2011, i, 1]).format('MMMM'), expected[i], expected[i]);
3969 assert.equal(moment([2011, i, 1]).format('MMM'), expected[i], expected[i]);
3970 }
3971 });
3972
3973 test('format week', function (assert) {
3974 var expected = 'الأحد أحد ح_الإثنين إثنين ن_الثلاثاء ثلاثاء ث_الأربعاء أربعاء ر_الخميس خميس خ_الجمعة جمعة ج_السبت سبت س'.split('_'), i;
3975 for (i = 0; i < expected.length; i++) {
3976 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
3977 }
3978 });
3979
3980 test('from', function (assert) {
3981 var start = moment([2007, 1, 28]);
3982 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), '٤٤ ثانية', '44 seconds = a few seconds');
3983 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'دقيقة واحدة', '45 seconds = a minute');
3984 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'دقيقة واحدة', '89 seconds = a minute');
3985 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), 'دقيقتان', '90 seconds = 2 minutes');
3986 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '٤٤ دقيقة', '44 minutes = 44 minutes');
3987 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ساعة واحدة', '45 minutes = an hour');
3988 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ساعة واحدة', '89 minutes = an hour');
3989 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), 'ساعتان', '90 minutes = 2 hours');
3990 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '٥ ساعات', '5 hours = 5 hours');
3991 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '٢١ ساعة', '21 hours = 21 hours');
3992 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'يوم واحد', '22 hours = a day');
3993 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'يوم واحد', '35 hours = a day');
3994 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), 'يومان', '36 hours = 2 days');
3995 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'يوم واحد', '1 day = a day');
3996 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '٥ أيام', '5 days = 5 days');
3997 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '٢٥ يومًا', '25 days = 25 days');
3998 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'شهر واحد', '26 days = a month');
3999 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'شهر واحد', '30 days = a month');
4000 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'شهر واحد', '43 days = a month');
4001 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), 'شهران', '46 days = 2 months');
4002 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), 'شهران', '75 days = 2 months');
4003 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '٣ أشهر', '76 days = 3 months');
4004 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'شهر واحد', '1 month = a month');
4005 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '٥ أشهر', '5 months = 5 months');
4006 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'عام واحد', '345 days = a year');
4007 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), 'عامان', '548 days = 2 years');
4008 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'عام واحد', '1 year = a year');
4009 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '٥ أعوام', '5 years = 5 years');
4010 });
4011
4012 test('suffix', function (assert) {
4013 assert.equal(moment(30000).from(0), 'بعد ٣٠ ثانية', 'prefix');
4014 assert.equal(moment(0).from(30000), 'منذ ٣٠ ثانية', 'suffix');
4015 });
4016
4017 test('now from now', function (assert) {
4018 assert.equal(moment().fromNow(), 'منذ ثانية واحدة', 'now from now should display as in the past');
4019 });
4020
4021 test('fromNow', function (assert) {
4022 assert.equal(moment().add({s: 30}).fromNow(), 'بعد ٣٠ ثانية', 'in a few seconds');
4023 assert.equal(moment().add({d: 5}).fromNow(), 'بعد ٥ أيام', 'in 5 days');
4024 });
4025
4026 test('calendar day', function (assert) {
4027 var a = moment().hours(12).minutes(0).seconds(0);
4028
4029 assert.equal(moment(a).calendar(), 'اليوم عند الساعة ١٢:٠٠', 'today at the same time');
4030 assert.equal(moment(a).add({m: 25}).calendar(), 'اليوم عند الساعة ١٢:٢٥', 'Now plus 25 min');
4031 assert.equal(moment(a).add({h: 1}).calendar(), 'اليوم عند الساعة ١٣:٠٠', 'Now plus 1 hour');
4032 assert.equal(moment(a).add({d: 1}).calendar(), 'غدًا عند الساعة ١٢:٠٠', 'tomorrow at the same time');
4033 assert.equal(moment(a).subtract({h: 1}).calendar(), 'اليوم عند الساعة ١١:٠٠', 'Now minus 1 hour');
4034 assert.equal(moment(a).subtract({d: 1}).calendar(), 'أمس عند الساعة ١٢:٠٠', 'yesterday at the same time');
4035 });
4036
4037 test('calendar next week', function (assert) {
4038 var i, m;
4039 for (i = 2; i < 7; i++) {
4040 m = moment().add({d: i});
4041 assert.equal(m.calendar(), m.format('dddd [عند الساعة] LT'), 'Today + ' + i + ' days current time');
4042 m.hours(0).minutes(0).seconds(0).milliseconds(0);
4043 assert.equal(m.calendar(), m.format('dddd [عند الساعة] LT'), 'Today + ' + i + ' days beginning of day');
4044 m.hours(23).minutes(59).seconds(59).milliseconds(999);
4045 assert.equal(m.calendar(), m.format('dddd [عند الساعة] LT'), 'Today + ' + i + ' days end of day');
516f5f67 4046 }
db71a655
KM
4047 });
4048
4049 test('calendar last week', function (assert) {
4050 var i, m;
4051 for (i = 2; i < 7; i++) {
4052 m = moment().subtract({d: i});
4053 assert.equal(m.calendar(), m.format('dddd [عند الساعة] LT'), 'Today - ' + i + ' days current time');
4054 m.hours(0).minutes(0).seconds(0).milliseconds(0);
4055 assert.equal(m.calendar(), m.format('dddd [عند الساعة] LT'), 'Today - ' + i + ' days beginning of day');
4056 m.hours(23).minutes(59).seconds(59).milliseconds(999);
4057 assert.equal(m.calendar(), m.format('dddd [عند الساعة] LT'), 'Today - ' + i + ' days end of day');
516f5f67 4058 }
db71a655 4059 });
516f5f67 4060
db71a655
KM
4061 test('calendar all else', function (assert) {
4062 var weeksAgo = moment().subtract({w: 1}),
4063 weeksFromNow = moment().add({w: 1});
516f5f67 4064
db71a655
KM
4065 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
4066 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 4067
db71a655
KM
4068 weeksAgo = moment().subtract({w: 2});
4069 weeksFromNow = moment().add({w: 2});
516f5f67 4070
db71a655
KM
4071 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
4072 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
4073 });
4074
4075 test('weeks year starting wednesday custom', function (assert) {
4076 assert.equal(moment('2003 1 6', 'gggg w d').format('YYYY-MM-DD'), '٢٠٠٢-١٢-٢٨', 'Week 1 of 2003 should be Dec 28 2002');
4077 assert.equal(moment('2003 1 0', 'gggg w e').format('YYYY-MM-DD'), '٢٠٠٢-١٢-٢٨', 'Week 1 of 2003 should be Dec 28 2002');
4078 assert.equal(moment('2003 1 6', 'gggg w d').format('gggg w d'), '٢٠٠٣ ١ ٦', 'Saturday of week 1 of 2003 parsed should be formatted as 2003 1 6');
4079 assert.equal(moment('2003 1 0', 'gggg w e').format('gggg w e'), '٢٠٠٣ ١ ٠', '1st day of week 1 of 2003 parsed should be formatted as 2003 1 0');
4080 });
4081
4082 test('weeks year starting sunday formatted', function (assert) {
4083 assert.equal(moment([2011, 11, 31]).format('w ww wo'), '١ ٠١ ١', 'Dec 31 2011 should be week 1');
4084 assert.equal(moment([2012, 0, 6]).format('w ww wo'), '١ ٠١ ١', 'Jan 6 2012 should be week 1');
4085 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '٢ ٠٢ ٢', 'Jan 7 2012 should be week 2');
4086 assert.equal(moment([2012, 0, 13]).format('w ww wo'), '٢ ٠٢ ٢', 'Jan 13 2012 should be week 2');
4087 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '٣ ٠٣ ٣', 'Jan 14 2012 should be week 3');
4088 });
4089
4090 test('no leading zeros in long date formats', function (assert) {
4091 var i, j, longDateStr, shortDateStr;
4092 for (i = 1; i <= 9; ++i) {
4093 for (j = 1; j <= 9; ++j) {
4094 longDateStr = moment([2014, i, j]).format('L');
4095 shortDateStr = moment([2014, i, j]).format('l');
4096 assert.equal(longDateStr, shortDateStr, 'should not have leading zeros in month or day');
73f3c911 4097 }
db71a655
KM
4098 }
4099 });
4100
4101 // locale-specific
4102 test('ar strict mode parsing works', function (assert) {
4103 var m, formattedDate;
4104 m = moment().locale('ar');
4105 formattedDate = m.format('l');
4106 assert.equal(moment.utc(formattedDate, 'l', 'ar', false).isValid(), true, 'Non-strict parsing works');
4107 assert.equal(moment.utc(formattedDate, 'l', 'ar', true).isValid(), true,'Strict parsing must work');
4108 });
9483e2a4 4109
73f3c911
IC
4110})));
4111
516f5f67 4112
c74a101d
IC
4113;(function (global, factory) {
4114 typeof exports === 'object' && typeof module !== 'undefined'
4115 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
4116 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
4117 factory(global.moment)
73f3c911 4118}(this, (function (moment) { 'use strict';
516f5f67 4119
db71a655
KM
4120 function each(array, callback) {
4121 var i;
4122 for (i = 0; i < array.length; i++) {
4123 callback(array[i], i, array);
4124 }
b135bf1a
IC
4125 }
4126
c58511b9
KM
4127 function setupDeprecationHandler(test, moment$$1, scope) {
4128 test._expectedDeprecations = null;
4129 test._observedDeprecations = null;
4130 test._oldSupress = moment$$1.suppressDeprecationWarnings;
4131 moment$$1.suppressDeprecationWarnings = true;
4132 test.expectedDeprecations = function () {
4133 test._expectedDeprecations = arguments;
4134 test._observedDeprecations = [];
4135 };
4136 moment$$1.deprecationHandler = function (name, msg) {
4137 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
4138 if (deprecationId === -1) {
4139 throw new Error('Unexpected deprecation thrown name=' +
4140 name + ' msg=' + msg);
4141 }
4142 test._observedDeprecations[deprecationId] = 1;
4143 };
4144 }
4145
4146 function teardownDeprecationHandler(test, moment$$1, scope) {
4147 moment$$1.suppressDeprecationWarnings = test._oldSupress;
4148
4149 if (test._expectedDeprecations != null) {
4150 var missedDeprecations = [];
4151 each(test._expectedDeprecations, function (deprecationPattern, id) {
4152 if (test._observedDeprecations[id] !== 1) {
4153 missedDeprecations.push(deprecationPattern);
4154 }
4155 });
4156 if (missedDeprecations.length !== 0) {
4157 throw new Error('Expected deprecation warnings did not happen: ' +
4158 missedDeprecations.join(' '));
4159 }
4160 }
4161 }
4162
4163 function matchedDeprecation(name, msg, deprecations) {
4164 if (deprecations == null) {
4165 return -1;
4166 }
4167 for (var i = 0; i < deprecations.length; ++i) {
4168 if (name != null && name === deprecations[i]) {
4169 return i;
4170 }
4171 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
4172 return i;
4173 }
4174 }
4175 return -1;
4176 }
4177
4178 /*global QUnit:false*/
4179
4180 var test = QUnit.test;
4181
db71a655
KM
4182 function objectKeys(obj) {
4183 if (Object.keys) {
4184 return Object.keys(obj);
4185 } else {
4186 // IE8
4187 var res = [], i;
4188 for (i in obj) {
4189 if (obj.hasOwnProperty(i)) {
4190 res.push(i);
4191 }
b135bf1a 4192 }
db71a655 4193 return res;
b135bf1a
IC
4194 }
4195 }
4196
db71a655 4197 // Pick the first defined of two or three arguments.
b135bf1a 4198
db71a655
KM
4199 function defineCommonLocaleTests(locale, options) {
4200 test('lenient day of month ordinal parsing', function (assert) {
4201 var i, ordinalStr, testMoment;
4202 for (i = 1; i <= 31; ++i) {
4203 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
4204 testMoment = moment(ordinalStr, 'YYYY MM Do');
4205 assert.equal(testMoment.year(), 2014,
4206 'lenient day of month ordinal parsing ' + i + ' year check');
4207 assert.equal(testMoment.month(), 0,
4208 'lenient day of month ordinal parsing ' + i + ' month check');
4209 assert.equal(testMoment.date(), i,
4210 'lenient day of month ordinal parsing ' + i + ' date check');
4211 }
4212 });
b135bf1a 4213
db71a655
KM
4214 test('lenient day of month ordinal parsing of number', function (assert) {
4215 var i, testMoment;
4216 for (i = 1; i <= 31; ++i) {
4217 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
4218 assert.equal(testMoment.year(), 2014,
4219 'lenient day of month ordinal parsing of number ' + i + ' year check');
4220 assert.equal(testMoment.month(), 0,
4221 'lenient day of month ordinal parsing of number ' + i + ' month check');
4222 assert.equal(testMoment.date(), i,
4223 'lenient day of month ordinal parsing of number ' + i + ' date check');
4224 }
4225 });
b135bf1a 4226
db71a655
KM
4227 test('strict day of month ordinal parsing', function (assert) {
4228 var i, ordinalStr, testMoment;
4229 for (i = 1; i <= 31; ++i) {
4230 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
4231 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
4232 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
4233 }
4234 });
b135bf1a 4235
db71a655
KM
4236 test('meridiem invariant', function (assert) {
4237 var h, m, t1, t2;
4238 for (h = 0; h < 24; ++h) {
4239 for (m = 0; m < 60; m += 15) {
4240 t1 = moment.utc([2000, 0, 1, h, m]);
4241 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
4242 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
4243 'meridiem at ' + t1.format('HH:mm'));
4244 }
4245 }
4246 });
4247
4248 test('date format correctness', function (assert) {
4249 var data, tokens;
4250 data = moment.localeData()._longDateFormat;
4251 tokens = objectKeys(data);
4252 each(tokens, function (srchToken) {
4253 // Check each format string to make sure it does not contain any
4254 // tokens that need to be expanded.
4255 each(tokens, function (baseToken) {
4256 // strip escaped sequences
4257 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
4258 assert.equal(false, !!~format.indexOf(srchToken),
4259 'contains ' + srchToken + ' in ' + baseToken);
4260 });
b135bf1a
IC
4261 });
4262 });
d6651c21 4263
db71a655
KM
4264 test('month parsing correctness', function (assert) {
4265 var i, m;
4266
4267 if (locale === 'tr') {
4268 // I can't fix it :(
c58511b9 4269 assert.expect(0);
db71a655
KM
4270 return;
4271 }
4272 function tester(format) {
4273 var r;
4274 r = moment(m.format(format), format);
4275 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
4276 if (locale !== 'ka') {
4277 r = moment(m.format(format).toLocaleUpperCase(), format);
4278 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
4279 }
db71a655
KM
4280 r = moment(m.format(format).toLocaleLowerCase(), format);
4281 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
4282
4283 r = moment(m.format(format), format, true);
4284 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
4285 if (locale !== 'ka') {
4286 r = moment(m.format(format).toLocaleUpperCase(), format, true);
4287 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
4288 }
db71a655
KM
4289 r = moment(m.format(format).toLocaleLowerCase(), format, true);
4290 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
4291 }
4292
4293 for (i = 0; i < 12; ++i) {
4294 m = moment([2015, i, 15, 18]);
4295 tester('MMM');
4296 tester('MMM.');
4297 tester('MMMM');
4298 tester('MMMM.');
4299 }
4300 });
d6651c21 4301
db71a655
KM
4302 test('weekday parsing correctness', function (assert) {
4303 var i, m;
4304
96d0d679 4305 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
4306 // tr, az: There is a lower-case letter (ı), that converted to
4307 // upper then lower changes to i
4308 // ro: there is the letter ț which behaves weird under IE8
4309 // mt: letter Ħ
96d0d679 4310 // ga: month with spaces
c58511b9 4311 assert.expect(0);
db71a655
KM
4312 return;
4313 }
4314 function tester(format) {
4315 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
4316 r = moment(m.format(format), format);
4317 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
4318 if (locale !== 'ka') {
4319 r = moment(m.format(format).toLocaleUpperCase(), format);
4320 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
4321 }
db71a655
KM
4322 r = moment(m.format(format).toLocaleLowerCase(), format);
4323 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
4324 r = moment(m.format(format), format, true);
4325 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
4326 if (locale !== 'ka') {
4327 r = moment(m.format(format).toLocaleUpperCase(), format, true);
4328 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
4329 }
db71a655
KM
4330 r = moment(m.format(format).toLocaleLowerCase(), format, true);
4331 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
4332 }
4333
4334 for (i = 0; i < 7; ++i) {
4335 m = moment.utc([2015, 0, i + 1, 18]);
4336 tester('dd');
4337 tester('ddd');
4338 tester('dddd');
4339 }
4340 });
d6651c21 4341
db71a655
KM
4342 test('valid localeData', function (assert) {
4343 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
4344 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
4345 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
4346 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
4347 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
4348 });
96d0d679
KM
4349
4350 test('localeData weekdays can localeSort', function (assert) {
4351 var weekdays = moment().localeData().weekdays();
4352 var weekdaysShort = moment().localeData().weekdaysShort();
4353 var weekdaysMin = moment().localeData().weekdaysMin();
4354 var shift = moment().localeData()._week.dow;
4355 assert.deepEqual(
4356 moment().localeData().weekdays(true),
4357 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
4358 'weekdays should localeSort');
4359 assert.deepEqual(
4360 moment().localeData().weekdaysShort(true),
4361 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
4362 'weekdaysShort should localeSort');
4363 assert.deepEqual(
4364 moment().localeData().weekdaysMin(true),
4365 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
4366 'weekdaysMin should localeSort');
4367 });
db71a655 4368 }
d6651c21 4369
db71a655 4370 /*global QUnit:false*/
c74a101d 4371
db71a655
KM
4372 function localeModule (name, lifecycle) {
4373 QUnit.module('locale:' + name, {
c58511b9 4374 beforeEach : function () {
db71a655
KM
4375 moment.locale(name);
4376 moment.createFromInputFallback = function (config) {
4377 throw new Error('input not handled by moment: ' + config._i);
4378 };
4379 setupDeprecationHandler(test, moment, 'locale');
4380 if (lifecycle && lifecycle.setup) {
4381 lifecycle.setup();
4382 }
4383 },
c58511b9 4384 afterEach : function () {
db71a655
KM
4385 moment.locale('en');
4386 teardownDeprecationHandler(test, moment, 'locale');
4387 if (lifecycle && lifecycle.teardown) {
4388 lifecycle.teardown();
4389 }
516f5f67
IC
4390 }
4391 });
db71a655
KM
4392 defineCommonLocaleTests(name, -1, -1);
4393 }
4394
4395 localeModule('az');
4396
4397 test('parse', function (assert) {
4398 var tests = 'yanvar yan_fevral fev_mart mar_Aprel apr_may may_iyun iyn_iyul iyl_Avqust avq_sentyabr sen_oktyabr okt_noyabr noy_dekabr dek'.split('_'), i;
4399 function equalTest(input, mmm, i) {
4400 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
4401 }
4402 for (i = 0; i < 12; i++) {
4403 tests[i] = tests[i].split(' ');
4404 equalTest(tests[i][0], 'MMM', i);
4405 equalTest(tests[i][1], 'MMM', i);
4406 equalTest(tests[i][0], 'MMMM', i);
4407 equalTest(tests[i][1], 'MMMM', i);
4408 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
4409 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
4410 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
4411 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
4412 }
4413 });
4414
4415 test('format', function (assert) {
4416 var a = [
4417 ['dddd, D MMMM YYYY, HH:mm:ss', 'Bazar, 14 fevral 2010, 15:25:50'],
4418 ['ddd, A h', 'Baz, gündüz 3'],
4419 ['M Mo MM MMMM MMM', '2 2-nci 02 fevral fev'],
4420 ['YYYY YY', '2010 10'],
4421 ['D Do DD', '14 14-üncü 14'],
4422 ['d do dddd ddd dd', '0 0-ıncı Bazar Baz Bz'],
4423 ['DDD DDDo DDDD', '45 45-inci 045'],
4424 ['w wo ww', '7 7-nci 07'],
4425 ['h hh', '3 03'],
4426 ['H HH', '15 15'],
4427 ['m mm', '25 25'],
4428 ['s ss', '50 50'],
4429 ['a A', 'gündüz gündüz'],
4430 ['[ilin] DDDo [günü]', 'ilin 45-inci günü'],
4431 ['LT', '15:25'],
4432 ['LTS', '15:25:50'],
4433 ['L', '14.02.2010'],
4434 ['LL', '14 fevral 2010'],
4435 ['LLL', '14 fevral 2010 15:25'],
4436 ['LLLL', 'Bazar, 14 fevral 2010 15:25'],
4437 ['l', '14.2.2010'],
4438 ['ll', '14 fev 2010'],
4439 ['lll', '14 fev 2010 15:25'],
4440 ['llll', 'Baz, 14 fev 2010 15:25']
4441 ],
4442 DDDo = [
4443 [359, '360-ıncı'],
4444 [199, '200-üncü'],
4445 [149, '150-nci']
4446 ],
4447 dt = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
4448 DDDoDt,
4449 i;
4450
4451 for (i = 0; i < a.length; i++) {
4452 assert.equal(dt.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
4453 }
4454 for (i = 0; i < DDDo.length; i++) {
4455 DDDoDt = moment([2010]);
4456 assert.equal(DDDoDt.add(DDDo[i][0], 'days').format('DDDo'), DDDo[i][1], DDDo[i][0] + ' ---> ' + DDDo[i][1]);
4457 }
4458 });
4459
4460 test('format ordinal', function (assert) {
4461 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-inci', '1st');
4462 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-nci', '2nd');
4463 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-üncü', '3rd');
4464 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-üncü', '4th');
4465 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-inci', '5th');
4466 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-ncı', '6th');
4467 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-nci', '7th');
4468 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-inci', '8th');
4469 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-uncu', '9th');
4470 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-uncu', '10th');
4471
4472 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-inci', '11th');
4473 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-nci', '12th');
4474 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-üncü', '13th');
4475 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-üncü', '14th');
4476 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-inci', '15th');
4477 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-ncı', '16th');
4478 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-nci', '17th');
4479 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-inci', '18th');
4480 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-uncu', '19th');
4481 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-nci', '20th');
4482
4483 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-inci', '21th');
4484 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-nci', '22th');
4485 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-üncü', '23th');
4486 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-üncü', '24th');
4487 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-inci', '25th');
4488 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-ncı', '26th');
4489 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-nci', '27th');
4490 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-inci', '28th');
4491 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-uncu', '29th');
4492 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-uncu', '30th');
4493
4494 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-inci', '31st');
4495 });
4496
4497 test('format month', function (assert) {
4498 var expected = 'yanvar yan_fevral fev_mart mar_aprel apr_may may_iyun iyn_iyul iyl_avqust avq_sentyabr sen_oktyabr okt_noyabr noy_dekabr dek'.split('_'), i;
4499 for (i = 0; i < expected.length; i++) {
4500 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
4501 }
4502 });
4503
4504 test('format week', function (assert) {
4505 var expected = 'Bazar Baz Bz_Bazar ertəsi BzE BE_Çərşənbə axşamı ÇAx ÇA_Çərşənbə Çər Çə_Cümə axşamı CAx CA_Cümə Cüm Cü_Şənbə Şən Şə'.split('_'), i;
4506 for (i = 0; i < expected.length; i++) {
4507 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
4508 }
4509 });
4510
4511 test('from', function (assert) {
4512 var start = moment([2007, 1, 28]);
2e2a5b35 4513 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'birneçə saniyə', '44 seconds = a few seconds');
db71a655
KM
4514 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'bir dəqiqə', '45 seconds = a minute');
4515 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'bir dəqiqə', '89 seconds = a minute');
4516 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 dəqiqə', '90 seconds = 2 minutes');
4517 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 dəqiqə', '44 minutes = 44 minutes');
4518 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'bir saat', '45 minutes = an hour');
4519 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'bir saat', '89 minutes = an hour');
4520 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 saat', '90 minutes = 2 hours');
4521 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 saat', '5 hours = 5 hours');
4522 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 saat', '21 hours = 21 hours');
4523 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'bir gün', '22 hours = a day');
4524 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'bir gün', '35 hours = a day');
4525 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 gün', '36 hours = 2 days');
4526 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'bir gün', '1 day = a day');
4527 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 gün', '5 days = 5 days');
4528 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 gün', '25 days = 25 days');
4529 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'bir ay', '26 days = a month');
4530 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'bir ay', '30 days = a month');
4531 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 ay', '46 days = 2 months');
4532 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 ay', '75 days = 2 months');
4533 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 ay', '76 days = 3 months');
4534 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'bir ay', '1 month = a month');
4535 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 ay', '5 months = 5 months');
4536 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'bir il', '345 days = a year');
4537 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 il', '548 days = 2 years');
4538 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'bir il', '1 year = a year');
4539 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 il', '5 years = 5 years');
4540 });
4541
4542 test('suffix', function (assert) {
2e2a5b35
KM
4543 assert.equal(moment(30000).from(0), 'birneçə saniyə sonra', 'prefix');
4544 assert.equal(moment(0).from(30000), 'birneçə saniyə əvvəl', 'suffix');
db71a655
KM
4545 });
4546
4547 test('now from now', function (assert) {
2e2a5b35 4548 assert.equal(moment().fromNow(), 'birneçə saniyə əvvəl', 'now from now should display as in the past');
db71a655
KM
4549 });
4550
4551 test('fromNow', function (assert) {
2e2a5b35 4552 assert.equal(moment().add({s: 30}).fromNow(), 'birneçə saniyə sonra', 'in a few seconds');
db71a655
KM
4553 assert.equal(moment().add({d: 5}).fromNow(), '5 gün sonra', 'in 5 days');
4554 });
4555
4556 test('calendar day', function (assert) {
4557 var a = moment().hours(12).minutes(0).seconds(0);
4558
4559 assert.equal(moment(a).calendar(), 'bugün saat 12:00', 'today at the same time');
4560 assert.equal(moment(a).add({m: 25}).calendar(), 'bugün saat 12:25', 'Now plus 25 min');
4561 assert.equal(moment(a).add({h: 1}).calendar(), 'bugün saat 13:00', 'Now plus 1 hour');
4562 assert.equal(moment(a).add({d: 1}).calendar(), 'sabah saat 12:00', 'tomorrow at the same time');
4563 assert.equal(moment(a).subtract({h: 1}).calendar(), 'bugün saat 11:00', 'Now minus 1 hour');
4564 assert.equal(moment(a).subtract({d: 1}).calendar(), 'dünən 12:00', 'yesterday at the same time');
4565 });
4566
4567 test('calendar next week', function (assert) {
4568 var i, m;
4569 for (i = 2; i < 7; i++) {
4570 m = moment().add({d: i});
4571 assert.equal(m.calendar(), m.format('[gələn həftə] dddd [saat] LT'), 'Today + ' + i + ' days current time');
4572 m.hours(0).minutes(0).seconds(0).milliseconds(0);
4573 assert.equal(m.calendar(), m.format('[gələn həftə] dddd [saat] LT'), 'Today + ' + i + ' days beginning of day');
4574 m.hours(23).minutes(59).seconds(59).milliseconds(999);
4575 assert.equal(m.calendar(), m.format('[gələn həftə] dddd [saat] LT'), 'Today + ' + i + ' days end of day');
73f3c911 4576 }
db71a655 4577 });
516f5f67 4578
db71a655
KM
4579 test('calendar last week', function (assert) {
4580 var i, m;
4581 for (i = 2; i < 7; i++) {
4582 m = moment().subtract({d: i});
4583 assert.equal(m.calendar(), m.format('[keçən həftə] dddd [saat] LT'), 'Today - ' + i + ' days current time');
4584 m.hours(0).minutes(0).seconds(0).milliseconds(0);
4585 assert.equal(m.calendar(), m.format('[keçən həftə] dddd [saat] LT'), 'Today - ' + i + ' days beginning of day');
4586 m.hours(23).minutes(59).seconds(59).milliseconds(999);
4587 assert.equal(m.calendar(), m.format('[keçən həftə] dddd [saat] LT'), 'Today - ' + i + ' days end of day');
516f5f67 4588 }
db71a655 4589 });
516f5f67 4590
db71a655
KM
4591 test('calendar all else', function (assert) {
4592 var weeksAgo = moment().subtract({w: 1}),
4593 weeksFromNow = moment().add({w: 1});
516f5f67 4594
db71a655
KM
4595 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
4596 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 4597
db71a655
KM
4598 weeksAgo = moment().subtract({w: 2});
4599 weeksFromNow = moment().add({w: 2});
516f5f67 4600
db71a655
KM
4601 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
4602 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
4603 });
516f5f67 4604
db71a655
KM
4605 test('weeks year starting sunday formatted', function (assert) {
4606 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-inci', 'Dec 26 2011 should be week 1');
4607 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-inci', 'Jan 1 2012 should be week 1');
4608 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-nci', 'Jan 2 2012 should be week 2');
4609 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-nci', 'Jan 8 2012 should be week 2');
4610 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-üncü', 'Jan 9 2012 should be week 3');
4611 });
73f3c911
IC
4612
4613})));
516f5f67 4614
516f5f67 4615
c74a101d
IC
4616;(function (global, factory) {
4617 typeof exports === 'object' && typeof module !== 'undefined'
4618 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
4619 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
4620 factory(global.moment)
73f3c911 4621}(this, (function (moment) { 'use strict';
516f5f67 4622
db71a655
KM
4623 function each(array, callback) {
4624 var i;
4625 for (i = 0; i < array.length; i++) {
4626 callback(array[i], i, array);
4627 }
b135bf1a
IC
4628 }
4629
c58511b9
KM
4630 function setupDeprecationHandler(test, moment$$1, scope) {
4631 test._expectedDeprecations = null;
4632 test._observedDeprecations = null;
4633 test._oldSupress = moment$$1.suppressDeprecationWarnings;
4634 moment$$1.suppressDeprecationWarnings = true;
4635 test.expectedDeprecations = function () {
4636 test._expectedDeprecations = arguments;
4637 test._observedDeprecations = [];
4638 };
4639 moment$$1.deprecationHandler = function (name, msg) {
4640 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
4641 if (deprecationId === -1) {
4642 throw new Error('Unexpected deprecation thrown name=' +
4643 name + ' msg=' + msg);
4644 }
4645 test._observedDeprecations[deprecationId] = 1;
4646 };
4647 }
4648
4649 function teardownDeprecationHandler(test, moment$$1, scope) {
4650 moment$$1.suppressDeprecationWarnings = test._oldSupress;
4651
4652 if (test._expectedDeprecations != null) {
4653 var missedDeprecations = [];
4654 each(test._expectedDeprecations, function (deprecationPattern, id) {
4655 if (test._observedDeprecations[id] !== 1) {
4656 missedDeprecations.push(deprecationPattern);
4657 }
4658 });
4659 if (missedDeprecations.length !== 0) {
4660 throw new Error('Expected deprecation warnings did not happen: ' +
4661 missedDeprecations.join(' '));
4662 }
4663 }
4664 }
4665
4666 function matchedDeprecation(name, msg, deprecations) {
4667 if (deprecations == null) {
4668 return -1;
4669 }
4670 for (var i = 0; i < deprecations.length; ++i) {
4671 if (name != null && name === deprecations[i]) {
4672 return i;
4673 }
4674 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
4675 return i;
4676 }
4677 }
4678 return -1;
4679 }
4680
4681 /*global QUnit:false*/
4682
4683 var test = QUnit.test;
4684
db71a655
KM
4685 function objectKeys(obj) {
4686 if (Object.keys) {
4687 return Object.keys(obj);
4688 } else {
4689 // IE8
4690 var res = [], i;
4691 for (i in obj) {
4692 if (obj.hasOwnProperty(i)) {
4693 res.push(i);
4694 }
b135bf1a 4695 }
db71a655 4696 return res;
b135bf1a
IC
4697 }
4698 }
4699
db71a655 4700 // Pick the first defined of two or three arguments.
73f3c911 4701
db71a655
KM
4702 function defineCommonLocaleTests(locale, options) {
4703 test('lenient day of month ordinal parsing', function (assert) {
4704 var i, ordinalStr, testMoment;
4705 for (i = 1; i <= 31; ++i) {
4706 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
4707 testMoment = moment(ordinalStr, 'YYYY MM Do');
4708 assert.equal(testMoment.year(), 2014,
4709 'lenient day of month ordinal parsing ' + i + ' year check');
4710 assert.equal(testMoment.month(), 0,
4711 'lenient day of month ordinal parsing ' + i + ' month check');
4712 assert.equal(testMoment.date(), i,
4713 'lenient day of month ordinal parsing ' + i + ' date check');
4714 }
4715 });
73f3c911 4716
db71a655
KM
4717 test('lenient day of month ordinal parsing of number', function (assert) {
4718 var i, testMoment;
4719 for (i = 1; i <= 31; ++i) {
4720 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
4721 assert.equal(testMoment.year(), 2014,
4722 'lenient day of month ordinal parsing of number ' + i + ' year check');
4723 assert.equal(testMoment.month(), 0,
4724 'lenient day of month ordinal parsing of number ' + i + ' month check');
4725 assert.equal(testMoment.date(), i,
4726 'lenient day of month ordinal parsing of number ' + i + ' date check');
4727 }
4728 });
b135bf1a 4729
db71a655
KM
4730 test('strict day of month ordinal parsing', function (assert) {
4731 var i, ordinalStr, testMoment;
4732 for (i = 1; i <= 31; ++i) {
4733 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
4734 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
4735 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
4736 }
4737 });
b135bf1a 4738
db71a655
KM
4739 test('meridiem invariant', function (assert) {
4740 var h, m, t1, t2;
4741 for (h = 0; h < 24; ++h) {
4742 for (m = 0; m < 60; m += 15) {
4743 t1 = moment.utc([2000, 0, 1, h, m]);
4744 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
4745 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
4746 'meridiem at ' + t1.format('HH:mm'));
4747 }
4748 }
4749 });
4750
4751 test('date format correctness', function (assert) {
4752 var data, tokens;
4753 data = moment.localeData()._longDateFormat;
4754 tokens = objectKeys(data);
4755 each(tokens, function (srchToken) {
4756 // Check each format string to make sure it does not contain any
4757 // tokens that need to be expanded.
4758 each(tokens, function (baseToken) {
4759 // strip escaped sequences
4760 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
4761 assert.equal(false, !!~format.indexOf(srchToken),
4762 'contains ' + srchToken + ' in ' + baseToken);
4763 });
b135bf1a
IC
4764 });
4765 });
d6651c21 4766
db71a655
KM
4767 test('month parsing correctness', function (assert) {
4768 var i, m;
4769
4770 if (locale === 'tr') {
4771 // I can't fix it :(
c58511b9 4772 assert.expect(0);
db71a655
KM
4773 return;
4774 }
4775 function tester(format) {
4776 var r;
4777 r = moment(m.format(format), format);
4778 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
4779 if (locale !== 'ka') {
4780 r = moment(m.format(format).toLocaleUpperCase(), format);
4781 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
4782 }
db71a655
KM
4783 r = moment(m.format(format).toLocaleLowerCase(), format);
4784 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
4785
4786 r = moment(m.format(format), format, true);
4787 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
4788 if (locale !== 'ka') {
4789 r = moment(m.format(format).toLocaleUpperCase(), format, true);
4790 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
4791 }
db71a655
KM
4792 r = moment(m.format(format).toLocaleLowerCase(), format, true);
4793 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
4794 }
4795
4796 for (i = 0; i < 12; ++i) {
4797 m = moment([2015, i, 15, 18]);
4798 tester('MMM');
4799 tester('MMM.');
4800 tester('MMMM');
4801 tester('MMMM.');
4802 }
4803 });
d6651c21 4804
db71a655
KM
4805 test('weekday parsing correctness', function (assert) {
4806 var i, m;
4807
96d0d679 4808 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
4809 // tr, az: There is a lower-case letter (ı), that converted to
4810 // upper then lower changes to i
4811 // ro: there is the letter ț which behaves weird under IE8
4812 // mt: letter Ħ
96d0d679 4813 // ga: month with spaces
c58511b9 4814 assert.expect(0);
db71a655
KM
4815 return;
4816 }
4817 function tester(format) {
4818 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
4819 r = moment(m.format(format), format);
4820 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
4821 if (locale !== 'ka') {
4822 r = moment(m.format(format).toLocaleUpperCase(), format);
4823 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
4824 }
db71a655
KM
4825 r = moment(m.format(format).toLocaleLowerCase(), format);
4826 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
4827 r = moment(m.format(format), format, true);
4828 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
4829 if (locale !== 'ka') {
4830 r = moment(m.format(format).toLocaleUpperCase(), format, true);
4831 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
4832 }
db71a655
KM
4833 r = moment(m.format(format).toLocaleLowerCase(), format, true);
4834 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
4835 }
4836
4837 for (i = 0; i < 7; ++i) {
4838 m = moment.utc([2015, 0, i + 1, 18]);
4839 tester('dd');
4840 tester('ddd');
4841 tester('dddd');
4842 }
4843 });
d6651c21 4844
db71a655
KM
4845 test('valid localeData', function (assert) {
4846 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
4847 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
4848 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
4849 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
4850 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
4851 });
96d0d679
KM
4852
4853 test('localeData weekdays can localeSort', function (assert) {
4854 var weekdays = moment().localeData().weekdays();
4855 var weekdaysShort = moment().localeData().weekdaysShort();
4856 var weekdaysMin = moment().localeData().weekdaysMin();
4857 var shift = moment().localeData()._week.dow;
4858 assert.deepEqual(
4859 moment().localeData().weekdays(true),
4860 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
4861 'weekdays should localeSort');
4862 assert.deepEqual(
4863 moment().localeData().weekdaysShort(true),
4864 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
4865 'weekdaysShort should localeSort');
4866 assert.deepEqual(
4867 moment().localeData().weekdaysMin(true),
4868 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
4869 'weekdaysMin should localeSort');
4870 });
db71a655 4871 }
d6651c21 4872
db71a655
KM
4873 /*global QUnit:false*/
4874
db71a655
KM
4875 function localeModule (name, lifecycle) {
4876 QUnit.module('locale:' + name, {
c58511b9 4877 beforeEach : function () {
db71a655
KM
4878 moment.locale(name);
4879 moment.createFromInputFallback = function (config) {
4880 throw new Error('input not handled by moment: ' + config._i);
4881 };
4882 setupDeprecationHandler(test, moment, 'locale');
4883 if (lifecycle && lifecycle.setup) {
4884 lifecycle.setup();
4885 }
4886 },
c58511b9 4887 afterEach : function () {
db71a655
KM
4888 moment.locale('en');
4889 teardownDeprecationHandler(test, moment, 'locale');
4890 if (lifecycle && lifecycle.teardown) {
4891 lifecycle.teardown();
4892 }
516f5f67
IC
4893 }
4894 });
db71a655
KM
4895 defineCommonLocaleTests(name, -1, -1);
4896 }
4897
4898 localeModule('be');
4899
4900 test('parse', function (assert) {
4901 var tests = 'студзень студ_люты лют_сакавік сак_красавік крас_травень трав_чэрвень чэрв_ліпень ліп_жнівень жнів_верасень вер_кастрычнік каст_лістапад ліст_снежань снеж'.split('_'), i;
4902 function equalTest(input, mmm, i) {
4903 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
4904 }
4905 for (i = 0; i < 12; i++) {
4906 tests[i] = tests[i].split(' ');
4907 equalTest(tests[i][0], 'MMM', i);
4908 equalTest(tests[i][1], 'MMM', i);
4909 equalTest(tests[i][0], 'MMMM', i);
4910 equalTest(tests[i][1], 'MMMM', i);
4911 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
4912 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
4913 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
4914 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
4915 }
4916 });
4917
4918 test('format', function (assert) {
4919 var a = [
4920 ['dddd, Do MMMM YYYY, HH:mm:ss', 'нядзеля, 14-га лютага 2010, 15:25:50'],
4921 ['ddd, h A', 'нд, 3 дня'],
4922 ['M Mo MM MMMM MMM', '2 2-і 02 люты лют'],
4923 ['YYYY YY', '2010 10'],
4924 ['D Do DD', '14 14-га 14'],
4925 ['d do dddd ddd dd', '0 0-ы нядзеля нд нд'],
4926 ['DDD DDDo DDDD', '45 45-ы 045'],
4927 ['w wo ww', '7 7-ы 07'],
4928 ['h hh', '3 03'],
4929 ['H HH', '15 15'],
4930 ['m mm', '25 25'],
4931 ['s ss', '50 50'],
4932 ['a A', 'дня дня'],
4933 ['DDDo [дзень года]', '45-ы дзень года'],
4934 ['LT', '15:25'],
4935 ['LTS', '15:25:50'],
4936 ['L', '14.02.2010'],
4937 ['LL', '14 лютага 2010 г.'],
4938 ['LLL', '14 лютага 2010 г., 15:25'],
4939 ['LLLL', 'нядзеля, 14 лютага 2010 г., 15:25'],
4940 ['l', '14.2.2010'],
4941 ['ll', '14 лют 2010 г.'],
4942 ['lll', '14 лют 2010 г., 15:25'],
4943 ['llll', 'нд, 14 лют 2010 г., 15:25']
4944 ],
4945 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
4946 i;
4947 for (i = 0; i < a.length; i++) {
4948 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
4949 }
4950 });
4951
4952 test('format meridiem', function (assert) {
4953 assert.equal(moment([2012, 11, 28, 0, 0]).format('A'), 'ночы', 'night');
4954 assert.equal(moment([2012, 11, 28, 3, 59]).format('A'), 'ночы', 'night');
4955 assert.equal(moment([2012, 11, 28, 4, 0]).format('A'), 'раніцы', 'morning');
4956 assert.equal(moment([2012, 11, 28, 11, 59]).format('A'), 'раніцы', 'morning');
4957 assert.equal(moment([2012, 11, 28, 12, 0]).format('A'), 'дня', 'afternoon');
4958 assert.equal(moment([2012, 11, 28, 16, 59]).format('A'), 'дня', 'afternoon');
4959 assert.equal(moment([2012, 11, 28, 17, 0]).format('A'), 'вечара', 'evening');
4960 assert.equal(moment([2012, 11, 28, 23, 59]).format('A'), 'вечара', 'evening');
4961 });
4962
4963 test('format ordinal', function (assert) {
4964 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-ы', '1-ы');
4965 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-і', '2-і');
4966 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-і', '3-і');
4967 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-ы', '4-ы');
4968 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-ы', '5-ы');
4969 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-ы', '6-ы');
4970 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-ы', '7-ы');
4971 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-ы', '8-ы');
4972 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-ы', '9-ы');
4973 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-ы', '10-ы');
4974
4975 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-ы', '11-ы');
4976 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-ы', '12-ы');
4977 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-ы', '13-ы');
4978 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-ы', '14-ы');
4979 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-ы', '15-ы');
4980 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-ы', '16-ы');
4981 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-ы', '17-ы');
4982 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-ы', '18-ы');
4983 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-ы', '19-ы');
4984 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-ы', '20-ы');
4985
4986 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-ы', '21-ы');
4987 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-і', '22-і');
4988 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-і', '23-і');
4989 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-ы', '24-ы');
4990 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-ы', '25-ы');
4991 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-ы', '26-ы');
4992 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-ы', '27-ы');
4993 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-ы', '28-ы');
4994 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-ы', '29-ы');
4995 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-ы', '30-ы');
4996
4997 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-ы', '31-ы');
4998 });
4999
5000 test('format month', function (assert) {
5001 var expected = 'студзень студ_люты лют_сакавік сак_красавік крас_травень трав_чэрвень чэрв_ліпень ліп_жнівень жнів_верасень вер_кастрычнік каст_лістапад ліст_снежань снеж'.split('_'), i;
5002 for (i = 0; i < expected.length; i++) {
5003 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
5004 }
5005 });
5006
5007 test('format month case', function (assert) {
5008 var months = {
5009 'nominative': 'студзень_люты_сакавік_красавік_травень_чэрвень_ліпень_жнівень_верасень_кастрычнік_лістапад_снежань'.split('_'),
5010 'accusative': 'студзеня_лютага_сакавіка_красавіка_траўня_чэрвеня_ліпеня_жніўня_верасня_кастрычніка_лістапада_снежня'.split('_')
5011 }, i;
5012 for (i = 0; i < 12; i++) {
5013 assert.equal(moment([2011, i, 1]).format('D MMMM'), '1 ' + months.accusative[i], '1 ' + months.accusative[i]);
5014 assert.equal(moment([2011, i, 1]).format('MMMM'), months.nominative[i], '1 ' + months.nominative[i]);
5015 }
5016 });
5017
5018 test('format month case with escaped symbols', function (assert) {
5019 var months = {
5020 'nominative': 'студзень_люты_сакавік_красавік_травень_чэрвень_ліпень_жнівень_верасень_кастрычнік_лістапад_снежань'.split('_'),
5021 'accusative': 'студзеня_лютага_сакавіка_красавіка_траўня_чэрвеня_ліпеня_жніўня_верасня_кастрычніка_лістапада_снежня'.split('_')
5022 }, i;
5023 for (i = 0; i < 12; i++) {
5024 assert.equal(moment([2013, i, 1]).format('D[] MMMM'), '1 ' + months.accusative[i], '1 ' + months.accusative[i]);
5025 assert.equal(moment([2013, i, 1]).format('[<i>]D[</i>] [<b>]MMMM[</b>]'), '<i>1</i> <b>' + months.accusative[i] + '</b>', '1 <b>' + months.accusative[i] + '</b>');
5026 assert.equal(moment([2013, i, 1]).format('D[-ы дзень] MMMM'), '1-ы дзень ' + months.accusative[i], '1-ы дзень ' + months.accusative[i]);
5027 assert.equal(moment([2013, i, 1]).format('D, MMMM'), '1, ' + months.nominative[i], '1, ' + months.nominative[i]);
5028 }
5029 });
5030
5031 test('format week', function (assert) {
5032 var expected = 'нядзеля нд нд_панядзелак пн пн_аўторак ат ат_серада ср ср_чацвер чц чц_пятніца пт пт_субота сб сб'.split('_'), i;
5033 for (i = 0; i < expected.length; i++) {
5034 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
5035 }
5036 });
5037
5038 test('from', function (assert) {
5039 var start = moment([2007, 1, 28]);
5040 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'некалькі секунд', '44 seconds = a few seconds');
5041 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'хвіліна', '45 seconds = a minute');
5042 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'хвіліна', '89 seconds = a minute');
5043 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 хвіліны', '90 seconds = 2 minutes');
5044 assert.equal(start.from(moment([2007, 1, 28]).add({m: 31}), true), '31 хвіліна', '31 minutes = 31 minutes');
5045 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 хвіліны', '44 minutes = 44 minutes');
5046 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'гадзіна', '45 minutes = an hour');
5047 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'гадзіна', '89 minutes = an hour');
5048 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 гадзіны', '90 minutes = 2 hours');
5049 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 гадзін', '5 hours = 5 hours');
5050 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 гадзіна', '21 hours = 21 hours');
5051 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'дзень', '22 hours = a day');
5052 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'дзень', '35 hours = a day');
5053 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 дні', '36 hours = 2 days');
5054 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'дзень', '1 day = a day');
5055 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 дзён', '5 days = 5 days');
5056 assert.equal(start.from(moment([2007, 1, 28]).add({d: 11}), true), '11 дзён', '11 days = 11 days');
5057 assert.equal(start.from(moment([2007, 1, 28]).add({d: 21}), true), '21 дзень', '21 days = 21 days');
5058 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 дзён', '25 days = 25 days');
5059 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'месяц', '26 days = a month');
5060 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'месяц', '30 days = a month');
5061 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'месяц', '43 days = a month');
5062 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 месяцы', '46 days = 2 months');
5063 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 месяцы', '75 days = 2 months');
5064 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 месяцы', '76 days = 3 months');
5065 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'месяц', '1 month = a month');
5066 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 месяцаў', '5 months = 5 months');
5067 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'год', '345 days = a year');
5068 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 гады', '548 days = 2 years');
5069 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'год', '1 year = a year');
5070 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 гадоў', '5 years = 5 years');
5071 });
5072
5073 test('suffix', function (assert) {
5074 assert.equal(moment(30000).from(0), 'праз некалькі секунд', 'prefix');
5075 assert.equal(moment(0).from(30000), 'некалькі секунд таму', 'suffix');
5076 });
5077
5078 test('fromNow', function (assert) {
5079 assert.equal(moment().add({s: 30}).fromNow(), 'праз некалькі секунд', 'in a few seconds');
5080 assert.equal(moment().add({d: 5}).fromNow(), 'праз 5 дзён', 'in 5 days');
5081 assert.equal(moment().add({m: 31}).fromNow(), 'праз 31 хвіліну', 'in 31 minutes = in 31 minutes');
5082 assert.equal(moment().subtract({m: 31}).fromNow(), '31 хвіліну таму', '31 minutes ago = 31 minutes ago');
5083 });
5084
5085 test('calendar day', function (assert) {
5086 var a = moment().hours(12).minutes(0).seconds(0);
5087
5088 assert.equal(moment(a).calendar(), 'Сёння ў 12:00', 'today at the same time');
5089 assert.equal(moment(a).add({m: 25}).calendar(), 'Сёння ў 12:25', 'Now plus 25 min');
5090 assert.equal(moment(a).add({h: 1}).calendar(), 'Сёння ў 13:00', 'Now plus 1 hour');
5091 assert.equal(moment(a).add({d: 1}).calendar(), 'Заўтра ў 12:00', 'tomorrow at the same time');
5092 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Сёння ў 11:00', 'Now minus 1 hour');
5093 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Учора ў 12:00', 'yesterday at the same time');
5094 });
5095
5096 test('calendar next week', function (assert) {
5097 var i, m;
5098 function makeFormat(d) {
5099 return '[У] dddd [ў] LT';
73f3c911 5100 }
516f5f67 5101
db71a655
KM
5102 for (i = 2; i < 7; i++) {
5103 m = moment().add({d: i});
5104 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time');
5105 m.hours(0).minutes(0).seconds(0).milliseconds(0);
5106 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day');
5107 m.hours(23).minutes(59).seconds(59).milliseconds(999);
5108 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day');
516f5f67 5109 }
db71a655
KM
5110 });
5111
5112 test('calendar last week', function (assert) {
5113 var i, m;
5114
5115 function makeFormat(d) {
5116 switch (d.day()) {
5117 case 0:
5118 case 3:
5119 case 5:
5120 case 6:
5121 return '[У мінулую] dddd [ў] LT';
5122 case 1:
5123 case 2:
5124 case 4:
5125 return '[У мінулы] dddd [ў] LT';
5126 }
516f5f67
IC
5127 }
5128
db71a655
KM
5129 for (i = 2; i < 7; i++) {
5130 m = moment().subtract({d: i});
5131 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time');
5132 m.hours(0).minutes(0).seconds(0).milliseconds(0);
5133 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day');
5134 m.hours(23).minutes(59).seconds(59).milliseconds(999);
5135 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day');
5136 }
5137 });
516f5f67 5138
db71a655
KM
5139 test('calendar all else', function (assert) {
5140 var weeksAgo = moment().subtract({w: 1}),
5141 weeksFromNow = moment().add({w: 1});
516f5f67 5142
db71a655
KM
5143 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
5144 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 5145
db71a655
KM
5146 weeksAgo = moment().subtract({w: 2});
5147 weeksFromNow = moment().add({w: 2});
5148
5149 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
5150 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
5151 });
5152
5153 test('weeks year starting sunday formatted', function (assert) {
5154 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-ы', 'Dec 26 2011 should be week 1');
5155 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-ы', 'Jan 1 2012 should be week 1');
5156 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-і', 'Jan 2 2012 should be week 2');
5157 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-і', 'Jan 8 2012 should be week 2');
5158 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-і', 'Jan 9 2012 should be week 3');
5159 });
73f3c911 5160
2e2a5b35
KM
5161 test('calendar should format', function (assert) {
5162 assert.equal(moment('2018-04-13').calendar(moment('2018-04-16')), 'У мінулую пятніцу ў 00:00', 'calendar should handle day of week');
5163 });
5164
73f3c911 5165})));
516f5f67 5166
516f5f67 5167
c74a101d
IC
5168;(function (global, factory) {
5169 typeof exports === 'object' && typeof module !== 'undefined'
5170 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
5171 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
5172 factory(global.moment)
73f3c911 5173}(this, (function (moment) { 'use strict';
516f5f67 5174
db71a655
KM
5175 function each(array, callback) {
5176 var i;
5177 for (i = 0; i < array.length; i++) {
5178 callback(array[i], i, array);
5179 }
b135bf1a
IC
5180 }
5181
c58511b9
KM
5182 function setupDeprecationHandler(test, moment$$1, scope) {
5183 test._expectedDeprecations = null;
5184 test._observedDeprecations = null;
5185 test._oldSupress = moment$$1.suppressDeprecationWarnings;
5186 moment$$1.suppressDeprecationWarnings = true;
5187 test.expectedDeprecations = function () {
5188 test._expectedDeprecations = arguments;
5189 test._observedDeprecations = [];
5190 };
5191 moment$$1.deprecationHandler = function (name, msg) {
5192 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
5193 if (deprecationId === -1) {
5194 throw new Error('Unexpected deprecation thrown name=' +
5195 name + ' msg=' + msg);
5196 }
5197 test._observedDeprecations[deprecationId] = 1;
5198 };
5199 }
5200
5201 function teardownDeprecationHandler(test, moment$$1, scope) {
5202 moment$$1.suppressDeprecationWarnings = test._oldSupress;
5203
5204 if (test._expectedDeprecations != null) {
5205 var missedDeprecations = [];
5206 each(test._expectedDeprecations, function (deprecationPattern, id) {
5207 if (test._observedDeprecations[id] !== 1) {
5208 missedDeprecations.push(deprecationPattern);
5209 }
5210 });
5211 if (missedDeprecations.length !== 0) {
5212 throw new Error('Expected deprecation warnings did not happen: ' +
5213 missedDeprecations.join(' '));
5214 }
5215 }
5216 }
5217
5218 function matchedDeprecation(name, msg, deprecations) {
5219 if (deprecations == null) {
5220 return -1;
5221 }
5222 for (var i = 0; i < deprecations.length; ++i) {
5223 if (name != null && name === deprecations[i]) {
5224 return i;
5225 }
5226 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
5227 return i;
5228 }
5229 }
5230 return -1;
5231 }
5232
5233 /*global QUnit:false*/
5234
5235 var test = QUnit.test;
5236
db71a655
KM
5237 function objectKeys(obj) {
5238 if (Object.keys) {
5239 return Object.keys(obj);
5240 } else {
5241 // IE8
5242 var res = [], i;
5243 for (i in obj) {
5244 if (obj.hasOwnProperty(i)) {
5245 res.push(i);
5246 }
b135bf1a 5247 }
db71a655 5248 return res;
b135bf1a 5249 }
b135bf1a
IC
5250 }
5251
db71a655 5252 // Pick the first defined of two or three arguments.
b135bf1a 5253
db71a655
KM
5254 function defineCommonLocaleTests(locale, options) {
5255 test('lenient day of month ordinal parsing', function (assert) {
5256 var i, ordinalStr, testMoment;
5257 for (i = 1; i <= 31; ++i) {
5258 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
5259 testMoment = moment(ordinalStr, 'YYYY MM Do');
5260 assert.equal(testMoment.year(), 2014,
5261 'lenient day of month ordinal parsing ' + i + ' year check');
5262 assert.equal(testMoment.month(), 0,
5263 'lenient day of month ordinal parsing ' + i + ' month check');
5264 assert.equal(testMoment.date(), i,
5265 'lenient day of month ordinal parsing ' + i + ' date check');
5266 }
5267 });
b135bf1a 5268
db71a655
KM
5269 test('lenient day of month ordinal parsing of number', function (assert) {
5270 var i, testMoment;
5271 for (i = 1; i <= 31; ++i) {
5272 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
5273 assert.equal(testMoment.year(), 2014,
5274 'lenient day of month ordinal parsing of number ' + i + ' year check');
5275 assert.equal(testMoment.month(), 0,
5276 'lenient day of month ordinal parsing of number ' + i + ' month check');
5277 assert.equal(testMoment.date(), i,
5278 'lenient day of month ordinal parsing of number ' + i + ' date check');
5279 }
5280 });
b135bf1a 5281
db71a655
KM
5282 test('strict day of month ordinal parsing', function (assert) {
5283 var i, ordinalStr, testMoment;
5284 for (i = 1; i <= 31; ++i) {
5285 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
5286 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
5287 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
5288 }
5289 });
b135bf1a 5290
db71a655
KM
5291 test('meridiem invariant', function (assert) {
5292 var h, m, t1, t2;
5293 for (h = 0; h < 24; ++h) {
5294 for (m = 0; m < 60; m += 15) {
5295 t1 = moment.utc([2000, 0, 1, h, m]);
5296 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
5297 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
5298 'meridiem at ' + t1.format('HH:mm'));
5299 }
5300 }
5301 });
5302
5303 test('date format correctness', function (assert) {
5304 var data, tokens;
5305 data = moment.localeData()._longDateFormat;
5306 tokens = objectKeys(data);
5307 each(tokens, function (srchToken) {
5308 // Check each format string to make sure it does not contain any
5309 // tokens that need to be expanded.
5310 each(tokens, function (baseToken) {
5311 // strip escaped sequences
5312 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
5313 assert.equal(false, !!~format.indexOf(srchToken),
5314 'contains ' + srchToken + ' in ' + baseToken);
5315 });
b135bf1a
IC
5316 });
5317 });
d6651c21 5318
db71a655
KM
5319 test('month parsing correctness', function (assert) {
5320 var i, m;
5321
5322 if (locale === 'tr') {
5323 // I can't fix it :(
c58511b9 5324 assert.expect(0);
db71a655
KM
5325 return;
5326 }
5327 function tester(format) {
5328 var r;
5329 r = moment(m.format(format), format);
5330 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
5331 if (locale !== 'ka') {
5332 r = moment(m.format(format).toLocaleUpperCase(), format);
5333 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
5334 }
db71a655
KM
5335 r = moment(m.format(format).toLocaleLowerCase(), format);
5336 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
5337
5338 r = moment(m.format(format), format, true);
5339 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
5340 if (locale !== 'ka') {
5341 r = moment(m.format(format).toLocaleUpperCase(), format, true);
5342 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
5343 }
db71a655
KM
5344 r = moment(m.format(format).toLocaleLowerCase(), format, true);
5345 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
5346 }
5347
5348 for (i = 0; i < 12; ++i) {
5349 m = moment([2015, i, 15, 18]);
5350 tester('MMM');
5351 tester('MMM.');
5352 tester('MMMM');
5353 tester('MMMM.');
5354 }
5355 });
d6651c21 5356
db71a655
KM
5357 test('weekday parsing correctness', function (assert) {
5358 var i, m;
5359
96d0d679 5360 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
5361 // tr, az: There is a lower-case letter (ı), that converted to
5362 // upper then lower changes to i
5363 // ro: there is the letter ț which behaves weird under IE8
5364 // mt: letter Ħ
96d0d679 5365 // ga: month with spaces
c58511b9 5366 assert.expect(0);
db71a655
KM
5367 return;
5368 }
5369 function tester(format) {
5370 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
5371 r = moment(m.format(format), format);
5372 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
5373 if (locale !== 'ka') {
5374 r = moment(m.format(format).toLocaleUpperCase(), format);
5375 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
5376 }
db71a655
KM
5377 r = moment(m.format(format).toLocaleLowerCase(), format);
5378 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
5379 r = moment(m.format(format), format, true);
5380 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
5381 if (locale !== 'ka') {
5382 r = moment(m.format(format).toLocaleUpperCase(), format, true);
5383 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
5384 }
db71a655
KM
5385 r = moment(m.format(format).toLocaleLowerCase(), format, true);
5386 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
5387 }
5388
5389 for (i = 0; i < 7; ++i) {
5390 m = moment.utc([2015, 0, i + 1, 18]);
5391 tester('dd');
5392 tester('ddd');
5393 tester('dddd');
5394 }
5395 });
d6651c21 5396
db71a655
KM
5397 test('valid localeData', function (assert) {
5398 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
5399 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
5400 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
5401 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
5402 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
5403 });
96d0d679
KM
5404
5405 test('localeData weekdays can localeSort', function (assert) {
5406 var weekdays = moment().localeData().weekdays();
5407 var weekdaysShort = moment().localeData().weekdaysShort();
5408 var weekdaysMin = moment().localeData().weekdaysMin();
5409 var shift = moment().localeData()._week.dow;
5410 assert.deepEqual(
5411 moment().localeData().weekdays(true),
5412 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
5413 'weekdays should localeSort');
5414 assert.deepEqual(
5415 moment().localeData().weekdaysShort(true),
5416 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
5417 'weekdaysShort should localeSort');
5418 assert.deepEqual(
5419 moment().localeData().weekdaysMin(true),
5420 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
5421 'weekdaysMin should localeSort');
5422 });
db71a655 5423 }
d6651c21 5424
db71a655 5425 /*global QUnit:false*/
516f5f67 5426
db71a655
KM
5427 function localeModule (name, lifecycle) {
5428 QUnit.module('locale:' + name, {
c58511b9 5429 beforeEach : function () {
db71a655
KM
5430 moment.locale(name);
5431 moment.createFromInputFallback = function (config) {
5432 throw new Error('input not handled by moment: ' + config._i);
5433 };
5434 setupDeprecationHandler(test, moment, 'locale');
5435 if (lifecycle && lifecycle.setup) {
5436 lifecycle.setup();
5437 }
5438 },
c58511b9 5439 afterEach : function () {
db71a655
KM
5440 moment.locale('en');
5441 teardownDeprecationHandler(test, moment, 'locale');
5442 if (lifecycle && lifecycle.teardown) {
5443 lifecycle.teardown();
5444 }
516f5f67
IC
5445 }
5446 });
db71a655
KM
5447 defineCommonLocaleTests(name, -1, -1);
5448 }
5449
5450 localeModule('bg');
5451
5452 test('parse', function (assert) {
5453 var tests = 'януари янр_февруари фев_март мар_април апр_май май_юни юни_юли юли_август авг_септември сеп_октомври окт_ноември ное_декември дек'.split('_'), i;
5454 function equalTest(input, mmm, i) {
5455 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
5456 }
5457 for (i = 0; i < 12; i++) {
5458 tests[i] = tests[i].split(' ');
5459 equalTest(tests[i][0], 'MMM', i);
5460 equalTest(tests[i][1], 'MMM', i);
5461 equalTest(tests[i][0], 'MMMM', i);
5462 equalTest(tests[i][1], 'MMMM', i);
5463 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
5464 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
5465 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
5466 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
5467 }
5468 });
5469
5470 test('format', function (assert) {
5471 var a = [
5472 ['dddd, MMMM Do YYYY, H:mm:ss', 'неделя, февруари 14-ти 2010, 15:25:50'],
5473 ['ddd, hA', 'нед, 3PM'],
5474 ['M Mo MM MMMM MMM', '2 2-ри 02 февруари фев'],
5475 ['YYYY YY', '2010 10'],
5476 ['D Do DD', '14 14-ти 14'],
5477 ['d do dddd ddd dd', '0 0-ев неделя нед нд'],
5478 ['DDD DDDo DDDD', '45 45-ти 045'],
5479 ['w wo ww', '7 7-ми 07'],
5480 ['h hh', '3 03'],
5481 ['H HH', '15 15'],
5482 ['m mm', '25 25'],
5483 ['s ss', '50 50'],
5484 ['a A', 'pm PM'],
5485 ['[the] DDDo [day of the year]', 'the 45-ти day of the year'],
5486 ['LT', '15:25'],
5487 ['LTS', '15:25:50'],
5488 ['L', '14.02.2010'],
5489 ['LL', '14 февруари 2010'],
5490 ['LLL', '14 февруари 2010 15:25'],
5491 ['LLLL', 'неделя, 14 февруари 2010 15:25'],
5492 ['l', '14.2.2010'],
5493 ['ll', '14 фев 2010'],
5494 ['lll', '14 фев 2010 15:25'],
5495 ['llll', 'нед, 14 фев 2010 15:25']
5496 ],
5497 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
5498 i;
5499 for (i = 0; i < a.length; i++) {
5500 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
5501 }
5502 });
5503
5504 test('format ordinal', function (assert) {
5505 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-ви', '1-ви');
5506 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-ри', '2-ри');
5507 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-ти', '3-ти');
5508 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-ти', '4-ти');
5509 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-ти', '5-ти');
5510 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-ти', '6-ти');
5511 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-ми', '7-ми');
5512 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-ми', '8-ми');
5513 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-ти', '9-ти');
5514 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-ти', '10-ти');
5515
5516 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-ти', '11-ти');
5517 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-ти', '12-ти');
5518 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-ти', '13-ти');
5519 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-ти', '14-ти');
5520 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-ти', '15-ти');
5521 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-ти', '16-ти');
5522 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-ти', '17-ти');
5523 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-ти', '18-ти');
5524 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-ти', '19-ти');
5525 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-ти', '20-ти');
5526
5527 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-ви', '21-ви');
5528 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-ри', '22-ри');
5529 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-ти', '23-ти');
5530 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-ти', '24-ти');
5531 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-ти', '25-ти');
5532 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-ти', '26-ти');
5533 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-ми', '27-ми');
5534 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-ми', '28-ми');
5535 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-ти', '29-ти');
5536 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-ти', '30-ти');
5537
5538 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-ви', '31-ви');
5539 });
5540
5541 test('format month', function (assert) {
5542 var expected = 'януари янр_февруари фев_март мар_април апр_май май_юни юни_юли юли_август авг_септември сеп_октомври окт_ноември ное_декември дек'.split('_'), i;
5543 for (i = 0; i < expected.length; i++) {
5544 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
5545 }
5546 });
5547
5548 test('format week', function (assert) {
5549 var expected = 'неделя нед нд_понеделник пон пн_вторник вто вт_сряда сря ср_четвъртък чет чт_петък пет пт_събота съб сб'.split('_'), i;
5550 for (i = 0; i < expected.length; i++) {
5551 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
5552 }
5553 });
5554
5555 test('from', function (assert) {
5556 var start = moment([2007, 1, 28]);
5557 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'няколко секунди', '44 seconds = a few seconds');
5558 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'минута', '45 seconds = a minute');
5559 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'минута', '89 seconds = a minute');
5560 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 минути', '90 seconds = 2 minutes');
5561 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 минути', '44 minutes = 44 minutes');
5562 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'час', '45 minutes = an hour');
5563 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'час', '89 minutes = an hour');
5564 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 часа', '90 minutes = 2 hours');
5565 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 часа', '5 hours = 5 hours');
5566 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 часа', '21 hours = 21 hours');
5567 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ден', '22 hours = a day');
5568 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ден', '35 hours = a day');
5569 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 дни', '36 hours = 2 days');
5570 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ден', '1 day = a day');
5571 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 дни', '5 days = 5 days');
5572 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 дни', '25 days = 25 days');
5573 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'месец', '26 days = a month');
5574 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'месец', '30 days = a month');
5575 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'месец', '43 days = a month');
5576 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 месеца', '46 days = 2 months');
5577 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 месеца', '75 days = 2 months');
5578 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 месеца', '76 days = 3 months');
5579 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'месец', '1 month = a month');
5580 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 месеца', '5 months = 5 months');
5581 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'година', '345 days = a year');
5582 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 години', '548 days = 2 years');
5583 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'година', '1 year = a year');
5584 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 години', '5 years = 5 years');
5585 });
5586
5587 test('suffix', function (assert) {
5588 assert.equal(moment(30000).from(0), 'след няколко секунди', 'prefix');
5589 assert.equal(moment(0).from(30000), 'преди няколко секунди', 'suffix');
5590 });
5591
5592 test('now from now', function (assert) {
5593 assert.equal(moment().fromNow(), 'преди няколко секунди', 'now from now should display as in the past');
5594 });
5595
5596 test('fromNow', function (assert) {
5597 assert.equal(moment().add({s: 30}).fromNow(), 'след няколко секунди', 'in a few seconds');
5598 assert.equal(moment().add({d: 5}).fromNow(), 'след 5 дни', 'in 5 days');
5599 });
5600
5601 test('calendar day', function (assert) {
5602 var a = moment().hours(12).minutes(0).seconds(0);
5603
5604 assert.equal(moment(a).calendar(), 'Днес в 12:00', 'today at the same time');
5605 assert.equal(moment(a).add({m: 25}).calendar(), 'Днес в 12:25', 'Now plus 25 min');
5606 assert.equal(moment(a).add({h: 1}).calendar(), 'Днес в 13:00', 'Now plus 1 hour');
5607 assert.equal(moment(a).add({d: 1}).calendar(), 'Утре в 12:00', 'tomorrow at the same time');
5608 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Днес в 11:00', 'Now minus 1 hour');
5609 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Вчера в 12:00', 'yesterday at the same time');
5610 });
5611
5612 test('calendar next week', function (assert) {
5613 var i, m;
5614 for (i = 2; i < 7; i++) {
5615 m = moment().add({d: i});
5616 assert.equal(m.calendar(), m.format('dddd [в] LT'), 'Today + ' + i + ' days current time');
5617 m.hours(0).minutes(0).seconds(0).milliseconds(0);
5618 assert.equal(m.calendar(), m.format('dddd [в] LT'), 'Today + ' + i + ' days beginning of day');
5619 m.hours(23).minutes(59).seconds(59).milliseconds(999);
5620 assert.equal(m.calendar(), m.format('dddd [в] LT'), 'Today + ' + i + ' days end of day');
73f3c911 5621 }
db71a655 5622 });
516f5f67 5623
db71a655
KM
5624 test('calendar last week', function (assert) {
5625 var i, m;
5626
5627 function makeFormat(d) {
5628 switch (d.day()) {
5629 case 0:
5630 case 3:
5631 case 6:
5632 return '[В изминалата] dddd [в] LT';
5633 case 1:
5634 case 2:
5635 case 4:
5636 case 5:
5637 return '[В изминалия] dddd [в] LT';
5638 }
516f5f67 5639 }
db71a655
KM
5640
5641 for (i = 2; i < 7; i++) {
5642 m = moment().subtract({d: i});
5643 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time');
5644 m.hours(0).minutes(0).seconds(0).milliseconds(0);
5645 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day');
5646 m.hours(23).minutes(59).seconds(59).milliseconds(999);
5647 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day');
516f5f67 5648 }
db71a655 5649 });
516f5f67 5650
db71a655
KM
5651 test('calendar all else', function (assert) {
5652 var weeksAgo = moment().subtract({w: 1}),
5653 weeksFromNow = moment().add({w: 1});
516f5f67 5654
db71a655
KM
5655 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
5656 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 5657
db71a655
KM
5658 weeksAgo = moment().subtract({w: 2});
5659 weeksFromNow = moment().add({w: 2});
516f5f67 5660
db71a655
KM
5661 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
5662 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
5663 });
5664
5665 test('weeks year starting sunday formatted', function (assert) {
5666 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-ви', 'Dec 26 2011 should be week 1');
5667 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-ви', 'Jan 1 2012 should be week 1');
5668 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-ри', 'Jan 2 2012 should be week 2');
5669 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-ри', 'Jan 8 2012 should be week 2');
5670 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-ти', 'Jan 9 2012 should be week 3');
5671 });
73f3c911
IC
5672
5673})));
516f5f67 5674
516f5f67 5675
c74a101d
IC
5676;(function (global, factory) {
5677 typeof exports === 'object' && typeof module !== 'undefined'
5678 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
5679 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
5680 factory(global.moment)
73f3c911 5681}(this, (function (moment) { 'use strict';
516f5f67 5682
db71a655
KM
5683 function each(array, callback) {
5684 var i;
5685 for (i = 0; i < array.length; i++) {
5686 callback(array[i], i, array);
5687 }
b135bf1a
IC
5688 }
5689
c58511b9
KM
5690 function setupDeprecationHandler(test, moment$$1, scope) {
5691 test._expectedDeprecations = null;
5692 test._observedDeprecations = null;
5693 test._oldSupress = moment$$1.suppressDeprecationWarnings;
5694 moment$$1.suppressDeprecationWarnings = true;
5695 test.expectedDeprecations = function () {
5696 test._expectedDeprecations = arguments;
5697 test._observedDeprecations = [];
5698 };
5699 moment$$1.deprecationHandler = function (name, msg) {
5700 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
5701 if (deprecationId === -1) {
5702 throw new Error('Unexpected deprecation thrown name=' +
5703 name + ' msg=' + msg);
5704 }
5705 test._observedDeprecations[deprecationId] = 1;
5706 };
5707 }
5708
5709 function teardownDeprecationHandler(test, moment$$1, scope) {
5710 moment$$1.suppressDeprecationWarnings = test._oldSupress;
5711
5712 if (test._expectedDeprecations != null) {
5713 var missedDeprecations = [];
5714 each(test._expectedDeprecations, function (deprecationPattern, id) {
5715 if (test._observedDeprecations[id] !== 1) {
5716 missedDeprecations.push(deprecationPattern);
5717 }
5718 });
5719 if (missedDeprecations.length !== 0) {
5720 throw new Error('Expected deprecation warnings did not happen: ' +
5721 missedDeprecations.join(' '));
5722 }
5723 }
5724 }
5725
5726 function matchedDeprecation(name, msg, deprecations) {
5727 if (deprecations == null) {
5728 return -1;
5729 }
5730 for (var i = 0; i < deprecations.length; ++i) {
5731 if (name != null && name === deprecations[i]) {
5732 return i;
5733 }
5734 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
5735 return i;
5736 }
5737 }
5738 return -1;
5739 }
5740
5741 /*global QUnit:false*/
5742
5743 var test = QUnit.test;
5744
db71a655
KM
5745 function objectKeys(obj) {
5746 if (Object.keys) {
5747 return Object.keys(obj);
5748 } else {
5749 // IE8
5750 var res = [], i;
5751 for (i in obj) {
5752 if (obj.hasOwnProperty(i)) {
5753 res.push(i);
5754 }
b135bf1a 5755 }
db71a655 5756 return res;
b135bf1a
IC
5757 }
5758 }
5759
db71a655 5760 // Pick the first defined of two or three arguments.
73f3c911 5761
db71a655
KM
5762 function defineCommonLocaleTests(locale, options) {
5763 test('lenient day of month ordinal parsing', function (assert) {
5764 var i, ordinalStr, testMoment;
5765 for (i = 1; i <= 31; ++i) {
5766 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
5767 testMoment = moment(ordinalStr, 'YYYY MM Do');
5768 assert.equal(testMoment.year(), 2014,
5769 'lenient day of month ordinal parsing ' + i + ' year check');
5770 assert.equal(testMoment.month(), 0,
5771 'lenient day of month ordinal parsing ' + i + ' month check');
5772 assert.equal(testMoment.date(), i,
5773 'lenient day of month ordinal parsing ' + i + ' date check');
5774 }
5775 });
73f3c911 5776
db71a655
KM
5777 test('lenient day of month ordinal parsing of number', function (assert) {
5778 var i, testMoment;
5779 for (i = 1; i <= 31; ++i) {
5780 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
5781 assert.equal(testMoment.year(), 2014,
5782 'lenient day of month ordinal parsing of number ' + i + ' year check');
5783 assert.equal(testMoment.month(), 0,
5784 'lenient day of month ordinal parsing of number ' + i + ' month check');
5785 assert.equal(testMoment.date(), i,
5786 'lenient day of month ordinal parsing of number ' + i + ' date check');
5787 }
5788 });
b135bf1a 5789
db71a655
KM
5790 test('strict day of month ordinal parsing', function (assert) {
5791 var i, ordinalStr, testMoment;
5792 for (i = 1; i <= 31; ++i) {
5793 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
5794 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
5795 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
5796 }
5797 });
b135bf1a 5798
db71a655
KM
5799 test('meridiem invariant', function (assert) {
5800 var h, m, t1, t2;
5801 for (h = 0; h < 24; ++h) {
5802 for (m = 0; m < 60; m += 15) {
5803 t1 = moment.utc([2000, 0, 1, h, m]);
5804 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
5805 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
5806 'meridiem at ' + t1.format('HH:mm'));
5807 }
5808 }
5809 });
5810
5811 test('date format correctness', function (assert) {
5812 var data, tokens;
5813 data = moment.localeData()._longDateFormat;
5814 tokens = objectKeys(data);
5815 each(tokens, function (srchToken) {
5816 // Check each format string to make sure it does not contain any
5817 // tokens that need to be expanded.
5818 each(tokens, function (baseToken) {
5819 // strip escaped sequences
5820 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
5821 assert.equal(false, !!~format.indexOf(srchToken),
5822 'contains ' + srchToken + ' in ' + baseToken);
5823 });
73f3c911 5824 });
b135bf1a
IC
5825 });
5826
db71a655
KM
5827 test('month parsing correctness', function (assert) {
5828 var i, m;
5829
5830 if (locale === 'tr') {
5831 // I can't fix it :(
c58511b9 5832 assert.expect(0);
db71a655
KM
5833 return;
5834 }
5835 function tester(format) {
5836 var r;
5837 r = moment(m.format(format), format);
5838 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
5839 if (locale !== 'ka') {
5840 r = moment(m.format(format).toLocaleUpperCase(), format);
5841 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
5842 }
db71a655
KM
5843 r = moment(m.format(format).toLocaleLowerCase(), format);
5844 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
5845
5846 r = moment(m.format(format), format, true);
5847 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
5848 if (locale !== 'ka') {
5849 r = moment(m.format(format).toLocaleUpperCase(), format, true);
5850 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
5851 }
db71a655
KM
5852 r = moment(m.format(format).toLocaleLowerCase(), format, true);
5853 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
5854 }
5855
5856 for (i = 0; i < 12; ++i) {
5857 m = moment([2015, i, 15, 18]);
5858 tester('MMM');
5859 tester('MMM.');
5860 tester('MMMM');
5861 tester('MMMM.');
5862 }
5863 });
b135bf1a 5864
db71a655
KM
5865 test('weekday parsing correctness', function (assert) {
5866 var i, m;
5867
96d0d679 5868 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
5869 // tr, az: There is a lower-case letter (ı), that converted to
5870 // upper then lower changes to i
5871 // ro: there is the letter ț which behaves weird under IE8
5872 // mt: letter Ħ
96d0d679 5873 // ga: month with spaces
c58511b9 5874 assert.expect(0);
db71a655
KM
5875 return;
5876 }
5877 function tester(format) {
5878 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
5879 r = moment(m.format(format), format);
5880 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
5881 if (locale !== 'ka') {
5882 r = moment(m.format(format).toLocaleUpperCase(), format);
5883 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
5884 }
db71a655
KM
5885 r = moment(m.format(format).toLocaleLowerCase(), format);
5886 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
5887 r = moment(m.format(format), format, true);
5888 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
5889 if (locale !== 'ka') {
5890 r = moment(m.format(format).toLocaleUpperCase(), format, true);
5891 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
5892 }
db71a655
KM
5893 r = moment(m.format(format).toLocaleLowerCase(), format, true);
5894 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
5895 }
5896
5897 for (i = 0; i < 7; ++i) {
5898 m = moment.utc([2015, 0, i + 1, 18]);
5899 tester('dd');
5900 tester('ddd');
5901 tester('dddd');
5902 }
5903 });
b135bf1a 5904
db71a655
KM
5905 test('valid localeData', function (assert) {
5906 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
5907 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
5908 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
5909 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
5910 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
5911 });
96d0d679
KM
5912
5913 test('localeData weekdays can localeSort', function (assert) {
5914 var weekdays = moment().localeData().weekdays();
5915 var weekdaysShort = moment().localeData().weekdaysShort();
5916 var weekdaysMin = moment().localeData().weekdaysMin();
5917 var shift = moment().localeData()._week.dow;
5918 assert.deepEqual(
5919 moment().localeData().weekdays(true),
5920 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
5921 'weekdays should localeSort');
5922 assert.deepEqual(
5923 moment().localeData().weekdaysShort(true),
5924 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
5925 'weekdaysShort should localeSort');
5926 assert.deepEqual(
5927 moment().localeData().weekdaysMin(true),
5928 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
5929 'weekdaysMin should localeSort');
5930 });
db71a655 5931 }
d6651c21 5932
db71a655
KM
5933 /*global QUnit:false*/
5934
db71a655
KM
5935 function localeModule (name, lifecycle) {
5936 QUnit.module('locale:' + name, {
c58511b9 5937 beforeEach : function () {
db71a655
KM
5938 moment.locale(name);
5939 moment.createFromInputFallback = function (config) {
5940 throw new Error('input not handled by moment: ' + config._i);
5941 };
5942 setupDeprecationHandler(test, moment, 'locale');
5943 if (lifecycle && lifecycle.setup) {
5944 lifecycle.setup();
5945 }
5946 },
c58511b9 5947 afterEach : function () {
db71a655
KM
5948 moment.locale('en');
5949 teardownDeprecationHandler(test, moment, 'locale');
5950 if (lifecycle && lifecycle.teardown) {
5951 lifecycle.teardown();
5952 }
516f5f67
IC
5953 }
5954 });
db71a655
KM
5955 defineCommonLocaleTests(name, -1, -1);
5956 }
5957
5958 localeModule('bm');
5959
5960 test('parse', function (assert) {
5961 var i,
5962 tests = 'Zanwuyekalo Zan_Fewuruyekalo Few_Marisikalo Mar_Awirilikalo Awi_Mɛkalo Mɛ_Zuwɛnkalo Zuw_Zuluyekalo Zul_Utikalo Uti_Sɛtanburukalo Sɛt_ɔkutɔburukalo ɔku_Nowanburukalo Now_Desanburukalo Des'.split('_');
5963
5964 function equalTest(input, mmm, i) {
5965 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
5966 }
5967
5968 for (i = 0; i < 12; i++) {
5969 tests[i] = tests[i].split(' ');
5970 equalTest(tests[i][0], 'MMM', i);
5971 equalTest(tests[i][1], 'MMM', i);
5972 equalTest(tests[i][0], 'MMMM', i);
5973 equalTest(tests[i][1], 'MMMM', i);
5974 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
5975 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
5976 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
5977 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
5978 }
5979 });
5980
5981 test('format', function (assert) {
5982 var a = [
5983 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Kari, Fewuruyekalo 14 2010, 3:25:50 pm'],
5984 ['ddd, hA', 'Kar, 3PM'],
5985 ['M Mo MM MMMM MMM', '2 2 02 Fewuruyekalo Few'],
5986 ['YYYY YY', '2010 10'],
5987 ['D Do DD', '14 14 14'],
5988 ['d do dddd ddd dd', '0 0 Kari Kar Ka'],
5989 ['DDD DDDo DDDD', '45 45 045'],
5990 ['w wo ww', '6 6 06'],
5991 ['h hh', '3 03'],
5992 ['H HH', '15 15'],
5993 ['m mm', '25 25'],
5994 ['s ss', '50 50'],
5995 ['a A', 'pm PM'],
5996 ['[le] Do [jour du mois]', 'le 14 jour du mois'],
5997 ['[le] DDDo [jour de l’année]', 'le 45 jour de l’année'],
5998 ['LTS', '15:25:50'],
5999 ['L', '14/02/2010'],
6000 ['LL', 'Fewuruyekalo tile 14 san 2010'],
6001 ['LLL', 'Fewuruyekalo tile 14 san 2010 lɛrɛ 15:25'],
6002 ['LLLL', 'Kari Fewuruyekalo tile 14 san 2010 lɛrɛ 15:25'],
6003 ['l', '14/2/2010'],
6004 ['ll', 'Few tile 14 san 2010'],
6005 ['lll', 'Few tile 14 san 2010 lɛrɛ 15:25'],
6006 ['llll', 'Kar Few tile 14 san 2010 lɛrɛ 15:25']
6007 ],
6008 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
6009 i;
6010
6011 for (i = 0; i < a.length; i++) {
6012 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
6013 }
6014 });
6015
6016 test('format month', function (assert) {
6017 var i,
6018 expected = 'Zanwuyekalo Zan_Fewuruyekalo Few_Marisikalo Mar_Awirilikalo Awi_Mɛkalo Mɛ_Zuwɛnkalo Zuw_Zuluyekalo Zul_Utikalo Uti_Sɛtanburukalo Sɛt_ɔkutɔburukalo ɔku_Nowanburukalo Now_Desanburukalo Des'.split('_');
6019
6020 for (i = 0; i < expected.length; i++) {
6021 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
6022 }
6023 });
6024
6025 test('format week', function (assert) {
6026 var i,
6027 expected = 'Kari Kar Ka_Ntɛnɛn Ntɛ Nt_Tarata Tar Ta_Araba Ara Ar_Alamisa Ala Al_Juma Jum Ju_Sibiri Sib Si'.split('_');
6028
6029 for (i = 0; i < expected.length; i++) {
6030 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
6031 }
6032 });
6033
6034 test('from', function (assert) {
6035 var start = moment([2007, 1, 28]);
6036
6037 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'sanga dama dama', '44 seconds = a few seconds');
6038 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'miniti kelen', '45 seconds = a minute');
6039 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'miniti kelen', '89 seconds = a minute');
6040 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), 'miniti 2', '90 seconds = 2 minutes');
6041 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), 'miniti 44', '44 minutes = 44 minutes');
6042 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'lɛrɛ kelen', '45 minutes = an hour');
6043 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'lɛrɛ kelen', '89 minutes = an hour');
6044 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), 'lɛrɛ 2', '90 minutes = 2 hours');
6045 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), 'lɛrɛ 5', '5 hours = 5 hours');
6046 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), 'lɛrɛ 21', '21 hours = 21 hours');
6047 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'tile kelen', '22 hours = a day');
6048 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'tile kelen', '35 hours = a day');
6049 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), 'tile 2', '36 hours = 2 days');
6050 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'tile kelen', '1 day = a day');
6051 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), 'tile 5', '5 days = 5 days');
6052 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), 'tile 25', '25 days = 25 days');
6053 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'kalo kelen', '26 days = a month');
6054 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'kalo kelen', '30 days = a month');
6055 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'kalo kelen', '43 days = a month');
6056 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), 'kalo 2', '46 days = 2 months');
6057 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), 'kalo 2', '75 days = 2 months');
6058 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), 'kalo 3', '76 days = 3 months');
6059 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'kalo kelen', '1 month = a month');
6060 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), 'kalo 5', '5 months = 5 months');
6061 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'san kelen', '345 days = a year');
6062 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), 'san 2', '548 days = 2 years');
6063 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'san kelen', '1 year = a year');
6064 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), 'san 5', '5 years = 5 years');
6065 });
6066
6067 test('suffix', function (assert) {
6068 assert.equal(moment(30000).from(0), 'sanga dama dama kɔnɔ', 'prefix');
6069 assert.equal(moment(0).from(30000), 'a bɛ sanga dama dama bɔ', 'suffix');
6070 });
6071
6072 test('fromNow', function (assert) {
6073 assert.equal(moment().add({s: 30}).fromNow(), 'sanga dama dama kɔnɔ', 'in a few seconds');
6074 assert.equal(moment().add({d: 5}).fromNow(), 'tile 5 kɔnɔ', 'in 5 days');
6075 });
6076
6077 test('same day', function (assert) {
6078 var a = moment().hours(12).minutes(0).seconds(0);
6079
6080 assert.equal(moment(a).calendar(), 'Bi lɛrɛ 12:00', 'Today at the same time');
6081 assert.equal(moment(a).add({m: 25}).calendar(), 'Bi lɛrɛ 12:25', 'Now plus 25 min');
6082 assert.equal(moment(a).add({h: 1}).calendar(), 'Bi lɛrɛ 13:00', 'Now plus 1 hour');
6083 assert.equal(moment(a).add({d: 1}).calendar(), 'Sini lɛrɛ 12:00', 'Tomorrow at the same time');
6084 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Bi lɛrɛ 11:00', 'Now minus 1 hour');
6085 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Kunu lɛrɛ 12:00', 'Yesterday at the same time');
6086 });
6087
6088 test('same next week', function (assert) {
6089 var i, m;
516f5f67 6090
db71a655
KM
6091 for (i = 2; i < 7; i++) {
6092 m = moment().add({d: i});
6093 assert.equal(m.calendar(), m.format('dddd [don lɛrɛ] LT'), 'Today + ' + i + ' days current time');
6094 m.hours(0).minutes(0).seconds(0).milliseconds(0);
6095 assert.equal(m.calendar(), m.format('dddd [don lɛrɛ] LT'), 'Today + ' + i + ' days beginning of day');
6096 m.hours(23).minutes(59).seconds(59).milliseconds(999);
6097 assert.equal(m.calendar(), m.format('dddd [don lɛrɛ] LT'), 'Today + ' + i + ' days end of day');
516f5f67 6098 }
db71a655
KM
6099 });
6100
6101 test('same last week', function (assert) {
6102 var i, m;
6103
6104 for (i = 2; i < 7; i++) {
6105 m = moment().subtract({d: i});
6106 assert.equal(m.calendar(), m.format('dddd [tɛmɛnen lɛrɛ] LT'), 'Today - ' + i + ' days current time');
6107 m.hours(0).minutes(0).seconds(0).milliseconds(0);
6108 assert.equal(m.calendar(), m.format('dddd [tɛmɛnen lɛrɛ] LT'), 'Today - ' + i + ' days beginning of day');
6109 m.hours(23).minutes(59).seconds(59).milliseconds(999);
6110 assert.equal(m.calendar(), m.format('dddd [tɛmɛnen lɛrɛ] LT'), 'Today - ' + i + ' days end of day');
516f5f67 6111 }
db71a655 6112 });
516f5f67 6113
db71a655
KM
6114 test('same all else', function (assert) {
6115 var weeksAgo = moment().subtract({w: 1}),
6116 weeksFromNow = moment().add({w: 1});
516f5f67 6117
db71a655
KM
6118 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
6119 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 6120
db71a655
KM
6121 weeksAgo = moment().subtract({w: 2});
6122 weeksFromNow = moment().add({w: 2});
516f5f67 6123
db71a655
KM
6124 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
6125 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
6126 });
9483e2a4 6127
db71a655
KM
6128 test('weeks year starting sunday formatted', function (assert) {
6129 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52', 'Jan 1 2012 should be week 52');
6130 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1', 'Jan 2 2012 should be week 1');
6131 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1', 'Jan 8 2012 should be week 1');
6132 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2', 'Jan 9 2012 should be week 2');
6133 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2', 'Jan 15 2012 should be week 2');
6134 });
9483e2a4
IC
6135
6136})));
6137
6138
6139;(function (global, factory) {
6140 typeof exports === 'object' && typeof module !== 'undefined'
6141 && typeof require === 'function' ? factory(require('../../moment')) :
6142 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
6143 factory(global.moment)
6144}(this, (function (moment) { 'use strict';
6145
db71a655
KM
6146 function each(array, callback) {
6147 var i;
6148 for (i = 0; i < array.length; i++) {
6149 callback(array[i], i, array);
6150 }
9483e2a4 6151 }
9483e2a4 6152
c58511b9
KM
6153 function setupDeprecationHandler(test, moment$$1, scope) {
6154 test._expectedDeprecations = null;
6155 test._observedDeprecations = null;
6156 test._oldSupress = moment$$1.suppressDeprecationWarnings;
6157 moment$$1.suppressDeprecationWarnings = true;
6158 test.expectedDeprecations = function () {
6159 test._expectedDeprecations = arguments;
6160 test._observedDeprecations = [];
6161 };
6162 moment$$1.deprecationHandler = function (name, msg) {
6163 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
6164 if (deprecationId === -1) {
6165 throw new Error('Unexpected deprecation thrown name=' +
6166 name + ' msg=' + msg);
6167 }
6168 test._observedDeprecations[deprecationId] = 1;
6169 };
6170 }
6171
6172 function teardownDeprecationHandler(test, moment$$1, scope) {
6173 moment$$1.suppressDeprecationWarnings = test._oldSupress;
6174
6175 if (test._expectedDeprecations != null) {
6176 var missedDeprecations = [];
6177 each(test._expectedDeprecations, function (deprecationPattern, id) {
6178 if (test._observedDeprecations[id] !== 1) {
6179 missedDeprecations.push(deprecationPattern);
6180 }
6181 });
6182 if (missedDeprecations.length !== 0) {
6183 throw new Error('Expected deprecation warnings did not happen: ' +
6184 missedDeprecations.join(' '));
6185 }
6186 }
6187 }
6188
6189 function matchedDeprecation(name, msg, deprecations) {
6190 if (deprecations == null) {
6191 return -1;
6192 }
6193 for (var i = 0; i < deprecations.length; ++i) {
6194 if (name != null && name === deprecations[i]) {
6195 return i;
6196 }
6197 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
6198 return i;
6199 }
6200 }
6201 return -1;
6202 }
6203
6204 /*global QUnit:false*/
6205
6206 var test = QUnit.test;
6207
db71a655
KM
6208 function objectKeys(obj) {
6209 if (Object.keys) {
6210 return Object.keys(obj);
6211 } else {
6212 // IE8
6213 var res = [], i;
6214 for (i in obj) {
6215 if (obj.hasOwnProperty(i)) {
6216 res.push(i);
6217 }
9483e2a4 6218 }
db71a655 6219 return res;
9483e2a4 6220 }
9483e2a4 6221 }
9483e2a4 6222
db71a655 6223 // Pick the first defined of two or three arguments.
9483e2a4 6224
db71a655
KM
6225 function defineCommonLocaleTests(locale, options) {
6226 test('lenient day of month ordinal parsing', function (assert) {
6227 var i, ordinalStr, testMoment;
6228 for (i = 1; i <= 31; ++i) {
6229 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
6230 testMoment = moment(ordinalStr, 'YYYY MM Do');
6231 assert.equal(testMoment.year(), 2014,
6232 'lenient day of month ordinal parsing ' + i + ' year check');
6233 assert.equal(testMoment.month(), 0,
6234 'lenient day of month ordinal parsing ' + i + ' month check');
6235 assert.equal(testMoment.date(), i,
6236 'lenient day of month ordinal parsing ' + i + ' date check');
6237 }
6238 });
9483e2a4 6239
db71a655
KM
6240 test('lenient day of month ordinal parsing of number', function (assert) {
6241 var i, testMoment;
6242 for (i = 1; i <= 31; ++i) {
6243 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
6244 assert.equal(testMoment.year(), 2014,
6245 'lenient day of month ordinal parsing of number ' + i + ' year check');
6246 assert.equal(testMoment.month(), 0,
6247 'lenient day of month ordinal parsing of number ' + i + ' month check');
6248 assert.equal(testMoment.date(), i,
6249 'lenient day of month ordinal parsing of number ' + i + ' date check');
6250 }
6251 });
9483e2a4 6252
db71a655
KM
6253 test('strict day of month ordinal parsing', function (assert) {
6254 var i, ordinalStr, testMoment;
6255 for (i = 1; i <= 31; ++i) {
6256 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
6257 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
6258 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
6259 }
6260 });
9483e2a4 6261
db71a655
KM
6262 test('meridiem invariant', function (assert) {
6263 var h, m, t1, t2;
6264 for (h = 0; h < 24; ++h) {
6265 for (m = 0; m < 60; m += 15) {
6266 t1 = moment.utc([2000, 0, 1, h, m]);
6267 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
6268 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
6269 'meridiem at ' + t1.format('HH:mm'));
6270 }
6271 }
6272 });
6273
6274 test('date format correctness', function (assert) {
6275 var data, tokens;
6276 data = moment.localeData()._longDateFormat;
6277 tokens = objectKeys(data);
6278 each(tokens, function (srchToken) {
6279 // Check each format string to make sure it does not contain any
6280 // tokens that need to be expanded.
6281 each(tokens, function (baseToken) {
6282 // strip escaped sequences
6283 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
6284 assert.equal(false, !!~format.indexOf(srchToken),
6285 'contains ' + srchToken + ' in ' + baseToken);
6286 });
9483e2a4
IC
6287 });
6288 });
9483e2a4 6289
db71a655
KM
6290 test('month parsing correctness', function (assert) {
6291 var i, m;
6292
6293 if (locale === 'tr') {
6294 // I can't fix it :(
c58511b9 6295 assert.expect(0);
db71a655
KM
6296 return;
6297 }
6298 function tester(format) {
6299 var r;
6300 r = moment(m.format(format), format);
6301 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
6302 if (locale !== 'ka') {
6303 r = moment(m.format(format).toLocaleUpperCase(), format);
6304 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
6305 }
db71a655
KM
6306 r = moment(m.format(format).toLocaleLowerCase(), format);
6307 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
6308
6309 r = moment(m.format(format), format, true);
6310 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
6311 if (locale !== 'ka') {
6312 r = moment(m.format(format).toLocaleUpperCase(), format, true);
6313 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
6314 }
db71a655
KM
6315 r = moment(m.format(format).toLocaleLowerCase(), format, true);
6316 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
6317 }
6318
6319 for (i = 0; i < 12; ++i) {
6320 m = moment([2015, i, 15, 18]);
6321 tester('MMM');
6322 tester('MMM.');
6323 tester('MMMM');
6324 tester('MMMM.');
6325 }
6326 });
9483e2a4 6327
db71a655
KM
6328 test('weekday parsing correctness', function (assert) {
6329 var i, m;
6330
96d0d679 6331 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
6332 // tr, az: There is a lower-case letter (ı), that converted to
6333 // upper then lower changes to i
6334 // ro: there is the letter ț which behaves weird under IE8
6335 // mt: letter Ħ
96d0d679 6336 // ga: month with spaces
c58511b9 6337 assert.expect(0);
db71a655
KM
6338 return;
6339 }
6340 function tester(format) {
6341 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
6342 r = moment(m.format(format), format);
6343 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
6344 if (locale !== 'ka') {
6345 r = moment(m.format(format).toLocaleUpperCase(), format);
6346 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
6347 }
db71a655
KM
6348 r = moment(m.format(format).toLocaleLowerCase(), format);
6349 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
6350 r = moment(m.format(format), format, true);
6351 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
6352 if (locale !== 'ka') {
6353 r = moment(m.format(format).toLocaleUpperCase(), format, true);
6354 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
6355 }
db71a655
KM
6356 r = moment(m.format(format).toLocaleLowerCase(), format, true);
6357 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
6358 }
6359
6360 for (i = 0; i < 7; ++i) {
6361 m = moment.utc([2015, 0, i + 1, 18]);
6362 tester('dd');
6363 tester('ddd');
6364 tester('dddd');
6365 }
6366 });
9483e2a4 6367
db71a655
KM
6368 test('valid localeData', function (assert) {
6369 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
6370 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
6371 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
6372 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
6373 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
6374 });
96d0d679
KM
6375
6376 test('localeData weekdays can localeSort', function (assert) {
6377 var weekdays = moment().localeData().weekdays();
6378 var weekdaysShort = moment().localeData().weekdaysShort();
6379 var weekdaysMin = moment().localeData().weekdaysMin();
6380 var shift = moment().localeData()._week.dow;
6381 assert.deepEqual(
6382 moment().localeData().weekdays(true),
6383 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
6384 'weekdays should localeSort');
6385 assert.deepEqual(
6386 moment().localeData().weekdaysShort(true),
6387 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
6388 'weekdaysShort should localeSort');
6389 assert.deepEqual(
6390 moment().localeData().weekdaysMin(true),
6391 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
6392 'weekdaysMin should localeSort');
6393 });
db71a655 6394 }
9483e2a4 6395
db71a655
KM
6396 /*global QUnit:false*/
6397
db71a655
KM
6398 function localeModule (name, lifecycle) {
6399 QUnit.module('locale:' + name, {
c58511b9 6400 beforeEach : function () {
db71a655
KM
6401 moment.locale(name);
6402 moment.createFromInputFallback = function (config) {
6403 throw new Error('input not handled by moment: ' + config._i);
6404 };
6405 setupDeprecationHandler(test, moment, 'locale');
6406 if (lifecycle && lifecycle.setup) {
6407 lifecycle.setup();
6408 }
6409 },
c58511b9 6410 afterEach : function () {
db71a655
KM
6411 moment.locale('en');
6412 teardownDeprecationHandler(test, moment, 'locale');
6413 if (lifecycle && lifecycle.teardown) {
6414 lifecycle.teardown();
6415 }
9483e2a4
IC
6416 }
6417 });
db71a655
KM
6418 defineCommonLocaleTests(name, -1, -1);
6419 }
6420
6421 localeModule('bn');
6422
6423 test('parse', function (assert) {
6424 var tests = 'জানুয়ারী জানু_ফেব্রুয়ারি ফেব_মার্চ মার্চ_এপ্রিল এপ্র_মে মে_জুন জুন_জুলাই জুল_আগস্ট আগ_সেপ্টেম্বর সেপ্ট_অক্টোবর অক্টো_নভেম্বর নভে_ডিসেম্বর ডিসে'.split('_'), i;
6425 function equalTest(input, mmm, i) {
6426 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
6427 }
6428 for (i = 0; i < 12; i++) {
6429 tests[i] = tests[i].split(' ');
6430 equalTest(tests[i][0], 'MMM', i);
6431 equalTest(tests[i][1], 'MMM', i);
6432 equalTest(tests[i][0], 'MMMM', i);
6433 equalTest(tests[i][1], 'MMMM', i);
6434 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
6435 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
6436 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
6437 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
6438 }
6439 });
6440
6441 test('format', function (assert) {
6442 var a = [
6443 ['dddd, Do MMMM YYYY, a h:mm:ss সময়', 'রবিবার, ১৪ ফেব্রুয়ারি ২০১০, দুপুর ৩:২৫:৫০ সময়'],
6444 ['ddd, a h সময়', 'রবি, দুপুর ৩ সময়'],
6445 ['M Mo MM MMMM MMM', '২ ২ ০২ ফেব্রুয়ারি ফেব'],
6446 ['YYYY YY', '২০১০ ১০'],
6447 ['D Do DD', '১৪ ১৪ ১৪'],
6448 ['d do dddd ddd dd', '০ ০ রবিবার রবি রবি'],
6449 ['DDD DDDo DDDD', '৪৫ ৪৫ ০৪৫'],
6450 ['w wo ww', '৮ ৮ ০৮'],
6451 ['h hh', '৩ ০৩'],
6452 ['H HH', '১৫ ১৫'],
6453 ['m mm', '২৫ ২৫'],
6454 ['s ss', '৫০ ৫০'],
6455 ['a A', 'দুপুর দুপুর'],
6456 ['LT', 'দুপুর ৩:২৫ সময়'],
6457 ['LTS', 'দুপুর ৩:২৫:৫০ সময়'],
6458 ['L', '১৪/০২/২০১০'],
6459 ['LL', '১৪ ফেব্রুয়ারি ২০১০'],
6460 ['LLL', '১৪ ফেব্রুয়ারি ২০১০, দুপুর ৩:২৫ সময়'],
6461 ['LLLL', 'রবিবার, ১৪ ফেব্রুয়ারি ২০১০, দুপুর ৩:২৫ সময়'],
6462 ['l', '১৪/২/২০১০'],
6463 ['ll', '১৪ ফেব ২০১০'],
6464 ['lll', '১৪ ফেব ২০১০, দুপুর ৩:২৫ সময়'],
6465 ['llll', 'রবি, ১৪ ফেব ২০১০, দুপুর ৩:২৫ সময়']
6466 ],
6467 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
6468 i;
6469 for (i = 0; i < a.length; i++) {
6470 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
6471 }
6472 });
6473
6474 test('format ordinal', function (assert) {
6475 assert.equal(moment([2011, 0, 1]).format('DDDo'), '১', '১');
6476 assert.equal(moment([2011, 0, 2]).format('DDDo'), '২', '২');
6477 assert.equal(moment([2011, 0, 3]).format('DDDo'), '৩', '৩');
6478 assert.equal(moment([2011, 0, 4]).format('DDDo'), '৪', '৪');
6479 assert.equal(moment([2011, 0, 5]).format('DDDo'), '৫', '৫');
6480 assert.equal(moment([2011, 0, 6]).format('DDDo'), '৬', '৬');
6481 assert.equal(moment([2011, 0, 7]).format('DDDo'), '৭', '৭');
6482 assert.equal(moment([2011, 0, 8]).format('DDDo'), '৮', '৮');
6483 assert.equal(moment([2011, 0, 9]).format('DDDo'), '৯', '৯');
6484 assert.equal(moment([2011, 0, 10]).format('DDDo'), '১০', '১০');
6485
6486 assert.equal(moment([2011, 0, 11]).format('DDDo'), '১১', '১১');
6487 assert.equal(moment([2011, 0, 12]).format('DDDo'), '১২', '১২');
6488 assert.equal(moment([2011, 0, 13]).format('DDDo'), '১৩', '১৩');
6489 assert.equal(moment([2011, 0, 14]).format('DDDo'), '১৪', '১৪');
6490 assert.equal(moment([2011, 0, 15]).format('DDDo'), '১৫', '১৫');
6491 assert.equal(moment([2011, 0, 16]).format('DDDo'), '১৬', '১৬');
6492 assert.equal(moment([2011, 0, 17]).format('DDDo'), '১৭', '১৭');
6493 assert.equal(moment([2011, 0, 18]).format('DDDo'), '১৮', '১৮');
6494 assert.equal(moment([2011, 0, 19]).format('DDDo'), '১৯', '১৯');
6495 assert.equal(moment([2011, 0, 20]).format('DDDo'), '২০', '২০');
6496
6497 assert.equal(moment([2011, 0, 21]).format('DDDo'), '২১', '২১');
6498 assert.equal(moment([2011, 0, 22]).format('DDDo'), '২২', '২২');
6499 assert.equal(moment([2011, 0, 23]).format('DDDo'), '২৩', '২৩');
6500 assert.equal(moment([2011, 0, 24]).format('DDDo'), '২৪', '২৪');
6501 assert.equal(moment([2011, 0, 25]).format('DDDo'), '২৫', '২৫');
6502 assert.equal(moment([2011, 0, 26]).format('DDDo'), '২৬', '২৬');
6503 assert.equal(moment([2011, 0, 27]).format('DDDo'), '২৭', '২৭');
6504 assert.equal(moment([2011, 0, 28]).format('DDDo'), '২৮', '२৮');
6505 assert.equal(moment([2011, 0, 29]).format('DDDo'), '২৯', '২৯');
6506 assert.equal(moment([2011, 0, 30]).format('DDDo'), '৩০', '৩০');
6507
6508 assert.equal(moment([2011, 0, 31]).format('DDDo'), '৩১', '৩১');
6509 });
6510
6511 test('format month', function (assert) {
6512 var expected = 'জানুয়ারী জানু_ফেব্রুয়ারি ফেব_মার্চ মার্চ_এপ্রিল এপ্র_মে মে_জুন জুন_জুলাই জুল_আগস্ট আগ_সেপ্টেম্বর সেপ্ট_অক্টোবর অক্টো_নভেম্বর নভে_ডিসেম্বর ডিসে'.split('_'), i;
6513 for (i = 0; i < expected.length; i++) {
6514 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
6515 }
6516 });
6517
6518 test('format week', function (assert) {
6519 var expected = 'রবিবার রবি রবি_সোমবার সোম সোম_মঙ্গলবার মঙ্গল মঙ্গ_বুধবার বুধ বুধ_বৃহস্পতিবার বৃহস্পতি বৃহঃ_শুক্রবার শুক্র শুক্র_শনিবার শনি শনি'.split('_'), i;
6520 for (i = 0; i < expected.length; i++) {
6521 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
6522 }
6523 });
6524
6525 test('from', function (assert) {
6526 var start = moment([2007, 1, 28]);
6527 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'কয়েক সেকেন্ড', '44 seconds = a few seconds');
6528 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'এক মিনিট', '45 seconds = a minute');
6529 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'এক মিনিট', '89 seconds = a minute');
6530 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '২ মিনিট', '90 seconds = 2 minutes');
6531 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '৪৪ মিনিট', '44 minutes = 44 minutes');
6532 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'এক ঘন্টা', '45 minutes = an hour');
6533 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'এক ঘন্টা', '89 minutes = an hour');
6534 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '২ ঘন্টা', '90 minutes = 2 hours');
6535 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '৫ ঘন্টা', '5 hours = 5 hours');
6536 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '২১ ঘন্টা', '21 hours = 21 hours');
6537 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'এক দিন', '22 hours = a day');
6538 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'এক দিন', '35 hours = a day');
6539 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '২ দিন', '36 hours = 2 days');
6540 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'এক দিন', '1 day = a day');
6541 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '৫ দিন', '5 days = 5 days');
6542 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '২৫ দিন', '25 days = 25 days');
6543 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'এক মাস', '26 days = a month');
6544 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'এক মাস', '30 days = a month');
6545 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '২ মাস', '46 days = 2 months');
6546 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '২ মাস', '75 days = 2 months');
6547 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '৩ মাস', '76 days = 3 months');
6548 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'এক মাস', '1 month = a month');
6549 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '৫ মাস', '5 months = 5 months');
6550 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'এক বছর', '345 days = a year');
6551 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '২ বছর', '548 days = 2 years');
6552 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'এক বছর', '1 year = a year');
6553 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '৫ বছর', '5 years = 5 years');
6554 });
6555
6556 test('suffix', function (assert) {
6557 assert.equal(moment(30000).from(0), 'কয়েক সেকেন্ড পরে', 'prefix');
6558 assert.equal(moment(0).from(30000), 'কয়েক সেকেন্ড আগে', 'suffix');
6559 });
6560
6561 test('now from now', function (assert) {
6562 assert.equal(moment().fromNow(), 'কয়েক সেকেন্ড আগে', 'now from now should display as in the past');
6563 });
6564
6565 test('fromNow', function (assert) {
6566 assert.equal(moment().add({s: 30}).fromNow(), 'কয়েক সেকেন্ড পরে', 'কয়েক সেকেন্ড পরে');
6567 assert.equal(moment().add({d: 5}).fromNow(), '৫ দিন পরে', '৫ দিন পরে');
6568 });
6569
6570 test('calendar day', function (assert) {
6571 var a = moment().hours(12).minutes(0).seconds(0);
6572
6573 assert.equal(moment(a).calendar(), 'আজ দুপুর ১২:০০ সময়', 'today at the same time');
6574 assert.equal(moment(a).add({m: 25}).calendar(), 'আজ দুপুর ১২:২৫ সময়', 'Now plus 25 min');
6575 assert.equal(moment(a).add({h: 3}).calendar(), 'আজ দুপুর ৩:০০ সময়', 'Now plus 3 hours');
6576 assert.equal(moment(a).add({d: 1}).calendar(), 'আগামীকাল দুপুর ১২:০০ সময়', 'tomorrow at the same time');
6577 assert.equal(moment(a).subtract({h: 1}).calendar(), 'আজ দুপুর ১১:০০ সময়', 'Now minus 1 hour');
6578 assert.equal(moment(a).subtract({d: 1}).calendar(), 'গতকাল দুপুর ১২:০০ সময়', 'yesterday at the same time');
6579 });
6580
6581 test('calendar next week', function (assert) {
6582 var i, m;
6583 for (i = 2; i < 7; i++) {
6584 m = moment().add({d: i});
6585 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days current time');
6586 m.hours(0).minutes(0).seconds(0).milliseconds(0);
6587 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days beginning of day');
6588 m.hours(23).minutes(59).seconds(59).milliseconds(999);
6589 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days end of day');
9483e2a4 6590 }
db71a655 6591 });
9483e2a4 6592
db71a655
KM
6593 test('calendar last week', function (assert) {
6594 var i, m;
6595
6596 for (i = 2; i < 7; i++) {
6597 m = moment().subtract({d: i});
6598 assert.equal(m.calendar(), m.format('[গত] dddd[,] LT'), 'Today - ' + i + ' days current time');
6599 m.hours(0).minutes(0).seconds(0).milliseconds(0);
6600 assert.equal(m.calendar(), m.format('[গত] dddd[,] LT'), 'Today - ' + i + ' days beginning of day');
6601 m.hours(23).minutes(59).seconds(59).milliseconds(999);
6602 assert.equal(m.calendar(), m.format('[গত] dddd[,] LT'), 'Today - ' + i + ' days end of day');
9483e2a4 6603 }
db71a655 6604 });
9483e2a4 6605
db71a655
KM
6606 test('calendar all else', function (assert) {
6607 var weeksAgo = moment().subtract({w: 1}),
6608 weeksFromNow = moment().add({w: 1});
9483e2a4 6609
db71a655
KM
6610 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
6611 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
9483e2a4 6612
db71a655
KM
6613 weeksAgo = moment().subtract({w: 2});
6614 weeksFromNow = moment().add({w: 2});
9483e2a4 6615
db71a655
KM
6616 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
6617 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
6618 });
6619
6620 test('meridiem', function (assert) {
6621 assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), 'রাত', 'before dawn');
6622 assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), 'সকাল', 'morning');
6623 assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), 'দুপুর', 'during day');
6624 assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), 'বিকাল', 'evening');
6625 assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), 'বিকাল', 'late evening');
6626 assert.equal(moment([2011, 2, 23, 21, 20]).format('a'), 'রাত', 'night');
6627
6628 assert.equal(moment([2011, 2, 23, 2, 30]).format('A'), 'রাত', 'before dawn');
6629 assert.equal(moment([2011, 2, 23, 9, 30]).format('A'), 'সকাল', 'morning');
6630 assert.equal(moment([2011, 2, 23, 14, 30]).format('A'), 'দুপুর', ' during day');
6631 assert.equal(moment([2011, 2, 23, 17, 30]).format('A'), 'বিকাল', 'evening');
6632 assert.equal(moment([2011, 2, 23, 19, 30]).format('A'), 'বিকাল', 'late evening');
6633 assert.equal(moment([2011, 2, 23, 21, 20]).format('A'), 'রাত', 'night');
6634 });
6635
6636 test('weeks year starting sunday formatted', function (assert) {
6637 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '১ ০১ ১', 'Jan 1 2012 should be week 1');
6638 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '১ ০১ ১', 'Jan 7 2012 should be week 1');
6639 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '২ ০২ ২', 'Jan 8 2012 should be week 2');
6640 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '২ ০২ ২', 'Jan 14 2012 should be week 2');
6641 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '৩ ০৩ ৩', 'Jan 15 2012 should be week 3');
6642 });
73f3c911
IC
6643
6644})));
516f5f67 6645
516f5f67 6646
c74a101d
IC
6647;(function (global, factory) {
6648 typeof exports === 'object' && typeof module !== 'undefined'
6649 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
6650 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
6651 factory(global.moment)
73f3c911 6652}(this, (function (moment) { 'use strict';
516f5f67 6653
db71a655
KM
6654 function each(array, callback) {
6655 var i;
6656 for (i = 0; i < array.length; i++) {
6657 callback(array[i], i, array);
6658 }
b135bf1a
IC
6659 }
6660
c58511b9
KM
6661 function setupDeprecationHandler(test, moment$$1, scope) {
6662 test._expectedDeprecations = null;
6663 test._observedDeprecations = null;
6664 test._oldSupress = moment$$1.suppressDeprecationWarnings;
6665 moment$$1.suppressDeprecationWarnings = true;
6666 test.expectedDeprecations = function () {
6667 test._expectedDeprecations = arguments;
6668 test._observedDeprecations = [];
6669 };
6670 moment$$1.deprecationHandler = function (name, msg) {
6671 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
6672 if (deprecationId === -1) {
6673 throw new Error('Unexpected deprecation thrown name=' +
6674 name + ' msg=' + msg);
6675 }
6676 test._observedDeprecations[deprecationId] = 1;
6677 };
6678 }
6679
6680 function teardownDeprecationHandler(test, moment$$1, scope) {
6681 moment$$1.suppressDeprecationWarnings = test._oldSupress;
6682
6683 if (test._expectedDeprecations != null) {
6684 var missedDeprecations = [];
6685 each(test._expectedDeprecations, function (deprecationPattern, id) {
6686 if (test._observedDeprecations[id] !== 1) {
6687 missedDeprecations.push(deprecationPattern);
6688 }
6689 });
6690 if (missedDeprecations.length !== 0) {
6691 throw new Error('Expected deprecation warnings did not happen: ' +
6692 missedDeprecations.join(' '));
6693 }
6694 }
6695 }
6696
6697 function matchedDeprecation(name, msg, deprecations) {
6698 if (deprecations == null) {
6699 return -1;
6700 }
6701 for (var i = 0; i < deprecations.length; ++i) {
6702 if (name != null && name === deprecations[i]) {
6703 return i;
6704 }
6705 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
6706 return i;
6707 }
6708 }
6709 return -1;
6710 }
6711
6712 /*global QUnit:false*/
6713
6714 var test = QUnit.test;
6715
db71a655
KM
6716 function objectKeys(obj) {
6717 if (Object.keys) {
6718 return Object.keys(obj);
6719 } else {
6720 // IE8
6721 var res = [], i;
6722 for (i in obj) {
6723 if (obj.hasOwnProperty(i)) {
6724 res.push(i);
6725 }
b135bf1a 6726 }
db71a655 6727 return res;
b135bf1a
IC
6728 }
6729 }
6730
db71a655 6731 // Pick the first defined of two or three arguments.
73f3c911 6732
db71a655
KM
6733 function defineCommonLocaleTests(locale, options) {
6734 test('lenient day of month ordinal parsing', function (assert) {
6735 var i, ordinalStr, testMoment;
6736 for (i = 1; i <= 31; ++i) {
6737 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
6738 testMoment = moment(ordinalStr, 'YYYY MM Do');
6739 assert.equal(testMoment.year(), 2014,
6740 'lenient day of month ordinal parsing ' + i + ' year check');
6741 assert.equal(testMoment.month(), 0,
6742 'lenient day of month ordinal parsing ' + i + ' month check');
6743 assert.equal(testMoment.date(), i,
6744 'lenient day of month ordinal parsing ' + i + ' date check');
6745 }
6746 });
73f3c911 6747
db71a655
KM
6748 test('lenient day of month ordinal parsing of number', function (assert) {
6749 var i, testMoment;
6750 for (i = 1; i <= 31; ++i) {
6751 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
6752 assert.equal(testMoment.year(), 2014,
6753 'lenient day of month ordinal parsing of number ' + i + ' year check');
6754 assert.equal(testMoment.month(), 0,
6755 'lenient day of month ordinal parsing of number ' + i + ' month check');
6756 assert.equal(testMoment.date(), i,
6757 'lenient day of month ordinal parsing of number ' + i + ' date check');
6758 }
6759 });
b135bf1a 6760
db71a655
KM
6761 test('strict day of month ordinal parsing', function (assert) {
6762 var i, ordinalStr, testMoment;
6763 for (i = 1; i <= 31; ++i) {
6764 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
6765 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
6766 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
6767 }
6768 });
b135bf1a 6769
db71a655
KM
6770 test('meridiem invariant', function (assert) {
6771 var h, m, t1, t2;
6772 for (h = 0; h < 24; ++h) {
6773 for (m = 0; m < 60; m += 15) {
6774 t1 = moment.utc([2000, 0, 1, h, m]);
6775 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
6776 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
6777 'meridiem at ' + t1.format('HH:mm'));
6778 }
6779 }
b135bf1a
IC
6780 });
6781
db71a655
KM
6782 test('date format correctness', function (assert) {
6783 var data, tokens;
6784 data = moment.localeData()._longDateFormat;
6785 tokens = objectKeys(data);
6786 each(tokens, function (srchToken) {
6787 // Check each format string to make sure it does not contain any
6788 // tokens that need to be expanded.
6789 each(tokens, function (baseToken) {
6790 // strip escaped sequences
6791 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
6792 assert.equal(false, !!~format.indexOf(srchToken),
6793 'contains ' + srchToken + ' in ' + baseToken);
6794 });
6795 });
6796 });
b135bf1a 6797
db71a655
KM
6798 test('month parsing correctness', function (assert) {
6799 var i, m;
6800
6801 if (locale === 'tr') {
6802 // I can't fix it :(
c58511b9 6803 assert.expect(0);
db71a655
KM
6804 return;
6805 }
6806 function tester(format) {
6807 var r;
6808 r = moment(m.format(format), format);
6809 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
6810 if (locale !== 'ka') {
6811 r = moment(m.format(format).toLocaleUpperCase(), format);
6812 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
6813 }
db71a655
KM
6814 r = moment(m.format(format).toLocaleLowerCase(), format);
6815 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
6816
6817 r = moment(m.format(format), format, true);
6818 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
6819 if (locale !== 'ka') {
6820 r = moment(m.format(format).toLocaleUpperCase(), format, true);
6821 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
6822 }
db71a655
KM
6823 r = moment(m.format(format).toLocaleLowerCase(), format, true);
6824 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
6825 }
6826
6827 for (i = 0; i < 12; ++i) {
6828 m = moment([2015, i, 15, 18]);
6829 tester('MMM');
6830 tester('MMM.');
6831 tester('MMMM');
6832 tester('MMMM.');
6833 }
6834 });
b135bf1a 6835
db71a655
KM
6836 test('weekday parsing correctness', function (assert) {
6837 var i, m;
6838
96d0d679 6839 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
6840 // tr, az: There is a lower-case letter (ı), that converted to
6841 // upper then lower changes to i
6842 // ro: there is the letter ț which behaves weird under IE8
6843 // mt: letter Ħ
96d0d679 6844 // ga: month with spaces
c58511b9 6845 assert.expect(0);
db71a655
KM
6846 return;
6847 }
6848 function tester(format) {
6849 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
6850 r = moment(m.format(format), format);
6851 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
6852 if (locale !== 'ka') {
6853 r = moment(m.format(format).toLocaleUpperCase(), format);
6854 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
6855 }
db71a655
KM
6856 r = moment(m.format(format).toLocaleLowerCase(), format);
6857 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
6858 r = moment(m.format(format), format, true);
6859 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
6860 if (locale !== 'ka') {
6861 r = moment(m.format(format).toLocaleUpperCase(), format, true);
6862 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
6863 }
db71a655
KM
6864 r = moment(m.format(format).toLocaleLowerCase(), format, true);
6865 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
6866 }
6867
6868 for (i = 0; i < 7; ++i) {
6869 m = moment.utc([2015, 0, i + 1, 18]);
6870 tester('dd');
6871 tester('ddd');
6872 tester('dddd');
6873 }
6874 });
d6651c21 6875
db71a655
KM
6876 test('valid localeData', function (assert) {
6877 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
6878 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
6879 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
6880 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
6881 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
6882 });
96d0d679
KM
6883
6884 test('localeData weekdays can localeSort', function (assert) {
6885 var weekdays = moment().localeData().weekdays();
6886 var weekdaysShort = moment().localeData().weekdaysShort();
6887 var weekdaysMin = moment().localeData().weekdaysMin();
6888 var shift = moment().localeData()._week.dow;
6889 assert.deepEqual(
6890 moment().localeData().weekdays(true),
6891 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
6892 'weekdays should localeSort');
6893 assert.deepEqual(
6894 moment().localeData().weekdaysShort(true),
6895 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
6896 'weekdaysShort should localeSort');
6897 assert.deepEqual(
6898 moment().localeData().weekdaysMin(true),
6899 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
6900 'weekdaysMin should localeSort');
6901 });
db71a655 6902 }
d6651c21 6903
db71a655 6904 /*global QUnit:false*/
73f3c911 6905
db71a655
KM
6906 function localeModule (name, lifecycle) {
6907 QUnit.module('locale:' + name, {
c58511b9 6908 beforeEach : function () {
db71a655
KM
6909 moment.locale(name);
6910 moment.createFromInputFallback = function (config) {
6911 throw new Error('input not handled by moment: ' + config._i);
6912 };
6913 setupDeprecationHandler(test, moment, 'locale');
6914 if (lifecycle && lifecycle.setup) {
6915 lifecycle.setup();
6916 }
6917 },
c58511b9 6918 afterEach : function () {
db71a655
KM
6919 moment.locale('en');
6920 teardownDeprecationHandler(test, moment, 'locale');
6921 if (lifecycle && lifecycle.teardown) {
6922 lifecycle.teardown();
6923 }
d6651c21 6924 }
73f3c911 6925 });
db71a655
KM
6926 defineCommonLocaleTests(name, -1, -1);
6927 }
6928
6929 localeModule('bo');
6930
6931 test('parse', function (assert) {
6932 var tests = 'ཟླ་བ་དང་པོ ཟླ་བ་དང་པོ._ཟླ་བ་གཉིས་པ ཟླ་བ་གཉིས་པ_ཟླ་བ་གསུམ་པ ཟླ་བ་གསུམ་པ_ཟླ་བ་བཞི་པ ཟླ་བ་བཞི་པ_ཟླ་བ་ལྔ་པ ཟླ་བ་ལྔ་པ_ཟླ་བ་དྲུག་པ ཟླ་བ་དྲུག་པ_ཟླ་བ་བདུན་པ ཟླ་བ་བདུན་པ_ཟླ་བ་བརྒྱད་པ ཟླ་བ་བརྒྱད་པ_ཟླ་བ་དགུ་པ ཟླ་བ་དགུ་པ_ཟླ་བ་བཅུ་པ ཟླ་བ་བཅུ་པ_ཟླ་བ་བཅུ་གཅིག་པ ཟླ་བ་བཅུ་གཅིག་པ_ཟླ་བ་བཅུ་གཉིས་པ ཟླ་བ་བཅུ་གཉིས་པ'.split('_'), i;
6933 function equalTest(input, mmm, i) {
6934 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
6935 }
6936 for (i = 0; i < 12; i++) {
6937 tests[i] = tests[i].split(' ');
6938 equalTest(tests[i][0], 'MMM', i);
6939 equalTest(tests[i][1], 'MMM', i);
6940 equalTest(tests[i][0], 'MMMM', i);
6941 equalTest(tests[i][1], 'MMMM', i);
6942 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
6943 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
6944 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
6945 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
6946 }
6947 });
6948
6949 test('format', function (assert) {
6950 var a = [
6951 ['dddd, Do MMMM YYYY, a h:mm:ss ལ་', 'གཟའ་ཉི་མ་, ༡༤ ཟླ་བ་གཉིས་པ ༢༠༡༠, ཉིན་གུང ༣:༢༥:༥༠ ལ་'],
6952 ['ddd, a h ལ་', 'ཉི་མ་, ཉིན་གུང ༣ ལ་'],
6953 ['M Mo MM MMMM MMM', '༢ ༢ ༠༢ ཟླ་བ་གཉིས་པ ཟླ་བ་གཉིས་པ'],
6954 ['YYYY YY', '༢༠༡༠ ༡༠'],
6955 ['D Do DD', '༡༤ ༡༤ ༡༤'],
6956 ['d do dddd ddd dd', '༠ ༠ གཟའ་ཉི་མ་ ཉི་མ་ ཉི་མ་'],
6957 ['DDD DDDo DDDD', '༤༥ ༤༥ ༠༤༥'],
6958 ['w wo ww', '༨ ༨ ༠༨'],
6959 ['h hh', '༣ ༠༣'],
6960 ['H HH', '༡༥ ༡༥'],
6961 ['m mm', '༢༥ ༢༥'],
6962 ['s ss', '༥༠ ༥༠'],
6963 ['a A', 'ཉིན་གུང ཉིན་གུང'],
6964 ['LT', 'ཉིན་གུང ༣:༢༥'],
6965 ['LTS', 'ཉིན་གུང ༣:༢༥:༥༠'],
6966 ['L', '༡༤/༠༢/༢༠༡༠'],
6967 ['LL', '༡༤ ཟླ་བ་གཉིས་པ ༢༠༡༠'],
6968 ['LLL', '༡༤ ཟླ་བ་གཉིས་པ ༢༠༡༠, ཉིན་གུང ༣:༢༥'],
6969 ['LLLL', 'གཟའ་ཉི་མ་, ༡༤ ཟླ་བ་གཉིས་པ ༢༠༡༠, ཉིན་གུང ༣:༢༥'],
6970 ['l', '༡༤/༢/༢༠༡༠'],
6971 ['ll', '༡༤ ཟླ་བ་གཉིས་པ ༢༠༡༠'],
6972 ['lll', '༡༤ ཟླ་བ་གཉིས་པ ༢༠༡༠, ཉིན་གུང ༣:༢༥'],
6973 ['llll', 'ཉི་མ་, ༡༤ ཟླ་བ་གཉིས་པ ༢༠༡༠, ཉིན་གུང ༣:༢༥']
6974 ],
6975 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
6976 i;
6977 for (i = 0; i < a.length; i++) {
6978 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
6979 }
6980 });
6981
6982 test('format ordinal', function (assert) {
6983 assert.equal(moment([2011, 0, 1]).format('DDDo'), '༡', '༡');
6984 assert.equal(moment([2011, 0, 2]).format('DDDo'), '༢', '༢');
6985 assert.equal(moment([2011, 0, 3]).format('DDDo'), '༣', '༣');
6986 assert.equal(moment([2011, 0, 4]).format('DDDo'), '༤', '༤');
6987 assert.equal(moment([2011, 0, 5]).format('DDDo'), '༥', '༥');
6988 assert.equal(moment([2011, 0, 6]).format('DDDo'), '༦', '༦');
6989 assert.equal(moment([2011, 0, 7]).format('DDDo'), '༧', '༧');
6990 assert.equal(moment([2011, 0, 8]).format('DDDo'), '༨', '༨');
6991 assert.equal(moment([2011, 0, 9]).format('DDDo'), '༩', '༩');
6992 assert.equal(moment([2011, 0, 10]).format('DDDo'), '༡༠', '༡༠');
6993
6994 assert.equal(moment([2011, 0, 11]).format('DDDo'), '༡༡', '༡༡');
6995 assert.equal(moment([2011, 0, 12]).format('DDDo'), '༡༢', '༡༢');
6996 assert.equal(moment([2011, 0, 13]).format('DDDo'), '༡༣', '༡༣');
6997 assert.equal(moment([2011, 0, 14]).format('DDDo'), '༡༤', '༡༤');
6998 assert.equal(moment([2011, 0, 15]).format('DDDo'), '༡༥', '༡༥');
6999 assert.equal(moment([2011, 0, 16]).format('DDDo'), '༡༦', '༡༦');
7000 assert.equal(moment([2011, 0, 17]).format('DDDo'), '༡༧', '༡༧');
7001 assert.equal(moment([2011, 0, 18]).format('DDDo'), '༡༨', '༡༨');
7002 assert.equal(moment([2011, 0, 19]).format('DDDo'), '༡༩', '༡༩');
7003 assert.equal(moment([2011, 0, 20]).format('DDDo'), '༢༠', '༢༠');
7004
7005 assert.equal(moment([2011, 0, 21]).format('DDDo'), '༢༡', '༢༡');
7006 assert.equal(moment([2011, 0, 22]).format('DDDo'), '༢༢', '༢༢');
7007 assert.equal(moment([2011, 0, 23]).format('DDDo'), '༢༣', '༢༣');
7008 assert.equal(moment([2011, 0, 24]).format('DDDo'), '༢༤', '༢༤');
7009 assert.equal(moment([2011, 0, 25]).format('DDDo'), '༢༥', '༢༥');
7010 assert.equal(moment([2011, 0, 26]).format('DDDo'), '༢༦', '༢༦');
7011 assert.equal(moment([2011, 0, 27]).format('DDDo'), '༢༧', '༢༧');
7012 assert.equal(moment([2011, 0, 28]).format('DDDo'), '༢༨', '༢༨');
7013 assert.equal(moment([2011, 0, 29]).format('DDDo'), '༢༩', '༢༩');
7014 assert.equal(moment([2011, 0, 30]).format('DDDo'), '༣༠', '༣༠');
7015
7016 assert.equal(moment([2011, 0, 31]).format('DDDo'), '༣༡', '༣༡');
7017 });
7018
7019 test('format month', function (assert) {
7020 var expected = 'ཟླ་བ་དང་པོ ཟླ་བ་དང་པོ_ཟླ་བ་གཉིས་པ ཟླ་བ་གཉིས་པ_ཟླ་བ་གསུམ་པ ཟླ་བ་གསུམ་པ_ཟླ་བ་བཞི་པ ཟླ་བ་བཞི་པ_ཟླ་བ་ལྔ་པ ཟླ་བ་ལྔ་པ_ཟླ་བ་དྲུག་པ ཟླ་བ་དྲུག་པ_ཟླ་བ་བདུན་པ ཟླ་བ་བདུན་པ_ཟླ་བ་བརྒྱད་པ ཟླ་བ་བརྒྱད་པ_ཟླ་བ་དགུ་པ ཟླ་བ་དགུ་པ_ཟླ་བ་བཅུ་པ ཟླ་བ་བཅུ་པ_ཟླ་བ་བཅུ་གཅིག་པ ཟླ་བ་བཅུ་གཅིག་པ_ཟླ་བ་བཅུ་གཉིས་པ ཟླ་བ་བཅུ་གཉིས་པ'.split('_'), i;
7021 for (i = 0; i < expected.length; i++) {
7022 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
7023 }
7024 });
7025
7026 test('format week', function (assert) {
7027 var expected = 'གཟའ་ཉི་མ་ ཉི་མ་ ཉི་མ་_གཟའ་ཟླ་བ་ ཟླ་བ་ ཟླ་བ་_གཟའ་མིག་དམར་ མིག་དམར་ མིག་དམར་_གཟའ་ལྷག་པ་ ལྷག་པ་ ལྷག་པ་_གཟའ་ཕུར་བུ ཕུར་བུ ཕུར་བུ_གཟའ་པ་སངས་ པ་སངས་ པ་སངས་_གཟའ་སྤེན་པ་ སྤེན་པ་ སྤེན་པ་'.split('_'), i;
7028 for (i = 0; i < expected.length; i++) {
7029 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
7030 }
7031 });
7032
7033 test('from', function (assert) {
7034 var start = moment([2007, 1, 28]);
7035 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ལམ་སང', '44 seconds = a few seconds');
7036 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'སྐར་མ་གཅིག', '45 seconds = a minute');
7037 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'སྐར་མ་གཅིག', '89 seconds = a minute');
7038 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '༢ སྐར་མ', '90 seconds = 2 minutes');
7039 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '༤༤ སྐར་མ', '44 minutes = 44 minutes');
7040 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ཆུ་ཚོད་གཅིག', '45 minutes = an hour');
7041 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ཆུ་ཚོད་གཅིག', '89 minutes = an hour');
7042 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '༢ ཆུ་ཚོད', '90 minutes = 2 hours');
7043 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '༥ ཆུ་ཚོད', '5 hours = 5 hours');
7044 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '༢༡ ཆུ་ཚོད', '21 hours = 21 hours');
7045 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ཉིན་གཅིག', '22 hours = a day');
7046 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ཉིན་གཅིག', '35 hours = a day');
7047 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '༢ ཉིན་', '36 hours = 2 days');
7048 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ཉིན་གཅིག', '1 day = a day');
7049 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '༥ ཉིན་', '5 days = 5 days');
7050 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '༢༥ ཉིན་', '25 days = 25 days');
7051 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ཟླ་བ་གཅིག', '26 days = a month');
7052 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ཟླ་བ་གཅིག', '30 days = a month');
7053 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ཟླ་བ་གཅིག', '43 days = a month');
7054 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '༢ ཟླ་བ', '46 days = 2 months');
7055 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '༢ ཟླ་བ', '75 days = 2 months');
7056 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '༣ ཟླ་བ', '76 days = 3 months');
7057 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ཟླ་བ་གཅིག', '1 month = a month');
7058 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '༥ ཟླ་བ', '5 months = 5 months');
7059 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ལོ་གཅིག', '345 days = a year');
7060 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '༢ ལོ', '548 days = 2 years');
7061 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ལོ་གཅིག', '1 year = a year');
7062 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '༥ ལོ', '5 years = 5 years');
7063 });
7064
7065 test('suffix', function (assert) {
7066 assert.equal(moment(30000).from(0), 'ལམ་སང ལ་', 'prefix');
7067 assert.equal(moment(0).from(30000), 'ལམ་སང སྔན་ལ', 'suffix');
7068 });
7069
7070 test('now from now', function (assert) {
7071 assert.equal(moment().fromNow(), 'ལམ་སང སྔན་ལ', 'now from now should display as in the past');
7072 });
7073
7074 test('fromNow', function (assert) {
7075 assert.equal(moment().add({s: 30}).fromNow(), 'ལམ་སང ལ་', 'ལམ་སང ལ་');
7076 assert.equal(moment().add({d: 5}).fromNow(), '༥ ཉིན་ ལ་', '༥ ཉིན་ ལ་');
7077 });
7078
7079 test('calendar day', function (assert) {
7080 var a = moment().hours(12).minutes(0).seconds(0);
7081
7082 assert.equal(moment(a).calendar(), 'དི་རིང ཉིན་གུང ༡༢:༠༠', 'today at the same time');
7083 assert.equal(moment(a).add({m: 25}).calendar(), 'དི་རིང ཉིན་གུང ༡༢:༢༥', 'Now plus 25 min');
7084 assert.equal(moment(a).add({h: 3}).calendar(), 'དི་རིང ཉིན་གུང ༣:༠༠', 'Now plus 3 hours');
7085 assert.equal(moment(a).add({d: 1}).calendar(), 'སང་ཉིན ཉིན་གུང ༡༢:༠༠', 'tomorrow at the same time');
7086 assert.equal(moment(a).subtract({h: 1}).calendar(), 'དི་རིང ཉིན་གུང ༡༡:༠༠', 'Now minus 1 hour');
7087 assert.equal(moment(a).subtract({d: 1}).calendar(), 'ཁ་སང ཉིན་གུང ༡༢:༠༠', 'yesterday at the same time');
7088 });
7089
7090 test('calendar next week', function (assert) {
7091 var i, m;
7092 for (i = 2; i < 7; i++) {
7093 m = moment().add({d: i});
7094 assert.equal(m.calendar(), m.format('[བདུན་ཕྲག་རྗེས་མ][,] LT'), 'Today + ' + i + ' days current time');
7095 m.hours(0).minutes(0).seconds(0).milliseconds(0);
7096 assert.equal(m.calendar(), m.format('[བདུན་ཕྲག་རྗེས་མ][,] LT'), 'Today + ' + i + ' days beginning of day');
7097 m.hours(23).minutes(59).seconds(59).milliseconds(999);
7098 assert.equal(m.calendar(), m.format('[བདུན་ཕྲག་རྗེས་མ][,] LT'), 'Today + ' + i + ' days end of day');
d6651c21 7099 }
db71a655 7100 });
73f3c911 7101
db71a655
KM
7102 test('calendar last week', function (assert) {
7103 var i, m;
7104
7105 for (i = 2; i < 7; i++) {
7106 m = moment().subtract({d: i});
7107 assert.equal(m.calendar(), m.format('[བདུན་ཕྲག་མཐའ་མ] dddd[,] LT'), 'Today - ' + i + ' days current time');
7108 m.hours(0).minutes(0).seconds(0).milliseconds(0);
7109 assert.equal(m.calendar(), m.format('[བདུན་ཕྲག་མཐའ་མ] dddd[,] LT'), 'Today - ' + i + ' days beginning of day');
7110 m.hours(23).minutes(59).seconds(59).milliseconds(999);
7111 assert.equal(m.calendar(), m.format('[བདུན་ཕྲག་མཐའ་མ] dddd[,] LT'), 'Today - ' + i + ' days end of day');
73f3c911 7112 }
db71a655 7113 });
b135bf1a 7114
db71a655
KM
7115 test('calendar all else', function (assert) {
7116 var weeksAgo = moment().subtract({w: 1}),
7117 weeksFromNow = moment().add({w: 1});
516f5f67 7118
db71a655
KM
7119 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
7120 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 7121
db71a655
KM
7122 weeksAgo = moment().subtract({w: 2});
7123 weeksFromNow = moment().add({w: 2});
c74a101d 7124
db71a655
KM
7125 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
7126 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
7127 });
7128
7129 test('meridiem', function (assert) {
7130 assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), 'མཚན་མོ', 'before dawn');
7131 assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), 'ཞོགས་ཀས', 'morning');
7132 assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), 'ཉིན་གུང', 'during day');
7133 assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), 'དགོང་དག', 'evening');
7134 assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), 'དགོང་དག', 'late evening');
7135 assert.equal(moment([2011, 2, 23, 21, 20]).format('a'), 'མཚན་མོ', 'night');
7136
7137 assert.equal(moment([2011, 2, 23, 2, 30]).format('A'), 'མཚན་མོ', 'before dawn');
7138 assert.equal(moment([2011, 2, 23, 9, 30]).format('A'), 'ཞོགས་ཀས', 'morning');
7139 assert.equal(moment([2011, 2, 23, 14, 30]).format('A'), 'ཉིན་གུང', ' during day');
7140 assert.equal(moment([2011, 2, 23, 17, 30]).format('A'), 'དགོང་དག', 'evening');
7141 assert.equal(moment([2011, 2, 23, 19, 30]).format('A'), 'དགོང་དག', 'late evening');
7142 assert.equal(moment([2011, 2, 23, 21, 20]).format('A'), 'མཚན་མོ', 'night');
7143 });
7144
7145 test('weeks year starting sunday formatted', function (assert) {
7146 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '༡ ༠༡ ༡', 'Jan 1 2012 should be week 1');
7147 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '༡ ༠༡ ༡', 'Jan 7 2012 should be week 1');
7148 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '༢ ༠༢ ༢', 'Jan 8 2012 should be week 2');
7149 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '༢ ༠༢ ༢', 'Jan 14 2012 should be week 2');
7150 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '༣ ༠༣ ༣', 'Jan 15 2012 should be week 3');
7151 });
73f3c911
IC
7152
7153})));
7154
7155
7156;(function (global, factory) {
7157 typeof exports === 'object' && typeof module !== 'undefined'
7158 && typeof require === 'function' ? factory(require('../../moment')) :
7159 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
7160 factory(global.moment)
7161}(this, (function (moment) { 'use strict';
7162
db71a655
KM
7163 function each(array, callback) {
7164 var i;
7165 for (i = 0; i < array.length; i++) {
7166 callback(array[i], i, array);
7167 }
516f5f67
IC
7168 }
7169
c58511b9
KM
7170 function setupDeprecationHandler(test, moment$$1, scope) {
7171 test._expectedDeprecations = null;
7172 test._observedDeprecations = null;
7173 test._oldSupress = moment$$1.suppressDeprecationWarnings;
7174 moment$$1.suppressDeprecationWarnings = true;
7175 test.expectedDeprecations = function () {
7176 test._expectedDeprecations = arguments;
7177 test._observedDeprecations = [];
7178 };
7179 moment$$1.deprecationHandler = function (name, msg) {
7180 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
7181 if (deprecationId === -1) {
7182 throw new Error('Unexpected deprecation thrown name=' +
7183 name + ' msg=' + msg);
7184 }
7185 test._observedDeprecations[deprecationId] = 1;
7186 };
7187 }
7188
7189 function teardownDeprecationHandler(test, moment$$1, scope) {
7190 moment$$1.suppressDeprecationWarnings = test._oldSupress;
7191
7192 if (test._expectedDeprecations != null) {
7193 var missedDeprecations = [];
7194 each(test._expectedDeprecations, function (deprecationPattern, id) {
7195 if (test._observedDeprecations[id] !== 1) {
7196 missedDeprecations.push(deprecationPattern);
7197 }
7198 });
7199 if (missedDeprecations.length !== 0) {
7200 throw new Error('Expected deprecation warnings did not happen: ' +
7201 missedDeprecations.join(' '));
7202 }
7203 }
7204 }
7205
7206 function matchedDeprecation(name, msg, deprecations) {
7207 if (deprecations == null) {
7208 return -1;
7209 }
7210 for (var i = 0; i < deprecations.length; ++i) {
7211 if (name != null && name === deprecations[i]) {
7212 return i;
7213 }
7214 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
7215 return i;
7216 }
7217 }
7218 return -1;
7219 }
7220
7221 /*global QUnit:false*/
7222
7223 var test = QUnit.test;
7224
db71a655
KM
7225 function objectKeys(obj) {
7226 if (Object.keys) {
7227 return Object.keys(obj);
7228 } else {
7229 // IE8
7230 var res = [], i;
7231 for (i in obj) {
7232 if (obj.hasOwnProperty(i)) {
7233 res.push(i);
7234 }
516f5f67 7235 }
db71a655 7236 return res;
73f3c911 7237 }
73f3c911 7238 }
516f5f67 7239
db71a655 7240 // Pick the first defined of two or three arguments.
73f3c911 7241
db71a655
KM
7242 function defineCommonLocaleTests(locale, options) {
7243 test('lenient day of month ordinal parsing', function (assert) {
7244 var i, ordinalStr, testMoment;
7245 for (i = 1; i <= 31; ++i) {
7246 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
7247 testMoment = moment(ordinalStr, 'YYYY MM Do');
7248 assert.equal(testMoment.year(), 2014,
7249 'lenient day of month ordinal parsing ' + i + ' year check');
7250 assert.equal(testMoment.month(), 0,
7251 'lenient day of month ordinal parsing ' + i + ' month check');
7252 assert.equal(testMoment.date(), i,
7253 'lenient day of month ordinal parsing ' + i + ' date check');
7254 }
7255 });
516f5f67 7256
db71a655
KM
7257 test('lenient day of month ordinal parsing of number', function (assert) {
7258 var i, testMoment;
7259 for (i = 1; i <= 31; ++i) {
7260 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
7261 assert.equal(testMoment.year(), 2014,
7262 'lenient day of month ordinal parsing of number ' + i + ' year check');
7263 assert.equal(testMoment.month(), 0,
7264 'lenient day of month ordinal parsing of number ' + i + ' month check');
7265 assert.equal(testMoment.date(), i,
7266 'lenient day of month ordinal parsing of number ' + i + ' date check');
7267 }
7268 });
516f5f67 7269
db71a655
KM
7270 test('strict day of month ordinal parsing', function (assert) {
7271 var i, ordinalStr, testMoment;
7272 for (i = 1; i <= 31; ++i) {
7273 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
7274 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
7275 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
7276 }
7277 });
516f5f67 7278
db71a655
KM
7279 test('meridiem invariant', function (assert) {
7280 var h, m, t1, t2;
7281 for (h = 0; h < 24; ++h) {
7282 for (m = 0; m < 60; m += 15) {
7283 t1 = moment.utc([2000, 0, 1, h, m]);
7284 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
7285 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
7286 'meridiem at ' + t1.format('HH:mm'));
7287 }
7288 }
7289 });
7290
7291 test('date format correctness', function (assert) {
7292 var data, tokens;
7293 data = moment.localeData()._longDateFormat;
7294 tokens = objectKeys(data);
7295 each(tokens, function (srchToken) {
7296 // Check each format string to make sure it does not contain any
7297 // tokens that need to be expanded.
7298 each(tokens, function (baseToken) {
7299 // strip escaped sequences
7300 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
7301 assert.equal(false, !!~format.indexOf(srchToken),
7302 'contains ' + srchToken + ' in ' + baseToken);
7303 });
73f3c911
IC
7304 });
7305 });
73f3c911 7306
db71a655
KM
7307 test('month parsing correctness', function (assert) {
7308 var i, m;
7309
7310 if (locale === 'tr') {
7311 // I can't fix it :(
c58511b9 7312 assert.expect(0);
db71a655
KM
7313 return;
7314 }
7315 function tester(format) {
7316 var r;
7317 r = moment(m.format(format), format);
7318 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
7319 if (locale !== 'ka') {
7320 r = moment(m.format(format).toLocaleUpperCase(), format);
7321 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
7322 }
db71a655
KM
7323 r = moment(m.format(format).toLocaleLowerCase(), format);
7324 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
7325
7326 r = moment(m.format(format), format, true);
7327 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
7328 if (locale !== 'ka') {
7329 r = moment(m.format(format).toLocaleUpperCase(), format, true);
7330 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
7331 }
db71a655
KM
7332 r = moment(m.format(format).toLocaleLowerCase(), format, true);
7333 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
7334 }
7335
7336 for (i = 0; i < 12; ++i) {
7337 m = moment([2015, i, 15, 18]);
7338 tester('MMM');
7339 tester('MMM.');
7340 tester('MMMM');
7341 tester('MMMM.');
7342 }
7343 });
516f5f67 7344
db71a655
KM
7345 test('weekday parsing correctness', function (assert) {
7346 var i, m;
7347
96d0d679 7348 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
7349 // tr, az: There is a lower-case letter (ı), that converted to
7350 // upper then lower changes to i
7351 // ro: there is the letter ț which behaves weird under IE8
7352 // mt: letter Ħ
96d0d679 7353 // ga: month with spaces
c58511b9 7354 assert.expect(0);
db71a655
KM
7355 return;
7356 }
7357 function tester(format) {
7358 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
7359 r = moment(m.format(format), format);
7360 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
7361 if (locale !== 'ka') {
7362 r = moment(m.format(format).toLocaleUpperCase(), format);
7363 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
7364 }
db71a655
KM
7365 r = moment(m.format(format).toLocaleLowerCase(), format);
7366 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
7367 r = moment(m.format(format), format, true);
7368 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
7369 if (locale !== 'ka') {
7370 r = moment(m.format(format).toLocaleUpperCase(), format, true);
7371 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
7372 }
db71a655
KM
7373 r = moment(m.format(format).toLocaleLowerCase(), format, true);
7374 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
7375 }
7376
7377 for (i = 0; i < 7; ++i) {
7378 m = moment.utc([2015, 0, i + 1, 18]);
7379 tester('dd');
7380 tester('ddd');
7381 tester('dddd');
7382 }
7383 });
516f5f67 7384
db71a655
KM
7385 test('valid localeData', function (assert) {
7386 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
7387 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
7388 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
7389 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
7390 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
7391 });
96d0d679
KM
7392
7393 test('localeData weekdays can localeSort', function (assert) {
7394 var weekdays = moment().localeData().weekdays();
7395 var weekdaysShort = moment().localeData().weekdaysShort();
7396 var weekdaysMin = moment().localeData().weekdaysMin();
7397 var shift = moment().localeData()._week.dow;
7398 assert.deepEqual(
7399 moment().localeData().weekdays(true),
7400 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
7401 'weekdays should localeSort');
7402 assert.deepEqual(
7403 moment().localeData().weekdaysShort(true),
7404 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
7405 'weekdaysShort should localeSort');
7406 assert.deepEqual(
7407 moment().localeData().weekdaysMin(true),
7408 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
7409 'weekdaysMin should localeSort');
7410 });
db71a655 7411 }
516f5f67 7412
db71a655
KM
7413 /*global QUnit:false*/
7414
db71a655
KM
7415 function localeModule (name, lifecycle) {
7416 QUnit.module('locale:' + name, {
c58511b9 7417 beforeEach : function () {
db71a655
KM
7418 moment.locale(name);
7419 moment.createFromInputFallback = function (config) {
7420 throw new Error('input not handled by moment: ' + config._i);
7421 };
7422 setupDeprecationHandler(test, moment, 'locale');
7423 if (lifecycle && lifecycle.setup) {
7424 lifecycle.setup();
7425 }
7426 },
c58511b9 7427 afterEach : function () {
db71a655
KM
7428 moment.locale('en');
7429 teardownDeprecationHandler(test, moment, 'locale');
7430 if (lifecycle && lifecycle.teardown) {
7431 lifecycle.teardown();
7432 }
b135bf1a 7433 }
73f3c911 7434 });
db71a655
KM
7435 defineCommonLocaleTests(name, -1, -1);
7436 }
7437
7438 localeModule('br');
7439
7440 test('parse', function (assert) {
7441 var tests = 'Genver Gen_C\'hwevrer C\'hwe_Meurzh Meu_Ebrel Ebr_Mae Mae_Mezheven Eve_Gouere Gou_Eost Eos_Gwengolo Gwe_Here Her_Du Du_Kerzu Ker'.split('_'), i;
7442 function equalTest(input, mmm, i) {
7443 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
7444 }
7445 for (i = 0; i < 12; i++) {
7446 tests[i] = tests[i].split(' ');
7447 equalTest(tests[i][0], 'MMM', i);
7448 equalTest(tests[i][1], 'MMM', i);
7449 equalTest(tests[i][0], 'MMMM', i);
7450 equalTest(tests[i][1], 'MMMM', i);
7451 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
7452 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
7453 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
7454 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
7455 }
7456 });
7457
7458 test('format', function (assert) {
7459 moment.locale('br');
7460 var a = [
7461 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Sul, C\'hwevrer 14vet 2010, 3:25:50 pm'],
7462 ['ddd, h A', 'Sul, 3 PM'],
7463 ['M Mo MM MMMM MMM', '2 2vet 02 C\'hwevrer C\'hwe'],
7464 ['YYYY YY', '2010 10'],
7465 ['D Do DD', '14 14vet 14'],
7466 ['d do dddd ddd dd', '0 0vet Sul Sul Su'],
7467 ['DDD DDDo DDDD', '45 45vet 045'],
7468 ['w wo ww', '6 6vet 06'],
7469 ['h hh', '3 03'],
7470 ['H HH', '15 15'],
7471 ['m mm', '25 25'],
7472 ['s ss', '50 50'],
7473 ['DDDo [devezh] [ar] [vloaz]', '45vet devezh ar vloaz'],
7474 ['L', '14/02/2010'],
7475 ['LL', '14 a viz C\'hwevrer 2010'],
7476 ['LLL', '14 a viz C\'hwevrer 2010 3e25 PM'],
7477 ['LLLL', 'Sul, 14 a viz C\'hwevrer 2010 3e25 PM']
7478 ],
7479 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
7480 i;
7481 for (i = 0; i < a.length; i++) {
7482 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
7483 }
7484 });
7485
7486 test('format ordinal', function (assert) {
7487 moment.locale('br');
7488 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1añ', '1añ');
7489 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2vet', '2vet');
7490 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3vet', '3vet');
7491 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4vet', '4vet');
7492 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5vet', '5vet');
7493 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6vet', '6vet');
7494 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7vet', '7vet');
7495 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8vet', '8vet');
7496 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9vet', '9vet');
7497 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10vet', '10vet');
7498
7499 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11vet', '11vet');
7500 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12vet', '12vet');
7501 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13vet', '13vet');
7502 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14vet', '14vet');
7503 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15vet', '15vet');
7504 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16vet', '16vet');
7505 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17vet', '17vet');
7506 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18vet', '18vet');
7507 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19vet', '19vet');
7508 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20vet', '20vet');
7509
7510 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21vet', '21vet');
7511 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22vet', '22vet');
7512 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23vet', '23vet');
7513 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24vet', '24vet');
7514 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25vet', '25vet');
7515 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26vet', '26vet');
7516 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27vet', '27vet');
7517 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28vet', '28vet');
7518 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29vet', '29vet');
7519 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30vet', '30vet');
7520
7521 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31vet', '31vet');
7522 });
7523
7524 test('format month', function (assert) {
7525 moment.locale('br');
7526 var expected = 'Genver Gen_C\'hwevrer C\'hwe_Meurzh Meu_Ebrel Ebr_Mae Mae_Mezheven Eve_Gouere Gou_Eost Eos_Gwengolo Gwe_Here Her_Du Du_Kerzu Ker'.split('_'), i;
7527 for (i = 0; i < expected.length; i++) {
7528 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
7529 }
7530 });
7531
7532 test('format week', function (assert) {
7533 moment.locale('br');
7534 var expected = 'Sul Sul Su_Lun Lun Lu_Meurzh Meu Me_Merc\'her Mer Mer_Yaou Yao Ya_Gwener Gwe Gw_Sadorn Sad Sa'.split('_'), i;
7535 for (i = 0; i < expected.length; i++) {
7536 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
7537 }
7538 });
7539
7540 test('from', function (assert) {
7541 moment.locale('br');
7542 var start = moment([2007, 1, 28]);
7543 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'un nebeud segondennoù', '44 seconds = a few seconds');
7544 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ur vunutenn', '45 seconds = a minute');
7545 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ur vunutenn', '89 seconds = a minute');
7546 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 vunutenn', '90 seconds = 2 minutes');
7547 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 munutenn', '44 minutes = 44 minutes');
7548 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'un eur', '45 minutes = an hour');
7549 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'un eur', '89 minutes = an hour');
7550 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 eur', '90 minutes = 2 hours');
7551 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 eur', '5 hours = 5 hours');
7552 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 eur', '21 hours = 21 hours');
7553 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un devezh', '22 hours = a day');
7554 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un devezh', '35 hours = a day');
7555 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 zevezh', '36 hours = 2 days');
7556 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un devezh', '1 day = a day');
7557 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 devezh', '5 days = 5 days');
7558 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 devezh', '25 days = 25 days');
7559 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ur miz', '26 days = a month');
7560 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ur miz', '30 days = a month');
7561 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ur miz', '43 days = a month');
7562 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 viz', '46 days = 2 months');
7563 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 viz', '75 days = 2 months');
7564 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 miz', '76 days = 3 months');
7565 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ur miz', '1 month = a month');
7566 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 miz', '5 months = 5 months');
7567 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ur bloaz', '345 days = a year');
7568 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 vloaz', '548 days = 2 years');
7569 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ur bloaz', '1 year = a year');
7570 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 bloaz', '5 years = 5 years');
7571 });
7572
7573 test('suffix', function (assert) {
7574 moment.locale('br');
7575 assert.equal(moment(30000).from(0), 'a-benn un nebeud segondennoù', 'prefix');
7576 assert.equal(moment(0).from(30000), 'un nebeud segondennoù \'zo', 'suffix');
7577 });
7578
7579 test('now from now', function (assert) {
7580 moment.locale('br');
7581 assert.equal(moment().fromNow(), 'un nebeud segondennoù \'zo', 'now from now should display as in the past');
7582 });
7583
7584 test('fromNow', function (assert) {
7585 moment.locale('br');
7586 assert.equal(moment().add({s: 30}).fromNow(), 'a-benn un nebeud segondennoù', 'in a few seconds');
7587 assert.equal(moment().add({d: 5}).fromNow(), 'a-benn 5 devezh', 'in 5 days');
7588 });
7589
7590 test('calendar day', function (assert) {
7591 moment.locale('br');
7592
7593 var a = moment().hours(12).minutes(0).seconds(0);
7594
7595 assert.equal(moment(a).calendar(), 'Hiziv da 12e00 PM', 'today at the same time');
7596 assert.equal(moment(a).add({m: 25}).calendar(), 'Hiziv da 12e25 PM', 'Now plus 25 min');
7597 assert.equal(moment(a).add({h: 1}).calendar(), 'Hiziv da 1e00 PM', 'Now plus 1 hour');
7598 assert.equal(moment(a).add({d: 1}).calendar(), 'Warc\'hoazh da 12e00 PM', 'tomorrow at the same time');
7599 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Hiziv da 11e00 AM', 'Now minus 1 hour');
7600 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Dec\'h da 12e00 PM', 'yesterday at the same time');
7601 });
7602
7603 test('calendar next week', function (assert) {
7604 moment.locale('br');
b135bf1a 7605
db71a655
KM
7606 var i, m;
7607 for (i = 2; i < 7; i++) {
7608 m = moment().add({d: i});
7609 assert.equal(m.calendar(), m.format('dddd [da] LT'), 'Today + ' + i + ' days current time');
7610 m.hours(0).minutes(0).seconds(0).milliseconds(0);
7611 assert.equal(m.calendar(), m.format('dddd [da] LT'), 'Today + ' + i + ' days beginning of day');
7612 m.hours(23).minutes(59).seconds(59).milliseconds(999);
7613 assert.equal(m.calendar(), m.format('dddd [da] LT'), 'Today + ' + i + ' days end of day');
b135bf1a 7614 }
db71a655
KM
7615 });
7616
7617 test('calendar last week', function (assert) {
7618 moment.locale('br');
7619
7620 var i, m;
7621 for (i = 2; i < 7; i++) {
7622 m = moment().subtract({d: i});
7623 assert.equal(m.calendar(), m.format('dddd [paset da] LT'), 'Today - ' + i + ' days current time');
7624 m.hours(0).minutes(0).seconds(0).milliseconds(0);
7625 assert.equal(m.calendar(), m.format('dddd [paset da] LT'), 'Today - ' + i + ' days beginning of day');
7626 m.hours(23).minutes(59).seconds(59).milliseconds(999);
7627 assert.equal(m.calendar(), m.format('dddd [paset da] LT'), 'Today - ' + i + ' days end of day');
b135bf1a 7628 }
db71a655 7629 });
b135bf1a 7630
db71a655
KM
7631 test('calendar all else', function (assert) {
7632 moment.locale('br');
7633 var weeksAgo = moment().subtract({w: 1}),
7634 weeksFromNow = moment().add({w: 1});
b135bf1a 7635
db71a655
KM
7636 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
7637 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
b135bf1a 7638
db71a655
KM
7639 weeksAgo = moment().subtract({w: 2});
7640 weeksFromNow = moment().add({w: 2});
b135bf1a 7641
db71a655
KM
7642 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
7643 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
7644 });
7645
7646 test('special mutations for years', function (assert) {
7647 moment.locale('br');
7648 var start = moment([2007, 1, 28]);
7649 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ur bloaz', 'mutation 1 year');
7650 assert.equal(start.from(moment([2007, 1, 28]).add({y: 2}), true), '2 vloaz', 'mutation 2 years');
7651 assert.equal(start.from(moment([2007, 1, 28]).add({y: 3}), true), '3 bloaz', 'mutation 3 years');
7652 assert.equal(start.from(moment([2007, 1, 28]).add({y: 4}), true), '4 bloaz', 'mutation 4 years');
7653 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 bloaz', 'mutation 5 years');
7654 assert.equal(start.from(moment([2007, 1, 28]).add({y: 9}), true), '9 bloaz', 'mutation 9 years');
7655 assert.equal(start.from(moment([2007, 1, 28]).add({y: 10}), true), '10 vloaz', 'mutation 10 years');
7656 assert.equal(start.from(moment([2007, 1, 28]).add({y: 21}), true), '21 bloaz', 'mutation 21 years');
7657 assert.equal(start.from(moment([2007, 1, 28]).add({y: 22}), true), '22 vloaz', 'mutation 22 years');
7658 assert.equal(start.from(moment([2007, 1, 28]).add({y: 133}), true), '133 bloaz', 'mutation 133 years');
7659 assert.equal(start.from(moment([2007, 1, 28]).add({y: 148}), true), '148 vloaz', 'mutation 148 years');
7660 assert.equal(start.from(moment([2007, 1, 28]).add({y: 261}), true), '261 bloaz', 'mutation 261 years');
7661 });
73f3c911
IC
7662
7663})));
d6651c21 7664
73f3c911
IC
7665
7666;(function (global, factory) {
7667 typeof exports === 'object' && typeof module !== 'undefined'
7668 && typeof require === 'function' ? factory(require('../../moment')) :
7669 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
7670 factory(global.moment)
7671}(this, (function (moment) { 'use strict';
7672
db71a655
KM
7673 function each(array, callback) {
7674 var i;
7675 for (i = 0; i < array.length; i++) {
7676 callback(array[i], i, array);
7677 }
d6651c21
IC
7678 }
7679
c58511b9
KM
7680 function setupDeprecationHandler(test, moment$$1, scope) {
7681 test._expectedDeprecations = null;
7682 test._observedDeprecations = null;
7683 test._oldSupress = moment$$1.suppressDeprecationWarnings;
7684 moment$$1.suppressDeprecationWarnings = true;
7685 test.expectedDeprecations = function () {
7686 test._expectedDeprecations = arguments;
7687 test._observedDeprecations = [];
7688 };
7689 moment$$1.deprecationHandler = function (name, msg) {
7690 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
7691 if (deprecationId === -1) {
7692 throw new Error('Unexpected deprecation thrown name=' +
7693 name + ' msg=' + msg);
7694 }
7695 test._observedDeprecations[deprecationId] = 1;
7696 };
7697 }
7698
7699 function teardownDeprecationHandler(test, moment$$1, scope) {
7700 moment$$1.suppressDeprecationWarnings = test._oldSupress;
7701
7702 if (test._expectedDeprecations != null) {
7703 var missedDeprecations = [];
7704 each(test._expectedDeprecations, function (deprecationPattern, id) {
7705 if (test._observedDeprecations[id] !== 1) {
7706 missedDeprecations.push(deprecationPattern);
7707 }
7708 });
7709 if (missedDeprecations.length !== 0) {
7710 throw new Error('Expected deprecation warnings did not happen: ' +
7711 missedDeprecations.join(' '));
7712 }
7713 }
7714 }
7715
7716 function matchedDeprecation(name, msg, deprecations) {
7717 if (deprecations == null) {
7718 return -1;
7719 }
7720 for (var i = 0; i < deprecations.length; ++i) {
7721 if (name != null && name === deprecations[i]) {
7722 return i;
7723 }
7724 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
7725 return i;
7726 }
7727 }
7728 return -1;
7729 }
7730
7731 /*global QUnit:false*/
7732
7733 var test = QUnit.test;
7734
db71a655
KM
7735 function objectKeys(obj) {
7736 if (Object.keys) {
7737 return Object.keys(obj);
7738 } else {
7739 // IE8
7740 var res = [], i;
7741 for (i in obj) {
7742 if (obj.hasOwnProperty(i)) {
7743 res.push(i);
7744 }
d6651c21 7745 }
db71a655 7746 return res;
73f3c911 7747 }
d6651c21
IC
7748 }
7749
db71a655 7750 // Pick the first defined of two or three arguments.
d6651c21 7751
db71a655
KM
7752 function defineCommonLocaleTests(locale, options) {
7753 test('lenient day of month ordinal parsing', function (assert) {
7754 var i, ordinalStr, testMoment;
7755 for (i = 1; i <= 31; ++i) {
7756 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
7757 testMoment = moment(ordinalStr, 'YYYY MM Do');
7758 assert.equal(testMoment.year(), 2014,
7759 'lenient day of month ordinal parsing ' + i + ' year check');
7760 assert.equal(testMoment.month(), 0,
7761 'lenient day of month ordinal parsing ' + i + ' month check');
7762 assert.equal(testMoment.date(), i,
7763 'lenient day of month ordinal parsing ' + i + ' date check');
7764 }
7765 });
d6651c21 7766
db71a655
KM
7767 test('lenient day of month ordinal parsing of number', function (assert) {
7768 var i, testMoment;
7769 for (i = 1; i <= 31; ++i) {
7770 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
7771 assert.equal(testMoment.year(), 2014,
7772 'lenient day of month ordinal parsing of number ' + i + ' year check');
7773 assert.equal(testMoment.month(), 0,
7774 'lenient day of month ordinal parsing of number ' + i + ' month check');
7775 assert.equal(testMoment.date(), i,
7776 'lenient day of month ordinal parsing of number ' + i + ' date check');
7777 }
7778 });
73f3c911 7779
db71a655
KM
7780 test('strict day of month ordinal parsing', function (assert) {
7781 var i, ordinalStr, testMoment;
7782 for (i = 1; i <= 31; ++i) {
7783 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
7784 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
7785 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
7786 }
7787 });
b135bf1a 7788
db71a655
KM
7789 test('meridiem invariant', function (assert) {
7790 var h, m, t1, t2;
7791 for (h = 0; h < 24; ++h) {
7792 for (m = 0; m < 60; m += 15) {
7793 t1 = moment.utc([2000, 0, 1, h, m]);
7794 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
7795 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
7796 'meridiem at ' + t1.format('HH:mm'));
7797 }
7798 }
7799 });
7800
7801 test('date format correctness', function (assert) {
7802 var data, tokens;
7803 data = moment.localeData()._longDateFormat;
7804 tokens = objectKeys(data);
7805 each(tokens, function (srchToken) {
7806 // Check each format string to make sure it does not contain any
7807 // tokens that need to be expanded.
7808 each(tokens, function (baseToken) {
7809 // strip escaped sequences
7810 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
7811 assert.equal(false, !!~format.indexOf(srchToken),
7812 'contains ' + srchToken + ' in ' + baseToken);
7813 });
73f3c911
IC
7814 });
7815 });
516f5f67 7816
db71a655
KM
7817 test('month parsing correctness', function (assert) {
7818 var i, m;
7819
7820 if (locale === 'tr') {
7821 // I can't fix it :(
c58511b9 7822 assert.expect(0);
db71a655
KM
7823 return;
7824 }
7825 function tester(format) {
7826 var r;
7827 r = moment(m.format(format), format);
7828 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
7829 if (locale !== 'ka') {
7830 r = moment(m.format(format).toLocaleUpperCase(), format);
7831 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
7832 }
db71a655
KM
7833 r = moment(m.format(format).toLocaleLowerCase(), format);
7834 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
7835
7836 r = moment(m.format(format), format, true);
7837 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
7838 if (locale !== 'ka') {
7839 r = moment(m.format(format).toLocaleUpperCase(), format, true);
7840 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
7841 }
db71a655
KM
7842 r = moment(m.format(format).toLocaleLowerCase(), format, true);
7843 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
7844 }
7845
7846 for (i = 0; i < 12; ++i) {
7847 m = moment([2015, i, 15, 18]);
7848 tester('MMM');
7849 tester('MMM.');
7850 tester('MMMM');
7851 tester('MMMM.');
7852 }
7853 });
516f5f67 7854
db71a655
KM
7855 test('weekday parsing correctness', function (assert) {
7856 var i, m;
7857
96d0d679 7858 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
7859 // tr, az: There is a lower-case letter (ı), that converted to
7860 // upper then lower changes to i
7861 // ro: there is the letter ț which behaves weird under IE8
7862 // mt: letter Ħ
96d0d679 7863 // ga: month with spaces
c58511b9 7864 assert.expect(0);
db71a655
KM
7865 return;
7866 }
7867 function tester(format) {
7868 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
7869 r = moment(m.format(format), format);
7870 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
7871 if (locale !== 'ka') {
7872 r = moment(m.format(format).toLocaleUpperCase(), format);
7873 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
7874 }
db71a655
KM
7875 r = moment(m.format(format).toLocaleLowerCase(), format);
7876 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
7877 r = moment(m.format(format), format, true);
7878 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
7879 if (locale !== 'ka') {
7880 r = moment(m.format(format).toLocaleUpperCase(), format, true);
7881 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
7882 }
db71a655
KM
7883 r = moment(m.format(format).toLocaleLowerCase(), format, true);
7884 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
7885 }
7886
7887 for (i = 0; i < 7; ++i) {
7888 m = moment.utc([2015, 0, i + 1, 18]);
7889 tester('dd');
7890 tester('ddd');
7891 tester('dddd');
7892 }
7893 });
c74a101d 7894
db71a655
KM
7895 test('valid localeData', function (assert) {
7896 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
7897 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
7898 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
7899 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
7900 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
7901 });
96d0d679
KM
7902
7903 test('localeData weekdays can localeSort', function (assert) {
7904 var weekdays = moment().localeData().weekdays();
7905 var weekdaysShort = moment().localeData().weekdaysShort();
7906 var weekdaysMin = moment().localeData().weekdaysMin();
7907 var shift = moment().localeData()._week.dow;
7908 assert.deepEqual(
7909 moment().localeData().weekdays(true),
7910 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
7911 'weekdays should localeSort');
7912 assert.deepEqual(
7913 moment().localeData().weekdaysShort(true),
7914 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
7915 'weekdaysShort should localeSort');
7916 assert.deepEqual(
7917 moment().localeData().weekdaysMin(true),
7918 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
7919 'weekdaysMin should localeSort');
7920 });
db71a655 7921 }
516f5f67 7922
db71a655 7923 /*global QUnit:false*/
516f5f67 7924
db71a655
KM
7925 function localeModule (name, lifecycle) {
7926 QUnit.module('locale:' + name, {
c58511b9 7927 beforeEach : function () {
db71a655
KM
7928 moment.locale(name);
7929 moment.createFromInputFallback = function (config) {
7930 throw new Error('input not handled by moment: ' + config._i);
7931 };
7932 setupDeprecationHandler(test, moment, 'locale');
7933 if (lifecycle && lifecycle.setup) {
7934 lifecycle.setup();
7935 }
7936 },
c58511b9 7937 afterEach : function () {
db71a655
KM
7938 moment.locale('en');
7939 teardownDeprecationHandler(test, moment, 'locale');
7940 if (lifecycle && lifecycle.teardown) {
7941 lifecycle.teardown();
7942 }
516f5f67 7943 }
73f3c911 7944 });
db71a655
KM
7945 defineCommonLocaleTests(name, -1, -1);
7946 }
7947
7948 localeModule('bs');
7949
7950 test('parse', function (assert) {
7951 var tests = 'januar jan._februar feb._mart mar._april apr._maj maj._juni jun._juli jul._august aug._septembar sep._oktobar okt._novembar nov._decembar dec.'.split('_'), i;
7952 function equalTest(input, mmm, i) {
7953 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1) + ' inp ' + mmm);
7954 }
7955 for (i = 0; i < 12; i++) {
7956 tests[i] = tests[i].split(' ');
7957 equalTest(tests[i][0], 'MMM', i);
7958 equalTest(tests[i][1], 'MMM', i);
7959 equalTest(tests[i][0], 'MMMM', i);
7960 equalTest(tests[i][1], 'MMMM', i);
7961 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
7962 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
7963 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
7964 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
7965 }
7966 });
7967
7968 test('format', function (assert) {
7969 var a = [
7970 ['dddd, Do MMMM YYYY, h:mm:ss a', 'nedjelja, 14. februar 2010, 3:25:50 pm'],
7971 ['ddd, hA', 'ned., 3PM'],
7972 ['M Mo MM MMMM MMM', '2 2. 02 februar feb.'],
7973 ['YYYY YY', '2010 10'],
7974 ['D Do DD', '14 14. 14'],
7975 ['d do dddd ddd dd', '0 0. nedjelja ned. ne'],
7976 ['DDD DDDo DDDD', '45 45. 045'],
7977 ['w wo ww', '7 7. 07'],
7978 ['h hh', '3 03'],
7979 ['H HH', '15 15'],
7980 ['m mm', '25 25'],
7981 ['s ss', '50 50'],
7982 ['a A', 'pm PM'],
7983 ['[the] DDDo [day of the year]', 'the 45. day of the year'],
7984 ['LTS', '15:25:50'],
7985 ['L', '14.02.2010'],
7986 ['LL', '14. februar 2010'],
7987 ['LLL', '14. februar 2010 15:25'],
7988 ['LLLL', 'nedjelja, 14. februar 2010 15:25'],
7989 ['l', '14.2.2010'],
7990 ['ll', '14. feb. 2010'],
7991 ['lll', '14. feb. 2010 15:25'],
7992 ['llll', 'ned., 14. feb. 2010 15:25']
7993 ],
7994 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
7995 i;
7996 for (i = 0; i < a.length; i++) {
7997 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
7998 }
7999 });
8000
8001 test('format ordinal', function (assert) {
8002 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
8003 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
8004 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
8005 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
8006 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
8007 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
8008 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
8009 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
8010 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
8011 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
8012
8013 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
8014 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
8015 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
8016 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
8017 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
8018 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
8019 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
8020 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
8021 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
8022 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
8023
8024 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
8025 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
8026 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
8027 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
8028 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
8029 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
8030 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
8031 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
8032 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
8033 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
8034
8035 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
8036 });
8037
8038 test('format month', function (assert) {
8039 var expected = 'januar jan._februar feb._mart mar._april apr._maj maj._juni jun._juli jul._august aug._septembar sep._oktobar okt._novembar nov._decembar dec.'.split('_'), i;
8040 for (i = 0; i < expected.length; i++) {
8041 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
8042 }
8043 });
8044
8045 test('format week', function (assert) {
8046 var expected = 'nedjelja ned. ne_ponedjeljak pon. po_utorak uto. ut_srijeda sri. sr_četvrtak čet. če_petak pet. pe_subota sub. su'.split('_'), i;
8047 for (i = 0; i < expected.length; i++) {
8048 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
8049 }
8050 });
8051
8052 test('from', function (assert) {
8053 var start = moment([2007, 1, 28]);
8054 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'par sekundi', '44 seconds = a few seconds');
8055 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'jedna minuta', '45 seconds = a minute');
8056 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'jedna minuta', '89 seconds = a minute');
8057 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minute', '90 seconds = 2 minutes');
8058 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuta', '44 minutes = 44 minutes');
8059 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'jedan sat', '45 minutes = an hour');
8060 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'jedan sat', '89 minutes = an hour');
8061 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 sata', '90 minutes = 2 hours');
8062 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 sati', '5 hours = 5 hours');
8063 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 sati', '21 hours = 21 hours');
8064 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'dan', '22 hours = a day');
8065 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'dan', '35 hours = a day');
8066 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dana', '36 hours = 2 days');
8067 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'dan', '1 day = a day');
8068 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dana', '5 days = 5 days');
8069 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dana', '25 days = 25 days');
8070 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mjesec', '26 days = a month');
8071 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mjesec', '30 days = a month');
8072 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mjesec', '43 days = a month');
8073 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mjeseca', '46 days = 2 months');
8074 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mjeseca', '75 days = 2 months');
8075 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mjeseca', '76 days = 3 months');
8076 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mjesec', '1 month = a month');
8077 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mjeseci', '5 months = 5 months');
8078 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'godinu', '345 days = a year');
8079 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 godine', '548 days = 2 years');
8080 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'godinu', '1 year = a year');
8081 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 godina', '5 years = 5 years');
8082 });
8083
8084 test('suffix', function (assert) {
8085 assert.equal(moment(30000).from(0), 'za par sekundi', 'prefix');
8086 assert.equal(moment(0).from(30000), 'prije par sekundi', 'prefix');
8087 });
8088
8089 test('now from now', function (assert) {
8090 assert.equal(moment().fromNow(), 'prije par sekundi', 'now from now should display as in the past');
8091 });
8092
8093 test('fromNow', function (assert) {
8094 assert.equal(moment().add({s: 30}).fromNow(), 'za par sekundi', 'in a few seconds');
8095 assert.equal(moment().add({d: 5}).fromNow(), 'za 5 dana', 'in 5 days');
8096 });
8097
8098 test('calendar day', function (assert) {
8099 var a = moment().hours(12).minutes(0).seconds(0);
8100
8101 assert.equal(moment(a).calendar(), 'danas u 12:00', 'today at the same time');
8102 assert.equal(moment(a).add({m: 25}).calendar(), 'danas u 12:25', 'Now plus 25 min');
8103 assert.equal(moment(a).add({h: 1}).calendar(), 'danas u 13:00', 'Now plus 1 hour');
8104 assert.equal(moment(a).add({d: 1}).calendar(), 'sutra u 12:00', 'tomorrow at the same time');
8105 assert.equal(moment(a).subtract({h: 1}).calendar(), 'danas u 11:00', 'Now minus 1 hour');
8106 assert.equal(moment(a).subtract({d: 1}).calendar(), 'jučer u 12:00', 'yesterday at the same time');
8107 });
8108
8109 test('calendar next week', function (assert) {
8110 var i, m;
8111
8112 function makeFormat(d) {
8113 switch (d.day()) {
8114 case 0:
8115 return '[u] [nedjelju] [u] LT';
8116 case 3:
8117 return '[u] [srijedu] [u] LT';
8118 case 6:
8119 return '[u] [subotu] [u] LT';
8120 case 1:
8121 case 2:
8122 case 4:
8123 case 5:
8124 return '[u] dddd [u] LT';
8125 }
516f5f67
IC
8126 }
8127
db71a655
KM
8128 for (i = 2; i < 7; i++) {
8129 m = moment().add({d: i});
8130 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time');
8131 m.hours(0).minutes(0).seconds(0).milliseconds(0);
8132 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day');
8133 m.hours(23).minutes(59).seconds(59).milliseconds(999);
8134 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day');
516f5f67 8135 }
db71a655
KM
8136 });
8137
8138 test('calendar last week', function (assert) {
8139 var i, m;
8140
8141 function makeFormat(d) {
8142 switch (d.day()) {
8143 case 0:
8144 case 3:
8145 return '[prošlu] dddd [u] LT';
8146 case 6:
8147 return '[prošle] [subote] [u] LT';
8148 case 1:
8149 case 2:
8150 case 4:
8151 case 5:
8152 return '[prošli] dddd [u] LT';
8153 }
73f3c911 8154 }
516f5f67 8155
db71a655
KM
8156 for (i = 2; i < 7; i++) {
8157 m = moment().subtract({d: i});
8158 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time');
8159 m.hours(0).minutes(0).seconds(0).milliseconds(0);
8160 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day');
8161 m.hours(23).minutes(59).seconds(59).milliseconds(999);
8162 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day');
8163 }
8164 });
516f5f67 8165
db71a655
KM
8166 test('calendar all else', function (assert) {
8167 var weeksAgo = moment().subtract({w: 1}),
8168 weeksFromNow = moment().add({w: 1});
516f5f67 8169
db71a655
KM
8170 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
8171 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 8172
db71a655
KM
8173 weeksAgo = moment().subtract({w: 2});
8174 weeksFromNow = moment().add({w: 2});
8175
8176 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
8177 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
8178 });
8179
8180 test('weeks year starting sunday formatted', function (assert) {
8181 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', 'Dec 26 2011 should be week 1');
8182 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1.', 'Jan 1 2012 should be week 1');
8183 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2.', 'Jan 2 2012 should be week 2');
8184 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2.', 'Jan 8 2012 should be week 2');
8185 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3.', 'Jan 9 2012 should be week 3');
8186 });
73f3c911
IC
8187
8188})));
8189
516f5f67 8190
c74a101d
IC
8191;(function (global, factory) {
8192 typeof exports === 'object' && typeof module !== 'undefined'
8193 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
8194 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
8195 factory(global.moment)
73f3c911 8196}(this, (function (moment) { 'use strict';
516f5f67 8197
db71a655
KM
8198 function each(array, callback) {
8199 var i;
8200 for (i = 0; i < array.length; i++) {
8201 callback(array[i], i, array);
8202 }
b135bf1a
IC
8203 }
8204
db71a655
KM
8205 function setupDeprecationHandler(test, moment$$1, scope) {
8206 test._expectedDeprecations = null;
8207 test._observedDeprecations = null;
8208 test._oldSupress = moment$$1.suppressDeprecationWarnings;
8209 moment$$1.suppressDeprecationWarnings = true;
8210 test.expectedDeprecations = function () {
8211 test._expectedDeprecations = arguments;
8212 test._observedDeprecations = [];
8213 };
8214 moment$$1.deprecationHandler = function (name, msg) {
8215 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
8216 if (deprecationId === -1) {
8217 throw new Error('Unexpected deprecation thrown name=' +
8218 name + ' msg=' + msg);
8219 }
8220 test._observedDeprecations[deprecationId] = 1;
8221 };
8222 }
73f3c911 8223
db71a655
KM
8224 function teardownDeprecationHandler(test, moment$$1, scope) {
8225 moment$$1.suppressDeprecationWarnings = test._oldSupress;
d6651c21 8226
db71a655
KM
8227 if (test._expectedDeprecations != null) {
8228 var missedDeprecations = [];
8229 each(test._expectedDeprecations, function (deprecationPattern, id) {
8230 if (test._observedDeprecations[id] !== 1) {
8231 missedDeprecations.push(deprecationPattern);
8232 }
8233 });
8234 if (missedDeprecations.length !== 0) {
8235 throw new Error('Expected deprecation warnings did not happen: ' +
8236 missedDeprecations.join(' '));
8237 }
d6651c21 8238 }
db71a655 8239 }
b135bf1a 8240
db71a655
KM
8241 function matchedDeprecation(name, msg, deprecations) {
8242 if (deprecations == null) {
8243 return -1;
73f3c911 8244 }
db71a655
KM
8245 for (var i = 0; i < deprecations.length; ++i) {
8246 if (name != null && name === deprecations[i]) {
8247 return i;
8248 }
8249 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
8250 return i;
8251 }
8252 }
8253 return -1;
8254 }
516f5f67 8255
db71a655 8256 /*global QUnit:false*/
c74a101d 8257
db71a655
KM
8258 var test = QUnit.test;
8259
c58511b9
KM
8260 function objectKeys(obj) {
8261 if (Object.keys) {
8262 return Object.keys(obj);
8263 } else {
8264 // IE8
8265 var res = [], i;
8266 for (i in obj) {
8267 if (obj.hasOwnProperty(i)) {
8268 res.push(i);
8269 }
8270 }
8271 return res;
8272 }
8273 }
8274
8275 // Pick the first defined of two or three arguments.
8276
8277 function defineCommonLocaleTests(locale, options) {
8278 test('lenient day of month ordinal parsing', function (assert) {
8279 var i, ordinalStr, testMoment;
8280 for (i = 1; i <= 31; ++i) {
8281 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
8282 testMoment = moment(ordinalStr, 'YYYY MM Do');
8283 assert.equal(testMoment.year(), 2014,
8284 'lenient day of month ordinal parsing ' + i + ' year check');
8285 assert.equal(testMoment.month(), 0,
8286 'lenient day of month ordinal parsing ' + i + ' month check');
8287 assert.equal(testMoment.date(), i,
8288 'lenient day of month ordinal parsing ' + i + ' date check');
8289 }
8290 });
8291
8292 test('lenient day of month ordinal parsing of number', function (assert) {
8293 var i, testMoment;
8294 for (i = 1; i <= 31; ++i) {
8295 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
8296 assert.equal(testMoment.year(), 2014,
8297 'lenient day of month ordinal parsing of number ' + i + ' year check');
8298 assert.equal(testMoment.month(), 0,
8299 'lenient day of month ordinal parsing of number ' + i + ' month check');
8300 assert.equal(testMoment.date(), i,
8301 'lenient day of month ordinal parsing of number ' + i + ' date check');
8302 }
8303 });
8304
8305 test('strict day of month ordinal parsing', function (assert) {
8306 var i, ordinalStr, testMoment;
8307 for (i = 1; i <= 31; ++i) {
8308 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
8309 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
8310 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
8311 }
8312 });
8313
8314 test('meridiem invariant', function (assert) {
8315 var h, m, t1, t2;
8316 for (h = 0; h < 24; ++h) {
8317 for (m = 0; m < 60; m += 15) {
8318 t1 = moment.utc([2000, 0, 1, h, m]);
8319 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
8320 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
8321 'meridiem at ' + t1.format('HH:mm'));
8322 }
8323 }
8324 });
8325
8326 test('date format correctness', function (assert) {
8327 var data, tokens;
8328 data = moment.localeData()._longDateFormat;
8329 tokens = objectKeys(data);
8330 each(tokens, function (srchToken) {
8331 // Check each format string to make sure it does not contain any
8332 // tokens that need to be expanded.
8333 each(tokens, function (baseToken) {
8334 // strip escaped sequences
8335 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
8336 assert.equal(false, !!~format.indexOf(srchToken),
8337 'contains ' + srchToken + ' in ' + baseToken);
8338 });
8339 });
8340 });
8341
8342 test('month parsing correctness', function (assert) {
8343 var i, m;
8344
8345 if (locale === 'tr') {
8346 // I can't fix it :(
8347 assert.expect(0);
8348 return;
8349 }
8350 function tester(format) {
8351 var r;
8352 r = moment(m.format(format), format);
8353 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
8354 if (locale !== 'ka') {
8355 r = moment(m.format(format).toLocaleUpperCase(), format);
8356 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
8357 }
c58511b9
KM
8358 r = moment(m.format(format).toLocaleLowerCase(), format);
8359 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
8360
8361 r = moment(m.format(format), format, true);
8362 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
8363 if (locale !== 'ka') {
8364 r = moment(m.format(format).toLocaleUpperCase(), format, true);
8365 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
8366 }
c58511b9
KM
8367 r = moment(m.format(format).toLocaleLowerCase(), format, true);
8368 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
8369 }
8370
8371 for (i = 0; i < 12; ++i) {
8372 m = moment([2015, i, 15, 18]);
8373 tester('MMM');
8374 tester('MMM.');
8375 tester('MMMM');
8376 tester('MMMM.');
8377 }
8378 });
8379
8380 test('weekday parsing correctness', function (assert) {
8381 var i, m;
8382
96d0d679 8383 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
c58511b9
KM
8384 // tr, az: There is a lower-case letter (ı), that converted to
8385 // upper then lower changes to i
8386 // ro: there is the letter ț which behaves weird under IE8
8387 // mt: letter Ħ
96d0d679 8388 // ga: month with spaces
c58511b9
KM
8389 assert.expect(0);
8390 return;
8391 }
8392 function tester(format) {
8393 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
8394 r = moment(m.format(format), format);
8395 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
8396 if (locale !== 'ka') {
8397 r = moment(m.format(format).toLocaleUpperCase(), format);
8398 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
8399 }
c58511b9
KM
8400 r = moment(m.format(format).toLocaleLowerCase(), format);
8401 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
8402 r = moment(m.format(format), format, true);
8403 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
8404 if (locale !== 'ka') {
8405 r = moment(m.format(format).toLocaleUpperCase(), format, true);
8406 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
8407 }
c58511b9
KM
8408 r = moment(m.format(format).toLocaleLowerCase(), format, true);
8409 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
8410 }
8411
8412 for (i = 0; i < 7; ++i) {
8413 m = moment.utc([2015, 0, i + 1, 18]);
8414 tester('dd');
8415 tester('ddd');
8416 tester('dddd');
8417 }
8418 });
8419
8420 test('valid localeData', function (assert) {
8421 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
8422 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
8423 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
8424 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
8425 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
8426 });
96d0d679
KM
8427
8428 test('localeData weekdays can localeSort', function (assert) {
8429 var weekdays = moment().localeData().weekdays();
8430 var weekdaysShort = moment().localeData().weekdaysShort();
8431 var weekdaysMin = moment().localeData().weekdaysMin();
8432 var shift = moment().localeData()._week.dow;
8433 assert.deepEqual(
8434 moment().localeData().weekdays(true),
8435 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
8436 'weekdays should localeSort');
8437 assert.deepEqual(
8438 moment().localeData().weekdaysShort(true),
8439 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
8440 'weekdaysShort should localeSort');
8441 assert.deepEqual(
8442 moment().localeData().weekdaysMin(true),
8443 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
8444 'weekdaysMin should localeSort');
8445 });
c58511b9
KM
8446 }
8447
8448 /*global QUnit:false*/
db71a655
KM
8449
8450 function localeModule (name, lifecycle) {
8451 QUnit.module('locale:' + name, {
c58511b9 8452 beforeEach : function () {
db71a655
KM
8453 moment.locale(name);
8454 moment.createFromInputFallback = function (config) {
8455 throw new Error('input not handled by moment: ' + config._i);
8456 };
8457 setupDeprecationHandler(test, moment, 'locale');
8458 if (lifecycle && lifecycle.setup) {
8459 lifecycle.setup();
8460 }
8461 },
c58511b9 8462 afterEach : function () {
db71a655
KM
8463 moment.locale('en');
8464 teardownDeprecationHandler(test, moment, 'locale');
8465 if (lifecycle && lifecycle.teardown) {
8466 lifecycle.teardown();
8467 }
516f5f67
IC
8468 }
8469 });
db71a655
KM
8470 defineCommonLocaleTests(name, -1, -1);
8471 }
8472
8473 localeModule('ca');
8474
8475 test('parse', function (assert) {
8476 var tests = 'gener gen._febrer febr._març març_abril abr._maig maig_juny juny_juliol jul._agost ag._setembre set._octubre oct._novembre nov._desembre des.'.split('_'), i;
8477 function equalTest(input, mmm, i) {
8478 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
8479 }
8480 for (i = 0; i < 12; i++) {
8481 tests[i] = tests[i].split(' ');
8482 equalTest(tests[i][0], 'MMM', i);
8483 equalTest(tests[i][1], 'MMM', i);
8484 equalTest(tests[i][0], 'MMMM', i);
8485 equalTest(tests[i][1], 'MMMM', i);
8486 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
8487 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
8488 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
8489 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
8490 }
8491 });
8492
8493 test('format', function (assert) {
8494 var a = [
8495 ['dddd, Do MMMM YYYY, h:mm:ss a', 'diumenge, 14è de febrer 2010, 3:25:50 pm'],
8496 ['ddd, hA', 'dg., 3PM'],
8497 ['M Mo MM MMMM MMM', '2 2n 02 febrer febr.'],
8498 ['YYYY YY', '2010 10'],
8499 ['D Do DD', '14 14è 14'],
8500 ['d do dddd ddd dd', '0 0è diumenge dg. dg'],
8501 ['DDD DDDo DDDD', '45 45è 045'],
8502 ['w wo ww', '6 6a 06'],
8503 ['h hh', '3 03'],
8504 ['H HH', '15 15'],
8505 ['m mm', '25 25'],
8506 ['s ss', '50 50'],
8507 ['a A', 'pm PM'],
8508 ['[the] DDDo [day of the year]', 'the 45è day of the year'],
8509 ['LTS', '15:25:50'],
8510 ['L', '14/02/2010'],
8511 ['LL', '14 de febrer de 2010'],
8512 ['LLL', '14 de febrer de 2010 a les 15:25'],
8513 ['LLLL', 'diumenge 14 de febrer de 2010 a les 15:25'],
8514 ['l', '14/2/2010'],
8515 ['ll', '14 febr. 2010'],
8516 ['lll', '14 febr. 2010, 15:25'],
8517 ['llll', 'dg. 14 febr. 2010, 15:25']
8518 ],
8519 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
8520 i;
8521 for (i = 0; i < a.length; i++) {
8522 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
8523 }
8524 });
8525
8526 test('format ordinal', function (assert) {
8527 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1r', '1r');
8528 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2n', '2n');
8529 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3r', '3r');
8530 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4t', '4t');
8531 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5è', '5è');
8532 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6è', '6è');
8533 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7è', '7è');
8534 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8è', '8è');
8535 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9è', '9è');
8536 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10è', '10è');
8537
8538 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11è', '11è');
8539 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12è', '12è');
8540 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13è', '13è');
8541 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14è', '14è');
8542 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15è', '15è');
8543 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16è', '16è');
8544 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17è', '17è');
8545 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18è', '18è');
8546 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19è', '19è');
8547 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20è', '20è');
8548
8549 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21è', '21è');
8550 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22è', '22è');
8551 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23è', '23è');
8552 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24è', '24è');
8553 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25è', '25è');
8554 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26è', '26è');
8555 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27è', '27è');
8556 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28è', '28è');
8557 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29è', '29è');
8558 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30è', '30è');
8559
8560 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31è', '31è');
8561 });
8562
8563 test('format month', function (assert) {
8564 var expected = 'gener gen._febrer febr._març març_abril abr._maig maig_juny juny_juliol jul._agost ag._setembre set._octubre oct._novembre nov._desembre des.'.split('_'), i;
8565 for (i = 0; i < expected.length; i++) {
8566 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
8567 }
8568 });
8569
8570 test('format week', function (assert) {
8571 var expected = 'diumenge dg. dg_dilluns dl. dl_dimarts dt. dt_dimecres dc. dc_dijous dj. dj_divendres dv. dv_dissabte ds. ds'.split('_'), i;
8572 for (i = 0; i < expected.length; i++) {
8573 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
8574 }
8575 });
8576
8577 test('from', function (assert) {
8578 var start = moment([2007, 1, 28]);
8579 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'uns segons', '44 seconds = a few seconds');
8580 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'un minut', '45 seconds = a minute');
8581 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'un minut', '89 seconds = a minute');
8582 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuts', '90 seconds = 2 minutes');
8583 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuts', '44 minutes = 44 minutes');
8584 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'una hora', '45 minutes = an hour');
8585 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'una hora', '89 minutes = an hour');
8586 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hores', '90 minutes = 2 hours');
8587 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hores', '5 hours = 5 hours');
8588 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hores', '21 hours = 21 hours');
8589 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un dia', '22 hours = a day');
8590 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un dia', '35 hours = a day');
8591 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dies', '36 hours = 2 days');
8592 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un dia', '1 day = a day');
8593 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dies', '5 days = 5 days');
8594 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dies', '25 days = 25 days');
8595 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'un mes', '26 days = a month');
8596 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'un mes', '30 days = a month');
8597 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'un mes', '43 days = a month');
8598 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mesos', '46 days = 2 months');
8599 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mesos', '75 days = 2 months');
8600 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mesos', '76 days = 3 months');
8601 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'un mes', '1 month = a month');
8602 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mesos', '5 months = 5 months');
8603 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un any', '345 days = a year');
8604 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 anys', '548 days = 2 years');
8605 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un any', '1 year = a year');
8606 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 anys', '5 years = 5 years');
8607 });
8608
8609 test('suffix', function (assert) {
8610 assert.equal(moment(30000).from(0), 'd\'aquí uns segons', 'prefix');
8611 assert.equal(moment(0).from(30000), 'fa uns segons', 'suffix');
8612 });
8613
8614 test('now from now', function (assert) {
8615 assert.equal(moment().fromNow(), 'fa uns segons', 'now from now should display as in the past');
8616 });
8617
8618 test('fromNow', function (assert) {
8619 assert.equal(moment().add({s: 30}).fromNow(), 'd\'aquí uns segons', 'd\'aquí uns segons');
8620 assert.equal(moment().add({d: 5}).fromNow(), 'd\'aquí 5 dies', 'd\'aquí 5 dies');
8621 });
8622
8623 test('calendar day', function (assert) {
8624 var a = moment().hours(12).minutes(0).seconds(0);
8625
8626 assert.equal(moment(a).calendar(), 'avui a les 12:00', 'today at the same time');
8627 assert.equal(moment(a).add({m: 25}).calendar(), 'avui a les 12:25', 'Now plus 25 min');
8628 assert.equal(moment(a).add({h: 1}).calendar(), 'avui a les 13:00', 'Now plus 1 hour');
8629 assert.equal(moment(a).add({d: 1}).calendar(), 'demà a les 12:00', 'tomorrow at the same time');
8630 assert.equal(moment(a).add({d: 1, h : -1}).calendar(), 'demà a les 11:00', 'tomorrow minus 1 hour');
8631 assert.equal(moment(a).subtract({h: 1}).calendar(), 'avui a les 11:00', 'Now minus 1 hour');
8632 assert.equal(moment(a).subtract({d: 1}).calendar(), 'ahir a les 12:00', 'yesterday at the same time');
8633 });
8634
8635 test('calendar next week', function (assert) {
8636 var i, m;
8637 for (i = 2; i < 7; i++) {
8638 m = moment().add({d: i});
8639 assert.equal(m.calendar(), m.format('dddd [a ' + ((m.hours() !== 1) ? 'les' : 'la') + '] LT'), 'Today + ' + i + ' days current time');
8640 m.hours(0).minutes(0).seconds(0).milliseconds(0);
8641 assert.equal(m.calendar(), m.format('dddd [a ' + ((m.hours() !== 1) ? 'les' : 'la') + '] LT'), 'Today + ' + i + ' days beginning of day');
8642 m.hours(23).minutes(59).seconds(59).milliseconds(999);
8643 assert.equal(m.calendar(), m.format('dddd [a ' + ((m.hours() !== 1) ? 'les' : 'la') + '] LT'), 'Today + ' + i + ' days end of day');
73f3c911 8644 }
db71a655 8645 });
516f5f67 8646
db71a655
KM
8647 test('calendar last week', function (assert) {
8648 var i, m;
8649 for (i = 2; i < 7; i++) {
8650 m = moment().subtract({d: i});
8651 assert.equal(m.calendar(), m.format('[el] dddd [passat a ' + ((m.hours() !== 1) ? 'les' : 'la') + '] LT'), 'Today - ' + i + ' days current time');
8652 m.hours(0).minutes(0).seconds(0).milliseconds(0);
8653 assert.equal(m.calendar(), m.format('[el] dddd [passat a ' + ((m.hours() !== 1) ? 'les' : 'la') + '] LT'), 'Today - ' + i + ' days beginning of day');
8654 m.hours(23).minutes(59).seconds(59).milliseconds(999);
8655 assert.equal(m.calendar(), m.format('[el] dddd [passat a ' + ((m.hours() !== 1) ? 'les' : 'la') + '] LT'), 'Today - ' + i + ' days end of day');
516f5f67 8656 }
db71a655 8657 });
516f5f67 8658
db71a655
KM
8659 test('calendar all else', function (assert) {
8660 var weeksAgo = moment().subtract({w: 1}),
8661 weeksFromNow = moment().add({w: 1});
516f5f67 8662
db71a655
KM
8663 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
8664 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 8665
db71a655
KM
8666 weeksAgo = moment().subtract({w: 2});
8667 weeksFromNow = moment().add({w: 2});
516f5f67 8668
db71a655
KM
8669 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
8670 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
8671 });
8672
8673 test('weeks year starting sunday formatted', function (assert) {
8674 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52a', 'Jan 1 2012 should be week 52');
8675 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1a', 'Jan 2 2012 should be week 1');
8676 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1a', 'Jan 8 2012 should be week 1');
8677 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2a', 'Jan 9 2012 should be week 2');
8678 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2a', 'Jan 15 2012 should be week 2');
8679 });
8680
8681 test('day and month', function (assert) {
8682 assert.equal(moment([2012, 1, 15]).format('D MMMM'), '15 de febrer');
8683 assert.equal(moment([2012, 9, 15]).format('D MMMM'), '15 d\'octubre');
8684 assert.equal(moment([2012, 9, 15]).format('MMMM, D'), 'octubre, 15');
8685 });
f2af24d5 8686
73f3c911
IC
8687})));
8688
516f5f67 8689
c74a101d
IC
8690;(function (global, factory) {
8691 typeof exports === 'object' && typeof module !== 'undefined'
8692 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
8693 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
8694 factory(global.moment)
73f3c911 8695}(this, (function (moment) { 'use strict';
516f5f67 8696
db71a655
KM
8697 function each(array, callback) {
8698 var i;
8699 for (i = 0; i < array.length; i++) {
8700 callback(array[i], i, array);
8701 }
b135bf1a
IC
8702 }
8703
c58511b9
KM
8704 function setupDeprecationHandler(test, moment$$1, scope) {
8705 test._expectedDeprecations = null;
8706 test._observedDeprecations = null;
8707 test._oldSupress = moment$$1.suppressDeprecationWarnings;
8708 moment$$1.suppressDeprecationWarnings = true;
8709 test.expectedDeprecations = function () {
8710 test._expectedDeprecations = arguments;
8711 test._observedDeprecations = [];
8712 };
8713 moment$$1.deprecationHandler = function (name, msg) {
8714 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
8715 if (deprecationId === -1) {
8716 throw new Error('Unexpected deprecation thrown name=' +
8717 name + ' msg=' + msg);
8718 }
8719 test._observedDeprecations[deprecationId] = 1;
8720 };
8721 }
8722
8723 function teardownDeprecationHandler(test, moment$$1, scope) {
8724 moment$$1.suppressDeprecationWarnings = test._oldSupress;
8725
8726 if (test._expectedDeprecations != null) {
8727 var missedDeprecations = [];
8728 each(test._expectedDeprecations, function (deprecationPattern, id) {
8729 if (test._observedDeprecations[id] !== 1) {
8730 missedDeprecations.push(deprecationPattern);
8731 }
8732 });
8733 if (missedDeprecations.length !== 0) {
8734 throw new Error('Expected deprecation warnings did not happen: ' +
8735 missedDeprecations.join(' '));
8736 }
8737 }
8738 }
8739
8740 function matchedDeprecation(name, msg, deprecations) {
8741 if (deprecations == null) {
8742 return -1;
8743 }
8744 for (var i = 0; i < deprecations.length; ++i) {
8745 if (name != null && name === deprecations[i]) {
8746 return i;
8747 }
8748 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
8749 return i;
8750 }
8751 }
8752 return -1;
8753 }
8754
8755 /*global QUnit:false*/
8756
8757 var test = QUnit.test;
8758
db71a655
KM
8759 function objectKeys(obj) {
8760 if (Object.keys) {
8761 return Object.keys(obj);
8762 } else {
8763 // IE8
8764 var res = [], i;
8765 for (i in obj) {
8766 if (obj.hasOwnProperty(i)) {
8767 res.push(i);
8768 }
b135bf1a 8769 }
db71a655 8770 return res;
b135bf1a
IC
8771 }
8772 }
8773
db71a655 8774 // Pick the first defined of two or three arguments.
73f3c911 8775
db71a655
KM
8776 function defineCommonLocaleTests(locale, options) {
8777 test('lenient day of month ordinal parsing', function (assert) {
8778 var i, ordinalStr, testMoment;
8779 for (i = 1; i <= 31; ++i) {
8780 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
8781 testMoment = moment(ordinalStr, 'YYYY MM Do');
8782 assert.equal(testMoment.year(), 2014,
8783 'lenient day of month ordinal parsing ' + i + ' year check');
8784 assert.equal(testMoment.month(), 0,
8785 'lenient day of month ordinal parsing ' + i + ' month check');
8786 assert.equal(testMoment.date(), i,
8787 'lenient day of month ordinal parsing ' + i + ' date check');
8788 }
8789 });
b135bf1a 8790
db71a655
KM
8791 test('lenient day of month ordinal parsing of number', function (assert) {
8792 var i, testMoment;
8793 for (i = 1; i <= 31; ++i) {
8794 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
8795 assert.equal(testMoment.year(), 2014,
8796 'lenient day of month ordinal parsing of number ' + i + ' year check');
8797 assert.equal(testMoment.month(), 0,
8798 'lenient day of month ordinal parsing of number ' + i + ' month check');
8799 assert.equal(testMoment.date(), i,
8800 'lenient day of month ordinal parsing of number ' + i + ' date check');
8801 }
b135bf1a
IC
8802 });
8803
db71a655
KM
8804 test('strict day of month ordinal parsing', function (assert) {
8805 var i, ordinalStr, testMoment;
8806 for (i = 1; i <= 31; ++i) {
8807 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
8808 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
8809 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
8810 }
8811 });
b135bf1a 8812
db71a655
KM
8813 test('meridiem invariant', function (assert) {
8814 var h, m, t1, t2;
8815 for (h = 0; h < 24; ++h) {
8816 for (m = 0; m < 60; m += 15) {
8817 t1 = moment.utc([2000, 0, 1, h, m]);
8818 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
8819 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
8820 'meridiem at ' + t1.format('HH:mm'));
8821 }
8822 }
8823 });
d6651c21 8824
db71a655
KM
8825 test('date format correctness', function (assert) {
8826 var data, tokens;
8827 data = moment.localeData()._longDateFormat;
8828 tokens = objectKeys(data);
8829 each(tokens, function (srchToken) {
8830 // Check each format string to make sure it does not contain any
8831 // tokens that need to be expanded.
8832 each(tokens, function (baseToken) {
8833 // strip escaped sequences
8834 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
8835 assert.equal(false, !!~format.indexOf(srchToken),
8836 'contains ' + srchToken + ' in ' + baseToken);
8837 });
8838 });
8839 });
d6651c21 8840
db71a655
KM
8841 test('month parsing correctness', function (assert) {
8842 var i, m;
8843
8844 if (locale === 'tr') {
8845 // I can't fix it :(
c58511b9 8846 assert.expect(0);
db71a655
KM
8847 return;
8848 }
8849 function tester(format) {
8850 var r;
8851 r = moment(m.format(format), format);
8852 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
8853 if (locale !== 'ka') {
8854 r = moment(m.format(format).toLocaleUpperCase(), format);
8855 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
8856 }
db71a655
KM
8857 r = moment(m.format(format).toLocaleLowerCase(), format);
8858 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
8859
8860 r = moment(m.format(format), format, true);
8861 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
8862 if (locale !== 'ka') {
8863 r = moment(m.format(format).toLocaleUpperCase(), format, true);
8864 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
8865 }
db71a655
KM
8866 r = moment(m.format(format).toLocaleLowerCase(), format, true);
8867 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
8868 }
8869
8870 for (i = 0; i < 12; ++i) {
8871 m = moment([2015, i, 15, 18]);
8872 tester('MMM');
8873 tester('MMM.');
8874 tester('MMMM');
8875 tester('MMMM.');
8876 }
8877 });
d6651c21 8878
db71a655
KM
8879 test('weekday parsing correctness', function (assert) {
8880 var i, m;
8881
96d0d679 8882 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
8883 // tr, az: There is a lower-case letter (ı), that converted to
8884 // upper then lower changes to i
8885 // ro: there is the letter ț which behaves weird under IE8
8886 // mt: letter Ħ
96d0d679 8887 // ga: month with spaces
c58511b9 8888 assert.expect(0);
db71a655
KM
8889 return;
8890 }
8891 function tester(format) {
8892 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
8893 r = moment(m.format(format), format);
8894 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
8895 if (locale !== 'ka') {
8896 r = moment(m.format(format).toLocaleUpperCase(), format);
8897 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
8898 }
db71a655
KM
8899 r = moment(m.format(format).toLocaleLowerCase(), format);
8900 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
8901 r = moment(m.format(format), format, true);
8902 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
8903 if (locale !== 'ka') {
8904 r = moment(m.format(format).toLocaleUpperCase(), format, true);
8905 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
8906 }
db71a655
KM
8907 r = moment(m.format(format).toLocaleLowerCase(), format, true);
8908 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
8909 }
8910
8911 for (i = 0; i < 7; ++i) {
8912 m = moment.utc([2015, 0, i + 1, 18]);
8913 tester('dd');
8914 tester('ddd');
8915 tester('dddd');
8916 }
8917 });
d6651c21 8918
db71a655
KM
8919 test('valid localeData', function (assert) {
8920 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
8921 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
8922 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
8923 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
8924 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
8925 });
96d0d679
KM
8926
8927 test('localeData weekdays can localeSort', function (assert) {
8928 var weekdays = moment().localeData().weekdays();
8929 var weekdaysShort = moment().localeData().weekdaysShort();
8930 var weekdaysMin = moment().localeData().weekdaysMin();
8931 var shift = moment().localeData()._week.dow;
8932 assert.deepEqual(
8933 moment().localeData().weekdays(true),
8934 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
8935 'weekdays should localeSort');
8936 assert.deepEqual(
8937 moment().localeData().weekdaysShort(true),
8938 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
8939 'weekdaysShort should localeSort');
8940 assert.deepEqual(
8941 moment().localeData().weekdaysMin(true),
8942 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
8943 'weekdaysMin should localeSort');
8944 });
db71a655 8945 }
d6651c21 8946
db71a655 8947 /*global QUnit:false*/
516f5f67 8948
db71a655
KM
8949 function localeModule (name, lifecycle) {
8950 QUnit.module('locale:' + name, {
c58511b9 8951 beforeEach : function () {
db71a655
KM
8952 moment.locale(name);
8953 moment.createFromInputFallback = function (config) {
8954 throw new Error('input not handled by moment: ' + config._i);
8955 };
8956 setupDeprecationHandler(test, moment, 'locale');
8957 if (lifecycle && lifecycle.setup) {
8958 lifecycle.setup();
8959 }
8960 },
c58511b9 8961 afterEach : function () {
db71a655
KM
8962 moment.locale('en');
8963 teardownDeprecationHandler(test, moment, 'locale');
8964 if (lifecycle && lifecycle.teardown) {
8965 lifecycle.teardown();
8966 }
516f5f67 8967 }
db71a655
KM
8968 });
8969 defineCommonLocaleTests(name, -1, -1);
8970 }
8971
8972 localeModule('cs');
8973
8974 test('parse', function (assert) {
96d0d679 8975 var tests = 'leden led ledna_únor úno února_březen bře března_duben dub dubna_květen kvě května_červen čvn června_červenec čvc července_srpen srp srpna_září zář září_říjen říj října_listopad lis listopadu_prosinec pro prosince'.split('_'), i;
db71a655
KM
8976 function equalTest(input, mmm, monthIndex) {
8977 assert.equal(moment(input, mmm).month(), monthIndex, input + ' ' + mmm + ' should be month ' + (monthIndex + 1));
8978 }
8979 function equalTestStrict(input, mmm, monthIndex) {
8980 assert.equal(moment(input, mmm, true).month(), monthIndex, input + ' ' + mmm + ' should be strict month ' + (monthIndex + 1));
8981 }
8982 for (i = 0; i < 12; i++) {
8983 tests[i] = tests[i].split(' ');
8984 equalTest(tests[i][0], 'MMM', i);
8985 equalTest(tests[i][1], 'MMM', i);
96d0d679 8986 equalTest(tests[i][2], 'MMM', i);
db71a655
KM
8987 equalTest(tests[i][0], 'MMMM', i);
8988 equalTest(tests[i][1], 'MMMM', i);
96d0d679 8989 equalTest(tests[i][2], 'MMMM', i);
db71a655
KM
8990 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
8991 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
96d0d679 8992 equalTest(tests[i][2].toLocaleLowerCase(), 'MMMM', i);
db71a655
KM
8993 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
8994 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
96d0d679 8995 equalTest(tests[i][2].toLocaleUpperCase(), 'MMMM', i);
db71a655
KM
8996
8997 equalTestStrict(tests[i][1], 'MMM', i);
8998 equalTestStrict(tests[i][0], 'MMMM', i);
96d0d679 8999 equalTestStrict(tests[i][2], 'MMMM', i);
db71a655
KM
9000 equalTestStrict(tests[i][1].toLocaleLowerCase(), 'MMM', i);
9001 equalTestStrict(tests[i][1].toLocaleUpperCase(), 'MMM', i);
9002 equalTestStrict(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
9003 equalTestStrict(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
96d0d679
KM
9004 equalTestStrict(tests[i][2].toLocaleLowerCase(), 'MMMM', i);
9005 equalTestStrict(tests[i][2].toLocaleUpperCase(), 'MMMM', i);
db71a655
KM
9006 }
9007 });
9008
9009 test('format', function (assert) {
9010 var a = [
9011 ['dddd, MMMM Do YYYY, h:mm:ss', 'neděle, únor 14. 2010, 3:25:50'],
9012 ['ddd, h', 'ne, 3'],
9013 ['M Mo MM MMMM MMM', '2 2. 02 únor úno'],
9014 ['YYYY YY', '2010 10'],
9015 ['D Do DD', '14 14. 14'],
9016 ['d do dddd ddd dd', '0 0. neděle ne ne'],
9017 ['DDD DDDo DDDD', '45 45. 045'],
9018 ['w wo ww', '6 6. 06'],
9019 ['h hh', '3 03'],
9020 ['H HH', '15 15'],
9021 ['m mm', '25 25'],
9022 ['s ss', '50 50'],
9023 ['a A', 'pm PM'],
9024 ['DDDo [den v roce]', '45. den v roce'],
9025 ['LTS', '15:25:50'],
9026 ['L', '14.02.2010'],
9027 ['LL', '14. únor 2010'],
9028 ['LLL', '14. únor 2010 15:25'],
9029 ['LLLL', 'neděle 14. únor 2010 15:25'],
9030 ['l', '14. 2. 2010'],
9031 ['ll', '14. úno 2010'],
9032 ['lll', '14. úno 2010 15:25'],
9033 ['llll', 'ne 14. úno 2010 15:25']
9034 ],
9035 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
9036 i;
9037 for (i = 0; i < a.length; i++) {
9038 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
9039 }
9040 });
9041
9042 test('format ordinal', function (assert) {
9043 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
9044 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
9045 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
9046 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
9047 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
9048 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
9049 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
9050 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
9051 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
9052 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
9053
9054 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
9055 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
9056 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
9057 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
9058 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
9059 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
9060 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
9061 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
9062 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
9063 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
9064
9065 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
9066 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
9067 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
9068 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
9069 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
9070 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
9071 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
9072 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
9073 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
9074 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
9075
9076 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
9077 });
9078
9079 test('format month', function (assert) {
9080 var expected = 'leden led_únor úno_březen bře_duben dub_květen kvě_červen čvn_červenec čvc_srpen srp_září zář_říjen říj_listopad lis_prosinec pro'.split('_'), i;
9081 for (i = 0; i < expected.length; i++) {
9082 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
9083 }
9084 });
9085
9086 test('format week', function (assert) {
9087 var expected = 'neděle ne ne_pondělí po po_úterý út út_středa st st_čtvrtek čt čt_pátek pá pá_sobota so so'.split('_'), i;
9088 for (i = 0; i < expected.length; i++) {
9089 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
9090 }
9091 });
9092
9093 test('from', function (assert) {
9094 var start = moment([2007, 1, 28]);
9095 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'pár sekund', '44 seconds = a few seconds');
9096 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minuta', '45 seconds = a minute');
9097 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minuta', '89 seconds = a minute');
9098 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuty', '90 seconds = 2 minutes');
9099 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minut', '44 minutes = 44 minutes');
9100 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'hodina', '45 minutes = an hour');
9101 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'hodina', '89 minutes = an hour');
9102 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hodiny', '90 minutes = 2 hours');
9103 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hodin', '5 hours = 5 hours');
9104 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hodin', '21 hours = 21 hours');
9105 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'den', '22 hours = a day');
9106 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'den', '35 hours = a day');
9107 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dny', '36 hours = 2 days');
9108 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'den', '1 day = a day');
9109 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dní', '5 days = 5 days');
9110 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dní', '25 days = 25 days');
9111 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'měsíc', '26 days = a month');
9112 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'měsíc', '30 days = a month');
9113 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'měsíc', '43 days = a month');
9114 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 měsíce', '46 days = 2 months');
9115 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 měsíce', '75 days = 2 months');
9116 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 měsíce', '76 days = 3 months');
9117 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'měsíc', '1 month = a month');
9118 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 měsíců', '5 months = 5 months');
9119 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'rok', '345 days = a year');
9120 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 roky', '548 days = 2 years');
9121 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'rok', '1 year = a year');
9122 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 let', '5 years = 5 years');
9123 });
9124
9125 test('suffix', function (assert) {
9126 assert.equal(moment(30000).from(0), 'za pár sekund', 'prefix');
9127 assert.equal(moment(0).from(30000), 'před pár sekundami', 'suffix');
9128 });
9129
9130 test('now from now', function (assert) {
9131 assert.equal(moment().fromNow(), 'před pár sekundami', 'now from now should display as in the past');
9132 });
9133
9134 test('fromNow (future)', function (assert) {
9135 assert.equal(moment().add({s: 30}).fromNow(), 'za pár sekund', 'in a few seconds');
9136 assert.equal(moment().add({m: 1}).fromNow(), 'za minutu', 'in a minute');
9137 assert.equal(moment().add({m: 3}).fromNow(), 'za 3 minuty', 'in 3 minutes');
9138 assert.equal(moment().add({m: 10}).fromNow(), 'za 10 minut', 'in 10 minutes');
9139 assert.equal(moment().add({h: 1}).fromNow(), 'za hodinu', 'in an hour');
9140 assert.equal(moment().add({h: 3}).fromNow(), 'za 3 hodiny', 'in 3 hours');
9141 assert.equal(moment().add({h: 10}).fromNow(), 'za 10 hodin', 'in 10 hours');
9142 assert.equal(moment().add({d: 1}).fromNow(), 'za den', 'in a day');
9143 assert.equal(moment().add({d: 3}).fromNow(), 'za 3 dny', 'in 3 days');
9144 assert.equal(moment().add({d: 10}).fromNow(), 'za 10 dní', 'in 10 days');
9145 assert.equal(moment().add({M: 1}).fromNow(), 'za měsíc', 'in a month');
9146 assert.equal(moment().add({M: 3}).fromNow(), 'za 3 měsíce', 'in 3 months');
9147 assert.equal(moment().add({M: 10}).fromNow(), 'za 10 měsíců', 'in 10 months');
9148 assert.equal(moment().add({y: 1}).fromNow(), 'za rok', 'in a year');
9149 assert.equal(moment().add({y: 3}).fromNow(), 'za 3 roky', 'in 3 years');
9150 assert.equal(moment().add({y: 10}).fromNow(), 'za 10 let', 'in 10 years');
9151 });
9152
9153 test('fromNow (past)', function (assert) {
9154 assert.equal(moment().subtract({s: 30}).fromNow(), 'před pár sekundami', 'a few seconds ago');
9155 assert.equal(moment().subtract({m: 1}).fromNow(), 'před minutou', 'a minute ago');
9156 assert.equal(moment().subtract({m: 3}).fromNow(), 'před 3 minutami', '3 minutes ago');
9157 assert.equal(moment().subtract({m: 10}).fromNow(), 'před 10 minutami', '10 minutes ago');
9158 assert.equal(moment().subtract({h: 1}).fromNow(), 'před hodinou', 'an hour ago');
9159 assert.equal(moment().subtract({h: 3}).fromNow(), 'před 3 hodinami', '3 hours ago');
9160 assert.equal(moment().subtract({h: 10}).fromNow(), 'před 10 hodinami', '10 hours ago');
9161 assert.equal(moment().subtract({d: 1}).fromNow(), 'před dnem', 'a day ago');
9162 assert.equal(moment().subtract({d: 3}).fromNow(), 'před 3 dny', '3 days ago');
9163 assert.equal(moment().subtract({d: 10}).fromNow(), 'před 10 dny', '10 days ago');
9164 assert.equal(moment().subtract({M: 1}).fromNow(), 'před měsícem', 'a month ago');
9165 assert.equal(moment().subtract({M: 3}).fromNow(), 'před 3 měsíci', '3 months ago');
9166 assert.equal(moment().subtract({M: 10}).fromNow(), 'před 10 měsíci', '10 months ago');
9167 assert.equal(moment().subtract({y: 1}).fromNow(), 'před rokem', 'a year ago');
9168 assert.equal(moment().subtract({y: 3}).fromNow(), 'před 3 lety', '3 years ago');
9169 assert.equal(moment().subtract({y: 10}).fromNow(), 'před 10 lety', '10 years ago');
9170 });
9171
9172 test('calendar day', function (assert) {
9173 var a = moment().hours(12).minutes(0).seconds(0);
9174
9175 assert.equal(moment(a).calendar(), 'dnes v 12:00', 'today at the same time');
9176 assert.equal(moment(a).add({m: 25}).calendar(), 'dnes v 12:25', 'Now plus 25 min');
9177 assert.equal(moment(a).add({h: 1}).calendar(), 'dnes v 13:00', 'Now plus 1 hour');
9178 assert.equal(moment(a).add({d: 1}).calendar(), 'zítra v 12:00', 'tomorrow at the same time');
9179 assert.equal(moment(a).subtract({h: 1}).calendar(), 'dnes v 11:00', 'Now minus 1 hour');
9180 assert.equal(moment(a).subtract({d: 1}).calendar(), 'včera v 12:00', 'yesterday at the same time');
9181 });
9182
9183 test('calendar next week', function (assert) {
9184 var i, m, nextDay;
9185 for (i = 2; i < 7; i++) {
9186 m = moment().add({d: i});
9187 nextDay = '';
9188 switch (m.day()) {
9189 case 0:
9190 nextDay = 'v neděli';
9191 break;
9192 case 1:
9193 nextDay = 'v pondělí';
9194 break;
9195 case 2:
9196 nextDay = 'v úterý';
9197 break;
9198 case 3:
9199 nextDay = 've středu';
9200 break;
9201 case 4:
9202 nextDay = 've čtvrtek';
9203 break;
9204 case 5:
9205 nextDay = 'v pátek';
9206 break;
9207 case 6:
9208 nextDay = 'v sobotu';
9209 break;
9210 }
9211 assert.equal(m.calendar(), m.format('[' + nextDay + '] [v] LT'), 'Today + ' + i + ' days current time');
9212 m.hours(0).minutes(0).seconds(0).milliseconds(0);
9213 assert.equal(m.calendar(), m.format('[' + nextDay + '] [v] LT'), 'Today + ' + i + ' days beginning of day');
9214 m.hours(23).minutes(59).seconds(59).milliseconds(999);
9215 assert.equal(m.calendar(), m.format('[' + nextDay + '] [v] LT'), 'Today + ' + i + ' days end of day');
9216 }
9217 });
9218
9219 test('calendar last week', function (assert) {
9220 var i, m, lastDay;
9221 for (i = 2; i < 7; i++) {
9222 m = moment().subtract({d: i});
9223 lastDay = '';
9224 switch (m.day()) {
9225 case 0:
9226 lastDay = 'minulou neděli';
9227 break;
9228 case 1:
9229 lastDay = 'minulé pondělí';
9230 break;
9231 case 2:
9232 lastDay = 'minulé úterý';
9233 break;
9234 case 3:
9235 lastDay = 'minulou středu';
9236 break;
9237 case 4:
9238 lastDay = 'minulý čtvrtek';
9239 break;
9240 case 5:
9241 lastDay = 'minulý pátek';
9242 break;
9243 case 6:
9244 lastDay = 'minulou sobotu';
9245 break;
9246 }
9247 assert.equal(m.calendar(), m.format('[' + lastDay + '] [v] LT'), 'Today - ' + i + ' days current time');
9248 m.hours(0).minutes(0).seconds(0).milliseconds(0);
9249 assert.equal(m.calendar(), m.format('[' + lastDay + '] [v] LT'), 'Today - ' + i + ' days beginning of day');
9250 m.hours(23).minutes(59).seconds(59).milliseconds(999);
9251 assert.equal(m.calendar(), m.format('[' + lastDay + '] [v] LT'), 'Today - ' + i + ' days end of day');
9252 }
9253 });
9254
9255 test('calendar all else', function (assert) {
9256 var weeksAgo = moment().subtract({w: 1}),
9257 weeksFromNow = moment().add({w: 1});
9258
9259 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
9260 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
9261
9262 weeksAgo = moment().subtract({w: 2});
9263 weeksFromNow = moment().add({w: 2});
9264
9265 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
9266 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
9267 });
9268
9269 test('humanize duration', function (assert) {
9270 assert.equal(moment.duration(1, 'minutes').humanize(), 'minuta', 'a minute (future)');
9271 assert.equal(moment.duration(1, 'minutes').humanize(true), 'za minutu', 'in a minute');
9272 assert.equal(moment.duration(-1, 'minutes').humanize(), 'minuta', 'a minute (past)');
9273 assert.equal(moment.duration(-1, 'minutes').humanize(true), 'před minutou', 'a minute ago');
9274 });
9275
9276 test('weeks year starting sunday formatted', function (assert) {
9277 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
9278 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
9279 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
9280 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
9281 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
9282 });
73f3c911
IC
9283
9284})));
516f5f67 9285
516f5f67 9286
c74a101d
IC
9287;(function (global, factory) {
9288 typeof exports === 'object' && typeof module !== 'undefined'
9289 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
9290 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
9291 factory(global.moment)
73f3c911 9292}(this, (function (moment) { 'use strict';
516f5f67 9293
db71a655
KM
9294 function each(array, callback) {
9295 var i;
9296 for (i = 0; i < array.length; i++) {
9297 callback(array[i], i, array);
9298 }
b135bf1a
IC
9299 }
9300
c58511b9
KM
9301 function setupDeprecationHandler(test, moment$$1, scope) {
9302 test._expectedDeprecations = null;
9303 test._observedDeprecations = null;
9304 test._oldSupress = moment$$1.suppressDeprecationWarnings;
9305 moment$$1.suppressDeprecationWarnings = true;
9306 test.expectedDeprecations = function () {
9307 test._expectedDeprecations = arguments;
9308 test._observedDeprecations = [];
9309 };
9310 moment$$1.deprecationHandler = function (name, msg) {
9311 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
9312 if (deprecationId === -1) {
9313 throw new Error('Unexpected deprecation thrown name=' +
9314 name + ' msg=' + msg);
9315 }
9316 test._observedDeprecations[deprecationId] = 1;
9317 };
9318 }
9319
9320 function teardownDeprecationHandler(test, moment$$1, scope) {
9321 moment$$1.suppressDeprecationWarnings = test._oldSupress;
9322
9323 if (test._expectedDeprecations != null) {
9324 var missedDeprecations = [];
9325 each(test._expectedDeprecations, function (deprecationPattern, id) {
9326 if (test._observedDeprecations[id] !== 1) {
9327 missedDeprecations.push(deprecationPattern);
9328 }
9329 });
9330 if (missedDeprecations.length !== 0) {
9331 throw new Error('Expected deprecation warnings did not happen: ' +
9332 missedDeprecations.join(' '));
9333 }
9334 }
9335 }
9336
9337 function matchedDeprecation(name, msg, deprecations) {
9338 if (deprecations == null) {
9339 return -1;
9340 }
9341 for (var i = 0; i < deprecations.length; ++i) {
9342 if (name != null && name === deprecations[i]) {
9343 return i;
9344 }
9345 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
9346 return i;
9347 }
9348 }
9349 return -1;
9350 }
9351
9352 /*global QUnit:false*/
9353
9354 var test = QUnit.test;
9355
db71a655
KM
9356 function objectKeys(obj) {
9357 if (Object.keys) {
9358 return Object.keys(obj);
9359 } else {
9360 // IE8
9361 var res = [], i;
9362 for (i in obj) {
9363 if (obj.hasOwnProperty(i)) {
9364 res.push(i);
9365 }
b135bf1a 9366 }
db71a655 9367 return res;
b135bf1a 9368 }
b135bf1a
IC
9369 }
9370
db71a655 9371 // Pick the first defined of two or three arguments.
b135bf1a 9372
db71a655
KM
9373 function defineCommonLocaleTests(locale, options) {
9374 test('lenient day of month ordinal parsing', function (assert) {
9375 var i, ordinalStr, testMoment;
9376 for (i = 1; i <= 31; ++i) {
9377 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
9378 testMoment = moment(ordinalStr, 'YYYY MM Do');
9379 assert.equal(testMoment.year(), 2014,
9380 'lenient day of month ordinal parsing ' + i + ' year check');
9381 assert.equal(testMoment.month(), 0,
9382 'lenient day of month ordinal parsing ' + i + ' month check');
9383 assert.equal(testMoment.date(), i,
9384 'lenient day of month ordinal parsing ' + i + ' date check');
9385 }
9386 });
b135bf1a 9387
db71a655
KM
9388 test('lenient day of month ordinal parsing of number', function (assert) {
9389 var i, testMoment;
9390 for (i = 1; i <= 31; ++i) {
9391 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
9392 assert.equal(testMoment.year(), 2014,
9393 'lenient day of month ordinal parsing of number ' + i + ' year check');
9394 assert.equal(testMoment.month(), 0,
9395 'lenient day of month ordinal parsing of number ' + i + ' month check');
9396 assert.equal(testMoment.date(), i,
9397 'lenient day of month ordinal parsing of number ' + i + ' date check');
9398 }
9399 });
b135bf1a 9400
db71a655
KM
9401 test('strict day of month ordinal parsing', function (assert) {
9402 var i, ordinalStr, testMoment;
9403 for (i = 1; i <= 31; ++i) {
9404 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
9405 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
9406 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
9407 }
9408 });
b135bf1a 9409
db71a655
KM
9410 test('meridiem invariant', function (assert) {
9411 var h, m, t1, t2;
9412 for (h = 0; h < 24; ++h) {
9413 for (m = 0; m < 60; m += 15) {
9414 t1 = moment.utc([2000, 0, 1, h, m]);
9415 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
9416 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
9417 'meridiem at ' + t1.format('HH:mm'));
9418 }
9419 }
9420 });
9421
9422 test('date format correctness', function (assert) {
9423 var data, tokens;
9424 data = moment.localeData()._longDateFormat;
9425 tokens = objectKeys(data);
9426 each(tokens, function (srchToken) {
9427 // Check each format string to make sure it does not contain any
9428 // tokens that need to be expanded.
9429 each(tokens, function (baseToken) {
9430 // strip escaped sequences
9431 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
9432 assert.equal(false, !!~format.indexOf(srchToken),
9433 'contains ' + srchToken + ' in ' + baseToken);
9434 });
b135bf1a
IC
9435 });
9436 });
d6651c21 9437
db71a655
KM
9438 test('month parsing correctness', function (assert) {
9439 var i, m;
9440
9441 if (locale === 'tr') {
9442 // I can't fix it :(
c58511b9 9443 assert.expect(0);
db71a655
KM
9444 return;
9445 }
9446 function tester(format) {
9447 var r;
9448 r = moment(m.format(format), format);
9449 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
9450 if (locale !== 'ka') {
9451 r = moment(m.format(format).toLocaleUpperCase(), format);
9452 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
9453 }
db71a655
KM
9454 r = moment(m.format(format).toLocaleLowerCase(), format);
9455 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
9456
9457 r = moment(m.format(format), format, true);
9458 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
9459 if (locale !== 'ka') {
9460 r = moment(m.format(format).toLocaleUpperCase(), format, true);
9461 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
9462 }
db71a655
KM
9463 r = moment(m.format(format).toLocaleLowerCase(), format, true);
9464 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
9465 }
9466
9467 for (i = 0; i < 12; ++i) {
9468 m = moment([2015, i, 15, 18]);
9469 tester('MMM');
9470 tester('MMM.');
9471 tester('MMMM');
9472 tester('MMMM.');
9473 }
9474 });
d6651c21 9475
db71a655
KM
9476 test('weekday parsing correctness', function (assert) {
9477 var i, m;
9478
96d0d679 9479 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
9480 // tr, az: There is a lower-case letter (ı), that converted to
9481 // upper then lower changes to i
9482 // ro: there is the letter ț which behaves weird under IE8
9483 // mt: letter Ħ
96d0d679 9484 // ga: month with spaces
c58511b9 9485 assert.expect(0);
db71a655
KM
9486 return;
9487 }
9488 function tester(format) {
9489 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
9490 r = moment(m.format(format), format);
9491 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
9492 if (locale !== 'ka') {
9493 r = moment(m.format(format).toLocaleUpperCase(), format);
9494 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
9495 }
db71a655
KM
9496 r = moment(m.format(format).toLocaleLowerCase(), format);
9497 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
9498 r = moment(m.format(format), format, true);
9499 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
9500 if (locale !== 'ka') {
9501 r = moment(m.format(format).toLocaleUpperCase(), format, true);
9502 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
9503 }
db71a655
KM
9504 r = moment(m.format(format).toLocaleLowerCase(), format, true);
9505 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
9506 }
9507
9508 for (i = 0; i < 7; ++i) {
9509 m = moment.utc([2015, 0, i + 1, 18]);
9510 tester('dd');
9511 tester('ddd');
9512 tester('dddd');
9513 }
9514 });
d6651c21 9515
db71a655
KM
9516 test('valid localeData', function (assert) {
9517 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
9518 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
9519 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
9520 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
9521 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
9522 });
96d0d679
KM
9523
9524 test('localeData weekdays can localeSort', function (assert) {
9525 var weekdays = moment().localeData().weekdays();
9526 var weekdaysShort = moment().localeData().weekdaysShort();
9527 var weekdaysMin = moment().localeData().weekdaysMin();
9528 var shift = moment().localeData()._week.dow;
9529 assert.deepEqual(
9530 moment().localeData().weekdays(true),
9531 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
9532 'weekdays should localeSort');
9533 assert.deepEqual(
9534 moment().localeData().weekdaysShort(true),
9535 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
9536 'weekdaysShort should localeSort');
9537 assert.deepEqual(
9538 moment().localeData().weekdaysMin(true),
9539 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
9540 'weekdaysMin should localeSort');
9541 });
db71a655 9542 }
d6651c21 9543
db71a655
KM
9544 /*global QUnit:false*/
9545
db71a655
KM
9546 function localeModule (name, lifecycle) {
9547 QUnit.module('locale:' + name, {
c58511b9 9548 beforeEach : function () {
db71a655
KM
9549 moment.locale(name);
9550 moment.createFromInputFallback = function (config) {
9551 throw new Error('input not handled by moment: ' + config._i);
9552 };
9553 setupDeprecationHandler(test, moment, 'locale');
9554 if (lifecycle && lifecycle.setup) {
9555 lifecycle.setup();
9556 }
9557 },
c58511b9 9558 afterEach : function () {
db71a655
KM
9559 moment.locale('en');
9560 teardownDeprecationHandler(test, moment, 'locale');
9561 if (lifecycle && lifecycle.teardown) {
9562 lifecycle.teardown();
9563 }
516f5f67
IC
9564 }
9565 });
db71a655
KM
9566 defineCommonLocaleTests(name, -1, -1);
9567 }
9568
9569 localeModule('cv');
9570
9571 test('parse', function (assert) {
9572 var tests = 'кӑрлач кӑр_нарӑс нар_пуш пуш_ака ака_май май_ҫӗртме ҫӗр_утӑ утӑ_ҫурла ҫур_авӑн авн_юпа юпа_чӳк чӳк_раштав раш'.split('_'), i;
9573 function equalTest(input, mmm, i) {
9574 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
9575 }
9576 for (i = 0; i < 12; i++) {
9577 tests[i] = tests[i].split(' ');
9578 equalTest(tests[i][0], 'MMM', i);
9579 equalTest(tests[i][1], 'MMM', i);
9580 equalTest(tests[i][0], 'MMMM', i);
9581 equalTest(tests[i][1], 'MMMM', i);
9582 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
9583 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
9584 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
9585 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
9586 }
9587 });
9588
9589 test('format', function (assert) {
9590 var a = [
9591 ['dddd, MMMM Do YYYY, h:mm:ss a', 'вырсарникун, нарӑс 14-мӗш 2010, 3:25:50 pm'],
9592 ['ddd, hA', 'выр, 3PM'],
9593 ['M Mo MM MMMM MMM', '2 2-мӗш 02 нарӑс нар'],
9594 ['YYYY YY', '2010 10'],
9595 ['D Do DD', '14 14-мӗш 14'],
9596 ['d do dddd ddd dd', '0 0-мӗш вырсарникун выр вр'],
9597 ['DDD DDDo DDDD', '45 45-мӗш 045'],
9598 ['w wo ww', '7 7-мӗш 07'],
9599 ['h hh', '3 03'],
9600 ['H HH', '15 15'],
9601 ['m mm', '25 25'],
9602 ['s ss', '50 50'],
9603 ['a A', 'pm PM'],
9604 ['Ҫулӑн DDDo кунӗ', 'Ҫулӑн 45-мӗш кунӗ'],
9605 ['LTS', '15:25:50'],
9606 ['L', '14-02-2010'],
9607 ['LL', '2010 ҫулхи нарӑс уйӑхӗн 14-мӗшӗ'],
9608 ['LLL', '2010 ҫулхи нарӑс уйӑхӗн 14-мӗшӗ, 15:25'],
9609 ['LLLL', 'вырсарникун, 2010 ҫулхи нарӑс уйӑхӗн 14-мӗшӗ, 15:25'],
9610 ['l', '14-2-2010'],
9611 ['ll', '2010 ҫулхи нар уйӑхӗн 14-мӗшӗ'],
9612 ['lll', '2010 ҫулхи нар уйӑхӗн 14-мӗшӗ, 15:25'],
9613 ['llll', 'выр, 2010 ҫулхи нар уйӑхӗн 14-мӗшӗ, 15:25']
9614 ],
9615 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
9616 i;
9617 for (i = 0; i < a.length; i++) {
9618 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
9619 }
9620 });
9621
9622 test('format ordinal', function (assert) {
9623 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-мӗш', '1-мӗш');
9624 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-мӗш', '2-мӗш');
9625 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-мӗш', '3-мӗш');
9626 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-мӗш', '4-мӗш');
9627 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-мӗш', '5-мӗш');
9628 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-мӗш', '6-мӗш');
9629 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-мӗш', '7-мӗш');
9630 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-мӗш', '8-мӗш');
9631 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-мӗш', '9-мӗш');
9632 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-мӗш', '10-мӗш');
9633
9634 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-мӗш', '11-мӗш');
9635 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-мӗш', '12-мӗш');
9636 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-мӗш', '13-мӗш');
9637 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-мӗш', '14-мӗш');
9638 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-мӗш', '15-мӗш');
9639 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-мӗш', '16-мӗш');
9640 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-мӗш', '17-мӗш');
9641 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-мӗш', '18-мӗш');
9642 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-мӗш', '19-мӗш');
9643 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-мӗш', '20-мӗш');
9644
9645 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-мӗш', '21-мӗш');
9646 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-мӗш', '22-мӗш');
9647 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-мӗш', '23-мӗш');
9648 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-мӗш', '24-мӗш');
9649 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-мӗш', '25-мӗш');
9650 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-мӗш', '26-мӗш');
9651 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-мӗш', '27-мӗш');
9652 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-мӗш', '28-мӗш');
9653 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-мӗш', '29-мӗш');
9654 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-мӗш', '30-мӗш');
9655
9656 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-мӗш', '31-мӗш');
9657 });
9658
9659 test('format month', function (assert) {
9660 var expected = 'кӑрлач кӑр_нарӑс нар_пуш пуш_ака ака_май май_ҫӗртме ҫӗр_утӑ утӑ_ҫурла ҫур_авӑн авн_юпа юпа_чӳк чӳк_раштав раш'.split('_'), i;
9661 for (i = 0; i < expected.length; i++) {
9662 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
9663 }
9664 });
9665
9666 test('format week', function (assert) {
9667 var expected = 'вырсарникун выр вр_тунтикун тун тн_ытларикун ытл ыт_юнкун юн юн_кӗҫнерникун кӗҫ кҫ_эрнекун эрн эр_шӑматкун шӑм шм'.split('_'), i;
9668 for (i = 0; i < expected.length; i++) {
9669 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
9670 }
9671 });
9672
9673 test('from', function (assert) {
9674 var start = moment([2007, 1, 28]);
9675 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'пӗр-ик ҫеккунт', '44 sekunder = a few seconds');
9676 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'пӗр минут', '45 seconds = a minute');
9677 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'пӗр минут', '89 seconds = a minute');
9678 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 минут', '90 seconds = 2 minutes');
9679 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 минут', '44 minutes = 44 minutes');
9680 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'пӗр сехет', '45 minutes = an hour');
9681 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'пӗр сехет', '89 minutes = an hour');
9682 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 сехет', '90 minutes = 2 hours');
9683 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 сехет', '5 hours = 5 hours');
9684 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 сехет', '21 hours = 21 hours');
9685 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'пӗр кун', '22 hours = a day');
9686 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'пӗр кун', '35 hours = a day');
9687 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 кун', '36 hours = 2 days');
9688 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'пӗр кун', '1 day = a day');
9689 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 кун', '5 days = 5 days');
9690 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 кун', '25 days = 25 days');
9691 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'пӗр уйӑх', '26 days = a month');
9692 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'пӗр уйӑх', '30 days = a month');
9693 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'пӗр уйӑх', '43 days = a month');
9694 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 уйӑх', '46 days = 2 months');
9695 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 уйӑх', '75 days = 2 months');
9696 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 уйӑх', '76 days = 3 months');
9697 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'пӗр уйӑх', '1 month = a month');
9698 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 уйӑх', '5 months = 5 months');
9699 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'пӗр ҫул', '345 days = a year');
9700 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ҫул', '548 days = 2 years');
9701 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'пӗр ҫул', '1 year = a year');
9702 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ҫул', '5 years = 5 years');
9703 });
9704
9705 test('suffix', function (assert) {
9706 assert.equal(moment(30000).from(0), 'пӗр-ик ҫеккунтран', 'prefix');
9707 assert.equal(moment(0).from(30000), 'пӗр-ик ҫеккунт каялла', 'suffix');
9708 });
9709
9710 test('now from now', function (assert) {
9711 assert.equal(moment().fromNow(), 'пӗр-ик ҫеккунт каялла', 'now from now should display as in the past');
9712 });
9713
9714 test('fromNow', function (assert) {
9715 assert.equal(moment().add({s: 30}).fromNow(), 'пӗр-ик ҫеккунтран', 'in a few seconds');
9716 assert.equal(moment().add({d: 5}).fromNow(), '5 кунран', 'in 5 days');
9717 assert.equal(moment().add({h: 2}).fromNow(), '2 сехетрен', 'in 2 hours, the right suffix!');
9718 assert.equal(moment().add({y: 3}).fromNow(), '3 ҫултан', 'in 3 years, the right suffix!');
9719 });
9720
9721 test('calendar day', function (assert) {
9722 var a = moment().hours(12).minutes(0).seconds(0);
9723 assert.equal(moment(a).calendar(), 'Паян 12:00 сехетре', 'today at the same time');
9724 assert.equal(moment(a).add({m: 25}).calendar(), 'Паян 12:25 сехетре', 'Now plus 25 min');
9725 assert.equal(moment(a).add({h: 1}).calendar(), 'Паян 13:00 сехетре', 'Now plus 1 hour');
9726 assert.equal(moment(a).add({d: 1}).calendar(), 'Ыран 12:00 сехетре', 'tomorrow at the same time');
9727 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Паян 11:00 сехетре', 'Now minus 1 hour');
9728 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Ӗнер 12:00 сехетре', 'yesterday at the same time');
9729 });
9730
9731 test('calendar next week', function (assert) {
9732 var i, m;
516f5f67 9733
db71a655
KM
9734 for (i = 2; i < 7; i++) {
9735 m = moment().add({d: i});
9736 assert.equal(m.calendar(), m.format('[Ҫитес] dddd LT [сехетре]'), 'Today + ' + i + ' days current time');
9737 m.hours(0).minutes(0).seconds(0).milliseconds(0);
9738 assert.equal(m.calendar(), m.format('[Ҫитес] dddd LT [сехетре]'), 'Today + ' + i + ' days beginning of day');
9739 m.hours(23).minutes(59).seconds(59).milliseconds(999);
9740 assert.equal(m.calendar(), m.format('[Ҫитес] dddd LT [сехетре]'), 'Today + ' + i + ' days end of day');
516f5f67 9741 }
db71a655
KM
9742 });
9743
9744 test('calendar last week', function (assert) {
9745 var i, m;
9746
9747 for (i = 2; i < 7; i++) {
9748 m = moment().subtract({d: i});
9749 assert.equal(m.calendar(), m.format('[Иртнӗ] dddd LT [сехетре]'), 'Today - ' + i + ' days current time');
9750 m.hours(0).minutes(0).seconds(0).milliseconds(0);
9751 assert.equal(m.calendar(), m.format('[Иртнӗ] dddd LT [сехетре]'), 'Today - ' + i + ' days beginning of day');
9752 m.hours(23).minutes(59).seconds(59).milliseconds(999);
9753 assert.equal(m.calendar(), m.format('[Иртнӗ] dddd LT [сехетре]'), 'Today - ' + i + ' days end of day');
516f5f67 9754 }
db71a655 9755 });
516f5f67 9756
db71a655
KM
9757 test('calendar all else', function (assert) {
9758 var weeksAgo = moment().subtract({w: 1}),
9759 weeksFromNow = moment().add({w: 1});
516f5f67 9760
db71a655
KM
9761 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
9762 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 9763
db71a655
KM
9764 weeksAgo = moment().subtract({w: 2});
9765 weeksFromNow = moment().add({w: 2});
516f5f67 9766
db71a655
KM
9767 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
9768 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
9769 });
9770
9771 // Monday is the first day of the week.
9772 // The week that contains Jan 1st is the first week of the year.
9773
9774 test('weeks year starting sunday formatted', function (assert) {
9775 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-мӗш', 'Dec 26 2011 should be week 1');
9776 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-мӗш', 'Jan 1 2012 should be week 1');
9777 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-мӗш', 'Jan 2 2012 should be week 2');
9778 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-мӗш', 'Jan 8 2012 should be week 2');
9779 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-мӗш', 'Jan 9 2012 should be week 3');
9780 });
73f3c911
IC
9781
9782})));
516f5f67 9783
516f5f67 9784
c74a101d
IC
9785;(function (global, factory) {
9786 typeof exports === 'object' && typeof module !== 'undefined'
9787 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
9788 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
9789 factory(global.moment)
73f3c911 9790}(this, (function (moment) { 'use strict';
516f5f67 9791
db71a655
KM
9792 function each(array, callback) {
9793 var i;
9794 for (i = 0; i < array.length; i++) {
9795 callback(array[i], i, array);
9796 }
b135bf1a
IC
9797 }
9798
c58511b9
KM
9799 function setupDeprecationHandler(test, moment$$1, scope) {
9800 test._expectedDeprecations = null;
9801 test._observedDeprecations = null;
9802 test._oldSupress = moment$$1.suppressDeprecationWarnings;
9803 moment$$1.suppressDeprecationWarnings = true;
9804 test.expectedDeprecations = function () {
9805 test._expectedDeprecations = arguments;
9806 test._observedDeprecations = [];
9807 };
9808 moment$$1.deprecationHandler = function (name, msg) {
9809 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
9810 if (deprecationId === -1) {
9811 throw new Error('Unexpected deprecation thrown name=' +
9812 name + ' msg=' + msg);
9813 }
9814 test._observedDeprecations[deprecationId] = 1;
9815 };
9816 }
9817
9818 function teardownDeprecationHandler(test, moment$$1, scope) {
9819 moment$$1.suppressDeprecationWarnings = test._oldSupress;
9820
9821 if (test._expectedDeprecations != null) {
9822 var missedDeprecations = [];
9823 each(test._expectedDeprecations, function (deprecationPattern, id) {
9824 if (test._observedDeprecations[id] !== 1) {
9825 missedDeprecations.push(deprecationPattern);
9826 }
9827 });
9828 if (missedDeprecations.length !== 0) {
9829 throw new Error('Expected deprecation warnings did not happen: ' +
9830 missedDeprecations.join(' '));
9831 }
9832 }
9833 }
9834
9835 function matchedDeprecation(name, msg, deprecations) {
9836 if (deprecations == null) {
9837 return -1;
9838 }
9839 for (var i = 0; i < deprecations.length; ++i) {
9840 if (name != null && name === deprecations[i]) {
9841 return i;
9842 }
9843 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
9844 return i;
9845 }
9846 }
9847 return -1;
9848 }
9849
9850 /*global QUnit:false*/
9851
9852 var test = QUnit.test;
9853
db71a655
KM
9854 function objectKeys(obj) {
9855 if (Object.keys) {
9856 return Object.keys(obj);
9857 } else {
9858 // IE8
9859 var res = [], i;
9860 for (i in obj) {
9861 if (obj.hasOwnProperty(i)) {
9862 res.push(i);
9863 }
b135bf1a 9864 }
db71a655 9865 return res;
b135bf1a
IC
9866 }
9867 }
b135bf1a 9868
db71a655 9869 // Pick the first defined of two or three arguments.
b135bf1a 9870
db71a655
KM
9871 function defineCommonLocaleTests(locale, options) {
9872 test('lenient day of month ordinal parsing', function (assert) {
9873 var i, ordinalStr, testMoment;
9874 for (i = 1; i <= 31; ++i) {
9875 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
9876 testMoment = moment(ordinalStr, 'YYYY MM Do');
9877 assert.equal(testMoment.year(), 2014,
9878 'lenient day of month ordinal parsing ' + i + ' year check');
9879 assert.equal(testMoment.month(), 0,
9880 'lenient day of month ordinal parsing ' + i + ' month check');
9881 assert.equal(testMoment.date(), i,
9882 'lenient day of month ordinal parsing ' + i + ' date check');
9883 }
9884 });
b135bf1a 9885
db71a655
KM
9886 test('lenient day of month ordinal parsing of number', function (assert) {
9887 var i, testMoment;
9888 for (i = 1; i <= 31; ++i) {
9889 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
9890 assert.equal(testMoment.year(), 2014,
9891 'lenient day of month ordinal parsing of number ' + i + ' year check');
9892 assert.equal(testMoment.month(), 0,
9893 'lenient day of month ordinal parsing of number ' + i + ' month check');
9894 assert.equal(testMoment.date(), i,
9895 'lenient day of month ordinal parsing of number ' + i + ' date check');
9896 }
b135bf1a 9897 });
d6651c21 9898
db71a655
KM
9899 test('strict day of month ordinal parsing', function (assert) {
9900 var i, ordinalStr, testMoment;
9901 for (i = 1; i <= 31; ++i) {
9902 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
9903 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
9904 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
9905 }
9906 });
d6651c21 9907
db71a655
KM
9908 test('meridiem invariant', function (assert) {
9909 var h, m, t1, t2;
9910 for (h = 0; h < 24; ++h) {
9911 for (m = 0; m < 60; m += 15) {
9912 t1 = moment.utc([2000, 0, 1, h, m]);
9913 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
9914 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
9915 'meridiem at ' + t1.format('HH:mm'));
9916 }
9917 }
9918 });
d6651c21 9919
db71a655
KM
9920 test('date format correctness', function (assert) {
9921 var data, tokens;
9922 data = moment.localeData()._longDateFormat;
9923 tokens = objectKeys(data);
9924 each(tokens, function (srchToken) {
9925 // Check each format string to make sure it does not contain any
9926 // tokens that need to be expanded.
9927 each(tokens, function (baseToken) {
9928 // strip escaped sequences
9929 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
9930 assert.equal(false, !!~format.indexOf(srchToken),
9931 'contains ' + srchToken + ' in ' + baseToken);
9932 });
9933 });
9934 });
d6651c21 9935
db71a655
KM
9936 test('month parsing correctness', function (assert) {
9937 var i, m;
9938
9939 if (locale === 'tr') {
9940 // I can't fix it :(
c58511b9 9941 assert.expect(0);
db71a655
KM
9942 return;
9943 }
9944 function tester(format) {
9945 var r;
9946 r = moment(m.format(format), format);
9947 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
9948 if (locale !== 'ka') {
9949 r = moment(m.format(format).toLocaleUpperCase(), format);
9950 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
9951 }
db71a655
KM
9952 r = moment(m.format(format).toLocaleLowerCase(), format);
9953 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
9954
9955 r = moment(m.format(format), format, true);
9956 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
9957 if (locale !== 'ka') {
9958 r = moment(m.format(format).toLocaleUpperCase(), format, true);
9959 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
9960 }
db71a655
KM
9961 r = moment(m.format(format).toLocaleLowerCase(), format, true);
9962 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
9963 }
9964
9965 for (i = 0; i < 12; ++i) {
9966 m = moment([2015, i, 15, 18]);
9967 tester('MMM');
9968 tester('MMM.');
9969 tester('MMMM');
9970 tester('MMMM.');
9971 }
9972 });
73f3c911 9973
db71a655
KM
9974 test('weekday parsing correctness', function (assert) {
9975 var i, m;
9976
96d0d679 9977 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
9978 // tr, az: There is a lower-case letter (ı), that converted to
9979 // upper then lower changes to i
9980 // ro: there is the letter ț which behaves weird under IE8
9981 // mt: letter Ħ
96d0d679 9982 // ga: month with spaces
c58511b9 9983 assert.expect(0);
db71a655
KM
9984 return;
9985 }
9986 function tester(format) {
9987 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
9988 r = moment(m.format(format), format);
9989 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
9990 if (locale !== 'ka') {
9991 r = moment(m.format(format).toLocaleUpperCase(), format);
9992 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
9993 }
db71a655
KM
9994 r = moment(m.format(format).toLocaleLowerCase(), format);
9995 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
9996 r = moment(m.format(format), format, true);
9997 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
9998 if (locale !== 'ka') {
9999 r = moment(m.format(format).toLocaleUpperCase(), format, true);
10000 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
10001 }
db71a655
KM
10002 r = moment(m.format(format).toLocaleLowerCase(), format, true);
10003 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
10004 }
10005
10006 for (i = 0; i < 7; ++i) {
10007 m = moment.utc([2015, 0, i + 1, 18]);
10008 tester('dd');
10009 tester('ddd');
10010 tester('dddd');
10011 }
10012 });
d6651c21 10013
db71a655
KM
10014 test('valid localeData', function (assert) {
10015 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
10016 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
10017 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
10018 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
10019 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
10020 });
96d0d679
KM
10021
10022 test('localeData weekdays can localeSort', function (assert) {
10023 var weekdays = moment().localeData().weekdays();
10024 var weekdaysShort = moment().localeData().weekdaysShort();
10025 var weekdaysMin = moment().localeData().weekdaysMin();
10026 var shift = moment().localeData()._week.dow;
10027 assert.deepEqual(
10028 moment().localeData().weekdays(true),
10029 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
10030 'weekdays should localeSort');
10031 assert.deepEqual(
10032 moment().localeData().weekdaysShort(true),
10033 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
10034 'weekdaysShort should localeSort');
10035 assert.deepEqual(
10036 moment().localeData().weekdaysMin(true),
10037 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
10038 'weekdaysMin should localeSort');
10039 });
db71a655 10040 }
b135bf1a 10041
db71a655 10042 /*global QUnit:false*/
516f5f67 10043
db71a655
KM
10044 function localeModule (name, lifecycle) {
10045 QUnit.module('locale:' + name, {
c58511b9 10046 beforeEach : function () {
db71a655
KM
10047 moment.locale(name);
10048 moment.createFromInputFallback = function (config) {
10049 throw new Error('input not handled by moment: ' + config._i);
10050 };
10051 setupDeprecationHandler(test, moment, 'locale');
10052 if (lifecycle && lifecycle.setup) {
10053 lifecycle.setup();
10054 }
10055 },
c58511b9 10056 afterEach : function () {
db71a655
KM
10057 moment.locale('en');
10058 teardownDeprecationHandler(test, moment, 'locale');
10059 if (lifecycle && lifecycle.teardown) {
10060 lifecycle.teardown();
10061 }
73f3c911 10062 }
db71a655
KM
10063 });
10064 defineCommonLocaleTests(name, -1, -1);
10065 }
10066
10067 localeModule('cy');
10068
10069 test('parse', function (assert) {
10070 var tests = 'Ionawr Ion_Chwefror Chwe_Mawrth Maw_Ebrill Ebr_Mai Mai_Mehefin Meh_Gorffennaf Gor_Awst Aws_Medi Med_Hydref Hyd_Tachwedd Tach_Rhagfyr Rhag'.split('_'),
10071 i;
10072 function equalTest(input, mmm, i) {
10073 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
10074 }
10075 for (i = 0; i < 12; i++) {
10076 tests[i] = tests[i].split(' ');
10077 equalTest(tests[i][0], 'MMM', i);
10078 equalTest(tests[i][1], 'MMM', i);
10079 equalTest(tests[i][0], 'MMMM', i);
10080 equalTest(tests[i][1], 'MMMM', i);
10081 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
10082 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
10083 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
10084 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
10085 }
10086 });
10087
10088 test('format', function (assert) {
10089 var a = [
10090 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Dydd Sul, Chwefror 14eg 2010, 3:25:50 pm'],
10091 ['ddd, hA', 'Sul, 3PM'],
10092 ['M Mo MM MMMM MMM', '2 2il 02 Chwefror Chwe'],
10093 ['YYYY YY', '2010 10'],
10094 ['D Do DD', '14 14eg 14'],
10095 ['d do dddd ddd dd', '0 0 Dydd Sul Sul Su'],
10096 ['DDD DDDo DDDD', '45 45ain 045'],
10097 ['w wo ww', '6 6ed 06'],
10098 ['h hh', '3 03'],
10099 ['H HH', '15 15'],
10100 ['m mm', '25 25'],
10101 ['s ss', '50 50'],
10102 ['a A', 'pm PM'],
10103 ['[the] DDDo [day of the year]', 'the 45ain day of the year'],
10104 ['LTS', '15:25:50'],
10105 ['L', '14/02/2010'],
10106 ['LL', '14 Chwefror 2010'],
10107 ['LLL', '14 Chwefror 2010 15:25'],
10108 ['LLLL', 'Dydd Sul, 14 Chwefror 2010 15:25'],
10109 ['l', '14/2/2010'],
10110 ['ll', '14 Chwe 2010'],
10111 ['lll', '14 Chwe 2010 15:25'],
10112 ['llll', 'Sul, 14 Chwe 2010 15:25']
10113 ],
10114 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
10115 i;
10116 for (i = 0; i < a.length; i++) {
10117 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
10118 }
10119 });
10120
10121 test('format ordinal', function (assert) {
10122 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1af', '1af');
10123 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2il', '2il');
10124 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3ydd', '3ydd');
10125 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4ydd', '4ydd');
10126 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5ed', '5ed');
10127 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6ed', '6ed');
10128 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7ed', '7ed');
10129 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8fed', '8fed');
10130 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9fed', '9fed');
10131 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10fed', '10fed');
10132
10133 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11eg', '11eg');
10134 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12fed', '12fed');
10135 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13eg', '13eg');
10136 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14eg', '14eg');
10137 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15fed', '15fed');
10138 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16eg', '16eg');
10139 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17eg', '17eg');
10140 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18fed', '18fed');
10141 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19eg', '19eg');
10142 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20fed', '20fed');
10143
10144 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21ain', '21ain');
10145 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22ain', '22ain');
10146 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23ain', '23ain');
10147 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24ain', '24ain');
10148 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25ain', '25ain');
10149 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26ain', '26ain');
10150 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27ain', '27ain');
10151 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28ain', '28ain');
10152 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29ain', '29ain');
10153 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30ain', '30ain');
10154
10155 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31ain', '31ain');
10156 });
10157
10158 test('format month', function (assert) {
10159 var expected = 'Ionawr Ion_Chwefror Chwe_Mawrth Maw_Ebrill Ebr_Mai Mai_Mehefin Meh_Gorffennaf Gor_Awst Aws_Medi Med_Hydref Hyd_Tachwedd Tach_Rhagfyr Rhag'.split('_'), i;
10160 for (i = 0; i < expected.length; i++) {
10161 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
10162 }
10163 });
10164
10165 test('format week', function (assert) {
10166 var expected = 'Dydd Sul Sul Su_Dydd Llun Llun Ll_Dydd Mawrth Maw Ma_Dydd Mercher Mer Me_Dydd Iau Iau Ia_Dydd Gwener Gwe Gw_Dydd Sadwrn Sad Sa'.split('_'), i;
10167 for (i = 0; i < expected.length; i++) {
10168 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
10169 }
10170 });
10171
10172 test('from', function (assert) {
10173 var start = moment([2007, 1, 28]);
10174 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ychydig eiliadau', '44 seconds = a few seconds');
10175 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'munud', '45 seconds = a minute');
10176 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'munud', '89 seconds = a minute');
10177 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 munud', '90 seconds = 2 minutes');
10178 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 munud', '44 minutes = 44 minutes');
10179 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'awr', '45 minutes = an hour');
10180 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'awr', '89 minutes = an hour');
10181 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 awr', '90 minutes = 2 hours');
10182 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 awr', '5 hours = 5 hours');
10183 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 awr', '21 hours = 21 hours');
10184 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'diwrnod', '22 hours = a day');
10185 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'diwrnod', '35 hours = a day');
10186 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 diwrnod', '36 hours = 2 days');
10187 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'diwrnod', '1 day = a day');
10188 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 diwrnod', '5 days = 5 days');
10189 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 diwrnod', '25 days = 25 days');
10190 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mis', '26 days = a month');
10191 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mis', '30 days = a month');
10192 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mis', '43 days = a month');
10193 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mis', '46 days = 2 months');
10194 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mis', '75 days = 2 months');
10195 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mis', '76 days = 3 months');
10196 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mis', '1 month = a month');
10197 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mis', '5 months = 5 months');
10198 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'blwyddyn', '345 days = a year');
10199 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 flynedd', '548 days = 2 years');
10200 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'blwyddyn', '1 year = a year');
10201 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 flynedd', '5 years = 5 years');
10202 });
10203
10204 test('suffix', function (assert) {
10205 assert.equal(moment(30000).from(0), 'mewn ychydig eiliadau', 'prefix');
10206 assert.equal(moment(0).from(30000), 'ychydig eiliadau yn ôl', 'suffix');
10207 });
10208
10209 test('fromNow', function (assert) {
10210 assert.equal(moment().add({s: 30}).fromNow(), 'mewn ychydig eiliadau', 'in a few seconds');
10211 assert.equal(moment().add({d: 5}).fromNow(), 'mewn 5 diwrnod', 'in 5 days');
10212 });
10213
10214 test('calendar day', function (assert) {
10215 var a = moment().hours(12).minutes(0).seconds(0);
10216
10217 assert.equal(moment(a).calendar(), 'Heddiw am 12:00', 'today at the same time');
10218 assert.equal(moment(a).add({m: 25}).calendar(), 'Heddiw am 12:25', 'Now plus 25 min');
10219 assert.equal(moment(a).add({h: 1}).calendar(), 'Heddiw am 13:00', 'Now plus 1 hour');
10220 assert.equal(moment(a).add({d: 1}).calendar(), 'Yfory am 12:00', 'tomorrow at the same time');
10221 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Heddiw am 11:00', 'Now minus 1 hour');
10222 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Ddoe am 12:00', 'yesterday at the same time');
10223 });
10224
10225 test('calendar next week', function (assert) {
10226 var i, m;
10227
10228 for (i = 2; i < 7; i++) {
10229 m = moment().add({d: i});
10230 assert.equal(m.calendar(), m.format('dddd [am] LT'), 'Today + ' + i + ' days current time');
10231 m.hours(0).minutes(0).seconds(0).milliseconds(0);
10232 assert.equal(m.calendar(), m.format('dddd [am] LT'), 'Today + ' + i + ' days beginning of day');
10233 m.hours(23).minutes(59).seconds(59).milliseconds(999);
10234 assert.equal(m.calendar(), m.format('dddd [am] LT'), 'Today + ' + i + ' days end of day');
10235 }
10236 });
10237
10238 test('calendar last week', function (assert) {
10239 var i, m;
10240
10241 for (i = 2; i < 7; i++) {
10242 m = moment().subtract({d: i});
10243 assert.equal(m.calendar(), m.format('dddd [diwethaf am] LT'), 'Today - ' + i + ' days current time');
10244 m.hours(0).minutes(0).seconds(0).milliseconds(0);
10245 assert.equal(m.calendar(), m.format('dddd [diwethaf am] LT'), 'Today - ' + i + ' days beginning of day');
10246 m.hours(23).minutes(59).seconds(59).milliseconds(999);
10247 assert.equal(m.calendar(), m.format('dddd [diwethaf am] LT'), 'Today - ' + i + ' days end of day');
73f3c911 10248 }
516f5f67
IC
10249 });
10250
db71a655
KM
10251 test('calendar all else', function (assert) {
10252 var weeksAgo = moment().subtract({w: 1}),
10253 weeksFromNow = moment().add({w: 1});
73f3c911 10254
db71a655
KM
10255 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
10256 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
10257
10258 weeksAgo = moment().subtract({w: 2});
10259 weeksFromNow = moment().add({w: 2});
10260
10261 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
10262 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
10263 });
10264
10265 test('weeks year starting sunday formatted', function (assert) {
10266 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52ain', 'Jan 1 2012 should be week 52');
10267 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1af', 'Jan 2 2012 should be week 1');
10268 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1af', 'Jan 8 2012 should be week 1');
10269 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2il', 'Jan 9 2012 should be week 2');
10270 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2il', 'Jan 15 2012 should be week 2');
10271 });
73f3c911
IC
10272
10273})));
516f5f67 10274
516f5f67 10275
c74a101d
IC
10276;(function (global, factory) {
10277 typeof exports === 'object' && typeof module !== 'undefined'
10278 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
10279 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
10280 factory(global.moment)
73f3c911 10281}(this, (function (moment) { 'use strict';
516f5f67 10282
db71a655
KM
10283 function each(array, callback) {
10284 var i;
10285 for (i = 0; i < array.length; i++) {
10286 callback(array[i], i, array);
10287 }
b135bf1a
IC
10288 }
10289
c58511b9
KM
10290 function setupDeprecationHandler(test, moment$$1, scope) {
10291 test._expectedDeprecations = null;
10292 test._observedDeprecations = null;
10293 test._oldSupress = moment$$1.suppressDeprecationWarnings;
10294 moment$$1.suppressDeprecationWarnings = true;
10295 test.expectedDeprecations = function () {
10296 test._expectedDeprecations = arguments;
10297 test._observedDeprecations = [];
10298 };
10299 moment$$1.deprecationHandler = function (name, msg) {
10300 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
10301 if (deprecationId === -1) {
10302 throw new Error('Unexpected deprecation thrown name=' +
10303 name + ' msg=' + msg);
10304 }
10305 test._observedDeprecations[deprecationId] = 1;
10306 };
10307 }
10308
10309 function teardownDeprecationHandler(test, moment$$1, scope) {
10310 moment$$1.suppressDeprecationWarnings = test._oldSupress;
10311
10312 if (test._expectedDeprecations != null) {
10313 var missedDeprecations = [];
10314 each(test._expectedDeprecations, function (deprecationPattern, id) {
10315 if (test._observedDeprecations[id] !== 1) {
10316 missedDeprecations.push(deprecationPattern);
10317 }
10318 });
10319 if (missedDeprecations.length !== 0) {
10320 throw new Error('Expected deprecation warnings did not happen: ' +
10321 missedDeprecations.join(' '));
10322 }
10323 }
10324 }
10325
10326 function matchedDeprecation(name, msg, deprecations) {
10327 if (deprecations == null) {
10328 return -1;
10329 }
10330 for (var i = 0; i < deprecations.length; ++i) {
10331 if (name != null && name === deprecations[i]) {
10332 return i;
10333 }
10334 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
10335 return i;
10336 }
10337 }
10338 return -1;
10339 }
10340
10341 /*global QUnit:false*/
10342
10343 var test = QUnit.test;
10344
db71a655
KM
10345 function objectKeys(obj) {
10346 if (Object.keys) {
10347 return Object.keys(obj);
10348 } else {
10349 // IE8
10350 var res = [], i;
10351 for (i in obj) {
10352 if (obj.hasOwnProperty(i)) {
10353 res.push(i);
10354 }
b135bf1a 10355 }
db71a655 10356 return res;
b135bf1a 10357 }
b135bf1a
IC
10358 }
10359
db71a655 10360 // Pick the first defined of two or three arguments.
b135bf1a 10361
db71a655
KM
10362 function defineCommonLocaleTests(locale, options) {
10363 test('lenient day of month ordinal parsing', function (assert) {
10364 var i, ordinalStr, testMoment;
10365 for (i = 1; i <= 31; ++i) {
10366 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
10367 testMoment = moment(ordinalStr, 'YYYY MM Do');
10368 assert.equal(testMoment.year(), 2014,
10369 'lenient day of month ordinal parsing ' + i + ' year check');
10370 assert.equal(testMoment.month(), 0,
10371 'lenient day of month ordinal parsing ' + i + ' month check');
10372 assert.equal(testMoment.date(), i,
10373 'lenient day of month ordinal parsing ' + i + ' date check');
10374 }
10375 });
b135bf1a 10376
db71a655
KM
10377 test('lenient day of month ordinal parsing of number', function (assert) {
10378 var i, testMoment;
10379 for (i = 1; i <= 31; ++i) {
10380 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
10381 assert.equal(testMoment.year(), 2014,
10382 'lenient day of month ordinal parsing of number ' + i + ' year check');
10383 assert.equal(testMoment.month(), 0,
10384 'lenient day of month ordinal parsing of number ' + i + ' month check');
10385 assert.equal(testMoment.date(), i,
10386 'lenient day of month ordinal parsing of number ' + i + ' date check');
10387 }
10388 });
b135bf1a 10389
db71a655
KM
10390 test('strict day of month ordinal parsing', function (assert) {
10391 var i, ordinalStr, testMoment;
10392 for (i = 1; i <= 31; ++i) {
10393 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
10394 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
10395 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
10396 }
10397 });
b135bf1a 10398
db71a655
KM
10399 test('meridiem invariant', function (assert) {
10400 var h, m, t1, t2;
10401 for (h = 0; h < 24; ++h) {
10402 for (m = 0; m < 60; m += 15) {
10403 t1 = moment.utc([2000, 0, 1, h, m]);
10404 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
10405 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
10406 'meridiem at ' + t1.format('HH:mm'));
10407 }
10408 }
10409 });
10410
10411 test('date format correctness', function (assert) {
10412 var data, tokens;
10413 data = moment.localeData()._longDateFormat;
10414 tokens = objectKeys(data);
10415 each(tokens, function (srchToken) {
10416 // Check each format string to make sure it does not contain any
10417 // tokens that need to be expanded.
10418 each(tokens, function (baseToken) {
10419 // strip escaped sequences
10420 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
10421 assert.equal(false, !!~format.indexOf(srchToken),
10422 'contains ' + srchToken + ' in ' + baseToken);
10423 });
b135bf1a
IC
10424 });
10425 });
d6651c21 10426
db71a655
KM
10427 test('month parsing correctness', function (assert) {
10428 var i, m;
10429
10430 if (locale === 'tr') {
10431 // I can't fix it :(
c58511b9 10432 assert.expect(0);
db71a655
KM
10433 return;
10434 }
10435 function tester(format) {
10436 var r;
10437 r = moment(m.format(format), format);
10438 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
10439 if (locale !== 'ka') {
10440 r = moment(m.format(format).toLocaleUpperCase(), format);
10441 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
10442 }
db71a655
KM
10443 r = moment(m.format(format).toLocaleLowerCase(), format);
10444 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
10445
10446 r = moment(m.format(format), format, true);
10447 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
10448 if (locale !== 'ka') {
10449 r = moment(m.format(format).toLocaleUpperCase(), format, true);
10450 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
10451 }
db71a655
KM
10452 r = moment(m.format(format).toLocaleLowerCase(), format, true);
10453 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
10454 }
10455
10456 for (i = 0; i < 12; ++i) {
10457 m = moment([2015, i, 15, 18]);
10458 tester('MMM');
10459 tester('MMM.');
10460 tester('MMMM');
10461 tester('MMMM.');
10462 }
10463 });
d6651c21 10464
db71a655
KM
10465 test('weekday parsing correctness', function (assert) {
10466 var i, m;
10467
96d0d679 10468 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
10469 // tr, az: There is a lower-case letter (ı), that converted to
10470 // upper then lower changes to i
10471 // ro: there is the letter ț which behaves weird under IE8
10472 // mt: letter Ħ
96d0d679 10473 // ga: month with spaces
c58511b9 10474 assert.expect(0);
db71a655
KM
10475 return;
10476 }
10477 function tester(format) {
10478 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
10479 r = moment(m.format(format), format);
10480 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
10481 if (locale !== 'ka') {
10482 r = moment(m.format(format).toLocaleUpperCase(), format);
10483 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
10484 }
db71a655
KM
10485 r = moment(m.format(format).toLocaleLowerCase(), format);
10486 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
10487 r = moment(m.format(format), format, true);
10488 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
10489 if (locale !== 'ka') {
10490 r = moment(m.format(format).toLocaleUpperCase(), format, true);
10491 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
10492 }
db71a655
KM
10493 r = moment(m.format(format).toLocaleLowerCase(), format, true);
10494 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
10495 }
10496
10497 for (i = 0; i < 7; ++i) {
10498 m = moment.utc([2015, 0, i + 1, 18]);
10499 tester('dd');
10500 tester('ddd');
10501 tester('dddd');
10502 }
10503 });
d6651c21 10504
db71a655
KM
10505 test('valid localeData', function (assert) {
10506 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
10507 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
10508 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
10509 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
10510 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
10511 });
96d0d679
KM
10512
10513 test('localeData weekdays can localeSort', function (assert) {
10514 var weekdays = moment().localeData().weekdays();
10515 var weekdaysShort = moment().localeData().weekdaysShort();
10516 var weekdaysMin = moment().localeData().weekdaysMin();
10517 var shift = moment().localeData()._week.dow;
10518 assert.deepEqual(
10519 moment().localeData().weekdays(true),
10520 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
10521 'weekdays should localeSort');
10522 assert.deepEqual(
10523 moment().localeData().weekdaysShort(true),
10524 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
10525 'weekdaysShort should localeSort');
10526 assert.deepEqual(
10527 moment().localeData().weekdaysMin(true),
10528 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
10529 'weekdaysMin should localeSort');
10530 });
db71a655 10531 }
d6651c21 10532
db71a655 10533 /*global QUnit:false*/
516f5f67 10534
db71a655
KM
10535 function localeModule (name, lifecycle) {
10536 QUnit.module('locale:' + name, {
c58511b9 10537 beforeEach : function () {
db71a655
KM
10538 moment.locale(name);
10539 moment.createFromInputFallback = function (config) {
10540 throw new Error('input not handled by moment: ' + config._i);
10541 };
10542 setupDeprecationHandler(test, moment, 'locale');
10543 if (lifecycle && lifecycle.setup) {
10544 lifecycle.setup();
10545 }
10546 },
c58511b9 10547 afterEach : function () {
db71a655
KM
10548 moment.locale('en');
10549 teardownDeprecationHandler(test, moment, 'locale');
10550 if (lifecycle && lifecycle.teardown) {
10551 lifecycle.teardown();
10552 }
516f5f67
IC
10553 }
10554 });
db71a655
KM
10555 defineCommonLocaleTests(name, -1, -1);
10556 }
10557
10558 localeModule('da');
10559
10560 test('parse', function (assert) {
10561 var tests = 'januar jan_februar feb_marts mar_april apr_maj maj_juni jun_juli jul_august aug_september sep_oktober okt_november nov_december dec'.split('_'), i;
10562 function equalTest(input, mmm, i) {
10563 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
10564 }
10565 for (i = 0; i < 12; i++) {
10566 tests[i] = tests[i].split(' ');
10567 equalTest(tests[i][0], 'MMM', i);
10568 equalTest(tests[i][1], 'MMM', i);
10569 equalTest(tests[i][0], 'MMMM', i);
10570 equalTest(tests[i][1], 'MMMM', i);
10571 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
10572 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
10573 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
10574 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
10575 }
10576 });
10577
10578 test('format', function (assert) {
10579 var a = [
10580 ['dddd [den] Do MMMM YYYY, h:mm:ss a', 'søndag den 14. februar 2010, 3:25:50 pm'],
10581 ['ddd hA', 'søn 3PM'],
10582 ['M Mo MM MMMM MMM', '2 2. 02 februar feb'],
10583 ['YYYY YY', '2010 10'],
10584 ['D Do DD', '14 14. 14'],
10585 ['d do dddd ddd dd', '0 0. søndag søn sø'],
10586 ['DDD DDDo DDDD', '45 45. 045'],
10587 ['w wo ww', '6 6. 06'],
10588 ['h hh', '3 03'],
10589 ['H HH', '15 15'],
10590 ['m mm', '25 25'],
10591 ['s ss', '50 50'],
10592 ['a A', 'pm PM'],
10593 ['[den] DDDo [dag på året]', 'den 45. dag på året'],
10594 ['LTS', '15:25:50'],
10595 ['L', '14.02.2010'],
10596 ['LL', '14. februar 2010'],
10597 ['LLL', '14. februar 2010 15:25'],
10598 ['LLLL', 'søndag d. 14. februar 2010 kl. 15:25'],
10599 ['l', '14.2.2010'],
10600 ['ll', '14. feb 2010'],
10601 ['lll', '14. feb 2010 15:25'],
10602 ['llll', 'søn d. 14. feb 2010 kl. 15:25']
10603 ],
10604 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
10605 i;
10606 for (i = 0; i < a.length; i++) {
10607 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
10608 }
10609 });
10610
10611 test('format ordinal', function (assert) {
10612 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
10613 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
10614 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
10615 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
10616 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
10617 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
10618 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
10619 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
10620 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
10621 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
10622
10623 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
10624 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
10625 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
10626 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
10627 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
10628 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
10629 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
10630 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
10631 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
10632 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
10633
10634 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
10635 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
10636 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
10637 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
10638 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
10639 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
10640 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
10641 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
10642 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
10643 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
10644
10645 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
10646 });
10647
10648 test('format month', function (assert) {
10649 var expected = 'januar jan_februar feb_marts mar_april apr_maj maj_juni jun_juli jul_august aug_september sep_oktober okt_november nov_december dec'.split('_'), i;
10650 for (i = 0; i < expected.length; i++) {
10651 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
10652 }
10653 });
10654
10655 test('format week', function (assert) {
10656 var expected = 'søndag søn sø_mandag man ma_tirsdag tir ti_onsdag ons on_torsdag tor to_fredag fre fr_lørdag lør lø'.split('_'), i;
10657 for (i = 0; i < expected.length; i++) {
10658 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
10659 }
10660 });
10661
10662 test('from', function (assert) {
10663 var start = moment([2007, 1, 28]);
10664 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'få sekunder', '44 seconds = a few seconds');
10665 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'et minut', '45 seconds = a minute');
10666 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'et minut', '89 seconds = a minute');
10667 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutter', '90 seconds = 2 minutes');
10668 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutter', '44 minutes = 44 minutes');
10669 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'en time', '45 minutes = an hour');
10670 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'en time', '89 minutes = an hour');
10671 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 timer', '90 minutes = 2 hours');
10672 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 timer', '5 hours = 5 hours');
10673 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 timer', '21 hours = 21 hours');
10674 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'en dag', '22 hours = a day');
10675 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'en dag', '35 hours = a day');
10676 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dage', '36 hours = 2 days');
10677 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'en dag', '1 day = a day');
10678 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dage', '5 days = 5 days');
10679 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dage', '25 days = 25 days');
10680 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'en måned', '26 days = a month');
10681 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'en måned', '30 days = a month');
10682 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'en måned', '43 days = a month');
10683 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 måneder', '46 days = 2 months');
10684 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 måneder', '75 days = 2 months');
10685 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 måneder', '76 days = 3 months');
10686 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'en måned', '1 month = a month');
10687 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 måneder', '5 months = 5 months');
10688 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'et år', '345 days = a year');
10689 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 år', '548 days = 2 years');
10690 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'et år', '1 year = a year');
10691 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 år', '5 years = 5 years');
10692 });
10693
10694 test('suffix', function (assert) {
10695 assert.equal(moment(30000).from(0), 'om få sekunder', 'prefix');
10696 assert.equal(moment(0).from(30000), 'få sekunder siden', 'suffix');
10697 });
10698
10699 test('now from now', function (assert) {
10700 assert.equal(moment().fromNow(), 'få sekunder siden', 'now from now should display as in the past');
10701 });
10702
10703 test('fromNow', function (assert) {
10704 assert.equal(moment().add({s: 30}).fromNow(), 'om få sekunder', 'in a few seconds');
10705 assert.equal(moment().add({d: 5}).fromNow(), 'om 5 dage', 'in 5 days');
10706 });
10707
10708
10709 test('calendar day', function (assert) {
10710 var a = moment().hours(12).minutes(0).seconds(0);
10711
10712 assert.equal(moment(a).calendar(), 'i dag kl. 12:00', 'today at the same time');
10713 assert.equal(moment(a).add({m: 25}).calendar(), 'i dag kl. 12:25', 'Now plus 25 min');
10714 assert.equal(moment(a).add({h: 1}).calendar(), 'i dag kl. 13:00', 'Now plus 1 hour');
10715 assert.equal(moment(a).add({d: 1}).calendar(), 'i morgen kl. 12:00', 'tomorrow at the same time');
10716 assert.equal(moment(a).subtract({h: 1}).calendar(), 'i dag kl. 11:00', 'Now minus 1 hour');
10717 assert.equal(moment(a).subtract({d: 1}).calendar(), 'i går kl. 12:00', 'yesterday at the same time');
10718 });
10719
10720 test('calendar next week', function (assert) {
10721 var i, m;
516f5f67 10722
db71a655
KM
10723 for (i = 2; i < 7; i++) {
10724 m = moment().add({d: i});
10725 assert.equal(m.calendar(), m.format('på dddd [kl.] LT'), 'Today + ' + i + ' days current time');
10726 m.hours(0).minutes(0).seconds(0).milliseconds(0);
10727 assert.equal(m.calendar(), m.format('på dddd [kl.] LT'), 'Today + ' + i + ' days beginning of day');
10728 m.hours(23).minutes(59).seconds(59).milliseconds(999);
10729 assert.equal(m.calendar(), m.format('på dddd [kl.] LT'), 'Today + ' + i + ' days end of day');
d6651c21 10730 }
db71a655
KM
10731 });
10732
10733 test('calendar last week', function (assert) {
10734 var i, m;
10735
10736 for (i = 2; i < 7; i++) {
10737 m = moment().subtract({d: i});
10738 assert.equal(m.calendar(), m.format('[i] dddd[s kl.] LT'), 'Today - ' + i + ' days current time');
10739 m.hours(0).minutes(0).seconds(0).milliseconds(0);
10740 assert.equal(m.calendar(), m.format('[i] dddd[s kl.] LT'), 'Today - ' + i + ' days beginning of day');
10741 m.hours(23).minutes(59).seconds(59).milliseconds(999);
10742 assert.equal(m.calendar(), m.format('[i] dddd[s kl.] LT'), 'Today - ' + i + ' days end of day');
d6651c21 10743 }
db71a655 10744 });
d6651c21 10745
db71a655
KM
10746 test('calendar all else', function (assert) {
10747 var weeksAgo = moment().subtract({w: 1}),
10748 weeksFromNow = moment().add({w: 1});
d6651c21 10749
db71a655
KM
10750 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
10751 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
d6651c21 10752
db71a655
KM
10753 weeksAgo = moment().subtract({w: 2});
10754 weeksFromNow = moment().add({w: 2});
d6651c21 10755
db71a655
KM
10756 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
10757 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
10758 });
10759
10760 test('weeks year starting sunday formatted', function (assert) {
10761 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
10762 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
10763 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
10764 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
10765 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
10766 });
73f3c911
IC
10767
10768})));
10769
516f5f67 10770
c74a101d
IC
10771;(function (global, factory) {
10772 typeof exports === 'object' && typeof module !== 'undefined'
10773 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
10774 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
10775 factory(global.moment)
73f3c911 10776}(this, (function (moment) { 'use strict';
516f5f67 10777
db71a655
KM
10778 function each(array, callback) {
10779 var i;
10780 for (i = 0; i < array.length; i++) {
10781 callback(array[i], i, array);
10782 }
b135bf1a
IC
10783 }
10784
c58511b9
KM
10785 function setupDeprecationHandler(test, moment$$1, scope) {
10786 test._expectedDeprecations = null;
10787 test._observedDeprecations = null;
10788 test._oldSupress = moment$$1.suppressDeprecationWarnings;
10789 moment$$1.suppressDeprecationWarnings = true;
10790 test.expectedDeprecations = function () {
10791 test._expectedDeprecations = arguments;
10792 test._observedDeprecations = [];
10793 };
10794 moment$$1.deprecationHandler = function (name, msg) {
10795 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
10796 if (deprecationId === -1) {
10797 throw new Error('Unexpected deprecation thrown name=' +
10798 name + ' msg=' + msg);
10799 }
10800 test._observedDeprecations[deprecationId] = 1;
10801 };
10802 }
10803
10804 function teardownDeprecationHandler(test, moment$$1, scope) {
10805 moment$$1.suppressDeprecationWarnings = test._oldSupress;
10806
10807 if (test._expectedDeprecations != null) {
10808 var missedDeprecations = [];
10809 each(test._expectedDeprecations, function (deprecationPattern, id) {
10810 if (test._observedDeprecations[id] !== 1) {
10811 missedDeprecations.push(deprecationPattern);
10812 }
10813 });
10814 if (missedDeprecations.length !== 0) {
10815 throw new Error('Expected deprecation warnings did not happen: ' +
10816 missedDeprecations.join(' '));
10817 }
10818 }
10819 }
10820
10821 function matchedDeprecation(name, msg, deprecations) {
10822 if (deprecations == null) {
10823 return -1;
10824 }
10825 for (var i = 0; i < deprecations.length; ++i) {
10826 if (name != null && name === deprecations[i]) {
10827 return i;
10828 }
10829 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
10830 return i;
10831 }
10832 }
10833 return -1;
10834 }
10835
10836 /*global QUnit:false*/
10837
10838 var test = QUnit.test;
10839
db71a655
KM
10840 function objectKeys(obj) {
10841 if (Object.keys) {
10842 return Object.keys(obj);
10843 } else {
10844 // IE8
10845 var res = [], i;
10846 for (i in obj) {
10847 if (obj.hasOwnProperty(i)) {
10848 res.push(i);
10849 }
b135bf1a 10850 }
db71a655 10851 return res;
b135bf1a
IC
10852 }
10853 }
b135bf1a 10854
db71a655 10855 // Pick the first defined of two or three arguments.
b135bf1a 10856
db71a655
KM
10857 function defineCommonLocaleTests(locale, options) {
10858 test('lenient day of month ordinal parsing', function (assert) {
10859 var i, ordinalStr, testMoment;
10860 for (i = 1; i <= 31; ++i) {
10861 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
10862 testMoment = moment(ordinalStr, 'YYYY MM Do');
10863 assert.equal(testMoment.year(), 2014,
10864 'lenient day of month ordinal parsing ' + i + ' year check');
10865 assert.equal(testMoment.month(), 0,
10866 'lenient day of month ordinal parsing ' + i + ' month check');
10867 assert.equal(testMoment.date(), i,
10868 'lenient day of month ordinal parsing ' + i + ' date check');
10869 }
10870 });
b135bf1a 10871
db71a655
KM
10872 test('lenient day of month ordinal parsing of number', function (assert) {
10873 var i, testMoment;
10874 for (i = 1; i <= 31; ++i) {
10875 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
10876 assert.equal(testMoment.year(), 2014,
10877 'lenient day of month ordinal parsing of number ' + i + ' year check');
10878 assert.equal(testMoment.month(), 0,
10879 'lenient day of month ordinal parsing of number ' + i + ' month check');
10880 assert.equal(testMoment.date(), i,
10881 'lenient day of month ordinal parsing of number ' + i + ' date check');
10882 }
b135bf1a 10883 });
d6651c21 10884
db71a655
KM
10885 test('strict day of month ordinal parsing', function (assert) {
10886 var i, ordinalStr, testMoment;
10887 for (i = 1; i <= 31; ++i) {
10888 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
10889 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
10890 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
10891 }
10892 });
d6651c21 10893
db71a655
KM
10894 test('meridiem invariant', function (assert) {
10895 var h, m, t1, t2;
10896 for (h = 0; h < 24; ++h) {
10897 for (m = 0; m < 60; m += 15) {
10898 t1 = moment.utc([2000, 0, 1, h, m]);
10899 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
10900 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
10901 'meridiem at ' + t1.format('HH:mm'));
10902 }
10903 }
10904 });
d6651c21 10905
db71a655
KM
10906 test('date format correctness', function (assert) {
10907 var data, tokens;
10908 data = moment.localeData()._longDateFormat;
10909 tokens = objectKeys(data);
10910 each(tokens, function (srchToken) {
10911 // Check each format string to make sure it does not contain any
10912 // tokens that need to be expanded.
10913 each(tokens, function (baseToken) {
10914 // strip escaped sequences
10915 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
10916 assert.equal(false, !!~format.indexOf(srchToken),
10917 'contains ' + srchToken + ' in ' + baseToken);
10918 });
10919 });
10920 });
d6651c21 10921
db71a655
KM
10922 test('month parsing correctness', function (assert) {
10923 var i, m;
10924
10925 if (locale === 'tr') {
10926 // I can't fix it :(
c58511b9 10927 assert.expect(0);
db71a655
KM
10928 return;
10929 }
10930 function tester(format) {
10931 var r;
10932 r = moment(m.format(format), format);
10933 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
10934 if (locale !== 'ka') {
10935 r = moment(m.format(format).toLocaleUpperCase(), format);
10936 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
10937 }
db71a655
KM
10938 r = moment(m.format(format).toLocaleLowerCase(), format);
10939 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
10940
10941 r = moment(m.format(format), format, true);
10942 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
10943 if (locale !== 'ka') {
10944 r = moment(m.format(format).toLocaleUpperCase(), format, true);
10945 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
10946 }
db71a655
KM
10947 r = moment(m.format(format).toLocaleLowerCase(), format, true);
10948 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
10949 }
10950
10951 for (i = 0; i < 12; ++i) {
10952 m = moment([2015, i, 15, 18]);
10953 tester('MMM');
10954 tester('MMM.');
10955 tester('MMMM');
10956 tester('MMMM.');
10957 }
10958 });
d6651c21 10959
db71a655
KM
10960 test('weekday parsing correctness', function (assert) {
10961 var i, m;
10962
96d0d679 10963 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
10964 // tr, az: There is a lower-case letter (ı), that converted to
10965 // upper then lower changes to i
10966 // ro: there is the letter ț which behaves weird under IE8
10967 // mt: letter Ħ
96d0d679 10968 // ga: month with spaces
c58511b9 10969 assert.expect(0);
db71a655
KM
10970 return;
10971 }
10972 function tester(format) {
10973 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
10974 r = moment(m.format(format), format);
10975 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
10976 if (locale !== 'ka') {
10977 r = moment(m.format(format).toLocaleUpperCase(), format);
10978 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
10979 }
db71a655
KM
10980 r = moment(m.format(format).toLocaleLowerCase(), format);
10981 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
10982 r = moment(m.format(format), format, true);
10983 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
10984 if (locale !== 'ka') {
10985 r = moment(m.format(format).toLocaleUpperCase(), format, true);
10986 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
10987 }
db71a655
KM
10988 r = moment(m.format(format).toLocaleLowerCase(), format, true);
10989 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
10990 }
10991
10992 for (i = 0; i < 7; ++i) {
10993 m = moment.utc([2015, 0, i + 1, 18]);
10994 tester('dd');
10995 tester('ddd');
10996 tester('dddd');
10997 }
10998 });
73f3c911 10999
db71a655
KM
11000 test('valid localeData', function (assert) {
11001 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
11002 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
11003 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
11004 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
11005 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
11006 });
96d0d679
KM
11007
11008 test('localeData weekdays can localeSort', function (assert) {
11009 var weekdays = moment().localeData().weekdays();
11010 var weekdaysShort = moment().localeData().weekdaysShort();
11011 var weekdaysMin = moment().localeData().weekdaysMin();
11012 var shift = moment().localeData()._week.dow;
11013 assert.deepEqual(
11014 moment().localeData().weekdays(true),
11015 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
11016 'weekdays should localeSort');
11017 assert.deepEqual(
11018 moment().localeData().weekdaysShort(true),
11019 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
11020 'weekdaysShort should localeSort');
11021 assert.deepEqual(
11022 moment().localeData().weekdaysMin(true),
11023 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
11024 'weekdaysMin should localeSort');
11025 });
db71a655 11026 }
b135bf1a 11027
db71a655 11028 /*global QUnit:false*/
73f3c911 11029
db71a655
KM
11030 function localeModule (name, lifecycle) {
11031 QUnit.module('locale:' + name, {
c58511b9 11032 beforeEach : function () {
db71a655
KM
11033 moment.locale(name);
11034 moment.createFromInputFallback = function (config) {
11035 throw new Error('input not handled by moment: ' + config._i);
11036 };
11037 setupDeprecationHandler(test, moment, 'locale');
11038 if (lifecycle && lifecycle.setup) {
11039 lifecycle.setup();
11040 }
11041 },
c58511b9 11042 afterEach : function () {
db71a655
KM
11043 moment.locale('en');
11044 teardownDeprecationHandler(test, moment, 'locale');
11045 if (lifecycle && lifecycle.teardown) {
11046 lifecycle.teardown();
11047 }
73f3c911 11048 }
db71a655
KM
11049 });
11050 defineCommonLocaleTests(name, -1, -1);
11051 }
11052
11053 localeModule('de-at');
11054
11055 test('parse', function (assert) {
11056 var tests = 'Jänner Jän._Februar Feb._März März_April Apr._Mai Mai_Juni Juni_Juli Juli_August Aug._September Sep._Oktober Okt._November Nov._Dezember Dez.'.split('_'), i;
11057
11058 function equalTest(input, mmm, i) {
11059 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
11060 }
11061
11062 for (i = 0; i < 12; i++) {
11063 tests[i] = tests[i].split(' ');
11064 equalTest(tests[i][0], 'MMM', i);
11065 equalTest(tests[i][1], 'MMM', i);
11066 equalTest(tests[i][0], 'MMMM', i);
11067 equalTest(tests[i][1], 'MMMM', i);
11068 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
11069 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
11070 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
11071 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
11072 }
11073 });
11074
11075 test('format', function (assert) {
11076 var a = [
11077 ['dddd, Do MMMM YYYY, h:mm:ss a', 'Sonntag, 14. Februar 2010, 3:25:50 pm'],
11078 ['ddd, hA', 'So., 3PM'],
11079 ['M Mo MM MMMM MMM', '2 2. 02 Februar Feb.'],
11080 ['YYYY YY', '2010 10'],
11081 ['D Do DD', '14 14. 14'],
11082 ['d do dddd ddd dd', '0 0. Sonntag So. So'],
11083 ['DDD DDDo DDDD', '45 45. 045'],
11084 ['w wo ww', '6 6. 06'],
11085 ['h hh', '3 03'],
11086 ['H HH', '15 15'],
11087 ['m mm', '25 25'],
11088 ['s ss', '50 50'],
11089 ['a A', 'pm PM'],
11090 ['[the] DDDo [day of the year]', 'the 45. day of the year'],
11091 ['LTS', '15:25:50'],
11092 ['L', '14.02.2010'],
11093 ['LL', '14. Februar 2010'],
11094 ['LLL', '14. Februar 2010 15:25'],
11095 ['LLLL', 'Sonntag, 14. Februar 2010 15:25'],
11096 ['l', '14.2.2010'],
11097 ['ll', '14. Feb. 2010'],
11098 ['lll', '14. Feb. 2010 15:25'],
11099 ['llll', 'So., 14. Feb. 2010 15:25']
11100 ],
11101 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
11102 i;
11103 for (i = 0; i < a.length; i++) {
11104 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
11105 }
11106 });
11107
11108 test('format ordinal', function (assert) {
11109 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
11110 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
11111 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
11112 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
11113 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
11114 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
11115 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
11116 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
11117 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
11118 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
11119
11120 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
11121 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
11122 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
11123 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
11124 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
11125 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
11126 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
11127 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
11128 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
11129 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
11130
11131 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
11132 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
11133 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
11134 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
11135 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
11136 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
11137 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
11138 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
11139 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
11140 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
11141
11142 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
11143 });
11144
11145 test('format month', function (assert) {
11146 var expected = 'Jänner Jän._Februar Feb._März März_April Apr._Mai Mai_Juni Juni_Juli Juli_August Aug._September Sep._Oktober Okt._November Nov._Dezember Dez.'.split('_'), i;
11147 for (i = 0; i < expected.length; i++) {
11148 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
11149 }
11150 });
11151
11152 test('format week', function (assert) {
11153 var expected = 'Sonntag So. So_Montag Mo. Mo_Dienstag Di. Di_Mittwoch Mi. Mi_Donnerstag Do. Do_Freitag Fr. Fr_Samstag Sa. Sa'.split('_'), i;
11154 for (i = 0; i < expected.length; i++) {
11155 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
11156 }
11157 });
11158
11159 test('from', function (assert) {
11160 var start = moment([2007, 1, 28]);
11161 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ein paar Sekunden', '44 seconds = a few seconds');
11162 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'eine Minute', '45 seconds = a minute');
11163 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'eine Minute', '89 seconds = a minute');
11164 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 Minuten', '90 seconds = 2 minutes');
11165 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 Minuten', '44 minutes = 44 minutes');
11166 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'eine Stunde', '45 minutes = an hour');
11167 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'eine Stunde', '89 minutes = an hour');
11168 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 Stunden', '90 minutes = 2 hours');
11169 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 Stunden', '5 hours = 5 hours');
11170 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 Stunden', '21 hours = 21 hours');
11171 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ein Tag', '22 hours = a day');
11172 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ein Tag', '35 hours = a day');
11173 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 Tage', '36 hours = 2 days');
11174 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ein Tag', '1 day = a day');
11175 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 Tage', '5 days = 5 days');
11176 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 Tage', '25 days = 25 days');
11177 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ein Monat', '26 days = a month');
11178 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ein Monat', '30 days = a month');
11179 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 Monate', '46 days = 2 months');
11180 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 Monate', '75 days = 2 months');
11181 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 Monate', '76 days = 3 months');
11182 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ein Monat', '1 month = a month');
11183 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 Monate', '5 months = 5 months');
11184 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ein Jahr', '345 days = a year');
11185 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 Jahre', '548 days = 2 years');
11186 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ein Jahr', '1 year = a year');
11187 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 Jahre', '5 years = 5 years');
11188 });
11189
11190 test('suffix', function (assert) {
11191 assert.equal(moment(30000).from(0), 'in ein paar Sekunden', 'prefix');
11192 assert.equal(moment(0).from(30000), 'vor ein paar Sekunden', 'suffix');
11193 });
11194
11195 test('fromNow', function (assert) {
11196 assert.equal(moment().add({s: 30}).fromNow(), 'in ein paar Sekunden', 'in a few seconds');
11197 assert.equal(moment().add({d: 5}).fromNow(), 'in 5 Tagen', 'in 5 days');
11198 });
11199
11200 test('calendar day', function (assert) {
11201 var a = moment().hours(12).minutes(0).seconds(0);
11202
11203 assert.equal(moment(a).calendar(), 'heute um 12:00 Uhr', 'today at the same time');
11204 assert.equal(moment(a).add({m: 25}).calendar(), 'heute um 12:25 Uhr', 'Now plus 25 min');
11205 assert.equal(moment(a).add({h: 1}).calendar(), 'heute um 13:00 Uhr', 'Now plus 1 hour');
11206 assert.equal(moment(a).add({d: 1}).calendar(), 'morgen um 12:00 Uhr', 'tomorrow at the same time');
11207 assert.equal(moment(a).subtract({h: 1}).calendar(), 'heute um 11:00 Uhr', 'Now minus 1 hour');
11208 assert.equal(moment(a).subtract({d: 1}).calendar(), 'gestern um 12:00 Uhr', 'yesterday at the same time');
11209 });
11210
11211 test('calendar next week', function (assert) {
11212 var i, m;
11213 for (i = 2; i < 7; i++) {
11214 m = moment().add({d: i});
11215 assert.equal(m.calendar(), m.format('dddd [um] LT [Uhr]'), 'Today + ' + i + ' days current time');
11216 m.hours(0).minutes(0).seconds(0).milliseconds(0);
11217 assert.equal(m.calendar(), m.format('dddd [um] LT [Uhr]'), 'Today + ' + i + ' days beginning of day');
11218 m.hours(23).minutes(59).seconds(59).milliseconds(999);
11219 assert.equal(m.calendar(), m.format('dddd [um] LT [Uhr]'), 'Today + ' + i + ' days end of day');
516f5f67
IC
11220 }
11221 });
11222
db71a655
KM
11223 test('calendar last week', function (assert) {
11224 var i, m;
11225 for (i = 2; i < 7; i++) {
11226 m = moment().subtract({d: i});
11227 assert.equal(m.calendar(), m.format('[letzten] dddd [um] LT [Uhr]'), 'Today + ' + i + ' days current time');
11228 m.hours(0).minutes(0).seconds(0).milliseconds(0);
11229 assert.equal(m.calendar(), m.format('[letzten] dddd [um] LT [Uhr]'), 'Today + ' + i + ' days beginning of day');
11230 m.hours(23).minutes(59).seconds(59).milliseconds(999);
11231 assert.equal(m.calendar(), m.format('[letzten] dddd [um] LT [Uhr]'), 'Today + ' + i + ' days end of day');
11232 }
11233 });
516f5f67 11234
db71a655
KM
11235 test('calendar all else', function (assert) {
11236 var weeksAgo = moment().subtract({w: 1}),
11237 weeksFromNow = moment().add({w: 1});
516f5f67 11238
db71a655
KM
11239 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
11240 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 11241
db71a655
KM
11242 weeksAgo = moment().subtract({w: 2});
11243 weeksFromNow = moment().add({w: 2});
516f5f67 11244
db71a655
KM
11245 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
11246 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
11247 });
11248
11249 test('weeks year starting sunday formatted', function (assert) {
11250 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
11251 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
11252 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
11253 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
11254 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
11255 });
73f3c911
IC
11256
11257})));
516f5f67 11258
516f5f67 11259
c74a101d
IC
11260;(function (global, factory) {
11261 typeof exports === 'object' && typeof module !== 'undefined'
11262 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
11263 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
11264 factory(global.moment)
73f3c911 11265}(this, (function (moment) { 'use strict';
516f5f67 11266
db71a655
KM
11267 function each(array, callback) {
11268 var i;
11269 for (i = 0; i < array.length; i++) {
11270 callback(array[i], i, array);
11271 }
b135bf1a
IC
11272 }
11273
c58511b9
KM
11274 function setupDeprecationHandler(test, moment$$1, scope) {
11275 test._expectedDeprecations = null;
11276 test._observedDeprecations = null;
11277 test._oldSupress = moment$$1.suppressDeprecationWarnings;
11278 moment$$1.suppressDeprecationWarnings = true;
11279 test.expectedDeprecations = function () {
11280 test._expectedDeprecations = arguments;
11281 test._observedDeprecations = [];
11282 };
11283 moment$$1.deprecationHandler = function (name, msg) {
11284 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
11285 if (deprecationId === -1) {
11286 throw new Error('Unexpected deprecation thrown name=' +
11287 name + ' msg=' + msg);
11288 }
11289 test._observedDeprecations[deprecationId] = 1;
11290 };
11291 }
11292
11293 function teardownDeprecationHandler(test, moment$$1, scope) {
11294 moment$$1.suppressDeprecationWarnings = test._oldSupress;
11295
11296 if (test._expectedDeprecations != null) {
11297 var missedDeprecations = [];
11298 each(test._expectedDeprecations, function (deprecationPattern, id) {
11299 if (test._observedDeprecations[id] !== 1) {
11300 missedDeprecations.push(deprecationPattern);
11301 }
11302 });
11303 if (missedDeprecations.length !== 0) {
11304 throw new Error('Expected deprecation warnings did not happen: ' +
11305 missedDeprecations.join(' '));
11306 }
11307 }
11308 }
11309
11310 function matchedDeprecation(name, msg, deprecations) {
11311 if (deprecations == null) {
11312 return -1;
11313 }
11314 for (var i = 0; i < deprecations.length; ++i) {
11315 if (name != null && name === deprecations[i]) {
11316 return i;
11317 }
11318 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
11319 return i;
11320 }
11321 }
11322 return -1;
11323 }
11324
11325 /*global QUnit:false*/
11326
11327 var test = QUnit.test;
11328
db71a655
KM
11329 function objectKeys(obj) {
11330 if (Object.keys) {
11331 return Object.keys(obj);
11332 } else {
11333 // IE8
11334 var res = [], i;
11335 for (i in obj) {
11336 if (obj.hasOwnProperty(i)) {
11337 res.push(i);
11338 }
b135bf1a 11339 }
db71a655 11340 return res;
b135bf1a 11341 }
b135bf1a
IC
11342 }
11343
db71a655 11344 // Pick the first defined of two or three arguments.
b135bf1a 11345
db71a655
KM
11346 function defineCommonLocaleTests(locale, options) {
11347 test('lenient day of month ordinal parsing', function (assert) {
11348 var i, ordinalStr, testMoment;
11349 for (i = 1; i <= 31; ++i) {
11350 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
11351 testMoment = moment(ordinalStr, 'YYYY MM Do');
11352 assert.equal(testMoment.year(), 2014,
11353 'lenient day of month ordinal parsing ' + i + ' year check');
11354 assert.equal(testMoment.month(), 0,
11355 'lenient day of month ordinal parsing ' + i + ' month check');
11356 assert.equal(testMoment.date(), i,
11357 'lenient day of month ordinal parsing ' + i + ' date check');
11358 }
11359 });
b135bf1a 11360
db71a655
KM
11361 test('lenient day of month ordinal parsing of number', function (assert) {
11362 var i, testMoment;
11363 for (i = 1; i <= 31; ++i) {
11364 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
11365 assert.equal(testMoment.year(), 2014,
11366 'lenient day of month ordinal parsing of number ' + i + ' year check');
11367 assert.equal(testMoment.month(), 0,
11368 'lenient day of month ordinal parsing of number ' + i + ' month check');
11369 assert.equal(testMoment.date(), i,
11370 'lenient day of month ordinal parsing of number ' + i + ' date check');
11371 }
11372 });
b135bf1a 11373
db71a655
KM
11374 test('strict day of month ordinal parsing', function (assert) {
11375 var i, ordinalStr, testMoment;
11376 for (i = 1; i <= 31; ++i) {
11377 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
11378 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
11379 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
11380 }
11381 });
b135bf1a 11382
db71a655
KM
11383 test('meridiem invariant', function (assert) {
11384 var h, m, t1, t2;
11385 for (h = 0; h < 24; ++h) {
11386 for (m = 0; m < 60; m += 15) {
11387 t1 = moment.utc([2000, 0, 1, h, m]);
11388 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
11389 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
11390 'meridiem at ' + t1.format('HH:mm'));
11391 }
11392 }
11393 });
11394
11395 test('date format correctness', function (assert) {
11396 var data, tokens;
11397 data = moment.localeData()._longDateFormat;
11398 tokens = objectKeys(data);
11399 each(tokens, function (srchToken) {
11400 // Check each format string to make sure it does not contain any
11401 // tokens that need to be expanded.
11402 each(tokens, function (baseToken) {
11403 // strip escaped sequences
11404 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
11405 assert.equal(false, !!~format.indexOf(srchToken),
11406 'contains ' + srchToken + ' in ' + baseToken);
11407 });
b135bf1a
IC
11408 });
11409 });
d6651c21 11410
db71a655
KM
11411 test('month parsing correctness', function (assert) {
11412 var i, m;
11413
11414 if (locale === 'tr') {
11415 // I can't fix it :(
c58511b9 11416 assert.expect(0);
db71a655
KM
11417 return;
11418 }
11419 function tester(format) {
11420 var r;
11421 r = moment(m.format(format), format);
11422 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
11423 if (locale !== 'ka') {
11424 r = moment(m.format(format).toLocaleUpperCase(), format);
11425 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
11426 }
db71a655
KM
11427 r = moment(m.format(format).toLocaleLowerCase(), format);
11428 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
11429
11430 r = moment(m.format(format), format, true);
11431 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
11432 if (locale !== 'ka') {
11433 r = moment(m.format(format).toLocaleUpperCase(), format, true);
11434 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
11435 }
db71a655
KM
11436 r = moment(m.format(format).toLocaleLowerCase(), format, true);
11437 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
11438 }
11439
11440 for (i = 0; i < 12; ++i) {
11441 m = moment([2015, i, 15, 18]);
11442 tester('MMM');
11443 tester('MMM.');
11444 tester('MMMM');
11445 tester('MMMM.');
11446 }
11447 });
d6651c21 11448
db71a655
KM
11449 test('weekday parsing correctness', function (assert) {
11450 var i, m;
11451
96d0d679 11452 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
11453 // tr, az: There is a lower-case letter (ı), that converted to
11454 // upper then lower changes to i
11455 // ro: there is the letter ț which behaves weird under IE8
11456 // mt: letter Ħ
96d0d679 11457 // ga: month with spaces
c58511b9 11458 assert.expect(0);
db71a655
KM
11459 return;
11460 }
11461 function tester(format) {
11462 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
11463 r = moment(m.format(format), format);
11464 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
11465 if (locale !== 'ka') {
11466 r = moment(m.format(format).toLocaleUpperCase(), format);
11467 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
11468 }
db71a655
KM
11469 r = moment(m.format(format).toLocaleLowerCase(), format);
11470 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
11471 r = moment(m.format(format), format, true);
11472 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
11473 if (locale !== 'ka') {
11474 r = moment(m.format(format).toLocaleUpperCase(), format, true);
11475 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
11476 }
db71a655
KM
11477 r = moment(m.format(format).toLocaleLowerCase(), format, true);
11478 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
11479 }
11480
11481 for (i = 0; i < 7; ++i) {
11482 m = moment.utc([2015, 0, i + 1, 18]);
11483 tester('dd');
11484 tester('ddd');
11485 tester('dddd');
11486 }
11487 });
d6651c21 11488
db71a655
KM
11489 test('valid localeData', function (assert) {
11490 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
11491 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
11492 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
11493 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
11494 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
11495 });
96d0d679
KM
11496
11497 test('localeData weekdays can localeSort', function (assert) {
11498 var weekdays = moment().localeData().weekdays();
11499 var weekdaysShort = moment().localeData().weekdaysShort();
11500 var weekdaysMin = moment().localeData().weekdaysMin();
11501 var shift = moment().localeData()._week.dow;
11502 assert.deepEqual(
11503 moment().localeData().weekdays(true),
11504 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
11505 'weekdays should localeSort');
11506 assert.deepEqual(
11507 moment().localeData().weekdaysShort(true),
11508 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
11509 'weekdaysShort should localeSort');
11510 assert.deepEqual(
11511 moment().localeData().weekdaysMin(true),
11512 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
11513 'weekdaysMin should localeSort');
11514 });
db71a655 11515 }
d6651c21 11516
db71a655
KM
11517 /*global QUnit:false*/
11518
db71a655
KM
11519 function localeModule (name, lifecycle) {
11520 QUnit.module('locale:' + name, {
c58511b9 11521 beforeEach : function () {
db71a655
KM
11522 moment.locale(name);
11523 moment.createFromInputFallback = function (config) {
11524 throw new Error('input not handled by moment: ' + config._i);
11525 };
11526 setupDeprecationHandler(test, moment, 'locale');
11527 if (lifecycle && lifecycle.setup) {
11528 lifecycle.setup();
11529 }
11530 },
c58511b9 11531 afterEach : function () {
db71a655
KM
11532 moment.locale('en');
11533 teardownDeprecationHandler(test, moment, 'locale');
11534 if (lifecycle && lifecycle.teardown) {
11535 lifecycle.teardown();
11536 }
516f5f67
IC
11537 }
11538 });
db71a655
KM
11539 defineCommonLocaleTests(name, -1, -1);
11540 }
11541
11542 localeModule('de-ch');
11543
11544 test('parse', function (assert) {
11545 var tests = 'Januar Jan._Februar Feb._März März_April Apr._Mai Mai_Juni Juni_Juli Juli_August Aug._September Sep._Oktober Okt._November Nov._Dezember Dez.'.split('_'), i;
11546 function equalTest(input, mmm, i) {
11547 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
11548 }
11549 for (i = 0; i < 12; i++) {
11550 tests[i] = tests[i].split(' ');
11551 equalTest(tests[i][0], 'MMM', i);
11552 equalTest(tests[i][1], 'MMM', i);
11553 equalTest(tests[i][0], 'MMMM', i);
11554 equalTest(tests[i][1], 'MMMM', i);
11555 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
11556 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
11557 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
11558 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
11559 }
11560 });
11561
11562 test('format', function (assert) {
11563 var a = [
11564 ['dddd, Do MMMM YYYY, h:mm:ss a', 'Sonntag, 14. Februar 2010, 3:25:50 pm'],
11565 ['ddd, hA', 'So, 3PM'],
11566 ['M Mo MM MMMM MMM', '2 2. 02 Februar Feb.'],
11567 ['YYYY YY', '2010 10'],
11568 ['D Do DD', '14 14. 14'],
11569 ['d do dddd ddd dd', '0 0. Sonntag So So'],
11570 ['DDD DDDo DDDD', '45 45. 045'],
11571 ['w wo ww', '6 6. 06'],
11572 ['h hh', '3 03'],
11573 ['H HH', '15 15'],
11574 ['m mm', '25 25'],
11575 ['s ss', '50 50'],
11576 ['a A', 'pm PM'],
11577 ['[the] DDDo [day of the year]', 'the 45. day of the year'],
11578 ['LT', '15:25'],
11579 ['LTS', '15:25:50'],
11580 ['L', '14.02.2010'],
11581 ['LL', '14. Februar 2010'],
11582 ['LLL', '14. Februar 2010 15:25'],
11583 ['LLLL', 'Sonntag, 14. Februar 2010 15:25'],
11584 ['l', '14.2.2010'],
11585 ['ll', '14. Feb. 2010'],
11586 ['lll', '14. Feb. 2010 15:25'],
11587 ['llll', 'So, 14. Feb. 2010 15:25']
11588 ],
11589 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
11590 i;
11591 for (i = 0; i < a.length; i++) {
11592 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
11593 }
11594 });
11595
11596 test('format ordinal', function (assert) {
11597 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
11598 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
11599 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
11600 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
11601 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
11602 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
11603 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
11604 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
11605 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
11606 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
11607
11608 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
11609 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
11610 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
11611 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
11612 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
11613 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
11614 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
11615 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
11616 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
11617 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
11618
11619 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
11620 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
11621 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
11622 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
11623 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
11624 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
11625 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
11626 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
11627 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
11628 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
11629
11630 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
11631 });
11632
11633 test('format month', function (assert) {
11634 var expected = 'Januar Jan._Februar Feb._März März_April Apr._Mai Mai_Juni Juni_Juli Juli_August Aug._September Sep._Oktober Okt._November Nov._Dezember Dez.'.split('_'), i;
11635 for (i = 0; i < expected.length; i++) {
11636 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
11637 }
11638 });
11639
11640 test('format week', function (assert) {
11641 var expected = 'Sonntag So So_Montag Mo Mo_Dienstag Di Di_Mittwoch Mi Mi_Donnerstag Do Do_Freitag Fr Fr_Samstag Sa Sa'.split('_'), i;
11642 for (i = 0; i < expected.length; i++) {
11643 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
11644 }
11645 });
11646
11647 test('from', function (assert) {
11648 var start = moment([2007, 1, 28]);
11649 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ein paar Sekunden', '44 seconds = a few seconds');
11650 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'eine Minute', '45 seconds = a minute');
11651 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'eine Minute', '89 seconds = a minute');
11652 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 Minuten', '90 seconds = 2 minutes');
11653 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 Minuten', '44 minutes = 44 minutes');
11654 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'eine Stunde', '45 minutes = an hour');
11655 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'eine Stunde', '89 minutes = an hour');
11656 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 Stunden', '90 minutes = 2 hours');
11657 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 Stunden', '5 hours = 5 hours');
11658 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 Stunden', '21 hours = 21 hours');
11659 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ein Tag', '22 hours = a day');
11660 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ein Tag', '35 hours = a day');
11661 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 Tage', '36 hours = 2 days');
11662 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ein Tag', '1 day = a day');
11663 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 Tage', '5 days = 5 days');
11664 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 Tage', '25 days = 25 days');
11665 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ein Monat', '26 days = a month');
11666 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ein Monat', '30 days = a month');
11667 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ein Monat', '43 days = a month');
11668 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 Monate', '46 days = 2 months');
11669 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 Monate', '75 days = 2 months');
11670 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 Monate', '76 days = 3 months');
11671 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ein Monat', '1 month = a month');
11672 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 Monate', '5 months = 5 months');
11673 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ein Jahr', '345 days = a year');
11674 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 Jahre', '548 days = 2 years');
11675 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ein Jahr', '1 year = a year');
11676 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 Jahre', '5 years = 5 years');
11677 });
11678
11679 test('suffix', function (assert) {
11680 assert.equal(moment(30000).from(0), 'in ein paar Sekunden', 'prefix');
11681 assert.equal(moment(0).from(30000), 'vor ein paar Sekunden', 'suffix');
11682 });
11683
11684 test('fromNow', function (assert) {
11685 assert.equal(moment().add({s: 30}).fromNow(), 'in ein paar Sekunden', 'in a few seconds');
11686 assert.equal(moment().add({d: 5}).fromNow(), 'in 5 Tagen', 'in 5 days');
11687 });
11688
11689 test('calendar day', function (assert) {
11690 var a = moment().hours(12).minutes(0).seconds(0);
11691
11692 assert.equal(moment(a).calendar(), 'heute um 12:00 Uhr', 'today at the same time');
11693 assert.equal(moment(a).add({m: 25}).calendar(), 'heute um 12:25 Uhr', 'Now plus 25 min');
11694 assert.equal(moment(a).add({h: 1}).calendar(), 'heute um 13:00 Uhr', 'Now plus 1 hour');
11695 assert.equal(moment(a).add({d: 1}).calendar(), 'morgen um 12:00 Uhr', 'tomorrow at the same time');
11696 assert.equal(moment(a).subtract({h: 1}).calendar(), 'heute um 11:00 Uhr', 'Now minus 1 hour');
11697 assert.equal(moment(a).subtract({d: 1}).calendar(), 'gestern um 12:00 Uhr', 'yesterday at the same time');
11698 });
11699
11700 test('calendar next week', function (assert) {
11701 var i, m;
11702 for (i = 2; i < 7; i++) {
11703 m = moment().add({d: i});
11704 assert.equal(m.calendar(), m.format('dddd [um] LT [Uhr]'), 'Today + ' + i + ' days current time');
11705 m.hours(0).minutes(0).seconds(0).milliseconds(0);
11706 assert.equal(m.calendar(), m.format('dddd [um] LT [Uhr]'), 'Today + ' + i + ' days beginning of day');
11707 m.hours(23).minutes(59).seconds(59).milliseconds(999);
11708 assert.equal(m.calendar(), m.format('dddd [um] LT [Uhr]'), 'Today + ' + i + ' days end of day');
73f3c911 11709 }
db71a655 11710 });
516f5f67 11711
db71a655
KM
11712 test('calendar last week', function (assert) {
11713 var i, m;
11714 for (i = 2; i < 7; i++) {
11715 m = moment().subtract({d: i});
11716 assert.equal(m.calendar(), m.format('[letzten] dddd [um] LT [Uhr]'), 'Today + ' + i + ' days current time');
11717 m.hours(0).minutes(0).seconds(0).milliseconds(0);
11718 assert.equal(m.calendar(), m.format('[letzten] dddd [um] LT [Uhr]'), 'Today + ' + i + ' days beginning of day');
11719 m.hours(23).minutes(59).seconds(59).milliseconds(999);
11720 assert.equal(m.calendar(), m.format('[letzten] dddd [um] LT [Uhr]'), 'Today + ' + i + ' days end of day');
516f5f67 11721 }
db71a655 11722 });
516f5f67 11723
db71a655
KM
11724 test('calendar all else', function (assert) {
11725 var weeksAgo = moment().subtract({w: 1}),
11726 weeksFromNow = moment().add({w: 1});
516f5f67 11727
db71a655
KM
11728 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
11729 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 11730
db71a655
KM
11731 weeksAgo = moment().subtract({w: 2});
11732 weeksFromNow = moment().add({w: 2});
516f5f67 11733
db71a655
KM
11734 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
11735 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
11736 });
11737
11738 test('weeks year starting sunday formatted', function (assert) {
11739 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
11740 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
11741 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
11742 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
11743 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
11744 });
73f3c911
IC
11745
11746})));
11747
516f5f67 11748
c74a101d
IC
11749;(function (global, factory) {
11750 typeof exports === 'object' && typeof module !== 'undefined'
11751 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
11752 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
11753 factory(global.moment)
73f3c911 11754}(this, (function (moment) { 'use strict';
516f5f67 11755
db71a655
KM
11756 function each(array, callback) {
11757 var i;
11758 for (i = 0; i < array.length; i++) {
11759 callback(array[i], i, array);
11760 }
b135bf1a
IC
11761 }
11762
c58511b9
KM
11763 function setupDeprecationHandler(test, moment$$1, scope) {
11764 test._expectedDeprecations = null;
11765 test._observedDeprecations = null;
11766 test._oldSupress = moment$$1.suppressDeprecationWarnings;
11767 moment$$1.suppressDeprecationWarnings = true;
11768 test.expectedDeprecations = function () {
11769 test._expectedDeprecations = arguments;
11770 test._observedDeprecations = [];
11771 };
11772 moment$$1.deprecationHandler = function (name, msg) {
11773 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
11774 if (deprecationId === -1) {
11775 throw new Error('Unexpected deprecation thrown name=' +
11776 name + ' msg=' + msg);
11777 }
11778 test._observedDeprecations[deprecationId] = 1;
11779 };
11780 }
11781
11782 function teardownDeprecationHandler(test, moment$$1, scope) {
11783 moment$$1.suppressDeprecationWarnings = test._oldSupress;
11784
11785 if (test._expectedDeprecations != null) {
11786 var missedDeprecations = [];
11787 each(test._expectedDeprecations, function (deprecationPattern, id) {
11788 if (test._observedDeprecations[id] !== 1) {
11789 missedDeprecations.push(deprecationPattern);
11790 }
11791 });
11792 if (missedDeprecations.length !== 0) {
11793 throw new Error('Expected deprecation warnings did not happen: ' +
11794 missedDeprecations.join(' '));
11795 }
11796 }
11797 }
11798
11799 function matchedDeprecation(name, msg, deprecations) {
11800 if (deprecations == null) {
11801 return -1;
11802 }
11803 for (var i = 0; i < deprecations.length; ++i) {
11804 if (name != null && name === deprecations[i]) {
11805 return i;
11806 }
11807 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
11808 return i;
11809 }
11810 }
11811 return -1;
11812 }
11813
11814 /*global QUnit:false*/
11815
11816 var test = QUnit.test;
11817
db71a655
KM
11818 function objectKeys(obj) {
11819 if (Object.keys) {
11820 return Object.keys(obj);
11821 } else {
11822 // IE8
11823 var res = [], i;
11824 for (i in obj) {
11825 if (obj.hasOwnProperty(i)) {
11826 res.push(i);
11827 }
b135bf1a 11828 }
db71a655 11829 return res;
b135bf1a
IC
11830 }
11831 }
11832
db71a655 11833 // Pick the first defined of two or three arguments.
73f3c911 11834
db71a655
KM
11835 function defineCommonLocaleTests(locale, options) {
11836 test('lenient day of month ordinal parsing', function (assert) {
11837 var i, ordinalStr, testMoment;
11838 for (i = 1; i <= 31; ++i) {
11839 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
11840 testMoment = moment(ordinalStr, 'YYYY MM Do');
11841 assert.equal(testMoment.year(), 2014,
11842 'lenient day of month ordinal parsing ' + i + ' year check');
11843 assert.equal(testMoment.month(), 0,
11844 'lenient day of month ordinal parsing ' + i + ' month check');
11845 assert.equal(testMoment.date(), i,
11846 'lenient day of month ordinal parsing ' + i + ' date check');
11847 }
11848 });
73f3c911 11849
db71a655
KM
11850 test('lenient day of month ordinal parsing of number', function (assert) {
11851 var i, testMoment;
11852 for (i = 1; i <= 31; ++i) {
11853 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
11854 assert.equal(testMoment.year(), 2014,
11855 'lenient day of month ordinal parsing of number ' + i + ' year check');
11856 assert.equal(testMoment.month(), 0,
11857 'lenient day of month ordinal parsing of number ' + i + ' month check');
11858 assert.equal(testMoment.date(), i,
11859 'lenient day of month ordinal parsing of number ' + i + ' date check');
11860 }
11861 });
b135bf1a 11862
db71a655
KM
11863 test('strict day of month ordinal parsing', function (assert) {
11864 var i, ordinalStr, testMoment;
11865 for (i = 1; i <= 31; ++i) {
11866 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
11867 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
11868 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
11869 }
11870 });
b135bf1a 11871
db71a655
KM
11872 test('meridiem invariant', function (assert) {
11873 var h, m, t1, t2;
11874 for (h = 0; h < 24; ++h) {
11875 for (m = 0; m < 60; m += 15) {
11876 t1 = moment.utc([2000, 0, 1, h, m]);
11877 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
11878 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
11879 'meridiem at ' + t1.format('HH:mm'));
11880 }
11881 }
11882 });
11883
11884 test('date format correctness', function (assert) {
11885 var data, tokens;
11886 data = moment.localeData()._longDateFormat;
11887 tokens = objectKeys(data);
11888 each(tokens, function (srchToken) {
11889 // Check each format string to make sure it does not contain any
11890 // tokens that need to be expanded.
11891 each(tokens, function (baseToken) {
11892 // strip escaped sequences
11893 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
11894 assert.equal(false, !!~format.indexOf(srchToken),
11895 'contains ' + srchToken + ' in ' + baseToken);
11896 });
73f3c911 11897 });
b135bf1a
IC
11898 });
11899
db71a655
KM
11900 test('month parsing correctness', function (assert) {
11901 var i, m;
11902
11903 if (locale === 'tr') {
11904 // I can't fix it :(
c58511b9 11905 assert.expect(0);
db71a655
KM
11906 return;
11907 }
11908 function tester(format) {
11909 var r;
11910 r = moment(m.format(format), format);
11911 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
11912 if (locale !== 'ka') {
11913 r = moment(m.format(format).toLocaleUpperCase(), format);
11914 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
11915 }
db71a655
KM
11916 r = moment(m.format(format).toLocaleLowerCase(), format);
11917 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
11918
11919 r = moment(m.format(format), format, true);
11920 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
11921 if (locale !== 'ka') {
11922 r = moment(m.format(format).toLocaleUpperCase(), format, true);
11923 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
11924 }
db71a655
KM
11925 r = moment(m.format(format).toLocaleLowerCase(), format, true);
11926 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
11927 }
11928
11929 for (i = 0; i < 12; ++i) {
11930 m = moment([2015, i, 15, 18]);
11931 tester('MMM');
11932 tester('MMM.');
11933 tester('MMMM');
11934 tester('MMMM.');
11935 }
11936 });
d6651c21 11937
db71a655
KM
11938 test('weekday parsing correctness', function (assert) {
11939 var i, m;
11940
96d0d679 11941 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
11942 // tr, az: There is a lower-case letter (ı), that converted to
11943 // upper then lower changes to i
11944 // ro: there is the letter ț which behaves weird under IE8
11945 // mt: letter Ħ
96d0d679 11946 // ga: month with spaces
c58511b9 11947 assert.expect(0);
db71a655
KM
11948 return;
11949 }
11950 function tester(format) {
11951 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
11952 r = moment(m.format(format), format);
11953 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
11954 if (locale !== 'ka') {
11955 r = moment(m.format(format).toLocaleUpperCase(), format);
11956 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
11957 }
db71a655
KM
11958 r = moment(m.format(format).toLocaleLowerCase(), format);
11959 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
11960 r = moment(m.format(format), format, true);
11961 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
11962 if (locale !== 'ka') {
11963 r = moment(m.format(format).toLocaleUpperCase(), format, true);
11964 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
11965 }
db71a655
KM
11966 r = moment(m.format(format).toLocaleLowerCase(), format, true);
11967 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
11968 }
11969
11970 for (i = 0; i < 7; ++i) {
11971 m = moment.utc([2015, 0, i + 1, 18]);
11972 tester('dd');
11973 tester('ddd');
11974 tester('dddd');
11975 }
11976 });
d6651c21 11977
db71a655
KM
11978 test('valid localeData', function (assert) {
11979 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
11980 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
11981 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
11982 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
11983 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
11984 });
96d0d679
KM
11985
11986 test('localeData weekdays can localeSort', function (assert) {
11987 var weekdays = moment().localeData().weekdays();
11988 var weekdaysShort = moment().localeData().weekdaysShort();
11989 var weekdaysMin = moment().localeData().weekdaysMin();
11990 var shift = moment().localeData()._week.dow;
11991 assert.deepEqual(
11992 moment().localeData().weekdays(true),
11993 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
11994 'weekdays should localeSort');
11995 assert.deepEqual(
11996 moment().localeData().weekdaysShort(true),
11997 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
11998 'weekdaysShort should localeSort');
11999 assert.deepEqual(
12000 moment().localeData().weekdaysMin(true),
12001 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
12002 'weekdaysMin should localeSort');
12003 });
db71a655 12004 }
d6651c21 12005
db71a655 12006 /*global QUnit:false*/
516f5f67 12007
db71a655
KM
12008 function localeModule (name, lifecycle) {
12009 QUnit.module('locale:' + name, {
c58511b9 12010 beforeEach : function () {
db71a655
KM
12011 moment.locale(name);
12012 moment.createFromInputFallback = function (config) {
12013 throw new Error('input not handled by moment: ' + config._i);
12014 };
12015 setupDeprecationHandler(test, moment, 'locale');
12016 if (lifecycle && lifecycle.setup) {
12017 lifecycle.setup();
12018 }
12019 },
c58511b9 12020 afterEach : function () {
db71a655
KM
12021 moment.locale('en');
12022 teardownDeprecationHandler(test, moment, 'locale');
12023 if (lifecycle && lifecycle.teardown) {
12024 lifecycle.teardown();
12025 }
516f5f67
IC
12026 }
12027 });
db71a655
KM
12028 defineCommonLocaleTests(name, -1, -1);
12029 }
12030
12031 localeModule('de');
12032
12033 test('parse', function (assert) {
12034 var tests = 'Januar Jan._Februar Feb._März März_April Apr._Mai Mai_Juni Juni_Juli Juli_August Aug._September Sep._Oktober Okt._November Nov._Dezember Dez.'.split('_'), i;
12035 function equalTest(input, mmm, i) {
12036 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
12037 }
12038 for (i = 0; i < 12; i++) {
12039 tests[i] = tests[i].split(' ');
12040 equalTest(tests[i][0], 'MMM', i);
12041 equalTest(tests[i][1], 'MMM', i);
12042 equalTest(tests[i][0], 'MMMM', i);
12043 equalTest(tests[i][1], 'MMMM', i);
12044 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
12045 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
12046 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
12047 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
12048 }
12049 });
12050
12051 test('format', function (assert) {
12052 var a = [
12053 ['dddd, Do MMMM YYYY, h:mm:ss a', 'Sonntag, 14. Februar 2010, 3:25:50 pm'],
12054 ['ddd, hA', 'So., 3PM'],
12055 ['M Mo MM MMMM MMM', '2 2. 02 Februar Feb.'],
12056 ['YYYY YY', '2010 10'],
12057 ['D Do DD', '14 14. 14'],
12058 ['d do dddd ddd dd', '0 0. Sonntag So. So'],
12059 ['DDD DDDo DDDD', '45 45. 045'],
12060 ['w wo ww', '6 6. 06'],
12061 ['h hh', '3 03'],
12062 ['H HH', '15 15'],
12063 ['m mm', '25 25'],
12064 ['s ss', '50 50'],
12065 ['a A', 'pm PM'],
12066 ['[the] DDDo [day of the year]', 'the 45. day of the year'],
12067 ['LTS', '15:25:50'],
12068 ['L', '14.02.2010'],
12069 ['LL', '14. Februar 2010'],
12070 ['LLL', '14. Februar 2010 15:25'],
12071 ['LLLL', 'Sonntag, 14. Februar 2010 15:25'],
12072 ['l', '14.2.2010'],
12073 ['ll', '14. Feb. 2010'],
12074 ['lll', '14. Feb. 2010 15:25'],
12075 ['llll', 'So., 14. Feb. 2010 15:25']
12076 ],
12077 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
12078 i;
12079 for (i = 0; i < a.length; i++) {
12080 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
12081 }
12082 });
12083
12084 test('format ordinal', function (assert) {
12085 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
12086 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
12087 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
12088 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
12089 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
12090 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
12091 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
12092 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
12093 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
12094 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
12095
12096 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
12097 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
12098 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
12099 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
12100 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
12101 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
12102 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
12103 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
12104 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
12105 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
12106
12107 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
12108 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
12109 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
12110 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
12111 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
12112 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
12113 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
12114 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
12115 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
12116 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
12117
12118 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
12119 });
12120
12121 test('format month', function (assert) {
12122 var expected = 'Januar Jan._Februar Feb._März März_April Apr._Mai Mai_Juni Juni_Juli Juli_August Aug._September Sep._Oktober Okt._November Nov._Dezember Dez.'.split('_'), i;
12123 for (i = 0; i < expected.length; i++) {
12124 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
12125 }
12126 });
12127
12128 test('format week', function (assert) {
12129 var expected = 'Sonntag So. So_Montag Mo. Mo_Dienstag Di. Di_Mittwoch Mi. Mi_Donnerstag Do. Do_Freitag Fr. Fr_Samstag Sa. Sa'.split('_'), i;
12130 for (i = 0; i < expected.length; i++) {
12131 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
12132 }
12133 });
12134
12135 test('from', function (assert) {
12136 var start = moment([2007, 1, 28]);
12137 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ein paar Sekunden', '44 seconds = a few seconds');
12138 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'eine Minute', '45 seconds = a minute');
12139 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'eine Minute', '89 seconds = a minute');
12140 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 Minuten', '90 seconds = 2 minutes');
12141 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 Minuten', '44 minutes = 44 minutes');
12142 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'eine Stunde', '45 minutes = an hour');
12143 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'eine Stunde', '89 minutes = an hour');
12144 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 Stunden', '90 minutes = 2 hours');
12145 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 Stunden', '5 hours = 5 hours');
12146 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 Stunden', '21 hours = 21 hours');
12147 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ein Tag', '22 hours = a day');
12148 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ein Tag', '35 hours = a day');
12149 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 Tage', '36 hours = 2 days');
12150 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ein Tag', '1 day = a day');
12151 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 Tage', '5 days = 5 days');
12152 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 Tage', '25 days = 25 days');
12153 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ein Monat', '26 days = a month');
12154 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ein Monat', '30 days = a month');
12155 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ein Monat', '43 days = a month');
12156 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 Monate', '46 days = 2 months');
12157 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 Monate', '75 days = 2 months');
12158 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 Monate', '76 days = 3 months');
12159 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ein Monat', '1 month = a month');
12160 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 Monate', '5 months = 5 months');
12161 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ein Jahr', '345 days = a year');
12162 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 Jahre', '548 days = 2 years');
12163 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ein Jahr', '1 year = a year');
12164 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 Jahre', '5 years = 5 years');
12165 });
12166
12167 test('suffix', function (assert) {
12168 assert.equal(moment(30000).from(0), 'in ein paar Sekunden', 'prefix');
12169 assert.equal(moment(0).from(30000), 'vor ein paar Sekunden', 'suffix');
12170 });
12171
12172 test('fromNow', function (assert) {
12173 assert.equal(moment().add({s: 30}).fromNow(), 'in ein paar Sekunden', 'in a few seconds');
12174 assert.equal(moment().add({d: 5}).fromNow(), 'in 5 Tagen', 'in 5 days');
12175 });
12176
12177 test('calendar day', function (assert) {
12178 var a = moment().hours(12).minutes(0).seconds(0);
12179
12180 assert.equal(moment(a).calendar(), 'heute um 12:00 Uhr', 'today at the same time');
12181 assert.equal(moment(a).add({m: 25}).calendar(), 'heute um 12:25 Uhr', 'Now plus 25 min');
12182 assert.equal(moment(a).add({h: 1}).calendar(), 'heute um 13:00 Uhr', 'Now plus 1 hour');
12183 assert.equal(moment(a).add({d: 1}).calendar(), 'morgen um 12:00 Uhr', 'tomorrow at the same time');
12184 assert.equal(moment(a).subtract({h: 1}).calendar(), 'heute um 11:00 Uhr', 'Now minus 1 hour');
12185 assert.equal(moment(a).subtract({d: 1}).calendar(), 'gestern um 12:00 Uhr', 'yesterday at the same time');
12186 });
12187
12188 test('calendar next week', function (assert) {
12189 var i, m;
12190 for (i = 2; i < 7; i++) {
12191 m = moment().add({d: i});
12192 assert.equal(m.calendar(), m.format('dddd [um] LT [Uhr]'), 'Today + ' + i + ' days current time');
12193 m.hours(0).minutes(0).seconds(0).milliseconds(0);
12194 assert.equal(m.calendar(), m.format('dddd [um] LT [Uhr]'), 'Today + ' + i + ' days beginning of day');
12195 m.hours(23).minutes(59).seconds(59).milliseconds(999);
12196 assert.equal(m.calendar(), m.format('dddd [um] LT [Uhr]'), 'Today + ' + i + ' days end of day');
73f3c911 12197 }
db71a655 12198 });
516f5f67 12199
db71a655
KM
12200 test('calendar last week', function (assert) {
12201 var i, m;
12202 for (i = 2; i < 7; i++) {
12203 m = moment().subtract({d: i});
12204 assert.equal(m.calendar(), m.format('[letzten] dddd [um] LT [Uhr]'), 'Today + ' + i + ' days current time');
12205 m.hours(0).minutes(0).seconds(0).milliseconds(0);
12206 assert.equal(m.calendar(), m.format('[letzten] dddd [um] LT [Uhr]'), 'Today + ' + i + ' days beginning of day');
12207 m.hours(23).minutes(59).seconds(59).milliseconds(999);
12208 assert.equal(m.calendar(), m.format('[letzten] dddd [um] LT [Uhr]'), 'Today + ' + i + ' days end of day');
73f3c911 12209 }
db71a655 12210 });
c74a101d 12211
db71a655
KM
12212 test('calendar all else', function (assert) {
12213 var weeksAgo = moment().subtract({w: 1}),
12214 weeksFromNow = moment().add({w: 1});
c74a101d 12215
db71a655
KM
12216 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
12217 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
c74a101d 12218
db71a655
KM
12219 weeksAgo = moment().subtract({w: 2});
12220 weeksFromNow = moment().add({w: 2});
c74a101d 12221
db71a655
KM
12222 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
12223 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
12224 });
12225
12226 test('weeks year starting sunday formatted', function (assert) {
12227 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
12228 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
12229 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
12230 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
12231 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
12232 });
73f3c911
IC
12233
12234})));
d6651c21 12235
c74a101d
IC
12236
12237;(function (global, factory) {
12238 typeof exports === 'object' && typeof module !== 'undefined'
12239 && typeof require === 'function' ? factory(require('../../moment')) :
12240 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
12241 factory(global.moment)
73f3c911 12242}(this, (function (moment) { 'use strict';
c74a101d 12243
db71a655
KM
12244 function each(array, callback) {
12245 var i;
12246 for (i = 0; i < array.length; i++) {
12247 callback(array[i], i, array);
12248 }
b135bf1a
IC
12249 }
12250
c58511b9
KM
12251 function setupDeprecationHandler(test, moment$$1, scope) {
12252 test._expectedDeprecations = null;
12253 test._observedDeprecations = null;
12254 test._oldSupress = moment$$1.suppressDeprecationWarnings;
12255 moment$$1.suppressDeprecationWarnings = true;
12256 test.expectedDeprecations = function () {
12257 test._expectedDeprecations = arguments;
12258 test._observedDeprecations = [];
12259 };
12260 moment$$1.deprecationHandler = function (name, msg) {
12261 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
12262 if (deprecationId === -1) {
12263 throw new Error('Unexpected deprecation thrown name=' +
12264 name + ' msg=' + msg);
12265 }
12266 test._observedDeprecations[deprecationId] = 1;
12267 };
12268 }
12269
12270 function teardownDeprecationHandler(test, moment$$1, scope) {
12271 moment$$1.suppressDeprecationWarnings = test._oldSupress;
12272
12273 if (test._expectedDeprecations != null) {
12274 var missedDeprecations = [];
12275 each(test._expectedDeprecations, function (deprecationPattern, id) {
12276 if (test._observedDeprecations[id] !== 1) {
12277 missedDeprecations.push(deprecationPattern);
12278 }
12279 });
12280 if (missedDeprecations.length !== 0) {
12281 throw new Error('Expected deprecation warnings did not happen: ' +
12282 missedDeprecations.join(' '));
12283 }
12284 }
12285 }
12286
12287 function matchedDeprecation(name, msg, deprecations) {
12288 if (deprecations == null) {
12289 return -1;
12290 }
12291 for (var i = 0; i < deprecations.length; ++i) {
12292 if (name != null && name === deprecations[i]) {
12293 return i;
12294 }
12295 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
12296 return i;
12297 }
12298 }
12299 return -1;
12300 }
12301
12302 /*global QUnit:false*/
12303
12304 var test = QUnit.test;
12305
db71a655
KM
12306 function objectKeys(obj) {
12307 if (Object.keys) {
12308 return Object.keys(obj);
12309 } else {
12310 // IE8
12311 var res = [], i;
12312 for (i in obj) {
12313 if (obj.hasOwnProperty(i)) {
12314 res.push(i);
12315 }
b135bf1a 12316 }
db71a655 12317 return res;
b135bf1a 12318 }
b135bf1a
IC
12319 }
12320
db71a655 12321 // Pick the first defined of two or three arguments.
b135bf1a 12322
db71a655
KM
12323 function defineCommonLocaleTests(locale, options) {
12324 test('lenient day of month ordinal parsing', function (assert) {
12325 var i, ordinalStr, testMoment;
12326 for (i = 1; i <= 31; ++i) {
12327 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
12328 testMoment = moment(ordinalStr, 'YYYY MM Do');
12329 assert.equal(testMoment.year(), 2014,
12330 'lenient day of month ordinal parsing ' + i + ' year check');
12331 assert.equal(testMoment.month(), 0,
12332 'lenient day of month ordinal parsing ' + i + ' month check');
12333 assert.equal(testMoment.date(), i,
12334 'lenient day of month ordinal parsing ' + i + ' date check');
12335 }
12336 });
b135bf1a 12337
db71a655
KM
12338 test('lenient day of month ordinal parsing of number', function (assert) {
12339 var i, testMoment;
12340 for (i = 1; i <= 31; ++i) {
12341 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
12342 assert.equal(testMoment.year(), 2014,
12343 'lenient day of month ordinal parsing of number ' + i + ' year check');
12344 assert.equal(testMoment.month(), 0,
12345 'lenient day of month ordinal parsing of number ' + i + ' month check');
12346 assert.equal(testMoment.date(), i,
12347 'lenient day of month ordinal parsing of number ' + i + ' date check');
12348 }
12349 });
b135bf1a 12350
db71a655
KM
12351 test('strict day of month ordinal parsing', function (assert) {
12352 var i, ordinalStr, testMoment;
12353 for (i = 1; i <= 31; ++i) {
12354 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
12355 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
12356 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
12357 }
12358 });
b135bf1a 12359
db71a655
KM
12360 test('meridiem invariant', function (assert) {
12361 var h, m, t1, t2;
12362 for (h = 0; h < 24; ++h) {
12363 for (m = 0; m < 60; m += 15) {
12364 t1 = moment.utc([2000, 0, 1, h, m]);
12365 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
12366 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
12367 'meridiem at ' + t1.format('HH:mm'));
12368 }
12369 }
12370 });
12371
12372 test('date format correctness', function (assert) {
12373 var data, tokens;
12374 data = moment.localeData()._longDateFormat;
12375 tokens = objectKeys(data);
12376 each(tokens, function (srchToken) {
12377 // Check each format string to make sure it does not contain any
12378 // tokens that need to be expanded.
12379 each(tokens, function (baseToken) {
12380 // strip escaped sequences
12381 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
12382 assert.equal(false, !!~format.indexOf(srchToken),
12383 'contains ' + srchToken + ' in ' + baseToken);
12384 });
b135bf1a
IC
12385 });
12386 });
d6651c21 12387
db71a655
KM
12388 test('month parsing correctness', function (assert) {
12389 var i, m;
12390
12391 if (locale === 'tr') {
12392 // I can't fix it :(
c58511b9 12393 assert.expect(0);
db71a655
KM
12394 return;
12395 }
12396 function tester(format) {
12397 var r;
12398 r = moment(m.format(format), format);
12399 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
12400 if (locale !== 'ka') {
12401 r = moment(m.format(format).toLocaleUpperCase(), format);
12402 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
12403 }
db71a655
KM
12404 r = moment(m.format(format).toLocaleLowerCase(), format);
12405 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
12406
12407 r = moment(m.format(format), format, true);
12408 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
12409 if (locale !== 'ka') {
12410 r = moment(m.format(format).toLocaleUpperCase(), format, true);
12411 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
12412 }
db71a655
KM
12413 r = moment(m.format(format).toLocaleLowerCase(), format, true);
12414 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
12415 }
12416
12417 for (i = 0; i < 12; ++i) {
12418 m = moment([2015, i, 15, 18]);
12419 tester('MMM');
12420 tester('MMM.');
12421 tester('MMMM');
12422 tester('MMMM.');
12423 }
12424 });
d6651c21 12425
db71a655
KM
12426 test('weekday parsing correctness', function (assert) {
12427 var i, m;
12428
96d0d679 12429 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
12430 // tr, az: There is a lower-case letter (ı), that converted to
12431 // upper then lower changes to i
12432 // ro: there is the letter ț which behaves weird under IE8
12433 // mt: letter Ħ
96d0d679 12434 // ga: month with spaces
c58511b9 12435 assert.expect(0);
db71a655
KM
12436 return;
12437 }
12438 function tester(format) {
12439 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
12440 r = moment(m.format(format), format);
12441 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
12442 if (locale !== 'ka') {
12443 r = moment(m.format(format).toLocaleUpperCase(), format);
12444 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
12445 }
db71a655
KM
12446 r = moment(m.format(format).toLocaleLowerCase(), format);
12447 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
12448 r = moment(m.format(format), format, true);
12449 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
12450 if (locale !== 'ka') {
12451 r = moment(m.format(format).toLocaleUpperCase(), format, true);
12452 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
12453 }
db71a655
KM
12454 r = moment(m.format(format).toLocaleLowerCase(), format, true);
12455 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
12456 }
12457
12458 for (i = 0; i < 7; ++i) {
12459 m = moment.utc([2015, 0, i + 1, 18]);
12460 tester('dd');
12461 tester('ddd');
12462 tester('dddd');
12463 }
12464 });
d6651c21 12465
db71a655
KM
12466 test('valid localeData', function (assert) {
12467 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
12468 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
12469 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
12470 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
12471 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
12472 });
96d0d679
KM
12473
12474 test('localeData weekdays can localeSort', function (assert) {
12475 var weekdays = moment().localeData().weekdays();
12476 var weekdaysShort = moment().localeData().weekdaysShort();
12477 var weekdaysMin = moment().localeData().weekdaysMin();
12478 var shift = moment().localeData()._week.dow;
12479 assert.deepEqual(
12480 moment().localeData().weekdays(true),
12481 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
12482 'weekdays should localeSort');
12483 assert.deepEqual(
12484 moment().localeData().weekdaysShort(true),
12485 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
12486 'weekdaysShort should localeSort');
12487 assert.deepEqual(
12488 moment().localeData().weekdaysMin(true),
12489 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
12490 'weekdaysMin should localeSort');
12491 });
db71a655 12492 }
d6651c21 12493
db71a655 12494 /*global QUnit:false*/
f2af24d5 12495
db71a655
KM
12496 function localeModule (name, lifecycle) {
12497 QUnit.module('locale:' + name, {
c58511b9 12498 beforeEach : function () {
db71a655
KM
12499 moment.locale(name);
12500 moment.createFromInputFallback = function (config) {
12501 throw new Error('input not handled by moment: ' + config._i);
12502 };
12503 setupDeprecationHandler(test, moment, 'locale');
12504 if (lifecycle && lifecycle.setup) {
12505 lifecycle.setup();
12506 }
12507 },
c58511b9 12508 afterEach : function () {
db71a655
KM
12509 moment.locale('en');
12510 teardownDeprecationHandler(test, moment, 'locale');
12511 if (lifecycle && lifecycle.teardown) {
12512 lifecycle.teardown();
12513 }
f2af24d5
IC
12514 }
12515 });
db71a655
KM
12516 defineCommonLocaleTests(name, -1, -1);
12517 }
12518
12519 localeModule('dv');
12520
12521 test('parse', function (assert) {
12522 var i,
12523 tests = [
12524 'ޖެނުއަރީ',
12525 'ފެބްރުއަރީ',
12526 'މާރިޗު',
12527 'އޭޕްރީލު',
12528 'މޭ',
12529 'ޖޫން',
12530 'ޖުލައި',
12531 'އޯގަސްޓު',
12532 'ސެޕްޓެމްބަރު',
12533 'އޮކްޓޯބަރު',
12534 'ނޮވެމްބަރު',
12535 'ޑިސެމްބަރު'
12536 ];
f2af24d5 12537
db71a655
KM
12538 function equalTest(input, mmm, i) {
12539 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
12540 }
12541
12542 for (i = 0; i < 12; i++) {
12543 equalTest(tests[i], 'MMM', i);
12544 equalTest(tests[i], 'MMMM', i);
12545 equalTest(tests[i].toLocaleLowerCase(), 'MMMM', i);
12546 equalTest(tests[i].toLocaleUpperCase(), 'MMMM', i);
12547 }
12548 });
12549
12550 test('format', function (assert) {
12551 var a = [
12552 ['dddd, MMMM Do YYYY, h:mm:ss a', 'އާދިއްތަ، ފެބްރުއަރީ 14 2010، 3:25:50 މފ'],
12553 ['ddd, hA', 'އާދިއްތަ، 3މފ'],
12554 ['M Mo MM MMMM MMM', '2 2 02 ފެބްރުއަރީ ފެބްރުއަރީ'],
12555 ['YYYY YY', '2010 10'],
12556 ['D Do DD', '14 14 14'],
12557 ['d do dddd ddd dd', '0 0 އާދިއްތަ އާދިއްތަ އާދި'],
12558 ['DDD DDDo DDDD', '45 45 045'],
12559 ['w wo ww', '8 8 08'],
12560 ['h hh', '3 03'],
12561 ['H HH', '15 15'],
12562 ['m mm', '25 25'],
12563 ['s ss', '50 50'],
12564 ['a A', 'މފ މފ'],
12565 ['LTS', '15:25:50'],
12566 ['L', '14/2/2010'],
12567 ['LL', '14 ފެބްރުއަރީ 2010'],
12568 ['LLL', '14 ފެބްރުއަރީ 2010 15:25'],
12569 ['LLLL', 'އާދިއްތަ 14 ފެބްރުއަރީ 2010 15:25'],
12570 ['l', '14/2/2010'],
12571 ['ll', '14 ފެބްރުއަރީ 2010'],
12572 ['lll', '14 ފެބްރުއަރީ 2010 15:25'],
12573 ['llll', 'އާދިއްތަ 14 ފެބްރުއަރީ 2010 15:25']
12574 ],
12575 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
12576 i;
12577
12578 for (i = 0; i < a.length; i++) {
12579 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
12580 }
12581 });
12582
12583 test('format month', function (assert) {
12584 var i,
12585 expected = [
12586 'ޖެނުއަރީ',
12587 'ފެބްރުއަރީ',
12588 'މާރިޗު',
12589 'އޭޕްރީލު',
12590 'މޭ',
12591 'ޖޫން',
12592 'ޖުލައި',
12593 'އޯގަސްޓު',
12594 'ސެޕްޓެމްބަރު',
12595 'އޮކްޓޯބަރު',
12596 'ނޮވެމްބަރު',
12597 'ޑިސެމްބަރު'
12598 ];
12599
12600 for (i = 0; i < expected.length; i++) {
12601 assert.equal(moment([2011, i, 1]).format('MMMM'), expected[i]);
f2af24d5 12602 }
db71a655 12603 });
f2af24d5 12604
db71a655
KM
12605 test('format week', function (assert) {
12606 var i,
12607 expected = [
12608 'އާދިއްތަ',
12609 'ހޯމަ',
12610 'އަންގާރަ',
12611 'ބުދަ',
12612 'ބުރާސްފަތި',
12613 'ހުކުރު',
12614 'ހޮނިހިރު'
12615 ];
f2af24d5 12616
db71a655
KM
12617 for (i = 0; i < expected.length; i++) {
12618 assert.equal(moment([2011, 0, 2 + i]).format('dddd'), expected[i]);
12619 }
12620 });
12621
12622
12623 test('from', function (assert) {
12624 var start = moment([2007, 1, 28]);
12625 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ސިކުންތުކޮޅެއް', '44 seconds = a few seconds');
12626 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'މިނިޓެއް', '45 seconds = a minute');
12627 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'މިނިޓެއް', '89 seconds = a minute');
12628 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), 'މިނިޓު 2', '90 seconds = 2 minutes');
12629 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), 'މިނިޓު 44', '44 minutes = 44 minutes');
12630 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ގަޑިއިރެއް', '45 minutes = an hour');
12631 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ގަޑިއިރެއް', '89 minutes = an hour');
12632 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), 'ގަޑިއިރު 2', '90 minutes = 2 hours');
12633 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), 'ގަޑިއިރު 5', '5 hours = 5 hours');
12634 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), 'ގަޑިއިރު 21', '21 hours = 21 hours');
12635 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ދުވަހެއް', '22 hours = a day');
12636 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ދުވަހެއް', '35 hours = a day');
12637 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), 'ދުވަސް 2', '36 hours = 2 days');
12638 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ދުވަހެއް', '1 day = a day');
12639 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), 'ދުވަސް 5', '5 days = 5 days');
12640 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), 'ދުވަސް 25', '25 days = 25 days');
12641 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'މަހެއް', '26 days = a month');
12642 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'މަހެއް', '30 days = a month');
12643 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'މަހެއް', '43 days = a month');
12644 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), 'މަސް 2', '46 days = 2 months');
12645 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), 'މަސް 2', '75 days = 2 months');
12646 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), 'މަސް 3', '76 days = 3 months');
12647 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'މަހެއް', '1 month = a month');
12648 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), 'މަސް 5', '5 months = 5 months');
12649 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'އަހަރެއް', '345 days = a year');
12650 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), 'އަހަރު 2', '548 days = 2 years');
12651 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'އަހަރެއް', '1 year = a year');
12652 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), 'އަހަރު 5', '5 years = 5 years');
12653 });
12654
12655 test('suffix', function (assert) {
12656 assert.equal(moment(30000).from(0), 'ތެރޭގައި ސިކުންތުކޮޅެއް', 'prefix');
12657 assert.equal(moment(0).from(30000), 'ކުރިން ސިކުންތުކޮޅެއް', 'suffix');
12658 });
12659
12660 test('fromNow', function (assert) {
12661 assert.equal(moment().add({s: 30}).fromNow(), 'ތެރޭގައި ސިކުންތުކޮޅެއް', 'in a few seconds');
12662 assert.equal(moment().add({d: 5}).fromNow(), 'ތެރޭގައި ދުވަސް 5', 'in 5 days');
12663 });
12664
12665 test('calendar day', function (assert) {
12666 var a = moment().hours(12).minutes(0).seconds(0);
12667
12668 assert.equal(moment(a).calendar(), 'މިއަދު 12:00', 'today at the same time');
12669 assert.equal(moment(a).add({m: 25}).calendar(), 'މިއަދު 12:25', 'Now plus 25 min');
12670 assert.equal(moment(a).add({h: 1}).calendar(), 'މިއަދު 13:00', 'Now plus 1 hour');
12671 assert.equal(moment(a).add({d: 1}).calendar(), 'މާދަމާ 12:00', 'tomorrow at the same time');
12672 assert.equal(moment(a).subtract({h: 1}).calendar(), 'މިއަދު 11:00', 'Now minus 1 hour');
12673 assert.equal(moment(a).subtract({d: 1}).calendar(), 'އިއްޔެ 12:00', 'yesterday at the same time');
12674 });
12675
12676 test('calendar next week', function (assert) {
12677 var i, m;
12678 for (i = 2; i < 7; i++) {
12679 m = moment().add({d: i});
12680 assert.equal(m.calendar(), m.format('dddd LT'), 'Today + ' + i + ' days current time');
12681 m.hours(0).minutes(0).seconds(0).milliseconds(0);
12682 assert.equal(m.calendar(), m.format('dddd LT'), 'Today + ' + i + ' days beginning of day');
12683 m.hours(23).minutes(59).seconds(59).milliseconds(999);
12684 assert.equal(m.calendar(), m.format('dddd LT'), 'Today + ' + i + ' days end of day');
12685 }
12686 });
f2af24d5 12687
db71a655
KM
12688 test('calendar last week', function (assert) {
12689 var i, m;
12690 for (i = 2; i < 7; i++) {
12691 m = moment().subtract({d: i});
12692 assert.equal(m.calendar(), m.format('[ފާއިތުވި] dddd LT'), 'Today + ' + i + ' days current time');
12693 m.hours(0).minutes(0).seconds(0).milliseconds(0);
12694 assert.equal(m.calendar(), m.format('[ފާއިތުވި] dddd LT'), 'Today + ' + i + ' days beginning of day');
12695 m.hours(23).minutes(59).seconds(59).milliseconds(999);
12696 assert.equal(m.calendar(), m.format('[ފާއިތުވި] dddd LT'), 'Today + ' + i + ' days end of day');
12697 }
12698 });
f2af24d5 12699
db71a655
KM
12700 test('calendar all else', function (assert) {
12701 var weeksAgo = moment().subtract({w: 1}),
12702 weeksFromNow = moment().add({w: 1});
f2af24d5 12703
db71a655
KM
12704 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
12705 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
f2af24d5 12706
db71a655
KM
12707 weeksAgo = moment().subtract({w: 2});
12708 weeksFromNow = moment().add({w: 2});
f2af24d5 12709
db71a655
KM
12710 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
12711 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
12712 });
f2af24d5 12713
db71a655
KM
12714 test('weeks year starting sunday formatted', function (assert) {
12715 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1');
12716 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1', 'Jan 2 2012 should be week 1');
12717 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2');
12718 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2', 'Jan 9 2012 should be week 2');
12719 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', 'Jan 15 2012 should be week 3');
12720 });
f2af24d5
IC
12721
12722})));
12723
12724
12725;(function (global, factory) {
12726 typeof exports === 'object' && typeof module !== 'undefined'
12727 && typeof require === 'function' ? factory(require('../../moment')) :
12728 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
12729 factory(global.moment)
12730}(this, (function (moment) { 'use strict';
12731
db71a655
KM
12732 function each(array, callback) {
12733 var i;
12734 for (i = 0; i < array.length; i++) {
12735 callback(array[i], i, array);
12736 }
f2af24d5 12737 }
f2af24d5 12738
c58511b9
KM
12739 function setupDeprecationHandler(test, moment$$1, scope) {
12740 test._expectedDeprecations = null;
12741 test._observedDeprecations = null;
12742 test._oldSupress = moment$$1.suppressDeprecationWarnings;
12743 moment$$1.suppressDeprecationWarnings = true;
12744 test.expectedDeprecations = function () {
12745 test._expectedDeprecations = arguments;
12746 test._observedDeprecations = [];
12747 };
12748 moment$$1.deprecationHandler = function (name, msg) {
12749 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
12750 if (deprecationId === -1) {
12751 throw new Error('Unexpected deprecation thrown name=' +
12752 name + ' msg=' + msg);
12753 }
12754 test._observedDeprecations[deprecationId] = 1;
12755 };
12756 }
12757
12758 function teardownDeprecationHandler(test, moment$$1, scope) {
12759 moment$$1.suppressDeprecationWarnings = test._oldSupress;
12760
12761 if (test._expectedDeprecations != null) {
12762 var missedDeprecations = [];
12763 each(test._expectedDeprecations, function (deprecationPattern, id) {
12764 if (test._observedDeprecations[id] !== 1) {
12765 missedDeprecations.push(deprecationPattern);
12766 }
12767 });
12768 if (missedDeprecations.length !== 0) {
12769 throw new Error('Expected deprecation warnings did not happen: ' +
12770 missedDeprecations.join(' '));
12771 }
12772 }
12773 }
12774
12775 function matchedDeprecation(name, msg, deprecations) {
12776 if (deprecations == null) {
12777 return -1;
12778 }
12779 for (var i = 0; i < deprecations.length; ++i) {
12780 if (name != null && name === deprecations[i]) {
12781 return i;
12782 }
12783 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
12784 return i;
12785 }
12786 }
12787 return -1;
12788 }
12789
12790 /*global QUnit:false*/
12791
12792 var test = QUnit.test;
12793
db71a655
KM
12794 function objectKeys(obj) {
12795 if (Object.keys) {
12796 return Object.keys(obj);
12797 } else {
12798 // IE8
12799 var res = [], i;
12800 for (i in obj) {
12801 if (obj.hasOwnProperty(i)) {
12802 res.push(i);
12803 }
f2af24d5 12804 }
db71a655 12805 return res;
f2af24d5 12806 }
f2af24d5 12807 }
f2af24d5 12808
db71a655 12809 // Pick the first defined of two or three arguments.
f2af24d5 12810
db71a655
KM
12811 function defineCommonLocaleTests(locale, options) {
12812 test('lenient day of month ordinal parsing', function (assert) {
12813 var i, ordinalStr, testMoment;
12814 for (i = 1; i <= 31; ++i) {
12815 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
12816 testMoment = moment(ordinalStr, 'YYYY MM Do');
12817 assert.equal(testMoment.year(), 2014,
12818 'lenient day of month ordinal parsing ' + i + ' year check');
12819 assert.equal(testMoment.month(), 0,
12820 'lenient day of month ordinal parsing ' + i + ' month check');
12821 assert.equal(testMoment.date(), i,
12822 'lenient day of month ordinal parsing ' + i + ' date check');
12823 }
12824 });
f2af24d5 12825
db71a655
KM
12826 test('lenient day of month ordinal parsing of number', function (assert) {
12827 var i, testMoment;
12828 for (i = 1; i <= 31; ++i) {
12829 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
12830 assert.equal(testMoment.year(), 2014,
12831 'lenient day of month ordinal parsing of number ' + i + ' year check');
12832 assert.equal(testMoment.month(), 0,
12833 'lenient day of month ordinal parsing of number ' + i + ' month check');
12834 assert.equal(testMoment.date(), i,
12835 'lenient day of month ordinal parsing of number ' + i + ' date check');
12836 }
12837 });
f2af24d5 12838
db71a655
KM
12839 test('strict day of month ordinal parsing', function (assert) {
12840 var i, ordinalStr, testMoment;
12841 for (i = 1; i <= 31; ++i) {
12842 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
12843 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
12844 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
12845 }
12846 });
f2af24d5 12847
db71a655
KM
12848 test('meridiem invariant', function (assert) {
12849 var h, m, t1, t2;
12850 for (h = 0; h < 24; ++h) {
12851 for (m = 0; m < 60; m += 15) {
12852 t1 = moment.utc([2000, 0, 1, h, m]);
12853 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
12854 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
12855 'meridiem at ' + t1.format('HH:mm'));
12856 }
12857 }
12858 });
12859
12860 test('date format correctness', function (assert) {
12861 var data, tokens;
12862 data = moment.localeData()._longDateFormat;
12863 tokens = objectKeys(data);
12864 each(tokens, function (srchToken) {
12865 // Check each format string to make sure it does not contain any
12866 // tokens that need to be expanded.
12867 each(tokens, function (baseToken) {
12868 // strip escaped sequences
12869 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
12870 assert.equal(false, !!~format.indexOf(srchToken),
12871 'contains ' + srchToken + ' in ' + baseToken);
12872 });
f2af24d5
IC
12873 });
12874 });
f2af24d5 12875
db71a655
KM
12876 test('month parsing correctness', function (assert) {
12877 var i, m;
12878
12879 if (locale === 'tr') {
12880 // I can't fix it :(
c58511b9 12881 assert.expect(0);
db71a655
KM
12882 return;
12883 }
12884 function tester(format) {
12885 var r;
12886 r = moment(m.format(format), format);
12887 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
12888 if (locale !== 'ka') {
12889 r = moment(m.format(format).toLocaleUpperCase(), format);
12890 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
12891 }
db71a655
KM
12892 r = moment(m.format(format).toLocaleLowerCase(), format);
12893 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
12894
12895 r = moment(m.format(format), format, true);
12896 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
12897 if (locale !== 'ka') {
12898 r = moment(m.format(format).toLocaleUpperCase(), format, true);
12899 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
12900 }
db71a655
KM
12901 r = moment(m.format(format).toLocaleLowerCase(), format, true);
12902 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
12903 }
12904
12905 for (i = 0; i < 12; ++i) {
12906 m = moment([2015, i, 15, 18]);
12907 tester('MMM');
12908 tester('MMM.');
12909 tester('MMMM');
12910 tester('MMMM.');
12911 }
12912 });
f2af24d5 12913
db71a655
KM
12914 test('weekday parsing correctness', function (assert) {
12915 var i, m;
12916
96d0d679 12917 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
12918 // tr, az: There is a lower-case letter (ı), that converted to
12919 // upper then lower changes to i
12920 // ro: there is the letter ț which behaves weird under IE8
12921 // mt: letter Ħ
96d0d679 12922 // ga: month with spaces
c58511b9 12923 assert.expect(0);
db71a655
KM
12924 return;
12925 }
12926 function tester(format) {
12927 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
12928 r = moment(m.format(format), format);
12929 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
12930 if (locale !== 'ka') {
12931 r = moment(m.format(format).toLocaleUpperCase(), format);
12932 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
12933 }
db71a655
KM
12934 r = moment(m.format(format).toLocaleLowerCase(), format);
12935 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
12936 r = moment(m.format(format), format, true);
12937 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
12938 if (locale !== 'ka') {
12939 r = moment(m.format(format).toLocaleUpperCase(), format, true);
12940 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
12941 }
db71a655
KM
12942 r = moment(m.format(format).toLocaleLowerCase(), format, true);
12943 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
12944 }
12945
12946 for (i = 0; i < 7; ++i) {
12947 m = moment.utc([2015, 0, i + 1, 18]);
12948 tester('dd');
12949 tester('ddd');
12950 tester('dddd');
12951 }
12952 });
f2af24d5 12953
db71a655
KM
12954 test('valid localeData', function (assert) {
12955 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
12956 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
12957 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
12958 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
12959 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
12960 });
96d0d679
KM
12961
12962 test('localeData weekdays can localeSort', function (assert) {
12963 var weekdays = moment().localeData().weekdays();
12964 var weekdaysShort = moment().localeData().weekdaysShort();
12965 var weekdaysMin = moment().localeData().weekdaysMin();
12966 var shift = moment().localeData()._week.dow;
12967 assert.deepEqual(
12968 moment().localeData().weekdays(true),
12969 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
12970 'weekdays should localeSort');
12971 assert.deepEqual(
12972 moment().localeData().weekdaysShort(true),
12973 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
12974 'weekdaysShort should localeSort');
12975 assert.deepEqual(
12976 moment().localeData().weekdaysMin(true),
12977 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
12978 'weekdaysMin should localeSort');
12979 });
db71a655 12980 }
f2af24d5 12981
db71a655 12982 /*global QUnit:false*/
c74a101d 12983
db71a655
KM
12984 function localeModule (name, lifecycle) {
12985 QUnit.module('locale:' + name, {
c58511b9 12986 beforeEach : function () {
db71a655
KM
12987 moment.locale(name);
12988 moment.createFromInputFallback = function (config) {
12989 throw new Error('input not handled by moment: ' + config._i);
12990 };
12991 setupDeprecationHandler(test, moment, 'locale');
12992 if (lifecycle && lifecycle.setup) {
12993 lifecycle.setup();
12994 }
12995 },
c58511b9 12996 afterEach : function () {
db71a655
KM
12997 moment.locale('en');
12998 teardownDeprecationHandler(test, moment, 'locale');
12999 if (lifecycle && lifecycle.teardown) {
13000 lifecycle.teardown();
13001 }
c74a101d
IC
13002 }
13003 });
db71a655
KM
13004 defineCommonLocaleTests(name, -1, -1);
13005 }
13006
13007 localeModule('el');
13008
13009 test('parse', function (assert) {
13010 var i,
13011 tests = 'Ιανουάριος Ιαν_Φεβρουάριος Φεβ_Μάρτιος Μαρ_Απρίλιος Απρ_Μάιος Μαϊ_Ιούνιος Ιουν_Ιούλιος Ιουλ_Αύγουστος Αυγ_Σεπτέμβριος Σεπ_Οκτώβριος Οκτ_Νοέμβριος Νοε_Δεκέμβριος Δεκ'.split('_');
13012
13013 function equalTest(input, mmm, i) {
13014 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
13015 }
13016
13017 for (i = 0; i < 12; i++) {
13018 tests[i] = tests[i].split(' ');
13019 equalTest(tests[i][0], 'MMM', i);
13020 equalTest(tests[i][1], 'MMM', i);
13021 equalTest(tests[i][0], 'MMMM', i);
13022 equalTest(tests[i][1], 'MMMM', i);
13023 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
13024 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
13025 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
13026 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
13027 }
13028 });
13029
13030 test('parse meridiem', function (assert) {
13031 var i,
13032 b = moment(),
13033 meridiemTests = [
13034 // h a patterns, expected hours, isValid
13035 ['10 πμ', 10, true],
13036 ['10 μμ', 22, true],
13037 ['10 π.μ.', 10, true],
13038 ['10 μ.μ.', 22, true],
13039 ['10 π', 10, true],
13040 ['10 μ', 22, true],
13041 ['10 ΠΜ', 10, true],
13042 ['10 ΜΜ', 22, true],
13043 ['10 Π.Μ.', 10, true],
13044 ['10 Μ.Μ.', 22, true],
13045 ['10 Π', 10, true],
13046 ['10 Μ', 22, true],
13047 ['10 am', 10, false],
13048 ['10 pm', 10, false]
13049 ],
13050 parsed;
13051
13052 // test that a formatted moment including meridiem string can be parsed back to the same moment
13053 assert.ok(b.isSame(moment(b.format('h:mm:ss a'), 'h:mm:ss a', 'el', true), 'seconds'), b.format('h:mm:ss a') + ' should be equal to ' + moment(b.format('h:mm:ss a'), 'h:mm:ss a', 'el', true).format('h:mm:ss a'));
13054
13055 // test that a formatted moment having a meridiem string can be parsed with strict flag
13056 assert.ok(moment(b.format('h:mm:ss a'), 'h:mm:ss a', 'el', true).isValid(), b.format('h:mm:ss a') + ' should be parsed as valid');
13057
13058 for (i = 0; i < meridiemTests.length; i++) {
13059 parsed = moment(meridiemTests[i][0], 'h a', 'el', true);
13060 assert.equal(parsed.isValid(), meridiemTests[i][2], 'validity for ' + meridiemTests[i][0]);
13061 if (parsed.isValid()) {
13062 assert.equal(parsed.hours(), meridiemTests[i][1], 'hours for ' + meridiemTests[i][0]);
13063 }
13064 }
13065 });
13066
13067 test('format', function (assert) {
13068 var a = [
13069 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Κυριακή, Φεβρουάριος 14η 2010, 3:25:50 μμ'],
13070 ['dddd, D MMMM YYYY, h:mm:ss a', 'Κυριακή, 14 Φεβρουαρίου 2010, 3:25:50 μμ'],
13071 ['ddd, hA', 'Κυρ, 3ΜΜ'],
13072 ['dddd, MMMM YYYY', 'Κυριακή, Φεβρουάριος 2010'],
13073 ['M Mo MM MMMM MMM', '2 2η 02 Φεβρουάριος Φεβ'],
13074 ['YYYY YY', '2010 10'],
13075 ['D Do DD', '14 14η 14'],
13076 ['d do dddd ddd dd', '0 0η Κυριακή Κυρ Κυ'],
13077 ['DDD DDDo DDDD', '45 45η 045'],
13078 ['w wo ww', '6 6η 06'],
13079 ['h hh', '3 03'],
13080 ['H HH', '15 15'],
13081 ['m mm', '25 25'],
13082 ['s ss', '50 50'],
13083 ['a A', 'μμ ΜΜ'],
13084 ['[the] DDDo [day of the year]', 'the 45η day of the year'],
13085 ['LTS', '3:25:50 ΜΜ'],
13086 ['L', '14/02/2010'],
13087 ['LL', '14 Φεβρουαρίου 2010'],
13088 ['LLL', '14 Φεβρουαρίου 2010 3:25 ΜΜ'],
13089 ['LLLL', 'Κυριακή, 14 Φεβρουαρίου 2010 3:25 ΜΜ'],
13090 ['l', '14/2/2010'],
13091 ['ll', '14 Φεβ 2010'],
13092 ['lll', '14 Φεβ 2010 3:25 ΜΜ'],
13093 ['llll', 'Κυρ, 14 Φεβ 2010 3:25 ΜΜ']
13094 ],
13095 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
13096 i;
13097
13098 for (i = 0; i < a.length; i++) {
13099 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
13100 }
13101 });
13102
13103 test('format ordinal', function (assert) {
13104 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1η', '1η');
13105 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2η', '2η');
13106 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3η', '3η');
13107 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4η', '4η');
13108 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5η', '5η');
13109 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6η', '6η');
13110 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7η', '7η');
13111 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8η', '8η');
13112 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9η', '9η');
13113 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10η', '10η');
13114
13115 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11η', '11η');
13116 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12η', '12η');
13117 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13η', '13η');
13118 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14η', '14η');
13119 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15η', '15η');
13120 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16η', '16η');
13121 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17η', '17η');
13122 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18η', '18η');
13123 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19η', '19η');
13124 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20η', '20η');
13125
13126 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21η', '21η');
13127 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22η', '22η');
13128 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23η', '23η');
13129 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24η', '24η');
13130 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25η', '25η');
13131 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26η', '26η');
13132 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27η', '27η');
13133 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28η', '28η');
13134 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29η', '29η');
13135 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30η', '30η');
13136
13137 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31η', '31η');
13138 });
13139
13140 test('format month', function (assert) {
13141 var i,
13142 expected = 'Ιανουάριος Ιαν_Φεβρουάριος Φεβ_Μάρτιος Μαρ_Απρίλιος Απρ_Μάιος Μαϊ_Ιούνιος Ιουν_Ιούλιος Ιουλ_Αύγουστος Αυγ_Σεπτέμβριος Σεπ_Οκτώβριος Οκτ_Νοέμβριος Νοε_Δεκέμβριος Δεκ'.split('_');
13143
13144 for (i = 0; i < expected.length; i++) {
13145 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
13146 }
13147 });
13148
13149 test('format week', function (assert) {
13150 var i,
13151 expected = 'Κυριακή Κυρ Κυ_Δευτέρα Δευ Δε_Τρίτη Τρι Τρ_Τετάρτη Τετ Τε_Πέμπτη Πεμ Πε_Παρασκευή Παρ Πα_Σάββατο Σαβ Σα'.split('_');
13152
13153 for (i = 0; i < expected.length; i++) {
13154 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
13155 }
13156 });
13157
13158 test('from', function (assert) {
13159 var start = moment([2007, 1, 28]);
13160
13161 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'λίγα δευτερόλεπτα', '44 seconds = a few seconds');
13162 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ένα λεπτό', '45 seconds = a minute');
13163 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ένα λεπτό', '89 seconds = a minute');
13164 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 λεπτά', '90 seconds = 2 minutes');
13165 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 λεπτά', '44 minutes = 44 minutes');
13166 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'μία ώρα', '45 minutes = an hour');
13167 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'μία ώρα', '89 minutes = an hour');
13168 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ώρες', '90 minutes = 2 hours');
13169 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ώρες', '5 hours = 5 hours');
13170 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ώρες', '21 hours = 21 hours');
13171 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'μία μέρα', '22 hours = a day');
13172 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'μία μέρα', '35 hours = a day');
13173 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 μέρες', '36 hours = 2 days');
13174 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'μία μέρα', '1 day = a day');
13175 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 μέρες', '5 days = 5 days');
13176 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 μέρες', '25 days = 25 days');
13177 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ένας μήνας', '26 days = a month');
13178 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ένας μήνας', '30 days = a month');
13179 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ένας μήνας', '43 days = a month');
13180 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 μήνες', '46 days = 2 months');
13181 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 μήνες', '75 days = 2 months');
13182 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 μήνες', '76 days = 3 months');
13183 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ένας μήνας', '1 month = a month');
13184 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 μήνες', '5 months = 5 months');
13185 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ένας χρόνος', '345 days = a year');
13186 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 χρόνια', '548 days = 2 years');
13187 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ένας χρόνος', '1 year = a year');
13188 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 χρόνια', '5 years = 5 years');
13189 });
13190
13191 test('suffix', function (assert) {
13192 assert.equal(moment(30000).from(0), 'σε λίγα δευτερόλεπτα', 'prefix');
13193 assert.equal(moment(0).from(30000), 'λίγα δευτερόλεπτα πριν', 'suffix');
13194 });
13195
13196 test('now from now', function (assert) {
13197 assert.equal(moment().fromNow(), 'λίγα δευτερόλεπτα πριν', 'now from now should display as in the past');
13198 });
13199
13200 test('fromNow', function (assert) {
13201 assert.equal(moment().add({s: 30}).fromNow(), 'σε λίγα δευτερόλεπτα', 'in a few seconds');
13202 assert.equal(moment().add({d: 5}).fromNow(), 'σε 5 μέρες', 'in 5 days');
13203 });
13204
13205 test('calendar day', function (assert) {
13206 var a = moment().hours(12).minutes(0).seconds(0);
13207
13208 assert.equal(moment(a).calendar(), 'Σήμερα στις 12:00 ΜΜ', 'today at the same time');
13209 assert.equal(moment(a).add({m: 25}).calendar(), 'Σήμερα στις 12:25 ΜΜ', 'Now plus 25 min');
13210 assert.equal(moment(a).add({h: 1}).calendar(), 'Σήμερα στη 1:00 ΜΜ', 'Now plus 1 hour');
13211 assert.equal(moment(a).add({d: 1}).calendar(), 'Αύριο στις 12:00 ΜΜ', 'tomorrow at the same time');
13212 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Σήμερα στις 11:00 ΠΜ', 'Now minus 1 hour');
13213 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Χθες στις 12:00 ΜΜ', 'yesterday at the same time');
13214 });
13215
13216 test('calendar next week', function (assert) {
13217 var i, m;
13218 for (i = 2; i < 7; i++) {
13219 m = moment().add({d: i});
13220 assert.equal(m.calendar(), m.format('dddd [' + (m.hours() % 12 === 1 ? 'στη' : 'στις') + '] LT'), 'Today + ' + i + ' days current time');
13221 m.hours(0).minutes(0).seconds(0).milliseconds(0);
13222 assert.equal(m.calendar(), m.format('dddd [στις] LT'), 'Today + ' + i + ' days beginning of day');
13223 m.hours(23).minutes(59).seconds(59).milliseconds(999);
13224 assert.equal(m.calendar(), m.format('dddd [στις] LT'), 'Today + ' + i + ' days end of day');
73f3c911 13225 }
db71a655 13226 });
c74a101d 13227
db71a655
KM
13228 test('calendar last week', function (assert) {
13229 var i, m, dayString;
13230 for (i = 2; i < 7; i++) {
13231 m = moment().subtract({d: i});
13232 dayString = m.day() === 6 ? '[το προηγούμενο Σάββατο]' : '[την προηγούμενη] dddd';
13233 assert.equal(m.calendar(), m.format(dayString + ' [' + (m.hours() % 12 === 1 ? 'στη' : 'στις') + '] LT'), 'Today - ' + i + ' days current time');
13234 m.hours(1).minutes(30).seconds(0).milliseconds(0);
13235 assert.equal(m.calendar(), m.format(dayString + ' [στη] LT'), 'Today - ' + i + ' days one o clock');
13236 m.hours(0).minutes(0).seconds(0).milliseconds(0);
13237 assert.equal(m.calendar(), m.format(dayString + ' [στις] LT'), 'Today - ' + i + ' days beginning of day');
13238 m.hours(23).minutes(59).seconds(59).milliseconds(999);
13239 assert.equal(m.calendar(), m.format(dayString + ' [στις] LT'), 'Today - ' + i + ' days end of day');
516f5f67 13240 }
db71a655 13241 });
516f5f67 13242
db71a655
KM
13243 test('calendar all else', function (assert) {
13244 var weeksAgo = moment().subtract({w: 1}),
13245 weeksFromNow = moment().add({w: 1});
516f5f67 13246
db71a655
KM
13247 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
13248 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 13249
db71a655
KM
13250 weeksAgo = moment().subtract({w: 2});
13251 weeksFromNow = moment().add({w: 2});
516f5f67 13252
db71a655
KM
13253 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
13254 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
13255 });
13256
13257 test('weeks year starting sunday format', function (assert) {
13258 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52η', 'Jan 1 2012 should be week 52');
13259 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1η', 'Jan 7 2012 should be week 1');
13260 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1η', 'Jan 8 2012 should be week 1');
13261 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2η', 'Jan 14 2012 should be week 2');
13262 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2η', 'Jan 15 2012 should be week 2');
13263 });
73f3c911 13264
db71a655
KM
13265 test('localeData months calls', function (assert) {
13266 var jan = moment('2012-01-01');
13267 assert.equal(moment.localeData().months(jan), 'Ιανουάριος', 'should return the nominative month name');
13268 assert.equal(moment.localeData().months(jan, 'D MMMM'), 'Ιανουαρίου', 'should return the genitive month name');
13269 });
9483e2a4 13270
73f3c911
IC
13271})));
13272
516f5f67 13273
c74a101d
IC
13274;(function (global, factory) {
13275 typeof exports === 'object' && typeof module !== 'undefined'
13276 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
13277 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
13278 factory(global.moment)
73f3c911 13279}(this, (function (moment) { 'use strict';
516f5f67 13280
db71a655
KM
13281 function each(array, callback) {
13282 var i;
13283 for (i = 0; i < array.length; i++) {
13284 callback(array[i], i, array);
13285 }
b135bf1a
IC
13286 }
13287
c58511b9
KM
13288 function setupDeprecationHandler(test, moment$$1, scope) {
13289 test._expectedDeprecations = null;
13290 test._observedDeprecations = null;
13291 test._oldSupress = moment$$1.suppressDeprecationWarnings;
13292 moment$$1.suppressDeprecationWarnings = true;
13293 test.expectedDeprecations = function () {
13294 test._expectedDeprecations = arguments;
13295 test._observedDeprecations = [];
13296 };
13297 moment$$1.deprecationHandler = function (name, msg) {
13298 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
13299 if (deprecationId === -1) {
13300 throw new Error('Unexpected deprecation thrown name=' +
13301 name + ' msg=' + msg);
13302 }
13303 test._observedDeprecations[deprecationId] = 1;
13304 };
13305 }
13306
13307 function teardownDeprecationHandler(test, moment$$1, scope) {
13308 moment$$1.suppressDeprecationWarnings = test._oldSupress;
13309
13310 if (test._expectedDeprecations != null) {
13311 var missedDeprecations = [];
13312 each(test._expectedDeprecations, function (deprecationPattern, id) {
13313 if (test._observedDeprecations[id] !== 1) {
13314 missedDeprecations.push(deprecationPattern);
13315 }
13316 });
13317 if (missedDeprecations.length !== 0) {
13318 throw new Error('Expected deprecation warnings did not happen: ' +
13319 missedDeprecations.join(' '));
13320 }
13321 }
13322 }
13323
13324 function matchedDeprecation(name, msg, deprecations) {
13325 if (deprecations == null) {
13326 return -1;
13327 }
13328 for (var i = 0; i < deprecations.length; ++i) {
13329 if (name != null && name === deprecations[i]) {
13330 return i;
13331 }
13332 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
13333 return i;
13334 }
13335 }
13336 return -1;
13337 }
13338
13339 /*global QUnit:false*/
13340
13341 var test = QUnit.test;
13342
db71a655
KM
13343 function objectKeys(obj) {
13344 if (Object.keys) {
13345 return Object.keys(obj);
13346 } else {
13347 // IE8
13348 var res = [], i;
13349 for (i in obj) {
13350 if (obj.hasOwnProperty(i)) {
13351 res.push(i);
13352 }
b135bf1a 13353 }
db71a655 13354 return res;
b135bf1a
IC
13355 }
13356 }
b135bf1a 13357
db71a655 13358 // Pick the first defined of two or three arguments.
b135bf1a 13359
db71a655
KM
13360 function defineCommonLocaleTests(locale, options) {
13361 test('lenient day of month ordinal parsing', function (assert) {
13362 var i, ordinalStr, testMoment;
13363 for (i = 1; i <= 31; ++i) {
13364 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
13365 testMoment = moment(ordinalStr, 'YYYY MM Do');
13366 assert.equal(testMoment.year(), 2014,
13367 'lenient day of month ordinal parsing ' + i + ' year check');
13368 assert.equal(testMoment.month(), 0,
13369 'lenient day of month ordinal parsing ' + i + ' month check');
13370 assert.equal(testMoment.date(), i,
13371 'lenient day of month ordinal parsing ' + i + ' date check');
13372 }
13373 });
b135bf1a 13374
db71a655
KM
13375 test('lenient day of month ordinal parsing of number', function (assert) {
13376 var i, testMoment;
13377 for (i = 1; i <= 31; ++i) {
13378 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
13379 assert.equal(testMoment.year(), 2014,
13380 'lenient day of month ordinal parsing of number ' + i + ' year check');
13381 assert.equal(testMoment.month(), 0,
13382 'lenient day of month ordinal parsing of number ' + i + ' month check');
13383 assert.equal(testMoment.date(), i,
13384 'lenient day of month ordinal parsing of number ' + i + ' date check');
13385 }
b135bf1a
IC
13386 });
13387
db71a655
KM
13388 test('strict day of month ordinal parsing', function (assert) {
13389 var i, ordinalStr, testMoment;
13390 for (i = 1; i <= 31; ++i) {
13391 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
13392 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
13393 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
13394 }
13395 });
b135bf1a 13396
db71a655
KM
13397 test('meridiem invariant', function (assert) {
13398 var h, m, t1, t2;
13399 for (h = 0; h < 24; ++h) {
13400 for (m = 0; m < 60; m += 15) {
13401 t1 = moment.utc([2000, 0, 1, h, m]);
13402 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
13403 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
13404 'meridiem at ' + t1.format('HH:mm'));
13405 }
13406 }
13407 });
d6651c21 13408
db71a655
KM
13409 test('date format correctness', function (assert) {
13410 var data, tokens;
13411 data = moment.localeData()._longDateFormat;
13412 tokens = objectKeys(data);
13413 each(tokens, function (srchToken) {
13414 // Check each format string to make sure it does not contain any
13415 // tokens that need to be expanded.
13416 each(tokens, function (baseToken) {
13417 // strip escaped sequences
13418 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
13419 assert.equal(false, !!~format.indexOf(srchToken),
13420 'contains ' + srchToken + ' in ' + baseToken);
13421 });
13422 });
13423 });
d6651c21 13424
db71a655
KM
13425 test('month parsing correctness', function (assert) {
13426 var i, m;
13427
13428 if (locale === 'tr') {
13429 // I can't fix it :(
c58511b9 13430 assert.expect(0);
db71a655
KM
13431 return;
13432 }
13433 function tester(format) {
13434 var r;
13435 r = moment(m.format(format), format);
13436 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
13437 if (locale !== 'ka') {
13438 r = moment(m.format(format).toLocaleUpperCase(), format);
13439 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
13440 }
db71a655
KM
13441 r = moment(m.format(format).toLocaleLowerCase(), format);
13442 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
13443
13444 r = moment(m.format(format), format, true);
13445 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
13446 if (locale !== 'ka') {
13447 r = moment(m.format(format).toLocaleUpperCase(), format, true);
13448 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
13449 }
db71a655
KM
13450 r = moment(m.format(format).toLocaleLowerCase(), format, true);
13451 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
13452 }
13453
13454 for (i = 0; i < 12; ++i) {
13455 m = moment([2015, i, 15, 18]);
13456 tester('MMM');
13457 tester('MMM.');
13458 tester('MMMM');
13459 tester('MMMM.');
13460 }
13461 });
d6651c21 13462
db71a655
KM
13463 test('weekday parsing correctness', function (assert) {
13464 var i, m;
13465
96d0d679 13466 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
13467 // tr, az: There is a lower-case letter (ı), that converted to
13468 // upper then lower changes to i
13469 // ro: there is the letter ț which behaves weird under IE8
13470 // mt: letter Ħ
96d0d679 13471 // ga: month with spaces
c58511b9 13472 assert.expect(0);
db71a655
KM
13473 return;
13474 }
13475 function tester(format) {
13476 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
13477 r = moment(m.format(format), format);
13478 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
13479 if (locale !== 'ka') {
13480 r = moment(m.format(format).toLocaleUpperCase(), format);
13481 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
13482 }
db71a655
KM
13483 r = moment(m.format(format).toLocaleLowerCase(), format);
13484 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
13485 r = moment(m.format(format), format, true);
13486 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
13487 if (locale !== 'ka') {
13488 r = moment(m.format(format).toLocaleUpperCase(), format, true);
13489 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
13490 }
db71a655
KM
13491 r = moment(m.format(format).toLocaleLowerCase(), format, true);
13492 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
13493 }
13494
13495 for (i = 0; i < 7; ++i) {
13496 m = moment.utc([2015, 0, i + 1, 18]);
13497 tester('dd');
13498 tester('ddd');
13499 tester('dddd');
13500 }
13501 });
d6651c21 13502
db71a655
KM
13503 test('valid localeData', function (assert) {
13504 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
13505 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
13506 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
13507 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
13508 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
13509 });
96d0d679
KM
13510
13511 test('localeData weekdays can localeSort', function (assert) {
13512 var weekdays = moment().localeData().weekdays();
13513 var weekdaysShort = moment().localeData().weekdaysShort();
13514 var weekdaysMin = moment().localeData().weekdaysMin();
13515 var shift = moment().localeData()._week.dow;
13516 assert.deepEqual(
13517 moment().localeData().weekdays(true),
13518 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
13519 'weekdays should localeSort');
13520 assert.deepEqual(
13521 moment().localeData().weekdaysShort(true),
13522 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
13523 'weekdaysShort should localeSort');
13524 assert.deepEqual(
13525 moment().localeData().weekdaysMin(true),
13526 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
13527 'weekdaysMin should localeSort');
13528 });
db71a655 13529 }
b135bf1a 13530
db71a655 13531 /*global QUnit:false*/
516f5f67 13532
db71a655
KM
13533 function localeModule (name, lifecycle) {
13534 QUnit.module('locale:' + name, {
c58511b9 13535 beforeEach : function () {
db71a655
KM
13536 moment.locale(name);
13537 moment.createFromInputFallback = function (config) {
13538 throw new Error('input not handled by moment: ' + config._i);
13539 };
13540 setupDeprecationHandler(test, moment, 'locale');
13541 if (lifecycle && lifecycle.setup) {
13542 lifecycle.setup();
13543 }
13544 },
c58511b9 13545 afterEach : function () {
db71a655
KM
13546 moment.locale('en');
13547 teardownDeprecationHandler(test, moment, 'locale');
13548 if (lifecycle && lifecycle.teardown) {
13549 lifecycle.teardown();
13550 }
73f3c911 13551 }
db71a655
KM
13552 });
13553 defineCommonLocaleTests(name, -1, -1);
13554 }
13555
96d0d679 13556 localeModule('en-SG');
db71a655
KM
13557
13558 test('parse', function (assert) {
13559 var tests = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_'), i;
13560 function equalTest(input, mmm, i) {
13561 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
13562 }
13563 for (i = 0; i < 12; i++) {
13564 tests[i] = tests[i].split(' ');
13565 equalTest(tests[i][0], 'MMM', i);
13566 equalTest(tests[i][1], 'MMM', i);
13567 equalTest(tests[i][0], 'MMMM', i);
13568 equalTest(tests[i][1], 'MMMM', i);
13569 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
13570 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
13571 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
13572 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
13573 }
13574 });
13575
13576 test('format', function (assert) {
13577 var a = [
13578 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Sunday, February 14th 2010, 3:25:50 pm'],
13579 ['ddd, hA', 'Sun, 3PM'],
13580 ['M Mo MM MMMM MMM', '2 2nd 02 February Feb'],
13581 ['YYYY YY', '2010 10'],
13582 ['D Do DD', '14 14th 14'],
13583 ['d do dddd ddd dd', '0 0th Sunday Sun Su'],
13584 ['DDD DDDo DDDD', '45 45th 045'],
13585 ['w wo ww', '6 6th 06'],
13586 ['h hh', '3 03'],
13587 ['H HH', '15 15'],
13588 ['m mm', '25 25'],
13589 ['s ss', '50 50'],
13590 ['a A', 'pm PM'],
13591 ['[the] DDDo [day of the year]', 'the 45th day of the year'],
96d0d679 13592 ['LTS', '15:25:50'],
db71a655
KM
13593 ['L', '14/02/2010'],
13594 ['LL', '14 February 2010'],
96d0d679
KM
13595 ['LLL', '14 February 2010 15:25'],
13596 ['LLLL', 'Sunday, 14 February 2010 15:25'],
db71a655
KM
13597 ['l', '14/2/2010'],
13598 ['ll', '14 Feb 2010'],
96d0d679
KM
13599 ['lll', '14 Feb 2010 15:25'],
13600 ['llll', 'Sun, 14 Feb 2010 15:25']
db71a655
KM
13601 ],
13602 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
13603 i;
13604 for (i = 0; i < a.length; i++) {
13605 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
13606 }
13607 });
13608
13609 test('format ordinal', function (assert) {
13610 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1st', '1st');
13611 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2nd', '2nd');
13612 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3rd', '3rd');
13613 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4th', '4th');
13614 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5th', '5th');
13615 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6th', '6th');
13616 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7th', '7th');
13617 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8th', '8th');
13618 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9th', '9th');
13619 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10th', '10th');
13620
13621 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11th', '11th');
13622 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12th', '12th');
13623 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13th', '13th');
13624 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14th', '14th');
13625 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15th', '15th');
13626 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16th', '16th');
13627 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17th', '17th');
13628 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18th', '18th');
13629 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19th', '19th');
13630 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20th', '20th');
13631
13632 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21st', '21st');
13633 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22nd', '22nd');
13634 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23rd', '23rd');
13635 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24th', '24th');
13636 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25th', '25th');
13637 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26th', '26th');
13638 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27th', '27th');
13639 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28th', '28th');
13640 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29th', '29th');
13641 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30th', '30th');
13642
13643 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31st', '31st');
13644 });
13645
13646 test('format month', function (assert) {
13647 var expected = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_'), i;
13648 for (i = 0; i < expected.length; i++) {
13649 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
13650 }
13651 });
13652
13653 test('format week', function (assert) {
13654 var expected = 'Sunday Sun Su_Monday Mon Mo_Tuesday Tue Tu_Wednesday Wed We_Thursday Thu Th_Friday Fri Fr_Saturday Sat Sa'.split('_'), i;
13655 for (i = 0; i < expected.length; i++) {
13656 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
13657 }
13658 });
13659
13660 test('from', function (assert) {
13661 var start = moment([2007, 1, 28]);
13662 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'a few seconds', '44 seconds = a few seconds');
13663 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'a minute', '45 seconds = a minute');
13664 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'a minute', '89 seconds = a minute');
13665 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes');
13666 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes');
13667 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'an hour', '45 minutes = an hour');
13668 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'an hour', '89 minutes = an hour');
13669 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hours', '90 minutes = 2 hours');
13670 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hours', '5 hours = 5 hours');
13671 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hours', '21 hours = 21 hours');
13672 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'a day', '22 hours = a day');
13673 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'a day', '35 hours = a day');
13674 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 days', '36 hours = 2 days');
13675 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'a day', '1 day = a day');
13676 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 days', '5 days = 5 days');
13677 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 days', '25 days = 25 days');
13678 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'a month', '26 days = a month');
13679 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'a month', '30 days = a month');
13680 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'a month', '43 days = a month');
13681 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 months', '46 days = 2 months');
13682 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 months', '75 days = 2 months');
13683 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 months', '76 days = 3 months');
13684 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'a month', '1 month = a month');
13685 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 months', '5 months = 5 months');
13686 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'a year', '345 days = a year');
13687 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 years', '548 days = 2 years');
13688 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'a year', '1 year = a year');
13689 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 years', '5 years = 5 years');
13690 });
13691
13692 test('suffix', function (assert) {
13693 assert.equal(moment(30000).from(0), 'in a few seconds', 'prefix');
13694 assert.equal(moment(0).from(30000), 'a few seconds ago', 'suffix');
13695 });
13696
13697 test('now from now', function (assert) {
13698 assert.equal(moment().fromNow(), 'a few seconds ago', 'now from now should display as in the past');
13699 });
13700
13701 test('fromNow', function (assert) {
13702 assert.equal(moment().add({s: 30}).fromNow(), 'in a few seconds', 'in a few seconds');
13703 assert.equal(moment().add({d: 5}).fromNow(), 'in 5 days', 'in 5 days');
13704 });
13705
13706 test('calendar day', function (assert) {
13707 var a = moment().hours(12).minutes(0).seconds(0);
13708
96d0d679
KM
13709 assert.equal(moment(a).calendar(), 'Today at 12:00', 'today at the same time');
13710 assert.equal(moment(a).add({m: 25}).calendar(), 'Today at 12:25', 'Now plus 25 min');
13711 assert.equal(moment(a).add({h: 1}).calendar(), 'Today at 13:00', 'Now plus 1 hour');
13712 assert.equal(moment(a).add({d: 1}).calendar(), 'Tomorrow at 12:00', 'tomorrow at the same time');
13713 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Today at 11:00', 'Now minus 1 hour');
13714 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Yesterday at 12:00', 'yesterday at the same time');
db71a655
KM
13715 });
13716
13717 test('calendar next week', function (assert) {
13718 var i, m;
13719 for (i = 2; i < 7; i++) {
13720 m = moment().add({d: i});
13721 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days current time');
13722 m.hours(0).minutes(0).seconds(0).milliseconds(0);
13723 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days beginning of day');
13724 m.hours(23).minutes(59).seconds(59).milliseconds(999);
13725 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days end of day');
13726 }
13727 });
13728
13729 test('calendar last week', function (assert) {
13730 var i, m;
13731
13732 for (i = 2; i < 7; i++) {
13733 m = moment().subtract({d: i});
13734 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days current time');
13735 m.hours(0).minutes(0).seconds(0).milliseconds(0);
13736 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days beginning of day');
13737 m.hours(23).minutes(59).seconds(59).milliseconds(999);
13738 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days end of day');
13739 }
13740 });
13741
13742 test('calendar all else', function (assert) {
13743 var weeksAgo = moment().subtract({w: 1}),
13744 weeksFromNow = moment().add({w: 1});
13745
13746 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
13747 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
13748
13749 weeksAgo = moment().subtract({w: 2});
13750 weeksFromNow = moment().add({w: 2});
13751
13752 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
13753 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
13754 });
13755
13756 test('weeks year starting sunday formatted', function (assert) {
13757 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52nd', 'Jan 1 2012 should be week 52');
13758 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1st', 'Jan 2 2012 should be week 1');
13759 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1st', 'Jan 8 2012 should be week 1');
13760 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2nd', 'Jan 9 2012 should be week 2');
13761 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2nd', 'Jan 15 2012 should be week 2');
13762 });
73f3c911
IC
13763
13764})));
13765
516f5f67 13766
c74a101d
IC
13767;(function (global, factory) {
13768 typeof exports === 'object' && typeof module !== 'undefined'
13769 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
13770 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
13771 factory(global.moment)
73f3c911 13772}(this, (function (moment) { 'use strict';
516f5f67 13773
db71a655
KM
13774 function each(array, callback) {
13775 var i;
13776 for (i = 0; i < array.length; i++) {
13777 callback(array[i], i, array);
13778 }
b135bf1a
IC
13779 }
13780
c58511b9
KM
13781 function setupDeprecationHandler(test, moment$$1, scope) {
13782 test._expectedDeprecations = null;
13783 test._observedDeprecations = null;
13784 test._oldSupress = moment$$1.suppressDeprecationWarnings;
13785 moment$$1.suppressDeprecationWarnings = true;
13786 test.expectedDeprecations = function () {
13787 test._expectedDeprecations = arguments;
13788 test._observedDeprecations = [];
13789 };
13790 moment$$1.deprecationHandler = function (name, msg) {
13791 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
13792 if (deprecationId === -1) {
13793 throw new Error('Unexpected deprecation thrown name=' +
13794 name + ' msg=' + msg);
13795 }
13796 test._observedDeprecations[deprecationId] = 1;
13797 };
13798 }
13799
13800 function teardownDeprecationHandler(test, moment$$1, scope) {
13801 moment$$1.suppressDeprecationWarnings = test._oldSupress;
13802
13803 if (test._expectedDeprecations != null) {
13804 var missedDeprecations = [];
13805 each(test._expectedDeprecations, function (deprecationPattern, id) {
13806 if (test._observedDeprecations[id] !== 1) {
13807 missedDeprecations.push(deprecationPattern);
13808 }
13809 });
13810 if (missedDeprecations.length !== 0) {
13811 throw new Error('Expected deprecation warnings did not happen: ' +
13812 missedDeprecations.join(' '));
13813 }
13814 }
13815 }
13816
13817 function matchedDeprecation(name, msg, deprecations) {
13818 if (deprecations == null) {
13819 return -1;
13820 }
13821 for (var i = 0; i < deprecations.length; ++i) {
13822 if (name != null && name === deprecations[i]) {
13823 return i;
13824 }
13825 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
13826 return i;
13827 }
13828 }
13829 return -1;
13830 }
13831
13832 /*global QUnit:false*/
13833
13834 var test = QUnit.test;
13835
db71a655
KM
13836 function objectKeys(obj) {
13837 if (Object.keys) {
13838 return Object.keys(obj);
13839 } else {
13840 // IE8
13841 var res = [], i;
13842 for (i in obj) {
13843 if (obj.hasOwnProperty(i)) {
13844 res.push(i);
13845 }
b135bf1a 13846 }
db71a655 13847 return res;
b135bf1a 13848 }
b135bf1a
IC
13849 }
13850
db71a655 13851 // Pick the first defined of two or three arguments.
b135bf1a 13852
db71a655
KM
13853 function defineCommonLocaleTests(locale, options) {
13854 test('lenient day of month ordinal parsing', function (assert) {
13855 var i, ordinalStr, testMoment;
13856 for (i = 1; i <= 31; ++i) {
13857 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
13858 testMoment = moment(ordinalStr, 'YYYY MM Do');
13859 assert.equal(testMoment.year(), 2014,
13860 'lenient day of month ordinal parsing ' + i + ' year check');
13861 assert.equal(testMoment.month(), 0,
13862 'lenient day of month ordinal parsing ' + i + ' month check');
13863 assert.equal(testMoment.date(), i,
13864 'lenient day of month ordinal parsing ' + i + ' date check');
13865 }
13866 });
b135bf1a 13867
db71a655
KM
13868 test('lenient day of month ordinal parsing of number', function (assert) {
13869 var i, testMoment;
13870 for (i = 1; i <= 31; ++i) {
13871 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
13872 assert.equal(testMoment.year(), 2014,
13873 'lenient day of month ordinal parsing of number ' + i + ' year check');
13874 assert.equal(testMoment.month(), 0,
13875 'lenient day of month ordinal parsing of number ' + i + ' month check');
13876 assert.equal(testMoment.date(), i,
13877 'lenient day of month ordinal parsing of number ' + i + ' date check');
13878 }
13879 });
b135bf1a 13880
db71a655
KM
13881 test('strict day of month ordinal parsing', function (assert) {
13882 var i, ordinalStr, testMoment;
13883 for (i = 1; i <= 31; ++i) {
13884 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
13885 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
13886 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
13887 }
13888 });
b135bf1a 13889
db71a655
KM
13890 test('meridiem invariant', function (assert) {
13891 var h, m, t1, t2;
13892 for (h = 0; h < 24; ++h) {
13893 for (m = 0; m < 60; m += 15) {
13894 t1 = moment.utc([2000, 0, 1, h, m]);
13895 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
13896 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
13897 'meridiem at ' + t1.format('HH:mm'));
13898 }
13899 }
13900 });
13901
13902 test('date format correctness', function (assert) {
13903 var data, tokens;
13904 data = moment.localeData()._longDateFormat;
13905 tokens = objectKeys(data);
13906 each(tokens, function (srchToken) {
13907 // Check each format string to make sure it does not contain any
13908 // tokens that need to be expanded.
13909 each(tokens, function (baseToken) {
13910 // strip escaped sequences
13911 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
13912 assert.equal(false, !!~format.indexOf(srchToken),
13913 'contains ' + srchToken + ' in ' + baseToken);
13914 });
b135bf1a
IC
13915 });
13916 });
d6651c21 13917
db71a655
KM
13918 test('month parsing correctness', function (assert) {
13919 var i, m;
13920
13921 if (locale === 'tr') {
13922 // I can't fix it :(
c58511b9 13923 assert.expect(0);
db71a655
KM
13924 return;
13925 }
13926 function tester(format) {
13927 var r;
13928 r = moment(m.format(format), format);
13929 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
13930 if (locale !== 'ka') {
13931 r = moment(m.format(format).toLocaleUpperCase(), format);
13932 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
13933 }
db71a655
KM
13934 r = moment(m.format(format).toLocaleLowerCase(), format);
13935 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
13936
13937 r = moment(m.format(format), format, true);
13938 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
13939 if (locale !== 'ka') {
13940 r = moment(m.format(format).toLocaleUpperCase(), format, true);
13941 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
13942 }
db71a655
KM
13943 r = moment(m.format(format).toLocaleLowerCase(), format, true);
13944 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
13945 }
13946
13947 for (i = 0; i < 12; ++i) {
13948 m = moment([2015, i, 15, 18]);
13949 tester('MMM');
13950 tester('MMM.');
13951 tester('MMMM');
13952 tester('MMMM.');
13953 }
13954 });
d6651c21 13955
db71a655
KM
13956 test('weekday parsing correctness', function (assert) {
13957 var i, m;
13958
96d0d679 13959 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
13960 // tr, az: There is a lower-case letter (ı), that converted to
13961 // upper then lower changes to i
13962 // ro: there is the letter ț which behaves weird under IE8
13963 // mt: letter Ħ
96d0d679 13964 // ga: month with spaces
c58511b9 13965 assert.expect(0);
db71a655
KM
13966 return;
13967 }
13968 function tester(format) {
13969 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
13970 r = moment(m.format(format), format);
13971 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
13972 if (locale !== 'ka') {
13973 r = moment(m.format(format).toLocaleUpperCase(), format);
13974 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
13975 }
db71a655
KM
13976 r = moment(m.format(format).toLocaleLowerCase(), format);
13977 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
13978 r = moment(m.format(format), format, true);
13979 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
13980 if (locale !== 'ka') {
13981 r = moment(m.format(format).toLocaleUpperCase(), format, true);
13982 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
13983 }
db71a655
KM
13984 r = moment(m.format(format).toLocaleLowerCase(), format, true);
13985 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
13986 }
13987
13988 for (i = 0; i < 7; ++i) {
13989 m = moment.utc([2015, 0, i + 1, 18]);
13990 tester('dd');
13991 tester('ddd');
13992 tester('dddd');
13993 }
13994 });
d6651c21 13995
db71a655
KM
13996 test('valid localeData', function (assert) {
13997 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
13998 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
13999 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
14000 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
14001 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
14002 });
96d0d679
KM
14003
14004 test('localeData weekdays can localeSort', function (assert) {
14005 var weekdays = moment().localeData().weekdays();
14006 var weekdaysShort = moment().localeData().weekdaysShort();
14007 var weekdaysMin = moment().localeData().weekdaysMin();
14008 var shift = moment().localeData()._week.dow;
14009 assert.deepEqual(
14010 moment().localeData().weekdays(true),
14011 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
14012 'weekdays should localeSort');
14013 assert.deepEqual(
14014 moment().localeData().weekdaysShort(true),
14015 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
14016 'weekdaysShort should localeSort');
14017 assert.deepEqual(
14018 moment().localeData().weekdaysMin(true),
14019 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
14020 'weekdaysMin should localeSort');
14021 });
db71a655 14022 }
d6651c21 14023
db71a655
KM
14024 /*global QUnit:false*/
14025
db71a655
KM
14026 function localeModule (name, lifecycle) {
14027 QUnit.module('locale:' + name, {
c58511b9 14028 beforeEach : function () {
db71a655
KM
14029 moment.locale(name);
14030 moment.createFromInputFallback = function (config) {
14031 throw new Error('input not handled by moment: ' + config._i);
14032 };
14033 setupDeprecationHandler(test, moment, 'locale');
14034 if (lifecycle && lifecycle.setup) {
14035 lifecycle.setup();
14036 }
14037 },
c58511b9 14038 afterEach : function () {
db71a655
KM
14039 moment.locale('en');
14040 teardownDeprecationHandler(test, moment, 'locale');
14041 if (lifecycle && lifecycle.teardown) {
14042 lifecycle.teardown();
14043 }
516f5f67
IC
14044 }
14045 });
db71a655
KM
14046 defineCommonLocaleTests(name, -1, -1);
14047 }
14048
96d0d679 14049 localeModule('en-au');
db71a655
KM
14050
14051 test('parse', function (assert) {
96d0d679 14052 var tests = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_'), i;
db71a655
KM
14053 function equalTest(input, mmm, i) {
14054 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
14055 }
db71a655
KM
14056 for (i = 0; i < 12; i++) {
14057 tests[i] = tests[i].split(' ');
14058 equalTest(tests[i][0], 'MMM', i);
14059 equalTest(tests[i][1], 'MMM', i);
14060 equalTest(tests[i][0], 'MMMM', i);
14061 equalTest(tests[i][1], 'MMMM', i);
14062 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
14063 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
14064 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
14065 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
14066 }
14067 });
14068
14069 test('format', function (assert) {
14070 var a = [
14071 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Sunday, February 14th 2010, 3:25:50 pm'],
14072 ['ddd, hA', 'Sun, 3PM'],
14073 ['M Mo MM MMMM MMM', '2 2nd 02 February Feb'],
14074 ['YYYY YY', '2010 10'],
14075 ['D Do DD', '14 14th 14'],
14076 ['d do dddd ddd dd', '0 0th Sunday Sun Su'],
14077 ['DDD DDDo DDDD', '45 45th 045'],
96d0d679 14078 ['w wo ww', '6 6th 06'],
db71a655
KM
14079 ['h hh', '3 03'],
14080 ['H HH', '15 15'],
14081 ['m mm', '25 25'],
14082 ['s ss', '50 50'],
14083 ['a A', 'pm PM'],
14084 ['[the] DDDo [day of the year]', 'the 45th day of the year'],
db71a655 14085 ['LTS', '3:25:50 PM'],
96d0d679
KM
14086 ['L', '14/02/2010'],
14087 ['LL', '14 February 2010'],
14088 ['LLL', '14 February 2010 3:25 PM'],
14089 ['LLLL', 'Sunday, 14 February 2010 3:25 PM'],
14090 ['l', '14/2/2010'],
14091 ['ll', '14 Feb 2010'],
14092 ['lll', '14 Feb 2010 3:25 PM'],
14093 ['llll', 'Sun, 14 Feb 2010 3:25 PM']
db71a655
KM
14094 ],
14095 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
14096 i;
db71a655
KM
14097 for (i = 0; i < a.length; i++) {
14098 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
14099 }
14100 });
14101
14102 test('format ordinal', function (assert) {
14103 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1st', '1st');
14104 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2nd', '2nd');
14105 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3rd', '3rd');
14106 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4th', '4th');
14107 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5th', '5th');
14108 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6th', '6th');
14109 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7th', '7th');
14110 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8th', '8th');
14111 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9th', '9th');
14112 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10th', '10th');
14113
14114 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11th', '11th');
14115 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12th', '12th');
14116 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13th', '13th');
14117 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14th', '14th');
14118 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15th', '15th');
14119 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16th', '16th');
14120 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17th', '17th');
14121 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18th', '18th');
14122 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19th', '19th');
14123 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20th', '20th');
14124
14125 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21st', '21st');
14126 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22nd', '22nd');
14127 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23rd', '23rd');
14128 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24th', '24th');
14129 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25th', '25th');
14130 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26th', '26th');
14131 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27th', '27th');
14132 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28th', '28th');
14133 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29th', '29th');
14134 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30th', '30th');
14135
14136 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31st', '31st');
14137 });
14138
14139 test('format month', function (assert) {
96d0d679 14140 var expected = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_'), i;
db71a655
KM
14141 for (i = 0; i < expected.length; i++) {
14142 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
14143 }
14144 });
14145
14146 test('format week', function (assert) {
96d0d679 14147 var expected = 'Sunday Sun Su_Monday Mon Mo_Tuesday Tue Tu_Wednesday Wed We_Thursday Thu Th_Friday Fri Fr_Saturday Sat Sa'.split('_'), i;
db71a655
KM
14148 for (i = 0; i < expected.length; i++) {
14149 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
14150 }
14151 });
14152
14153 test('from', function (assert) {
14154 var start = moment([2007, 1, 28]);
14155 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'a few seconds', '44 seconds = a few seconds');
14156 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'a minute', '45 seconds = a minute');
14157 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'a minute', '89 seconds = a minute');
14158 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes');
14159 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes');
14160 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'an hour', '45 minutes = an hour');
14161 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'an hour', '89 minutes = an hour');
14162 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hours', '90 minutes = 2 hours');
14163 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hours', '5 hours = 5 hours');
14164 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hours', '21 hours = 21 hours');
14165 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'a day', '22 hours = a day');
14166 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'a day', '35 hours = a day');
14167 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 days', '36 hours = 2 days');
14168 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'a day', '1 day = a day');
14169 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 days', '5 days = 5 days');
14170 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 days', '25 days = 25 days');
14171 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'a month', '26 days = a month');
14172 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'a month', '30 days = a month');
14173 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'a month', '43 days = a month');
14174 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 months', '46 days = 2 months');
14175 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 months', '75 days = 2 months');
14176 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 months', '76 days = 3 months');
14177 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'a month', '1 month = a month');
14178 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 months', '5 months = 5 months');
14179 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'a year', '345 days = a year');
14180 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 years', '548 days = 2 years');
14181 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'a year', '1 year = a year');
14182 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 years', '5 years = 5 years');
14183 });
14184
14185 test('suffix', function (assert) {
14186 assert.equal(moment(30000).from(0), 'in a few seconds', 'prefix');
14187 assert.equal(moment(0).from(30000), 'a few seconds ago', 'suffix');
14188 });
14189
14190 test('now from now', function (assert) {
14191 assert.equal(moment().fromNow(), 'a few seconds ago', 'now from now should display as in the past');
14192 });
14193
14194 test('fromNow', function (assert) {
14195 assert.equal(moment().add({s: 30}).fromNow(), 'in a few seconds', 'in a few seconds');
14196 assert.equal(moment().add({d: 5}).fromNow(), 'in 5 days', 'in 5 days');
14197 });
14198
14199 test('calendar day', function (assert) {
14200 var a = moment().hours(12).minutes(0).seconds(0);
14201
14202 assert.equal(moment(a).calendar(), 'Today at 12:00 PM', 'today at the same time');
14203 assert.equal(moment(a).add({m: 25}).calendar(), 'Today at 12:25 PM', 'Now plus 25 min');
14204 assert.equal(moment(a).add({h: 1}).calendar(), 'Today at 1:00 PM', 'Now plus 1 hour');
14205 assert.equal(moment(a).add({d: 1}).calendar(), 'Tomorrow at 12:00 PM', 'tomorrow at the same time');
14206 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Today at 11:00 AM', 'Now minus 1 hour');
14207 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Yesterday at 12:00 PM', 'yesterday at the same time');
14208 });
14209
14210 test('calendar next week', function (assert) {
14211 var i, m;
db71a655
KM
14212 for (i = 2; i < 7; i++) {
14213 m = moment().add({d: i});
14214 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days current time');
14215 m.hours(0).minutes(0).seconds(0).milliseconds(0);
14216 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days beginning of day');
14217 m.hours(23).minutes(59).seconds(59).milliseconds(999);
14218 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days end of day');
516f5f67 14219 }
db71a655
KM
14220 });
14221
14222 test('calendar last week', function (assert) {
14223 var i, m;
14224
14225 for (i = 2; i < 7; i++) {
14226 m = moment().subtract({d: i});
14227 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days current time');
14228 m.hours(0).minutes(0).seconds(0).milliseconds(0);
14229 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days beginning of day');
14230 m.hours(23).minutes(59).seconds(59).milliseconds(999);
14231 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days end of day');
73f3c911 14232 }
db71a655 14233 });
516f5f67 14234
db71a655
KM
14235 test('calendar all else', function (assert) {
14236 var weeksAgo = moment().subtract({w: 1}),
14237 weeksFromNow = moment().add({w: 1});
516f5f67 14238
db71a655
KM
14239 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
14240 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 14241
db71a655
KM
14242 weeksAgo = moment().subtract({w: 2});
14243 weeksFromNow = moment().add({w: 2});
516f5f67 14244
db71a655
KM
14245 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
14246 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
14247 });
516f5f67 14248
96d0d679
KM
14249 test('weeks year starting sunday formatted', function (assert) {
14250 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52nd', 'Jan 1 2012 should be week 52');
14251 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1st', 'Jan 2 2012 should be week 1');
14252 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1st', 'Jan 8 2012 should be week 1');
14253 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2nd', 'Jan 9 2012 should be week 2');
14254 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2nd', 'Jan 15 2012 should be week 2');
14255 });
14256
14257 // Concrete test for Locale#weekdaysMin
14258 test('Weekdays sort by locale', function (assert) {
14259 assert.deepEqual(
14260 moment().localeData('en-au').weekdays(),
14261 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'),
14262 'weekdays start on Sunday');
14263 assert.deepEqual(
14264 moment().localeData('en-au').weekdays(true),
14265 'Monday_Tuesday_Wednesday_Thursday_Friday_Saturday_Sunday'.split('_'),
14266 'locale-sorted weekdays start on Monday');
14267 assert.deepEqual(
14268 moment().localeData('en-au').weekdaysShort(),
14269 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'),
14270 'weekdaysShort start on Sunday');
14271 assert.deepEqual(
14272 moment().localeData('en-au').weekdaysShort(true),
14273 'Mon_Tue_Wed_Thu_Fri_Sat_Sun'.split('_'),
14274 'locale-sorted weekdaysShort start on Monday');
14275 assert.deepEqual(
14276 moment().localeData('en-au').weekdaysMin(),
14277 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'),
14278 'weekdaysMin start on Sunday');
14279 assert.deepEqual(
14280 moment().localeData('en-au').weekdaysMin(true),
14281 'Mo_Tu_We_Th_Fr_Sa_Su'.split('_'),
14282 'locale-sorted weekdaysMin start on Monday');
db71a655 14283 });
73f3c911
IC
14284
14285})));
516f5f67 14286
516f5f67 14287
c74a101d
IC
14288;(function (global, factory) {
14289 typeof exports === 'object' && typeof module !== 'undefined'
14290 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
14291 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
14292 factory(global.moment)
73f3c911 14293}(this, (function (moment) { 'use strict';
516f5f67 14294
db71a655
KM
14295 function each(array, callback) {
14296 var i;
14297 for (i = 0; i < array.length; i++) {
14298 callback(array[i], i, array);
14299 }
b135bf1a
IC
14300 }
14301
c58511b9
KM
14302 function setupDeprecationHandler(test, moment$$1, scope) {
14303 test._expectedDeprecations = null;
14304 test._observedDeprecations = null;
14305 test._oldSupress = moment$$1.suppressDeprecationWarnings;
14306 moment$$1.suppressDeprecationWarnings = true;
14307 test.expectedDeprecations = function () {
14308 test._expectedDeprecations = arguments;
14309 test._observedDeprecations = [];
14310 };
14311 moment$$1.deprecationHandler = function (name, msg) {
14312 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
14313 if (deprecationId === -1) {
14314 throw new Error('Unexpected deprecation thrown name=' +
14315 name + ' msg=' + msg);
14316 }
14317 test._observedDeprecations[deprecationId] = 1;
14318 };
14319 }
14320
14321 function teardownDeprecationHandler(test, moment$$1, scope) {
14322 moment$$1.suppressDeprecationWarnings = test._oldSupress;
14323
14324 if (test._expectedDeprecations != null) {
14325 var missedDeprecations = [];
14326 each(test._expectedDeprecations, function (deprecationPattern, id) {
14327 if (test._observedDeprecations[id] !== 1) {
14328 missedDeprecations.push(deprecationPattern);
14329 }
14330 });
14331 if (missedDeprecations.length !== 0) {
14332 throw new Error('Expected deprecation warnings did not happen: ' +
14333 missedDeprecations.join(' '));
14334 }
14335 }
14336 }
14337
14338 function matchedDeprecation(name, msg, deprecations) {
14339 if (deprecations == null) {
14340 return -1;
14341 }
14342 for (var i = 0; i < deprecations.length; ++i) {
14343 if (name != null && name === deprecations[i]) {
14344 return i;
14345 }
14346 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
14347 return i;
14348 }
14349 }
14350 return -1;
14351 }
14352
14353 /*global QUnit:false*/
14354
14355 var test = QUnit.test;
14356
db71a655
KM
14357 function objectKeys(obj) {
14358 if (Object.keys) {
14359 return Object.keys(obj);
14360 } else {
14361 // IE8
14362 var res = [], i;
14363 for (i in obj) {
14364 if (obj.hasOwnProperty(i)) {
14365 res.push(i);
14366 }
b135bf1a 14367 }
db71a655 14368 return res;
b135bf1a 14369 }
b135bf1a
IC
14370 }
14371
db71a655 14372 // Pick the first defined of two or three arguments.
b135bf1a 14373
db71a655
KM
14374 function defineCommonLocaleTests(locale, options) {
14375 test('lenient day of month ordinal parsing', function (assert) {
14376 var i, ordinalStr, testMoment;
14377 for (i = 1; i <= 31; ++i) {
14378 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
14379 testMoment = moment(ordinalStr, 'YYYY MM Do');
14380 assert.equal(testMoment.year(), 2014,
14381 'lenient day of month ordinal parsing ' + i + ' year check');
14382 assert.equal(testMoment.month(), 0,
14383 'lenient day of month ordinal parsing ' + i + ' month check');
14384 assert.equal(testMoment.date(), i,
14385 'lenient day of month ordinal parsing ' + i + ' date check');
14386 }
14387 });
b135bf1a 14388
db71a655
KM
14389 test('lenient day of month ordinal parsing of number', function (assert) {
14390 var i, testMoment;
14391 for (i = 1; i <= 31; ++i) {
14392 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
14393 assert.equal(testMoment.year(), 2014,
14394 'lenient day of month ordinal parsing of number ' + i + ' year check');
14395 assert.equal(testMoment.month(), 0,
14396 'lenient day of month ordinal parsing of number ' + i + ' month check');
14397 assert.equal(testMoment.date(), i,
14398 'lenient day of month ordinal parsing of number ' + i + ' date check');
14399 }
14400 });
b135bf1a 14401
db71a655
KM
14402 test('strict day of month ordinal parsing', function (assert) {
14403 var i, ordinalStr, testMoment;
14404 for (i = 1; i <= 31; ++i) {
14405 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
14406 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
14407 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
14408 }
14409 });
b135bf1a 14410
db71a655
KM
14411 test('meridiem invariant', function (assert) {
14412 var h, m, t1, t2;
14413 for (h = 0; h < 24; ++h) {
14414 for (m = 0; m < 60; m += 15) {
14415 t1 = moment.utc([2000, 0, 1, h, m]);
14416 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
14417 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
14418 'meridiem at ' + t1.format('HH:mm'));
14419 }
14420 }
14421 });
14422
14423 test('date format correctness', function (assert) {
14424 var data, tokens;
14425 data = moment.localeData()._longDateFormat;
14426 tokens = objectKeys(data);
14427 each(tokens, function (srchToken) {
14428 // Check each format string to make sure it does not contain any
14429 // tokens that need to be expanded.
14430 each(tokens, function (baseToken) {
14431 // strip escaped sequences
14432 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
14433 assert.equal(false, !!~format.indexOf(srchToken),
14434 'contains ' + srchToken + ' in ' + baseToken);
14435 });
b135bf1a
IC
14436 });
14437 });
d6651c21 14438
db71a655
KM
14439 test('month parsing correctness', function (assert) {
14440 var i, m;
14441
14442 if (locale === 'tr') {
14443 // I can't fix it :(
c58511b9 14444 assert.expect(0);
db71a655
KM
14445 return;
14446 }
14447 function tester(format) {
14448 var r;
14449 r = moment(m.format(format), format);
14450 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
14451 if (locale !== 'ka') {
14452 r = moment(m.format(format).toLocaleUpperCase(), format);
14453 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
14454 }
db71a655
KM
14455 r = moment(m.format(format).toLocaleLowerCase(), format);
14456 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
14457
14458 r = moment(m.format(format), format, true);
14459 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
14460 if (locale !== 'ka') {
14461 r = moment(m.format(format).toLocaleUpperCase(), format, true);
14462 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
14463 }
db71a655
KM
14464 r = moment(m.format(format).toLocaleLowerCase(), format, true);
14465 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
14466 }
14467
14468 for (i = 0; i < 12; ++i) {
14469 m = moment([2015, i, 15, 18]);
14470 tester('MMM');
14471 tester('MMM.');
14472 tester('MMMM');
14473 tester('MMMM.');
14474 }
14475 });
d6651c21 14476
db71a655
KM
14477 test('weekday parsing correctness', function (assert) {
14478 var i, m;
14479
96d0d679 14480 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
14481 // tr, az: There is a lower-case letter (ı), that converted to
14482 // upper then lower changes to i
14483 // ro: there is the letter ț which behaves weird under IE8
14484 // mt: letter Ħ
96d0d679 14485 // ga: month with spaces
c58511b9 14486 assert.expect(0);
db71a655
KM
14487 return;
14488 }
14489 function tester(format) {
14490 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
14491 r = moment(m.format(format), format);
14492 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
14493 if (locale !== 'ka') {
14494 r = moment(m.format(format).toLocaleUpperCase(), format);
14495 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
14496 }
db71a655
KM
14497 r = moment(m.format(format).toLocaleLowerCase(), format);
14498 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
14499 r = moment(m.format(format), format, true);
14500 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
14501 if (locale !== 'ka') {
14502 r = moment(m.format(format).toLocaleUpperCase(), format, true);
14503 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
14504 }
db71a655
KM
14505 r = moment(m.format(format).toLocaleLowerCase(), format, true);
14506 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
14507 }
14508
14509 for (i = 0; i < 7; ++i) {
14510 m = moment.utc([2015, 0, i + 1, 18]);
14511 tester('dd');
14512 tester('ddd');
14513 tester('dddd');
14514 }
14515 });
d6651c21 14516
db71a655
KM
14517 test('valid localeData', function (assert) {
14518 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
14519 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
14520 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
14521 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
14522 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
14523 });
96d0d679
KM
14524
14525 test('localeData weekdays can localeSort', function (assert) {
14526 var weekdays = moment().localeData().weekdays();
14527 var weekdaysShort = moment().localeData().weekdaysShort();
14528 var weekdaysMin = moment().localeData().weekdaysMin();
14529 var shift = moment().localeData()._week.dow;
14530 assert.deepEqual(
14531 moment().localeData().weekdays(true),
14532 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
14533 'weekdays should localeSort');
14534 assert.deepEqual(
14535 moment().localeData().weekdaysShort(true),
14536 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
14537 'weekdaysShort should localeSort');
14538 assert.deepEqual(
14539 moment().localeData().weekdaysMin(true),
14540 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
14541 'weekdaysMin should localeSort');
14542 });
db71a655 14543 }
d6651c21 14544
db71a655
KM
14545 /*global QUnit:false*/
14546
db71a655
KM
14547 function localeModule (name, lifecycle) {
14548 QUnit.module('locale:' + name, {
c58511b9 14549 beforeEach : function () {
db71a655
KM
14550 moment.locale(name);
14551 moment.createFromInputFallback = function (config) {
14552 throw new Error('input not handled by moment: ' + config._i);
14553 };
14554 setupDeprecationHandler(test, moment, 'locale');
14555 if (lifecycle && lifecycle.setup) {
14556 lifecycle.setup();
14557 }
14558 },
c58511b9 14559 afterEach : function () {
db71a655
KM
14560 moment.locale('en');
14561 teardownDeprecationHandler(test, moment, 'locale');
14562 if (lifecycle && lifecycle.teardown) {
14563 lifecycle.teardown();
14564 }
516f5f67
IC
14565 }
14566 });
db71a655
KM
14567 defineCommonLocaleTests(name, -1, -1);
14568 }
14569
96d0d679 14570 localeModule('en-ca');
db71a655
KM
14571
14572 test('parse', function (assert) {
96d0d679
KM
14573 var i,
14574 tests = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_');
14575
db71a655
KM
14576 function equalTest(input, mmm, i) {
14577 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
14578 }
96d0d679 14579
db71a655
KM
14580 for (i = 0; i < 12; i++) {
14581 tests[i] = tests[i].split(' ');
14582 equalTest(tests[i][0], 'MMM', i);
14583 equalTest(tests[i][1], 'MMM', i);
14584 equalTest(tests[i][0], 'MMMM', i);
14585 equalTest(tests[i][1], 'MMMM', i);
14586 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
14587 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
14588 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
14589 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
14590 }
14591 });
14592
14593 test('format', function (assert) {
14594 var a = [
14595 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Sunday, February 14th 2010, 3:25:50 pm'],
14596 ['ddd, hA', 'Sun, 3PM'],
14597 ['M Mo MM MMMM MMM', '2 2nd 02 February Feb'],
14598 ['YYYY YY', '2010 10'],
14599 ['D Do DD', '14 14th 14'],
14600 ['d do dddd ddd dd', '0 0th Sunday Sun Su'],
14601 ['DDD DDDo DDDD', '45 45th 045'],
96d0d679 14602 ['w wo ww', '8 8th 08'],
db71a655
KM
14603 ['h hh', '3 03'],
14604 ['H HH', '15 15'],
14605 ['m mm', '25 25'],
14606 ['s ss', '50 50'],
14607 ['a A', 'pm PM'],
14608 ['[the] DDDo [day of the year]', 'the 45th day of the year'],
96d0d679
KM
14609 ['L', '2010-02-14'],
14610 ['LTS', '3:25:50 PM'],
14611 ['LL', 'February 14, 2010'],
14612 ['LLL', 'February 14, 2010 3:25 PM'],
14613 ['LLLL', 'Sunday, February 14, 2010 3:25 PM'],
14614 ['l', '2010-2-14'],
14615 ['ll', 'Feb 14, 2010'],
14616 ['lll', 'Feb 14, 2010 3:25 PM'],
14617 ['llll', 'Sun, Feb 14, 2010 3:25 PM']
db71a655
KM
14618 ],
14619 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
14620 i;
96d0d679 14621
db71a655
KM
14622 for (i = 0; i < a.length; i++) {
14623 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
14624 }
14625 });
14626
14627 test('format ordinal', function (assert) {
14628 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1st', '1st');
14629 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2nd', '2nd');
14630 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3rd', '3rd');
14631 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4th', '4th');
14632 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5th', '5th');
14633 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6th', '6th');
14634 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7th', '7th');
14635 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8th', '8th');
14636 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9th', '9th');
14637 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10th', '10th');
14638
14639 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11th', '11th');
14640 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12th', '12th');
14641 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13th', '13th');
14642 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14th', '14th');
14643 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15th', '15th');
14644 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16th', '16th');
14645 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17th', '17th');
14646 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18th', '18th');
14647 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19th', '19th');
14648 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20th', '20th');
14649
14650 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21st', '21st');
14651 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22nd', '22nd');
14652 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23rd', '23rd');
14653 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24th', '24th');
14654 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25th', '25th');
14655 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26th', '26th');
14656 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27th', '27th');
14657 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28th', '28th');
14658 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29th', '29th');
14659 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30th', '30th');
14660
14661 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31st', '31st');
14662 });
14663
14664 test('format month', function (assert) {
96d0d679
KM
14665 var i,
14666 expected = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_');
14667
db71a655
KM
14668 for (i = 0; i < expected.length; i++) {
14669 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
14670 }
14671 });
14672
14673 test('format week', function (assert) {
96d0d679
KM
14674 var i,
14675 expected = 'Sunday Sun Su_Monday Mon Mo_Tuesday Tue Tu_Wednesday Wed We_Thursday Thu Th_Friday Fri Fr_Saturday Sat Sa'.split('_');
14676
db71a655
KM
14677 for (i = 0; i < expected.length; i++) {
14678 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
14679 }
14680 });
14681
14682 test('from', function (assert) {
14683 var start = moment([2007, 1, 28]);
14684 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'a few seconds', '44 seconds = a few seconds');
14685 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'a minute', '45 seconds = a minute');
14686 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'a minute', '89 seconds = a minute');
14687 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes');
14688 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes');
14689 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'an hour', '45 minutes = an hour');
14690 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'an hour', '89 minutes = an hour');
14691 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hours', '90 minutes = 2 hours');
14692 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hours', '5 hours = 5 hours');
14693 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hours', '21 hours = 21 hours');
14694 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'a day', '22 hours = a day');
14695 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'a day', '35 hours = a day');
14696 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 days', '36 hours = 2 days');
14697 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'a day', '1 day = a day');
14698 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 days', '5 days = 5 days');
14699 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 days', '25 days = 25 days');
14700 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'a month', '26 days = a month');
14701 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'a month', '30 days = a month');
14702 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'a month', '43 days = a month');
14703 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 months', '46 days = 2 months');
14704 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 months', '75 days = 2 months');
14705 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 months', '76 days = 3 months');
14706 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'a month', '1 month = a month');
14707 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 months', '5 months = 5 months');
14708 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'a year', '345 days = a year');
14709 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 years', '548 days = 2 years');
14710 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'a year', '1 year = a year');
14711 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 years', '5 years = 5 years');
14712 });
14713
14714 test('suffix', function (assert) {
14715 assert.equal(moment(30000).from(0), 'in a few seconds', 'prefix');
14716 assert.equal(moment(0).from(30000), 'a few seconds ago', 'suffix');
14717 });
14718
14719 test('now from now', function (assert) {
14720 assert.equal(moment().fromNow(), 'a few seconds ago', 'now from now should display as in the past');
14721 });
14722
14723 test('fromNow', function (assert) {
14724 assert.equal(moment().add({s: 30}).fromNow(), 'in a few seconds', 'in a few seconds');
14725 assert.equal(moment().add({d: 5}).fromNow(), 'in 5 days', 'in 5 days');
14726 });
14727
14728 test('calendar day', function (assert) {
14729 var a = moment().hours(12).minutes(0).seconds(0);
14730
96d0d679
KM
14731 assert.equal(moment(a).calendar(), 'Today at 12:00 PM', 'today at the same time');
14732 assert.equal(moment(a).add({m: 25}).calendar(), 'Today at 12:25 PM', 'Now plus 25 min');
14733 assert.equal(moment(a).add({h: 1}).calendar(), 'Today at 1:00 PM', 'Now plus 1 hour');
14734 assert.equal(moment(a).add({d: 1}).calendar(), 'Tomorrow at 12:00 PM', 'tomorrow at the same time');
14735 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Today at 11:00 AM', 'Now minus 1 hour');
14736 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Yesterday at 12:00 PM', 'yesterday at the same time');
db71a655
KM
14737 });
14738
14739 test('calendar next week', function (assert) {
14740 var i, m;
96d0d679 14741
db71a655
KM
14742 for (i = 2; i < 7; i++) {
14743 m = moment().add({d: i});
14744 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days current time');
14745 m.hours(0).minutes(0).seconds(0).milliseconds(0);
14746 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days beginning of day');
14747 m.hours(23).minutes(59).seconds(59).milliseconds(999);
14748 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days end of day');
73f3c911 14749 }
db71a655 14750 });
516f5f67 14751
db71a655
KM
14752 test('calendar last week', function (assert) {
14753 var i, m;
14754
14755 for (i = 2; i < 7; i++) {
14756 m = moment().subtract({d: i});
14757 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days current time');
14758 m.hours(0).minutes(0).seconds(0).milliseconds(0);
14759 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days beginning of day');
14760 m.hours(23).minutes(59).seconds(59).milliseconds(999);
14761 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days end of day');
516f5f67 14762 }
db71a655 14763 });
516f5f67 14764
db71a655
KM
14765 test('calendar all else', function (assert) {
14766 var weeksAgo = moment().subtract({w: 1}),
14767 weeksFromNow = moment().add({w: 1});
516f5f67 14768
db71a655
KM
14769 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
14770 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 14771
db71a655
KM
14772 weeksAgo = moment().subtract({w: 2});
14773 weeksFromNow = moment().add({w: 2});
516f5f67 14774
db71a655
KM
14775 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
14776 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
14777 });
14778
96d0d679
KM
14779 test('weeks year starting sunday format', function (assert) {
14780 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1st', 'Jan 1 2012 should be week 1');
14781 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1st', 'Jan 7 2012 should be week 1');
14782 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2nd', 'Jan 8 2012 should be week 2');
14783 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2nd', 'Jan 14 2012 should be week 2');
14784 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3rd', 'Jan 15 2012 should be week 3');
db71a655 14785 });
73f3c911
IC
14786
14787})));
14788
516f5f67 14789
c74a101d
IC
14790;(function (global, factory) {
14791 typeof exports === 'object' && typeof module !== 'undefined'
14792 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
14793 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
14794 factory(global.moment)
73f3c911 14795}(this, (function (moment) { 'use strict';
516f5f67 14796
db71a655
KM
14797 function each(array, callback) {
14798 var i;
14799 for (i = 0; i < array.length; i++) {
14800 callback(array[i], i, array);
14801 }
b135bf1a
IC
14802 }
14803
c58511b9
KM
14804 function setupDeprecationHandler(test, moment$$1, scope) {
14805 test._expectedDeprecations = null;
14806 test._observedDeprecations = null;
14807 test._oldSupress = moment$$1.suppressDeprecationWarnings;
14808 moment$$1.suppressDeprecationWarnings = true;
14809 test.expectedDeprecations = function () {
14810 test._expectedDeprecations = arguments;
14811 test._observedDeprecations = [];
14812 };
14813 moment$$1.deprecationHandler = function (name, msg) {
14814 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
14815 if (deprecationId === -1) {
14816 throw new Error('Unexpected deprecation thrown name=' +
14817 name + ' msg=' + msg);
14818 }
14819 test._observedDeprecations[deprecationId] = 1;
14820 };
14821 }
14822
14823 function teardownDeprecationHandler(test, moment$$1, scope) {
14824 moment$$1.suppressDeprecationWarnings = test._oldSupress;
14825
14826 if (test._expectedDeprecations != null) {
14827 var missedDeprecations = [];
14828 each(test._expectedDeprecations, function (deprecationPattern, id) {
14829 if (test._observedDeprecations[id] !== 1) {
14830 missedDeprecations.push(deprecationPattern);
14831 }
14832 });
14833 if (missedDeprecations.length !== 0) {
14834 throw new Error('Expected deprecation warnings did not happen: ' +
14835 missedDeprecations.join(' '));
14836 }
14837 }
14838 }
14839
14840 function matchedDeprecation(name, msg, deprecations) {
14841 if (deprecations == null) {
14842 return -1;
14843 }
14844 for (var i = 0; i < deprecations.length; ++i) {
14845 if (name != null && name === deprecations[i]) {
14846 return i;
14847 }
14848 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
14849 return i;
14850 }
14851 }
14852 return -1;
14853 }
14854
14855 /*global QUnit:false*/
14856
14857 var test = QUnit.test;
14858
db71a655
KM
14859 function objectKeys(obj) {
14860 if (Object.keys) {
14861 return Object.keys(obj);
14862 } else {
14863 // IE8
14864 var res = [], i;
14865 for (i in obj) {
14866 if (obj.hasOwnProperty(i)) {
14867 res.push(i);
14868 }
b135bf1a 14869 }
db71a655 14870 return res;
b135bf1a 14871 }
b135bf1a
IC
14872 }
14873
db71a655 14874 // Pick the first defined of two or three arguments.
b135bf1a 14875
db71a655
KM
14876 function defineCommonLocaleTests(locale, options) {
14877 test('lenient day of month ordinal parsing', function (assert) {
14878 var i, ordinalStr, testMoment;
14879 for (i = 1; i <= 31; ++i) {
14880 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
14881 testMoment = moment(ordinalStr, 'YYYY MM Do');
14882 assert.equal(testMoment.year(), 2014,
14883 'lenient day of month ordinal parsing ' + i + ' year check');
14884 assert.equal(testMoment.month(), 0,
14885 'lenient day of month ordinal parsing ' + i + ' month check');
14886 assert.equal(testMoment.date(), i,
14887 'lenient day of month ordinal parsing ' + i + ' date check');
14888 }
14889 });
b135bf1a 14890
db71a655
KM
14891 test('lenient day of month ordinal parsing of number', function (assert) {
14892 var i, testMoment;
14893 for (i = 1; i <= 31; ++i) {
14894 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
14895 assert.equal(testMoment.year(), 2014,
14896 'lenient day of month ordinal parsing of number ' + i + ' year check');
14897 assert.equal(testMoment.month(), 0,
14898 'lenient day of month ordinal parsing of number ' + i + ' month check');
14899 assert.equal(testMoment.date(), i,
14900 'lenient day of month ordinal parsing of number ' + i + ' date check');
14901 }
14902 });
b135bf1a 14903
db71a655
KM
14904 test('strict day of month ordinal parsing', function (assert) {
14905 var i, ordinalStr, testMoment;
14906 for (i = 1; i <= 31; ++i) {
14907 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
14908 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
14909 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
14910 }
14911 });
b135bf1a 14912
db71a655
KM
14913 test('meridiem invariant', function (assert) {
14914 var h, m, t1, t2;
14915 for (h = 0; h < 24; ++h) {
14916 for (m = 0; m < 60; m += 15) {
14917 t1 = moment.utc([2000, 0, 1, h, m]);
14918 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
14919 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
14920 'meridiem at ' + t1.format('HH:mm'));
14921 }
14922 }
14923 });
14924
14925 test('date format correctness', function (assert) {
14926 var data, tokens;
14927 data = moment.localeData()._longDateFormat;
14928 tokens = objectKeys(data);
14929 each(tokens, function (srchToken) {
14930 // Check each format string to make sure it does not contain any
14931 // tokens that need to be expanded.
14932 each(tokens, function (baseToken) {
14933 // strip escaped sequences
14934 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
14935 assert.equal(false, !!~format.indexOf(srchToken),
14936 'contains ' + srchToken + ' in ' + baseToken);
14937 });
b135bf1a
IC
14938 });
14939 });
d6651c21 14940
db71a655
KM
14941 test('month parsing correctness', function (assert) {
14942 var i, m;
14943
14944 if (locale === 'tr') {
14945 // I can't fix it :(
c58511b9 14946 assert.expect(0);
db71a655
KM
14947 return;
14948 }
14949 function tester(format) {
14950 var r;
14951 r = moment(m.format(format), format);
14952 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
14953 if (locale !== 'ka') {
14954 r = moment(m.format(format).toLocaleUpperCase(), format);
14955 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
14956 }
db71a655
KM
14957 r = moment(m.format(format).toLocaleLowerCase(), format);
14958 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
14959
14960 r = moment(m.format(format), format, true);
14961 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
14962 if (locale !== 'ka') {
14963 r = moment(m.format(format).toLocaleUpperCase(), format, true);
14964 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
14965 }
db71a655
KM
14966 r = moment(m.format(format).toLocaleLowerCase(), format, true);
14967 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
14968 }
14969
14970 for (i = 0; i < 12; ++i) {
14971 m = moment([2015, i, 15, 18]);
14972 tester('MMM');
14973 tester('MMM.');
14974 tester('MMMM');
14975 tester('MMMM.');
14976 }
14977 });
d6651c21 14978
db71a655
KM
14979 test('weekday parsing correctness', function (assert) {
14980 var i, m;
14981
96d0d679 14982 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
14983 // tr, az: There is a lower-case letter (ı), that converted to
14984 // upper then lower changes to i
14985 // ro: there is the letter ț which behaves weird under IE8
14986 // mt: letter Ħ
96d0d679 14987 // ga: month with spaces
c58511b9 14988 assert.expect(0);
db71a655
KM
14989 return;
14990 }
14991 function tester(format) {
14992 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
14993 r = moment(m.format(format), format);
14994 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
14995 if (locale !== 'ka') {
14996 r = moment(m.format(format).toLocaleUpperCase(), format);
14997 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
14998 }
db71a655
KM
14999 r = moment(m.format(format).toLocaleLowerCase(), format);
15000 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
15001 r = moment(m.format(format), format, true);
15002 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
15003 if (locale !== 'ka') {
15004 r = moment(m.format(format).toLocaleUpperCase(), format, true);
15005 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
15006 }
db71a655
KM
15007 r = moment(m.format(format).toLocaleLowerCase(), format, true);
15008 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
15009 }
15010
15011 for (i = 0; i < 7; ++i) {
15012 m = moment.utc([2015, 0, i + 1, 18]);
15013 tester('dd');
15014 tester('ddd');
15015 tester('dddd');
15016 }
15017 });
d6651c21 15018
db71a655
KM
15019 test('valid localeData', function (assert) {
15020 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
15021 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
15022 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
15023 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
15024 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
15025 });
96d0d679
KM
15026
15027 test('localeData weekdays can localeSort', function (assert) {
15028 var weekdays = moment().localeData().weekdays();
15029 var weekdaysShort = moment().localeData().weekdaysShort();
15030 var weekdaysMin = moment().localeData().weekdaysMin();
15031 var shift = moment().localeData()._week.dow;
15032 assert.deepEqual(
15033 moment().localeData().weekdays(true),
15034 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
15035 'weekdays should localeSort');
15036 assert.deepEqual(
15037 moment().localeData().weekdaysShort(true),
15038 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
15039 'weekdaysShort should localeSort');
15040 assert.deepEqual(
15041 moment().localeData().weekdaysMin(true),
15042 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
15043 'weekdaysMin should localeSort');
15044 });
db71a655 15045 }
d6651c21 15046
db71a655
KM
15047 /*global QUnit:false*/
15048
db71a655
KM
15049 function localeModule (name, lifecycle) {
15050 QUnit.module('locale:' + name, {
c58511b9 15051 beforeEach : function () {
db71a655
KM
15052 moment.locale(name);
15053 moment.createFromInputFallback = function (config) {
15054 throw new Error('input not handled by moment: ' + config._i);
15055 };
15056 setupDeprecationHandler(test, moment, 'locale');
15057 if (lifecycle && lifecycle.setup) {
15058 lifecycle.setup();
15059 }
15060 },
c58511b9 15061 afterEach : function () {
db71a655
KM
15062 moment.locale('en');
15063 teardownDeprecationHandler(test, moment, 'locale');
15064 if (lifecycle && lifecycle.teardown) {
15065 lifecycle.teardown();
15066 }
516f5f67
IC
15067 }
15068 });
db71a655
KM
15069 defineCommonLocaleTests(name, -1, -1);
15070 }
15071
96d0d679 15072 localeModule('en-gb');
db71a655
KM
15073
15074 test('parse', function (assert) {
15075 var tests = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_'), i;
15076 function equalTest(input, mmm, i) {
15077 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
15078 }
15079 for (i = 0; i < 12; i++) {
15080 tests[i] = tests[i].split(' ');
15081 equalTest(tests[i][0], 'MMM', i);
15082 equalTest(tests[i][1], 'MMM', i);
15083 equalTest(tests[i][0], 'MMMM', i);
15084 equalTest(tests[i][1], 'MMMM', i);
15085 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
15086 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
15087 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
15088 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
15089 }
15090 });
15091
15092 test('format', function (assert) {
15093 var a = [
15094 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Sunday, February 14th 2010, 3:25:50 pm'],
15095 ['ddd, hA', 'Sun, 3PM'],
15096 ['M Mo MM MMMM MMM', '2 2nd 02 February Feb'],
15097 ['YYYY YY', '2010 10'],
15098 ['D Do DD', '14 14th 14'],
15099 ['d do dddd ddd dd', '0 0th Sunday Sun Su'],
15100 ['DDD DDDo DDDD', '45 45th 045'],
15101 ['w wo ww', '6 6th 06'],
15102 ['h hh', '3 03'],
15103 ['H HH', '15 15'],
15104 ['m mm', '25 25'],
15105 ['s ss', '50 50'],
15106 ['a A', 'pm PM'],
15107 ['[the] DDDo [day of the year]', 'the 45th day of the year'],
15108 ['LTS', '15:25:50'],
96d0d679 15109 ['L', '14/02/2010'],
db71a655
KM
15110 ['LL', '14 February 2010'],
15111 ['LLL', '14 February 2010 15:25'],
96d0d679
KM
15112 ['LLLL', 'Sunday, 14 February 2010 15:25'],
15113 ['l', '14/2/2010'],
db71a655
KM
15114 ['ll', '14 Feb 2010'],
15115 ['lll', '14 Feb 2010 15:25'],
96d0d679 15116 ['llll', 'Sun, 14 Feb 2010 15:25']
db71a655
KM
15117 ],
15118 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
15119 i;
15120 for (i = 0; i < a.length; i++) {
15121 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
15122 }
15123 });
15124
15125 test('format ordinal', function (assert) {
15126 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1st', '1st');
15127 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2nd', '2nd');
15128 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3rd', '3rd');
15129 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4th', '4th');
15130 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5th', '5th');
15131 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6th', '6th');
15132 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7th', '7th');
15133 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8th', '8th');
15134 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9th', '9th');
15135 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10th', '10th');
15136
15137 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11th', '11th');
15138 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12th', '12th');
15139 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13th', '13th');
15140 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14th', '14th');
15141 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15th', '15th');
15142 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16th', '16th');
15143 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17th', '17th');
15144 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18th', '18th');
15145 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19th', '19th');
15146 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20th', '20th');
15147
15148 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21st', '21st');
15149 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22nd', '22nd');
15150 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23rd', '23rd');
15151 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24th', '24th');
15152 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25th', '25th');
15153 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26th', '26th');
15154 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27th', '27th');
15155 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28th', '28th');
15156 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29th', '29th');
15157 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30th', '30th');
15158
15159 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31st', '31st');
15160 });
15161
15162 test('format month', function (assert) {
15163 var expected = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_'), i;
15164 for (i = 0; i < expected.length; i++) {
15165 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
15166 }
15167 });
15168
15169 test('format week', function (assert) {
15170 var expected = 'Sunday Sun Su_Monday Mon Mo_Tuesday Tue Tu_Wednesday Wed We_Thursday Thu Th_Friday Fri Fr_Saturday Sat Sa'.split('_'), i;
15171 for (i = 0; i < expected.length; i++) {
15172 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
15173 }
15174 });
15175
15176 test('from', function (assert) {
15177 var start = moment([2007, 1, 28]);
15178 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'a few seconds', '44 seconds = a few seconds');
15179 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'a minute', '45 seconds = a minute');
15180 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'a minute', '89 seconds = a minute');
15181 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes');
15182 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes');
15183 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'an hour', '45 minutes = an hour');
15184 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'an hour', '89 minutes = an hour');
15185 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hours', '90 minutes = 2 hours');
15186 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hours', '5 hours = 5 hours');
15187 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hours', '21 hours = 21 hours');
15188 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'a day', '22 hours = a day');
15189 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'a day', '35 hours = a day');
15190 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 days', '36 hours = 2 days');
15191 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'a day', '1 day = a day');
15192 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 days', '5 days = 5 days');
15193 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 days', '25 days = 25 days');
15194 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'a month', '26 days = a month');
15195 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'a month', '30 days = a month');
15196 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'a month', '43 days = a month');
15197 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 months', '46 days = 2 months');
15198 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 months', '75 days = 2 months');
15199 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 months', '76 days = 3 months');
15200 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'a month', '1 month = a month');
15201 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 months', '5 months = 5 months');
15202 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'a year', '345 days = a year');
15203 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 years', '548 days = 2 years');
15204 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'a year', '1 year = a year');
15205 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 years', '5 years = 5 years');
15206 });
15207
15208 test('suffix', function (assert) {
15209 assert.equal(moment(30000).from(0), 'in a few seconds', 'prefix');
15210 assert.equal(moment(0).from(30000), 'a few seconds ago', 'suffix');
15211 });
15212
15213 test('now from now', function (assert) {
15214 assert.equal(moment().fromNow(), 'a few seconds ago', 'now from now should display as in the past');
15215 });
15216
15217 test('fromNow', function (assert) {
15218 assert.equal(moment().add({s: 30}).fromNow(), 'in a few seconds', 'in a few seconds');
15219 assert.equal(moment().add({d: 5}).fromNow(), 'in 5 days', 'in 5 days');
15220 });
15221
15222 test('calendar day', function (assert) {
15223 var a = moment().hours(12).minutes(0).seconds(0);
15224
15225 assert.equal(moment(a).calendar(), 'Today at 12:00', 'today at the same time');
15226 assert.equal(moment(a).add({m: 25}).calendar(), 'Today at 12:25', 'Now plus 25 min');
15227 assert.equal(moment(a).add({h: 1}).calendar(), 'Today at 13:00', 'Now plus 1 hour');
15228 assert.equal(moment(a).add({d: 1}).calendar(), 'Tomorrow at 12:00', 'tomorrow at the same time');
15229 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Today at 11:00', 'Now minus 1 hour');
15230 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Yesterday at 12:00', 'yesterday at the same time');
15231 });
15232
15233 test('calendar next week', function (assert) {
15234 var i, m;
15235 for (i = 2; i < 7; i++) {
15236 m = moment().add({d: i});
15237 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days current time');
15238 m.hours(0).minutes(0).seconds(0).milliseconds(0);
15239 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days beginning of day');
15240 m.hours(23).minutes(59).seconds(59).milliseconds(999);
15241 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days end of day');
73f3c911 15242 }
db71a655 15243 });
516f5f67 15244
db71a655
KM
15245 test('calendar last week', function (assert) {
15246 var i, m;
15247
15248 for (i = 2; i < 7; i++) {
15249 m = moment().subtract({d: i});
15250 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days current time');
15251 m.hours(0).minutes(0).seconds(0).milliseconds(0);
15252 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days beginning of day');
15253 m.hours(23).minutes(59).seconds(59).milliseconds(999);
15254 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days end of day');
516f5f67 15255 }
db71a655 15256 });
516f5f67 15257
db71a655
KM
15258 test('calendar all else', function (assert) {
15259 var weeksAgo = moment().subtract({w: 1}),
15260 weeksFromNow = moment().add({w: 1});
516f5f67 15261
db71a655
KM
15262 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
15263 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 15264
db71a655
KM
15265 weeksAgo = moment().subtract({w: 2});
15266 weeksFromNow = moment().add({w: 2});
516f5f67 15267
db71a655
KM
15268 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
15269 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
15270 });
15271
15272 test('weeks year starting sunday formatted', function (assert) {
15273 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52nd', 'Jan 1 2012 should be week 52');
15274 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1st', 'Jan 2 2012 should be week 1');
15275 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1st', 'Jan 8 2012 should be week 1');
15276 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2nd', 'Jan 9 2012 should be week 2');
15277 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2nd', 'Jan 15 2012 should be week 2');
15278 });
73f3c911
IC
15279
15280})));
15281
516f5f67 15282
c74a101d
IC
15283;(function (global, factory) {
15284 typeof exports === 'object' && typeof module !== 'undefined'
15285 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
15286 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
15287 factory(global.moment)
73f3c911 15288}(this, (function (moment) { 'use strict';
516f5f67 15289
db71a655
KM
15290 function each(array, callback) {
15291 var i;
15292 for (i = 0; i < array.length; i++) {
15293 callback(array[i], i, array);
15294 }
b135bf1a
IC
15295 }
15296
c58511b9
KM
15297 function setupDeprecationHandler(test, moment$$1, scope) {
15298 test._expectedDeprecations = null;
15299 test._observedDeprecations = null;
15300 test._oldSupress = moment$$1.suppressDeprecationWarnings;
15301 moment$$1.suppressDeprecationWarnings = true;
15302 test.expectedDeprecations = function () {
15303 test._expectedDeprecations = arguments;
15304 test._observedDeprecations = [];
15305 };
15306 moment$$1.deprecationHandler = function (name, msg) {
15307 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
15308 if (deprecationId === -1) {
15309 throw new Error('Unexpected deprecation thrown name=' +
15310 name + ' msg=' + msg);
15311 }
15312 test._observedDeprecations[deprecationId] = 1;
15313 };
15314 }
15315
15316 function teardownDeprecationHandler(test, moment$$1, scope) {
15317 moment$$1.suppressDeprecationWarnings = test._oldSupress;
15318
15319 if (test._expectedDeprecations != null) {
15320 var missedDeprecations = [];
15321 each(test._expectedDeprecations, function (deprecationPattern, id) {
15322 if (test._observedDeprecations[id] !== 1) {
15323 missedDeprecations.push(deprecationPattern);
15324 }
15325 });
15326 if (missedDeprecations.length !== 0) {
15327 throw new Error('Expected deprecation warnings did not happen: ' +
15328 missedDeprecations.join(' '));
15329 }
15330 }
15331 }
15332
15333 function matchedDeprecation(name, msg, deprecations) {
15334 if (deprecations == null) {
15335 return -1;
15336 }
15337 for (var i = 0; i < deprecations.length; ++i) {
15338 if (name != null && name === deprecations[i]) {
15339 return i;
15340 }
15341 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
15342 return i;
15343 }
15344 }
15345 return -1;
15346 }
15347
15348 /*global QUnit:false*/
15349
15350 var test = QUnit.test;
15351
db71a655
KM
15352 function objectKeys(obj) {
15353 if (Object.keys) {
15354 return Object.keys(obj);
15355 } else {
15356 // IE8
15357 var res = [], i;
15358 for (i in obj) {
15359 if (obj.hasOwnProperty(i)) {
15360 res.push(i);
15361 }
b135bf1a 15362 }
db71a655 15363 return res;
b135bf1a
IC
15364 }
15365 }
15366
db71a655 15367 // Pick the first defined of two or three arguments.
73f3c911 15368
db71a655
KM
15369 function defineCommonLocaleTests(locale, options) {
15370 test('lenient day of month ordinal parsing', function (assert) {
15371 var i, ordinalStr, testMoment;
15372 for (i = 1; i <= 31; ++i) {
15373 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
15374 testMoment = moment(ordinalStr, 'YYYY MM Do');
15375 assert.equal(testMoment.year(), 2014,
15376 'lenient day of month ordinal parsing ' + i + ' year check');
15377 assert.equal(testMoment.month(), 0,
15378 'lenient day of month ordinal parsing ' + i + ' month check');
15379 assert.equal(testMoment.date(), i,
15380 'lenient day of month ordinal parsing ' + i + ' date check');
15381 }
15382 });
73f3c911 15383
db71a655
KM
15384 test('lenient day of month ordinal parsing of number', function (assert) {
15385 var i, testMoment;
15386 for (i = 1; i <= 31; ++i) {
15387 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
15388 assert.equal(testMoment.year(), 2014,
15389 'lenient day of month ordinal parsing of number ' + i + ' year check');
15390 assert.equal(testMoment.month(), 0,
15391 'lenient day of month ordinal parsing of number ' + i + ' month check');
15392 assert.equal(testMoment.date(), i,
15393 'lenient day of month ordinal parsing of number ' + i + ' date check');
15394 }
15395 });
b135bf1a 15396
db71a655
KM
15397 test('strict day of month ordinal parsing', function (assert) {
15398 var i, ordinalStr, testMoment;
15399 for (i = 1; i <= 31; ++i) {
15400 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
15401 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
15402 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
15403 }
15404 });
b135bf1a 15405
db71a655
KM
15406 test('meridiem invariant', function (assert) {
15407 var h, m, t1, t2;
15408 for (h = 0; h < 24; ++h) {
15409 for (m = 0; m < 60; m += 15) {
15410 t1 = moment.utc([2000, 0, 1, h, m]);
15411 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
15412 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
15413 'meridiem at ' + t1.format('HH:mm'));
15414 }
15415 }
15416 });
15417
15418 test('date format correctness', function (assert) {
15419 var data, tokens;
15420 data = moment.localeData()._longDateFormat;
15421 tokens = objectKeys(data);
15422 each(tokens, function (srchToken) {
15423 // Check each format string to make sure it does not contain any
15424 // tokens that need to be expanded.
15425 each(tokens, function (baseToken) {
15426 // strip escaped sequences
15427 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
15428 assert.equal(false, !!~format.indexOf(srchToken),
15429 'contains ' + srchToken + ' in ' + baseToken);
15430 });
73f3c911 15431 });
b135bf1a
IC
15432 });
15433
db71a655
KM
15434 test('month parsing correctness', function (assert) {
15435 var i, m;
15436
15437 if (locale === 'tr') {
15438 // I can't fix it :(
c58511b9 15439 assert.expect(0);
db71a655
KM
15440 return;
15441 }
15442 function tester(format) {
15443 var r;
15444 r = moment(m.format(format), format);
15445 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
15446 if (locale !== 'ka') {
15447 r = moment(m.format(format).toLocaleUpperCase(), format);
15448 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
15449 }
db71a655
KM
15450 r = moment(m.format(format).toLocaleLowerCase(), format);
15451 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
15452
15453 r = moment(m.format(format), format, true);
15454 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
15455 if (locale !== 'ka') {
15456 r = moment(m.format(format).toLocaleUpperCase(), format, true);
15457 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
15458 }
db71a655
KM
15459 r = moment(m.format(format).toLocaleLowerCase(), format, true);
15460 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
15461 }
15462
15463 for (i = 0; i < 12; ++i) {
15464 m = moment([2015, i, 15, 18]);
15465 tester('MMM');
15466 tester('MMM.');
15467 tester('MMMM');
15468 tester('MMMM.');
15469 }
15470 });
b135bf1a 15471
db71a655
KM
15472 test('weekday parsing correctness', function (assert) {
15473 var i, m;
15474
96d0d679 15475 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
15476 // tr, az: There is a lower-case letter (ı), that converted to
15477 // upper then lower changes to i
15478 // ro: there is the letter ț which behaves weird under IE8
15479 // mt: letter Ħ
96d0d679 15480 // ga: month with spaces
c58511b9 15481 assert.expect(0);
db71a655
KM
15482 return;
15483 }
15484 function tester(format) {
15485 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
15486 r = moment(m.format(format), format);
15487 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
15488 if (locale !== 'ka') {
15489 r = moment(m.format(format).toLocaleUpperCase(), format);
15490 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
15491 }
db71a655
KM
15492 r = moment(m.format(format).toLocaleLowerCase(), format);
15493 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
15494 r = moment(m.format(format), format, true);
15495 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
15496 if (locale !== 'ka') {
15497 r = moment(m.format(format).toLocaleUpperCase(), format, true);
15498 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
15499 }
db71a655
KM
15500 r = moment(m.format(format).toLocaleLowerCase(), format, true);
15501 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
15502 }
15503
15504 for (i = 0; i < 7; ++i) {
15505 m = moment.utc([2015, 0, i + 1, 18]);
15506 tester('dd');
15507 tester('ddd');
15508 tester('dddd');
15509 }
15510 });
b135bf1a 15511
db71a655
KM
15512 test('valid localeData', function (assert) {
15513 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
15514 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
15515 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
15516 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
15517 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
15518 });
96d0d679
KM
15519
15520 test('localeData weekdays can localeSort', function (assert) {
15521 var weekdays = moment().localeData().weekdays();
15522 var weekdaysShort = moment().localeData().weekdaysShort();
15523 var weekdaysMin = moment().localeData().weekdaysMin();
15524 var shift = moment().localeData()._week.dow;
15525 assert.deepEqual(
15526 moment().localeData().weekdays(true),
15527 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
15528 'weekdays should localeSort');
15529 assert.deepEqual(
15530 moment().localeData().weekdaysShort(true),
15531 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
15532 'weekdaysShort should localeSort');
15533 assert.deepEqual(
15534 moment().localeData().weekdaysMin(true),
15535 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
15536 'weekdaysMin should localeSort');
15537 });
db71a655 15538 }
d6651c21 15539
db71a655
KM
15540 /*global QUnit:false*/
15541
db71a655
KM
15542 function localeModule (name, lifecycle) {
15543 QUnit.module('locale:' + name, {
c58511b9 15544 beforeEach : function () {
db71a655
KM
15545 moment.locale(name);
15546 moment.createFromInputFallback = function (config) {
15547 throw new Error('input not handled by moment: ' + config._i);
15548 };
15549 setupDeprecationHandler(test, moment, 'locale');
15550 if (lifecycle && lifecycle.setup) {
15551 lifecycle.setup();
15552 }
15553 },
c58511b9 15554 afterEach : function () {
db71a655
KM
15555 moment.locale('en');
15556 teardownDeprecationHandler(test, moment, 'locale');
15557 if (lifecycle && lifecycle.teardown) {
15558 lifecycle.teardown();
15559 }
d6651c21 15560 }
73f3c911 15561 });
db71a655
KM
15562 defineCommonLocaleTests(name, -1, -1);
15563 }
15564
96d0d679 15565 localeModule('en-ie');
db71a655
KM
15566
15567 test('parse', function (assert) {
15568 var tests = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_'), i;
15569 function equalTest(input, mmm, i) {
15570 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
15571 }
15572 for (i = 0; i < 12; i++) {
15573 tests[i] = tests[i].split(' ');
15574 equalTest(tests[i][0], 'MMM', i);
15575 equalTest(tests[i][1], 'MMM', i);
15576 equalTest(tests[i][0], 'MMMM', i);
15577 equalTest(tests[i][1], 'MMMM', i);
15578 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
15579 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
15580 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
15581 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
15582 }
15583 });
15584
15585 test('format', function (assert) {
15586 var a = [
15587 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Sunday, February 14th 2010, 3:25:50 pm'],
15588 ['ddd, hA', 'Sun, 3PM'],
15589 ['M Mo MM MMMM MMM', '2 2nd 02 February Feb'],
15590 ['YYYY YY', '2010 10'],
15591 ['D Do DD', '14 14th 14'],
15592 ['d do dddd ddd dd', '0 0th Sunday Sun Su'],
15593 ['DDD DDDo DDDD', '45 45th 045'],
96d0d679 15594 ['w wo ww', '6 6th 06'],
db71a655
KM
15595 ['h hh', '3 03'],
15596 ['H HH', '15 15'],
15597 ['m mm', '25 25'],
15598 ['s ss', '50 50'],
15599 ['a A', 'pm PM'],
15600 ['[the] DDDo [day of the year]', 'the 45th day of the year'],
15601 ['LTS', '15:25:50'],
15602 ['L', '14/02/2010'],
15603 ['LL', '14 February 2010'],
15604 ['LLL', '14 February 2010 15:25'],
96d0d679 15605 ['LLLL', 'Sunday 14 February 2010 15:25'],
db71a655
KM
15606 ['l', '14/2/2010'],
15607 ['ll', '14 Feb 2010'],
15608 ['lll', '14 Feb 2010 15:25'],
96d0d679 15609 ['llll', 'Sun 14 Feb 2010 15:25']
db71a655
KM
15610 ],
15611 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
15612 i;
15613 for (i = 0; i < a.length; i++) {
15614 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
15615 }
15616 });
15617
15618 test('format ordinal', function (assert) {
15619 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1st', '1st');
15620 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2nd', '2nd');
15621 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3rd', '3rd');
15622 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4th', '4th');
15623 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5th', '5th');
15624 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6th', '6th');
15625 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7th', '7th');
15626 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8th', '8th');
15627 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9th', '9th');
15628 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10th', '10th');
15629
15630 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11th', '11th');
15631 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12th', '12th');
15632 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13th', '13th');
15633 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14th', '14th');
15634 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15th', '15th');
15635 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16th', '16th');
15636 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17th', '17th');
15637 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18th', '18th');
15638 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19th', '19th');
15639 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20th', '20th');
15640
15641 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21st', '21st');
15642 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22nd', '22nd');
15643 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23rd', '23rd');
15644 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24th', '24th');
15645 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25th', '25th');
15646 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26th', '26th');
15647 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27th', '27th');
15648 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28th', '28th');
15649 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29th', '29th');
15650 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30th', '30th');
15651
15652 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31st', '31st');
15653 });
15654
15655 test('format month', function (assert) {
15656 var expected = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_'), i;
15657 for (i = 0; i < expected.length; i++) {
15658 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
15659 }
15660 });
15661
15662 test('format week', function (assert) {
15663 var expected = 'Sunday Sun Su_Monday Mon Mo_Tuesday Tue Tu_Wednesday Wed We_Thursday Thu Th_Friday Fri Fr_Saturday Sat Sa'.split('_'), i;
15664 for (i = 0; i < expected.length; i++) {
15665 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
15666 }
15667 });
15668
15669 test('from', function (assert) {
15670 var start = moment([2007, 1, 28]);
15671 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'a few seconds', '44 seconds = a few seconds');
15672 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'a minute', '45 seconds = a minute');
15673 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'a minute', '89 seconds = a minute');
15674 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes');
15675 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes');
15676 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'an hour', '45 minutes = an hour');
15677 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'an hour', '89 minutes = an hour');
15678 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hours', '90 minutes = 2 hours');
15679 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hours', '5 hours = 5 hours');
15680 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hours', '21 hours = 21 hours');
15681 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'a day', '22 hours = a day');
15682 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'a day', '35 hours = a day');
15683 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 days', '36 hours = 2 days');
15684 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'a day', '1 day = a day');
15685 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 days', '5 days = 5 days');
15686 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 days', '25 days = 25 days');
15687 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'a month', '26 days = a month');
15688 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'a month', '30 days = a month');
15689 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'a month', '43 days = a month');
15690 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 months', '46 days = 2 months');
15691 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 months', '75 days = 2 months');
15692 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 months', '76 days = 3 months');
15693 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'a month', '1 month = a month');
15694 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 months', '5 months = 5 months');
15695 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'a year', '345 days = a year');
15696 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 years', '548 days = 2 years');
15697 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'a year', '1 year = a year');
15698 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 years', '5 years = 5 years');
15699 });
15700
15701 test('suffix', function (assert) {
15702 assert.equal(moment(30000).from(0), 'in a few seconds', 'prefix');
15703 assert.equal(moment(0).from(30000), 'a few seconds ago', 'suffix');
15704 });
15705
15706 test('now from now', function (assert) {
15707 assert.equal(moment().fromNow(), 'a few seconds ago', 'now from now should display as in the past');
15708 });
15709
15710 test('fromNow', function (assert) {
15711 assert.equal(moment().add({s: 30}).fromNow(), 'in a few seconds', 'in a few seconds');
15712 assert.equal(moment().add({d: 5}).fromNow(), 'in 5 days', 'in 5 days');
15713 });
15714
15715 test('calendar day', function (assert) {
15716 var a = moment().hours(12).minutes(0).seconds(0);
15717
15718 assert.equal(moment(a).calendar(), 'Today at 12:00', 'today at the same time');
15719 assert.equal(moment(a).add({m: 25}).calendar(), 'Today at 12:25', 'Now plus 25 min');
15720 assert.equal(moment(a).add({h: 1}).calendar(), 'Today at 13:00', 'Now plus 1 hour');
15721 assert.equal(moment(a).add({d: 1}).calendar(), 'Tomorrow at 12:00', 'tomorrow at the same time');
15722 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Today at 11:00', 'Now minus 1 hour');
15723 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Yesterday at 12:00', 'yesterday at the same time');
15724 });
15725
15726 test('calendar next week', function (assert) {
15727 var i, m;
15728 for (i = 2; i < 7; i++) {
15729 m = moment().add({d: i});
15730 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days current time');
15731 m.hours(0).minutes(0).seconds(0).milliseconds(0);
15732 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days beginning of day');
15733 m.hours(23).minutes(59).seconds(59).milliseconds(999);
15734 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days end of day');
d6651c21 15735 }
db71a655 15736 });
b135bf1a 15737
db71a655
KM
15738 test('calendar last week', function (assert) {
15739 var i, m;
15740
15741 for (i = 2; i < 7; i++) {
15742 m = moment().subtract({d: i});
15743 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days current time');
15744 m.hours(0).minutes(0).seconds(0).milliseconds(0);
15745 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days beginning of day');
15746 m.hours(23).minutes(59).seconds(59).milliseconds(999);
15747 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days end of day');
516f5f67 15748 }
db71a655 15749 });
516f5f67 15750
db71a655
KM
15751 test('calendar all else', function (assert) {
15752 var weeksAgo = moment().subtract({w: 1}),
15753 weeksFromNow = moment().add({w: 1});
516f5f67 15754
db71a655
KM
15755 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
15756 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 15757
db71a655
KM
15758 weeksAgo = moment().subtract({w: 2});
15759 weeksFromNow = moment().add({w: 2});
516f5f67 15760
db71a655
KM
15761 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
15762 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
15763 });
15764
15765 test('weeks year starting sunday formatted', function (assert) {
96d0d679
KM
15766 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52nd', 'Jan 1 2012 should be week 52');
15767 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1st', 'Jan 2 2012 should be week 1');
15768 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1st', 'Jan 8 2012 should be week 1');
15769 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2nd', 'Jan 9 2012 should be week 2');
15770 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2nd', 'Jan 15 2012 should be week 2');
db71a655 15771 });
73f3c911
IC
15772
15773})));
15774
516f5f67 15775
c74a101d
IC
15776;(function (global, factory) {
15777 typeof exports === 'object' && typeof module !== 'undefined'
15778 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
15779 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
15780 factory(global.moment)
73f3c911 15781}(this, (function (moment) { 'use strict';
516f5f67 15782
db71a655
KM
15783 function each(array, callback) {
15784 var i;
15785 for (i = 0; i < array.length; i++) {
15786 callback(array[i], i, array);
15787 }
b135bf1a
IC
15788 }
15789
c58511b9
KM
15790 function setupDeprecationHandler(test, moment$$1, scope) {
15791 test._expectedDeprecations = null;
15792 test._observedDeprecations = null;
15793 test._oldSupress = moment$$1.suppressDeprecationWarnings;
15794 moment$$1.suppressDeprecationWarnings = true;
15795 test.expectedDeprecations = function () {
15796 test._expectedDeprecations = arguments;
15797 test._observedDeprecations = [];
15798 };
15799 moment$$1.deprecationHandler = function (name, msg) {
15800 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
15801 if (deprecationId === -1) {
15802 throw new Error('Unexpected deprecation thrown name=' +
15803 name + ' msg=' + msg);
15804 }
15805 test._observedDeprecations[deprecationId] = 1;
15806 };
15807 }
15808
15809 function teardownDeprecationHandler(test, moment$$1, scope) {
15810 moment$$1.suppressDeprecationWarnings = test._oldSupress;
15811
15812 if (test._expectedDeprecations != null) {
15813 var missedDeprecations = [];
15814 each(test._expectedDeprecations, function (deprecationPattern, id) {
15815 if (test._observedDeprecations[id] !== 1) {
15816 missedDeprecations.push(deprecationPattern);
15817 }
15818 });
15819 if (missedDeprecations.length !== 0) {
15820 throw new Error('Expected deprecation warnings did not happen: ' +
15821 missedDeprecations.join(' '));
15822 }
15823 }
15824 }
15825
15826 function matchedDeprecation(name, msg, deprecations) {
15827 if (deprecations == null) {
15828 return -1;
15829 }
15830 for (var i = 0; i < deprecations.length; ++i) {
15831 if (name != null && name === deprecations[i]) {
15832 return i;
15833 }
15834 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
15835 return i;
15836 }
15837 }
15838 return -1;
15839 }
15840
15841 /*global QUnit:false*/
15842
15843 var test = QUnit.test;
15844
db71a655
KM
15845 function objectKeys(obj) {
15846 if (Object.keys) {
15847 return Object.keys(obj);
15848 } else {
15849 // IE8
15850 var res = [], i;
15851 for (i in obj) {
15852 if (obj.hasOwnProperty(i)) {
15853 res.push(i);
15854 }
b135bf1a 15855 }
db71a655 15856 return res;
b135bf1a
IC
15857 }
15858 }
15859
db71a655 15860 // Pick the first defined of two or three arguments.
73f3c911 15861
db71a655
KM
15862 function defineCommonLocaleTests(locale, options) {
15863 test('lenient day of month ordinal parsing', function (assert) {
15864 var i, ordinalStr, testMoment;
15865 for (i = 1; i <= 31; ++i) {
15866 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
15867 testMoment = moment(ordinalStr, 'YYYY MM Do');
15868 assert.equal(testMoment.year(), 2014,
15869 'lenient day of month ordinal parsing ' + i + ' year check');
15870 assert.equal(testMoment.month(), 0,
15871 'lenient day of month ordinal parsing ' + i + ' month check');
15872 assert.equal(testMoment.date(), i,
15873 'lenient day of month ordinal parsing ' + i + ' date check');
15874 }
15875 });
73f3c911 15876
db71a655
KM
15877 test('lenient day of month ordinal parsing of number', function (assert) {
15878 var i, testMoment;
15879 for (i = 1; i <= 31; ++i) {
15880 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
15881 assert.equal(testMoment.year(), 2014,
15882 'lenient day of month ordinal parsing of number ' + i + ' year check');
15883 assert.equal(testMoment.month(), 0,
15884 'lenient day of month ordinal parsing of number ' + i + ' month check');
15885 assert.equal(testMoment.date(), i,
15886 'lenient day of month ordinal parsing of number ' + i + ' date check');
15887 }
15888 });
b135bf1a 15889
db71a655
KM
15890 test('strict day of month ordinal parsing', function (assert) {
15891 var i, ordinalStr, testMoment;
15892 for (i = 1; i <= 31; ++i) {
15893 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
15894 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
15895 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
15896 }
15897 });
b135bf1a 15898
db71a655
KM
15899 test('meridiem invariant', function (assert) {
15900 var h, m, t1, t2;
15901 for (h = 0; h < 24; ++h) {
15902 for (m = 0; m < 60; m += 15) {
15903 t1 = moment.utc([2000, 0, 1, h, m]);
15904 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
15905 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
15906 'meridiem at ' + t1.format('HH:mm'));
15907 }
15908 }
15909 });
15910
15911 test('date format correctness', function (assert) {
15912 var data, tokens;
15913 data = moment.localeData()._longDateFormat;
15914 tokens = objectKeys(data);
15915 each(tokens, function (srchToken) {
15916 // Check each format string to make sure it does not contain any
15917 // tokens that need to be expanded.
15918 each(tokens, function (baseToken) {
15919 // strip escaped sequences
15920 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
15921 assert.equal(false, !!~format.indexOf(srchToken),
15922 'contains ' + srchToken + ' in ' + baseToken);
15923 });
73f3c911 15924 });
b135bf1a
IC
15925 });
15926
db71a655
KM
15927 test('month parsing correctness', function (assert) {
15928 var i, m;
15929
15930 if (locale === 'tr') {
15931 // I can't fix it :(
c58511b9 15932 assert.expect(0);
db71a655
KM
15933 return;
15934 }
15935 function tester(format) {
15936 var r;
15937 r = moment(m.format(format), format);
15938 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
15939 if (locale !== 'ka') {
15940 r = moment(m.format(format).toLocaleUpperCase(), format);
15941 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
15942 }
db71a655
KM
15943 r = moment(m.format(format).toLocaleLowerCase(), format);
15944 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
15945
15946 r = moment(m.format(format), format, true);
15947 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
15948 if (locale !== 'ka') {
15949 r = moment(m.format(format).toLocaleUpperCase(), format, true);
15950 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
15951 }
db71a655
KM
15952 r = moment(m.format(format).toLocaleLowerCase(), format, true);
15953 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
15954 }
15955
15956 for (i = 0; i < 12; ++i) {
15957 m = moment([2015, i, 15, 18]);
15958 tester('MMM');
15959 tester('MMM.');
15960 tester('MMMM');
15961 tester('MMMM.');
15962 }
15963 });
b135bf1a 15964
db71a655
KM
15965 test('weekday parsing correctness', function (assert) {
15966 var i, m;
15967
96d0d679 15968 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
15969 // tr, az: There is a lower-case letter (ı), that converted to
15970 // upper then lower changes to i
15971 // ro: there is the letter ț which behaves weird under IE8
15972 // mt: letter Ħ
96d0d679 15973 // ga: month with spaces
c58511b9 15974 assert.expect(0);
db71a655
KM
15975 return;
15976 }
15977 function tester(format) {
15978 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
15979 r = moment(m.format(format), format);
15980 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
15981 if (locale !== 'ka') {
15982 r = moment(m.format(format).toLocaleUpperCase(), format);
15983 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
15984 }
db71a655
KM
15985 r = moment(m.format(format).toLocaleLowerCase(), format);
15986 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
15987 r = moment(m.format(format), format, true);
15988 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
15989 if (locale !== 'ka') {
15990 r = moment(m.format(format).toLocaleUpperCase(), format, true);
15991 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
15992 }
db71a655
KM
15993 r = moment(m.format(format).toLocaleLowerCase(), format, true);
15994 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
15995 }
15996
15997 for (i = 0; i < 7; ++i) {
15998 m = moment.utc([2015, 0, i + 1, 18]);
15999 tester('dd');
16000 tester('ddd');
16001 tester('dddd');
16002 }
16003 });
b135bf1a 16004
db71a655
KM
16005 test('valid localeData', function (assert) {
16006 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
16007 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
16008 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
16009 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
16010 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
16011 });
96d0d679
KM
16012
16013 test('localeData weekdays can localeSort', function (assert) {
16014 var weekdays = moment().localeData().weekdays();
16015 var weekdaysShort = moment().localeData().weekdaysShort();
16016 var weekdaysMin = moment().localeData().weekdaysMin();
16017 var shift = moment().localeData()._week.dow;
16018 assert.deepEqual(
16019 moment().localeData().weekdays(true),
16020 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
16021 'weekdays should localeSort');
16022 assert.deepEqual(
16023 moment().localeData().weekdaysShort(true),
16024 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
16025 'weekdaysShort should localeSort');
16026 assert.deepEqual(
16027 moment().localeData().weekdaysMin(true),
16028 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
16029 'weekdaysMin should localeSort');
16030 });
db71a655 16031 }
d6651c21 16032
db71a655 16033 /*global QUnit:false*/
73f3c911 16034
db71a655
KM
16035 function localeModule (name, lifecycle) {
16036 QUnit.module('locale:' + name, {
c58511b9 16037 beforeEach : function () {
db71a655
KM
16038 moment.locale(name);
16039 moment.createFromInputFallback = function (config) {
16040 throw new Error('input not handled by moment: ' + config._i);
16041 };
16042 setupDeprecationHandler(test, moment, 'locale');
16043 if (lifecycle && lifecycle.setup) {
16044 lifecycle.setup();
16045 }
16046 },
c58511b9 16047 afterEach : function () {
db71a655
KM
16048 moment.locale('en');
16049 teardownDeprecationHandler(test, moment, 'locale');
16050 if (lifecycle && lifecycle.teardown) {
16051 lifecycle.teardown();
16052 }
d6651c21 16053 }
73f3c911 16054 });
db71a655
KM
16055 defineCommonLocaleTests(name, -1, -1);
16056 }
16057
96d0d679 16058 localeModule('en-il');
db71a655
KM
16059
16060 test('parse', function (assert) {
16061 var tests = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_'), i;
16062 function equalTest(input, mmm, i) {
16063 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
16064 }
16065 for (i = 0; i < 12; i++) {
16066 tests[i] = tests[i].split(' ');
16067 equalTest(tests[i][0], 'MMM', i);
16068 equalTest(tests[i][1], 'MMM', i);
16069 equalTest(tests[i][0], 'MMMM', i);
16070 equalTest(tests[i][1], 'MMMM', i);
16071 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
16072 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
16073 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
16074 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
16075 }
16076 });
16077
16078 test('format', function (assert) {
16079 var a = [
16080 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Sunday, February 14th 2010, 3:25:50 pm'],
16081 ['ddd, hA', 'Sun, 3PM'],
16082 ['M Mo MM MMMM MMM', '2 2nd 02 February Feb'],
16083 ['YYYY YY', '2010 10'],
16084 ['D Do DD', '14 14th 14'],
16085 ['d do dddd ddd dd', '0 0th Sunday Sun Su'],
16086 ['DDD DDDo DDDD', '45 45th 045'],
96d0d679 16087 ['w wo ww', '8 8th 08'],
db71a655
KM
16088 ['h hh', '3 03'],
16089 ['H HH', '15 15'],
16090 ['m mm', '25 25'],
16091 ['s ss', '50 50'],
16092 ['a A', 'pm PM'],
16093 ['[the] DDDo [day of the year]', 'the 45th day of the year'],
96d0d679 16094 ['LTS', '15:25:50'],
db71a655
KM
16095 ['L', '14/02/2010'],
16096 ['LL', '14 February 2010'],
96d0d679
KM
16097 ['LLL', '14 February 2010 15:25'],
16098 ['LLLL', 'Sunday, 14 February 2010 15:25'],
db71a655
KM
16099 ['l', '14/2/2010'],
16100 ['ll', '14 Feb 2010'],
96d0d679
KM
16101 ['lll', '14 Feb 2010 15:25'],
16102 ['llll', 'Sun, 14 Feb 2010 15:25']
db71a655
KM
16103 ],
16104 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
16105 i;
16106 for (i = 0; i < a.length; i++) {
16107 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
16108 }
16109 });
16110
16111 test('format ordinal', function (assert) {
16112 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1st', '1st');
16113 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2nd', '2nd');
16114 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3rd', '3rd');
16115 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4th', '4th');
16116 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5th', '5th');
16117 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6th', '6th');
16118 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7th', '7th');
16119 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8th', '8th');
16120 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9th', '9th');
16121 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10th', '10th');
16122
16123 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11th', '11th');
16124 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12th', '12th');
16125 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13th', '13th');
16126 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14th', '14th');
16127 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15th', '15th');
16128 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16th', '16th');
16129 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17th', '17th');
16130 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18th', '18th');
16131 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19th', '19th');
16132 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20th', '20th');
16133
16134 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21st', '21st');
16135 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22nd', '22nd');
16136 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23rd', '23rd');
16137 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24th', '24th');
16138 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25th', '25th');
16139 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26th', '26th');
16140 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27th', '27th');
16141 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28th', '28th');
16142 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29th', '29th');
16143 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30th', '30th');
16144
16145 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31st', '31st');
16146 });
16147
16148 test('format month', function (assert) {
16149 var expected = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_'), i;
16150 for (i = 0; i < expected.length; i++) {
16151 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
16152 }
16153 });
16154
16155 test('format week', function (assert) {
16156 var expected = 'Sunday Sun Su_Monday Mon Mo_Tuesday Tue Tu_Wednesday Wed We_Thursday Thu Th_Friday Fri Fr_Saturday Sat Sa'.split('_'), i;
16157 for (i = 0; i < expected.length; i++) {
16158 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
16159 }
16160 });
16161
16162 test('from', function (assert) {
16163 var start = moment([2007, 1, 28]);
16164 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'a few seconds', '44 seconds = a few seconds');
16165 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'a minute', '45 seconds = a minute');
16166 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'a minute', '89 seconds = a minute');
16167 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes');
16168 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes');
16169 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'an hour', '45 minutes = an hour');
16170 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'an hour', '89 minutes = an hour');
16171 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hours', '90 minutes = 2 hours');
16172 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hours', '5 hours = 5 hours');
16173 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hours', '21 hours = 21 hours');
16174 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'a day', '22 hours = a day');
16175 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'a day', '35 hours = a day');
16176 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 days', '36 hours = 2 days');
16177 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'a day', '1 day = a day');
16178 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 days', '5 days = 5 days');
16179 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 days', '25 days = 25 days');
16180 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'a month', '26 days = a month');
16181 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'a month', '30 days = a month');
16182 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'a month', '43 days = a month');
16183 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 months', '46 days = 2 months');
16184 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 months', '75 days = 2 months');
16185 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 months', '76 days = 3 months');
16186 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'a month', '1 month = a month');
16187 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 months', '5 months = 5 months');
16188 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'a year', '345 days = a year');
16189 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 years', '548 days = 2 years');
16190 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'a year', '1 year = a year');
16191 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 years', '5 years = 5 years');
16192 });
16193
16194 test('suffix', function (assert) {
16195 assert.equal(moment(30000).from(0), 'in a few seconds', 'prefix');
16196 assert.equal(moment(0).from(30000), 'a few seconds ago', 'suffix');
16197 });
16198
16199 test('now from now', function (assert) {
16200 assert.equal(moment().fromNow(), 'a few seconds ago', 'now from now should display as in the past');
16201 });
16202
16203 test('fromNow', function (assert) {
16204 assert.equal(moment().add({s: 30}).fromNow(), 'in a few seconds', 'in a few seconds');
16205 assert.equal(moment().add({d: 5}).fromNow(), 'in 5 days', 'in 5 days');
16206 });
16207
16208 test('calendar day', function (assert) {
16209 var a = moment().hours(12).minutes(0).seconds(0);
16210
96d0d679
KM
16211 assert.equal(moment(a).calendar(), 'Today at 12:00', 'today at the same time');
16212 assert.equal(moment(a).add({m: 25}).calendar(), 'Today at 12:25', 'Now plus 25 min');
16213 assert.equal(moment(a).add({h: 1}).calendar(), 'Today at 13:00', 'Now plus 1 hour');
16214 assert.equal(moment(a).add({d: 1}).calendar(), 'Tomorrow at 12:00', 'tomorrow at the same time');
16215 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Today at 11:00', 'Now minus 1 hour');
16216 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Yesterday at 12:00', 'yesterday at the same time');
db71a655
KM
16217 });
16218
16219 test('calendar next week', function (assert) {
16220 var i, m;
16221 for (i = 2; i < 7; i++) {
16222 m = moment().add({d: i});
16223 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days current time');
16224 m.hours(0).minutes(0).seconds(0).milliseconds(0);
16225 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days beginning of day');
16226 m.hours(23).minutes(59).seconds(59).milliseconds(999);
16227 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days end of day');
d6651c21 16228 }
db71a655 16229 });
73f3c911 16230
db71a655
KM
16231 test('calendar last week', function (assert) {
16232 var i, m;
16233
16234 for (i = 2; i < 7; i++) {
16235 m = moment().subtract({d: i});
16236 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days current time');
16237 m.hours(0).minutes(0).seconds(0).milliseconds(0);
16238 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days beginning of day');
16239 m.hours(23).minutes(59).seconds(59).milliseconds(999);
16240 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days end of day');
73f3c911 16241 }
db71a655 16242 });
b135bf1a 16243
db71a655
KM
16244 test('calendar all else', function (assert) {
16245 var weeksAgo = moment().subtract({w: 1}),
16246 weeksFromNow = moment().add({w: 1});
516f5f67 16247
db71a655
KM
16248 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
16249 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 16250
db71a655
KM
16251 weeksAgo = moment().subtract({w: 2});
16252 weeksFromNow = moment().add({w: 2});
c74a101d 16253
db71a655
KM
16254 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
16255 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
16256 });
16257
16258 test('weeks year starting sunday formatted', function (assert) {
96d0d679
KM
16259 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1st', 'Jan 1 2012 should be week 1');
16260 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1st', 'Jan 7 2012 should be week 1');
16261 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2nd', 'Jan 8 2012 should be week 2');
16262 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2nd', 'Jan 14 2012 should be week 2');
16263 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3rd', 'Jan 15 2012 should be week 3');
16264 });
16265
16266 test('days start on sunday', function (assert) {
16267 assert.equal(moment().startOf('week').format('dddd'), 'Sunday', 'First day of the week should be Sunday');
db71a655 16268 });
73f3c911
IC
16269
16270})));
16271
16272
16273;(function (global, factory) {
16274 typeof exports === 'object' && typeof module !== 'undefined'
16275 && typeof require === 'function' ? factory(require('../../moment')) :
16276 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
16277 factory(global.moment)
16278}(this, (function (moment) { 'use strict';
16279
db71a655
KM
16280 function each(array, callback) {
16281 var i;
16282 for (i = 0; i < array.length; i++) {
16283 callback(array[i], i, array);
16284 }
516f5f67
IC
16285 }
16286
c58511b9
KM
16287 function setupDeprecationHandler(test, moment$$1, scope) {
16288 test._expectedDeprecations = null;
16289 test._observedDeprecations = null;
16290 test._oldSupress = moment$$1.suppressDeprecationWarnings;
16291 moment$$1.suppressDeprecationWarnings = true;
16292 test.expectedDeprecations = function () {
16293 test._expectedDeprecations = arguments;
16294 test._observedDeprecations = [];
16295 };
16296 moment$$1.deprecationHandler = function (name, msg) {
16297 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
16298 if (deprecationId === -1) {
16299 throw new Error('Unexpected deprecation thrown name=' +
16300 name + ' msg=' + msg);
16301 }
16302 test._observedDeprecations[deprecationId] = 1;
16303 };
16304 }
16305
16306 function teardownDeprecationHandler(test, moment$$1, scope) {
16307 moment$$1.suppressDeprecationWarnings = test._oldSupress;
16308
16309 if (test._expectedDeprecations != null) {
16310 var missedDeprecations = [];
16311 each(test._expectedDeprecations, function (deprecationPattern, id) {
16312 if (test._observedDeprecations[id] !== 1) {
16313 missedDeprecations.push(deprecationPattern);
16314 }
16315 });
16316 if (missedDeprecations.length !== 0) {
16317 throw new Error('Expected deprecation warnings did not happen: ' +
16318 missedDeprecations.join(' '));
16319 }
16320 }
16321 }
16322
16323 function matchedDeprecation(name, msg, deprecations) {
16324 if (deprecations == null) {
16325 return -1;
16326 }
16327 for (var i = 0; i < deprecations.length; ++i) {
16328 if (name != null && name === deprecations[i]) {
16329 return i;
16330 }
16331 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
16332 return i;
16333 }
16334 }
16335 return -1;
16336 }
16337
16338 /*global QUnit:false*/
16339
16340 var test = QUnit.test;
16341
db71a655
KM
16342 function objectKeys(obj) {
16343 if (Object.keys) {
16344 return Object.keys(obj);
16345 } else {
16346 // IE8
16347 var res = [], i;
16348 for (i in obj) {
16349 if (obj.hasOwnProperty(i)) {
16350 res.push(i);
16351 }
516f5f67 16352 }
db71a655 16353 return res;
73f3c911 16354 }
73f3c911 16355 }
516f5f67 16356
db71a655 16357 // Pick the first defined of two or three arguments.
73f3c911 16358
db71a655
KM
16359 function defineCommonLocaleTests(locale, options) {
16360 test('lenient day of month ordinal parsing', function (assert) {
16361 var i, ordinalStr, testMoment;
16362 for (i = 1; i <= 31; ++i) {
16363 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
16364 testMoment = moment(ordinalStr, 'YYYY MM Do');
16365 assert.equal(testMoment.year(), 2014,
16366 'lenient day of month ordinal parsing ' + i + ' year check');
16367 assert.equal(testMoment.month(), 0,
16368 'lenient day of month ordinal parsing ' + i + ' month check');
16369 assert.equal(testMoment.date(), i,
16370 'lenient day of month ordinal parsing ' + i + ' date check');
16371 }
16372 });
516f5f67 16373
db71a655
KM
16374 test('lenient day of month ordinal parsing of number', function (assert) {
16375 var i, testMoment;
16376 for (i = 1; i <= 31; ++i) {
16377 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
16378 assert.equal(testMoment.year(), 2014,
16379 'lenient day of month ordinal parsing of number ' + i + ' year check');
16380 assert.equal(testMoment.month(), 0,
16381 'lenient day of month ordinal parsing of number ' + i + ' month check');
16382 assert.equal(testMoment.date(), i,
16383 'lenient day of month ordinal parsing of number ' + i + ' date check');
16384 }
16385 });
516f5f67 16386
db71a655
KM
16387 test('strict day of month ordinal parsing', function (assert) {
16388 var i, ordinalStr, testMoment;
16389 for (i = 1; i <= 31; ++i) {
16390 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
16391 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
16392 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
16393 }
16394 });
516f5f67 16395
db71a655
KM
16396 test('meridiem invariant', function (assert) {
16397 var h, m, t1, t2;
16398 for (h = 0; h < 24; ++h) {
16399 for (m = 0; m < 60; m += 15) {
16400 t1 = moment.utc([2000, 0, 1, h, m]);
16401 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
16402 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
16403 'meridiem at ' + t1.format('HH:mm'));
16404 }
16405 }
16406 });
16407
16408 test('date format correctness', function (assert) {
16409 var data, tokens;
16410 data = moment.localeData()._longDateFormat;
16411 tokens = objectKeys(data);
16412 each(tokens, function (srchToken) {
16413 // Check each format string to make sure it does not contain any
16414 // tokens that need to be expanded.
16415 each(tokens, function (baseToken) {
16416 // strip escaped sequences
16417 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
16418 assert.equal(false, !!~format.indexOf(srchToken),
16419 'contains ' + srchToken + ' in ' + baseToken);
16420 });
73f3c911
IC
16421 });
16422 });
73f3c911 16423
db71a655
KM
16424 test('month parsing correctness', function (assert) {
16425 var i, m;
16426
16427 if (locale === 'tr') {
16428 // I can't fix it :(
c58511b9 16429 assert.expect(0);
db71a655
KM
16430 return;
16431 }
16432 function tester(format) {
16433 var r;
16434 r = moment(m.format(format), format);
16435 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
16436 if (locale !== 'ka') {
16437 r = moment(m.format(format).toLocaleUpperCase(), format);
16438 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
16439 }
db71a655
KM
16440 r = moment(m.format(format).toLocaleLowerCase(), format);
16441 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
16442
16443 r = moment(m.format(format), format, true);
16444 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
16445 if (locale !== 'ka') {
16446 r = moment(m.format(format).toLocaleUpperCase(), format, true);
16447 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
16448 }
db71a655
KM
16449 r = moment(m.format(format).toLocaleLowerCase(), format, true);
16450 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
16451 }
16452
16453 for (i = 0; i < 12; ++i) {
16454 m = moment([2015, i, 15, 18]);
16455 tester('MMM');
16456 tester('MMM.');
16457 tester('MMMM');
16458 tester('MMMM.');
16459 }
16460 });
516f5f67 16461
db71a655
KM
16462 test('weekday parsing correctness', function (assert) {
16463 var i, m;
16464
96d0d679 16465 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
16466 // tr, az: There is a lower-case letter (ı), that converted to
16467 // upper then lower changes to i
16468 // ro: there is the letter ț which behaves weird under IE8
16469 // mt: letter Ħ
96d0d679 16470 // ga: month with spaces
c58511b9 16471 assert.expect(0);
db71a655
KM
16472 return;
16473 }
16474 function tester(format) {
16475 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
16476 r = moment(m.format(format), format);
16477 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
16478 if (locale !== 'ka') {
16479 r = moment(m.format(format).toLocaleUpperCase(), format);
16480 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
16481 }
db71a655
KM
16482 r = moment(m.format(format).toLocaleLowerCase(), format);
16483 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
16484 r = moment(m.format(format), format, true);
16485 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
16486 if (locale !== 'ka') {
16487 r = moment(m.format(format).toLocaleUpperCase(), format, true);
16488 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
16489 }
db71a655
KM
16490 r = moment(m.format(format).toLocaleLowerCase(), format, true);
16491 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
16492 }
16493
16494 for (i = 0; i < 7; ++i) {
16495 m = moment.utc([2015, 0, i + 1, 18]);
16496 tester('dd');
16497 tester('ddd');
16498 tester('dddd');
16499 }
16500 });
516f5f67 16501
db71a655
KM
16502 test('valid localeData', function (assert) {
16503 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
16504 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
16505 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
16506 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
16507 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
16508 });
96d0d679
KM
16509
16510 test('localeData weekdays can localeSort', function (assert) {
16511 var weekdays = moment().localeData().weekdays();
16512 var weekdaysShort = moment().localeData().weekdaysShort();
16513 var weekdaysMin = moment().localeData().weekdaysMin();
16514 var shift = moment().localeData()._week.dow;
16515 assert.deepEqual(
16516 moment().localeData().weekdays(true),
16517 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
16518 'weekdays should localeSort');
16519 assert.deepEqual(
16520 moment().localeData().weekdaysShort(true),
16521 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
16522 'weekdaysShort should localeSort');
16523 assert.deepEqual(
16524 moment().localeData().weekdaysMin(true),
16525 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
16526 'weekdaysMin should localeSort');
16527 });
db71a655 16528 }
516f5f67 16529
db71a655 16530 /*global QUnit:false*/
73f3c911 16531
db71a655
KM
16532 function localeModule (name, lifecycle) {
16533 QUnit.module('locale:' + name, {
c58511b9 16534 beforeEach : function () {
db71a655
KM
16535 moment.locale(name);
16536 moment.createFromInputFallback = function (config) {
16537 throw new Error('input not handled by moment: ' + config._i);
16538 };
16539 setupDeprecationHandler(test, moment, 'locale');
16540 if (lifecycle && lifecycle.setup) {
16541 lifecycle.setup();
16542 }
16543 },
c58511b9 16544 afterEach : function () {
db71a655
KM
16545 moment.locale('en');
16546 teardownDeprecationHandler(test, moment, 'locale');
16547 if (lifecycle && lifecycle.teardown) {
16548 lifecycle.teardown();
16549 }
b135bf1a 16550 }
73f3c911 16551 });
db71a655
KM
16552 defineCommonLocaleTests(name, -1, -1);
16553 }
16554
96d0d679 16555 localeModule('en-nz');
db71a655
KM
16556
16557 test('parse', function (assert) {
96d0d679 16558 var tests = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_'), i;
db71a655
KM
16559 function equalTest(input, mmm, i) {
16560 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
16561 }
db71a655
KM
16562 for (i = 0; i < 12; i++) {
16563 tests[i] = tests[i].split(' ');
16564 equalTest(tests[i][0], 'MMM', i);
16565 equalTest(tests[i][1], 'MMM', i);
16566 equalTest(tests[i][0], 'MMMM', i);
16567 equalTest(tests[i][1], 'MMMM', i);
16568 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
16569 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
16570 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
16571 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
16572 }
16573 });
16574
16575 test('format', function (assert) {
16576 var a = [
16577 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Sunday, February 14th 2010, 3:25:50 pm'],
16578 ['ddd, hA', 'Sun, 3PM'],
16579 ['M Mo MM MMMM MMM', '2 2nd 02 February Feb'],
16580 ['YYYY YY', '2010 10'],
16581 ['D Do DD', '14 14th 14'],
16582 ['d do dddd ddd dd', '0 0th Sunday Sun Su'],
16583 ['DDD DDDo DDDD', '45 45th 045'],
96d0d679 16584 ['w wo ww', '6 6th 06'],
db71a655
KM
16585 ['h hh', '3 03'],
16586 ['H HH', '15 15'],
16587 ['m mm', '25 25'],
16588 ['s ss', '50 50'],
16589 ['a A', 'pm PM'],
16590 ['[the] DDDo [day of the year]', 'the 45th day of the year'],
16591 ['LTS', '3:25:50 PM'],
96d0d679
KM
16592 ['L', '14/02/2010'],
16593 ['LL', '14 February 2010'],
16594 ['LLL', '14 February 2010 3:25 PM'],
16595 ['LLLL', 'Sunday, 14 February 2010 3:25 PM'],
16596 ['l', '14/2/2010'],
16597 ['ll', '14 Feb 2010'],
16598 ['lll', '14 Feb 2010 3:25 PM'],
16599 ['llll', 'Sun, 14 Feb 2010 3:25 PM']
db71a655
KM
16600 ],
16601 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
16602 i;
db71a655
KM
16603 for (i = 0; i < a.length; i++) {
16604 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
16605 }
16606 });
16607
16608 test('format ordinal', function (assert) {
16609 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1st', '1st');
16610 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2nd', '2nd');
16611 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3rd', '3rd');
16612 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4th', '4th');
16613 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5th', '5th');
16614 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6th', '6th');
16615 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7th', '7th');
16616 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8th', '8th');
16617 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9th', '9th');
16618 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10th', '10th');
16619
16620 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11th', '11th');
16621 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12th', '12th');
16622 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13th', '13th');
16623 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14th', '14th');
16624 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15th', '15th');
16625 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16th', '16th');
16626 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17th', '17th');
16627 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18th', '18th');
16628 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19th', '19th');
16629 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20th', '20th');
16630
16631 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21st', '21st');
16632 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22nd', '22nd');
16633 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23rd', '23rd');
16634 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24th', '24th');
16635 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25th', '25th');
16636 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26th', '26th');
16637 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27th', '27th');
16638 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28th', '28th');
16639 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29th', '29th');
16640 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30th', '30th');
16641
16642 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31st', '31st');
16643 });
16644
16645 test('format month', function (assert) {
96d0d679 16646 var expected = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_'), i;
db71a655
KM
16647 for (i = 0; i < expected.length; i++) {
16648 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
16649 }
16650 });
16651
16652 test('format week', function (assert) {
96d0d679 16653 var expected = 'Sunday Sun Su_Monday Mon Mo_Tuesday Tue Tu_Wednesday Wed We_Thursday Thu Th_Friday Fri Fr_Saturday Sat Sa'.split('_'), i;
db71a655
KM
16654 for (i = 0; i < expected.length; i++) {
16655 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
16656 }
16657 });
16658
16659 test('from', function (assert) {
16660 var start = moment([2007, 1, 28]);
db71a655
KM
16661 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'a few seconds', '44 seconds = a few seconds');
16662 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'a minute', '45 seconds = a minute');
16663 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'a minute', '89 seconds = a minute');
16664 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes');
16665 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes');
16666 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'an hour', '45 minutes = an hour');
16667 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'an hour', '89 minutes = an hour');
16668 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hours', '90 minutes = 2 hours');
16669 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hours', '5 hours = 5 hours');
16670 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hours', '21 hours = 21 hours');
16671 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'a day', '22 hours = a day');
16672 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'a day', '35 hours = a day');
16673 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 days', '36 hours = 2 days');
16674 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'a day', '1 day = a day');
16675 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 days', '5 days = 5 days');
16676 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 days', '25 days = 25 days');
16677 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'a month', '26 days = a month');
16678 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'a month', '30 days = a month');
16679 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'a month', '43 days = a month');
16680 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 months', '46 days = 2 months');
16681 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 months', '75 days = 2 months');
16682 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 months', '76 days = 3 months');
16683 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'a month', '1 month = a month');
16684 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 months', '5 months = 5 months');
16685 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'a year', '345 days = a year');
16686 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 years', '548 days = 2 years');
16687 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'a year', '1 year = a year');
16688 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 years', '5 years = 5 years');
16689 });
16690
16691 test('suffix', function (assert) {
16692 assert.equal(moment(30000).from(0), 'in a few seconds', 'prefix');
16693 assert.equal(moment(0).from(30000), 'a few seconds ago', 'suffix');
16694 });
16695
16696 test('now from now', function (assert) {
16697 assert.equal(moment().fromNow(), 'a few seconds ago', 'now from now should display as in the past');
16698 });
16699
16700 test('fromNow', function (assert) {
16701 assert.equal(moment().add({s: 30}).fromNow(), 'in a few seconds', 'in a few seconds');
16702 assert.equal(moment().add({d: 5}).fromNow(), 'in 5 days', 'in 5 days');
16703 });
16704
16705 test('calendar day', function (assert) {
16706 var a = moment().hours(12).minutes(0).seconds(0);
16707
16708 assert.equal(moment(a).calendar(), 'Today at 12:00 PM', 'today at the same time');
16709 assert.equal(moment(a).add({m: 25}).calendar(), 'Today at 12:25 PM', 'Now plus 25 min');
16710 assert.equal(moment(a).add({h: 1}).calendar(), 'Today at 1:00 PM', 'Now plus 1 hour');
16711 assert.equal(moment(a).add({d: 1}).calendar(), 'Tomorrow at 12:00 PM', 'tomorrow at the same time');
16712 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Today at 11:00 AM', 'Now minus 1 hour');
16713 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Yesterday at 12:00 PM', 'yesterday at the same time');
16714 });
16715
16716 test('calendar next week', function (assert) {
16717 var i, m;
db71a655
KM
16718 for (i = 2; i < 7; i++) {
16719 m = moment().add({d: i});
16720 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days current time');
16721 m.hours(0).minutes(0).seconds(0).milliseconds(0);
16722 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days beginning of day');
16723 m.hours(23).minutes(59).seconds(59).milliseconds(999);
16724 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days end of day');
b135bf1a 16725 }
db71a655
KM
16726 });
16727
16728 test('calendar last week', function (assert) {
16729 var i, m;
16730
16731 for (i = 2; i < 7; i++) {
16732 m = moment().subtract({d: i});
16733 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days current time');
16734 m.hours(0).minutes(0).seconds(0).milliseconds(0);
16735 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days beginning of day');
16736 m.hours(23).minutes(59).seconds(59).milliseconds(999);
16737 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days end of day');
b135bf1a 16738 }
db71a655 16739 });
b135bf1a 16740
db71a655
KM
16741 test('calendar all else', function (assert) {
16742 var weeksAgo = moment().subtract({w: 1}),
16743 weeksFromNow = moment().add({w: 1});
b135bf1a 16744
db71a655
KM
16745 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
16746 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
b135bf1a 16747
db71a655
KM
16748 weeksAgo = moment().subtract({w: 2});
16749 weeksFromNow = moment().add({w: 2});
b135bf1a 16750
db71a655
KM
16751 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
16752 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
16753 });
16754
96d0d679
KM
16755 test('weeks year starting sunday formatted', function (assert) {
16756 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52nd', 'Jan 1 2012 should be week 52');
16757 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1st', 'Jan 2 2012 should be week 1');
16758 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1st', 'Jan 8 2012 should be week 1');
16759 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2nd', 'Jan 9 2012 should be week 2');
16760 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2nd', 'Jan 15 2012 should be week 2');
db71a655 16761 });
73f3c911
IC
16762
16763})));
d6651c21 16764
d6651c21 16765
73f3c911
IC
16766;(function (global, factory) {
16767 typeof exports === 'object' && typeof module !== 'undefined'
16768 && typeof require === 'function' ? factory(require('../../moment')) :
16769 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
16770 factory(global.moment)
16771}(this, (function (moment) { 'use strict';
d6651c21 16772
db71a655
KM
16773 function each(array, callback) {
16774 var i;
16775 for (i = 0; i < array.length; i++) {
16776 callback(array[i], i, array);
16777 }
73f3c911 16778 }
d6651c21 16779
c58511b9
KM
16780 function setupDeprecationHandler(test, moment$$1, scope) {
16781 test._expectedDeprecations = null;
16782 test._observedDeprecations = null;
16783 test._oldSupress = moment$$1.suppressDeprecationWarnings;
16784 moment$$1.suppressDeprecationWarnings = true;
16785 test.expectedDeprecations = function () {
16786 test._expectedDeprecations = arguments;
16787 test._observedDeprecations = [];
16788 };
16789 moment$$1.deprecationHandler = function (name, msg) {
16790 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
16791 if (deprecationId === -1) {
16792 throw new Error('Unexpected deprecation thrown name=' +
16793 name + ' msg=' + msg);
16794 }
16795 test._observedDeprecations[deprecationId] = 1;
16796 };
16797 }
16798
16799 function teardownDeprecationHandler(test, moment$$1, scope) {
16800 moment$$1.suppressDeprecationWarnings = test._oldSupress;
16801
16802 if (test._expectedDeprecations != null) {
16803 var missedDeprecations = [];
16804 each(test._expectedDeprecations, function (deprecationPattern, id) {
16805 if (test._observedDeprecations[id] !== 1) {
16806 missedDeprecations.push(deprecationPattern);
16807 }
16808 });
16809 if (missedDeprecations.length !== 0) {
16810 throw new Error('Expected deprecation warnings did not happen: ' +
16811 missedDeprecations.join(' '));
16812 }
16813 }
16814 }
16815
16816 function matchedDeprecation(name, msg, deprecations) {
16817 if (deprecations == null) {
16818 return -1;
16819 }
16820 for (var i = 0; i < deprecations.length; ++i) {
16821 if (name != null && name === deprecations[i]) {
16822 return i;
16823 }
16824 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
16825 return i;
16826 }
16827 }
16828 return -1;
16829 }
16830
16831 /*global QUnit:false*/
16832
16833 var test = QUnit.test;
16834
db71a655
KM
16835 function objectKeys(obj) {
16836 if (Object.keys) {
16837 return Object.keys(obj);
16838 } else {
16839 // IE8
16840 var res = [], i;
16841 for (i in obj) {
16842 if (obj.hasOwnProperty(i)) {
16843 res.push(i);
16844 }
d6651c21 16845 }
db71a655 16846 return res;
d6651c21
IC
16847 }
16848 }
16849
db71a655 16850 // Pick the first defined of two or three arguments.
b135bf1a 16851
db71a655
KM
16852 function defineCommonLocaleTests(locale, options) {
16853 test('lenient day of month ordinal parsing', function (assert) {
16854 var i, ordinalStr, testMoment;
16855 for (i = 1; i <= 31; ++i) {
16856 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
16857 testMoment = moment(ordinalStr, 'YYYY MM Do');
16858 assert.equal(testMoment.year(), 2014,
16859 'lenient day of month ordinal parsing ' + i + ' year check');
16860 assert.equal(testMoment.month(), 0,
16861 'lenient day of month ordinal parsing ' + i + ' month check');
16862 assert.equal(testMoment.date(), i,
16863 'lenient day of month ordinal parsing ' + i + ' date check');
16864 }
16865 });
516f5f67 16866
db71a655
KM
16867 test('lenient day of month ordinal parsing of number', function (assert) {
16868 var i, testMoment;
16869 for (i = 1; i <= 31; ++i) {
16870 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
16871 assert.equal(testMoment.year(), 2014,
16872 'lenient day of month ordinal parsing of number ' + i + ' year check');
16873 assert.equal(testMoment.month(), 0,
16874 'lenient day of month ordinal parsing of number ' + i + ' month check');
16875 assert.equal(testMoment.date(), i,
16876 'lenient day of month ordinal parsing of number ' + i + ' date check');
16877 }
16878 });
516f5f67 16879
db71a655
KM
16880 test('strict day of month ordinal parsing', function (assert) {
16881 var i, ordinalStr, testMoment;
16882 for (i = 1; i <= 31; ++i) {
16883 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
16884 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
16885 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
16886 }
16887 });
c74a101d 16888
db71a655
KM
16889 test('meridiem invariant', function (assert) {
16890 var h, m, t1, t2;
16891 for (h = 0; h < 24; ++h) {
16892 for (m = 0; m < 60; m += 15) {
16893 t1 = moment.utc([2000, 0, 1, h, m]);
16894 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
16895 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
16896 'meridiem at ' + t1.format('HH:mm'));
16897 }
16898 }
16899 });
16900
16901 test('date format correctness', function (assert) {
16902 var data, tokens;
16903 data = moment.localeData()._longDateFormat;
16904 tokens = objectKeys(data);
16905 each(tokens, function (srchToken) {
16906 // Check each format string to make sure it does not contain any
16907 // tokens that need to be expanded.
16908 each(tokens, function (baseToken) {
16909 // strip escaped sequences
16910 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
16911 assert.equal(false, !!~format.indexOf(srchToken),
16912 'contains ' + srchToken + ' in ' + baseToken);
16913 });
73f3c911 16914 });
516f5f67 16915 });
516f5f67 16916
db71a655
KM
16917 test('month parsing correctness', function (assert) {
16918 var i, m;
16919
16920 if (locale === 'tr') {
16921 // I can't fix it :(
c58511b9 16922 assert.expect(0);
db71a655
KM
16923 return;
16924 }
16925 function tester(format) {
16926 var r;
16927 r = moment(m.format(format), format);
16928 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
16929 if (locale !== 'ka') {
16930 r = moment(m.format(format).toLocaleUpperCase(), format);
16931 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
16932 }
db71a655
KM
16933 r = moment(m.format(format).toLocaleLowerCase(), format);
16934 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
16935
16936 r = moment(m.format(format), format, true);
16937 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
16938 if (locale !== 'ka') {
16939 r = moment(m.format(format).toLocaleUpperCase(), format, true);
16940 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
16941 }
db71a655
KM
16942 r = moment(m.format(format).toLocaleLowerCase(), format, true);
16943 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
16944 }
16945
16946 for (i = 0; i < 12; ++i) {
16947 m = moment([2015, i, 15, 18]);
16948 tester('MMM');
16949 tester('MMM.');
16950 tester('MMMM');
16951 tester('MMMM.');
16952 }
16953 });
c74a101d 16954
db71a655
KM
16955 test('weekday parsing correctness', function (assert) {
16956 var i, m;
16957
96d0d679 16958 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
16959 // tr, az: There is a lower-case letter (ı), that converted to
16960 // upper then lower changes to i
16961 // ro: there is the letter ț which behaves weird under IE8
16962 // mt: letter Ħ
96d0d679 16963 // ga: month with spaces
c58511b9 16964 assert.expect(0);
db71a655
KM
16965 return;
16966 }
16967 function tester(format) {
16968 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
16969 r = moment(m.format(format), format);
16970 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
16971 if (locale !== 'ka') {
16972 r = moment(m.format(format).toLocaleUpperCase(), format);
16973 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
16974 }
db71a655
KM
16975 r = moment(m.format(format).toLocaleLowerCase(), format);
16976 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
16977 r = moment(m.format(format), format, true);
16978 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
16979 if (locale !== 'ka') {
16980 r = moment(m.format(format).toLocaleUpperCase(), format, true);
16981 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
16982 }
db71a655
KM
16983 r = moment(m.format(format).toLocaleLowerCase(), format, true);
16984 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
16985 }
16986
16987 for (i = 0; i < 7; ++i) {
16988 m = moment.utc([2015, 0, i + 1, 18]);
16989 tester('dd');
16990 tester('ddd');
16991 tester('dddd');
16992 }
16993 });
516f5f67 16994
db71a655
KM
16995 test('valid localeData', function (assert) {
16996 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
16997 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
16998 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
16999 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
17000 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
17001 });
96d0d679
KM
17002
17003 test('localeData weekdays can localeSort', function (assert) {
17004 var weekdays = moment().localeData().weekdays();
17005 var weekdaysShort = moment().localeData().weekdaysShort();
17006 var weekdaysMin = moment().localeData().weekdaysMin();
17007 var shift = moment().localeData()._week.dow;
17008 assert.deepEqual(
17009 moment().localeData().weekdays(true),
17010 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
17011 'weekdays should localeSort');
17012 assert.deepEqual(
17013 moment().localeData().weekdaysShort(true),
17014 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
17015 'weekdaysShort should localeSort');
17016 assert.deepEqual(
17017 moment().localeData().weekdaysMin(true),
17018 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
17019 'weekdaysMin should localeSort');
17020 });
db71a655 17021 }
c74a101d 17022
db71a655
KM
17023 /*global QUnit:false*/
17024
db71a655
KM
17025 function localeModule (name, lifecycle) {
17026 QUnit.module('locale:' + name, {
c58511b9 17027 beforeEach : function () {
db71a655
KM
17028 moment.locale(name);
17029 moment.createFromInputFallback = function (config) {
17030 throw new Error('input not handled by moment: ' + config._i);
17031 };
17032 setupDeprecationHandler(test, moment, 'locale');
17033 if (lifecycle && lifecycle.setup) {
17034 lifecycle.setup();
17035 }
17036 },
c58511b9 17037 afterEach : function () {
db71a655
KM
17038 moment.locale('en');
17039 teardownDeprecationHandler(test, moment, 'locale');
17040 if (lifecycle && lifecycle.teardown) {
17041 lifecycle.teardown();
17042 }
b135bf1a 17043 }
73f3c911 17044 });
db71a655
KM
17045 defineCommonLocaleTests(name, -1, -1);
17046 }
17047
96d0d679 17048 localeModule('en');
db71a655
KM
17049
17050 test('parse', function (assert) {
96d0d679
KM
17051 var i,
17052 tests = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_');
17053
db71a655
KM
17054 function equalTest(input, mmm, i) {
17055 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
17056 }
96d0d679 17057
db71a655
KM
17058 for (i = 0; i < 12; i++) {
17059 tests[i] = tests[i].split(' ');
17060 equalTest(tests[i][0], 'MMM', i);
17061 equalTest(tests[i][1], 'MMM', i);
17062 equalTest(tests[i][0], 'MMMM', i);
17063 equalTest(tests[i][1], 'MMMM', i);
17064 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
17065 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
17066 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
17067 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
17068 }
17069 });
17070
17071 test('format', function (assert) {
17072 var a = [
96d0d679
KM
17073 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Sunday, February 14th 2010, 3:25:50 pm'],
17074 ['ddd, hA', 'Sun, 3PM'],
17075 ['M Mo MM MMMM MMM', '2 2nd 02 February Feb'],
db71a655 17076 ['YYYY YY', '2010 10'],
96d0d679
KM
17077 ['D Do DD', '14 14th 14'],
17078 ['d do dddd ddd dd', '0 0th Sunday Sun Su'],
17079 ['DDD DDDo DDDD', '45 45th 045'],
17080 ['w wo ww', '8 8th 08'],
db71a655
KM
17081 ['h hh', '3 03'],
17082 ['H HH', '15 15'],
17083 ['m mm', '25 25'],
17084 ['s ss', '50 50'],
96d0d679
KM
17085 ['a A', 'pm PM'],
17086 ['[the] DDDo [day of the year]', 'the 45th day of the year'],
17087 ['LTS', '3:25:50 PM'],
17088 ['L', '02/14/2010'],
17089 ['LL', 'February 14, 2010'],
17090 ['LLL', 'February 14, 2010 3:25 PM'],
17091 ['LLLL', 'Sunday, February 14, 2010 3:25 PM'],
17092 ['l', '2/14/2010'],
17093 ['ll', 'Feb 14, 2010'],
17094 ['lll', 'Feb 14, 2010 3:25 PM'],
17095 ['llll', 'Sun, Feb 14, 2010 3:25 PM']
db71a655
KM
17096 ],
17097 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
17098 i;
96d0d679 17099
db71a655
KM
17100 for (i = 0; i < a.length; i++) {
17101 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
17102 }
17103 });
17104
17105 test('format ordinal', function (assert) {
96d0d679
KM
17106 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1st', '1st');
17107 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2nd', '2nd');
17108 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3rd', '3rd');
17109 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4th', '4th');
17110 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5th', '5th');
17111 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6th', '6th');
17112 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7th', '7th');
17113 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8th', '8th');
17114 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9th', '9th');
17115 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10th', '10th');
db71a655 17116
96d0d679
KM
17117 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11th', '11th');
17118 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12th', '12th');
17119 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13th', '13th');
17120 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14th', '14th');
17121 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15th', '15th');
17122 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16th', '16th');
17123 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17th', '17th');
17124 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18th', '18th');
17125 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19th', '19th');
17126 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20th', '20th');
db71a655 17127
96d0d679
KM
17128 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21st', '21st');
17129 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22nd', '22nd');
17130 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23rd', '23rd');
17131 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24th', '24th');
17132 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25th', '25th');
17133 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26th', '26th');
17134 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27th', '27th');
17135 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28th', '28th');
17136 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29th', '29th');
17137 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30th', '30th');
db71a655 17138
96d0d679 17139 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31st', '31st');
db71a655
KM
17140 });
17141
17142 test('format month', function (assert) {
96d0d679
KM
17143 var i,
17144 expected = 'January Jan_February Feb_March Mar_April Apr_May May_June Jun_July Jul_August Aug_September Sep_October Oct_November Nov_December Dec'.split('_');
17145
db71a655
KM
17146 for (i = 0; i < expected.length; i++) {
17147 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
17148 }
17149 });
17150
17151 test('format week', function (assert) {
96d0d679
KM
17152 var i,
17153 expected = 'Sunday Sun Su_Monday Mon Mo_Tuesday Tue Tu_Wednesday Wed We_Thursday Thu Th_Friday Fri Fr_Saturday Sat Sa'.split('_');
17154
db71a655
KM
17155 for (i = 0; i < expected.length; i++) {
17156 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
17157 }
17158 });
17159
17160 test('from', function (assert) {
17161 var start = moment([2007, 1, 28]);
96d0d679
KM
17162
17163 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'a few seconds', '44 seconds = a few seconds');
17164 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'a minute', '45 seconds = a minute');
17165 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'a minute', '89 seconds = a minute');
17166 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes');
17167 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes');
17168 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'an hour', '45 minutes = an hour');
17169 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'an hour', '89 minutes = an hour');
17170 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hours', '90 minutes = 2 hours');
17171 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hours', '5 hours = 5 hours');
17172 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hours', '21 hours = 21 hours');
17173 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'a day', '22 hours = a day');
17174 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'a day', '35 hours = a day');
17175 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 days', '36 hours = 2 days');
17176 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'a day', '1 day = a day');
17177 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 days', '5 days = 5 days');
17178 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 days', '25 days = 25 days');
17179 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'a month', '26 days = a month');
17180 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'a month', '30 days = a month');
17181 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'a month', '43 days = a month');
17182 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 months', '46 days = 2 months');
17183 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 months', '75 days = 2 months');
17184 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 months', '76 days = 3 months');
17185 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'a month', '1 month = a month');
17186 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 months', '5 months = 5 months');
17187 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'a year', '345 days = a year');
17188 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 years', '548 days = 2 years');
17189 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'a year', '1 year = a year');
17190 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 years', '5 years = 5 years');
db71a655
KM
17191 });
17192
17193 test('suffix', function (assert) {
96d0d679
KM
17194 assert.equal(moment(30000).from(0), 'in a few seconds', 'prefix');
17195 assert.equal(moment(0).from(30000), 'a few seconds ago', 'suffix');
db71a655
KM
17196 });
17197
17198 test('now from now', function (assert) {
96d0d679 17199 assert.equal(moment().fromNow(), 'a few seconds ago', 'now from now should display as in the past');
db71a655
KM
17200 });
17201
17202 test('fromNow', function (assert) {
96d0d679
KM
17203 assert.equal(moment().add({s: 30}).fromNow(), 'in a few seconds', 'in a few seconds');
17204 assert.equal(moment().add({d: 5}).fromNow(), 'in 5 days', 'in 5 days');
db71a655
KM
17205 });
17206
17207 test('calendar day', function (assert) {
17208 var a = moment().hours(12).minutes(0).seconds(0);
17209
96d0d679
KM
17210 assert.equal(moment(a).calendar(), 'Today at 12:00 PM', 'today at the same time');
17211 assert.equal(moment(a).add({m: 25}).calendar(), 'Today at 12:25 PM', 'Now plus 25 min');
17212 assert.equal(moment(a).add({h: 1}).calendar(), 'Today at 1:00 PM', 'Now plus 1 hour');
17213 assert.equal(moment(a).add({d: 1}).calendar(), 'Tomorrow at 12:00 PM', 'tomorrow at the same time');
17214 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Today at 11:00 AM', 'Now minus 1 hour');
17215 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Yesterday at 12:00 PM', 'yesterday at the same time');
db71a655
KM
17216 });
17217
17218 test('calendar next week', function (assert) {
17219 var i, m;
b135bf1a 17220
db71a655
KM
17221 for (i = 2; i < 7; i++) {
17222 m = moment().add({d: i});
96d0d679 17223 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days current time');
db71a655 17224 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 17225 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days beginning of day');
db71a655 17226 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 17227 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days end of day');
b135bf1a 17228 }
db71a655
KM
17229 });
17230
17231 test('calendar last week', function (assert) {
17232 var i, m;
17233
17234 for (i = 2; i < 7; i++) {
17235 m = moment().subtract({d: i});
96d0d679 17236 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days current time');
db71a655 17237 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 17238 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days beginning of day');
db71a655 17239 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 17240 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days end of day');
b135bf1a 17241 }
db71a655 17242 });
b135bf1a 17243
db71a655
KM
17244 test('calendar all else', function (assert) {
17245 var weeksAgo = moment().subtract({w: 1}),
17246 weeksFromNow = moment().add({w: 1});
b135bf1a 17247
db71a655
KM
17248 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
17249 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
b135bf1a 17250
db71a655
KM
17251 weeksAgo = moment().subtract({w: 2});
17252 weeksFromNow = moment().add({w: 2});
b135bf1a 17253
db71a655
KM
17254 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
17255 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
17256 });
17257
96d0d679
KM
17258 test('weeks year starting sunday format', function (assert) {
17259 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1st', 'Jan 1 2012 should be week 1');
17260 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1st', 'Jan 7 2012 should be week 1');
17261 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2nd', 'Jan 8 2012 should be week 2');
17262 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2nd', 'Jan 14 2012 should be week 2');
17263 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3rd', 'Jan 15 2012 should be week 3');
17264 });
17265
17266 test('weekdays strict parsing', function (assert) {
17267 var m = moment('2015-01-01T12', moment.ISO_8601, true),
17268 enLocale = moment.localeData('en');
17269
17270 for (var i = 0; i < 7; ++i) {
17271 assert.equal(moment(enLocale.weekdays(m.day(i), ''), 'dddd', true).isValid(), true, 'parse weekday ' + i);
17272 assert.equal(moment(enLocale.weekdaysShort(m.day(i), ''), 'ddd', true).isValid(), true, 'parse short weekday ' + i);
17273 assert.equal(moment(enLocale.weekdaysMin(m.day(i), ''), 'dd', true).isValid(), true, 'parse min weekday ' + i);
17274
17275 // negative tests
17276 assert.equal(moment(enLocale.weekdaysMin(m.day(i), ''), 'ddd', true).isValid(), false, 'parse short weekday ' + i);
17277 assert.equal(moment(enLocale.weekdaysShort(m.day(i), ''), 'dd', true).isValid(), false, 'parse min weekday ' + i);
17278 }
db71a655 17279 });
9483e2a4 17280
73f3c911 17281})));
d6651c21 17282
d6651c21 17283
73f3c911
IC
17284;(function (global, factory) {
17285 typeof exports === 'object' && typeof module !== 'undefined'
17286 && typeof require === 'function' ? factory(require('../../moment')) :
17287 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
17288 factory(global.moment)
17289}(this, (function (moment) { 'use strict';
d6651c21 17290
db71a655
KM
17291 function each(array, callback) {
17292 var i;
17293 for (i = 0; i < array.length; i++) {
17294 callback(array[i], i, array);
17295 }
d6651c21
IC
17296 }
17297
c58511b9
KM
17298 function setupDeprecationHandler(test, moment$$1, scope) {
17299 test._expectedDeprecations = null;
17300 test._observedDeprecations = null;
17301 test._oldSupress = moment$$1.suppressDeprecationWarnings;
17302 moment$$1.suppressDeprecationWarnings = true;
17303 test.expectedDeprecations = function () {
17304 test._expectedDeprecations = arguments;
17305 test._observedDeprecations = [];
17306 };
17307 moment$$1.deprecationHandler = function (name, msg) {
17308 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
17309 if (deprecationId === -1) {
17310 throw new Error('Unexpected deprecation thrown name=' +
17311 name + ' msg=' + msg);
17312 }
17313 test._observedDeprecations[deprecationId] = 1;
17314 };
17315 }
17316
17317 function teardownDeprecationHandler(test, moment$$1, scope) {
17318 moment$$1.suppressDeprecationWarnings = test._oldSupress;
17319
17320 if (test._expectedDeprecations != null) {
17321 var missedDeprecations = [];
17322 each(test._expectedDeprecations, function (deprecationPattern, id) {
17323 if (test._observedDeprecations[id] !== 1) {
17324 missedDeprecations.push(deprecationPattern);
17325 }
17326 });
17327 if (missedDeprecations.length !== 0) {
17328 throw new Error('Expected deprecation warnings did not happen: ' +
17329 missedDeprecations.join(' '));
17330 }
17331 }
17332 }
17333
17334 function matchedDeprecation(name, msg, deprecations) {
17335 if (deprecations == null) {
17336 return -1;
17337 }
17338 for (var i = 0; i < deprecations.length; ++i) {
17339 if (name != null && name === deprecations[i]) {
17340 return i;
17341 }
17342 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
17343 return i;
17344 }
17345 }
17346 return -1;
17347 }
17348
17349 /*global QUnit:false*/
17350
17351 var test = QUnit.test;
17352
db71a655
KM
17353 function objectKeys(obj) {
17354 if (Object.keys) {
17355 return Object.keys(obj);
17356 } else {
17357 // IE8
17358 var res = [], i;
17359 for (i in obj) {
17360 if (obj.hasOwnProperty(i)) {
17361 res.push(i);
17362 }
d6651c21 17363 }
db71a655 17364 return res;
d6651c21 17365 }
b135bf1a
IC
17366 }
17367
db71a655 17368 // Pick the first defined of two or three arguments.
73f3c911 17369
db71a655
KM
17370 function defineCommonLocaleTests(locale, options) {
17371 test('lenient day of month ordinal parsing', function (assert) {
17372 var i, ordinalStr, testMoment;
17373 for (i = 1; i <= 31; ++i) {
17374 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
17375 testMoment = moment(ordinalStr, 'YYYY MM Do');
17376 assert.equal(testMoment.year(), 2014,
17377 'lenient day of month ordinal parsing ' + i + ' year check');
17378 assert.equal(testMoment.month(), 0,
17379 'lenient day of month ordinal parsing ' + i + ' month check');
17380 assert.equal(testMoment.date(), i,
17381 'lenient day of month ordinal parsing ' + i + ' date check');
17382 }
17383 });
516f5f67 17384
db71a655
KM
17385 test('lenient day of month ordinal parsing of number', function (assert) {
17386 var i, testMoment;
17387 for (i = 1; i <= 31; ++i) {
17388 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
17389 assert.equal(testMoment.year(), 2014,
17390 'lenient day of month ordinal parsing of number ' + i + ' year check');
17391 assert.equal(testMoment.month(), 0,
17392 'lenient day of month ordinal parsing of number ' + i + ' month check');
17393 assert.equal(testMoment.date(), i,
17394 'lenient day of month ordinal parsing of number ' + i + ' date check');
17395 }
17396 });
516f5f67 17397
db71a655
KM
17398 test('strict day of month ordinal parsing', function (assert) {
17399 var i, ordinalStr, testMoment;
17400 for (i = 1; i <= 31; ++i) {
17401 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
17402 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
17403 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
17404 }
17405 });
c74a101d 17406
db71a655
KM
17407 test('meridiem invariant', function (assert) {
17408 var h, m, t1, t2;
17409 for (h = 0; h < 24; ++h) {
17410 for (m = 0; m < 60; m += 15) {
17411 t1 = moment.utc([2000, 0, 1, h, m]);
17412 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
17413 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
17414 'meridiem at ' + t1.format('HH:mm'));
17415 }
17416 }
17417 });
17418
17419 test('date format correctness', function (assert) {
17420 var data, tokens;
17421 data = moment.localeData()._longDateFormat;
17422 tokens = objectKeys(data);
17423 each(tokens, function (srchToken) {
17424 // Check each format string to make sure it does not contain any
17425 // tokens that need to be expanded.
17426 each(tokens, function (baseToken) {
17427 // strip escaped sequences
17428 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
17429 assert.equal(false, !!~format.indexOf(srchToken),
17430 'contains ' + srchToken + ' in ' + baseToken);
17431 });
73f3c911 17432 });
516f5f67 17433 });
516f5f67 17434
db71a655
KM
17435 test('month parsing correctness', function (assert) {
17436 var i, m;
17437
17438 if (locale === 'tr') {
17439 // I can't fix it :(
c58511b9 17440 assert.expect(0);
db71a655
KM
17441 return;
17442 }
17443 function tester(format) {
17444 var r;
17445 r = moment(m.format(format), format);
17446 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
17447 if (locale !== 'ka') {
17448 r = moment(m.format(format).toLocaleUpperCase(), format);
17449 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
17450 }
db71a655
KM
17451 r = moment(m.format(format).toLocaleLowerCase(), format);
17452 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
17453
17454 r = moment(m.format(format), format, true);
17455 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
17456 if (locale !== 'ka') {
17457 r = moment(m.format(format).toLocaleUpperCase(), format, true);
17458 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
17459 }
db71a655
KM
17460 r = moment(m.format(format).toLocaleLowerCase(), format, true);
17461 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
17462 }
17463
17464 for (i = 0; i < 12; ++i) {
17465 m = moment([2015, i, 15, 18]);
17466 tester('MMM');
17467 tester('MMM.');
17468 tester('MMMM');
17469 tester('MMMM.');
17470 }
17471 });
c74a101d 17472
db71a655
KM
17473 test('weekday parsing correctness', function (assert) {
17474 var i, m;
17475
96d0d679 17476 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
17477 // tr, az: There is a lower-case letter (ı), that converted to
17478 // upper then lower changes to i
17479 // ro: there is the letter ț which behaves weird under IE8
17480 // mt: letter Ħ
96d0d679 17481 // ga: month with spaces
c58511b9 17482 assert.expect(0);
db71a655
KM
17483 return;
17484 }
17485 function tester(format) {
17486 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
17487 r = moment(m.format(format), format);
17488 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
17489 if (locale !== 'ka') {
17490 r = moment(m.format(format).toLocaleUpperCase(), format);
17491 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
17492 }
db71a655
KM
17493 r = moment(m.format(format).toLocaleLowerCase(), format);
17494 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
17495 r = moment(m.format(format), format, true);
17496 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
17497 if (locale !== 'ka') {
17498 r = moment(m.format(format).toLocaleUpperCase(), format, true);
17499 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
17500 }
db71a655
KM
17501 r = moment(m.format(format).toLocaleLowerCase(), format, true);
17502 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
17503 }
17504
17505 for (i = 0; i < 7; ++i) {
17506 m = moment.utc([2015, 0, i + 1, 18]);
17507 tester('dd');
17508 tester('ddd');
17509 tester('dddd');
17510 }
17511 });
516f5f67 17512
db71a655
KM
17513 test('valid localeData', function (assert) {
17514 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
17515 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
17516 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
17517 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
17518 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
17519 });
96d0d679
KM
17520
17521 test('localeData weekdays can localeSort', function (assert) {
17522 var weekdays = moment().localeData().weekdays();
17523 var weekdaysShort = moment().localeData().weekdaysShort();
17524 var weekdaysMin = moment().localeData().weekdaysMin();
17525 var shift = moment().localeData()._week.dow;
17526 assert.deepEqual(
17527 moment().localeData().weekdays(true),
17528 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
17529 'weekdays should localeSort');
17530 assert.deepEqual(
17531 moment().localeData().weekdaysShort(true),
17532 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
17533 'weekdaysShort should localeSort');
17534 assert.deepEqual(
17535 moment().localeData().weekdaysMin(true),
17536 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
17537 'weekdaysMin should localeSort');
17538 });
db71a655 17539 }
c74a101d 17540
db71a655 17541 /*global QUnit:false*/
b135bf1a 17542
db71a655
KM
17543 function localeModule (name, lifecycle) {
17544 QUnit.module('locale:' + name, {
c58511b9 17545 beforeEach : function () {
db71a655
KM
17546 moment.locale(name);
17547 moment.createFromInputFallback = function (config) {
17548 throw new Error('input not handled by moment: ' + config._i);
17549 };
17550 setupDeprecationHandler(test, moment, 'locale');
17551 if (lifecycle && lifecycle.setup) {
17552 lifecycle.setup();
17553 }
17554 },
c58511b9 17555 afterEach : function () {
db71a655
KM
17556 moment.locale('en');
17557 teardownDeprecationHandler(test, moment, 'locale');
17558 if (lifecycle && lifecycle.teardown) {
17559 lifecycle.teardown();
17560 }
b135bf1a 17561 }
73f3c911 17562 });
db71a655
KM
17563 defineCommonLocaleTests(name, -1, -1);
17564 }
17565
96d0d679 17566 localeModule('eo');
db71a655
KM
17567
17568 test('parse', function (assert) {
96d0d679 17569 var tests = 'januaro jan_februaro feb_marto mar_aprilo apr_majo maj_junio jun_julio jul_aŭgusto aŭg_septembro sep_oktobro okt_novembro nov_decembro dec'.split('_'), i;
db71a655
KM
17570 function equalTest(input, mmm, i) {
17571 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
17572 }
17573 for (i = 0; i < 12; i++) {
17574 tests[i] = tests[i].split(' ');
17575 equalTest(tests[i][0], 'MMM', i);
17576 equalTest(tests[i][1], 'MMM', i);
17577 equalTest(tests[i][0], 'MMMM', i);
17578 equalTest(tests[i][1], 'MMMM', i);
17579 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
17580 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
17581 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
17582 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
17583 }
17584 });
17585
17586 test('format', function (assert) {
17587 var a = [
96d0d679
KM
17588 ['dddd, MMMM Do YYYY, h:mm:ss a', 'dimanĉo, februaro 14a 2010, 3:25:50 p.t.m.'],
17589 ['ddd, hA', 'dim, 3P.T.M.'],
17590 ['M Mo MM MMMM MMM', '2 2a 02 februaro feb'],
db71a655 17591 ['YYYY YY', '2010 10'],
96d0d679
KM
17592 ['D Do DD', '14 14a 14'],
17593 ['d do dddd ddd dd', '0 0a dimanĉo dim di'],
17594 ['DDD DDDo DDDD', '45 45a 045'],
17595 ['w wo ww', '7 7a 07'],
db71a655
KM
17596 ['h hh', '3 03'],
17597 ['H HH', '15 15'],
17598 ['m mm', '25 25'],
17599 ['s ss', '50 50'],
96d0d679
KM
17600 ['a A', 'p.t.m. P.T.M.'],
17601 ['[la] DDDo [tago] [de] [la] [jaro]', 'la 45a tago de la jaro'],
17602 ['LTS', '15:25:50'],
17603 ['L', '2010-02-14'],
17604 ['LL', '14-a de februaro, 2010'],
17605 ['LLL', '14-a de februaro, 2010 15:25'],
17606 ['LLLL', 'dimanĉo, la 14-a de februaro, 2010 15:25'],
17607 ['l', '2010-2-14'],
17608 ['ll', '14-a de feb, 2010'],
17609 ['lll', '14-a de feb, 2010 15:25'],
17610 ['llll', 'dim, la 14-a de feb, 2010 15:25']
db71a655
KM
17611 ],
17612 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
17613 i;
17614 for (i = 0; i < a.length; i++) {
17615 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
17616 }
17617 });
17618
17619 test('format ordinal', function (assert) {
96d0d679
KM
17620 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1a', '1a');
17621 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2a', '2a');
17622 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3a', '3a');
17623 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4a', '4a');
17624 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5a', '5a');
17625 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6a', '6a');
17626 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7a', '7a');
17627 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8a', '8a');
17628 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9a', '9a');
17629 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10a', '10a');
db71a655 17630
96d0d679
KM
17631 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11a', '11a');
17632 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12a', '12a');
17633 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13a', '13a');
17634 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14a', '14a');
17635 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15a', '15a');
17636 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16a', '16a');
17637 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17a', '17a');
17638 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18a', '18a');
17639 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19a', '19a');
17640 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20a', '20a');
db71a655 17641
96d0d679
KM
17642 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21a', '21a');
17643 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22a', '22a');
17644 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23a', '23a');
17645 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24a', '24a');
17646 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25a', '25a');
17647 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26a', '26a');
17648 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27a', '27a');
17649 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28a', '28a');
17650 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29a', '29a');
17651 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30a', '30a');
db71a655 17652
96d0d679 17653 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31a', '31a');
db71a655
KM
17654 });
17655
17656 test('format month', function (assert) {
96d0d679 17657 var expected = 'januaro jan_februaro feb_marto mar_aprilo apr_majo maj_junio jun_julio jul_aŭgusto aŭg_septembro sep_oktobro okt_novembro nov_decembro dec'.split('_'), i;
db71a655
KM
17658 for (i = 0; i < expected.length; i++) {
17659 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
17660 }
17661 });
17662
17663 test('format week', function (assert) {
96d0d679 17664 var expected = 'dimanĉo dim di_lundo lun lu_mardo mard ma_merkredo merk me_ĵaŭdo ĵaŭ ĵa_vendredo ven ve_sabato sab sa'.split('_'), i;
db71a655
KM
17665 for (i = 0; i < expected.length; i++) {
17666 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
17667 }
17668 });
17669
17670 test('from', function (assert) {
17671 var start = moment([2007, 1, 28]);
96d0d679
KM
17672 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'sekundoj', '44 seconds = a few seconds');
17673 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minuto', '45 seconds = a minute');
17674 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minuto', '89 seconds = a minute');
17675 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutoj', '90 seconds = 2 minutes');
17676 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutoj', '44 minutes = 44 minutes');
17677 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'horo', '45 minutes = an hour');
17678 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'horo', '89 minutes = an hour');
17679 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 horoj', '90 minutes = 2 hours');
17680 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 horoj', '5 hours = 5 hours');
17681 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 horoj', '21 hours = 21 hours');
17682 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'tago', '22 hours = a day');
17683 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'tago', '35 hours = a day');
17684 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 tagoj', '36 hours = 2 days');
17685 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'tago', '1 day = a day');
17686 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 tagoj', '5 days = 5 days');
17687 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 tagoj', '25 days = 25 days');
17688 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'monato', '26 days = a month');
17689 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'monato', '30 days = a month');
17690 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'monato', '43 days = a month');
17691 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 monatoj', '46 days = 2 months');
17692 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 monatoj', '75 days = 2 months');
17693 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 monatoj', '76 days = 3 months');
17694 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'monato', '1 month = a month');
17695 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 monatoj', '5 months = 5 months');
17696 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'jaro', '345 days = a year');
17697 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 jaroj', '548 days = 2 years');
17698 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'jaro', '1 year = a year');
17699 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 jaroj', '5 years = 5 years');
db71a655
KM
17700 });
17701
17702 test('suffix', function (assert) {
96d0d679
KM
17703 assert.equal(moment(30000).from(0), 'post sekundoj', 'post prefix');
17704 assert.equal(moment(0).from(30000), 'antaŭ sekundoj', 'antaŭ prefix');
db71a655
KM
17705 });
17706
17707 test('now from now', function (assert) {
96d0d679 17708 assert.equal(moment().fromNow(), 'antaŭ sekundoj', 'now from now should display as in the past');
db71a655
KM
17709 });
17710
17711 test('fromNow', function (assert) {
96d0d679
KM
17712 assert.equal(moment().add({s: 30}).fromNow(), 'post sekundoj', 'post sekundoj');
17713 assert.equal(moment().add({d: 5}).fromNow(), 'post 5 tagoj', 'post 5 tagoj');
db71a655
KM
17714 });
17715
17716 test('calendar day', function (assert) {
17717 var a = moment().hours(12).minutes(0).seconds(0);
17718
96d0d679
KM
17719 assert.equal(moment(a).calendar(), 'Hodiaŭ je 12:00', 'today at the same time');
17720 assert.equal(moment(a).add({m: 25}).calendar(), 'Hodiaŭ je 12:25', 'Now plus 25 min');
17721 assert.equal(moment(a).add({h: 1}).calendar(), 'Hodiaŭ je 13:00', 'Now plus 1 hour');
17722 assert.equal(moment(a).add({d: 1}).calendar(), 'Morgaŭ je 12:00', 'tomorrow at the same time');
17723 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Hodiaŭ je 11:00', 'Now minus 1 hour');
17724 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Hieraŭ je 12:00', 'yesterday at the same time');
db71a655
KM
17725 });
17726
17727 test('calendar next week', function (assert) {
17728 var i, m;
b135bf1a 17729
db71a655
KM
17730 for (i = 2; i < 7; i++) {
17731 m = moment().add({d: i});
96d0d679 17732 assert.equal(m.calendar(), m.format('dddd [je] LT'), 'Today + ' + i + ' days current time');
db71a655 17733 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 17734 assert.equal(m.calendar(), m.format('dddd [je] LT'), 'Today + ' + i + ' days beginning of day');
db71a655 17735 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 17736 assert.equal(m.calendar(), m.format('dddd [je] LT'), 'Today + ' + i + ' days end of day');
b135bf1a 17737 }
db71a655
KM
17738 });
17739
17740 test('calendar last week', function (assert) {
17741 var i, m;
17742
17743 for (i = 2; i < 7; i++) {
17744 m = moment().subtract({d: i});
96d0d679 17745 assert.equal(m.calendar(), m.format('[pasinta] dddd [je] LT'), 'Today - ' + i + ' days current time');
db71a655 17746 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 17747 assert.equal(m.calendar(), m.format('[pasinta] dddd [je] LT'), 'Today - ' + i + ' days beginning of day');
db71a655 17748 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 17749 assert.equal(m.calendar(), m.format('[pasinta] dddd [je] LT'), 'Today - ' + i + ' days end of day');
b135bf1a 17750 }
db71a655 17751 });
b135bf1a 17752
db71a655
KM
17753 test('calendar all else', function (assert) {
17754 var weeksAgo = moment().subtract({w: 1}),
17755 weeksFromNow = moment().add({w: 1});
b135bf1a 17756
db71a655
KM
17757 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
17758 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
b135bf1a 17759
db71a655
KM
17760 weeksAgo = moment().subtract({w: 2});
17761 weeksFromNow = moment().add({w: 2});
b135bf1a 17762
db71a655
KM
17763 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
17764 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
17765 });
17766
17767 test('weeks year starting sunday formatted', function (assert) {
96d0d679
KM
17768 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1a', 'Dec 26 2011 should be week 1');
17769 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1a', 'Jan 1 2012 should be week 1');
17770 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2a', 'Jan 2 2012 should be week 2');
17771 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2a', 'Jan 8 2012 should be week 2');
17772 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3a', 'Jan 9 2012 should be week 3');
db71a655 17773 });
73f3c911
IC
17774
17775})));
d6651c21 17776
d6651c21 17777
73f3c911
IC
17778;(function (global, factory) {
17779 typeof exports === 'object' && typeof module !== 'undefined'
17780 && typeof require === 'function' ? factory(require('../../moment')) :
17781 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
17782 factory(global.moment)
17783}(this, (function (moment) { 'use strict';
d6651c21 17784
db71a655
KM
17785 function each(array, callback) {
17786 var i;
17787 for (i = 0; i < array.length; i++) {
17788 callback(array[i], i, array);
17789 }
d6651c21
IC
17790 }
17791
c58511b9
KM
17792 function setupDeprecationHandler(test, moment$$1, scope) {
17793 test._expectedDeprecations = null;
17794 test._observedDeprecations = null;
17795 test._oldSupress = moment$$1.suppressDeprecationWarnings;
17796 moment$$1.suppressDeprecationWarnings = true;
17797 test.expectedDeprecations = function () {
17798 test._expectedDeprecations = arguments;
17799 test._observedDeprecations = [];
17800 };
17801 moment$$1.deprecationHandler = function (name, msg) {
17802 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
17803 if (deprecationId === -1) {
17804 throw new Error('Unexpected deprecation thrown name=' +
17805 name + ' msg=' + msg);
17806 }
17807 test._observedDeprecations[deprecationId] = 1;
17808 };
17809 }
17810
17811 function teardownDeprecationHandler(test, moment$$1, scope) {
17812 moment$$1.suppressDeprecationWarnings = test._oldSupress;
17813
17814 if (test._expectedDeprecations != null) {
17815 var missedDeprecations = [];
17816 each(test._expectedDeprecations, function (deprecationPattern, id) {
17817 if (test._observedDeprecations[id] !== 1) {
17818 missedDeprecations.push(deprecationPattern);
17819 }
17820 });
17821 if (missedDeprecations.length !== 0) {
17822 throw new Error('Expected deprecation warnings did not happen: ' +
17823 missedDeprecations.join(' '));
17824 }
17825 }
17826 }
17827
17828 function matchedDeprecation(name, msg, deprecations) {
17829 if (deprecations == null) {
17830 return -1;
17831 }
17832 for (var i = 0; i < deprecations.length; ++i) {
17833 if (name != null && name === deprecations[i]) {
17834 return i;
17835 }
17836 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
17837 return i;
17838 }
17839 }
17840 return -1;
17841 }
17842
17843 /*global QUnit:false*/
17844
17845 var test = QUnit.test;
17846
db71a655
KM
17847 function objectKeys(obj) {
17848 if (Object.keys) {
17849 return Object.keys(obj);
17850 } else {
17851 // IE8
17852 var res = [], i;
17853 for (i in obj) {
17854 if (obj.hasOwnProperty(i)) {
17855 res.push(i);
17856 }
d6651c21 17857 }
db71a655 17858 return res;
d6651c21 17859 }
b135bf1a 17860 }
516f5f67 17861
db71a655 17862 // Pick the first defined of two or three arguments.
d40760af 17863
db71a655
KM
17864 function defineCommonLocaleTests(locale, options) {
17865 test('lenient day of month ordinal parsing', function (assert) {
17866 var i, ordinalStr, testMoment;
17867 for (i = 1; i <= 31; ++i) {
17868 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
17869 testMoment = moment(ordinalStr, 'YYYY MM Do');
17870 assert.equal(testMoment.year(), 2014,
17871 'lenient day of month ordinal parsing ' + i + ' year check');
17872 assert.equal(testMoment.month(), 0,
17873 'lenient day of month ordinal parsing ' + i + ' month check');
17874 assert.equal(testMoment.date(), i,
17875 'lenient day of month ordinal parsing ' + i + ' date check');
17876 }
17877 });
516f5f67 17878
db71a655
KM
17879 test('lenient day of month ordinal parsing of number', function (assert) {
17880 var i, testMoment;
17881 for (i = 1; i <= 31; ++i) {
17882 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
17883 assert.equal(testMoment.year(), 2014,
17884 'lenient day of month ordinal parsing of number ' + i + ' year check');
17885 assert.equal(testMoment.month(), 0,
17886 'lenient day of month ordinal parsing of number ' + i + ' month check');
17887 assert.equal(testMoment.date(), i,
17888 'lenient day of month ordinal parsing of number ' + i + ' date check');
17889 }
73f3c911 17890 });
73f3c911 17891
db71a655
KM
17892 test('strict day of month ordinal parsing', function (assert) {
17893 var i, ordinalStr, testMoment;
17894 for (i = 1; i <= 31; ++i) {
17895 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
17896 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
17897 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
17898 }
17899 });
516f5f67 17900
db71a655
KM
17901 test('meridiem invariant', function (assert) {
17902 var h, m, t1, t2;
17903 for (h = 0; h < 24; ++h) {
17904 for (m = 0; m < 60; m += 15) {
17905 t1 = moment.utc([2000, 0, 1, h, m]);
17906 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
17907 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
17908 'meridiem at ' + t1.format('HH:mm'));
17909 }
17910 }
17911 });
516f5f67 17912
db71a655
KM
17913 test('date format correctness', function (assert) {
17914 var data, tokens;
17915 data = moment.localeData()._longDateFormat;
17916 tokens = objectKeys(data);
17917 each(tokens, function (srchToken) {
17918 // Check each format string to make sure it does not contain any
17919 // tokens that need to be expanded.
17920 each(tokens, function (baseToken) {
17921 // strip escaped sequences
17922 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
17923 assert.equal(false, !!~format.indexOf(srchToken),
17924 'contains ' + srchToken + ' in ' + baseToken);
17925 });
17926 });
17927 });
516f5f67 17928
db71a655
KM
17929 test('month parsing correctness', function (assert) {
17930 var i, m;
17931
17932 if (locale === 'tr') {
17933 // I can't fix it :(
c58511b9 17934 assert.expect(0);
db71a655
KM
17935 return;
17936 }
17937 function tester(format) {
17938 var r;
17939 r = moment(m.format(format), format);
17940 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
17941 if (locale !== 'ka') {
17942 r = moment(m.format(format).toLocaleUpperCase(), format);
17943 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
17944 }
db71a655
KM
17945 r = moment(m.format(format).toLocaleLowerCase(), format);
17946 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
17947
17948 r = moment(m.format(format), format, true);
17949 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
17950 if (locale !== 'ka') {
17951 r = moment(m.format(format).toLocaleUpperCase(), format, true);
17952 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
17953 }
db71a655
KM
17954 r = moment(m.format(format).toLocaleLowerCase(), format, true);
17955 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
17956 }
17957
17958 for (i = 0; i < 12; ++i) {
17959 m = moment([2015, i, 15, 18]);
17960 tester('MMM');
17961 tester('MMM.');
17962 tester('MMMM');
17963 tester('MMMM.');
17964 }
17965 });
516f5f67 17966
db71a655
KM
17967 test('weekday parsing correctness', function (assert) {
17968 var i, m;
17969
96d0d679 17970 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
17971 // tr, az: There is a lower-case letter (ı), that converted to
17972 // upper then lower changes to i
17973 // ro: there is the letter ț which behaves weird under IE8
17974 // mt: letter Ħ
96d0d679 17975 // ga: month with spaces
c58511b9 17976 assert.expect(0);
db71a655
KM
17977 return;
17978 }
17979 function tester(format) {
17980 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
17981 r = moment(m.format(format), format);
17982 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
17983 if (locale !== 'ka') {
17984 r = moment(m.format(format).toLocaleUpperCase(), format);
17985 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
17986 }
db71a655
KM
17987 r = moment(m.format(format).toLocaleLowerCase(), format);
17988 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
17989 r = moment(m.format(format), format, true);
17990 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
17991 if (locale !== 'ka') {
17992 r = moment(m.format(format).toLocaleUpperCase(), format, true);
17993 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
17994 }
db71a655
KM
17995 r = moment(m.format(format).toLocaleLowerCase(), format, true);
17996 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
17997 }
17998
17999 for (i = 0; i < 7; ++i) {
18000 m = moment.utc([2015, 0, i + 1, 18]);
18001 tester('dd');
18002 tester('ddd');
18003 tester('dddd');
18004 }
18005 });
516f5f67 18006
db71a655
KM
18007 test('valid localeData', function (assert) {
18008 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
18009 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
18010 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
18011 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
18012 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
18013 });
96d0d679
KM
18014
18015 test('localeData weekdays can localeSort', function (assert) {
18016 var weekdays = moment().localeData().weekdays();
18017 var weekdaysShort = moment().localeData().weekdaysShort();
18018 var weekdaysMin = moment().localeData().weekdaysMin();
18019 var shift = moment().localeData()._week.dow;
18020 assert.deepEqual(
18021 moment().localeData().weekdays(true),
18022 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
18023 'weekdays should localeSort');
18024 assert.deepEqual(
18025 moment().localeData().weekdaysShort(true),
18026 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
18027 'weekdaysShort should localeSort');
18028 assert.deepEqual(
18029 moment().localeData().weekdaysMin(true),
18030 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
18031 'weekdaysMin should localeSort');
18032 });
db71a655 18033 }
516f5f67 18034
db71a655 18035 /*global QUnit:false*/
b135bf1a 18036
db71a655
KM
18037 function localeModule (name, lifecycle) {
18038 QUnit.module('locale:' + name, {
c58511b9 18039 beforeEach : function () {
db71a655
KM
18040 moment.locale(name);
18041 moment.createFromInputFallback = function (config) {
18042 throw new Error('input not handled by moment: ' + config._i);
18043 };
18044 setupDeprecationHandler(test, moment, 'locale');
18045 if (lifecycle && lifecycle.setup) {
18046 lifecycle.setup();
18047 }
18048 },
c58511b9 18049 afterEach : function () {
db71a655
KM
18050 moment.locale('en');
18051 teardownDeprecationHandler(test, moment, 'locale');
18052 if (lifecycle && lifecycle.teardown) {
18053 lifecycle.teardown();
18054 }
d40760af 18055 }
db71a655
KM
18056 });
18057 defineCommonLocaleTests(name, -1, -1);
18058 }
18059
96d0d679 18060 localeModule('es-do');
db71a655
KM
18061
18062 test('parse', function (assert) {
18063 var tests = 'enero ene._febrero feb._marzo mar._abril abr._mayo may._junio jun._julio jul._agosto ago._septiembre sep._octubre oct._noviembre nov._diciembre dic.'.split('_'), i;
18064 function equalTest(input, mmm, i) {
18065 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
18066 }
18067 for (i = 0; i < 12; i++) {
18068 tests[i] = tests[i].split(' ');
18069 equalTest(tests[i][0], 'MMM', i);
18070 equalTest(tests[i][1], 'MMM', i);
18071 equalTest(tests[i][0], 'MMMM', i);
18072 equalTest(tests[i][1], 'MMMM', i);
18073 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
18074 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
18075 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
18076 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
18077 }
18078 });
18079
18080 test('format', function (assert) {
18081 var a = [
18082 ['dddd, MMMM Do YYYY, h:mm:ss a', 'domingo, febrero 14º 2010, 3:25:50 pm'],
18083 ['ddd, hA', 'dom., 3PM'],
18084 ['M Mo MM MMMM MMM', '2 2º 02 febrero feb.'],
18085 ['YYYY YY', '2010 10'],
18086 ['D Do DD', '14 14º 14'],
18087 ['d do dddd ddd dd', '0 0º domingo dom. do'],
18088 ['DDD DDDo DDDD', '45 45º 045'],
96d0d679 18089 ['w wo ww', '6 6º 06'],
db71a655
KM
18090 ['YYYY-MMM-DD', '2010-feb-14'],
18091 ['h hh', '3 03'],
18092 ['H HH', '15 15'],
18093 ['m mm', '25 25'],
18094 ['s ss', '50 50'],
18095 ['a A', 'pm PM'],
18096 ['[the] DDDo [day of the year]', 'the 45º day of the year'],
db71a655 18097 ['LTS', '3:25:50 PM'],
96d0d679
KM
18098 ['L', '14/02/2010'],
18099 ['LL', '14 de febrero de 2010'],
18100 ['LLL', '14 de febrero de 2010 3:25 PM'],
18101 ['LLLL', 'domingo, 14 de febrero de 2010 3:25 PM'],
18102 ['l', '14/2/2010'],
18103 ['ll', '14 de feb. de 2010'],
18104 ['lll', '14 de feb. de 2010 3:25 PM'],
18105 ['llll', 'dom., 14 de feb. de 2010 3:25 PM']
db71a655
KM
18106 ],
18107 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
18108 i;
18109 for (i = 0; i < a.length; i++) {
18110 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
18111 }
18112 });
18113
18114 test('format ordinal', function (assert) {
18115 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1º', '1º');
18116 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2º', '2º');
18117 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3º', '3º');
18118 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4º', '4º');
18119 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5º', '5º');
18120 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6º', '6º');
18121 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7º', '7º');
18122 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8º', '8º');
18123 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9º', '9º');
18124 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10º', '10º');
18125
18126 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11º', '11º');
18127 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12º', '12º');
18128 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13º', '13º');
18129 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14º', '14º');
18130 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15º', '15º');
18131 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16º', '16º');
18132 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17º', '17º');
18133 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18º', '18º');
18134 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19º', '19º');
18135 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20º', '20º');
18136
18137 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21º', '21º');
18138 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22º', '22º');
18139 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23º', '23º');
18140 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24º', '24º');
18141 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25º', '25º');
18142 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26º', '26º');
18143 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27º', '27º');
18144 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28º', '28º');
18145 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29º', '29º');
18146 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30º', '30º');
18147
18148 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31º', '31º');
18149 });
18150
18151 test('format month', function (assert) {
96d0d679 18152 var expected = 'enero ene._febrero feb._marzo mar._abril abr._mayo may._junio jun._julio jul._agosto ago._septiembre sep._octubre oct._noviembre nov._diciembre dic.'.split('_'), i;
db71a655
KM
18153 for (i = 0; i < expected.length; i++) {
18154 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
18155 }
18156 });
18157
18158 test('format week', function (assert) {
96d0d679 18159 var expected = 'domingo dom. do_lunes lun. lu_martes mar. ma_miércoles mié. mi_jueves jue. ju_viernes vie. vi_sábado sáb. sá'.split('_'), i;
db71a655
KM
18160 for (i = 0; i < expected.length; i++) {
18161 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
18162 }
18163 });
18164
18165 test('from', function (assert) {
18166 var start = moment([2007, 1, 28]);
db71a655
KM
18167 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'unos segundos', '44 seconds = a few seconds');
18168 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'un minuto', '45 seconds = a minute');
18169 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'un minuto', '89 seconds = a minute');
18170 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutos', '90 seconds = 2 minutes');
18171 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutos', '44 minutes = 44 minutes');
18172 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'una hora', '45 minutes = an hour');
18173 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'una hora', '89 minutes = an hour');
18174 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 horas', '90 minutes = 2 hours');
18175 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 horas', '5 hours = 5 hours');
18176 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 horas', '21 hours = 21 hours');
18177 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un día', '22 hours = a day');
18178 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un día', '35 hours = a day');
18179 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 días', '36 hours = 2 days');
18180 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un día', '1 day = a day');
18181 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 días', '5 days = 5 days');
18182 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 días', '25 days = 25 days');
18183 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'un mes', '26 days = a month');
18184 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'un mes', '30 days = a month');
18185 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'un mes', '43 days = a month');
18186 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 meses', '46 days = 2 months');
18187 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 meses', '75 days = 2 months');
18188 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 meses', '76 days = 3 months');
18189 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'un mes', '1 month = a month');
18190 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 meses', '5 months = 5 months');
18191 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un año', '345 days = a year');
18192 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 años', '548 days = 2 years');
18193 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un año', '1 year = a year');
18194 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 años', '5 years = 5 years');
18195 });
18196
18197 test('suffix', function (assert) {
18198 assert.equal(moment(30000).from(0), 'en unos segundos', 'prefix');
18199 assert.equal(moment(0).from(30000), 'hace unos segundos', 'suffix');
18200 });
18201
18202 test('now from now', function (assert) {
18203 assert.equal(moment().fromNow(), 'hace unos segundos', 'now from now should display as in the past');
18204 });
18205
18206 test('fromNow', function (assert) {
18207 assert.equal(moment().add({s: 30}).fromNow(), 'en unos segundos', 'en unos segundos');
18208 assert.equal(moment().add({d: 5}).fromNow(), 'en 5 días', 'en 5 días');
18209 });
18210
18211 test('calendar day', function (assert) {
18212 var a = moment().hours(12).minutes(0).seconds(0);
18213
18214 assert.equal(moment(a).calendar(), 'hoy a las 12:00 PM', 'today at the same time');
18215 assert.equal(moment(a).add({m: 25}).calendar(), 'hoy a las 12:25 PM', 'Now plus 25 min');
18216 assert.equal(moment(a).add({h: 1}).calendar(), 'hoy a las 1:00 PM', 'Now plus 1 hour');
18217 assert.equal(moment(a).add({d: 1}).calendar(), 'mañana a las 12:00 PM', 'tomorrow at the same time');
18218 assert.equal(moment(a).add({d: 1, h : -1}).calendar(), 'mañana a las 11:00 AM', 'tomorrow minus 1 hour');
18219 assert.equal(moment(a).subtract({h: 1}).calendar(), 'hoy a las 11:00 AM', 'Now minus 1 hour');
18220 assert.equal(moment(a).subtract({d: 1}).calendar(), 'ayer a las 12:00 PM', 'yesterday at the same time');
18221 });
18222
18223 test('calendar next week', function (assert) {
18224 var i, m;
18225
18226 for (i = 2; i < 7; i++) {
18227 m = moment().add({d: i});
18228 assert.equal(m.calendar(), m.format('dddd [a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today + ' + i + ' days current time');
18229 m.hours(0).minutes(0).seconds(0).milliseconds(0);
18230 assert.equal(m.calendar(), m.format('dddd [a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today + ' + i + ' days beginning of day');
18231 m.hours(23).minutes(59).seconds(59).milliseconds(999);
18232 assert.equal(m.calendar(), m.format('dddd [a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today + ' + i + ' days end of day');
18233 }
18234 });
18235
18236 test('calendar last week', function (assert) {
18237 var i, m;
18238
18239 for (i = 2; i < 7; i++) {
18240 m = moment().subtract({d: i});
18241 assert.equal(m.calendar(), m.format('[el] dddd [pasado a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today - ' + i + ' days current time');
18242 m.hours(0).minutes(0).seconds(0).milliseconds(0);
18243 assert.equal(m.calendar(), m.format('[el] dddd [pasado a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today - ' + i + ' days beginning of day');
18244 m.hours(23).minutes(59).seconds(59).milliseconds(999);
18245 assert.equal(m.calendar(), m.format('[el] dddd [pasado a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today - ' + i + ' days end of day');
18246 }
18247 });
18248
18249 test('calendar all else', function (assert) {
18250 var weeksAgo = moment().subtract({w: 1}),
18251 weeksFromNow = moment().add({w: 1});
18252
18253 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
18254 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
18255
18256 weeksAgo = moment().subtract({w: 2});
18257 weeksFromNow = moment().add({w: 2});
18258
18259 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
18260 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
18261 });
18262
18263 test('weeks year starting sunday formatted', function (assert) {
96d0d679 18264 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52º', 'Jan 1 2012 should be week 52');
db71a655 18265 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1º', 'Jan 2 2012 should be week 1');
96d0d679
KM
18266 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1º', 'Jan 8 2012 should be week 1');
18267 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2º', 'Jan 9 2012 should be week 2');
18268 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2º', 'Jan 15 2012 should be week 2');
18269 });
18270
18271 test('test short months proper', function (assert) {
18272 var str = '02-ago-2016'; // "02-ago-2016"
18273 assert.equal(moment(str, 'DD-MMM-YYYY').month(), 7, '02-ago-2016 month should be 7');
18274 assert.equal(moment(str, 'DD-MMM-YYYY', true).month(), 7, '02-ago-2016 strict parse month should be 7');
db71a655 18275 });
73f3c911
IC
18276
18277})));
d40760af 18278
d40760af 18279
73f3c911
IC
18280;(function (global, factory) {
18281 typeof exports === 'object' && typeof module !== 'undefined'
18282 && typeof require === 'function' ? factory(require('../../moment')) :
18283 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
18284 factory(global.moment)
18285}(this, (function (moment) { 'use strict';
d40760af 18286
db71a655
KM
18287 function each(array, callback) {
18288 var i;
18289 for (i = 0; i < array.length; i++) {
18290 callback(array[i], i, array);
18291 }
d40760af
IC
18292 }
18293
c58511b9
KM
18294 function setupDeprecationHandler(test, moment$$1, scope) {
18295 test._expectedDeprecations = null;
18296 test._observedDeprecations = null;
18297 test._oldSupress = moment$$1.suppressDeprecationWarnings;
18298 moment$$1.suppressDeprecationWarnings = true;
18299 test.expectedDeprecations = function () {
18300 test._expectedDeprecations = arguments;
18301 test._observedDeprecations = [];
18302 };
18303 moment$$1.deprecationHandler = function (name, msg) {
18304 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
18305 if (deprecationId === -1) {
18306 throw new Error('Unexpected deprecation thrown name=' +
18307 name + ' msg=' + msg);
18308 }
18309 test._observedDeprecations[deprecationId] = 1;
18310 };
18311 }
18312
18313 function teardownDeprecationHandler(test, moment$$1, scope) {
18314 moment$$1.suppressDeprecationWarnings = test._oldSupress;
18315
18316 if (test._expectedDeprecations != null) {
18317 var missedDeprecations = [];
18318 each(test._expectedDeprecations, function (deprecationPattern, id) {
18319 if (test._observedDeprecations[id] !== 1) {
18320 missedDeprecations.push(deprecationPattern);
18321 }
18322 });
18323 if (missedDeprecations.length !== 0) {
18324 throw new Error('Expected deprecation warnings did not happen: ' +
18325 missedDeprecations.join(' '));
18326 }
18327 }
18328 }
18329
18330 function matchedDeprecation(name, msg, deprecations) {
18331 if (deprecations == null) {
18332 return -1;
18333 }
18334 for (var i = 0; i < deprecations.length; ++i) {
18335 if (name != null && name === deprecations[i]) {
18336 return i;
18337 }
18338 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
18339 return i;
18340 }
18341 }
18342 return -1;
18343 }
18344
18345 /*global QUnit:false*/
18346
18347 var test = QUnit.test;
18348
db71a655
KM
18349 function objectKeys(obj) {
18350 if (Object.keys) {
18351 return Object.keys(obj);
18352 } else {
18353 // IE8
18354 var res = [], i;
18355 for (i in obj) {
18356 if (obj.hasOwnProperty(i)) {
18357 res.push(i);
18358 }
d40760af 18359 }
db71a655 18360 return res;
d40760af 18361 }
d40760af
IC
18362 }
18363
db71a655 18364 // Pick the first defined of two or three arguments.
d40760af 18365
db71a655
KM
18366 function defineCommonLocaleTests(locale, options) {
18367 test('lenient day of month ordinal parsing', function (assert) {
18368 var i, ordinalStr, testMoment;
18369 for (i = 1; i <= 31; ++i) {
18370 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
18371 testMoment = moment(ordinalStr, 'YYYY MM Do');
18372 assert.equal(testMoment.year(), 2014,
18373 'lenient day of month ordinal parsing ' + i + ' year check');
18374 assert.equal(testMoment.month(), 0,
18375 'lenient day of month ordinal parsing ' + i + ' month check');
18376 assert.equal(testMoment.date(), i,
18377 'lenient day of month ordinal parsing ' + i + ' date check');
18378 }
18379 });
d40760af 18380
db71a655
KM
18381 test('lenient day of month ordinal parsing of number', function (assert) {
18382 var i, testMoment;
18383 for (i = 1; i <= 31; ++i) {
18384 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
18385 assert.equal(testMoment.year(), 2014,
18386 'lenient day of month ordinal parsing of number ' + i + ' year check');
18387 assert.equal(testMoment.month(), 0,
18388 'lenient day of month ordinal parsing of number ' + i + ' month check');
18389 assert.equal(testMoment.date(), i,
18390 'lenient day of month ordinal parsing of number ' + i + ' date check');
18391 }
18392 });
d40760af 18393
db71a655
KM
18394 test('strict day of month ordinal parsing', function (assert) {
18395 var i, ordinalStr, testMoment;
18396 for (i = 1; i <= 31; ++i) {
18397 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
18398 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
18399 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
18400 }
18401 });
d40760af 18402
db71a655
KM
18403 test('meridiem invariant', function (assert) {
18404 var h, m, t1, t2;
18405 for (h = 0; h < 24; ++h) {
18406 for (m = 0; m < 60; m += 15) {
18407 t1 = moment.utc([2000, 0, 1, h, m]);
18408 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
18409 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
18410 'meridiem at ' + t1.format('HH:mm'));
18411 }
18412 }
18413 });
18414
18415 test('date format correctness', function (assert) {
18416 var data, tokens;
18417 data = moment.localeData()._longDateFormat;
18418 tokens = objectKeys(data);
18419 each(tokens, function (srchToken) {
18420 // Check each format string to make sure it does not contain any
18421 // tokens that need to be expanded.
18422 each(tokens, function (baseToken) {
18423 // strip escaped sequences
18424 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
18425 assert.equal(false, !!~format.indexOf(srchToken),
18426 'contains ' + srchToken + ' in ' + baseToken);
18427 });
73f3c911 18428 });
d40760af 18429 });
d40760af 18430
db71a655
KM
18431 test('month parsing correctness', function (assert) {
18432 var i, m;
18433
18434 if (locale === 'tr') {
18435 // I can't fix it :(
c58511b9 18436 assert.expect(0);
db71a655
KM
18437 return;
18438 }
18439 function tester(format) {
18440 var r;
18441 r = moment(m.format(format), format);
18442 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
18443 if (locale !== 'ka') {
18444 r = moment(m.format(format).toLocaleUpperCase(), format);
18445 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
18446 }
db71a655
KM
18447 r = moment(m.format(format).toLocaleLowerCase(), format);
18448 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
18449
18450 r = moment(m.format(format), format, true);
18451 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
18452 if (locale !== 'ka') {
18453 r = moment(m.format(format).toLocaleUpperCase(), format, true);
18454 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
18455 }
db71a655
KM
18456 r = moment(m.format(format).toLocaleLowerCase(), format, true);
18457 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
18458 }
18459
18460 for (i = 0; i < 12; ++i) {
18461 m = moment([2015, i, 15, 18]);
18462 tester('MMM');
18463 tester('MMM.');
18464 tester('MMMM');
18465 tester('MMMM.');
18466 }
18467 });
d40760af 18468
db71a655
KM
18469 test('weekday parsing correctness', function (assert) {
18470 var i, m;
18471
96d0d679 18472 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
18473 // tr, az: There is a lower-case letter (ı), that converted to
18474 // upper then lower changes to i
18475 // ro: there is the letter ț which behaves weird under IE8
18476 // mt: letter Ħ
96d0d679 18477 // ga: month with spaces
c58511b9 18478 assert.expect(0);
db71a655
KM
18479 return;
18480 }
18481 function tester(format) {
18482 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
18483 r = moment(m.format(format), format);
18484 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
18485 if (locale !== 'ka') {
18486 r = moment(m.format(format).toLocaleUpperCase(), format);
18487 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
18488 }
db71a655
KM
18489 r = moment(m.format(format).toLocaleLowerCase(), format);
18490 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
18491 r = moment(m.format(format), format, true);
18492 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
18493 if (locale !== 'ka') {
18494 r = moment(m.format(format).toLocaleUpperCase(), format, true);
18495 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
18496 }
db71a655
KM
18497 r = moment(m.format(format).toLocaleLowerCase(), format, true);
18498 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
18499 }
18500
18501 for (i = 0; i < 7; ++i) {
18502 m = moment.utc([2015, 0, i + 1, 18]);
18503 tester('dd');
18504 tester('ddd');
18505 tester('dddd');
18506 }
18507 });
d40760af 18508
db71a655
KM
18509 test('valid localeData', function (assert) {
18510 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
18511 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
18512 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
18513 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
18514 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
18515 });
96d0d679
KM
18516
18517 test('localeData weekdays can localeSort', function (assert) {
18518 var weekdays = moment().localeData().weekdays();
18519 var weekdaysShort = moment().localeData().weekdaysShort();
18520 var weekdaysMin = moment().localeData().weekdaysMin();
18521 var shift = moment().localeData()._week.dow;
18522 assert.deepEqual(
18523 moment().localeData().weekdays(true),
18524 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
18525 'weekdays should localeSort');
18526 assert.deepEqual(
18527 moment().localeData().weekdaysShort(true),
18528 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
18529 'weekdaysShort should localeSort');
18530 assert.deepEqual(
18531 moment().localeData().weekdaysMin(true),
18532 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
18533 'weekdaysMin should localeSort');
18534 });
db71a655 18535 }
d40760af 18536
db71a655 18537 /*global QUnit:false*/
d40760af 18538
db71a655
KM
18539 function localeModule (name, lifecycle) {
18540 QUnit.module('locale:' + name, {
c58511b9 18541 beforeEach : function () {
db71a655
KM
18542 moment.locale(name);
18543 moment.createFromInputFallback = function (config) {
18544 throw new Error('input not handled by moment: ' + config._i);
18545 };
18546 setupDeprecationHandler(test, moment, 'locale');
18547 if (lifecycle && lifecycle.setup) {
18548 lifecycle.setup();
18549 }
18550 },
c58511b9 18551 afterEach : function () {
db71a655
KM
18552 moment.locale('en');
18553 teardownDeprecationHandler(test, moment, 'locale');
18554 if (lifecycle && lifecycle.teardown) {
18555 lifecycle.teardown();
18556 }
d40760af 18557 }
73f3c911 18558 });
db71a655
KM
18559 defineCommonLocaleTests(name, -1, -1);
18560 }
18561
96d0d679 18562 localeModule('es-us');
db71a655
KM
18563
18564 test('parse', function (assert) {
18565 var tests = 'enero ene._febrero feb._marzo mar._abril abr._mayo may._junio jun._julio jul._agosto ago._septiembre sep._octubre oct._noviembre nov._diciembre dic.'.split('_'), i;
18566 function equalTest(input, mmm, i) {
18567 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
18568 }
18569 for (i = 0; i < 12; i++) {
18570 tests[i] = tests[i].split(' ');
18571 equalTest(tests[i][0], 'MMM', i);
18572 equalTest(tests[i][1], 'MMM', i);
18573 equalTest(tests[i][0], 'MMMM', i);
18574 equalTest(tests[i][1], 'MMMM', i);
18575 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
18576 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
18577 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
18578 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
18579 }
18580 });
18581
18582 test('format', function (assert) {
18583 var a = [
18584 ['dddd, MMMM Do YYYY, h:mm:ss a', 'domingo, febrero 14º 2010, 3:25:50 pm'],
18585 ['ddd, hA', 'dom., 3PM'],
18586 ['M Mo MM MMMM MMM', '2 2º 02 febrero feb.'],
18587 ['YYYY YY', '2010 10'],
18588 ['D Do DD', '14 14º 14'],
18589 ['d do dddd ddd dd', '0 0º domingo dom. do'],
18590 ['DDD DDDo DDDD', '45 45º 045'],
96d0d679 18591 ['w wo ww', '8 8º 08'],
db71a655
KM
18592 ['YYYY-MMM-DD', '2010-feb-14'],
18593 ['h hh', '3 03'],
18594 ['H HH', '15 15'],
18595 ['m mm', '25 25'],
18596 ['s ss', '50 50'],
18597 ['a A', 'pm PM'],
18598 ['[the] DDDo [day of the year]', 'the 45º day of the year'],
96d0d679
KM
18599 ['LT', '3:25 PM'],
18600 ['LTS', '3:25:50 PM'],
18601 ['L', '02/14/2010'],
db71a655 18602 ['LL', '14 de febrero de 2010'],
96d0d679
KM
18603 ['LLL', '14 de febrero de 2010 3:25 PM'],
18604 ['LLLL', 'domingo, 14 de febrero de 2010 3:25 PM'],
18605 ['l', '2/14/2010'],
db71a655 18606 ['ll', '14 de feb. de 2010'],
96d0d679
KM
18607 ['lll', '14 de feb. de 2010 3:25 PM'],
18608 ['llll', 'dom., 14 de feb. de 2010 3:25 PM']
db71a655
KM
18609 ],
18610 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
18611 i;
18612 for (i = 0; i < a.length; i++) {
18613 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
18614 }
18615 });
18616
18617 test('format ordinal', function (assert) {
18618 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1º', '1º');
18619 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2º', '2º');
18620 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3º', '3º');
18621 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4º', '4º');
18622 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5º', '5º');
18623 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6º', '6º');
18624 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7º', '7º');
18625 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8º', '8º');
18626 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9º', '9º');
18627 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10º', '10º');
18628
18629 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11º', '11º');
18630 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12º', '12º');
18631 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13º', '13º');
18632 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14º', '14º');
18633 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15º', '15º');
18634 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16º', '16º');
18635 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17º', '17º');
18636 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18º', '18º');
18637 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19º', '19º');
18638 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20º', '20º');
18639
18640 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21º', '21º');
18641 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22º', '22º');
18642 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23º', '23º');
18643 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24º', '24º');
18644 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25º', '25º');
18645 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26º', '26º');
18646 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27º', '27º');
18647 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28º', '28º');
18648 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29º', '29º');
18649 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30º', '30º');
18650
18651 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31º', '31º');
18652 });
18653
18654 test('format month', function (assert) {
96d0d679
KM
18655 var i,
18656 expected = 'enero ene._febrero feb._marzo mar._abril abr._mayo may._junio jun._julio jul._agosto ago._septiembre sep._octubre oct._noviembre nov._diciembre dic.'.split('_');
18657
db71a655
KM
18658 for (i = 0; i < expected.length; i++) {
18659 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
18660 }
18661 });
18662
18663 test('format week', function (assert) {
96d0d679
KM
18664 var i,
18665 expected = 'domingo dom. do_lunes lun. lu_martes mar. ma_miércoles mié. mi_jueves jue. ju_viernes vie. vi_sábado sáb. sá'.split('_');
18666
db71a655
KM
18667 for (i = 0; i < expected.length; i++) {
18668 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
18669 }
18670 });
18671
18672 test('from', function (assert) {
18673 var start = moment([2007, 1, 28]);
96d0d679 18674
db71a655
KM
18675 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'unos segundos', '44 seconds = a few seconds');
18676 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'un minuto', '45 seconds = a minute');
18677 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'un minuto', '89 seconds = a minute');
18678 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutos', '90 seconds = 2 minutes');
18679 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutos', '44 minutes = 44 minutes');
18680 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'una hora', '45 minutes = an hour');
18681 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'una hora', '89 minutes = an hour');
18682 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 horas', '90 minutes = 2 hours');
18683 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 horas', '5 hours = 5 hours');
18684 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 horas', '21 hours = 21 hours');
18685 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un día', '22 hours = a day');
18686 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un día', '35 hours = a day');
18687 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 días', '36 hours = 2 days');
18688 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un día', '1 day = a day');
18689 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 días', '5 days = 5 days');
18690 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 días', '25 days = 25 days');
18691 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'un mes', '26 days = a month');
18692 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'un mes', '30 days = a month');
18693 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'un mes', '43 days = a month');
18694 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 meses', '46 days = 2 months');
18695 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 meses', '75 days = 2 months');
18696 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 meses', '76 days = 3 months');
18697 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'un mes', '1 month = a month');
18698 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 meses', '5 months = 5 months');
18699 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un año', '345 days = a year');
18700 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 años', '548 days = 2 years');
18701 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un año', '1 year = a year');
18702 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 años', '5 years = 5 years');
18703 });
18704
18705 test('suffix', function (assert) {
18706 assert.equal(moment(30000).from(0), 'en unos segundos', 'prefix');
18707 assert.equal(moment(0).from(30000), 'hace unos segundos', 'suffix');
18708 });
18709
18710 test('now from now', function (assert) {
18711 assert.equal(moment().fromNow(), 'hace unos segundos', 'now from now should display as in the past');
18712 });
18713
18714 test('fromNow', function (assert) {
18715 assert.equal(moment().add({s: 30}).fromNow(), 'en unos segundos', 'en unos segundos');
18716 assert.equal(moment().add({d: 5}).fromNow(), 'en 5 días', 'en 5 días');
18717 });
18718
18719 test('calendar day', function (assert) {
18720 var a = moment().hours(12).minutes(0).seconds(0);
18721
96d0d679
KM
18722 assert.equal(moment(a).calendar(), 'hoy a las 12:00 PM', 'today at the same time');
18723 assert.equal(moment(a).add({m: 25}).calendar(), 'hoy a las 12:25 PM', 'Now plus 25 min');
18724 assert.equal(moment(a).add({h: 1}).calendar(), 'hoy a las 1:00 PM', 'Now plus 1 hour');
18725 assert.equal(moment(a).add({d: 1}).calendar(), 'mañana a las 12:00 PM', 'tomorrow at the same time');
18726 assert.equal(moment(a).add({d: 1, h : -1}).calendar(), 'mañana a las 11:00 AM', 'tomorrow minus 1 hour');
18727 assert.equal(moment(a).subtract({h: 1}).calendar(), 'hoy a las 11:00 AM', 'Now minus 1 hour');
18728 assert.equal(moment(a).subtract({d: 1}).calendar(), 'ayer a las 12:00 PM', 'yesterday at the same time');
db71a655
KM
18729 });
18730
18731 test('calendar next week', function (assert) {
18732 var i, m;
d40760af 18733
db71a655
KM
18734 for (i = 2; i < 7; i++) {
18735 m = moment().add({d: i});
18736 assert.equal(m.calendar(), m.format('dddd [a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today + ' + i + ' days current time');
18737 m.hours(0).minutes(0).seconds(0).milliseconds(0);
18738 assert.equal(m.calendar(), m.format('dddd [a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today + ' + i + ' days beginning of day');
18739 m.hours(23).minutes(59).seconds(59).milliseconds(999);
18740 assert.equal(m.calendar(), m.format('dddd [a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today + ' + i + ' days end of day');
d40760af 18741 }
db71a655
KM
18742 });
18743
18744 test('calendar last week', function (assert) {
18745 var i, m;
18746
18747 for (i = 2; i < 7; i++) {
18748 m = moment().subtract({d: i});
18749 assert.equal(m.calendar(), m.format('[el] dddd [pasado a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today - ' + i + ' days current time');
18750 m.hours(0).minutes(0).seconds(0).milliseconds(0);
18751 assert.equal(m.calendar(), m.format('[el] dddd [pasado a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today - ' + i + ' days beginning of day');
18752 m.hours(23).minutes(59).seconds(59).milliseconds(999);
18753 assert.equal(m.calendar(), m.format('[el] dddd [pasado a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today - ' + i + ' days end of day');
d40760af 18754 }
db71a655 18755 });
d40760af 18756
db71a655
KM
18757 test('calendar all else', function (assert) {
18758 var weeksAgo = moment().subtract({w: 1}),
18759 weeksFromNow = moment().add({w: 1});
d40760af 18760
db71a655
KM
18761 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
18762 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
d40760af 18763
db71a655
KM
18764 weeksAgo = moment().subtract({w: 2});
18765 weeksFromNow = moment().add({w: 2});
d40760af 18766
db71a655
KM
18767 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
18768 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
18769 });
18770
18771 test('weeks year starting sunday formatted', function (assert) {
96d0d679 18772 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1º', 'Jan 1 2012 should be week 1');
db71a655 18773 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1º', 'Jan 2 2012 should be week 1');
96d0d679
KM
18774 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1º', 'Jan 7 2012 should be week 1');
18775 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2º', 'Jan 8 2012 should be week 2');
18776 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2º', 'Jan 14 2012 should be week 2');
18777 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3º', 'Jan 15 2012 should be week 3');
db71a655
KM
18778 });
18779
18780 test('test short months proper', function (assert) {
96d0d679
KM
18781 var str = '02-ago-2016'; // "02-ago-2016"
18782 assert.equal(moment(str, 'DD-MMM-YYYY').month(), 7, '02-ago-2016 month should be 7');
18783 assert.equal(moment(str, 'DD-MMM-YYYY', true).month(), 7, '02-ago-2016 strict parse month should be 7');
18784 });
18785
18786 test('test lenient month parsing', function (assert) {
18787 assert.ok(moment('nov 01, 2015', 'MMM D, YYYY', true).isValid(), 'nov 01, 2015 should parse correctly');
db71a655 18788 });
73f3c911
IC
18789
18790})));
d6651c21 18791
d6651c21 18792
73f3c911
IC
18793;(function (global, factory) {
18794 typeof exports === 'object' && typeof module !== 'undefined'
18795 && typeof require === 'function' ? factory(require('../../moment')) :
18796 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
18797 factory(global.moment)
18798}(this, (function (moment) { 'use strict';
d6651c21 18799
db71a655
KM
18800 function each(array, callback) {
18801 var i;
18802 for (i = 0; i < array.length; i++) {
18803 callback(array[i], i, array);
18804 }
d6651c21
IC
18805 }
18806
c58511b9
KM
18807 function setupDeprecationHandler(test, moment$$1, scope) {
18808 test._expectedDeprecations = null;
18809 test._observedDeprecations = null;
18810 test._oldSupress = moment$$1.suppressDeprecationWarnings;
18811 moment$$1.suppressDeprecationWarnings = true;
18812 test.expectedDeprecations = function () {
18813 test._expectedDeprecations = arguments;
18814 test._observedDeprecations = [];
18815 };
18816 moment$$1.deprecationHandler = function (name, msg) {
18817 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
18818 if (deprecationId === -1) {
18819 throw new Error('Unexpected deprecation thrown name=' +
18820 name + ' msg=' + msg);
18821 }
18822 test._observedDeprecations[deprecationId] = 1;
18823 };
18824 }
18825
18826 function teardownDeprecationHandler(test, moment$$1, scope) {
18827 moment$$1.suppressDeprecationWarnings = test._oldSupress;
18828
18829 if (test._expectedDeprecations != null) {
18830 var missedDeprecations = [];
18831 each(test._expectedDeprecations, function (deprecationPattern, id) {
18832 if (test._observedDeprecations[id] !== 1) {
18833 missedDeprecations.push(deprecationPattern);
18834 }
18835 });
18836 if (missedDeprecations.length !== 0) {
18837 throw new Error('Expected deprecation warnings did not happen: ' +
18838 missedDeprecations.join(' '));
18839 }
18840 }
18841 }
18842
18843 function matchedDeprecation(name, msg, deprecations) {
18844 if (deprecations == null) {
18845 return -1;
18846 }
18847 for (var i = 0; i < deprecations.length; ++i) {
18848 if (name != null && name === deprecations[i]) {
18849 return i;
18850 }
18851 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
18852 return i;
18853 }
18854 }
18855 return -1;
18856 }
18857
18858 /*global QUnit:false*/
18859
18860 var test = QUnit.test;
18861
db71a655
KM
18862 function objectKeys(obj) {
18863 if (Object.keys) {
18864 return Object.keys(obj);
18865 } else {
18866 // IE8
18867 var res = [], i;
18868 for (i in obj) {
18869 if (obj.hasOwnProperty(i)) {
18870 res.push(i);
18871 }
d6651c21 18872 }
db71a655 18873 return res;
d6651c21 18874 }
b135bf1a 18875 }
c74a101d 18876
db71a655 18877 // Pick the first defined of two or three arguments.
516f5f67 18878
db71a655
KM
18879 function defineCommonLocaleTests(locale, options) {
18880 test('lenient day of month ordinal parsing', function (assert) {
18881 var i, ordinalStr, testMoment;
18882 for (i = 1; i <= 31; ++i) {
18883 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
18884 testMoment = moment(ordinalStr, 'YYYY MM Do');
18885 assert.equal(testMoment.year(), 2014,
18886 'lenient day of month ordinal parsing ' + i + ' year check');
18887 assert.equal(testMoment.month(), 0,
18888 'lenient day of month ordinal parsing ' + i + ' month check');
18889 assert.equal(testMoment.date(), i,
18890 'lenient day of month ordinal parsing ' + i + ' date check');
18891 }
18892 });
516f5f67 18893
db71a655
KM
18894 test('lenient day of month ordinal parsing of number', function (assert) {
18895 var i, testMoment;
18896 for (i = 1; i <= 31; ++i) {
18897 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
18898 assert.equal(testMoment.year(), 2014,
18899 'lenient day of month ordinal parsing of number ' + i + ' year check');
18900 assert.equal(testMoment.month(), 0,
18901 'lenient day of month ordinal parsing of number ' + i + ' month check');
18902 assert.equal(testMoment.date(), i,
18903 'lenient day of month ordinal parsing of number ' + i + ' date check');
18904 }
73f3c911 18905 });
516f5f67 18906
db71a655
KM
18907 test('strict day of month ordinal parsing', function (assert) {
18908 var i, ordinalStr, testMoment;
18909 for (i = 1; i <= 31; ++i) {
18910 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
18911 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
18912 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
18913 }
18914 });
516f5f67 18915
db71a655
KM
18916 test('meridiem invariant', function (assert) {
18917 var h, m, t1, t2;
18918 for (h = 0; h < 24; ++h) {
18919 for (m = 0; m < 60; m += 15) {
18920 t1 = moment.utc([2000, 0, 1, h, m]);
18921 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
18922 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
18923 'meridiem at ' + t1.format('HH:mm'));
18924 }
18925 }
18926 });
b135bf1a 18927
db71a655
KM
18928 test('date format correctness', function (assert) {
18929 var data, tokens;
18930 data = moment.localeData()._longDateFormat;
18931 tokens = objectKeys(data);
18932 each(tokens, function (srchToken) {
18933 // Check each format string to make sure it does not contain any
18934 // tokens that need to be expanded.
18935 each(tokens, function (baseToken) {
18936 // strip escaped sequences
18937 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
18938 assert.equal(false, !!~format.indexOf(srchToken),
18939 'contains ' + srchToken + ' in ' + baseToken);
18940 });
18941 });
18942 });
b135bf1a 18943
db71a655
KM
18944 test('month parsing correctness', function (assert) {
18945 var i, m;
18946
18947 if (locale === 'tr') {
18948 // I can't fix it :(
c58511b9 18949 assert.expect(0);
db71a655
KM
18950 return;
18951 }
18952 function tester(format) {
18953 var r;
18954 r = moment(m.format(format), format);
18955 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
18956 if (locale !== 'ka') {
18957 r = moment(m.format(format).toLocaleUpperCase(), format);
18958 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
18959 }
db71a655
KM
18960 r = moment(m.format(format).toLocaleLowerCase(), format);
18961 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
18962
18963 r = moment(m.format(format), format, true);
18964 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
18965 if (locale !== 'ka') {
18966 r = moment(m.format(format).toLocaleUpperCase(), format, true);
18967 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
18968 }
db71a655
KM
18969 r = moment(m.format(format).toLocaleLowerCase(), format, true);
18970 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
18971 }
18972
18973 for (i = 0; i < 12; ++i) {
18974 m = moment([2015, i, 15, 18]);
18975 tester('MMM');
18976 tester('MMM.');
18977 tester('MMMM');
18978 tester('MMMM.');
18979 }
18980 });
b135bf1a 18981
db71a655
KM
18982 test('weekday parsing correctness', function (assert) {
18983 var i, m;
18984
96d0d679 18985 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
18986 // tr, az: There is a lower-case letter (ı), that converted to
18987 // upper then lower changes to i
18988 // ro: there is the letter ț which behaves weird under IE8
18989 // mt: letter Ħ
96d0d679 18990 // ga: month with spaces
c58511b9 18991 assert.expect(0);
db71a655
KM
18992 return;
18993 }
18994 function tester(format) {
18995 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
18996 r = moment(m.format(format), format);
18997 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
18998 if (locale !== 'ka') {
18999 r = moment(m.format(format).toLocaleUpperCase(), format);
19000 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
19001 }
db71a655
KM
19002 r = moment(m.format(format).toLocaleLowerCase(), format);
19003 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
19004 r = moment(m.format(format), format, true);
19005 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
19006 if (locale !== 'ka') {
19007 r = moment(m.format(format).toLocaleUpperCase(), format, true);
19008 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
19009 }
db71a655
KM
19010 r = moment(m.format(format).toLocaleLowerCase(), format, true);
19011 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
19012 }
19013
19014 for (i = 0; i < 7; ++i) {
19015 m = moment.utc([2015, 0, i + 1, 18]);
19016 tester('dd');
19017 tester('ddd');
19018 tester('dddd');
19019 }
19020 });
b135bf1a 19021
db71a655
KM
19022 test('valid localeData', function (assert) {
19023 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
19024 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
19025 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
19026 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
19027 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
19028 });
96d0d679
KM
19029
19030 test('localeData weekdays can localeSort', function (assert) {
19031 var weekdays = moment().localeData().weekdays();
19032 var weekdaysShort = moment().localeData().weekdaysShort();
19033 var weekdaysMin = moment().localeData().weekdaysMin();
19034 var shift = moment().localeData()._week.dow;
19035 assert.deepEqual(
19036 moment().localeData().weekdays(true),
19037 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
19038 'weekdays should localeSort');
19039 assert.deepEqual(
19040 moment().localeData().weekdaysShort(true),
19041 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
19042 'weekdaysShort should localeSort');
19043 assert.deepEqual(
19044 moment().localeData().weekdaysMin(true),
19045 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
19046 'weekdaysMin should localeSort');
19047 });
db71a655 19048 }
b135bf1a 19049
db71a655 19050 /*global QUnit:false*/
c74a101d 19051
db71a655
KM
19052 function localeModule (name, lifecycle) {
19053 QUnit.module('locale:' + name, {
c58511b9 19054 beforeEach : function () {
db71a655
KM
19055 moment.locale(name);
19056 moment.createFromInputFallback = function (config) {
19057 throw new Error('input not handled by moment: ' + config._i);
19058 };
19059 setupDeprecationHandler(test, moment, 'locale');
19060 if (lifecycle && lifecycle.setup) {
19061 lifecycle.setup();
19062 }
19063 },
c58511b9 19064 afterEach : function () {
db71a655
KM
19065 moment.locale('en');
19066 teardownDeprecationHandler(test, moment, 'locale');
19067 if (lifecycle && lifecycle.teardown) {
19068 lifecycle.teardown();
19069 }
73f3c911 19070 }
db71a655
KM
19071 });
19072 defineCommonLocaleTests(name, -1, -1);
19073 }
19074
96d0d679 19075 localeModule('es');
db71a655
KM
19076
19077 test('parse', function (assert) {
96d0d679 19078 var tests = 'enero ene._febrero feb._marzo mar._abril abr._mayo may._junio jun._julio jul._agosto ago._septiembre sep._octubre oct._noviembre nov._diciembre dic.'.split('_'), i;
db71a655 19079 function equalTest(input, mmm, i) {
96d0d679 19080 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
db71a655
KM
19081 }
19082 for (i = 0; i < 12; i++) {
19083 tests[i] = tests[i].split(' ');
19084 equalTest(tests[i][0], 'MMM', i);
19085 equalTest(tests[i][1], 'MMM', i);
19086 equalTest(tests[i][0], 'MMMM', i);
19087 equalTest(tests[i][1], 'MMMM', i);
19088 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
19089 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
19090 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
19091 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
19092 }
19093 });
19094
19095 test('format', function (assert) {
19096 var a = [
96d0d679
KM
19097 ['dddd, MMMM Do YYYY, h:mm:ss a', 'domingo, febrero 14º 2010, 3:25:50 pm'],
19098 ['ddd, hA', 'dom., 3PM'],
19099 ['M Mo MM MMMM MMM', '2 2º 02 febrero feb.'],
19100 ['YYYY YY', '2010 10'],
19101 ['D Do DD', '14 14º 14'],
19102 ['d do dddd ddd dd', '0 0º domingo dom. do'],
19103 ['DDD DDDo DDDD', '45 45º 045'],
19104 ['w wo ww', '6 6º 06'],
19105 ['YYYY-MMM-DD', '2010-feb-14'],
19106 ['h hh', '3 03'],
19107 ['H HH', '15 15'],
19108 ['m mm', '25 25'],
19109 ['s ss', '50 50'],
19110 ['a A', 'pm PM'],
19111 ['[the] DDDo [day of the year]', 'the 45º day of the year'],
19112 ['LTS', '15:25:50'],
19113 ['L', '14/02/2010'],
19114 ['LL', '14 de febrero de 2010'],
19115 ['LLL', '14 de febrero de 2010 15:25'],
19116 ['LLLL', 'domingo, 14 de febrero de 2010 15:25'],
19117 ['l', '14/2/2010'],
19118 ['ll', '14 de feb. de 2010'],
19119 ['lll', '14 de feb. de 2010 15:25'],
19120 ['llll', 'dom., 14 de feb. de 2010 15:25']
db71a655
KM
19121 ],
19122 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
19123 i;
19124 for (i = 0; i < a.length; i++) {
19125 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
19126 }
19127 });
19128
19129 test('format ordinal', function (assert) {
96d0d679
KM
19130 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1º', '1º');
19131 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2º', '2º');
19132 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3º', '3º');
19133 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4º', '4º');
19134 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5º', '5º');
19135 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6º', '6º');
19136 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7º', '7º');
19137 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8º', '8º');
19138 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9º', '9º');
19139 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10º', '10º');
db71a655 19140
96d0d679
KM
19141 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11º', '11º');
19142 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12º', '12º');
19143 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13º', '13º');
19144 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14º', '14º');
19145 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15º', '15º');
19146 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16º', '16º');
19147 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17º', '17º');
19148 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18º', '18º');
19149 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19º', '19º');
19150 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20º', '20º');
db71a655 19151
96d0d679
KM
19152 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21º', '21º');
19153 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22º', '22º');
19154 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23º', '23º');
19155 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24º', '24º');
19156 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25º', '25º');
19157 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26º', '26º');
19158 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27º', '27º');
19159 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28º', '28º');
19160 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29º', '29º');
19161 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30º', '30º');
db71a655 19162
96d0d679 19163 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31º', '31º');
db71a655
KM
19164 });
19165
19166 test('format month', function (assert) {
96d0d679 19167 var expected = 'enero ene._febrero feb._marzo mar._abril abr._mayo may._junio jun._julio jul._agosto ago._septiembre sep._octubre oct._noviembre nov._diciembre dic.'.split('_'), i;
db71a655
KM
19168 for (i = 0; i < expected.length; i++) {
19169 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
19170 }
19171 });
19172
19173 test('format week', function (assert) {
96d0d679 19174 var expected = 'domingo dom. do_lunes lun. lu_martes mar. ma_miércoles mié. mi_jueves jue. ju_viernes vie. vi_sábado sáb. sá'.split('_'), i;
db71a655
KM
19175 for (i = 0; i < expected.length; i++) {
19176 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
19177 }
19178 });
19179
19180 test('from', function (assert) {
19181 var start = moment([2007, 1, 28]);
96d0d679
KM
19182 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'unos segundos', '44 seconds = a few seconds');
19183 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'un minuto', '45 seconds = a minute');
19184 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'un minuto', '89 seconds = a minute');
19185 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutos', '90 seconds = 2 minutes');
19186 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutos', '44 minutes = 44 minutes');
19187 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'una hora', '45 minutes = an hour');
19188 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'una hora', '89 minutes = an hour');
19189 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 horas', '90 minutes = 2 hours');
19190 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 horas', '5 hours = 5 hours');
19191 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 horas', '21 hours = 21 hours');
19192 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un día', '22 hours = a day');
19193 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un día', '35 hours = a day');
19194 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 días', '36 hours = 2 days');
19195 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un día', '1 day = a day');
19196 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 días', '5 days = 5 days');
19197 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 días', '25 days = 25 days');
19198 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'un mes', '26 days = a month');
19199 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'un mes', '30 days = a month');
19200 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'un mes', '43 days = a month');
19201 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 meses', '46 days = 2 months');
19202 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 meses', '75 days = 2 months');
19203 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 meses', '76 days = 3 months');
19204 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'un mes', '1 month = a month');
19205 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 meses', '5 months = 5 months');
19206 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un año', '345 days = a year');
19207 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 años', '548 days = 2 years');
19208 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un año', '1 year = a year');
19209 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 años', '5 years = 5 years');
db71a655
KM
19210 });
19211
19212 test('suffix', function (assert) {
96d0d679
KM
19213 assert.equal(moment(30000).from(0), 'en unos segundos', 'prefix');
19214 assert.equal(moment(0).from(30000), 'hace unos segundos', 'suffix');
db71a655
KM
19215 });
19216
19217 test('now from now', function (assert) {
96d0d679 19218 assert.equal(moment().fromNow(), 'hace unos segundos', 'now from now should display as in the past');
db71a655
KM
19219 });
19220
19221 test('fromNow', function (assert) {
96d0d679
KM
19222 assert.equal(moment().add({s: 30}).fromNow(), 'en unos segundos', 'en unos segundos');
19223 assert.equal(moment().add({d: 5}).fromNow(), 'en 5 días', 'en 5 días');
db71a655 19224 });
516f5f67 19225
db71a655
KM
19226 test('calendar day', function (assert) {
19227 var a = moment().hours(12).minutes(0).seconds(0);
b135bf1a 19228
96d0d679
KM
19229 assert.equal(moment(a).calendar(), 'hoy a las 12:00', 'today at the same time');
19230 assert.equal(moment(a).add({m: 25}).calendar(), 'hoy a las 12:25', 'Now plus 25 min');
19231 assert.equal(moment(a).add({h: 1}).calendar(), 'hoy a las 13:00', 'Now plus 1 hour');
19232 assert.equal(moment(a).add({d: 1}).calendar(), 'mañana a las 12:00', 'tomorrow at the same time');
19233 assert.equal(moment(a).add({d: 1, h : -1}).calendar(), 'mañana a las 11:00', 'tomorrow minus 1 hour');
19234 assert.equal(moment(a).subtract({h: 1}).calendar(), 'hoy a las 11:00', 'Now minus 1 hour');
19235 assert.equal(moment(a).subtract({d: 1}).calendar(), 'ayer a las 12:00', 'yesterday at the same time');
db71a655 19236 });
b135bf1a 19237
db71a655
KM
19238 test('calendar next week', function (assert) {
19239 var i, m;
96d0d679 19240
db71a655
KM
19241 for (i = 2; i < 7; i++) {
19242 m = moment().add({d: i});
96d0d679 19243 assert.equal(m.calendar(), m.format('dddd [a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today + ' + i + ' days current time');
db71a655 19244 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 19245 assert.equal(m.calendar(), m.format('dddd [a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today + ' + i + ' days beginning of day');
db71a655 19246 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 19247 assert.equal(m.calendar(), m.format('dddd [a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today + ' + i + ' days end of day');
73f3c911
IC
19248 }
19249 });
b135bf1a 19250
db71a655
KM
19251 test('calendar last week', function (assert) {
19252 var i, m;
96d0d679 19253
db71a655
KM
19254 for (i = 2; i < 7; i++) {
19255 m = moment().subtract({d: i});
96d0d679 19256 assert.equal(m.calendar(), m.format('[el] dddd [pasado a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today - ' + i + ' days current time');
db71a655 19257 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 19258 assert.equal(m.calendar(), m.format('[el] dddd [pasado a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today - ' + i + ' days beginning of day');
db71a655 19259 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 19260 assert.equal(m.calendar(), m.format('[el] dddd [pasado a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today - ' + i + ' days end of day');
73f3c911
IC
19261 }
19262 });
b135bf1a 19263
db71a655
KM
19264 test('calendar all else', function (assert) {
19265 var weeksAgo = moment().subtract({w: 1}),
19266 weeksFromNow = moment().add({w: 1});
19267
96d0d679
KM
19268 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
19269 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
db71a655
KM
19270
19271 weeksAgo = moment().subtract({w: 2});
19272 weeksFromNow = moment().add({w: 2});
19273
96d0d679
KM
19274 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
19275 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
73f3c911 19276 });
b135bf1a 19277
db71a655 19278 test('weeks year starting sunday formatted', function (assert) {
96d0d679
KM
19279 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52º', 'Jan 1 2012 should be week 52');
19280 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1º', 'Jan 2 2012 should be week 1');
19281 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1º', 'Jan 8 2012 should be week 1');
19282 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2º', 'Jan 9 2012 should be week 2');
19283 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2º', 'Jan 15 2012 should be week 2');
19284 });
19285
19286 test('test short months proper', function (assert) {
19287 var str = '02-ago-2016';
19288 assert.equal(moment(str, 'DD-MMM-YYYY').month(), '7', '02-ago-2016 month should be 7');
73f3c911 19289 });
d6651c21 19290
db71a655 19291})));
d6651c21 19292
d6651c21 19293
db71a655
KM
19294;(function (global, factory) {
19295 typeof exports === 'object' && typeof module !== 'undefined'
19296 && typeof require === 'function' ? factory(require('../../moment')) :
19297 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
19298 factory(global.moment)
19299}(this, (function (moment) { 'use strict';
19300
19301 function each(array, callback) {
19302 var i;
19303 for (i = 0; i < array.length; i++) {
19304 callback(array[i], i, array);
73f3c911 19305 }
db71a655 19306 }
d6651c21 19307
c58511b9
KM
19308 function setupDeprecationHandler(test, moment$$1, scope) {
19309 test._expectedDeprecations = null;
19310 test._observedDeprecations = null;
19311 test._oldSupress = moment$$1.suppressDeprecationWarnings;
19312 moment$$1.suppressDeprecationWarnings = true;
19313 test.expectedDeprecations = function () {
19314 test._expectedDeprecations = arguments;
19315 test._observedDeprecations = [];
19316 };
19317 moment$$1.deprecationHandler = function (name, msg) {
19318 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
19319 if (deprecationId === -1) {
19320 throw new Error('Unexpected deprecation thrown name=' +
19321 name + ' msg=' + msg);
19322 }
19323 test._observedDeprecations[deprecationId] = 1;
19324 };
19325 }
19326
19327 function teardownDeprecationHandler(test, moment$$1, scope) {
19328 moment$$1.suppressDeprecationWarnings = test._oldSupress;
19329
19330 if (test._expectedDeprecations != null) {
19331 var missedDeprecations = [];
19332 each(test._expectedDeprecations, function (deprecationPattern, id) {
19333 if (test._observedDeprecations[id] !== 1) {
19334 missedDeprecations.push(deprecationPattern);
19335 }
19336 });
19337 if (missedDeprecations.length !== 0) {
19338 throw new Error('Expected deprecation warnings did not happen: ' +
19339 missedDeprecations.join(' '));
19340 }
19341 }
19342 }
19343
19344 function matchedDeprecation(name, msg, deprecations) {
19345 if (deprecations == null) {
19346 return -1;
19347 }
19348 for (var i = 0; i < deprecations.length; ++i) {
19349 if (name != null && name === deprecations[i]) {
19350 return i;
19351 }
19352 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
19353 return i;
19354 }
19355 }
19356 return -1;
19357 }
19358
19359 /*global QUnit:false*/
19360
19361 var test = QUnit.test;
19362
db71a655
KM
19363 function objectKeys(obj) {
19364 if (Object.keys) {
19365 return Object.keys(obj);
19366 } else {
19367 // IE8
19368 var res = [], i;
19369 for (i in obj) {
19370 if (obj.hasOwnProperty(i)) {
19371 res.push(i);
19372 }
19373 }
19374 return res;
d6651c21 19375 }
db71a655 19376 }
d6651c21 19377
db71a655 19378 // Pick the first defined of two or three arguments.
73f3c911 19379
db71a655
KM
19380 function defineCommonLocaleTests(locale, options) {
19381 test('lenient day of month ordinal parsing', function (assert) {
19382 var i, ordinalStr, testMoment;
19383 for (i = 1; i <= 31; ++i) {
19384 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
19385 testMoment = moment(ordinalStr, 'YYYY MM Do');
19386 assert.equal(testMoment.year(), 2014,
19387 'lenient day of month ordinal parsing ' + i + ' year check');
19388 assert.equal(testMoment.month(), 0,
19389 'lenient day of month ordinal parsing ' + i + ' month check');
19390 assert.equal(testMoment.date(), i,
19391 'lenient day of month ordinal parsing ' + i + ' date check');
19392 }
19393 });
b135bf1a 19394
db71a655
KM
19395 test('lenient day of month ordinal parsing of number', function (assert) {
19396 var i, testMoment;
19397 for (i = 1; i <= 31; ++i) {
19398 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
19399 assert.equal(testMoment.year(), 2014,
19400 'lenient day of month ordinal parsing of number ' + i + ' year check');
19401 assert.equal(testMoment.month(), 0,
19402 'lenient day of month ordinal parsing of number ' + i + ' month check');
19403 assert.equal(testMoment.date(), i,
19404 'lenient day of month ordinal parsing of number ' + i + ' date check');
19405 }
19406 });
19407
19408 test('strict day of month ordinal parsing', function (assert) {
19409 var i, ordinalStr, testMoment;
19410 for (i = 1; i <= 31; ++i) {
19411 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
19412 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
19413 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
19414 }
19415 });
516f5f67 19416
db71a655
KM
19417 test('meridiem invariant', function (assert) {
19418 var h, m, t1, t2;
19419 for (h = 0; h < 24; ++h) {
19420 for (m = 0; m < 60; m += 15) {
19421 t1 = moment.utc([2000, 0, 1, h, m]);
19422 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
19423 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
19424 'meridiem at ' + t1.format('HH:mm'));
19425 }
19426 }
19427 });
19428
19429 test('date format correctness', function (assert) {
19430 var data, tokens;
19431 data = moment.localeData()._longDateFormat;
19432 tokens = objectKeys(data);
19433 each(tokens, function (srchToken) {
19434 // Check each format string to make sure it does not contain any
19435 // tokens that need to be expanded.
19436 each(tokens, function (baseToken) {
19437 // strip escaped sequences
19438 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
19439 assert.equal(false, !!~format.indexOf(srchToken),
19440 'contains ' + srchToken + ' in ' + baseToken);
19441 });
19442 });
19443 });
c74a101d 19444
db71a655
KM
19445 test('month parsing correctness', function (assert) {
19446 var i, m;
19447
19448 if (locale === 'tr') {
19449 // I can't fix it :(
c58511b9 19450 assert.expect(0);
db71a655
KM
19451 return;
19452 }
19453 function tester(format) {
19454 var r;
19455 r = moment(m.format(format), format);
19456 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
19457 if (locale !== 'ka') {
19458 r = moment(m.format(format).toLocaleUpperCase(), format);
19459 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
19460 }
db71a655
KM
19461 r = moment(m.format(format).toLocaleLowerCase(), format);
19462 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
19463
19464 r = moment(m.format(format), format, true);
19465 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
19466 if (locale !== 'ka') {
19467 r = moment(m.format(format).toLocaleUpperCase(), format, true);
19468 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
19469 }
db71a655
KM
19470 r = moment(m.format(format).toLocaleLowerCase(), format, true);
19471 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
19472 }
19473
19474 for (i = 0; i < 12; ++i) {
19475 m = moment([2015, i, 15, 18]);
19476 tester('MMM');
19477 tester('MMM.');
19478 tester('MMMM');
19479 tester('MMMM.');
516f5f67
IC
19480 }
19481 });
db71a655
KM
19482
19483 test('weekday parsing correctness', function (assert) {
19484 var i, m;
19485
96d0d679 19486 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
19487 // tr, az: There is a lower-case letter (ı), that converted to
19488 // upper then lower changes to i
19489 // ro: there is the letter ț which behaves weird under IE8
19490 // mt: letter Ħ
96d0d679 19491 // ga: month with spaces
c58511b9 19492 assert.expect(0);
db71a655
KM
19493 return;
19494 }
19495 function tester(format) {
19496 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
19497 r = moment(m.format(format), format);
19498 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
19499 if (locale !== 'ka') {
19500 r = moment(m.format(format).toLocaleUpperCase(), format);
19501 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
19502 }
db71a655
KM
19503 r = moment(m.format(format).toLocaleLowerCase(), format);
19504 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
19505 r = moment(m.format(format), format, true);
19506 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
19507 if (locale !== 'ka') {
19508 r = moment(m.format(format).toLocaleUpperCase(), format, true);
19509 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
19510 }
db71a655
KM
19511 r = moment(m.format(format).toLocaleLowerCase(), format, true);
19512 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
19513 }
19514
19515 for (i = 0; i < 7; ++i) {
19516 m = moment.utc([2015, 0, i + 1, 18]);
19517 tester('dd');
19518 tester('ddd');
19519 tester('dddd');
19520 }
19521 });
19522
19523 test('valid localeData', function (assert) {
19524 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
19525 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
19526 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
19527 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
19528 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
19529 });
96d0d679
KM
19530
19531 test('localeData weekdays can localeSort', function (assert) {
19532 var weekdays = moment().localeData().weekdays();
19533 var weekdaysShort = moment().localeData().weekdaysShort();
19534 var weekdaysMin = moment().localeData().weekdaysMin();
19535 var shift = moment().localeData()._week.dow;
19536 assert.deepEqual(
19537 moment().localeData().weekdays(true),
19538 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
19539 'weekdays should localeSort');
19540 assert.deepEqual(
19541 moment().localeData().weekdaysShort(true),
19542 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
19543 'weekdaysShort should localeSort');
19544 assert.deepEqual(
19545 moment().localeData().weekdaysMin(true),
19546 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
19547 'weekdaysMin should localeSort');
19548 });
516f5f67
IC
19549 }
19550
db71a655 19551 /*global QUnit:false*/
516f5f67 19552
db71a655
KM
19553 function localeModule (name, lifecycle) {
19554 QUnit.module('locale:' + name, {
c58511b9 19555 beforeEach : function () {
db71a655
KM
19556 moment.locale(name);
19557 moment.createFromInputFallback = function (config) {
19558 throw new Error('input not handled by moment: ' + config._i);
19559 };
19560 setupDeprecationHandler(test, moment, 'locale');
19561 if (lifecycle && lifecycle.setup) {
19562 lifecycle.setup();
19563 }
19564 },
c58511b9 19565 afterEach : function () {
db71a655
KM
19566 moment.locale('en');
19567 teardownDeprecationHandler(test, moment, 'locale');
19568 if (lifecycle && lifecycle.teardown) {
19569 lifecycle.teardown();
19570 }
73f3c911 19571 }
db71a655
KM
19572 });
19573 defineCommonLocaleTests(name, -1, -1);
19574 }
19575
96d0d679 19576 localeModule('et');
db71a655
KM
19577
19578 test('parse', function (assert) {
96d0d679 19579 var tests = 'jaanuar jaan_veebruar veebr_märts märts_aprill apr_mai mai_juuni juuni_juuli juuli_august aug_september sept_oktoober okt_november nov_detsember dets'.split('_'), i;
db71a655 19580 function equalTest(input, mmm, i) {
96d0d679 19581 assert.equal(moment(input, mmm).month(), i, input + ' peaks olema kuu ' + (i + 1));
db71a655
KM
19582 }
19583 for (i = 0; i < 12; i++) {
19584 tests[i] = tests[i].split(' ');
19585 equalTest(tests[i][0], 'MMM', i);
19586 equalTest(tests[i][1], 'MMM', i);
19587 equalTest(tests[i][0], 'MMMM', i);
19588 equalTest(tests[i][1], 'MMMM', i);
19589 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
19590 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
19591 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
19592 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
19593 }
19594 });
19595
19596 test('format', function (assert) {
19597 var a = [
96d0d679
KM
19598 ['dddd, Do MMMM YYYY, H:mm:ss', 'pühapäev, 14. veebruar 2010, 15:25:50'],
19599 ['ddd, h', 'P, 3'],
19600 ['M Mo MM MMMM MMM', '2 2. 02 veebruar veebr'],
19601 ['YYYY YY', '2010 10'],
19602 ['D Do DD', '14 14. 14'],
19603 ['d do dddd ddd dd', '0 0. pühapäev P P'],
19604 ['DDD DDDo DDDD', '45 45. 045'],
19605 ['w wo ww', '6 6. 06'],
19606 ['h hh', '3 03'],
19607 ['H HH', '15 15'],
19608 ['m mm', '25 25'],
19609 ['s ss', '50 50'],
19610 ['a A', 'pm PM'],
19611 ['[aasta] DDDo [päev]', 'aasta 45. päev'],
19612 ['LTS', '15:25:50'],
19613 ['L', '14.02.2010'],
19614 ['LL', '14. veebruar 2010'],
19615 ['LLL', '14. veebruar 2010 15:25'],
19616 ['LLLL', 'pühapäev, 14. veebruar 2010 15:25'],
19617 ['l', '14.2.2010'],
19618 ['ll', '14. veebr 2010'],
19619 ['lll', '14. veebr 2010 15:25'],
19620 ['llll', 'P, 14. veebr 2010 15:25']
db71a655
KM
19621 ],
19622 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
19623 i;
19624 for (i = 0; i < a.length; i++) {
19625 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
19626 }
19627 });
19628
19629 test('format ordinal', function (assert) {
19630 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
19631 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
19632 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
19633 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
19634 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
19635 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
19636 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
19637 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
19638 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
19639 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
19640
19641 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
19642 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
19643 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
19644 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
19645 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
19646 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
19647 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
19648 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
19649 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
19650 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
19651
19652 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
19653 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
19654 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
19655 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
19656 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
19657 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
19658 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
19659 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
19660 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
19661 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
19662
19663 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
19664 });
19665
19666 test('format month', function (assert) {
96d0d679 19667 var expected = 'jaanuar jaan_veebruar veebr_märts märts_aprill apr_mai mai_juuni juuni_juuli juuli_august aug_september sept_oktoober okt_november nov_detsember dets'.split('_'), i;
db71a655
KM
19668 for (i = 0; i < expected.length; i++) {
19669 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
19670 }
19671 });
19672
19673 test('format week', function (assert) {
96d0d679 19674 var expected = 'pühapäev P P_esmaspäev E E_teisipäev T T_kolmapäev K K_neljapäev N N_reede R R_laupäev L L'.split('_'), i;
db71a655
KM
19675 for (i = 0; i < expected.length; i++) {
19676 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
19677 }
19678 });
19679
19680 test('from', function (assert) {
19681 var start = moment([2007, 1, 28]);
96d0d679
KM
19682 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'paar sekundit', '44 seconds = paar sekundit');
19683 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'üks minut', '45 seconds = üks minut');
19684 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'üks minut', '89 seconds = üks minut');
19685 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutit', '90 seconds = 2 minutit');
19686 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutit', '44 minutes = 44 minutit');
19687 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'üks tund', '45 minutes = tund aega');
19688 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'üks tund', '89 minutes = üks tund');
19689 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 tundi', '90 minutes = 2 tundi');
19690 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 tundi', '5 hours = 5 tundi');
19691 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 tundi', '21 hours = 21 tundi');
19692 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'üks päev', '22 hours = üks päev');
19693 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'üks päev', '35 hours = üks päev');
19694 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 päeva', '36 hours = 2 päeva');
19695 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'üks päev', '1 day = üks päev');
19696 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 päeva', '5 days = 5 päeva');
19697 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 päeva', '25 days = 25 päeva');
19698 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'üks kuu', '26 days = üks kuu');
19699 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'üks kuu', '30 days = üks kuu');
19700 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'üks kuu', '43 days = üks kuu');
19701 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 kuud', '46 days = 2 kuud');
19702 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 kuud', '75 days = 2 kuud');
19703 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 kuud', '76 days = 3 kuud');
19704 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'üks kuu', '1 month = üks kuu');
19705 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 kuud', '5 months = 5 kuud');
19706 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'üks aasta', '345 days = üks aasta');
19707 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 aastat', '548 days = 2 aastat');
19708 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'üks aasta', '1 year = üks aasta');
19709 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 aastat', '5 years = 5 aastat');
db71a655
KM
19710 });
19711
19712 test('suffix', function (assert) {
96d0d679
KM
19713 assert.equal(moment(30000).from(0), 'mõne sekundi pärast', 'prefix');
19714 assert.equal(moment(0).from(30000), 'mõni sekund tagasi', 'suffix');
db71a655
KM
19715 });
19716
19717 test('now from now', function (assert) {
96d0d679 19718 assert.equal(moment().fromNow(), 'mõni sekund tagasi', 'now from now should display as in the past');
db71a655
KM
19719 });
19720
19721 test('fromNow', function (assert) {
96d0d679
KM
19722 assert.equal(moment().add({s: 30}).fromNow(), 'mõne sekundi pärast', 'in a few seconds');
19723 assert.equal(moment().subtract({s: 30}).fromNow(), 'mõni sekund tagasi', 'a few seconds ago');
19724
19725 assert.equal(moment().add({m: 1}).fromNow(), 'ühe minuti pärast', 'in a minute');
19726 assert.equal(moment().subtract({m: 1}).fromNow(), 'üks minut tagasi', 'a minute ago');
19727
19728 assert.equal(moment().add({m: 5}).fromNow(), '5 minuti pärast', 'in 5 minutes');
19729 assert.equal(moment().subtract({m: 5}).fromNow(), '5 minutit tagasi', '5 minutes ago');
19730
19731 assert.equal(moment().add({d: 1}).fromNow(), 'ühe päeva pärast', 'in one day');
19732 assert.equal(moment().subtract({d: 1}).fromNow(), 'üks päev tagasi', 'one day ago');
19733
19734 assert.equal(moment().add({d: 5}).fromNow(), '5 päeva pärast', 'in 5 days');
19735 assert.equal(moment().subtract({d: 5}).fromNow(), '5 päeva tagasi', '5 days ago');
19736
19737 assert.equal(moment().add({M: 1}).fromNow(), 'kuu aja pärast', 'in a month');
19738 assert.equal(moment().subtract({M: 1}).fromNow(), 'kuu aega tagasi', 'a month ago');
19739
19740 assert.equal(moment().add({M: 5}).fromNow(), '5 kuu pärast', 'in 5 months');
19741 assert.equal(moment().subtract({M: 5}).fromNow(), '5 kuud tagasi', '5 months ago');
19742
19743 assert.equal(moment().add({y: 1}).fromNow(), 'ühe aasta pärast', 'in a year');
19744 assert.equal(moment().subtract({y: 1}).fromNow(), 'aasta tagasi', 'a year ago');
19745
19746 assert.equal(moment().add({y: 5}).fromNow(), '5 aasta pärast', 'in 5 years');
19747 assert.equal(moment().subtract({y: 5}).fromNow(), '5 aastat tagasi', '5 years ago');
db71a655
KM
19748 });
19749
19750 test('calendar day', function (assert) {
19751 var a = moment().hours(12).minutes(0).seconds(0);
19752
96d0d679
KM
19753 assert.equal(moment(a).calendar(), 'Täna, 12:00', 'today at the same time');
19754 assert.equal(moment(a).add({m: 25}).calendar(), 'Täna, 12:25', 'Now plus 25 min');
19755 assert.equal(moment(a).add({h: 1}).calendar(), 'Täna, 13:00', 'Now plus 1 hour');
19756 assert.equal(moment(a).add({d: 1}).calendar(), 'Homme, 12:00', 'tomorrow at the same time');
19757 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Täna, 11:00', 'Now minus 1 hour');
19758 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Eile, 12:00', 'yesterday at the same time');
db71a655
KM
19759 });
19760
19761 test('calendar next week', function (assert) {
19762 var i, m;
19763 for (i = 2; i < 7; i++) {
19764 m = moment().add({d: i});
96d0d679 19765 assert.equal(m.calendar(), m.format('[Järgmine] dddd LT'), 'Today + ' + i + ' days current time');
db71a655 19766 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 19767 assert.equal(m.calendar(), m.format('[Järgmine] dddd LT'), 'Today + ' + i + ' days beginning of day');
db71a655 19768 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 19769 assert.equal(m.calendar(), m.format('[Järgmine] dddd LT'), 'Today + ' + i + ' days end of day');
db71a655
KM
19770 }
19771 });
19772
19773 test('calendar last week', function (assert) {
19774 var i, m;
19775 for (i = 2; i < 7; i++) {
19776 m = moment().subtract({d: i});
96d0d679 19777 assert.equal(m.calendar(), m.format('[Eelmine] dddd LT'), 'Today - ' + i + ' days current time');
db71a655 19778 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 19779 assert.equal(m.calendar(), m.format('[Eelmine] dddd LT'), 'Today - ' + i + ' days beginning of day');
db71a655 19780 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 19781 assert.equal(m.calendar(), m.format('[Eelmine] dddd LT'), 'Today - ' + i + ' days end of day');
db71a655
KM
19782 }
19783 });
19784
19785 test('calendar all else', function (assert) {
19786 var weeksAgo = moment().subtract({w: 1}),
19787 weeksFromNow = moment().add({w: 1});
19788
96d0d679
KM
19789 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 nädal tagasi');
19790 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), '1 nädala pärast');
db71a655
KM
19791
19792 weeksAgo = moment().subtract({w: 2});
19793 weeksFromNow = moment().add({w: 2});
19794
96d0d679
KM
19795 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 nädalat tagasi');
19796 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), '2 nädala pärast');
db71a655
KM
19797 });
19798
19799 test('weeks year starting sunday formatted', function (assert) {
96d0d679
KM
19800 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
19801 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
19802 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
19803 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
19804 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
db71a655 19805 });
73f3c911
IC
19806
19807})));
19808
516f5f67 19809
c74a101d
IC
19810;(function (global, factory) {
19811 typeof exports === 'object' && typeof module !== 'undefined'
19812 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
19813 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
19814 factory(global.moment)
73f3c911 19815}(this, (function (moment) { 'use strict';
516f5f67 19816
db71a655
KM
19817 function each(array, callback) {
19818 var i;
19819 for (i = 0; i < array.length; i++) {
19820 callback(array[i], i, array);
19821 }
b135bf1a
IC
19822 }
19823
c58511b9
KM
19824 function setupDeprecationHandler(test, moment$$1, scope) {
19825 test._expectedDeprecations = null;
19826 test._observedDeprecations = null;
19827 test._oldSupress = moment$$1.suppressDeprecationWarnings;
19828 moment$$1.suppressDeprecationWarnings = true;
19829 test.expectedDeprecations = function () {
19830 test._expectedDeprecations = arguments;
19831 test._observedDeprecations = [];
19832 };
19833 moment$$1.deprecationHandler = function (name, msg) {
19834 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
19835 if (deprecationId === -1) {
19836 throw new Error('Unexpected deprecation thrown name=' +
19837 name + ' msg=' + msg);
19838 }
19839 test._observedDeprecations[deprecationId] = 1;
19840 };
19841 }
19842
19843 function teardownDeprecationHandler(test, moment$$1, scope) {
19844 moment$$1.suppressDeprecationWarnings = test._oldSupress;
19845
19846 if (test._expectedDeprecations != null) {
19847 var missedDeprecations = [];
19848 each(test._expectedDeprecations, function (deprecationPattern, id) {
19849 if (test._observedDeprecations[id] !== 1) {
19850 missedDeprecations.push(deprecationPattern);
19851 }
19852 });
19853 if (missedDeprecations.length !== 0) {
19854 throw new Error('Expected deprecation warnings did not happen: ' +
19855 missedDeprecations.join(' '));
19856 }
19857 }
19858 }
19859
19860 function matchedDeprecation(name, msg, deprecations) {
19861 if (deprecations == null) {
19862 return -1;
19863 }
19864 for (var i = 0; i < deprecations.length; ++i) {
19865 if (name != null && name === deprecations[i]) {
19866 return i;
19867 }
19868 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
19869 return i;
19870 }
19871 }
19872 return -1;
19873 }
19874
19875 /*global QUnit:false*/
19876
19877 var test = QUnit.test;
19878
db71a655
KM
19879 function objectKeys(obj) {
19880 if (Object.keys) {
19881 return Object.keys(obj);
19882 } else {
19883 // IE8
19884 var res = [], i;
19885 for (i in obj) {
19886 if (obj.hasOwnProperty(i)) {
19887 res.push(i);
19888 }
b135bf1a 19889 }
db71a655 19890 return res;
b135bf1a 19891 }
b135bf1a
IC
19892 }
19893
db71a655 19894 // Pick the first defined of two or three arguments.
b135bf1a 19895
db71a655
KM
19896 function defineCommonLocaleTests(locale, options) {
19897 test('lenient day of month ordinal parsing', function (assert) {
19898 var i, ordinalStr, testMoment;
19899 for (i = 1; i <= 31; ++i) {
19900 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
19901 testMoment = moment(ordinalStr, 'YYYY MM Do');
19902 assert.equal(testMoment.year(), 2014,
19903 'lenient day of month ordinal parsing ' + i + ' year check');
19904 assert.equal(testMoment.month(), 0,
19905 'lenient day of month ordinal parsing ' + i + ' month check');
19906 assert.equal(testMoment.date(), i,
19907 'lenient day of month ordinal parsing ' + i + ' date check');
19908 }
19909 });
b135bf1a 19910
db71a655
KM
19911 test('lenient day of month ordinal parsing of number', function (assert) {
19912 var i, testMoment;
19913 for (i = 1; i <= 31; ++i) {
19914 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
19915 assert.equal(testMoment.year(), 2014,
19916 'lenient day of month ordinal parsing of number ' + i + ' year check');
19917 assert.equal(testMoment.month(), 0,
19918 'lenient day of month ordinal parsing of number ' + i + ' month check');
19919 assert.equal(testMoment.date(), i,
19920 'lenient day of month ordinal parsing of number ' + i + ' date check');
19921 }
19922 });
b135bf1a 19923
db71a655
KM
19924 test('strict day of month ordinal parsing', function (assert) {
19925 var i, ordinalStr, testMoment;
19926 for (i = 1; i <= 31; ++i) {
19927 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
19928 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
19929 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
19930 }
19931 });
b135bf1a 19932
db71a655
KM
19933 test('meridiem invariant', function (assert) {
19934 var h, m, t1, t2;
19935 for (h = 0; h < 24; ++h) {
19936 for (m = 0; m < 60; m += 15) {
19937 t1 = moment.utc([2000, 0, 1, h, m]);
19938 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
19939 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
19940 'meridiem at ' + t1.format('HH:mm'));
19941 }
19942 }
19943 });
19944
19945 test('date format correctness', function (assert) {
19946 var data, tokens;
19947 data = moment.localeData()._longDateFormat;
19948 tokens = objectKeys(data);
19949 each(tokens, function (srchToken) {
19950 // Check each format string to make sure it does not contain any
19951 // tokens that need to be expanded.
19952 each(tokens, function (baseToken) {
19953 // strip escaped sequences
19954 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
19955 assert.equal(false, !!~format.indexOf(srchToken),
19956 'contains ' + srchToken + ' in ' + baseToken);
19957 });
b135bf1a
IC
19958 });
19959 });
d6651c21 19960
db71a655
KM
19961 test('month parsing correctness', function (assert) {
19962 var i, m;
19963
19964 if (locale === 'tr') {
19965 // I can't fix it :(
c58511b9 19966 assert.expect(0);
db71a655
KM
19967 return;
19968 }
19969 function tester(format) {
19970 var r;
19971 r = moment(m.format(format), format);
19972 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
19973 if (locale !== 'ka') {
19974 r = moment(m.format(format).toLocaleUpperCase(), format);
19975 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
19976 }
db71a655
KM
19977 r = moment(m.format(format).toLocaleLowerCase(), format);
19978 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
19979
19980 r = moment(m.format(format), format, true);
19981 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
19982 if (locale !== 'ka') {
19983 r = moment(m.format(format).toLocaleUpperCase(), format, true);
19984 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
19985 }
db71a655
KM
19986 r = moment(m.format(format).toLocaleLowerCase(), format, true);
19987 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
19988 }
19989
19990 for (i = 0; i < 12; ++i) {
19991 m = moment([2015, i, 15, 18]);
19992 tester('MMM');
19993 tester('MMM.');
19994 tester('MMMM');
19995 tester('MMMM.');
19996 }
19997 });
d6651c21 19998
db71a655
KM
19999 test('weekday parsing correctness', function (assert) {
20000 var i, m;
20001
96d0d679 20002 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
20003 // tr, az: There is a lower-case letter (ı), that converted to
20004 // upper then lower changes to i
20005 // ro: there is the letter ț which behaves weird under IE8
20006 // mt: letter Ħ
96d0d679 20007 // ga: month with spaces
c58511b9 20008 assert.expect(0);
db71a655
KM
20009 return;
20010 }
20011 function tester(format) {
20012 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
20013 r = moment(m.format(format), format);
20014 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
20015 if (locale !== 'ka') {
20016 r = moment(m.format(format).toLocaleUpperCase(), format);
20017 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
20018 }
db71a655
KM
20019 r = moment(m.format(format).toLocaleLowerCase(), format);
20020 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
20021 r = moment(m.format(format), format, true);
20022 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
20023 if (locale !== 'ka') {
20024 r = moment(m.format(format).toLocaleUpperCase(), format, true);
20025 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
20026 }
db71a655
KM
20027 r = moment(m.format(format).toLocaleLowerCase(), format, true);
20028 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
20029 }
20030
20031 for (i = 0; i < 7; ++i) {
20032 m = moment.utc([2015, 0, i + 1, 18]);
20033 tester('dd');
20034 tester('ddd');
20035 tester('dddd');
20036 }
20037 });
d6651c21 20038
db71a655
KM
20039 test('valid localeData', function (assert) {
20040 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
20041 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
20042 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
20043 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
20044 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
20045 });
96d0d679
KM
20046
20047 test('localeData weekdays can localeSort', function (assert) {
20048 var weekdays = moment().localeData().weekdays();
20049 var weekdaysShort = moment().localeData().weekdaysShort();
20050 var weekdaysMin = moment().localeData().weekdaysMin();
20051 var shift = moment().localeData()._week.dow;
20052 assert.deepEqual(
20053 moment().localeData().weekdays(true),
20054 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
20055 'weekdays should localeSort');
20056 assert.deepEqual(
20057 moment().localeData().weekdaysShort(true),
20058 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
20059 'weekdaysShort should localeSort');
20060 assert.deepEqual(
20061 moment().localeData().weekdaysMin(true),
20062 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
20063 'weekdaysMin should localeSort');
20064 });
db71a655 20065 }
d6651c21 20066
db71a655 20067 /*global QUnit:false*/
516f5f67 20068
db71a655
KM
20069 function localeModule (name, lifecycle) {
20070 QUnit.module('locale:' + name, {
c58511b9 20071 beforeEach : function () {
db71a655
KM
20072 moment.locale(name);
20073 moment.createFromInputFallback = function (config) {
20074 throw new Error('input not handled by moment: ' + config._i);
20075 };
20076 setupDeprecationHandler(test, moment, 'locale');
20077 if (lifecycle && lifecycle.setup) {
20078 lifecycle.setup();
20079 }
20080 },
c58511b9 20081 afterEach : function () {
db71a655
KM
20082 moment.locale('en');
20083 teardownDeprecationHandler(test, moment, 'locale');
20084 if (lifecycle && lifecycle.teardown) {
20085 lifecycle.teardown();
20086 }
516f5f67
IC
20087 }
20088 });
db71a655
KM
20089 defineCommonLocaleTests(name, -1, -1);
20090 }
20091
96d0d679 20092 localeModule('eu');
db71a655
KM
20093
20094 test('parse', function (assert) {
96d0d679 20095 var tests = 'urtarrila urt._otsaila ots._martxoa mar._apirila api._maiatza mai._ekaina eka._uztaila uzt._abuztua abu._iraila ira._urria urr._azaroa aza._abendua abe.'.split('_'), i;
db71a655 20096 function equalTest(input, mmm, i) {
96d0d679 20097 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
db71a655
KM
20098 }
20099 for (i = 0; i < 12; i++) {
96d0d679
KM
20100 tests[i] = tests[i].split(' ');
20101 equalTest(tests[i][0], 'MMM', i);
20102 equalTest(tests[i][1], 'MMM', i);
20103 equalTest(tests[i][0], 'MMMM', i);
20104 equalTest(tests[i][1], 'MMMM', i);
20105 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
20106 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
20107 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
20108 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
db71a655
KM
20109 }
20110 });
20111
20112 test('format', function (assert) {
20113 var a = [
96d0d679
KM
20114 ['dddd, MMMM Do YYYY, h:mm:ss a', 'igandea, otsaila 14. 2010, 3:25:50 pm'],
20115 ['ddd, hA', 'ig., 3PM'],
20116 ['M Mo MM MMMM MMM', '2 2. 02 otsaila ots.'],
20117 ['YYYY YY', '2010 10'],
20118 ['D Do DD', '14 14. 14'],
20119 ['d do dddd ddd dd', '0 0. igandea ig. ig'],
20120 ['DDD DDDo DDDD', '45 45. 045'],
20121 ['w wo ww', '7 7. 07'],
20122 ['h hh', '3 03'],
20123 ['H HH', '15 15'],
20124 ['m mm', '25 25'],
20125 ['s ss', '50 50'],
20126 ['a A', 'pm PM'],
20127 ['[the] DDDo [day of the year]', 'the 45. day of the year'],
20128 ['LTS', '15:25:50'],
20129 ['L', '2010-02-14'],
20130 ['LL', '2010ko otsailaren 14a'],
20131 ['LLL', '2010ko otsailaren 14a 15:25'],
20132 ['LLLL', 'igandea, 2010ko otsailaren 14a 15:25'],
20133 ['l', '2010-2-14'],
20134 ['ll', '2010ko ots. 14a'],
20135 ['lll', '2010ko ots. 14a 15:25'],
20136 ['llll', 'ig., 2010ko ots. 14a 15:25']
db71a655
KM
20137 ],
20138 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
20139 i;
20140 for (i = 0; i < a.length; i++) {
20141 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
20142 }
20143 });
20144
20145 test('format ordinal', function (assert) {
96d0d679
KM
20146 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
20147 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
20148 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
20149 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
20150 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
20151 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
20152 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
20153 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
20154 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
20155 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
db71a655 20156
96d0d679
KM
20157 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
20158 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
20159 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
20160 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
20161 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
20162 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
20163 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
20164 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
20165 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
20166 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
db71a655 20167
96d0d679
KM
20168 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
20169 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
20170 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
20171 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
20172 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
20173 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
20174 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
20175 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
20176 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
20177 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
db71a655 20178
96d0d679 20179 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
db71a655
KM
20180 });
20181
20182 test('format month', function (assert) {
96d0d679 20183 var expected = 'urtarrila urt._otsaila ots._martxoa mar._apirila api._maiatza mai._ekaina eka._uztaila uzt._abuztua abu._iraila ira._urria urr._azaroa aza._abendua abe.'.split('_'), i;
db71a655
KM
20184 for (i = 0; i < expected.length; i++) {
20185 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
20186 }
20187 });
20188
20189 test('format week', function (assert) {
96d0d679 20190 var expected = 'igandea ig. ig_astelehena al. al_asteartea ar. ar_asteazkena az. az_osteguna og. og_ostirala ol. ol_larunbata lr. lr'.split('_'), i;
db71a655
KM
20191 for (i = 0; i < expected.length; i++) {
20192 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
20193 }
20194 });
20195
20196 test('from', function (assert) {
20197 var start = moment([2007, 1, 28]);
96d0d679
KM
20198 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'segundo batzuk', '44 seconds = a few seconds');
20199 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minutu bat', '45 seconds = a minute');
20200 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minutu bat', '89 seconds = a minute');
20201 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutu', '90 seconds = 2 minutes');
20202 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutu', '44 minutes = 44 minutes');
20203 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ordu bat', '45 minutes = an hour');
20204 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ordu bat', '89 minutes = an hour');
20205 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ordu', '90 minutes = 2 hours');
20206 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ordu', '5 hours = 5 hours');
20207 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ordu', '21 hours = 21 hours');
20208 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'egun bat', '22 hours = a day');
20209 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'egun bat', '35 hours = a day');
20210 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 egun', '36 hours = 2 days');
20211 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'egun bat', '1 day = a day');
20212 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 egun', '5 days = 5 days');
20213 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 egun', '25 days = 25 days');
20214 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'hilabete bat', '26 days = a month');
20215 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'hilabete bat', '30 days = a month');
20216 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'hilabete bat', '43 days = a month');
20217 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 hilabete', '46 days = 2 months');
20218 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 hilabete', '75 days = 2 months');
20219 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 hilabete', '76 days = 3 months');
20220 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'hilabete bat', '1 month = a month');
20221 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 hilabete', '5 months = 5 months');
20222 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'urte bat', '345 days = a year');
20223 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 urte', '548 days = 2 years');
20224 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'urte bat', '1 year = a year');
20225 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 urte', '5 years = 5 years');
db71a655
KM
20226 });
20227
20228 test('suffix', function (assert) {
96d0d679
KM
20229 assert.equal(moment(30000).from(0), 'segundo batzuk barru', 'prefix');
20230 assert.equal(moment(0).from(30000), 'duela segundo batzuk', 'suffix');
db71a655
KM
20231 });
20232
20233 test('now from now', function (assert) {
96d0d679 20234 assert.equal(moment().fromNow(), 'duela segundo batzuk', 'now from now should display as in the past');
db71a655
KM
20235 });
20236
20237 test('fromNow', function (assert) {
96d0d679
KM
20238 assert.equal(moment().add({s: 30}).fromNow(), 'segundo batzuk barru', 'in seconds');
20239 assert.equal(moment().add({d: 5}).fromNow(), '5 egun barru', 'in 5 days');
db71a655
KM
20240 });
20241
20242 test('calendar day', function (assert) {
20243 var a = moment().hours(12).minutes(0).seconds(0);
20244
96d0d679
KM
20245 assert.equal(moment(a).calendar(), 'gaur 12:00etan', 'today at the same time');
20246 assert.equal(moment(a).add({m: 25}).calendar(), 'gaur 12:25etan', 'now plus 25 min');
20247 assert.equal(moment(a).add({h: 1}).calendar(), 'gaur 13:00etan', 'now plus 1 hour');
20248 assert.equal(moment(a).add({d: 1}).calendar(), 'bihar 12:00etan', 'tomorrow at the same time');
20249 assert.equal(moment(a).subtract({h: 1}).calendar(), 'gaur 11:00etan', 'now minus 1 hour');
20250 assert.equal(moment(a).subtract({d: 1}).calendar(), 'atzo 12:00etan', 'yesterday at the same time');
db71a655
KM
20251 });
20252
20253 test('calendar next week', function (assert) {
20254 var i, m;
20255 for (i = 2; i < 7; i++) {
20256 m = moment().add({d: i});
96d0d679 20257 assert.equal(m.calendar(), m.format('dddd LT[etan]'), 'Today + ' + i + ' days current time');
db71a655 20258 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 20259 assert.equal(m.calendar(), m.format('dddd LT[etan]'), 'Today + ' + i + ' days beginning of day');
db71a655 20260 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 20261 assert.equal(m.calendar(), m.format('dddd LT[etan]'), 'Today + ' + i + ' days end of day');
73f3c911 20262 }
db71a655 20263 });
516f5f67 20264
db71a655
KM
20265 test('calendar last week', function (assert) {
20266 var i, m;
20267 for (i = 2; i < 7; i++) {
20268 m = moment().subtract({d: i});
96d0d679 20269 assert.equal(m.calendar(), m.format('[aurreko] dddd LT[etan]'), 'Today - ' + i + ' days current time');
db71a655 20270 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 20271 assert.equal(m.calendar(), m.format('[aurreko] dddd LT[etan]'), 'Today - ' + i + ' days beginning of day');
db71a655 20272 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 20273 assert.equal(m.calendar(), m.format('[aurreko] dddd LT[etan]'), 'Today - ' + i + ' days end of day');
d6651c21 20274 }
db71a655 20275 });
d6651c21 20276
db71a655
KM
20277 test('calendar all else', function (assert) {
20278 var weeksAgo = moment().subtract({w: 1}),
20279 weeksFromNow = moment().add({w: 1});
d6651c21 20280
db71a655
KM
20281 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
20282 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
d6651c21 20283
db71a655
KM
20284 weeksAgo = moment().subtract({w: 2});
20285 weeksFromNow = moment().add({w: 2});
d6651c21 20286
db71a655
KM
20287 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
20288 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
20289 });
20290
20291 test('weeks year starting sunday formatted', function (assert) {
96d0d679
KM
20292 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', 'Dec 26 2011 should be week 1');
20293 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1.', 'Jan 1 2012 should be week 1');
20294 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2.', 'Jan 2 2012 should be week 2');
20295 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2.', 'Jan 8 2012 should be week 2');
20296 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3.', 'Jan 9 2012 should be week 3');
db71a655 20297 });
73f3c911
IC
20298
20299})));
20300
516f5f67 20301
c74a101d
IC
20302;(function (global, factory) {
20303 typeof exports === 'object' && typeof module !== 'undefined'
20304 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
20305 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
20306 factory(global.moment)
73f3c911 20307}(this, (function (moment) { 'use strict';
516f5f67 20308
db71a655
KM
20309 function each(array, callback) {
20310 var i;
20311 for (i = 0; i < array.length; i++) {
20312 callback(array[i], i, array);
20313 }
b135bf1a
IC
20314 }
20315
c58511b9
KM
20316 function setupDeprecationHandler(test, moment$$1, scope) {
20317 test._expectedDeprecations = null;
20318 test._observedDeprecations = null;
20319 test._oldSupress = moment$$1.suppressDeprecationWarnings;
20320 moment$$1.suppressDeprecationWarnings = true;
20321 test.expectedDeprecations = function () {
20322 test._expectedDeprecations = arguments;
20323 test._observedDeprecations = [];
20324 };
20325 moment$$1.deprecationHandler = function (name, msg) {
20326 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
20327 if (deprecationId === -1) {
20328 throw new Error('Unexpected deprecation thrown name=' +
20329 name + ' msg=' + msg);
20330 }
20331 test._observedDeprecations[deprecationId] = 1;
20332 };
20333 }
20334
20335 function teardownDeprecationHandler(test, moment$$1, scope) {
20336 moment$$1.suppressDeprecationWarnings = test._oldSupress;
20337
20338 if (test._expectedDeprecations != null) {
20339 var missedDeprecations = [];
20340 each(test._expectedDeprecations, function (deprecationPattern, id) {
20341 if (test._observedDeprecations[id] !== 1) {
20342 missedDeprecations.push(deprecationPattern);
20343 }
20344 });
20345 if (missedDeprecations.length !== 0) {
20346 throw new Error('Expected deprecation warnings did not happen: ' +
20347 missedDeprecations.join(' '));
20348 }
20349 }
20350 }
20351
20352 function matchedDeprecation(name, msg, deprecations) {
20353 if (deprecations == null) {
20354 return -1;
20355 }
20356 for (var i = 0; i < deprecations.length; ++i) {
20357 if (name != null && name === deprecations[i]) {
20358 return i;
20359 }
20360 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
20361 return i;
20362 }
20363 }
20364 return -1;
20365 }
20366
20367 /*global QUnit:false*/
20368
20369 var test = QUnit.test;
20370
db71a655
KM
20371 function objectKeys(obj) {
20372 if (Object.keys) {
20373 return Object.keys(obj);
20374 } else {
20375 // IE8
20376 var res = [], i;
20377 for (i in obj) {
20378 if (obj.hasOwnProperty(i)) {
20379 res.push(i);
20380 }
b135bf1a 20381 }
db71a655 20382 return res;
b135bf1a
IC
20383 }
20384 }
20385
db71a655 20386 // Pick the first defined of two or three arguments.
b135bf1a 20387
db71a655
KM
20388 function defineCommonLocaleTests(locale, options) {
20389 test('lenient day of month ordinal parsing', function (assert) {
20390 var i, ordinalStr, testMoment;
20391 for (i = 1; i <= 31; ++i) {
20392 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
20393 testMoment = moment(ordinalStr, 'YYYY MM Do');
20394 assert.equal(testMoment.year(), 2014,
20395 'lenient day of month ordinal parsing ' + i + ' year check');
20396 assert.equal(testMoment.month(), 0,
20397 'lenient day of month ordinal parsing ' + i + ' month check');
20398 assert.equal(testMoment.date(), i,
20399 'lenient day of month ordinal parsing ' + i + ' date check');
20400 }
20401 });
b135bf1a 20402
db71a655
KM
20403 test('lenient day of month ordinal parsing of number', function (assert) {
20404 var i, testMoment;
20405 for (i = 1; i <= 31; ++i) {
20406 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
20407 assert.equal(testMoment.year(), 2014,
20408 'lenient day of month ordinal parsing of number ' + i + ' year check');
20409 assert.equal(testMoment.month(), 0,
20410 'lenient day of month ordinal parsing of number ' + i + ' month check');
20411 assert.equal(testMoment.date(), i,
20412 'lenient day of month ordinal parsing of number ' + i + ' date check');
20413 }
20414 });
b135bf1a 20415
db71a655
KM
20416 test('strict day of month ordinal parsing', function (assert) {
20417 var i, ordinalStr, testMoment;
20418 for (i = 1; i <= 31; ++i) {
20419 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
20420 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
20421 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
20422 }
20423 });
b135bf1a 20424
db71a655
KM
20425 test('meridiem invariant', function (assert) {
20426 var h, m, t1, t2;
20427 for (h = 0; h < 24; ++h) {
20428 for (m = 0; m < 60; m += 15) {
20429 t1 = moment.utc([2000, 0, 1, h, m]);
20430 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
20431 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
20432 'meridiem at ' + t1.format('HH:mm'));
20433 }
20434 }
20435 });
20436
20437 test('date format correctness', function (assert) {
20438 var data, tokens;
20439 data = moment.localeData()._longDateFormat;
20440 tokens = objectKeys(data);
20441 each(tokens, function (srchToken) {
20442 // Check each format string to make sure it does not contain any
20443 // tokens that need to be expanded.
20444 each(tokens, function (baseToken) {
20445 // strip escaped sequences
20446 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
20447 assert.equal(false, !!~format.indexOf(srchToken),
20448 'contains ' + srchToken + ' in ' + baseToken);
20449 });
b135bf1a
IC
20450 });
20451 });
d6651c21 20452
db71a655
KM
20453 test('month parsing correctness', function (assert) {
20454 var i, m;
20455
20456 if (locale === 'tr') {
20457 // I can't fix it :(
c58511b9 20458 assert.expect(0);
db71a655
KM
20459 return;
20460 }
20461 function tester(format) {
20462 var r;
20463 r = moment(m.format(format), format);
20464 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
20465 if (locale !== 'ka') {
20466 r = moment(m.format(format).toLocaleUpperCase(), format);
20467 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
20468 }
db71a655
KM
20469 r = moment(m.format(format).toLocaleLowerCase(), format);
20470 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
20471
20472 r = moment(m.format(format), format, true);
20473 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
20474 if (locale !== 'ka') {
20475 r = moment(m.format(format).toLocaleUpperCase(), format, true);
20476 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
20477 }
db71a655
KM
20478 r = moment(m.format(format).toLocaleLowerCase(), format, true);
20479 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
20480 }
20481
20482 for (i = 0; i < 12; ++i) {
20483 m = moment([2015, i, 15, 18]);
20484 tester('MMM');
20485 tester('MMM.');
20486 tester('MMMM');
20487 tester('MMMM.');
20488 }
20489 });
d6651c21 20490
db71a655
KM
20491 test('weekday parsing correctness', function (assert) {
20492 var i, m;
20493
96d0d679 20494 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
20495 // tr, az: There is a lower-case letter (ı), that converted to
20496 // upper then lower changes to i
20497 // ro: there is the letter ț which behaves weird under IE8
20498 // mt: letter Ħ
96d0d679 20499 // ga: month with spaces
c58511b9 20500 assert.expect(0);
db71a655
KM
20501 return;
20502 }
20503 function tester(format) {
20504 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
20505 r = moment(m.format(format), format);
20506 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
20507 if (locale !== 'ka') {
20508 r = moment(m.format(format).toLocaleUpperCase(), format);
20509 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
20510 }
db71a655
KM
20511 r = moment(m.format(format).toLocaleLowerCase(), format);
20512 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
20513 r = moment(m.format(format), format, true);
20514 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
20515 if (locale !== 'ka') {
20516 r = moment(m.format(format).toLocaleUpperCase(), format, true);
20517 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
20518 }
db71a655
KM
20519 r = moment(m.format(format).toLocaleLowerCase(), format, true);
20520 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
20521 }
20522
20523 for (i = 0; i < 7; ++i) {
20524 m = moment.utc([2015, 0, i + 1, 18]);
20525 tester('dd');
20526 tester('ddd');
20527 tester('dddd');
20528 }
20529 });
d6651c21 20530
db71a655
KM
20531 test('valid localeData', function (assert) {
20532 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
20533 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
20534 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
20535 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
20536 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
20537 });
96d0d679
KM
20538
20539 test('localeData weekdays can localeSort', function (assert) {
20540 var weekdays = moment().localeData().weekdays();
20541 var weekdaysShort = moment().localeData().weekdaysShort();
20542 var weekdaysMin = moment().localeData().weekdaysMin();
20543 var shift = moment().localeData()._week.dow;
20544 assert.deepEqual(
20545 moment().localeData().weekdays(true),
20546 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
20547 'weekdays should localeSort');
20548 assert.deepEqual(
20549 moment().localeData().weekdaysShort(true),
20550 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
20551 'weekdaysShort should localeSort');
20552 assert.deepEqual(
20553 moment().localeData().weekdaysMin(true),
20554 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
20555 'weekdaysMin should localeSort');
20556 });
db71a655 20557 }
d6651c21 20558
db71a655 20559 /*global QUnit:false*/
c74a101d 20560
db71a655
KM
20561 function localeModule (name, lifecycle) {
20562 QUnit.module('locale:' + name, {
c58511b9 20563 beforeEach : function () {
db71a655
KM
20564 moment.locale(name);
20565 moment.createFromInputFallback = function (config) {
20566 throw new Error('input not handled by moment: ' + config._i);
20567 };
20568 setupDeprecationHandler(test, moment, 'locale');
20569 if (lifecycle && lifecycle.setup) {
20570 lifecycle.setup();
20571 }
20572 },
c58511b9 20573 afterEach : function () {
db71a655
KM
20574 moment.locale('en');
20575 teardownDeprecationHandler(test, moment, 'locale');
20576 if (lifecycle && lifecycle.teardown) {
20577 lifecycle.teardown();
20578 }
516f5f67
IC
20579 }
20580 });
db71a655
KM
20581 defineCommonLocaleTests(name, -1, -1);
20582 }
20583
96d0d679 20584 localeModule('fa');
db71a655
KM
20585
20586 test('parse', function (assert) {
96d0d679 20587 var tests = 'ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر'.split('_'), i;
db71a655 20588 function equalTest(input, mmm, i) {
96d0d679 20589 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1) + ' instead is month ' + moment(input, mmm).month());
db71a655
KM
20590 }
20591 for (i = 0; i < 12; i++) {
96d0d679
KM
20592 equalTest(tests[i], 'MMM', i);
20593 equalTest(tests[i], 'MMMM', i);
db71a655
KM
20594 }
20595 });
20596
20597 test('format', function (assert) {
20598 var a = [
96d0d679
KM
20599 ['dddd, MMMM Do YYYY, h:mm:ss a', 'یک\u200cشنبه، فوریه ۱۴م ۲۰۱۰، ۳:۲۵:۵۰ بعد از ظهر'],
20600 ['ddd, hA', 'یک\u200cشنبه، ۳بعد از ظهر'],
20601 ['M Mo MM MMMM MMM', '۲ ۲م ۰۲ فوریه فوریه'],
20602 ['YYYY YY', '۲۰۱۰ ۱۰'],
20603 ['D Do DD', '۱۴ ۱۴م ۱۴'],
20604 ['d do dddd ddd dd', '۰ ۰م یک\u200cشنبه یک\u200cشنبه ی'],
20605 ['DDD DDDo DDDD', '۴۵ ۴۵م ۰۴۵'],
20606 ['w wo ww', '۸ ۸م ۰۸'],
20607 ['h hh', '۳ ۰۳'],
20608 ['H HH', '۱۵ ۱۵'],
20609 ['m mm', '۲۵ ۲۵'],
20610 ['s ss', '۵۰ ۵۰'],
20611 ['a A', 'بعد از ظهر بعد از ظهر'],
20612 ['DDDo [روز سال]', '۴۵م روز سال'],
20613 ['LTS', '۱۵:۲۵:۵۰'],
20614 ['L', '۱۴/۰۲/۲۰۱۰'],
20615 ['LL', '۱۴ فوریه ۲۰۱۰'],
20616 ['LLL', '۱۴ فوریه ۲۰۱۰ ۱۵:۲۵'],
20617 ['LLLL', 'یک\u200cشنبه، ۱۴ فوریه ۲۰۱۰ ۱۵:۲۵'],
20618 ['l', '۱۴/۲/۲۰۱۰'],
20619 ['ll', '۱۴ فوریه ۲۰۱۰'],
20620 ['lll', '۱۴ فوریه ۲۰۱۰ ۱۵:۲۵'],
20621 ['llll', 'یک\u200cشنبه، ۱۴ فوریه ۲۰۱۰ ۱۵:۲۵']
db71a655
KM
20622 ],
20623 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
20624 i;
20625 for (i = 0; i < a.length; i++) {
20626 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
20627 }
20628 });
20629
20630 test('format ordinal', function (assert) {
96d0d679
KM
20631 assert.equal(moment([2011, 0, 1]).format('DDDo'), '۱م', '1');
20632 assert.equal(moment([2011, 0, 2]).format('DDDo'), '۲م', '2');
20633 assert.equal(moment([2011, 0, 3]).format('DDDo'), '۳م', '3');
20634 assert.equal(moment([2011, 0, 4]).format('DDDo'), '۴م', '4');
20635 assert.equal(moment([2011, 0, 5]).format('DDDo'), '۵م', '5');
20636 assert.equal(moment([2011, 0, 6]).format('DDDo'), '۶م', '6');
20637 assert.equal(moment([2011, 0, 7]).format('DDDo'), '۷م', '7');
20638 assert.equal(moment([2011, 0, 8]).format('DDDo'), '۸م', '8');
20639 assert.equal(moment([2011, 0, 9]).format('DDDo'), '۹م', '9');
20640 assert.equal(moment([2011, 0, 10]).format('DDDo'), '۱۰م', '10');
db71a655 20641
96d0d679
KM
20642 assert.equal(moment([2011, 0, 11]).format('DDDo'), '۱۱م', '11');
20643 assert.equal(moment([2011, 0, 12]).format('DDDo'), '۱۲م', '12');
20644 assert.equal(moment([2011, 0, 13]).format('DDDo'), '۱۳م', '13');
20645 assert.equal(moment([2011, 0, 14]).format('DDDo'), '۱۴م', '14');
20646 assert.equal(moment([2011, 0, 15]).format('DDDo'), '۱۵م', '15');
20647 assert.equal(moment([2011, 0, 16]).format('DDDo'), '۱۶م', '16');
20648 assert.equal(moment([2011, 0, 17]).format('DDDo'), '۱۷م', '17');
20649 assert.equal(moment([2011, 0, 18]).format('DDDo'), '۱۸م', '18');
20650 assert.equal(moment([2011, 0, 19]).format('DDDo'), '۱۹م', '19');
20651 assert.equal(moment([2011, 0, 20]).format('DDDo'), '۲۰م', '20');
db71a655 20652
96d0d679
KM
20653 assert.equal(moment([2011, 0, 21]).format('DDDo'), '۲۱م', '21');
20654 assert.equal(moment([2011, 0, 22]).format('DDDo'), '۲۲م', '22');
20655 assert.equal(moment([2011, 0, 23]).format('DDDo'), '۲۳م', '23');
20656 assert.equal(moment([2011, 0, 24]).format('DDDo'), '۲۴م', '24');
20657 assert.equal(moment([2011, 0, 25]).format('DDDo'), '۲۵م', '25');
20658 assert.equal(moment([2011, 0, 26]).format('DDDo'), '۲۶م', '26');
20659 assert.equal(moment([2011, 0, 27]).format('DDDo'), '۲۷م', '27');
20660 assert.equal(moment([2011, 0, 28]).format('DDDo'), '۲۸م', '28');
20661 assert.equal(moment([2011, 0, 29]).format('DDDo'), '۲۹م', '29');
20662 assert.equal(moment([2011, 0, 30]).format('DDDo'), '۳۰م', '30');
db71a655 20663
96d0d679 20664 assert.equal(moment([2011, 0, 31]).format('DDDo'), '۳۱م', '31');
db71a655
KM
20665 });
20666
20667 test('format month', function (assert) {
96d0d679 20668 var expected = 'ژانویه ژانویه_فوریه فوریه_مارس مارس_آوریل آوریل_مه مه_ژوئن ژوئن_ژوئیه ژوئیه_اوت اوت_سپتامبر سپتامبر_اکتبر اکتبر_نوامبر نوامبر_دسامبر دسامبر'.split('_'), i;
db71a655
KM
20669 for (i = 0; i < expected.length; i++) {
20670 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
20671 }
20672 });
20673
20674 test('format week', function (assert) {
96d0d679 20675 var expected = 'یک\u200cشنبه یک\u200cشنبه ی_دوشنبه دوشنبه د_سه\u200cشنبه سه\u200cشنبه س_چهارشنبه چهارشنبه چ_پنج\u200cشنبه پنج\u200cشنبه پ_جمعه جمعه ج_شنبه شنبه ش'.split('_'), i;
db71a655
KM
20676 for (i = 0; i < expected.length; i++) {
20677 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
20678 }
20679 });
20680
20681 test('from', function (assert) {
20682 var start = moment([2007, 1, 28]);
96d0d679
KM
20683 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'چند ثانیه', '44 seconds = a few seconds');
20684 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'یک دقیقه', '45 seconds = a minute');
20685 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'یک دقیقه', '89 seconds = a minute');
20686 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '۲ دقیقه', '90 seconds = 2 minutes');
20687 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '۴۴ دقیقه', '44 minutes = 44 minutes');
20688 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'یک ساعت', '45 minutes = an hour');
20689 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'یک ساعت', '89 minutes = an hour');
20690 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '۲ ساعت', '90 minutes = 2 hours');
20691 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '۵ ساعت', '5 hours = 5 hours');
20692 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '۲۱ ساعت', '21 hours = 21 hours');
20693 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'یک روز', '22 hours = a day');
20694 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'یک روز', '35 hours = a day');
20695 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '۲ روز', '36 hours = 2 days');
20696 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'یک روز', '1 day = a day');
20697 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '۵ روز', '5 days = 5 days');
20698 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '۲۵ روز', '25 days = 25 days');
20699 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'یک ماه', '26 days = a month');
20700 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'یک ماه', '30 days = a month');
20701 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'یک ماه', '43 days = a month');
20702 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '۲ ماه', '46 days = 2 months');
20703 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '۲ ماه', '75 days = 2 months');
20704 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '۳ ماه', '76 days = 3 months');
20705 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'یک ماه', '1 month = a month');
20706 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '۵ ماه', '5 months = 5 months');
20707 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'یک سال', '345 days = a year');
20708 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '۲ سال', '548 days = 2 years');
20709 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'یک سال', '1 year = a year');
20710 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '۵ سال', '5 years = 5 years');
db71a655
KM
20711 });
20712
20713 test('suffix', function (assert) {
96d0d679
KM
20714 assert.equal(moment(30000).from(0), 'در چند ثانیه', 'prefix');
20715 assert.equal(moment(0).from(30000), 'چند ثانیه پیش', 'suffix');
db71a655
KM
20716 });
20717
20718 test('now from now', function (assert) {
96d0d679 20719 assert.equal(moment().fromNow(), 'چند ثانیه پیش', 'now from now should display as in the past');
db71a655
KM
20720 });
20721
20722 test('fromNow', function (assert) {
96d0d679
KM
20723 assert.equal(moment().add({s: 30}).fromNow(), 'در چند ثانیه', 'in a few seconds');
20724 assert.equal(moment().add({d: 5}).fromNow(), 'در ۵ روز', 'in 5 days');
db71a655
KM
20725 });
20726
20727 test('calendar day', function (assert) {
20728 var a = moment().hours(12).minutes(0).seconds(0);
20729
96d0d679
KM
20730 assert.equal(moment(a).calendar(), 'امروز ساعت ۱۲:۰۰', 'today at the same time');
20731 assert.equal(moment(a).add({m: 25}).calendar(), 'امروز ساعت ۱۲:۲۵', 'Now plus 25 min');
20732 assert.equal(moment(a).add({h: 1}).calendar(), 'امروز ساعت ۱۳:۰۰', 'Now plus 1 hour');
20733 assert.equal(moment(a).add({d: 1}).calendar(), 'فردا ساعت ۱۲:۰۰', 'tomorrow at the same time');
20734 assert.equal(moment(a).subtract({h: 1}).calendar(), 'امروز ساعت ۱۱:۰۰', 'Now minus 1 hour');
20735 assert.equal(moment(a).subtract({d: 1}).calendar(), 'دیروز ساعت ۱۲:۰۰', 'yesterday at the same time');
db71a655
KM
20736 });
20737
20738 test('calendar next week', function (assert) {
20739 var i, m;
db71a655
KM
20740 for (i = 2; i < 7; i++) {
20741 m = moment().add({d: i});
96d0d679 20742 assert.equal(m.calendar(), m.format('dddd [ساعت] LT'), 'Today + ' + i + ' days current time');
db71a655 20743 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 20744 assert.equal(m.calendar(), m.format('dddd [ساعت] LT'), 'Today + ' + i + ' days beginning of day');
db71a655 20745 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 20746 assert.equal(m.calendar(), m.format('dddd [ساعت] LT'), 'Today + ' + i + ' days end of day');
516f5f67 20747 }
db71a655
KM
20748 });
20749
20750 test('calendar last week', function (assert) {
20751 var i, m;
20752 for (i = 2; i < 7; i++) {
20753 m = moment().subtract({d: i});
96d0d679 20754 assert.equal(m.calendar(), m.format('dddd [پیش ساعت] LT'), 'Today - ' + i + ' days current time');
db71a655 20755 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 20756 assert.equal(m.calendar(), m.format('dddd [پیش ساعت] LT'), 'Today - ' + i + ' days beginning of day');
db71a655 20757 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 20758 assert.equal(m.calendar(), m.format('dddd [پیش ساعت] LT'), 'Today - ' + i + ' days end of day');
73f3c911 20759 }
db71a655 20760 });
516f5f67 20761
db71a655
KM
20762 test('calendar all else', function (assert) {
20763 var weeksAgo = moment().subtract({w: 1}),
20764 weeksFromNow = moment().add({w: 1});
c74a101d 20765
96d0d679
KM
20766 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
20767 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 20768
db71a655
KM
20769 weeksAgo = moment().subtract({w: 2});
20770 weeksFromNow = moment().add({w: 2});
516f5f67 20771
96d0d679
KM
20772 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
20773 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
db71a655
KM
20774 });
20775
20776 test('weeks year starting sunday formatted', function (assert) {
96d0d679
KM
20777 assert.equal(moment([2011, 11, 31]).format('w ww wo'), '۱ ۰۱ ۱م', 'Dec 31 2011 should be week 1');
20778 assert.equal(moment([2012, 0, 6]).format('w ww wo'), '۱ ۰۱ ۱م', 'Jan 6 2012 should be week 1');
20779 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '۲ ۰۲ ۲م', 'Jan 7 2012 should be week 2');
20780 assert.equal(moment([2012, 0, 13]).format('w ww wo'), '۲ ۰۲ ۲م', 'Jan 13 2012 should be week 2');
20781 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '۳ ۰۳ ۳م', 'Jan 14 2012 should be week 3');
db71a655 20782 });
73f3c911
IC
20783
20784})));
516f5f67 20785
516f5f67 20786
c74a101d
IC
20787;(function (global, factory) {
20788 typeof exports === 'object' && typeof module !== 'undefined'
20789 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
20790 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
20791 factory(global.moment)
73f3c911 20792}(this, (function (moment) { 'use strict';
516f5f67 20793
db71a655
KM
20794 function each(array, callback) {
20795 var i;
20796 for (i = 0; i < array.length; i++) {
20797 callback(array[i], i, array);
20798 }
b135bf1a
IC
20799 }
20800
c58511b9
KM
20801 function setupDeprecationHandler(test, moment$$1, scope) {
20802 test._expectedDeprecations = null;
20803 test._observedDeprecations = null;
20804 test._oldSupress = moment$$1.suppressDeprecationWarnings;
20805 moment$$1.suppressDeprecationWarnings = true;
20806 test.expectedDeprecations = function () {
20807 test._expectedDeprecations = arguments;
20808 test._observedDeprecations = [];
20809 };
20810 moment$$1.deprecationHandler = function (name, msg) {
20811 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
20812 if (deprecationId === -1) {
20813 throw new Error('Unexpected deprecation thrown name=' +
20814 name + ' msg=' + msg);
20815 }
20816 test._observedDeprecations[deprecationId] = 1;
20817 };
20818 }
20819
20820 function teardownDeprecationHandler(test, moment$$1, scope) {
20821 moment$$1.suppressDeprecationWarnings = test._oldSupress;
20822
20823 if (test._expectedDeprecations != null) {
20824 var missedDeprecations = [];
20825 each(test._expectedDeprecations, function (deprecationPattern, id) {
20826 if (test._observedDeprecations[id] !== 1) {
20827 missedDeprecations.push(deprecationPattern);
20828 }
20829 });
20830 if (missedDeprecations.length !== 0) {
20831 throw new Error('Expected deprecation warnings did not happen: ' +
20832 missedDeprecations.join(' '));
20833 }
20834 }
20835 }
20836
20837 function matchedDeprecation(name, msg, deprecations) {
20838 if (deprecations == null) {
20839 return -1;
20840 }
20841 for (var i = 0; i < deprecations.length; ++i) {
20842 if (name != null && name === deprecations[i]) {
20843 return i;
20844 }
20845 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
20846 return i;
20847 }
20848 }
20849 return -1;
20850 }
20851
20852 /*global QUnit:false*/
20853
20854 var test = QUnit.test;
20855
db71a655
KM
20856 function objectKeys(obj) {
20857 if (Object.keys) {
20858 return Object.keys(obj);
20859 } else {
20860 // IE8
20861 var res = [], i;
20862 for (i in obj) {
20863 if (obj.hasOwnProperty(i)) {
20864 res.push(i);
20865 }
b135bf1a 20866 }
db71a655 20867 return res;
b135bf1a 20868 }
b135bf1a
IC
20869 }
20870
db71a655 20871 // Pick the first defined of two or three arguments.
b135bf1a 20872
db71a655
KM
20873 function defineCommonLocaleTests(locale, options) {
20874 test('lenient day of month ordinal parsing', function (assert) {
20875 var i, ordinalStr, testMoment;
20876 for (i = 1; i <= 31; ++i) {
20877 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
20878 testMoment = moment(ordinalStr, 'YYYY MM Do');
20879 assert.equal(testMoment.year(), 2014,
20880 'lenient day of month ordinal parsing ' + i + ' year check');
20881 assert.equal(testMoment.month(), 0,
20882 'lenient day of month ordinal parsing ' + i + ' month check');
20883 assert.equal(testMoment.date(), i,
20884 'lenient day of month ordinal parsing ' + i + ' date check');
20885 }
20886 });
b135bf1a 20887
db71a655
KM
20888 test('lenient day of month ordinal parsing of number', function (assert) {
20889 var i, testMoment;
20890 for (i = 1; i <= 31; ++i) {
20891 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
20892 assert.equal(testMoment.year(), 2014,
20893 'lenient day of month ordinal parsing of number ' + i + ' year check');
20894 assert.equal(testMoment.month(), 0,
20895 'lenient day of month ordinal parsing of number ' + i + ' month check');
20896 assert.equal(testMoment.date(), i,
20897 'lenient day of month ordinal parsing of number ' + i + ' date check');
20898 }
20899 });
b135bf1a 20900
db71a655
KM
20901 test('strict day of month ordinal parsing', function (assert) {
20902 var i, ordinalStr, testMoment;
20903 for (i = 1; i <= 31; ++i) {
20904 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
20905 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
20906 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
20907 }
20908 });
d6651c21 20909
db71a655
KM
20910 test('meridiem invariant', function (assert) {
20911 var h, m, t1, t2;
20912 for (h = 0; h < 24; ++h) {
20913 for (m = 0; m < 60; m += 15) {
20914 t1 = moment.utc([2000, 0, 1, h, m]);
20915 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
20916 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
20917 'meridiem at ' + t1.format('HH:mm'));
20918 }
20919 }
20920 });
20921
20922 test('date format correctness', function (assert) {
20923 var data, tokens;
20924 data = moment.localeData()._longDateFormat;
20925 tokens = objectKeys(data);
20926 each(tokens, function (srchToken) {
20927 // Check each format string to make sure it does not contain any
20928 // tokens that need to be expanded.
20929 each(tokens, function (baseToken) {
20930 // strip escaped sequences
20931 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
20932 assert.equal(false, !!~format.indexOf(srchToken),
20933 'contains ' + srchToken + ' in ' + baseToken);
20934 });
73f3c911 20935 });
d6651c21
IC
20936 });
20937
db71a655
KM
20938 test('month parsing correctness', function (assert) {
20939 var i, m;
20940
20941 if (locale === 'tr') {
20942 // I can't fix it :(
c58511b9 20943 assert.expect(0);
db71a655
KM
20944 return;
20945 }
20946 function tester(format) {
20947 var r;
20948 r = moment(m.format(format), format);
20949 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
20950 if (locale !== 'ka') {
20951 r = moment(m.format(format).toLocaleUpperCase(), format);
20952 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
20953 }
db71a655
KM
20954 r = moment(m.format(format).toLocaleLowerCase(), format);
20955 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
20956
20957 r = moment(m.format(format), format, true);
20958 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
20959 if (locale !== 'ka') {
20960 r = moment(m.format(format).toLocaleUpperCase(), format, true);
20961 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
20962 }
db71a655
KM
20963 r = moment(m.format(format).toLocaleLowerCase(), format, true);
20964 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
20965 }
20966
20967 for (i = 0; i < 12; ++i) {
20968 m = moment([2015, i, 15, 18]);
20969 tester('MMM');
20970 tester('MMM.');
20971 tester('MMMM');
20972 tester('MMMM.');
20973 }
20974 });
d6651c21 20975
db71a655
KM
20976 test('weekday parsing correctness', function (assert) {
20977 var i, m;
20978
96d0d679 20979 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
20980 // tr, az: There is a lower-case letter (ı), that converted to
20981 // upper then lower changes to i
20982 // ro: there is the letter ț which behaves weird under IE8
20983 // mt: letter Ħ
96d0d679 20984 // ga: month with spaces
c58511b9 20985 assert.expect(0);
db71a655
KM
20986 return;
20987 }
20988 function tester(format) {
20989 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
20990 r = moment(m.format(format), format);
20991 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
20992 if (locale !== 'ka') {
20993 r = moment(m.format(format).toLocaleUpperCase(), format);
20994 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
20995 }
db71a655
KM
20996 r = moment(m.format(format).toLocaleLowerCase(), format);
20997 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
20998 r = moment(m.format(format), format, true);
20999 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
21000 if (locale !== 'ka') {
21001 r = moment(m.format(format).toLocaleUpperCase(), format, true);
21002 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
21003 }
db71a655
KM
21004 r = moment(m.format(format).toLocaleLowerCase(), format, true);
21005 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
21006 }
21007
21008 for (i = 0; i < 7; ++i) {
21009 m = moment.utc([2015, 0, i + 1, 18]);
21010 tester('dd');
21011 tester('ddd');
21012 tester('dddd');
21013 }
21014 });
d6651c21 21015
db71a655
KM
21016 test('valid localeData', function (assert) {
21017 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
21018 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
21019 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
21020 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
21021 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
21022 });
96d0d679
KM
21023
21024 test('localeData weekdays can localeSort', function (assert) {
21025 var weekdays = moment().localeData().weekdays();
21026 var weekdaysShort = moment().localeData().weekdaysShort();
21027 var weekdaysMin = moment().localeData().weekdaysMin();
21028 var shift = moment().localeData()._week.dow;
21029 assert.deepEqual(
21030 moment().localeData().weekdays(true),
21031 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
21032 'weekdays should localeSort');
21033 assert.deepEqual(
21034 moment().localeData().weekdaysShort(true),
21035 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
21036 'weekdaysShort should localeSort');
21037 assert.deepEqual(
21038 moment().localeData().weekdaysMin(true),
21039 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
21040 'weekdaysMin should localeSort');
21041 });
db71a655 21042 }
d6651c21 21043
db71a655 21044 /*global QUnit:false*/
c74a101d 21045
db71a655
KM
21046 function localeModule (name, lifecycle) {
21047 QUnit.module('locale:' + name, {
c58511b9 21048 beforeEach : function () {
db71a655
KM
21049 moment.locale(name);
21050 moment.createFromInputFallback = function (config) {
21051 throw new Error('input not handled by moment: ' + config._i);
21052 };
21053 setupDeprecationHandler(test, moment, 'locale');
21054 if (lifecycle && lifecycle.setup) {
21055 lifecycle.setup();
21056 }
21057 },
c58511b9 21058 afterEach : function () {
db71a655
KM
21059 moment.locale('en');
21060 teardownDeprecationHandler(test, moment, 'locale');
21061 if (lifecycle && lifecycle.teardown) {
21062 lifecycle.teardown();
21063 }
516f5f67
IC
21064 }
21065 });
db71a655
KM
21066 defineCommonLocaleTests(name, -1, -1);
21067 }
21068
96d0d679 21069 localeModule('fi');
db71a655
KM
21070
21071 test('parse', function (assert) {
96d0d679 21072 var tests = 'tammikuu tammi_helmikuu helmi_maaliskuu maalis_huhtikuu huhti_toukokuu touko_kesäkuu kesä_heinäkuu heinä_elokuu elo_syyskuu syys_lokakuu loka_marraskuu marras_joulukuu joulu'.split('_'), i;
db71a655
KM
21073 function equalTest(input, mmm, i) {
21074 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
21075 }
21076 for (i = 0; i < 12; i++) {
21077 tests[i] = tests[i].split(' ');
21078 equalTest(tests[i][0], 'MMM', i);
21079 equalTest(tests[i][1], 'MMM', i);
21080 equalTest(tests[i][0], 'MMMM', i);
21081 equalTest(tests[i][1], 'MMMM', i);
21082 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
21083 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
21084 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
21085 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
21086 }
21087 });
21088
21089 test('format', function (assert) {
21090 var a = [
96d0d679
KM
21091 ['dddd, MMMM Do YYYY, h:mm:ss a', 'sunnuntai, helmikuu 14. 2010, 3:25:50 pm'],
21092 ['ddd, hA', 'su, 3PM'],
21093 ['M Mo MM MMMM MMM', '2 2. 02 helmikuu helmi'],
db71a655
KM
21094 ['YYYY YY', '2010 10'],
21095 ['D Do DD', '14 14. 14'],
96d0d679 21096 ['d do dddd ddd dd', '0 0. sunnuntai su su'],
db71a655
KM
21097 ['DDD DDDo DDDD', '45 45. 045'],
21098 ['w wo ww', '6 6. 06'],
21099 ['h hh', '3 03'],
21100 ['H HH', '15 15'],
21101 ['m mm', '25 25'],
21102 ['s ss', '50 50'],
21103 ['a A', 'pm PM'],
96d0d679
KM
21104 ['[vuoden] DDDo [päivä]', 'vuoden 45. päivä'],
21105 ['LTS', '15.25.50'],
21106 ['L', '14.02.2010'],
21107 ['LL', '14. helmikuuta 2010'],
21108 ['LLL', '14. helmikuuta 2010, klo 15.25'],
21109 ['LLLL', 'sunnuntai, 14. helmikuuta 2010, klo 15.25'],
21110 ['l', '14.2.2010'],
21111 ['ll', '14. helmi 2010'],
21112 ['lll', '14. helmi 2010, klo 15.25'],
21113 ['llll', 'su, 14. helmi 2010, klo 15.25']
db71a655
KM
21114 ],
21115 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
21116 i;
21117 for (i = 0; i < a.length; i++) {
21118 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
21119 }
21120 });
21121
21122 test('format ordinal', function (assert) {
96d0d679
KM
21123 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1st');
21124 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2nd');
21125 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3rd');
21126 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4th');
21127 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5th');
21128 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6th');
21129 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7th');
21130 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8th');
21131 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9th');
21132 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10th');
db71a655 21133
96d0d679
KM
21134 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11th');
21135 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12th');
21136 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13th');
21137 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14th');
21138 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15th');
21139 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16th');
21140 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17th');
21141 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18th');
21142 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19th');
21143 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20th');
db71a655 21144
96d0d679
KM
21145 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21st');
21146 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22nd');
21147 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23rd');
21148 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24th');
21149 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25th');
21150 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26th');
21151 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27th');
21152 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28th');
21153 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29th');
21154 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30th');
db71a655 21155
96d0d679 21156 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31st');
db71a655
KM
21157 });
21158
21159 test('format month', function (assert) {
96d0d679 21160 var expected = 'tammikuu tammi_helmikuu helmi_maaliskuu maalis_huhtikuu huhti_toukokuu touko_kesäkuu kesä_heinäkuu heinä_elokuu elo_syyskuu syys_lokakuu loka_marraskuu marras_joulukuu joulu'.split('_'), i;
db71a655
KM
21161 for (i = 0; i < expected.length; i++) {
21162 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
21163 }
21164 });
21165
21166 test('format week', function (assert) {
96d0d679 21167 var expected = 'sunnuntai su su_maanantai ma ma_tiistai ti ti_keskiviikko ke ke_torstai to to_perjantai pe pe_lauantai la la'.split('_'), i;
db71a655
KM
21168 for (i = 0; i < expected.length; i++) {
21169 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
21170 }
21171 });
21172
21173 test('from', function (assert) {
21174 var start = moment([2007, 1, 28]);
96d0d679
KM
21175 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'muutama sekunti', '44 seconds = few seconds');
21176 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minuutti', '45 seconds = a minute');
21177 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minuutti', '89 seconds = a minute');
21178 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), 'kaksi minuuttia', '90 seconds = 2 minutes');
21179 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuuttia', '44 minutes = 44 minutes');
21180 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'tunti', '45 minutes = an hour');
21181 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'tunti', '89 minutes = an hour');
21182 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), 'kaksi tuntia', '90 minutes = 2 hours');
21183 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), 'viisi tuntia', '5 hours = 5 hours');
21184 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 tuntia', '21 hours = 21 hours');
21185 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'päivä', '22 hours = a day');
21186 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'päivä', '35 hours = a day');
21187 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), 'kaksi päivää', '36 hours = 2 days');
21188 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'päivä', '1 day = a day');
21189 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), 'viisi päivää', '5 days = 5 days');
21190 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 päivää', '25 days = 25 days');
21191 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'kuukausi', '26 days = a month');
21192 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'kuukausi', '30 days = a month');
21193 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'kuukausi', '43 days = a month');
21194 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), 'kaksi kuukautta', '46 days = 2 months');
21195 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), 'kaksi kuukautta', '75 days = 2 months');
21196 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), 'kolme kuukautta', '76 days = 3 months');
21197 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'kuukausi', '1 month = a month');
21198 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), 'viisi kuukautta', '5 months = 5 months');
21199 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'vuosi', '345 days = a year');
21200 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), 'kaksi vuotta', '548 days = 2 years');
21201 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'vuosi', '1 year = a year');
21202 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), 'viisi vuotta', '5 years = 5 years');
db71a655
KM
21203 });
21204
21205 test('suffix', function (assert) {
96d0d679
KM
21206 assert.equal(moment(30000).from(0), 'muutaman sekunnin päästä', 'prefix');
21207 assert.equal(moment(0).from(30000), 'muutama sekunti sitten', 'suffix');
db71a655
KM
21208 });
21209
21210 test('now from now', function (assert) {
96d0d679 21211 assert.equal(moment().fromNow(), 'muutama sekunti sitten', 'now from now should display as in the past');
db71a655
KM
21212 });
21213
21214 test('fromNow', function (assert) {
96d0d679
KM
21215 assert.equal(moment().add({s: 30}).fromNow(), 'muutaman sekunnin päästä', 'in a few seconds');
21216 assert.equal(moment().add({d: 5}).fromNow(), 'viiden päivän päästä', 'in 5 days');
db71a655
KM
21217 });
21218
db71a655
KM
21219 test('calendar day', function (assert) {
21220 var a = moment().hours(12).minutes(0).seconds(0);
21221
96d0d679
KM
21222 assert.equal(moment(a).calendar(), 'tänään klo 12.00', 'today at the same time');
21223 assert.equal(moment(a).add({m: 25}).calendar(), 'tänään klo 12.25', 'Now plus 25 min');
21224 assert.equal(moment(a).add({h: 1}).calendar(), 'tänään klo 13.00', 'Now plus 1 hour');
21225 assert.equal(moment(a).add({d: 1}).calendar(), 'huomenna klo 12.00', 'tomorrow at the same time');
21226 assert.equal(moment(a).subtract({h: 1}).calendar(), 'tänään klo 11.00', 'Now minus 1 hour');
21227 assert.equal(moment(a).subtract({d: 1}).calendar(), 'eilen klo 12.00', 'yesterday at the same time');
db71a655
KM
21228 });
21229
21230 test('calendar next week', function (assert) {
21231 var i, m;
516f5f67 21232
db71a655
KM
21233 for (i = 2; i < 7; i++) {
21234 m = moment().add({d: i});
96d0d679 21235 assert.equal(m.calendar(), m.format('dddd [klo] LT'), 'today + ' + i + ' days current time');
db71a655 21236 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 21237 assert.equal(m.calendar(), m.format('dddd [klo] LT'), 'today + ' + i + ' days beginning of day');
db71a655 21238 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 21239 assert.equal(m.calendar(), m.format('dddd [klo] LT'), 'today + ' + i + ' days end of day');
516f5f67 21240 }
db71a655
KM
21241 });
21242
21243 test('calendar last week', function (assert) {
21244 var i, m;
21245 for (i = 2; i < 7; i++) {
21246 m = moment().subtract({d: i});
96d0d679 21247 assert.equal(m.calendar(), m.format('[viime] dddd[na] [klo] LT'), 'today - ' + i + ' days current time');
db71a655 21248 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 21249 assert.equal(m.calendar(), m.format('[viime] dddd[na] [klo] LT'), 'today - ' + i + ' days beginning of day');
db71a655 21250 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 21251 assert.equal(m.calendar(), m.format('[viime] dddd[na] [klo] LT'), 'today - ' + i + ' days end of day');
73f3c911 21252 }
db71a655 21253 });
516f5f67 21254
db71a655
KM
21255 test('calendar all else', function (assert) {
21256 var weeksAgo = moment().subtract({w: 1}),
21257 weeksFromNow = moment().add({w: 1});
c74a101d 21258
db71a655
KM
21259 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), 'yksi viikko sitten');
21260 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'yhden viikon päästä');
516f5f67 21261
db71a655
KM
21262 weeksAgo = moment().subtract({w: 2});
21263 weeksFromNow = moment().add({w: 2});
516f5f67 21264
db71a655
KM
21265 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), 'kaksi viikkoa sitten');
21266 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'kaden viikon päästä');
21267 });
21268
21269 test('weeks year starting sunday formatted', function (assert) {
21270 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
21271 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
21272 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
21273 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
21274 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
21275 });
73f3c911
IC
21276
21277})));
516f5f67 21278
516f5f67 21279
c74a101d
IC
21280;(function (global, factory) {
21281 typeof exports === 'object' && typeof module !== 'undefined'
21282 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
21283 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
21284 factory(global.moment)
73f3c911 21285}(this, (function (moment) { 'use strict';
516f5f67 21286
db71a655
KM
21287 function each(array, callback) {
21288 var i;
21289 for (i = 0; i < array.length; i++) {
21290 callback(array[i], i, array);
21291 }
b135bf1a
IC
21292 }
21293
c58511b9
KM
21294 function setupDeprecationHandler(test, moment$$1, scope) {
21295 test._expectedDeprecations = null;
21296 test._observedDeprecations = null;
21297 test._oldSupress = moment$$1.suppressDeprecationWarnings;
21298 moment$$1.suppressDeprecationWarnings = true;
21299 test.expectedDeprecations = function () {
21300 test._expectedDeprecations = arguments;
21301 test._observedDeprecations = [];
21302 };
21303 moment$$1.deprecationHandler = function (name, msg) {
21304 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
21305 if (deprecationId === -1) {
21306 throw new Error('Unexpected deprecation thrown name=' +
21307 name + ' msg=' + msg);
21308 }
21309 test._observedDeprecations[deprecationId] = 1;
21310 };
21311 }
21312
21313 function teardownDeprecationHandler(test, moment$$1, scope) {
21314 moment$$1.suppressDeprecationWarnings = test._oldSupress;
21315
21316 if (test._expectedDeprecations != null) {
21317 var missedDeprecations = [];
21318 each(test._expectedDeprecations, function (deprecationPattern, id) {
21319 if (test._observedDeprecations[id] !== 1) {
21320 missedDeprecations.push(deprecationPattern);
21321 }
21322 });
21323 if (missedDeprecations.length !== 0) {
21324 throw new Error('Expected deprecation warnings did not happen: ' +
21325 missedDeprecations.join(' '));
21326 }
21327 }
21328 }
21329
21330 function matchedDeprecation(name, msg, deprecations) {
21331 if (deprecations == null) {
21332 return -1;
21333 }
21334 for (var i = 0; i < deprecations.length; ++i) {
21335 if (name != null && name === deprecations[i]) {
21336 return i;
21337 }
21338 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
21339 return i;
21340 }
21341 }
21342 return -1;
21343 }
21344
21345 /*global QUnit:false*/
21346
21347 var test = QUnit.test;
21348
db71a655
KM
21349 function objectKeys(obj) {
21350 if (Object.keys) {
21351 return Object.keys(obj);
21352 } else {
21353 // IE8
21354 var res = [], i;
21355 for (i in obj) {
21356 if (obj.hasOwnProperty(i)) {
21357 res.push(i);
21358 }
b135bf1a 21359 }
db71a655 21360 return res;
b135bf1a
IC
21361 }
21362 }
21363
db71a655 21364 // Pick the first defined of two or three arguments.
b135bf1a 21365
db71a655
KM
21366 function defineCommonLocaleTests(locale, options) {
21367 test('lenient day of month ordinal parsing', function (assert) {
21368 var i, ordinalStr, testMoment;
21369 for (i = 1; i <= 31; ++i) {
21370 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
21371 testMoment = moment(ordinalStr, 'YYYY MM Do');
21372 assert.equal(testMoment.year(), 2014,
21373 'lenient day of month ordinal parsing ' + i + ' year check');
21374 assert.equal(testMoment.month(), 0,
21375 'lenient day of month ordinal parsing ' + i + ' month check');
21376 assert.equal(testMoment.date(), i,
21377 'lenient day of month ordinal parsing ' + i + ' date check');
21378 }
21379 });
b135bf1a 21380
db71a655
KM
21381 test('lenient day of month ordinal parsing of number', function (assert) {
21382 var i, testMoment;
21383 for (i = 1; i <= 31; ++i) {
21384 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
21385 assert.equal(testMoment.year(), 2014,
21386 'lenient day of month ordinal parsing of number ' + i + ' year check');
21387 assert.equal(testMoment.month(), 0,
21388 'lenient day of month ordinal parsing of number ' + i + ' month check');
21389 assert.equal(testMoment.date(), i,
21390 'lenient day of month ordinal parsing of number ' + i + ' date check');
21391 }
21392 });
b135bf1a 21393
db71a655
KM
21394 test('strict day of month ordinal parsing', function (assert) {
21395 var i, ordinalStr, testMoment;
21396 for (i = 1; i <= 31; ++i) {
21397 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
21398 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
21399 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
21400 }
21401 });
b135bf1a 21402
db71a655
KM
21403 test('meridiem invariant', function (assert) {
21404 var h, m, t1, t2;
21405 for (h = 0; h < 24; ++h) {
21406 for (m = 0; m < 60; m += 15) {
21407 t1 = moment.utc([2000, 0, 1, h, m]);
21408 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
21409 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
21410 'meridiem at ' + t1.format('HH:mm'));
21411 }
21412 }
21413 });
21414
21415 test('date format correctness', function (assert) {
21416 var data, tokens;
21417 data = moment.localeData()._longDateFormat;
21418 tokens = objectKeys(data);
21419 each(tokens, function (srchToken) {
21420 // Check each format string to make sure it does not contain any
21421 // tokens that need to be expanded.
21422 each(tokens, function (baseToken) {
21423 // strip escaped sequences
21424 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
21425 assert.equal(false, !!~format.indexOf(srchToken),
21426 'contains ' + srchToken + ' in ' + baseToken);
21427 });
b135bf1a
IC
21428 });
21429 });
d6651c21 21430
db71a655
KM
21431 test('month parsing correctness', function (assert) {
21432 var i, m;
21433
21434 if (locale === 'tr') {
21435 // I can't fix it :(
c58511b9 21436 assert.expect(0);
db71a655
KM
21437 return;
21438 }
21439 function tester(format) {
21440 var r;
21441 r = moment(m.format(format), format);
21442 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
21443 if (locale !== 'ka') {
21444 r = moment(m.format(format).toLocaleUpperCase(), format);
21445 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
21446 }
db71a655
KM
21447 r = moment(m.format(format).toLocaleLowerCase(), format);
21448 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
21449
21450 r = moment(m.format(format), format, true);
21451 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
21452 if (locale !== 'ka') {
21453 r = moment(m.format(format).toLocaleUpperCase(), format, true);
21454 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
21455 }
db71a655
KM
21456 r = moment(m.format(format).toLocaleLowerCase(), format, true);
21457 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
21458 }
21459
21460 for (i = 0; i < 12; ++i) {
21461 m = moment([2015, i, 15, 18]);
21462 tester('MMM');
21463 tester('MMM.');
21464 tester('MMMM');
21465 tester('MMMM.');
21466 }
21467 });
d6651c21 21468
db71a655
KM
21469 test('weekday parsing correctness', function (assert) {
21470 var i, m;
21471
96d0d679 21472 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
21473 // tr, az: There is a lower-case letter (ı), that converted to
21474 // upper then lower changes to i
21475 // ro: there is the letter ț which behaves weird under IE8
21476 // mt: letter Ħ
96d0d679 21477 // ga: month with spaces
c58511b9 21478 assert.expect(0);
db71a655
KM
21479 return;
21480 }
21481 function tester(format) {
21482 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
21483 r = moment(m.format(format), format);
21484 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
21485 if (locale !== 'ka') {
21486 r = moment(m.format(format).toLocaleUpperCase(), format);
21487 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
21488 }
db71a655
KM
21489 r = moment(m.format(format).toLocaleLowerCase(), format);
21490 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
21491 r = moment(m.format(format), format, true);
21492 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
21493 if (locale !== 'ka') {
21494 r = moment(m.format(format).toLocaleUpperCase(), format, true);
21495 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
21496 }
db71a655
KM
21497 r = moment(m.format(format).toLocaleLowerCase(), format, true);
21498 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
21499 }
21500
21501 for (i = 0; i < 7; ++i) {
21502 m = moment.utc([2015, 0, i + 1, 18]);
21503 tester('dd');
21504 tester('ddd');
21505 tester('dddd');
21506 }
21507 });
d6651c21 21508
db71a655
KM
21509 test('valid localeData', function (assert) {
21510 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
21511 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
21512 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
21513 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
21514 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
21515 });
96d0d679
KM
21516
21517 test('localeData weekdays can localeSort', function (assert) {
21518 var weekdays = moment().localeData().weekdays();
21519 var weekdaysShort = moment().localeData().weekdaysShort();
21520 var weekdaysMin = moment().localeData().weekdaysMin();
21521 var shift = moment().localeData()._week.dow;
21522 assert.deepEqual(
21523 moment().localeData().weekdays(true),
21524 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
21525 'weekdays should localeSort');
21526 assert.deepEqual(
21527 moment().localeData().weekdaysShort(true),
21528 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
21529 'weekdaysShort should localeSort');
21530 assert.deepEqual(
21531 moment().localeData().weekdaysMin(true),
21532 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
21533 'weekdaysMin should localeSort');
21534 });
db71a655 21535 }
d6651c21 21536
db71a655 21537 /*global QUnit:false*/
c74a101d 21538
db71a655
KM
21539 function localeModule (name, lifecycle) {
21540 QUnit.module('locale:' + name, {
c58511b9 21541 beforeEach : function () {
db71a655
KM
21542 moment.locale(name);
21543 moment.createFromInputFallback = function (config) {
21544 throw new Error('input not handled by moment: ' + config._i);
21545 };
21546 setupDeprecationHandler(test, moment, 'locale');
21547 if (lifecycle && lifecycle.setup) {
21548 lifecycle.setup();
21549 }
21550 },
c58511b9 21551 afterEach : function () {
db71a655
KM
21552 moment.locale('en');
21553 teardownDeprecationHandler(test, moment, 'locale');
21554 if (lifecycle && lifecycle.teardown) {
21555 lifecycle.teardown();
21556 }
516f5f67
IC
21557 }
21558 });
db71a655
KM
21559 defineCommonLocaleTests(name, -1, -1);
21560 }
21561
96d0d679 21562 localeModule('fo');
db71a655
KM
21563
21564 test('parse', function (assert) {
96d0d679 21565 var tests = 'januar jan_februar feb_mars mar_apríl apr_mai mai_juni jun_juli jul_august aug_september sep_oktober okt_november nov_desember des'.split('_'), i;
db71a655
KM
21566 function equalTest(input, mmm, i) {
21567 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
21568 }
db71a655
KM
21569 for (i = 0; i < 12; i++) {
21570 tests[i] = tests[i].split(' ');
21571 equalTest(tests[i][0], 'MMM', i);
21572 equalTest(tests[i][1], 'MMM', i);
21573 equalTest(tests[i][0], 'MMMM', i);
21574 equalTest(tests[i][1], 'MMMM', i);
21575 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
21576 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
21577 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
21578 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
21579 }
21580 });
21581
21582 test('format', function (assert) {
21583 var a = [
96d0d679
KM
21584 ['dddd [tann] Do MMMM YYYY, h:mm:ss a', 'sunnudagur tann 14. februar 2010, 3:25:50 pm'],
21585 ['ddd hA', 'sun 3PM'],
21586 ['M Mo MM MMMM MMM', '2 2. 02 februar feb'],
21587 ['YYYY YY', '2010 10'],
21588 ['D Do DD', '14 14. 14'],
21589 ['d do dddd ddd dd', '0 0. sunnudagur sun su'],
21590 ['DDD DDDo DDDD', '45 45. 045'],
21591 ['w wo ww', '6 6. 06'],
21592 ['h hh', '3 03'],
21593 ['H HH', '15 15'],
21594 ['m mm', '25 25'],
21595 ['s ss', '50 50'],
21596 ['a A', 'pm PM'],
21597 ['[tann] DDDo [dagin á árinum]', 'tann 45. dagin á árinum'],
21598 ['LTS', '15:25:50'],
21599 ['L', '14/02/2010'],
21600 ['LL', '14 februar 2010'],
21601 ['LLL', '14 februar 2010 15:25'],
21602 ['LLLL', 'sunnudagur 14. februar, 2010 15:25'],
21603 ['l', '14/2/2010'],
21604 ['ll', '14 feb 2010'],
21605 ['lll', '14 feb 2010 15:25'],
21606 ['llll', 'sun 14. feb, 2010 15:25']
db71a655
KM
21607 ],
21608 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
21609 i;
db71a655
KM
21610 for (i = 0; i < a.length; i++) {
21611 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
21612 }
21613 });
21614
21615 test('format ordinal', function (assert) {
96d0d679
KM
21616 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
21617 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
21618 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
21619 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
21620 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
21621 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
21622 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
21623 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
21624 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
21625 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
db71a655 21626
96d0d679
KM
21627 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
21628 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
21629 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
21630 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
21631 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
21632 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
21633 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
21634 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
21635 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
21636 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
db71a655 21637
96d0d679
KM
21638 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
21639 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
21640 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
21641 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
21642 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
21643 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
21644 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
21645 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
21646 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
21647 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
db71a655 21648
96d0d679 21649 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
db71a655
KM
21650 });
21651
21652 test('format month', function (assert) {
96d0d679 21653 var expected = 'januar jan_februar feb_mars mar_apríl apr_mai mai_juni jun_juli jul_august aug_september sep_oktober okt_november nov_desember des'.split('_'), i;
db71a655
KM
21654 for (i = 0; i < expected.length; i++) {
21655 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
21656 }
21657 });
21658
21659 test('format week', function (assert) {
96d0d679 21660 var expected = 'sunnudagur sun su_mánadagur mán má_týsdagur týs tý_mikudagur mik mi_hósdagur hós hó_fríggjadagur frí fr_leygardagur ley le'.split('_'), i;
db71a655
KM
21661 for (i = 0; i < expected.length; i++) {
21662 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
21663 }
21664 });
21665
21666 test('from', function (assert) {
21667 var start = moment([2007, 1, 28]);
96d0d679
KM
21668 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'fá sekund', '44 seconds = a few seconds');
21669 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ein minuttur', '45 seconds = a minute');
21670 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ein minuttur', '89 seconds = a minute');
21671 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuttir', '90 seconds = 2 minutes');
21672 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuttir', '44 minutes = 44 minutes');
21673 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ein tími', '45 minutes = an hour');
21674 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ein tími', '89 minutes = an hour');
21675 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 tímar', '90 minutes = 2 hours');
21676 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 tímar', '5 hours = 5 hours');
21677 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 tímar', '21 hours = 21 hours');
21678 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ein dagur', '22 hours = a day');
21679 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ein dagur', '35 hours = a day');
21680 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dagar', '36 hours = 2 days');
21681 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ein dagur', '1 day = a day');
21682 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dagar', '5 days = 5 days');
21683 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dagar', '25 days = 25 days');
21684 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ein mánaður', '26 days = a month');
21685 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ein mánaður', '30 days = a month');
21686 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ein mánaður', '43 days = a month');
21687 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mánaðir', '46 days = 2 months');
21688 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mánaðir', '75 days = 2 months');
21689 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mánaðir', '76 days = 3 months');
21690 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ein mánaður', '1 month = a month');
21691 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mánaðir', '5 months = 5 months');
21692 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'eitt ár', '345 days = a year');
21693 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ár', '548 days = 2 years');
21694 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'eitt ár', '1 year = a year');
21695 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ár', '5 years = 5 years');
db71a655
KM
21696 });
21697
21698 test('suffix', function (assert) {
96d0d679
KM
21699 assert.equal(moment(30000).from(0), 'um fá sekund', 'prefix');
21700 assert.equal(moment(0).from(30000), 'fá sekund síðani', 'suffix');
21701 });
21702
21703 test('now from now', function (assert) {
21704 assert.equal(moment().fromNow(), 'fá sekund síðani', 'now from now should display as in the past');
db71a655
KM
21705 });
21706
21707 test('fromNow', function (assert) {
96d0d679
KM
21708 assert.equal(moment().add({s: 30}).fromNow(), 'um fá sekund', 'in a few seconds');
21709 assert.equal(moment().add({d: 5}).fromNow(), 'um 5 dagar', 'in 5 days');
db71a655
KM
21710 });
21711
96d0d679
KM
21712
21713 test('calendar day', function (assert) {
db71a655
KM
21714 var a = moment().hours(12).minutes(0).seconds(0);
21715
96d0d679
KM
21716 assert.equal(moment(a).calendar(), 'Í dag kl. 12:00', 'today at the same time');
21717 assert.equal(moment(a).add({m: 25}).calendar(), 'Í dag kl. 12:25', 'Now plus 25 min');
21718 assert.equal(moment(a).add({h: 1}).calendar(), 'Í dag kl. 13:00', 'Now plus 1 hour');
21719 assert.equal(moment(a).add({d: 1}).calendar(), 'Í morgin kl. 12:00', 'tomorrow at the same time');
21720 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Í dag kl. 11:00', 'Now minus 1 hour');
21721 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Í gjár kl. 12:00', 'yesterday at the same time');
db71a655
KM
21722 });
21723
96d0d679 21724 test('calendar next week', function (assert) {
db71a655 21725 var i, m;
516f5f67 21726
db71a655
KM
21727 for (i = 2; i < 7; i++) {
21728 m = moment().add({d: i});
96d0d679 21729 assert.equal(m.calendar(), m.format('dddd [kl.] LT'), 'today + ' + i + ' days current time');
db71a655 21730 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 21731 assert.equal(m.calendar(), m.format('dddd [kl.] LT'), 'today + ' + i + ' days beginning of day');
db71a655 21732 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 21733 assert.equal(m.calendar(), m.format('dddd [kl.] LT'), 'today + ' + i + ' days end of day');
516f5f67 21734 }
db71a655
KM
21735 });
21736
96d0d679 21737 test('calendar last week', function (assert) {
db71a655 21738 var i, m;
db71a655
KM
21739 for (i = 2; i < 7; i++) {
21740 m = moment().subtract({d: i});
96d0d679 21741 assert.equal(m.calendar(), m.format('[síðstu] dddd [kl] LT'), 'today - ' + i + ' days current time');
db71a655 21742 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 21743 assert.equal(m.calendar(), m.format('[síðstu] dddd [kl] LT'), 'today - ' + i + ' days beginning of day');
db71a655 21744 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 21745 assert.equal(m.calendar(), m.format('[síðstu] dddd [kl] LT'), 'today - ' + i + ' days end of day');
73f3c911 21746 }
db71a655 21747 });
516f5f67 21748
96d0d679 21749 test('calendar all else', function (assert) {
db71a655
KM
21750 var weeksAgo = moment().subtract({w: 1}),
21751 weeksFromNow = moment().add({w: 1});
c74a101d 21752
96d0d679
KM
21753 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), 'yksi viikko sitten');
21754 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'yhden viikon päästä');
516f5f67 21755
db71a655
KM
21756 weeksAgo = moment().subtract({w: 2});
21757 weeksFromNow = moment().add({w: 2});
516f5f67 21758
96d0d679
KM
21759 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), 'kaksi viikkoa sitten');
21760 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'kaden viikon päästä');
db71a655 21761 });
f2af24d5 21762
db71a655 21763 test('weeks year starting sunday formatted', function (assert) {
96d0d679
KM
21764 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
21765 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
21766 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
21767 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
21768 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
db71a655 21769 });
73f3c911
IC
21770
21771})));
516f5f67 21772
516f5f67 21773
c74a101d
IC
21774;(function (global, factory) {
21775 typeof exports === 'object' && typeof module !== 'undefined'
21776 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
21777 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
21778 factory(global.moment)
73f3c911 21779}(this, (function (moment) { 'use strict';
516f5f67 21780
db71a655
KM
21781 function each(array, callback) {
21782 var i;
21783 for (i = 0; i < array.length; i++) {
21784 callback(array[i], i, array);
21785 }
b135bf1a
IC
21786 }
21787
c58511b9
KM
21788 function setupDeprecationHandler(test, moment$$1, scope) {
21789 test._expectedDeprecations = null;
21790 test._observedDeprecations = null;
21791 test._oldSupress = moment$$1.suppressDeprecationWarnings;
21792 moment$$1.suppressDeprecationWarnings = true;
21793 test.expectedDeprecations = function () {
21794 test._expectedDeprecations = arguments;
21795 test._observedDeprecations = [];
21796 };
21797 moment$$1.deprecationHandler = function (name, msg) {
21798 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
21799 if (deprecationId === -1) {
21800 throw new Error('Unexpected deprecation thrown name=' +
21801 name + ' msg=' + msg);
21802 }
21803 test._observedDeprecations[deprecationId] = 1;
21804 };
21805 }
21806
21807 function teardownDeprecationHandler(test, moment$$1, scope) {
21808 moment$$1.suppressDeprecationWarnings = test._oldSupress;
21809
21810 if (test._expectedDeprecations != null) {
21811 var missedDeprecations = [];
21812 each(test._expectedDeprecations, function (deprecationPattern, id) {
21813 if (test._observedDeprecations[id] !== 1) {
21814 missedDeprecations.push(deprecationPattern);
21815 }
21816 });
21817 if (missedDeprecations.length !== 0) {
21818 throw new Error('Expected deprecation warnings did not happen: ' +
21819 missedDeprecations.join(' '));
21820 }
21821 }
21822 }
21823
21824 function matchedDeprecation(name, msg, deprecations) {
21825 if (deprecations == null) {
21826 return -1;
21827 }
21828 for (var i = 0; i < deprecations.length; ++i) {
21829 if (name != null && name === deprecations[i]) {
21830 return i;
21831 }
21832 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
21833 return i;
21834 }
21835 }
21836 return -1;
21837 }
21838
21839 /*global QUnit:false*/
21840
21841 var test = QUnit.test;
21842
db71a655
KM
21843 function objectKeys(obj) {
21844 if (Object.keys) {
21845 return Object.keys(obj);
21846 } else {
21847 // IE8
21848 var res = [], i;
21849 for (i in obj) {
21850 if (obj.hasOwnProperty(i)) {
21851 res.push(i);
21852 }
b135bf1a 21853 }
db71a655 21854 return res;
b135bf1a
IC
21855 }
21856 }
21857
db71a655 21858 // Pick the first defined of two or three arguments.
73f3c911 21859
db71a655
KM
21860 function defineCommonLocaleTests(locale, options) {
21861 test('lenient day of month ordinal parsing', function (assert) {
21862 var i, ordinalStr, testMoment;
21863 for (i = 1; i <= 31; ++i) {
21864 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
21865 testMoment = moment(ordinalStr, 'YYYY MM Do');
21866 assert.equal(testMoment.year(), 2014,
21867 'lenient day of month ordinal parsing ' + i + ' year check');
21868 assert.equal(testMoment.month(), 0,
21869 'lenient day of month ordinal parsing ' + i + ' month check');
21870 assert.equal(testMoment.date(), i,
21871 'lenient day of month ordinal parsing ' + i + ' date check');
21872 }
21873 });
73f3c911 21874
db71a655
KM
21875 test('lenient day of month ordinal parsing of number', function (assert) {
21876 var i, testMoment;
21877 for (i = 1; i <= 31; ++i) {
21878 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
21879 assert.equal(testMoment.year(), 2014,
21880 'lenient day of month ordinal parsing of number ' + i + ' year check');
21881 assert.equal(testMoment.month(), 0,
21882 'lenient day of month ordinal parsing of number ' + i + ' month check');
21883 assert.equal(testMoment.date(), i,
21884 'lenient day of month ordinal parsing of number ' + i + ' date check');
21885 }
21886 });
b135bf1a 21887
db71a655
KM
21888 test('strict day of month ordinal parsing', function (assert) {
21889 var i, ordinalStr, testMoment;
21890 for (i = 1; i <= 31; ++i) {
21891 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
21892 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
21893 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
21894 }
21895 });
b135bf1a 21896
db71a655
KM
21897 test('meridiem invariant', function (assert) {
21898 var h, m, t1, t2;
21899 for (h = 0; h < 24; ++h) {
21900 for (m = 0; m < 60; m += 15) {
21901 t1 = moment.utc([2000, 0, 1, h, m]);
21902 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
21903 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
21904 'meridiem at ' + t1.format('HH:mm'));
21905 }
21906 }
21907 });
21908
21909 test('date format correctness', function (assert) {
21910 var data, tokens;
21911 data = moment.localeData()._longDateFormat;
21912 tokens = objectKeys(data);
21913 each(tokens, function (srchToken) {
21914 // Check each format string to make sure it does not contain any
21915 // tokens that need to be expanded.
21916 each(tokens, function (baseToken) {
21917 // strip escaped sequences
21918 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
21919 assert.equal(false, !!~format.indexOf(srchToken),
21920 'contains ' + srchToken + ' in ' + baseToken);
21921 });
b135bf1a
IC
21922 });
21923 });
d6651c21 21924
db71a655
KM
21925 test('month parsing correctness', function (assert) {
21926 var i, m;
21927
21928 if (locale === 'tr') {
21929 // I can't fix it :(
c58511b9 21930 assert.expect(0);
db71a655
KM
21931 return;
21932 }
21933 function tester(format) {
21934 var r;
21935 r = moment(m.format(format), format);
21936 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
21937 if (locale !== 'ka') {
21938 r = moment(m.format(format).toLocaleUpperCase(), format);
21939 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
21940 }
db71a655
KM
21941 r = moment(m.format(format).toLocaleLowerCase(), format);
21942 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
21943
21944 r = moment(m.format(format), format, true);
21945 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
21946 if (locale !== 'ka') {
21947 r = moment(m.format(format).toLocaleUpperCase(), format, true);
21948 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
21949 }
db71a655
KM
21950 r = moment(m.format(format).toLocaleLowerCase(), format, true);
21951 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
21952 }
21953
21954 for (i = 0; i < 12; ++i) {
21955 m = moment([2015, i, 15, 18]);
21956 tester('MMM');
21957 tester('MMM.');
21958 tester('MMMM');
21959 tester('MMMM.');
21960 }
21961 });
d6651c21 21962
db71a655
KM
21963 test('weekday parsing correctness', function (assert) {
21964 var i, m;
21965
96d0d679 21966 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
21967 // tr, az: There is a lower-case letter (ı), that converted to
21968 // upper then lower changes to i
21969 // ro: there is the letter ț which behaves weird under IE8
21970 // mt: letter Ħ
96d0d679 21971 // ga: month with spaces
c58511b9 21972 assert.expect(0);
db71a655
KM
21973 return;
21974 }
21975 function tester(format) {
21976 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
21977 r = moment(m.format(format), format);
21978 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
21979 if (locale !== 'ka') {
21980 r = moment(m.format(format).toLocaleUpperCase(), format);
21981 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
21982 }
db71a655
KM
21983 r = moment(m.format(format).toLocaleLowerCase(), format);
21984 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
21985 r = moment(m.format(format), format, true);
21986 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
21987 if (locale !== 'ka') {
21988 r = moment(m.format(format).toLocaleUpperCase(), format, true);
21989 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
21990 }
db71a655
KM
21991 r = moment(m.format(format).toLocaleLowerCase(), format, true);
21992 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
21993 }
21994
21995 for (i = 0; i < 7; ++i) {
21996 m = moment.utc([2015, 0, i + 1, 18]);
21997 tester('dd');
21998 tester('ddd');
21999 tester('dddd');
22000 }
22001 });
d6651c21 22002
db71a655
KM
22003 test('valid localeData', function (assert) {
22004 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
22005 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
22006 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
22007 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
22008 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
22009 });
96d0d679
KM
22010
22011 test('localeData weekdays can localeSort', function (assert) {
22012 var weekdays = moment().localeData().weekdays();
22013 var weekdaysShort = moment().localeData().weekdaysShort();
22014 var weekdaysMin = moment().localeData().weekdaysMin();
22015 var shift = moment().localeData()._week.dow;
22016 assert.deepEqual(
22017 moment().localeData().weekdays(true),
22018 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
22019 'weekdays should localeSort');
22020 assert.deepEqual(
22021 moment().localeData().weekdaysShort(true),
22022 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
22023 'weekdaysShort should localeSort');
22024 assert.deepEqual(
22025 moment().localeData().weekdaysMin(true),
22026 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
22027 'weekdaysMin should localeSort');
22028 });
db71a655 22029 }
d6651c21 22030
db71a655 22031 /*global QUnit:false*/
c74a101d 22032
db71a655
KM
22033 function localeModule (name, lifecycle) {
22034 QUnit.module('locale:' + name, {
c58511b9 22035 beforeEach : function () {
db71a655
KM
22036 moment.locale(name);
22037 moment.createFromInputFallback = function (config) {
22038 throw new Error('input not handled by moment: ' + config._i);
22039 };
22040 setupDeprecationHandler(test, moment, 'locale');
22041 if (lifecycle && lifecycle.setup) {
22042 lifecycle.setup();
22043 }
22044 },
c58511b9 22045 afterEach : function () {
db71a655
KM
22046 moment.locale('en');
22047 teardownDeprecationHandler(test, moment, 'locale');
22048 if (lifecycle && lifecycle.teardown) {
22049 lifecycle.teardown();
22050 }
516f5f67
IC
22051 }
22052 });
db71a655
KM
22053 defineCommonLocaleTests(name, -1, -1);
22054 }
22055
96d0d679 22056 localeModule('fr-ca');
db71a655
KM
22057
22058 test('parse', function (assert) {
22059 var i,
22060 tests = 'janvier janv._février févr._mars mars_avril avr._mai mai_juin juin_juillet juil._août août_septembre sept._octobre oct._novembre nov._décembre déc.'.split('_');
22061
22062 function equalTest(input, mmm, i) {
22063 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
22064 }
22065
22066 for (i = 0; i < 12; i++) {
22067 tests[i] = tests[i].split(' ');
22068 equalTest(tests[i][0], 'MMM', i);
22069 equalTest(tests[i][1], 'MMM', i);
22070 equalTest(tests[i][0], 'MMMM', i);
22071 equalTest(tests[i][1], 'MMMM', i);
22072 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
22073 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
22074 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
22075 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
22076 }
22077 });
22078
22079 test('format', function (assert) {
22080 var a = [
22081 ['dddd, MMMM Do YYYY, h:mm:ss a', 'dimanche, février 14e 2010, 3:25:50 pm'],
22082 ['ddd, hA', 'dim., 3PM'],
22083 ['M Mo MM MMMM MMM', '2 2e 02 février févr.'],
22084 ['YYYY YY', '2010 10'],
22085 ['D Do DD', '14 14e 14'],
22086 ['d do dddd ddd dd', '0 0e dimanche dim. di'],
22087 ['DDD DDDo DDDD', '45 45e 045'],
96d0d679 22088 ['w wo ww', '8 8e 08'],
db71a655
KM
22089 ['h hh', '3 03'],
22090 ['H HH', '15 15'],
22091 ['m mm', '25 25'],
22092 ['s ss', '50 50'],
22093 ['a A', 'pm PM'],
22094 ['[le] Do [jour du mois]', 'le 14e jour du mois'],
22095 ['[le] DDDo [jour de l’année]', 'le 45e jour de l’année'],
22096 ['LTS', '15:25:50'],
96d0d679 22097 ['L', '2010-02-14'],
db71a655
KM
22098 ['LL', '14 février 2010'],
22099 ['LLL', '14 février 2010 15:25'],
22100 ['LLLL', 'dimanche 14 février 2010 15:25'],
96d0d679 22101 ['l', '2010-2-14'],
db71a655
KM
22102 ['ll', '14 févr. 2010'],
22103 ['lll', '14 févr. 2010 15:25'],
22104 ['llll', 'dim. 14 févr. 2010 15:25']
22105 ],
22106 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
22107 i;
22108
22109 for (i = 0; i < a.length; i++) {
22110 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
22111 }
22112 });
22113
22114 test('format ordinal', function (assert) {
22115 assert.equal(moment([2017, 0, 1]).format('Mo'), '1er', '1er');
22116 assert.equal(moment([2017, 1, 1]).format('Mo'), '2e', '2e');
22117
22118 assert.equal(moment([2017, 0, 1]).format('Qo'), '1er', '1er');
22119 assert.equal(moment([2017, 3, 1]).format('Qo'), '2e', '2e');
22120
22121 assert.equal(moment([2017, 0, 1]).format('Do'), '1er', '1er');
22122 assert.equal(moment([2017, 0, 2]).format('Do'), '2e', '2e');
22123
22124 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1er', '1er');
22125 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2e', '2e');
22126 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3e', '3e');
22127 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4e', '4e');
22128 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5e', '5e');
22129 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6e', '6e');
22130 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7e', '7e');
22131 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8e', '8e');
22132 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9e', '9e');
22133 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10e', '10e');
22134
22135 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11e', '11e');
22136 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12e', '12e');
22137 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13e', '13e');
22138 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14e', '14e');
22139 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15e', '15e');
22140 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16e', '16e');
22141 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17e', '17e');
22142 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18e', '18e');
22143 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19e', '19e');
22144 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20e', '20e');
22145
22146 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21e', '21e');
22147 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22e', '22e');
22148 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23e', '23e');
22149 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24e', '24e');
22150 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25e', '25e');
22151 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26e', '26e');
22152 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27e', '27e');
22153 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28e', '28e');
22154 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29e', '29e');
22155 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30e', '30e');
22156
22157 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31e', '31e');
22158
22159 assert.equal(moment([2017, 0, 1]).format('do'), '0e', '0e');
22160 assert.equal(moment([2017, 0, 2]).format('do'), '1er', '1er');
22161
22162 assert.equal(moment([2017, 0, 4]).format('wo Wo'), '1re 1re', '1re 1re');
22163 assert.equal(moment([2017, 0, 11]).format('wo Wo'), '2e 2e', '2e 2e');
22164 });
22165
22166 test('format month', function (assert) {
22167 var i,
22168 expected = 'janvier janv._février févr._mars mars_avril avr._mai mai_juin juin_juillet juil._août août_septembre sept._octobre oct._novembre nov._décembre déc.'.split('_');
22169
22170 for (i = 0; i < expected.length; i++) {
22171 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
22172 }
22173 });
22174
22175 test('format week', function (assert) {
22176 var i,
22177 expected = 'dimanche dim. di_lundi lun. lu_mardi mar. ma_mercredi mer. me_jeudi jeu. je_vendredi ven. ve_samedi sam. sa'.split('_');
22178
22179 for (i = 0; i < expected.length; i++) {
22180 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
22181 }
22182 });
22183
22184 test('from', function (assert) {
22185 var start = moment([2007, 1, 28]);
22186
22187 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'quelques secondes', '44 seconds = a few seconds');
22188 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'une minute', '45 seconds = a minute');
22189 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'une minute', '89 seconds = a minute');
22190 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes');
22191 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes');
22192 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'une heure', '45 minutes = an hour');
22193 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'une heure', '89 minutes = an hour');
22194 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 heures', '90 minutes = 2 hours');
22195 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 heures', '5 hours = 5 hours');
22196 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 heures', '21 hours = 21 hours');
22197 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un jour', '22 hours = a day');
22198 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un jour', '35 hours = a day');
22199 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 jours', '36 hours = 2 days');
22200 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un jour', '1 day = a day');
22201 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 jours', '5 days = 5 days');
22202 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 jours', '25 days = 25 days');
22203 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'un mois', '26 days = a month');
22204 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'un mois', '30 days = a month');
22205 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'un mois', '43 days = a month');
22206 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mois', '46 days = 2 months');
22207 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mois', '75 days = 2 months');
22208 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mois', '76 days = 3 months');
22209 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'un mois', '1 month = a month');
22210 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mois', '5 months = 5 months');
22211 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un an', '345 days = a year');
22212 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ans', '548 days = 2 years');
22213 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un an', '1 year = a year');
22214 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ans', '5 years = 5 years');
22215 });
22216
22217 test('suffix', function (assert) {
22218 assert.equal(moment(30000).from(0), 'dans quelques secondes', 'prefix');
22219 assert.equal(moment(0).from(30000), 'il y a quelques secondes', 'suffix');
22220 });
22221
22222 test('fromNow', function (assert) {
22223 assert.equal(moment().add({s: 30}).fromNow(), 'dans quelques secondes', 'in a few seconds');
22224 assert.equal(moment().add({d: 5}).fromNow(), 'dans 5 jours', 'in 5 days');
22225 });
22226
22227 test('same day', function (assert) {
22228 var a = moment().hours(12).minutes(0).seconds(0);
22229
22230 assert.equal(moment(a).calendar(), 'Aujourd’hui à 12:00', 'Today at the same time');
22231 assert.equal(moment(a).add({m: 25}).calendar(), 'Aujourd’hui à 12:25', 'Now plus 25 min');
22232 assert.equal(moment(a).add({h: 1}).calendar(), 'Aujourd’hui à 13:00', 'Now plus 1 hour');
22233 assert.equal(moment(a).add({d: 1}).calendar(), 'Demain à 12:00', 'Tomorrow at the same time');
22234 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Aujourd’hui à 11:00', 'Now minus 1 hour');
22235 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Hier à 12:00', 'Yesterday at the same time');
22236 });
22237
22238 test('same next week', function (assert) {
22239 var i, m;
516f5f67 22240
db71a655
KM
22241 for (i = 2; i < 7; i++) {
22242 m = moment().add({d: i});
22243 assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days current time');
22244 m.hours(0).minutes(0).seconds(0).milliseconds(0);
22245 assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days beginning of day');
22246 m.hours(23).minutes(59).seconds(59).milliseconds(999);
22247 assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days end of day');
516f5f67 22248 }
db71a655
KM
22249 });
22250
22251 test('same last week', function (assert) {
22252 var i, m;
22253
22254 for (i = 2; i < 7; i++) {
22255 m = moment().subtract({d: i});
22256 assert.equal(m.calendar(), m.format('dddd [dernier à] LT'), 'Today - ' + i + ' days current time');
22257 m.hours(0).minutes(0).seconds(0).milliseconds(0);
22258 assert.equal(m.calendar(), m.format('dddd [dernier à] LT'), 'Today - ' + i + ' days beginning of day');
22259 m.hours(23).minutes(59).seconds(59).milliseconds(999);
22260 assert.equal(m.calendar(), m.format('dddd [dernier à] LT'), 'Today - ' + i + ' days end of day');
516f5f67 22261 }
db71a655 22262 });
516f5f67 22263
db71a655
KM
22264 test('same all else', function (assert) {
22265 var weeksAgo = moment().subtract({w: 1}),
22266 weeksFromNow = moment().add({w: 1});
516f5f67 22267
db71a655
KM
22268 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
22269 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 22270
db71a655
KM
22271 weeksAgo = moment().subtract({w: 2});
22272 weeksFromNow = moment().add({w: 2});
516f5f67 22273
db71a655
KM
22274 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
22275 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
22276 });
9483e2a4 22277
db71a655 22278 test('weeks year starting sunday formatted', function (assert) {
96d0d679
KM
22279 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1re', 'Jan 1 2012 should be week 1');
22280 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1re', 'Jan 7 2012 should be week 1');
22281 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2e', 'Jan 8 2012 should be week 2');
22282 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2e', 'Jan 14 2012 should be week 2');
22283 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3e', 'Jan 15 2012 should be week 3');
db71a655 22284 });
9483e2a4
IC
22285
22286})));
22287
22288
22289;(function (global, factory) {
22290 typeof exports === 'object' && typeof module !== 'undefined'
22291 && typeof require === 'function' ? factory(require('../../moment')) :
22292 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
22293 factory(global.moment)
22294}(this, (function (moment) { 'use strict';
22295
db71a655
KM
22296 function each(array, callback) {
22297 var i;
22298 for (i = 0; i < array.length; i++) {
22299 callback(array[i], i, array);
22300 }
9483e2a4 22301 }
9483e2a4 22302
db71a655
KM
22303 function setupDeprecationHandler(test, moment$$1, scope) {
22304 test._expectedDeprecations = null;
22305 test._observedDeprecations = null;
22306 test._oldSupress = moment$$1.suppressDeprecationWarnings;
22307 moment$$1.suppressDeprecationWarnings = true;
22308 test.expectedDeprecations = function () {
22309 test._expectedDeprecations = arguments;
22310 test._observedDeprecations = [];
22311 };
22312 moment$$1.deprecationHandler = function (name, msg) {
22313 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
22314 if (deprecationId === -1) {
22315 throw new Error('Unexpected deprecation thrown name=' +
22316 name + ' msg=' + msg);
22317 }
22318 test._observedDeprecations[deprecationId] = 1;
22319 };
22320 }
9483e2a4 22321
db71a655
KM
22322 function teardownDeprecationHandler(test, moment$$1, scope) {
22323 moment$$1.suppressDeprecationWarnings = test._oldSupress;
9483e2a4 22324
db71a655
KM
22325 if (test._expectedDeprecations != null) {
22326 var missedDeprecations = [];
22327 each(test._expectedDeprecations, function (deprecationPattern, id) {
22328 if (test._observedDeprecations[id] !== 1) {
22329 missedDeprecations.push(deprecationPattern);
22330 }
22331 });
22332 if (missedDeprecations.length !== 0) {
22333 throw new Error('Expected deprecation warnings did not happen: ' +
22334 missedDeprecations.join(' '));
22335 }
9483e2a4 22336 }
db71a655 22337 }
9483e2a4 22338
db71a655
KM
22339 function matchedDeprecation(name, msg, deprecations) {
22340 if (deprecations == null) {
22341 return -1;
9483e2a4 22342 }
db71a655
KM
22343 for (var i = 0; i < deprecations.length; ++i) {
22344 if (name != null && name === deprecations[i]) {
22345 return i;
22346 }
22347 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
22348 return i;
22349 }
22350 }
22351 return -1;
22352 }
9483e2a4 22353
db71a655 22354 /*global QUnit:false*/
9483e2a4 22355
db71a655
KM
22356 var test = QUnit.test;
22357
c58511b9
KM
22358 function objectKeys(obj) {
22359 if (Object.keys) {
22360 return Object.keys(obj);
22361 } else {
22362 // IE8
22363 var res = [], i;
22364 for (i in obj) {
22365 if (obj.hasOwnProperty(i)) {
22366 res.push(i);
22367 }
22368 }
22369 return res;
22370 }
22371 }
22372
22373 // Pick the first defined of two or three arguments.
22374
22375 function defineCommonLocaleTests(locale, options) {
22376 test('lenient day of month ordinal parsing', function (assert) {
22377 var i, ordinalStr, testMoment;
22378 for (i = 1; i <= 31; ++i) {
22379 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
22380 testMoment = moment(ordinalStr, 'YYYY MM Do');
22381 assert.equal(testMoment.year(), 2014,
22382 'lenient day of month ordinal parsing ' + i + ' year check');
22383 assert.equal(testMoment.month(), 0,
22384 'lenient day of month ordinal parsing ' + i + ' month check');
22385 assert.equal(testMoment.date(), i,
22386 'lenient day of month ordinal parsing ' + i + ' date check');
22387 }
22388 });
22389
22390 test('lenient day of month ordinal parsing of number', function (assert) {
22391 var i, testMoment;
22392 for (i = 1; i <= 31; ++i) {
22393 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
22394 assert.equal(testMoment.year(), 2014,
22395 'lenient day of month ordinal parsing of number ' + i + ' year check');
22396 assert.equal(testMoment.month(), 0,
22397 'lenient day of month ordinal parsing of number ' + i + ' month check');
22398 assert.equal(testMoment.date(), i,
22399 'lenient day of month ordinal parsing of number ' + i + ' date check');
22400 }
22401 });
22402
22403 test('strict day of month ordinal parsing', function (assert) {
22404 var i, ordinalStr, testMoment;
22405 for (i = 1; i <= 31; ++i) {
22406 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
22407 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
22408 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
22409 }
22410 });
22411
22412 test('meridiem invariant', function (assert) {
22413 var h, m, t1, t2;
22414 for (h = 0; h < 24; ++h) {
22415 for (m = 0; m < 60; m += 15) {
22416 t1 = moment.utc([2000, 0, 1, h, m]);
22417 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
22418 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
22419 'meridiem at ' + t1.format('HH:mm'));
22420 }
22421 }
22422 });
22423
22424 test('date format correctness', function (assert) {
22425 var data, tokens;
22426 data = moment.localeData()._longDateFormat;
22427 tokens = objectKeys(data);
22428 each(tokens, function (srchToken) {
22429 // Check each format string to make sure it does not contain any
22430 // tokens that need to be expanded.
22431 each(tokens, function (baseToken) {
22432 // strip escaped sequences
22433 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
22434 assert.equal(false, !!~format.indexOf(srchToken),
22435 'contains ' + srchToken + ' in ' + baseToken);
22436 });
22437 });
22438 });
22439
22440 test('month parsing correctness', function (assert) {
22441 var i, m;
22442
22443 if (locale === 'tr') {
22444 // I can't fix it :(
22445 assert.expect(0);
22446 return;
22447 }
22448 function tester(format) {
22449 var r;
22450 r = moment(m.format(format), format);
22451 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
22452 if (locale !== 'ka') {
22453 r = moment(m.format(format).toLocaleUpperCase(), format);
22454 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
22455 }
c58511b9
KM
22456 r = moment(m.format(format).toLocaleLowerCase(), format);
22457 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
22458
22459 r = moment(m.format(format), format, true);
22460 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
22461 if (locale !== 'ka') {
22462 r = moment(m.format(format).toLocaleUpperCase(), format, true);
22463 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
22464 }
c58511b9
KM
22465 r = moment(m.format(format).toLocaleLowerCase(), format, true);
22466 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
22467 }
22468
22469 for (i = 0; i < 12; ++i) {
22470 m = moment([2015, i, 15, 18]);
22471 tester('MMM');
22472 tester('MMM.');
22473 tester('MMMM');
22474 tester('MMMM.');
22475 }
22476 });
22477
22478 test('weekday parsing correctness', function (assert) {
22479 var i, m;
22480
96d0d679 22481 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
c58511b9
KM
22482 // tr, az: There is a lower-case letter (ı), that converted to
22483 // upper then lower changes to i
22484 // ro: there is the letter ț which behaves weird under IE8
22485 // mt: letter Ħ
96d0d679 22486 // ga: month with spaces
c58511b9
KM
22487 assert.expect(0);
22488 return;
22489 }
22490 function tester(format) {
22491 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
22492 r = moment(m.format(format), format);
22493 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
22494 if (locale !== 'ka') {
22495 r = moment(m.format(format).toLocaleUpperCase(), format);
22496 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
22497 }
c58511b9
KM
22498 r = moment(m.format(format).toLocaleLowerCase(), format);
22499 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
22500 r = moment(m.format(format), format, true);
22501 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
22502 if (locale !== 'ka') {
22503 r = moment(m.format(format).toLocaleUpperCase(), format, true);
22504 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
22505 }
c58511b9
KM
22506 r = moment(m.format(format).toLocaleLowerCase(), format, true);
22507 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
22508 }
22509
22510 for (i = 0; i < 7; ++i) {
22511 m = moment.utc([2015, 0, i + 1, 18]);
22512 tester('dd');
22513 tester('ddd');
22514 tester('dddd');
22515 }
22516 });
22517
22518 test('valid localeData', function (assert) {
22519 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
22520 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
22521 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
22522 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
22523 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
22524 });
96d0d679
KM
22525
22526 test('localeData weekdays can localeSort', function (assert) {
22527 var weekdays = moment().localeData().weekdays();
22528 var weekdaysShort = moment().localeData().weekdaysShort();
22529 var weekdaysMin = moment().localeData().weekdaysMin();
22530 var shift = moment().localeData()._week.dow;
22531 assert.deepEqual(
22532 moment().localeData().weekdays(true),
22533 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
22534 'weekdays should localeSort');
22535 assert.deepEqual(
22536 moment().localeData().weekdaysShort(true),
22537 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
22538 'weekdaysShort should localeSort');
22539 assert.deepEqual(
22540 moment().localeData().weekdaysMin(true),
22541 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
22542 'weekdaysMin should localeSort');
22543 });
c58511b9
KM
22544 }
22545
22546 /*global QUnit:false*/
db71a655
KM
22547
22548 function localeModule (name, lifecycle) {
22549 QUnit.module('locale:' + name, {
c58511b9 22550 beforeEach : function () {
db71a655
KM
22551 moment.locale(name);
22552 moment.createFromInputFallback = function (config) {
22553 throw new Error('input not handled by moment: ' + config._i);
22554 };
22555 setupDeprecationHandler(test, moment, 'locale');
22556 if (lifecycle && lifecycle.setup) {
22557 lifecycle.setup();
22558 }
22559 },
c58511b9 22560 afterEach : function () {
db71a655
KM
22561 moment.locale('en');
22562 teardownDeprecationHandler(test, moment, 'locale');
22563 if (lifecycle && lifecycle.teardown) {
22564 lifecycle.teardown();
22565 }
9483e2a4
IC
22566 }
22567 });
db71a655
KM
22568 defineCommonLocaleTests(name, -1, -1);
22569 }
22570
96d0d679 22571 localeModule('fr-ch');
db71a655
KM
22572
22573 test('parse', function (assert) {
22574 var i,
22575 tests = 'janvier janv._février févr._mars mars_avril avr._mai mai_juin juin_juillet juil._août août_septembre sept._octobre oct._novembre nov._décembre déc.'.split('_');
22576
22577 function equalTest(input, mmm, i) {
22578 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
22579 }
22580
22581 for (i = 0; i < 12; i++) {
22582 tests[i] = tests[i].split(' ');
22583 equalTest(tests[i][0], 'MMM', i);
22584 equalTest(tests[i][1], 'MMM', i);
22585 equalTest(tests[i][0], 'MMMM', i);
22586 equalTest(tests[i][1], 'MMMM', i);
22587 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
22588 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
22589 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
22590 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
22591 }
22592 });
22593
22594 test('format', function (assert) {
22595 var a = [
96d0d679 22596 ['dddd, MMMM Do YYYY, h:mm:ss a', 'dimanche, février 14e 2010, 3:25:50 pm'],
db71a655
KM
22597 ['ddd, hA', 'dim., 3PM'],
22598 ['M Mo MM MMMM MMM', '2 2e 02 février févr.'],
22599 ['YYYY YY', '2010 10'],
96d0d679 22600 ['D Do DD', '14 14e 14'],
db71a655
KM
22601 ['d do dddd ddd dd', '0 0e dimanche dim. di'],
22602 ['DDD DDDo DDDD', '45 45e 045'],
22603 ['w wo ww', '6 6e 06'],
22604 ['h hh', '3 03'],
22605 ['H HH', '15 15'],
22606 ['m mm', '25 25'],
22607 ['s ss', '50 50'],
22608 ['a A', 'pm PM'],
96d0d679 22609 ['[le] Do [jour du mois]', 'le 14e jour du mois'],
db71a655
KM
22610 ['[le] DDDo [jour de l’année]', 'le 45e jour de l’année'],
22611 ['LTS', '15:25:50'],
96d0d679 22612 ['L', '14.02.2010'],
db71a655
KM
22613 ['LL', '14 février 2010'],
22614 ['LLL', '14 février 2010 15:25'],
22615 ['LLLL', 'dimanche 14 février 2010 15:25'],
96d0d679 22616 ['l', '14.2.2010'],
db71a655
KM
22617 ['ll', '14 févr. 2010'],
22618 ['lll', '14 févr. 2010 15:25'],
22619 ['llll', 'dim. 14 févr. 2010 15:25']
22620 ],
22621 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
22622 i;
22623
22624 for (i = 0; i < a.length; i++) {
22625 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
22626 }
22627 });
22628
22629 test('format ordinal', function (assert) {
22630 assert.equal(moment([2017, 0, 1]).format('Mo'), '1er', '1er');
22631 assert.equal(moment([2017, 1, 1]).format('Mo'), '2e', '2e');
22632
22633 assert.equal(moment([2017, 0, 1]).format('Qo'), '1er', '1er');
22634 assert.equal(moment([2017, 3, 1]).format('Qo'), '2e', '2e');
22635
22636 assert.equal(moment([2017, 0, 1]).format('Do'), '1er', '1er');
96d0d679 22637 assert.equal(moment([2017, 0, 2]).format('Do'), '2e', '2e');
db71a655
KM
22638
22639 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1er', '1er');
22640 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2e', '2e');
22641 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3e', '3e');
22642 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4e', '4e');
22643 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5e', '5e');
22644 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6e', '6e');
22645 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7e', '7e');
22646 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8e', '8e');
22647 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9e', '9e');
22648 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10e', '10e');
22649
22650 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11e', '11e');
22651 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12e', '12e');
22652 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13e', '13e');
22653 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14e', '14e');
22654 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15e', '15e');
22655 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16e', '16e');
22656 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17e', '17e');
22657 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18e', '18e');
22658 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19e', '19e');
22659 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20e', '20e');
22660
22661 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21e', '21e');
22662 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22e', '22e');
22663 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23e', '23e');
22664 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24e', '24e');
22665 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25e', '25e');
22666 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26e', '26e');
22667 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27e', '27e');
22668 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28e', '28e');
22669 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29e', '29e');
22670 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30e', '30e');
22671
22672 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31e', '31e');
22673
22674 assert.equal(moment([2017, 0, 1]).format('do'), '0e', '0e');
22675 assert.equal(moment([2017, 0, 2]).format('do'), '1er', '1er');
22676
22677 assert.equal(moment([2017, 0, 4]).format('wo Wo'), '1re 1re', '1re 1re');
22678 assert.equal(moment([2017, 0, 11]).format('wo Wo'), '2e 2e', '2e 2e');
22679 });
22680
22681 test('format month', function (assert) {
22682 var i,
22683 expected = 'janvier janv._février févr._mars mars_avril avr._mai mai_juin juin_juillet juil._août août_septembre sept._octobre oct._novembre nov._décembre déc.'.split('_');
22684
22685 for (i = 0; i < expected.length; i++) {
22686 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
22687 }
22688 });
22689
22690 test('format week', function (assert) {
22691 var i,
22692 expected = 'dimanche dim. di_lundi lun. lu_mardi mar. ma_mercredi mer. me_jeudi jeu. je_vendredi ven. ve_samedi sam. sa'.split('_');
22693
22694 for (i = 0; i < expected.length; i++) {
22695 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
22696 }
22697 });
22698
22699 test('from', function (assert) {
22700 var start = moment([2007, 1, 28]);
22701
22702 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'quelques secondes', '44 seconds = a few seconds');
22703 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'une minute', '45 seconds = a minute');
22704 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'une minute', '89 seconds = a minute');
22705 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes');
22706 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes');
22707 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'une heure', '45 minutes = an hour');
22708 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'une heure', '89 minutes = an hour');
22709 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 heures', '90 minutes = 2 hours');
22710 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 heures', '5 hours = 5 hours');
22711 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 heures', '21 hours = 21 hours');
22712 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un jour', '22 hours = a day');
22713 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un jour', '35 hours = a day');
22714 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 jours', '36 hours = 2 days');
22715 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un jour', '1 day = a day');
22716 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 jours', '5 days = 5 days');
22717 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 jours', '25 days = 25 days');
22718 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'un mois', '26 days = a month');
22719 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'un mois', '30 days = a month');
22720 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'un mois', '43 days = a month');
22721 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mois', '46 days = 2 months');
22722 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mois', '75 days = 2 months');
22723 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mois', '76 days = 3 months');
22724 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'un mois', '1 month = a month');
22725 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mois', '5 months = 5 months');
22726 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un an', '345 days = a year');
22727 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ans', '548 days = 2 years');
22728 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un an', '1 year = a year');
22729 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ans', '5 years = 5 years');
22730 });
22731
22732 test('suffix', function (assert) {
22733 assert.equal(moment(30000).from(0), 'dans quelques secondes', 'prefix');
22734 assert.equal(moment(0).from(30000), 'il y a quelques secondes', 'suffix');
22735 });
22736
22737 test('fromNow', function (assert) {
22738 assert.equal(moment().add({s: 30}).fromNow(), 'dans quelques secondes', 'in a few seconds');
22739 assert.equal(moment().add({d: 5}).fromNow(), 'dans 5 jours', 'in 5 days');
22740 });
22741
22742 test('same day', function (assert) {
22743 var a = moment().hours(12).minutes(0).seconds(0);
22744
22745 assert.equal(moment(a).calendar(), 'Aujourd’hui à 12:00', 'Today at the same time');
22746 assert.equal(moment(a).add({m: 25}).calendar(), 'Aujourd’hui à 12:25', 'Now plus 25 min');
22747 assert.equal(moment(a).add({h: 1}).calendar(), 'Aujourd’hui à 13:00', 'Now plus 1 hour');
22748 assert.equal(moment(a).add({d: 1}).calendar(), 'Demain à 12:00', 'Tomorrow at the same time');
22749 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Aujourd’hui à 11:00', 'Now minus 1 hour');
22750 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Hier à 12:00', 'Yesterday at the same time');
22751 });
22752
22753 test('same next week', function (assert) {
22754 var i, m;
9483e2a4 22755
db71a655
KM
22756 for (i = 2; i < 7; i++) {
22757 m = moment().add({d: i});
22758 assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days current time');
22759 m.hours(0).minutes(0).seconds(0).milliseconds(0);
22760 assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days beginning of day');
22761 m.hours(23).minutes(59).seconds(59).milliseconds(999);
22762 assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days end of day');
9483e2a4 22763 }
db71a655
KM
22764 });
22765
22766 test('same last week', function (assert) {
22767 var i, m;
22768
22769 for (i = 2; i < 7; i++) {
22770 m = moment().subtract({d: i});
22771 assert.equal(m.calendar(), m.format('dddd [dernier à] LT'), 'Today - ' + i + ' days current time');
22772 m.hours(0).minutes(0).seconds(0).milliseconds(0);
22773 assert.equal(m.calendar(), m.format('dddd [dernier à] LT'), 'Today - ' + i + ' days beginning of day');
22774 m.hours(23).minutes(59).seconds(59).milliseconds(999);
22775 assert.equal(m.calendar(), m.format('dddd [dernier à] LT'), 'Today - ' + i + ' days end of day');
9483e2a4 22776 }
db71a655 22777 });
9483e2a4 22778
db71a655
KM
22779 test('same all else', function (assert) {
22780 var weeksAgo = moment().subtract({w: 1}),
22781 weeksFromNow = moment().add({w: 1});
9483e2a4 22782
db71a655
KM
22783 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
22784 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
9483e2a4 22785
db71a655
KM
22786 weeksAgo = moment().subtract({w: 2});
22787 weeksFromNow = moment().add({w: 2});
9483e2a4 22788
db71a655
KM
22789 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
22790 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
22791 });
7c4c091b 22792
db71a655
KM
22793 test('weeks year starting sunday formatted', function (assert) {
22794 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52e', 'Jan 1 2012 should be week 52');
22795 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1re', 'Jan 2 2012 should be week 1');
22796 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1re', 'Jan 8 2012 should be week 1');
22797 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2e', 'Jan 9 2012 should be week 2');
22798 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2e', 'Jan 15 2012 should be week 2');
22799 });
73f3c911
IC
22800
22801})));
516f5f67 22802
c74a101d
IC
22803
22804;(function (global, factory) {
22805 typeof exports === 'object' && typeof module !== 'undefined'
22806 && typeof require === 'function' ? factory(require('../../moment')) :
22807 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
22808 factory(global.moment)
73f3c911 22809}(this, (function (moment) { 'use strict';
c74a101d 22810
db71a655
KM
22811 function each(array, callback) {
22812 var i;
22813 for (i = 0; i < array.length; i++) {
22814 callback(array[i], i, array);
22815 }
b135bf1a
IC
22816 }
22817
c58511b9
KM
22818 function setupDeprecationHandler(test, moment$$1, scope) {
22819 test._expectedDeprecations = null;
22820 test._observedDeprecations = null;
22821 test._oldSupress = moment$$1.suppressDeprecationWarnings;
22822 moment$$1.suppressDeprecationWarnings = true;
22823 test.expectedDeprecations = function () {
22824 test._expectedDeprecations = arguments;
22825 test._observedDeprecations = [];
22826 };
22827 moment$$1.deprecationHandler = function (name, msg) {
22828 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
22829 if (deprecationId === -1) {
22830 throw new Error('Unexpected deprecation thrown name=' +
22831 name + ' msg=' + msg);
22832 }
22833 test._observedDeprecations[deprecationId] = 1;
22834 };
22835 }
22836
22837 function teardownDeprecationHandler(test, moment$$1, scope) {
22838 moment$$1.suppressDeprecationWarnings = test._oldSupress;
22839
22840 if (test._expectedDeprecations != null) {
22841 var missedDeprecations = [];
22842 each(test._expectedDeprecations, function (deprecationPattern, id) {
22843 if (test._observedDeprecations[id] !== 1) {
22844 missedDeprecations.push(deprecationPattern);
22845 }
22846 });
22847 if (missedDeprecations.length !== 0) {
22848 throw new Error('Expected deprecation warnings did not happen: ' +
22849 missedDeprecations.join(' '));
22850 }
22851 }
22852 }
22853
22854 function matchedDeprecation(name, msg, deprecations) {
22855 if (deprecations == null) {
22856 return -1;
22857 }
22858 for (var i = 0; i < deprecations.length; ++i) {
22859 if (name != null && name === deprecations[i]) {
22860 return i;
22861 }
22862 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
22863 return i;
22864 }
22865 }
22866 return -1;
22867 }
22868
22869 /*global QUnit:false*/
22870
22871 var test = QUnit.test;
22872
db71a655
KM
22873 function objectKeys(obj) {
22874 if (Object.keys) {
22875 return Object.keys(obj);
22876 } else {
22877 // IE8
22878 var res = [], i;
22879 for (i in obj) {
22880 if (obj.hasOwnProperty(i)) {
22881 res.push(i);
22882 }
b135bf1a 22883 }
db71a655 22884 return res;
b135bf1a
IC
22885 }
22886 }
22887
db71a655 22888 // Pick the first defined of two or three arguments.
b135bf1a 22889
db71a655
KM
22890 function defineCommonLocaleTests(locale, options) {
22891 test('lenient day of month ordinal parsing', function (assert) {
22892 var i, ordinalStr, testMoment;
22893 for (i = 1; i <= 31; ++i) {
22894 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
22895 testMoment = moment(ordinalStr, 'YYYY MM Do');
22896 assert.equal(testMoment.year(), 2014,
22897 'lenient day of month ordinal parsing ' + i + ' year check');
22898 assert.equal(testMoment.month(), 0,
22899 'lenient day of month ordinal parsing ' + i + ' month check');
22900 assert.equal(testMoment.date(), i,
22901 'lenient day of month ordinal parsing ' + i + ' date check');
22902 }
22903 });
b135bf1a 22904
db71a655
KM
22905 test('lenient day of month ordinal parsing of number', function (assert) {
22906 var i, testMoment;
22907 for (i = 1; i <= 31; ++i) {
22908 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
22909 assert.equal(testMoment.year(), 2014,
22910 'lenient day of month ordinal parsing of number ' + i + ' year check');
22911 assert.equal(testMoment.month(), 0,
22912 'lenient day of month ordinal parsing of number ' + i + ' month check');
22913 assert.equal(testMoment.date(), i,
22914 'lenient day of month ordinal parsing of number ' + i + ' date check');
22915 }
22916 });
b135bf1a 22917
db71a655
KM
22918 test('strict day of month ordinal parsing', function (assert) {
22919 var i, ordinalStr, testMoment;
22920 for (i = 1; i <= 31; ++i) {
22921 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
22922 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
22923 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
22924 }
22925 });
b135bf1a 22926
db71a655
KM
22927 test('meridiem invariant', function (assert) {
22928 var h, m, t1, t2;
22929 for (h = 0; h < 24; ++h) {
22930 for (m = 0; m < 60; m += 15) {
22931 t1 = moment.utc([2000, 0, 1, h, m]);
22932 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
22933 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
22934 'meridiem at ' + t1.format('HH:mm'));
22935 }
22936 }
22937 });
22938
22939 test('date format correctness', function (assert) {
22940 var data, tokens;
22941 data = moment.localeData()._longDateFormat;
22942 tokens = objectKeys(data);
22943 each(tokens, function (srchToken) {
22944 // Check each format string to make sure it does not contain any
22945 // tokens that need to be expanded.
22946 each(tokens, function (baseToken) {
22947 // strip escaped sequences
22948 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
22949 assert.equal(false, !!~format.indexOf(srchToken),
22950 'contains ' + srchToken + ' in ' + baseToken);
22951 });
b135bf1a
IC
22952 });
22953 });
d6651c21 22954
db71a655
KM
22955 test('month parsing correctness', function (assert) {
22956 var i, m;
22957
22958 if (locale === 'tr') {
22959 // I can't fix it :(
c58511b9 22960 assert.expect(0);
db71a655
KM
22961 return;
22962 }
22963 function tester(format) {
22964 var r;
22965 r = moment(m.format(format), format);
22966 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
22967 if (locale !== 'ka') {
22968 r = moment(m.format(format).toLocaleUpperCase(), format);
22969 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
22970 }
db71a655
KM
22971 r = moment(m.format(format).toLocaleLowerCase(), format);
22972 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
22973
22974 r = moment(m.format(format), format, true);
22975 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
22976 if (locale !== 'ka') {
22977 r = moment(m.format(format).toLocaleUpperCase(), format, true);
22978 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
22979 }
db71a655
KM
22980 r = moment(m.format(format).toLocaleLowerCase(), format, true);
22981 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
22982 }
22983
22984 for (i = 0; i < 12; ++i) {
22985 m = moment([2015, i, 15, 18]);
22986 tester('MMM');
22987 tester('MMM.');
22988 tester('MMMM');
22989 tester('MMMM.');
22990 }
22991 });
d6651c21 22992
db71a655
KM
22993 test('weekday parsing correctness', function (assert) {
22994 var i, m;
22995
96d0d679 22996 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
22997 // tr, az: There is a lower-case letter (ı), that converted to
22998 // upper then lower changes to i
22999 // ro: there is the letter ț which behaves weird under IE8
23000 // mt: letter Ħ
96d0d679 23001 // ga: month with spaces
c58511b9 23002 assert.expect(0);
db71a655
KM
23003 return;
23004 }
23005 function tester(format) {
23006 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
23007 r = moment(m.format(format), format);
23008 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
23009 if (locale !== 'ka') {
23010 r = moment(m.format(format).toLocaleUpperCase(), format);
23011 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
23012 }
db71a655
KM
23013 r = moment(m.format(format).toLocaleLowerCase(), format);
23014 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
23015 r = moment(m.format(format), format, true);
23016 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
23017 if (locale !== 'ka') {
23018 r = moment(m.format(format).toLocaleUpperCase(), format, true);
23019 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
23020 }
db71a655
KM
23021 r = moment(m.format(format).toLocaleLowerCase(), format, true);
23022 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
23023 }
23024
23025 for (i = 0; i < 7; ++i) {
23026 m = moment.utc([2015, 0, i + 1, 18]);
23027 tester('dd');
23028 tester('ddd');
23029 tester('dddd');
23030 }
23031 });
d6651c21 23032
db71a655
KM
23033 test('valid localeData', function (assert) {
23034 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
23035 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
23036 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
23037 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
23038 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
23039 });
96d0d679
KM
23040
23041 test('localeData weekdays can localeSort', function (assert) {
23042 var weekdays = moment().localeData().weekdays();
23043 var weekdaysShort = moment().localeData().weekdaysShort();
23044 var weekdaysMin = moment().localeData().weekdaysMin();
23045 var shift = moment().localeData()._week.dow;
23046 assert.deepEqual(
23047 moment().localeData().weekdays(true),
23048 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
23049 'weekdays should localeSort');
23050 assert.deepEqual(
23051 moment().localeData().weekdaysShort(true),
23052 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
23053 'weekdaysShort should localeSort');
23054 assert.deepEqual(
23055 moment().localeData().weekdaysMin(true),
23056 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
23057 'weekdaysMin should localeSort');
23058 });
db71a655 23059 }
d6651c21 23060
db71a655 23061 /*global QUnit:false*/
c74a101d 23062
db71a655
KM
23063 function localeModule (name, lifecycle) {
23064 QUnit.module('locale:' + name, {
c58511b9 23065 beforeEach : function () {
db71a655
KM
23066 moment.locale(name);
23067 moment.createFromInputFallback = function (config) {
23068 throw new Error('input not handled by moment: ' + config._i);
23069 };
23070 setupDeprecationHandler(test, moment, 'locale');
23071 if (lifecycle && lifecycle.setup) {
23072 lifecycle.setup();
23073 }
23074 },
c58511b9 23075 afterEach : function () {
db71a655
KM
23076 moment.locale('en');
23077 teardownDeprecationHandler(test, moment, 'locale');
23078 if (lifecycle && lifecycle.teardown) {
23079 lifecycle.teardown();
23080 }
516f5f67 23081 }
c74a101d 23082 });
db71a655
KM
23083 defineCommonLocaleTests(name, -1, -1);
23084 }
23085
96d0d679 23086 localeModule('fr');
db71a655
KM
23087
23088 test('parse', function (assert) {
96d0d679
KM
23089 var i,
23090 tests = 'janvier janv._février févr._mars mars_avril avr._mai mai_juin juin_juillet juil._août août_septembre sept._octobre oct._novembre nov._décembre déc.'.split('_');
23091
db71a655
KM
23092 function equalTest(input, mmm, i) {
23093 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
23094 }
96d0d679 23095
db71a655
KM
23096 for (i = 0; i < 12; i++) {
23097 tests[i] = tests[i].split(' ');
23098 equalTest(tests[i][0], 'MMM', i);
23099 equalTest(tests[i][1], 'MMM', i);
23100 equalTest(tests[i][0], 'MMMM', i);
23101 equalTest(tests[i][1], 'MMMM', i);
23102 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
23103 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
23104 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
23105 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
23106 }
23107 });
23108
23109 test('format', function (assert) {
23110 var a = [
96d0d679
KM
23111 ['dddd, MMMM Do YYYY, h:mm:ss a', 'dimanche, février 14 2010, 3:25:50 pm'],
23112 ['ddd, hA', 'dim., 3PM'],
23113 ['M Mo MM MMMM MMM', '2 2e 02 février févr.'],
23114 ['YYYY YY', '2010 10'],
23115 ['D Do DD', '14 14 14'],
23116 ['d do dddd ddd dd', '0 0e dimanche dim. di'],
23117 ['DDD DDDo DDDD', '45 45e 045'],
23118 ['w wo ww', '6 6e 06'],
23119 ['h hh', '3 03'],
23120 ['H HH', '15 15'],
23121 ['m mm', '25 25'],
23122 ['s ss', '50 50'],
23123 ['a A', 'pm PM'],
23124 ['[le] Do [jour du mois]', 'le 14 jour du mois'],
23125 ['[le] DDDo [jour de l’année]', 'le 45e jour de l’année'],
23126 ['LTS', '15:25:50'],
23127 ['L', '14/02/2010'],
23128 ['LL', '14 février 2010'],
23129 ['LLL', '14 février 2010 15:25'],
23130 ['LLLL', 'dimanche 14 février 2010 15:25'],
23131 ['l', '14/2/2010'],
23132 ['ll', '14 févr. 2010'],
23133 ['lll', '14 févr. 2010 15:25'],
23134 ['llll', 'dim. 14 févr. 2010 15:25']
db71a655
KM
23135 ],
23136 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
23137 i;
96d0d679 23138
db71a655
KM
23139 for (i = 0; i < a.length; i++) {
23140 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
23141 }
23142 });
23143
23144 test('format ordinal', function (assert) {
96d0d679
KM
23145 assert.equal(moment([2017, 0, 1]).format('Mo'), '1er', '1er');
23146 assert.equal(moment([2017, 1, 1]).format('Mo'), '2e', '2e');
db71a655 23147
96d0d679
KM
23148 assert.equal(moment([2017, 0, 1]).format('Qo'), '1er', '1er');
23149 assert.equal(moment([2017, 3, 1]).format('Qo'), '2e', '2e');
db71a655 23150
96d0d679
KM
23151 assert.equal(moment([2017, 0, 1]).format('Do'), '1er', '1er');
23152 assert.equal(moment([2017, 0, 2]).format('Do'), '2', '2');
db71a655 23153
96d0d679
KM
23154 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1er', '1er');
23155 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2e', '2e');
23156 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3e', '3e');
23157 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4e', '4e');
23158 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5e', '5e');
23159 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6e', '6e');
23160 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7e', '7e');
23161 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8e', '8e');
23162 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9e', '9e');
23163 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10e', '10e');
23164
23165 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11e', '11e');
23166 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12e', '12e');
23167 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13e', '13e');
23168 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14e', '14e');
23169 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15e', '15e');
23170 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16e', '16e');
23171 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17e', '17e');
23172 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18e', '18e');
23173 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19e', '19e');
23174 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20e', '20e');
23175
23176 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21e', '21e');
23177 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22e', '22e');
23178 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23e', '23e');
23179 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24e', '24e');
23180 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25e', '25e');
23181 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26e', '26e');
23182 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27e', '27e');
23183 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28e', '28e');
23184 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29e', '29e');
23185 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30e', '30e');
23186
23187 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31e', '31e');
23188
23189 assert.equal(moment([2017, 0, 1]).format('do'), '0e', '0e');
23190 assert.equal(moment([2017, 0, 2]).format('do'), '1er', '1er');
23191
23192 assert.equal(moment([2017, 0, 4]).format('wo Wo'), '1re 1re', '1re 1re');
23193 assert.equal(moment([2017, 0, 11]).format('wo Wo'), '2e 2e', '2e 2e');
db71a655
KM
23194 });
23195
23196 test('format month', function (assert) {
96d0d679
KM
23197 var i,
23198 expected = 'janvier janv._février févr._mars mars_avril avr._mai mai_juin juin_juillet juil._août août_septembre sept._octobre oct._novembre nov._décembre déc.'.split('_');
23199
db71a655
KM
23200 for (i = 0; i < expected.length; i++) {
23201 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
23202 }
23203 });
23204
23205 test('format week', function (assert) {
96d0d679
KM
23206 var i,
23207 expected = 'dimanche dim. di_lundi lun. lu_mardi mar. ma_mercredi mer. me_jeudi jeu. je_vendredi ven. ve_samedi sam. sa'.split('_');
23208
db71a655
KM
23209 for (i = 0; i < expected.length; i++) {
23210 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
23211 }
23212 });
23213
23214 test('from', function (assert) {
23215 var start = moment([2007, 1, 28]);
db71a655 23216
96d0d679
KM
23217 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'quelques secondes', '44 seconds = a few seconds');
23218 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'une minute', '45 seconds = a minute');
23219 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'une minute', '89 seconds = a minute');
23220 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes');
23221 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes');
23222 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'une heure', '45 minutes = an hour');
23223 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'une heure', '89 minutes = an hour');
23224 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 heures', '90 minutes = 2 hours');
23225 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 heures', '5 hours = 5 hours');
23226 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 heures', '21 hours = 21 hours');
23227 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un jour', '22 hours = a day');
23228 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un jour', '35 hours = a day');
23229 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 jours', '36 hours = 2 days');
23230 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un jour', '1 day = a day');
23231 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 jours', '5 days = 5 days');
23232 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 jours', '25 days = 25 days');
23233 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'un mois', '26 days = a month');
23234 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'un mois', '30 days = a month');
23235 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'un mois', '43 days = a month');
23236 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mois', '46 days = 2 months');
23237 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mois', '75 days = 2 months');
23238 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mois', '76 days = 3 months');
23239 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'un mois', '1 month = a month');
23240 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mois', '5 months = 5 months');
23241 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un an', '345 days = a year');
23242 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ans', '548 days = 2 years');
23243 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un an', '1 year = a year');
23244 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ans', '5 years = 5 years');
db71a655
KM
23245 });
23246
96d0d679
KM
23247 test('suffix', function (assert) {
23248 assert.equal(moment(30000).from(0), 'dans quelques secondes', 'prefix');
23249 assert.equal(moment(0).from(30000), 'il y a quelques secondes', 'suffix');
db71a655
KM
23250 });
23251
23252 test('fromNow', function (assert) {
96d0d679
KM
23253 assert.equal(moment().add({s: 30}).fromNow(), 'dans quelques secondes', 'in a few seconds');
23254 assert.equal(moment().add({d: 5}).fromNow(), 'dans 5 jours', 'in 5 days');
db71a655
KM
23255 });
23256
96d0d679 23257 test('same day', function (assert) {
db71a655
KM
23258 var a = moment().hours(12).minutes(0).seconds(0);
23259
96d0d679
KM
23260 assert.equal(moment(a).calendar(), 'Aujourd’hui à 12:00', 'Today at the same time');
23261 assert.equal(moment(a).add({m: 25}).calendar(), 'Aujourd’hui à 12:25', 'Now plus 25 min');
23262 assert.equal(moment(a).add({h: 1}).calendar(), 'Aujourd’hui à 13:00', 'Now plus 1 hour');
23263 assert.equal(moment(a).add({d: 1}).calendar(), 'Demain à 12:00', 'Tomorrow at the same time');
23264 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Aujourd’hui à 11:00', 'Now minus 1 hour');
23265 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Hier à 12:00', 'Yesterday at the same time');
db71a655
KM
23266 });
23267
96d0d679 23268 test('same next week', function (assert) {
db71a655 23269 var i, m;
96d0d679 23270
db71a655
KM
23271 for (i = 2; i < 7; i++) {
23272 m = moment().add({d: i});
96d0d679 23273 assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days current time');
db71a655 23274 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 23275 assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days beginning of day');
db71a655 23276 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 23277 assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days end of day');
c74a101d 23278 }
db71a655 23279 });
c74a101d 23280
96d0d679 23281 test('same last week', function (assert) {
db71a655 23282 var i, m;
96d0d679 23283
db71a655
KM
23284 for (i = 2; i < 7; i++) {
23285 m = moment().subtract({d: i});
96d0d679 23286 assert.equal(m.calendar(), m.format('dddd [dernier à] LT'), 'Today - ' + i + ' days current time');
db71a655 23287 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 23288 assert.equal(m.calendar(), m.format('dddd [dernier à] LT'), 'Today - ' + i + ' days beginning of day');
db71a655 23289 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 23290 assert.equal(m.calendar(), m.format('dddd [dernier à] LT'), 'Today - ' + i + ' days end of day');
c74a101d 23291 }
db71a655 23292 });
c74a101d 23293
96d0d679 23294 test('same all else', function (assert) {
db71a655
KM
23295 var weeksAgo = moment().subtract({w: 1}),
23296 weeksFromNow = moment().add({w: 1});
c74a101d 23297
96d0d679
KM
23298 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
23299 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
c74a101d 23300
db71a655
KM
23301 weeksAgo = moment().subtract({w: 2});
23302 weeksFromNow = moment().add({w: 2});
c74a101d 23303
96d0d679
KM
23304 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
23305 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
db71a655
KM
23306 });
23307
23308 test('weeks year starting sunday formatted', function (assert) {
96d0d679
KM
23309 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52e', 'Jan 1 2012 should be week 52');
23310 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1re', 'Jan 2 2012 should be week 1');
23311 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1re', 'Jan 8 2012 should be week 1');
23312 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2e', 'Jan 9 2012 should be week 2');
23313 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2e', 'Jan 15 2012 should be week 2');
db71a655 23314 });
7c4c091b
KM
23315
23316})));
23317
23318
23319;(function (global, factory) {
23320 typeof exports === 'object' && typeof module !== 'undefined'
23321 && typeof require === 'function' ? factory(require('../../moment')) :
23322 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
23323 factory(global.moment)
23324}(this, (function (moment) { 'use strict';
23325
db71a655
KM
23326 function each(array, callback) {
23327 var i;
23328 for (i = 0; i < array.length; i++) {
23329 callback(array[i], i, array);
23330 }
7c4c091b 23331 }
7c4c091b 23332
c58511b9
KM
23333 function setupDeprecationHandler(test, moment$$1, scope) {
23334 test._expectedDeprecations = null;
23335 test._observedDeprecations = null;
23336 test._oldSupress = moment$$1.suppressDeprecationWarnings;
23337 moment$$1.suppressDeprecationWarnings = true;
23338 test.expectedDeprecations = function () {
23339 test._expectedDeprecations = arguments;
23340 test._observedDeprecations = [];
23341 };
23342 moment$$1.deprecationHandler = function (name, msg) {
23343 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
23344 if (deprecationId === -1) {
23345 throw new Error('Unexpected deprecation thrown name=' +
23346 name + ' msg=' + msg);
23347 }
23348 test._observedDeprecations[deprecationId] = 1;
23349 };
23350 }
23351
23352 function teardownDeprecationHandler(test, moment$$1, scope) {
23353 moment$$1.suppressDeprecationWarnings = test._oldSupress;
23354
23355 if (test._expectedDeprecations != null) {
23356 var missedDeprecations = [];
23357 each(test._expectedDeprecations, function (deprecationPattern, id) {
23358 if (test._observedDeprecations[id] !== 1) {
23359 missedDeprecations.push(deprecationPattern);
23360 }
23361 });
23362 if (missedDeprecations.length !== 0) {
23363 throw new Error('Expected deprecation warnings did not happen: ' +
23364 missedDeprecations.join(' '));
23365 }
23366 }
23367 }
23368
23369 function matchedDeprecation(name, msg, deprecations) {
23370 if (deprecations == null) {
23371 return -1;
23372 }
23373 for (var i = 0; i < deprecations.length; ++i) {
23374 if (name != null && name === deprecations[i]) {
23375 return i;
23376 }
23377 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
23378 return i;
23379 }
23380 }
23381 return -1;
23382 }
23383
23384 /*global QUnit:false*/
23385
23386 var test = QUnit.test;
23387
db71a655
KM
23388 function objectKeys(obj) {
23389 if (Object.keys) {
23390 return Object.keys(obj);
23391 } else {
23392 // IE8
23393 var res = [], i;
23394 for (i in obj) {
23395 if (obj.hasOwnProperty(i)) {
23396 res.push(i);
23397 }
7c4c091b 23398 }
db71a655 23399 return res;
7c4c091b 23400 }
7c4c091b 23401 }
7c4c091b 23402
db71a655 23403 // Pick the first defined of two or three arguments.
7c4c091b 23404
db71a655
KM
23405 function defineCommonLocaleTests(locale, options) {
23406 test('lenient day of month ordinal parsing', function (assert) {
23407 var i, ordinalStr, testMoment;
23408 for (i = 1; i <= 31; ++i) {
23409 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
23410 testMoment = moment(ordinalStr, 'YYYY MM Do');
23411 assert.equal(testMoment.year(), 2014,
23412 'lenient day of month ordinal parsing ' + i + ' year check');
23413 assert.equal(testMoment.month(), 0,
23414 'lenient day of month ordinal parsing ' + i + ' month check');
23415 assert.equal(testMoment.date(), i,
23416 'lenient day of month ordinal parsing ' + i + ' date check');
23417 }
23418 });
7c4c091b 23419
db71a655
KM
23420 test('lenient day of month ordinal parsing of number', function (assert) {
23421 var i, testMoment;
23422 for (i = 1; i <= 31; ++i) {
23423 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
23424 assert.equal(testMoment.year(), 2014,
23425 'lenient day of month ordinal parsing of number ' + i + ' year check');
23426 assert.equal(testMoment.month(), 0,
23427 'lenient day of month ordinal parsing of number ' + i + ' month check');
23428 assert.equal(testMoment.date(), i,
23429 'lenient day of month ordinal parsing of number ' + i + ' date check');
23430 }
7c4c091b 23431 });
7c4c091b 23432
db71a655
KM
23433 test('strict day of month ordinal parsing', function (assert) {
23434 var i, ordinalStr, testMoment;
23435 for (i = 1; i <= 31; ++i) {
23436 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
23437 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
23438 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
23439 }
23440 });
7c4c091b 23441
db71a655
KM
23442 test('meridiem invariant', function (assert) {
23443 var h, m, t1, t2;
23444 for (h = 0; h < 24; ++h) {
23445 for (m = 0; m < 60; m += 15) {
23446 t1 = moment.utc([2000, 0, 1, h, m]);
23447 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
23448 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
23449 'meridiem at ' + t1.format('HH:mm'));
23450 }
23451 }
23452 });
7c4c091b 23453
db71a655
KM
23454 test('date format correctness', function (assert) {
23455 var data, tokens;
23456 data = moment.localeData()._longDateFormat;
23457 tokens = objectKeys(data);
23458 each(tokens, function (srchToken) {
23459 // Check each format string to make sure it does not contain any
23460 // tokens that need to be expanded.
23461 each(tokens, function (baseToken) {
23462 // strip escaped sequences
23463 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
23464 assert.equal(false, !!~format.indexOf(srchToken),
23465 'contains ' + srchToken + ' in ' + baseToken);
23466 });
23467 });
23468 });
7c4c091b 23469
db71a655
KM
23470 test('month parsing correctness', function (assert) {
23471 var i, m;
23472
23473 if (locale === 'tr') {
23474 // I can't fix it :(
c58511b9 23475 assert.expect(0);
db71a655
KM
23476 return;
23477 }
23478 function tester(format) {
23479 var r;
23480 r = moment(m.format(format), format);
23481 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
23482 if (locale !== 'ka') {
23483 r = moment(m.format(format).toLocaleUpperCase(), format);
23484 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
23485 }
db71a655
KM
23486 r = moment(m.format(format).toLocaleLowerCase(), format);
23487 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
23488
23489 r = moment(m.format(format), format, true);
23490 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
23491 if (locale !== 'ka') {
23492 r = moment(m.format(format).toLocaleUpperCase(), format, true);
23493 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
23494 }
db71a655
KM
23495 r = moment(m.format(format).toLocaleLowerCase(), format, true);
23496 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
23497 }
23498
23499 for (i = 0; i < 12; ++i) {
23500 m = moment([2015, i, 15, 18]);
23501 tester('MMM');
23502 tester('MMM.');
23503 tester('MMMM');
23504 tester('MMMM.');
23505 }
23506 });
7c4c091b 23507
db71a655
KM
23508 test('weekday parsing correctness', function (assert) {
23509 var i, m;
23510
96d0d679 23511 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
23512 // tr, az: There is a lower-case letter (ı), that converted to
23513 // upper then lower changes to i
23514 // ro: there is the letter ț which behaves weird under IE8
23515 // mt: letter Ħ
96d0d679 23516 // ga: month with spaces
c58511b9 23517 assert.expect(0);
db71a655
KM
23518 return;
23519 }
23520 function tester(format) {
23521 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
23522 r = moment(m.format(format), format);
23523 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
23524 if (locale !== 'ka') {
23525 r = moment(m.format(format).toLocaleUpperCase(), format);
23526 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
23527 }
db71a655
KM
23528 r = moment(m.format(format).toLocaleLowerCase(), format);
23529 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
23530 r = moment(m.format(format), format, true);
23531 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
23532 if (locale !== 'ka') {
23533 r = moment(m.format(format).toLocaleUpperCase(), format, true);
23534 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
23535 }
db71a655
KM
23536 r = moment(m.format(format).toLocaleLowerCase(), format, true);
23537 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
23538 }
23539
23540 for (i = 0; i < 7; ++i) {
23541 m = moment.utc([2015, 0, i + 1, 18]);
23542 tester('dd');
23543 tester('ddd');
23544 tester('dddd');
23545 }
23546 });
7c4c091b 23547
db71a655
KM
23548 test('valid localeData', function (assert) {
23549 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
23550 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
23551 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
23552 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
23553 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
23554 });
96d0d679
KM
23555
23556 test('localeData weekdays can localeSort', function (assert) {
23557 var weekdays = moment().localeData().weekdays();
23558 var weekdaysShort = moment().localeData().weekdaysShort();
23559 var weekdaysMin = moment().localeData().weekdaysMin();
23560 var shift = moment().localeData()._week.dow;
23561 assert.deepEqual(
23562 moment().localeData().weekdays(true),
23563 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
23564 'weekdays should localeSort');
23565 assert.deepEqual(
23566 moment().localeData().weekdaysShort(true),
23567 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
23568 'weekdaysShort should localeSort');
23569 assert.deepEqual(
23570 moment().localeData().weekdaysMin(true),
23571 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
23572 'weekdaysMin should localeSort');
23573 });
23574 }
23575
23576 /*global QUnit:false*/
23577
23578 function localeModule (name, lifecycle) {
23579 QUnit.module('locale:' + name, {
23580 beforeEach : function () {
23581 moment.locale(name);
23582 moment.createFromInputFallback = function (config) {
23583 throw new Error('input not handled by moment: ' + config._i);
23584 };
23585 setupDeprecationHandler(test, moment, 'locale');
23586 if (lifecycle && lifecycle.setup) {
23587 lifecycle.setup();
23588 }
23589 },
23590 afterEach : function () {
23591 moment.locale('en');
23592 teardownDeprecationHandler(test, moment, 'locale');
23593 if (lifecycle && lifecycle.teardown) {
23594 lifecycle.teardown();
23595 }
23596 }
23597 });
23598 defineCommonLocaleTests(name, -1, -1);
23599 }
23600
23601 localeModule('fy');
23602
23603 test('parse', function (assert) {
23604 var tests = 'jannewaris jan._febrewaris feb._maart mrt._april apr._maaie mai._juny jun._july jul._augustus aug._septimber sep._oktober okt._novimber nov._desimber des.'.split('_'), i;
23605 function equalTest(input, mmm, i) {
23606 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
23607 }
23608 for (i = 0; i < 12; i++) {
23609 tests[i] = tests[i].split(' ');
23610 equalTest(tests[i][0], 'MMM', i);
23611 equalTest(tests[i][1], 'MMM', i);
23612 equalTest(tests[i][0], 'MMMM', i);
23613 equalTest(tests[i][1], 'MMMM', i);
23614 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
23615 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
23616 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
23617 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
23618 }
23619 });
23620
23621 test('format', function (assert) {
23622 var a = [
23623 ['dddd, MMMM Do YYYY, HH:mm:ss', 'snein, febrewaris 14de 2010, 15:25:50'],
23624 ['ddd, HH', 'si., 15'],
23625 ['M Mo MM MMMM MMM', '2 2de 02 febrewaris feb.'],
23626 ['YYYY YY', '2010 10'],
23627 ['D Do DD', '14 14de 14'],
23628 ['d do dddd ddd dd', '0 0de snein si. Si'],
23629 ['DDD DDDo DDDD', '45 45ste 045'],
23630 ['w wo ww', '6 6de 06'],
23631 ['h hh', '3 03'],
23632 ['H HH', '15 15'],
23633 ['m mm', '25 25'],
23634 ['s ss', '50 50'],
23635 ['a A', 'pm PM'],
23636 ['[the] DDDo [day of the year]', 'the 45ste day of the year'],
23637 ['LTS', '15:25:50'],
23638 ['L', '14-02-2010'],
23639 ['LL', '14 febrewaris 2010'],
23640 ['LLL', '14 febrewaris 2010 15:25'],
23641 ['LLLL', 'snein 14 febrewaris 2010 15:25'],
23642 ['l', '14-2-2010'],
23643 ['ll', '14 feb. 2010'],
23644 ['lll', '14 feb. 2010 15:25'],
23645 ['llll', 'si. 14 feb. 2010 15:25']
23646 ],
23647 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
23648 i;
23649 for (i = 0; i < a.length; i++) {
23650 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
23651 }
23652 });
23653
23654 test('format ordinal', function (assert) {
23655 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1ste', '1ste');
23656 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2de', '2de');
23657 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3de', '3de');
23658 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4de', '4de');
23659 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5de', '5de');
23660 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6de', '6de');
23661 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7de', '7de');
23662 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8ste', '8ste');
23663 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9de', '9de');
23664 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10de', '10de');
23665
23666 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11de', '11de');
23667 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12de', '12de');
23668 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13de', '13de');
23669 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14de', '14de');
23670 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15de', '15de');
23671 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16de', '16de');
23672 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17de', '17de');
23673 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18de', '18de');
23674 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19de', '19de');
23675 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20ste', '20ste');
23676
23677 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21ste', '21ste');
23678 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22ste', '22ste');
23679 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23ste', '23ste');
23680 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24ste', '24ste');
23681 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25ste', '25ste');
23682 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26ste', '26ste');
23683 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27ste', '27ste');
23684 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28ste', '28ste');
23685 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29ste', '29ste');
23686 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30ste', '30ste');
23687
23688 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31ste', '31ste');
23689 });
23690
23691 test('format month', function (assert) {
23692 var expected = 'jannewaris jan._febrewaris feb._maart mrt._april apr._maaie mai_juny jun._july jul._augustus aug._septimber sep._oktober okt._novimber nov._desimber des.'.split('_'), i;
23693 for (i = 0; i < expected.length; i++) {
23694 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
23695 }
23696 });
23697
23698 test('format week', function (assert) {
23699 var expected = 'snein si. Si_moandei mo. Mo_tiisdei ti. Ti_woansdei wo. Wo_tongersdei to. To_freed fr. Fr_sneon so. So'.split('_'), i;
23700 for (i = 0; i < expected.length; i++) {
23701 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
23702 }
23703 });
23704
23705 test('from', function (assert) {
23706 var start = moment([2007, 1, 28]);
23707 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'in pear sekonden', '44 seconds = a few seconds');
23708 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ien minút', '45 seconds = a minute');
23709 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ien minút', '89 seconds = a minute');
23710 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuten', '90 seconds = 2 minutes');
23711 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuten', '44 minutes = 44 minutes');
23712 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ien oere', '45 minutes = an hour');
23713 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ien oere', '89 minutes = an hour');
23714 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 oeren', '90 minutes = 2 hours');
23715 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 oeren', '5 hours = 5 hours');
23716 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 oeren', '21 hours = 21 hours');
23717 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ien dei', '22 hours = a day');
23718 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ien dei', '35 hours = a day');
23719 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dagen', '36 hours = 2 days');
23720 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ien dei', '1 day = a day');
23721 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dagen', '5 days = 5 days');
23722 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dagen', '25 days = 25 days');
23723 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ien moanne', '26 days = a month');
23724 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ien moanne', '30 days = a month');
23725 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ien moanne', '43 days = a month');
23726 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 moannen', '46 days = 2 months');
23727 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 moannen', '75 days = 2 months');
23728 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 moannen', '76 days = 3 months');
23729 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ien moanne', '1 month = a month');
23730 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 moannen', '5 months = 5 months');
23731 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ien jier', '345 days = a year');
23732 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 jierren', '548 days = 2 years');
23733 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ien jier', '1 year = a year');
23734 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 jierren', '5 years = 5 years');
23735 });
23736
23737 test('suffix', function (assert) {
23738 assert.equal(moment(30000).from(0), 'oer in pear sekonden', 'prefix');
23739 assert.equal(moment(0).from(30000), 'in pear sekonden lyn', 'suffix');
23740 });
23741
23742 test('now from now', function (assert) {
23743 assert.equal(moment().fromNow(), 'in pear sekonden lyn', 'now from now should display as in the past');
23744 });
23745
23746 test('fromNow', function (assert) {
23747 assert.equal(moment().add({s: 30}).fromNow(), 'oer in pear sekonden', 'in a few seconds');
23748 assert.equal(moment().add({d: 5}).fromNow(), 'oer 5 dagen', 'in 5 days');
23749 });
23750
23751 test('calendar day', function (assert) {
23752 var a = moment().hours(12).minutes(0).seconds(0);
23753
23754 assert.equal(moment(a).calendar(), 'hjoed om 12:00', 'today at the same time');
23755 assert.equal(moment(a).add({m: 25}).calendar(), 'hjoed om 12:25', 'Now plus 25 min');
23756 assert.equal(moment(a).add({h: 1}).calendar(), 'hjoed om 13:00', 'Now plus 1 hour');
23757 assert.equal(moment(a).add({d: 1}).calendar(), 'moarn om 12:00', 'tomorrow at the same time');
23758 assert.equal(moment(a).subtract({h: 1}).calendar(), 'hjoed om 11:00', 'Now minus 1 hour');
23759 assert.equal(moment(a).subtract({d: 1}).calendar(), 'juster om 12:00', 'yesterday at the same time');
23760 });
23761
23762 test('calendar next week', function (assert) {
23763 var i, m;
23764 for (i = 2; i < 7; i++) {
23765 m = moment().add({d: i});
23766 assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days current time');
23767 m.hours(0).minutes(0).seconds(0).milliseconds(0);
23768 assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days beginning of day');
23769 m.hours(23).minutes(59).seconds(59).milliseconds(999);
23770 assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days end of day');
23771 }
23772 });
23773
23774 test('calendar last week', function (assert) {
23775 var i, m;
23776 for (i = 2; i < 7; i++) {
23777 m = moment().subtract({d: i});
23778 assert.equal(m.calendar(), m.format('[ôfrûne] dddd [om] LT'), 'Today - ' + i + ' days current time');
23779 m.hours(0).minutes(0).seconds(0).milliseconds(0);
23780 assert.equal(m.calendar(), m.format('[ôfrûne] dddd [om] LT'), 'Today - ' + i + ' days beginning of day');
23781 m.hours(23).minutes(59).seconds(59).milliseconds(999);
23782 assert.equal(m.calendar(), m.format('[ôfrûne] dddd [om] LT'), 'Today - ' + i + ' days end of day');
23783 }
23784 });
23785
23786 test('calendar all else', function (assert) {
23787 var weeksAgo = moment().subtract({w: 1}),
23788 weeksFromNow = moment().add({w: 1});
23789
23790 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
23791 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
23792
23793 weeksAgo = moment().subtract({w: 2});
23794 weeksFromNow = moment().add({w: 2});
23795
23796 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
23797 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
23798 });
23799
23800 test('month abbreviation', function (assert) {
23801 assert.equal(moment([2012, 5, 23]).format('D-MMM-YYYY'), '23-jun-2012', 'format month abbreviation surrounded by dashes should not include a dot');
23802 assert.equal(moment([2012, 5, 23]).format('D MMM YYYY'), '23 jun. 2012', 'format month abbreviation not surrounded by dashes should include a dot');
23803 });
23804
23805 test('weeks year starting sunday formatted', function (assert) {
23806 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52ste', 'Jan 1 2012 should be week 52');
23807 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1ste', 'Jan 2 2012 should be week 1');
23808 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1ste', 'Jan 8 2012 should be week 1');
23809 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2de', 'Jan 9 2012 should be week 2');
23810 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2de', 'Jan 15 2012 should be week 2');
23811 });
23812
23813})));
23814
23815
23816;(function (global, factory) {
23817 typeof exports === 'object' && typeof module !== 'undefined'
23818 && typeof require === 'function' ? factory(require('../../moment')) :
23819 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
23820 factory(global.moment)
23821}(this, (function (moment) { 'use strict';
23822
23823 function each(array, callback) {
23824 var i;
23825 for (i = 0; i < array.length; i++) {
23826 callback(array[i], i, array);
23827 }
23828 }
23829
23830 function setupDeprecationHandler(test, moment$$1, scope) {
23831 test._expectedDeprecations = null;
23832 test._observedDeprecations = null;
23833 test._oldSupress = moment$$1.suppressDeprecationWarnings;
23834 moment$$1.suppressDeprecationWarnings = true;
23835 test.expectedDeprecations = function () {
23836 test._expectedDeprecations = arguments;
23837 test._observedDeprecations = [];
23838 };
23839 moment$$1.deprecationHandler = function (name, msg) {
23840 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
23841 if (deprecationId === -1) {
23842 throw new Error('Unexpected deprecation thrown name=' +
23843 name + ' msg=' + msg);
23844 }
23845 test._observedDeprecations[deprecationId] = 1;
23846 };
23847 }
23848
23849 function teardownDeprecationHandler(test, moment$$1, scope) {
23850 moment$$1.suppressDeprecationWarnings = test._oldSupress;
23851
23852 if (test._expectedDeprecations != null) {
23853 var missedDeprecations = [];
23854 each(test._expectedDeprecations, function (deprecationPattern, id) {
23855 if (test._observedDeprecations[id] !== 1) {
23856 missedDeprecations.push(deprecationPattern);
23857 }
23858 });
23859 if (missedDeprecations.length !== 0) {
23860 throw new Error('Expected deprecation warnings did not happen: ' +
23861 missedDeprecations.join(' '));
23862 }
23863 }
23864 }
23865
23866 function matchedDeprecation(name, msg, deprecations) {
23867 if (deprecations == null) {
23868 return -1;
23869 }
23870 for (var i = 0; i < deprecations.length; ++i) {
23871 if (name != null && name === deprecations[i]) {
23872 return i;
23873 }
23874 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
23875 return i;
23876 }
23877 }
23878 return -1;
23879 }
23880
23881 /*global QUnit:false*/
23882
23883 var test = QUnit.test;
23884
23885 function objectKeys(obj) {
23886 if (Object.keys) {
23887 return Object.keys(obj);
23888 } else {
23889 // IE8
23890 var res = [], i;
23891 for (i in obj) {
23892 if (obj.hasOwnProperty(i)) {
23893 res.push(i);
23894 }
23895 }
23896 return res;
23897 }
23898 }
23899
23900 // Pick the first defined of two or three arguments.
23901
23902 function defineCommonLocaleTests(locale, options) {
23903 test('lenient day of month ordinal parsing', function (assert) {
23904 var i, ordinalStr, testMoment;
23905 for (i = 1; i <= 31; ++i) {
23906 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
23907 testMoment = moment(ordinalStr, 'YYYY MM Do');
23908 assert.equal(testMoment.year(), 2014,
23909 'lenient day of month ordinal parsing ' + i + ' year check');
23910 assert.equal(testMoment.month(), 0,
23911 'lenient day of month ordinal parsing ' + i + ' month check');
23912 assert.equal(testMoment.date(), i,
23913 'lenient day of month ordinal parsing ' + i + ' date check');
23914 }
23915 });
23916
23917 test('lenient day of month ordinal parsing of number', function (assert) {
23918 var i, testMoment;
23919 for (i = 1; i <= 31; ++i) {
23920 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
23921 assert.equal(testMoment.year(), 2014,
23922 'lenient day of month ordinal parsing of number ' + i + ' year check');
23923 assert.equal(testMoment.month(), 0,
23924 'lenient day of month ordinal parsing of number ' + i + ' month check');
23925 assert.equal(testMoment.date(), i,
23926 'lenient day of month ordinal parsing of number ' + i + ' date check');
23927 }
23928 });
23929
23930 test('strict day of month ordinal parsing', function (assert) {
23931 var i, ordinalStr, testMoment;
23932 for (i = 1; i <= 31; ++i) {
23933 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
23934 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
23935 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
23936 }
23937 });
23938
23939 test('meridiem invariant', function (assert) {
23940 var h, m, t1, t2;
23941 for (h = 0; h < 24; ++h) {
23942 for (m = 0; m < 60; m += 15) {
23943 t1 = moment.utc([2000, 0, 1, h, m]);
23944 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
23945 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
23946 'meridiem at ' + t1.format('HH:mm'));
23947 }
23948 }
23949 });
23950
23951 test('date format correctness', function (assert) {
23952 var data, tokens;
23953 data = moment.localeData()._longDateFormat;
23954 tokens = objectKeys(data);
23955 each(tokens, function (srchToken) {
23956 // Check each format string to make sure it does not contain any
23957 // tokens that need to be expanded.
23958 each(tokens, function (baseToken) {
23959 // strip escaped sequences
23960 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
23961 assert.equal(false, !!~format.indexOf(srchToken),
23962 'contains ' + srchToken + ' in ' + baseToken);
23963 });
23964 });
23965 });
23966
23967 test('month parsing correctness', function (assert) {
23968 var i, m;
23969
23970 if (locale === 'tr') {
23971 // I can't fix it :(
23972 assert.expect(0);
23973 return;
23974 }
23975 function tester(format) {
23976 var r;
23977 r = moment(m.format(format), format);
23978 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
23979 if (locale !== 'ka') {
23980 r = moment(m.format(format).toLocaleUpperCase(), format);
23981 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
23982 }
23983 r = moment(m.format(format).toLocaleLowerCase(), format);
23984 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
23985
23986 r = moment(m.format(format), format, true);
23987 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
23988 if (locale !== 'ka') {
23989 r = moment(m.format(format).toLocaleUpperCase(), format, true);
23990 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
23991 }
23992 r = moment(m.format(format).toLocaleLowerCase(), format, true);
23993 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
23994 }
23995
23996 for (i = 0; i < 12; ++i) {
23997 m = moment([2015, i, 15, 18]);
23998 tester('MMM');
23999 tester('MMM.');
24000 tester('MMMM');
24001 tester('MMMM.');
24002 }
24003 });
24004
24005 test('weekday parsing correctness', function (assert) {
24006 var i, m;
24007
24008 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
24009 // tr, az: There is a lower-case letter (ı), that converted to
24010 // upper then lower changes to i
24011 // ro: there is the letter ț which behaves weird under IE8
24012 // mt: letter Ħ
24013 // ga: month with spaces
24014 assert.expect(0);
24015 return;
24016 }
24017 function tester(format) {
24018 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
24019 r = moment(m.format(format), format);
24020 assert.equal(r.weekday(), m.weekday(), baseMsg);
24021 if (locale !== 'ka') {
24022 r = moment(m.format(format).toLocaleUpperCase(), format);
24023 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
24024 }
24025 r = moment(m.format(format).toLocaleLowerCase(), format);
24026 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
24027 r = moment(m.format(format), format, true);
24028 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
24029 if (locale !== 'ka') {
24030 r = moment(m.format(format).toLocaleUpperCase(), format, true);
24031 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
24032 }
24033 r = moment(m.format(format).toLocaleLowerCase(), format, true);
24034 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
24035 }
24036
24037 for (i = 0; i < 7; ++i) {
24038 m = moment.utc([2015, 0, i + 1, 18]);
24039 tester('dd');
24040 tester('ddd');
24041 tester('dddd');
24042 }
24043 });
24044
24045 test('valid localeData', function (assert) {
24046 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
24047 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
24048 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
24049 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
24050 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
24051 });
24052
24053 test('localeData weekdays can localeSort', function (assert) {
24054 var weekdays = moment().localeData().weekdays();
24055 var weekdaysShort = moment().localeData().weekdaysShort();
24056 var weekdaysMin = moment().localeData().weekdaysMin();
24057 var shift = moment().localeData()._week.dow;
24058 assert.deepEqual(
24059 moment().localeData().weekdays(true),
24060 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
24061 'weekdays should localeSort');
24062 assert.deepEqual(
24063 moment().localeData().weekdaysShort(true),
24064 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
24065 'weekdaysShort should localeSort');
24066 assert.deepEqual(
24067 moment().localeData().weekdaysMin(true),
24068 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
24069 'weekdaysMin should localeSort');
24070 });
24071 }
24072
24073 /*global QUnit:false*/
24074
24075 function localeModule (name, lifecycle) {
24076 QUnit.module('locale:' + name, {
24077 beforeEach : function () {
24078 moment.locale(name);
24079 moment.createFromInputFallback = function (config) {
24080 throw new Error('input not handled by moment: ' + config._i);
24081 };
24082 setupDeprecationHandler(test, moment, 'locale');
24083 if (lifecycle && lifecycle.setup) {
24084 lifecycle.setup();
24085 }
24086 },
24087 afterEach : function () {
24088 moment.locale('en');
24089 teardownDeprecationHandler(test, moment, 'locale');
24090 if (lifecycle && lifecycle.teardown) {
24091 lifecycle.teardown();
24092 }
24093 }
24094 });
24095 defineCommonLocaleTests(name, -1, -1);
24096 }
24097
24098 localeModule('ga');
24099
24100 var months = [
24101 'Eanáir,Eaná',
24102 'Feabhra,Feab',
24103 'Márta,Márt',
24104 'Aibreán,Aibr',
24105 'Bealtaine,Beal',
24106 'Méitheamh,Méit',
24107 'Iúil,Iúil',
24108 'Lúnasa,Lúna',
24109 'Meán Fómhair,Meán',
24110 'Deaireadh Fómhair,Deai',
24111 'Samhain,Samh',
24112 'Nollaig,Noll'
24113 ];
24114
24115 test('parse', function (assert) {
24116 function equalTest(monthName, monthFormat, monthNum) {
24117 assert.equal(moment(monthName, monthFormat).month(), monthNum, monthName + ' should be month ' + (monthNum + 1));
24118 }
24119
24120 for (var i = 0; i < 12; i++) {
24121 var testMonth = months[i].split(',');
24122 equalTest(testMonth[0], 'MMM', i);
24123 equalTest(testMonth[1], 'MMM', i);
24124 equalTest(testMonth[0], 'MMMM', i);
24125 equalTest(testMonth[1], 'MMMM', i);
24126 equalTest(testMonth[0].toLocaleLowerCase(), 'MMMM', i);
24127 equalTest(testMonth[1].toLocaleLowerCase(), 'MMMM', i);
24128 equalTest(testMonth[0].toLocaleUpperCase(), 'MMMM', i);
24129 equalTest(testMonth[1].toLocaleUpperCase(), 'MMMM', i);
24130 }
24131 });
24132
24133 test('format', function (assert) {
24134 var a = [
24135 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Dé Domhnaigh, Feabhra 14mh 2010, 3:25:50 pm'],
24136 ['ddd, hA', 'Dom, 3PM'],
24137 ['M Mo MM MMMM MMM', '2 2na 02 Feabhra Feab'],
24138 ['YYYY YY', '2010 10'],
24139 ['D Do DD', '14 14mh 14'],
24140 ['d do dddd ddd dd', '0 0mh Dé Domhnaigh Dom Do'],
24141 ['DDD DDDo DDDD', '45 45mh 045'],
24142 ['w wo ww', '6 6mh 06'],
24143 ['h hh', '3 03'],
24144 ['H HH', '15 15'],
24145 ['m mm', '25 25'],
24146 ['s ss', '50 50'],
24147 ['a A', 'pm PM'],
24148 ['[an] DDDo [latha den bhliadhna]', 'an 45mh latha den bhliadhna'],
24149 ['LTS', '15:25:50'],
24150 ['L', '14/02/2010'],
24151 ['LL', '14 Feabhra 2010'],
24152 ['LLL', '14 Feabhra 2010 15:25'],
24153 ['LLLL', 'Dé Domhnaigh, 14 Feabhra 2010 15:25'],
24154 ['l', '14/2/2010'],
24155 ['ll', '14 Feab 2010'],
24156 ['lll', '14 Feab 2010 15:25'],
24157 ['llll', 'Dom, 14 Feab 2010 15:25']
24158 ],
24159 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
24160 i;
24161 for (i = 0; i < a.length; i++) {
24162 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
24163 }
24164 });
24165
24166 test('format ordinal', function (assert) {
24167 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1d', '1d');
24168 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2na', '2na');
24169 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3mh', '3mh');
24170 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4mh', '4mh');
24171 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5mh', '5mh');
24172 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6mh', '6mh');
24173 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7mh', '7mh');
24174 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8mh', '8mh');
24175 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9mh', '9mh');
24176 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10mh', '10mh');
24177 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11mh', '11mh');
24178 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12na', '12na');
24179 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13mh', '13mh');
24180 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14mh', '14mh');
24181 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15mh', '15mh');
24182 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16mh', '16mh');
24183 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17mh', '17mh');
24184 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18mh', '18mh');
24185 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19mh', '19mh');
24186 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20mh', '20mh');
24187 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21mh', '21mh');
24188 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22na', '22na');
24189 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23mh', '23mh');
24190 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24mh', '24mh');
24191 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25mh', '25mh');
24192 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26mh', '26mh');
24193 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27mh', '27mh');
24194 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28mh', '28mh');
24195 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29mh', '29mh');
24196 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30mh', '30mh');
24197 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31mh', '31mh');
24198 });
24199
24200 test('format month', function (assert) {
24201 var expected = months;
24202 for (var i = 0; i < expected.length; i++) {
24203 assert.equal(moment([2011, i, 1]).format('MMMM,MMM'), expected[i], expected[i]);
24204 }
24205 });
24206
24207 test('format week', function (assert) {
24208 var expected = ['Dé Domhnaigh Dom Do', 'Dé Luain Lua Lu', 'Dé Máirt Mái Má', 'Dé Céadaoin Céa Ce', 'Déardaoin Déa Dé', 'Dé hAoine hAo hA', 'Dé Satharn Sat Sa'];
24209 for (var i = 0; i < expected.length; i++) {
24210 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
24211 }
24212 });
24213
24214 test('from', function (assert) {
24215 var start = moment([2007, 1, 28]);
24216 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'cúpla soicind', '44 seconds = a few seconds');
24217 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'nóiméad', '45 seconds = a minute');
24218 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'nóiméad', '89 seconds = a minute');
24219 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 nóiméad', '90 seconds = 2 minutes');
24220 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 nóiméad', '44 minutes = 44 minutes');
24221 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'uair an chloig', '45 minutes = an hour');
24222 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'uair an chloig', '89 minutes = an hour');
24223 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 uair an chloig', '90 minutes = 2 hours');
24224 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 uair an chloig', '5 hours = 5 hours');
24225 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 uair an chloig', '21 hours = 21 hours');
24226 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'lá', '22 hours = a day');
24227 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'lá', '35 hours = a day');
24228 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 lá', '36 hours = 2 days');
24229 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'lá', '1 day = a day');
24230 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 lá', '5 days = 5 days');
24231 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 lá', '25 days = 25 days');
24232 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mí', '26 days = a month');
24233 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mí', '30 days = a month');
24234 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mí', '43 days = a month');
24235 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mí', '46 days = 2 months');
24236 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mí', '75 days = 2 months');
24237 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mí', '76 days = 3 months');
24238 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mí', '1 month = a month');
24239 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mí', '5 months = 5 months');
24240 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'bliain', '345 days = a year');
24241 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 bliain', '548 days = 2 years');
24242 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'bliain', '1 year = a year');
24243 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 bliain', '5 years = 5 years');
24244 });
24245
24246 test('suffix', function (assert) {
24247 assert.equal(moment(30000).from(0), 'i cúpla soicind', 'prefix');
24248 assert.equal(moment(0).from(30000), 'cúpla soicind ó shin', 'suffix');
24249 });
24250
24251 test('now from now', function (assert) {
24252 assert.equal(moment().fromNow(), 'cúpla soicind ó shin', 'now from now should display as in the past');
24253 });
24254
24255 test('fromNow', function (assert) {
24256 assert.equal(moment().add({s: 30}).fromNow(), 'i cúpla soicind', 'in a few seconds');
24257 assert.equal(moment().add({d: 5}).fromNow(), 'i 5 lá', 'in 5 days');
24258 });
24259
24260 test('calendar day', function (assert) {
24261 var a = moment().hours(12).minutes(0).seconds(0);
24262
24263 assert.equal(moment(a).calendar(), 'Inniu ag 12:00', 'today at the same time');
24264 assert.equal(moment(a).add({m: 25}).calendar(), 'Inniu ag 12:25', 'Now plus 25 min');
24265 assert.equal(moment(a).add({h: 1}).calendar(), 'Inniu ag 13:00', 'Now plus 1 hour');
24266 assert.equal(moment(a).add({d: 1}).calendar(), 'Amárach ag 12:00', 'tomorrow at the same time');
24267 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Inniu ag 11:00', 'Now minus 1 hour');
24268 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Inné aig 12:00', 'yesterday at the same time');
24269 });
24270
24271 test('calendar next week', function (assert) {
24272 var i, m;
24273 for (i = 2; i < 7; i++) {
24274 m = moment().add({d: i});
24275 assert.equal(m.calendar(), m.format('dddd [ag] LT'), 'Today + ' + i + ' days current time');
24276 m.hours(0).minutes(0).seconds(0).milliseconds(0);
24277 assert.equal(m.calendar(), m.format('dddd [ag] LT'), 'Today + ' + i + ' days beginning of day');
24278 m.hours(23).minutes(59).seconds(59).milliseconds(999);
24279 assert.equal(m.calendar(), m.format('dddd [ag] LT'), 'Today + ' + i + ' days end of day');
24280 }
24281 });
24282
24283 test('calendar last week', function (assert) {
24284 var i, m;
24285
24286 for (i = 2; i < 7; i++) {
24287 m = moment().subtract({d: i});
24288 assert.equal(m.calendar(), m.format('dddd [seo caite] [ag] LT'), 'Today - ' + i + ' days current time');
24289 m.hours(0).minutes(0).seconds(0).milliseconds(0);
24290 assert.equal(m.calendar(), m.format('dddd [seo caite] [ag] LT'), 'Today - ' + i + ' days beginning of day');
24291 m.hours(23).minutes(59).seconds(59).milliseconds(999);
24292 assert.equal(m.calendar(), m.format('dddd [seo caite] [ag] LT'), 'Today - ' + i + ' days end of day');
24293 }
24294 });
24295
24296 test('calendar all else', function (assert) {
24297 var weeksAgo = moment().subtract({w: 1}),
24298 weeksFromNow = moment().add({w: 1});
24299
24300 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
24301 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
24302
24303 weeksAgo = moment().subtract({w: 2});
24304 weeksFromNow = moment().add({w: 2});
24305
24306 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
24307 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
24308 });
24309
24310 test('weeks year starting sunday formatted', function (assert) {
24311 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52na', 'Eaná 1 2012 should be week 52');
24312 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1d', 'Eaná 2 2012 should be week 1');
24313 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1d', 'Eaná 8 2012 should be week 1');
24314 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2na', 'Eaná 9 2012 should be week 2');
24315 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2na', 'Eaná 15 2012 should be week 2');
24316 });
24317
24318})));
24319
24320
24321;(function (global, factory) {
24322 typeof exports === 'object' && typeof module !== 'undefined'
24323 && typeof require === 'function' ? factory(require('../../moment')) :
24324 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
24325 factory(global.moment)
24326}(this, (function (moment) { 'use strict';
24327
24328 function each(array, callback) {
24329 var i;
24330 for (i = 0; i < array.length; i++) {
24331 callback(array[i], i, array);
24332 }
24333 }
24334
24335 function setupDeprecationHandler(test, moment$$1, scope) {
24336 test._expectedDeprecations = null;
24337 test._observedDeprecations = null;
24338 test._oldSupress = moment$$1.suppressDeprecationWarnings;
24339 moment$$1.suppressDeprecationWarnings = true;
24340 test.expectedDeprecations = function () {
24341 test._expectedDeprecations = arguments;
24342 test._observedDeprecations = [];
24343 };
24344 moment$$1.deprecationHandler = function (name, msg) {
24345 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
24346 if (deprecationId === -1) {
24347 throw new Error('Unexpected deprecation thrown name=' +
24348 name + ' msg=' + msg);
24349 }
24350 test._observedDeprecations[deprecationId] = 1;
24351 };
24352 }
24353
24354 function teardownDeprecationHandler(test, moment$$1, scope) {
24355 moment$$1.suppressDeprecationWarnings = test._oldSupress;
24356
24357 if (test._expectedDeprecations != null) {
24358 var missedDeprecations = [];
24359 each(test._expectedDeprecations, function (deprecationPattern, id) {
24360 if (test._observedDeprecations[id] !== 1) {
24361 missedDeprecations.push(deprecationPattern);
24362 }
24363 });
24364 if (missedDeprecations.length !== 0) {
24365 throw new Error('Expected deprecation warnings did not happen: ' +
24366 missedDeprecations.join(' '));
24367 }
24368 }
24369 }
24370
24371 function matchedDeprecation(name, msg, deprecations) {
24372 if (deprecations == null) {
24373 return -1;
24374 }
24375 for (var i = 0; i < deprecations.length; ++i) {
24376 if (name != null && name === deprecations[i]) {
24377 return i;
24378 }
24379 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
24380 return i;
24381 }
24382 }
24383 return -1;
24384 }
24385
24386 /*global QUnit:false*/
24387
24388 var test = QUnit.test;
24389
24390 function objectKeys(obj) {
24391 if (Object.keys) {
24392 return Object.keys(obj);
24393 } else {
24394 // IE8
24395 var res = [], i;
24396 for (i in obj) {
24397 if (obj.hasOwnProperty(i)) {
24398 res.push(i);
24399 }
24400 }
24401 return res;
24402 }
24403 }
24404
24405 // Pick the first defined of two or three arguments.
24406
24407 function defineCommonLocaleTests(locale, options) {
24408 test('lenient day of month ordinal parsing', function (assert) {
24409 var i, ordinalStr, testMoment;
24410 for (i = 1; i <= 31; ++i) {
24411 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
24412 testMoment = moment(ordinalStr, 'YYYY MM Do');
24413 assert.equal(testMoment.year(), 2014,
24414 'lenient day of month ordinal parsing ' + i + ' year check');
24415 assert.equal(testMoment.month(), 0,
24416 'lenient day of month ordinal parsing ' + i + ' month check');
24417 assert.equal(testMoment.date(), i,
24418 'lenient day of month ordinal parsing ' + i + ' date check');
24419 }
24420 });
24421
24422 test('lenient day of month ordinal parsing of number', function (assert) {
24423 var i, testMoment;
24424 for (i = 1; i <= 31; ++i) {
24425 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
24426 assert.equal(testMoment.year(), 2014,
24427 'lenient day of month ordinal parsing of number ' + i + ' year check');
24428 assert.equal(testMoment.month(), 0,
24429 'lenient day of month ordinal parsing of number ' + i + ' month check');
24430 assert.equal(testMoment.date(), i,
24431 'lenient day of month ordinal parsing of number ' + i + ' date check');
24432 }
24433 });
24434
24435 test('strict day of month ordinal parsing', function (assert) {
24436 var i, ordinalStr, testMoment;
24437 for (i = 1; i <= 31; ++i) {
24438 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
24439 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
24440 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
24441 }
24442 });
24443
24444 test('meridiem invariant', function (assert) {
24445 var h, m, t1, t2;
24446 for (h = 0; h < 24; ++h) {
24447 for (m = 0; m < 60; m += 15) {
24448 t1 = moment.utc([2000, 0, 1, h, m]);
24449 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
24450 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
24451 'meridiem at ' + t1.format('HH:mm'));
24452 }
24453 }
24454 });
24455
24456 test('date format correctness', function (assert) {
24457 var data, tokens;
24458 data = moment.localeData()._longDateFormat;
24459 tokens = objectKeys(data);
24460 each(tokens, function (srchToken) {
24461 // Check each format string to make sure it does not contain any
24462 // tokens that need to be expanded.
24463 each(tokens, function (baseToken) {
24464 // strip escaped sequences
24465 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
24466 assert.equal(false, !!~format.indexOf(srchToken),
24467 'contains ' + srchToken + ' in ' + baseToken);
24468 });
24469 });
24470 });
24471
24472 test('month parsing correctness', function (assert) {
24473 var i, m;
24474
24475 if (locale === 'tr') {
24476 // I can't fix it :(
24477 assert.expect(0);
24478 return;
24479 }
24480 function tester(format) {
24481 var r;
24482 r = moment(m.format(format), format);
24483 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
24484 if (locale !== 'ka') {
24485 r = moment(m.format(format).toLocaleUpperCase(), format);
24486 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
24487 }
24488 r = moment(m.format(format).toLocaleLowerCase(), format);
24489 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
24490
24491 r = moment(m.format(format), format, true);
24492 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
24493 if (locale !== 'ka') {
24494 r = moment(m.format(format).toLocaleUpperCase(), format, true);
24495 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
24496 }
24497 r = moment(m.format(format).toLocaleLowerCase(), format, true);
24498 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
24499 }
24500
24501 for (i = 0; i < 12; ++i) {
24502 m = moment([2015, i, 15, 18]);
24503 tester('MMM');
24504 tester('MMM.');
24505 tester('MMMM');
24506 tester('MMMM.');
24507 }
24508 });
24509
24510 test('weekday parsing correctness', function (assert) {
24511 var i, m;
24512
24513 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
24514 // tr, az: There is a lower-case letter (ı), that converted to
24515 // upper then lower changes to i
24516 // ro: there is the letter ț which behaves weird under IE8
24517 // mt: letter Ħ
24518 // ga: month with spaces
24519 assert.expect(0);
24520 return;
24521 }
24522 function tester(format) {
24523 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
24524 r = moment(m.format(format), format);
24525 assert.equal(r.weekday(), m.weekday(), baseMsg);
24526 if (locale !== 'ka') {
24527 r = moment(m.format(format).toLocaleUpperCase(), format);
24528 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
24529 }
24530 r = moment(m.format(format).toLocaleLowerCase(), format);
24531 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
24532 r = moment(m.format(format), format, true);
24533 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
24534 if (locale !== 'ka') {
24535 r = moment(m.format(format).toLocaleUpperCase(), format, true);
24536 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
24537 }
24538 r = moment(m.format(format).toLocaleLowerCase(), format, true);
24539 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
24540 }
24541
24542 for (i = 0; i < 7; ++i) {
24543 m = moment.utc([2015, 0, i + 1, 18]);
24544 tester('dd');
24545 tester('ddd');
24546 tester('dddd');
24547 }
24548 });
24549
24550 test('valid localeData', function (assert) {
24551 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
24552 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
24553 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
24554 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
24555 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
24556 });
24557
24558 test('localeData weekdays can localeSort', function (assert) {
24559 var weekdays = moment().localeData().weekdays();
24560 var weekdaysShort = moment().localeData().weekdaysShort();
24561 var weekdaysMin = moment().localeData().weekdaysMin();
24562 var shift = moment().localeData()._week.dow;
24563 assert.deepEqual(
24564 moment().localeData().weekdays(true),
24565 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
24566 'weekdays should localeSort');
24567 assert.deepEqual(
24568 moment().localeData().weekdaysShort(true),
24569 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
24570 'weekdaysShort should localeSort');
24571 assert.deepEqual(
24572 moment().localeData().weekdaysMin(true),
24573 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
24574 'weekdaysMin should localeSort');
24575 });
db71a655 24576 }
7c4c091b 24577
db71a655 24578 /*global QUnit:false*/
7c4c091b 24579
db71a655
KM
24580 function localeModule (name, lifecycle) {
24581 QUnit.module('locale:' + name, {
c58511b9 24582 beforeEach : function () {
db71a655
KM
24583 moment.locale(name);
24584 moment.createFromInputFallback = function (config) {
24585 throw new Error('input not handled by moment: ' + config._i);
24586 };
24587 setupDeprecationHandler(test, moment, 'locale');
24588 if (lifecycle && lifecycle.setup) {
24589 lifecycle.setup();
24590 }
24591 },
c58511b9 24592 afterEach : function () {
db71a655
KM
24593 moment.locale('en');
24594 teardownDeprecationHandler(test, moment, 'locale');
24595 if (lifecycle && lifecycle.teardown) {
24596 lifecycle.teardown();
24597 }
73f3c911 24598 }
db71a655
KM
24599 });
24600 defineCommonLocaleTests(name, -1, -1);
24601 }
24602
24603 localeModule('gd');
24604
24605 var months = [
24606 'Am Faoilleach,Faoi',
24607 'An Gearran,Gear',
24608 'Am Màrt,Màrt',
24609 'An Giblean,Gibl',
24610 'An Cèitean,Cèit',
24611 'An t-Ògmhios,Ògmh',
24612 'An t-Iuchar,Iuch',
24613 'An Lùnastal,Lùn',
24614 'An t-Sultain,Sult',
24615 'An Dàmhair,Dàmh',
24616 'An t-Samhain,Samh',
24617 'An Dùbhlachd,Dùbh'
24618 ];
73f3c911 24619
db71a655
KM
24620 test('parse', function (assert) {
24621 function equalTest(monthName, monthFormat, monthNum) {
24622 assert.equal(moment(monthName, monthFormat).month(), monthNum, monthName + ' should be month ' + (monthNum + 1));
24623 }
c74a101d 24624
db71a655
KM
24625 for (var i = 0; i < 12; i++) {
24626 var testMonth = months[i].split(',');
24627 equalTest(testMonth[0], 'MMM', i);
24628 equalTest(testMonth[1], 'MMM', i);
24629 equalTest(testMonth[0], 'MMMM', i);
24630 equalTest(testMonth[1], 'MMMM', i);
24631 equalTest(testMonth[0].toLocaleLowerCase(), 'MMMM', i);
24632 equalTest(testMonth[1].toLocaleLowerCase(), 'MMMM', i);
24633 equalTest(testMonth[0].toLocaleUpperCase(), 'MMMM', i);
24634 equalTest(testMonth[1].toLocaleUpperCase(), 'MMMM', i);
24635 }
24636 });
516f5f67 24637
db71a655
KM
24638 test('format', function (assert) {
24639 var a = [
24640 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Didòmhnaich, An Gearran 14mh 2010, 3:25:50 pm'],
24641 ['ddd, hA', 'Did, 3PM'],
24642 ['M Mo MM MMMM MMM', '2 2na 02 An Gearran Gear'],
24643 ['YYYY YY', '2010 10'],
24644 ['D Do DD', '14 14mh 14'],
24645 ['d do dddd ddd dd', '0 0mh Didòmhnaich Did Dò'],
24646 ['DDD DDDo DDDD', '45 45mh 045'],
24647 ['w wo ww', '6 6mh 06'],
24648 ['h hh', '3 03'],
24649 ['H HH', '15 15'],
24650 ['m mm', '25 25'],
24651 ['s ss', '50 50'],
24652 ['a A', 'pm PM'],
24653 ['[an] DDDo [latha den bhliadhna]', 'an 45mh latha den bhliadhna'],
24654 ['LTS', '15:25:50'],
24655 ['L', '14/02/2010'],
24656 ['LL', '14 An Gearran 2010'],
24657 ['LLL', '14 An Gearran 2010 15:25'],
24658 ['LLLL', 'Didòmhnaich, 14 An Gearran 2010 15:25'],
24659 ['l', '14/2/2010'],
24660 ['ll', '14 Gear 2010'],
24661 ['lll', '14 Gear 2010 15:25'],
24662 ['llll', 'Did, 14 Gear 2010 15:25']
24663 ],
24664 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
24665 i;
24666 for (i = 0; i < a.length; i++) {
24667 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
24668 }
24669 });
24670
24671 test('format ordinal', function (assert) {
24672 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1d', '1d');
24673 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2na', '2na');
24674 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3mh', '3mh');
24675 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4mh', '4mh');
24676 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5mh', '5mh');
24677 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6mh', '6mh');
24678 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7mh', '7mh');
24679 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8mh', '8mh');
24680 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9mh', '9mh');
24681 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10mh', '10mh');
24682 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11mh', '11mh');
24683 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12na', '12na');
24684 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13mh', '13mh');
24685 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14mh', '14mh');
24686 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15mh', '15mh');
24687 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16mh', '16mh');
24688 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17mh', '17mh');
24689 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18mh', '18mh');
24690 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19mh', '19mh');
24691 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20mh', '20mh');
24692 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21mh', '21mh');
24693 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22na', '22na');
24694 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23mh', '23mh');
24695 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24mh', '24mh');
24696 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25mh', '25mh');
24697 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26mh', '26mh');
24698 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27mh', '27mh');
24699 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28mh', '28mh');
24700 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29mh', '29mh');
24701 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30mh', '30mh');
24702 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31mh', '31mh');
24703 });
24704
24705 test('format month', function (assert) {
24706 var expected = months;
24707 for (var i = 0; i < expected.length; i++) {
24708 assert.equal(moment([2011, i, 1]).format('MMMM,MMM'), expected[i], expected[i]);
24709 }
24710 });
24711
24712 test('format week', function (assert) {
24713 var expected = ['Didòmhnaich Did Dò', 'Diluain Dil Lu', 'Dimàirt Dim Mà', 'Diciadain Dic Ci', 'Diardaoin Dia Ar', 'Dihaoine Dih Ha', 'Disathairne Dis Sa'];
24714 for (var i = 0; i < expected.length; i++) {
24715 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
24716 }
24717 });
24718
24719 test('from', function (assert) {
24720 var start = moment([2007, 1, 28]);
24721 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'beagan diogan', '44 seconds = a few seconds');
24722 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'mionaid', '45 seconds = a minute');
24723 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'mionaid', '89 seconds = a minute');
24724 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 mionaidean', '90 seconds = 2 minutes');
24725 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 mionaidean', '44 minutes = 44 minutes');
24726 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'uair', '45 minutes = an hour');
24727 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'uair', '89 minutes = an hour');
24728 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 uairean', '90 minutes = 2 hours');
24729 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 uairean', '5 hours = 5 hours');
24730 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 uairean', '21 hours = 21 hours');
24731 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'latha', '22 hours = a day');
24732 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'latha', '35 hours = a day');
24733 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 latha', '36 hours = 2 days');
24734 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'latha', '1 day = a day');
24735 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 latha', '5 days = 5 days');
24736 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 latha', '25 days = 25 days');
24737 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mìos', '26 days = a month');
24738 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mìos', '30 days = a month');
24739 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mìos', '43 days = a month');
24740 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mìosan', '46 days = 2 months');
24741 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mìosan', '75 days = 2 months');
24742 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mìosan', '76 days = 3 months');
24743 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mìos', '1 month = a month');
24744 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mìosan', '5 months = 5 months');
24745 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'bliadhna', '345 days = a year');
24746 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 bliadhna', '548 days = 2 years');
24747 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'bliadhna', '1 year = a year');
24748 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 bliadhna', '5 years = 5 years');
24749 });
24750
24751 test('suffix', function (assert) {
24752 assert.equal(moment(30000).from(0), 'ann an beagan diogan', 'prefix');
24753 assert.equal(moment(0).from(30000), 'bho chionn beagan diogan', 'suffix');
24754 });
24755
24756 test('now from now', function (assert) {
24757 assert.equal(moment().fromNow(), 'bho chionn beagan diogan', 'now from now should display as in the past');
24758 });
24759
24760 test('fromNow', function (assert) {
24761 assert.equal(moment().add({s: 30}).fromNow(), 'ann an beagan diogan', 'in a few seconds');
24762 assert.equal(moment().add({d: 5}).fromNow(), 'ann an 5 latha', 'in 5 days');
24763 });
24764
24765 test('calendar day', function (assert) {
24766 var a = moment().hours(12).minutes(0).seconds(0);
24767
24768 assert.equal(moment(a).calendar(), 'An-diugh aig 12:00', 'today at the same time');
24769 assert.equal(moment(a).add({m: 25}).calendar(), 'An-diugh aig 12:25', 'Now plus 25 min');
24770 assert.equal(moment(a).add({h: 1}).calendar(), 'An-diugh aig 13:00', 'Now plus 1 hour');
24771 assert.equal(moment(a).add({d: 1}).calendar(), 'A-màireach aig 12:00', 'tomorrow at the same time');
24772 assert.equal(moment(a).subtract({h: 1}).calendar(), 'An-diugh aig 11:00', 'Now minus 1 hour');
24773 assert.equal(moment(a).subtract({d: 1}).calendar(), 'An-dè aig 12:00', 'yesterday at the same time');
24774 });
24775
24776 test('calendar next week', function (assert) {
24777 var i, m;
24778 for (i = 2; i < 7; i++) {
24779 m = moment().add({d: i});
24780 assert.equal(m.calendar(), m.format('dddd [aig] LT'), 'Today + ' + i + ' days current time');
24781 m.hours(0).minutes(0).seconds(0).milliseconds(0);
24782 assert.equal(m.calendar(), m.format('dddd [aig] LT'), 'Today + ' + i + ' days beginning of day');
24783 m.hours(23).minutes(59).seconds(59).milliseconds(999);
24784 assert.equal(m.calendar(), m.format('dddd [aig] LT'), 'Today + ' + i + ' days end of day');
24785 }
24786 });
24787
24788 test('calendar last week', function (assert) {
24789 var i, m;
24790
24791 for (i = 2; i < 7; i++) {
24792 m = moment().subtract({d: i});
24793 assert.equal(m.calendar(), m.format('dddd [seo chaidh] [aig] LT'), 'Today - ' + i + ' days current time');
24794 m.hours(0).minutes(0).seconds(0).milliseconds(0);
24795 assert.equal(m.calendar(), m.format('dddd [seo chaidh] [aig] LT'), 'Today - ' + i + ' days beginning of day');
24796 m.hours(23).minutes(59).seconds(59).milliseconds(999);
24797 assert.equal(m.calendar(), m.format('dddd [seo chaidh] [aig] LT'), 'Today - ' + i + ' days end of day');
24798 }
24799 });
24800
24801 test('calendar all else', function (assert) {
24802 var weeksAgo = moment().subtract({w: 1}),
24803 weeksFromNow = moment().add({w: 1});
24804
24805 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
24806 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
24807
24808 weeksAgo = moment().subtract({w: 2});
24809 weeksFromNow = moment().add({w: 2});
24810
24811 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
24812 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
24813 });
24814
24815 test('weeks year starting sunday formatted', function (assert) {
24816 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52na', 'Faoi 1 2012 should be week 52');
24817 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1d', 'Faoi 2 2012 should be week 1');
24818 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1d', 'Faoi 8 2012 should be week 1');
24819 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2na', 'Faoi 9 2012 should be week 2');
24820 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2na', 'Faoi 15 2012 should be week 2');
24821 });
24822
24823})));
24824
24825
24826;(function (global, factory) {
24827 typeof exports === 'object' && typeof module !== 'undefined'
c74a101d 24828 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
24829 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
24830 factory(global.moment)
73f3c911 24831}(this, (function (moment) { 'use strict';
516f5f67 24832
db71a655
KM
24833 function each(array, callback) {
24834 var i;
24835 for (i = 0; i < array.length; i++) {
24836 callback(array[i], i, array);
24837 }
b135bf1a
IC
24838 }
24839
c58511b9
KM
24840 function setupDeprecationHandler(test, moment$$1, scope) {
24841 test._expectedDeprecations = null;
24842 test._observedDeprecations = null;
24843 test._oldSupress = moment$$1.suppressDeprecationWarnings;
24844 moment$$1.suppressDeprecationWarnings = true;
24845 test.expectedDeprecations = function () {
24846 test._expectedDeprecations = arguments;
24847 test._observedDeprecations = [];
24848 };
24849 moment$$1.deprecationHandler = function (name, msg) {
24850 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
24851 if (deprecationId === -1) {
24852 throw new Error('Unexpected deprecation thrown name=' +
24853 name + ' msg=' + msg);
24854 }
24855 test._observedDeprecations[deprecationId] = 1;
24856 };
24857 }
24858
24859 function teardownDeprecationHandler(test, moment$$1, scope) {
24860 moment$$1.suppressDeprecationWarnings = test._oldSupress;
24861
24862 if (test._expectedDeprecations != null) {
24863 var missedDeprecations = [];
24864 each(test._expectedDeprecations, function (deprecationPattern, id) {
24865 if (test._observedDeprecations[id] !== 1) {
24866 missedDeprecations.push(deprecationPattern);
24867 }
24868 });
24869 if (missedDeprecations.length !== 0) {
24870 throw new Error('Expected deprecation warnings did not happen: ' +
24871 missedDeprecations.join(' '));
24872 }
24873 }
24874 }
24875
24876 function matchedDeprecation(name, msg, deprecations) {
24877 if (deprecations == null) {
24878 return -1;
24879 }
24880 for (var i = 0; i < deprecations.length; ++i) {
24881 if (name != null && name === deprecations[i]) {
24882 return i;
24883 }
24884 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
24885 return i;
24886 }
24887 }
24888 return -1;
24889 }
24890
24891 /*global QUnit:false*/
24892
24893 var test = QUnit.test;
24894
db71a655
KM
24895 function objectKeys(obj) {
24896 if (Object.keys) {
24897 return Object.keys(obj);
24898 } else {
24899 // IE8
24900 var res = [], i;
24901 for (i in obj) {
24902 if (obj.hasOwnProperty(i)) {
24903 res.push(i);
24904 }
b135bf1a 24905 }
db71a655 24906 return res;
b135bf1a
IC
24907 }
24908 }
24909
db71a655 24910 // Pick the first defined of two or three arguments.
73f3c911 24911
db71a655
KM
24912 function defineCommonLocaleTests(locale, options) {
24913 test('lenient day of month ordinal parsing', function (assert) {
24914 var i, ordinalStr, testMoment;
24915 for (i = 1; i <= 31; ++i) {
24916 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
24917 testMoment = moment(ordinalStr, 'YYYY MM Do');
24918 assert.equal(testMoment.year(), 2014,
24919 'lenient day of month ordinal parsing ' + i + ' year check');
24920 assert.equal(testMoment.month(), 0,
24921 'lenient day of month ordinal parsing ' + i + ' month check');
24922 assert.equal(testMoment.date(), i,
24923 'lenient day of month ordinal parsing ' + i + ' date check');
24924 }
24925 });
73f3c911 24926
db71a655
KM
24927 test('lenient day of month ordinal parsing of number', function (assert) {
24928 var i, testMoment;
24929 for (i = 1; i <= 31; ++i) {
24930 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
24931 assert.equal(testMoment.year(), 2014,
24932 'lenient day of month ordinal parsing of number ' + i + ' year check');
24933 assert.equal(testMoment.month(), 0,
24934 'lenient day of month ordinal parsing of number ' + i + ' month check');
24935 assert.equal(testMoment.date(), i,
24936 'lenient day of month ordinal parsing of number ' + i + ' date check');
24937 }
24938 });
b135bf1a 24939
db71a655
KM
24940 test('strict day of month ordinal parsing', function (assert) {
24941 var i, ordinalStr, testMoment;
24942 for (i = 1; i <= 31; ++i) {
24943 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
24944 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
24945 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
24946 }
24947 });
b135bf1a 24948
db71a655
KM
24949 test('meridiem invariant', function (assert) {
24950 var h, m, t1, t2;
24951 for (h = 0; h < 24; ++h) {
24952 for (m = 0; m < 60; m += 15) {
24953 t1 = moment.utc([2000, 0, 1, h, m]);
24954 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
24955 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
24956 'meridiem at ' + t1.format('HH:mm'));
24957 }
24958 }
24959 });
24960
24961 test('date format correctness', function (assert) {
24962 var data, tokens;
24963 data = moment.localeData()._longDateFormat;
24964 tokens = objectKeys(data);
24965 each(tokens, function (srchToken) {
24966 // Check each format string to make sure it does not contain any
24967 // tokens that need to be expanded.
24968 each(tokens, function (baseToken) {
24969 // strip escaped sequences
24970 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
24971 assert.equal(false, !!~format.indexOf(srchToken),
24972 'contains ' + srchToken + ' in ' + baseToken);
24973 });
73f3c911 24974 });
b135bf1a
IC
24975 });
24976
db71a655
KM
24977 test('month parsing correctness', function (assert) {
24978 var i, m;
24979
24980 if (locale === 'tr') {
24981 // I can't fix it :(
c58511b9 24982 assert.expect(0);
db71a655
KM
24983 return;
24984 }
24985 function tester(format) {
24986 var r;
24987 r = moment(m.format(format), format);
24988 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
24989 if (locale !== 'ka') {
24990 r = moment(m.format(format).toLocaleUpperCase(), format);
24991 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
24992 }
db71a655
KM
24993 r = moment(m.format(format).toLocaleLowerCase(), format);
24994 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
24995
24996 r = moment(m.format(format), format, true);
24997 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
24998 if (locale !== 'ka') {
24999 r = moment(m.format(format).toLocaleUpperCase(), format, true);
25000 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
25001 }
db71a655
KM
25002 r = moment(m.format(format).toLocaleLowerCase(), format, true);
25003 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
25004 }
25005
25006 for (i = 0; i < 12; ++i) {
25007 m = moment([2015, i, 15, 18]);
25008 tester('MMM');
25009 tester('MMM.');
25010 tester('MMMM');
25011 tester('MMMM.');
25012 }
25013 });
d6651c21 25014
db71a655
KM
25015 test('weekday parsing correctness', function (assert) {
25016 var i, m;
25017
96d0d679
KM
25018 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
25019 // tr, az: There is a lower-case letter (ı), that converted to
25020 // upper then lower changes to i
25021 // ro: there is the letter ț which behaves weird under IE8
25022 // mt: letter Ħ
25023 // ga: month with spaces
25024 assert.expect(0);
25025 return;
25026 }
25027 function tester(format) {
25028 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
25029 r = moment(m.format(format), format);
25030 assert.equal(r.weekday(), m.weekday(), baseMsg);
25031 if (locale !== 'ka') {
25032 r = moment(m.format(format).toLocaleUpperCase(), format);
25033 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
25034 }
25035 r = moment(m.format(format).toLocaleLowerCase(), format);
25036 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
25037 r = moment(m.format(format), format, true);
25038 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
25039 if (locale !== 'ka') {
25040 r = moment(m.format(format).toLocaleUpperCase(), format, true);
25041 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
25042 }
25043 r = moment(m.format(format).toLocaleLowerCase(), format, true);
25044 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
25045 }
25046
25047 for (i = 0; i < 7; ++i) {
25048 m = moment.utc([2015, 0, i + 1, 18]);
25049 tester('dd');
25050 tester('ddd');
25051 tester('dddd');
25052 }
25053 });
25054
25055 test('valid localeData', function (assert) {
25056 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
25057 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
25058 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
25059 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
25060 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
25061 });
25062
25063 test('localeData weekdays can localeSort', function (assert) {
25064 var weekdays = moment().localeData().weekdays();
25065 var weekdaysShort = moment().localeData().weekdaysShort();
25066 var weekdaysMin = moment().localeData().weekdaysMin();
25067 var shift = moment().localeData()._week.dow;
25068 assert.deepEqual(
25069 moment().localeData().weekdays(true),
25070 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
25071 'weekdays should localeSort');
25072 assert.deepEqual(
25073 moment().localeData().weekdaysShort(true),
25074 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
25075 'weekdaysShort should localeSort');
25076 assert.deepEqual(
25077 moment().localeData().weekdaysMin(true),
25078 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
25079 'weekdaysMin should localeSort');
25080 });
25081 }
25082
25083 /*global QUnit:false*/
25084
25085 function localeModule (name, lifecycle) {
25086 QUnit.module('locale:' + name, {
25087 beforeEach : function () {
25088 moment.locale(name);
25089 moment.createFromInputFallback = function (config) {
25090 throw new Error('input not handled by moment: ' + config._i);
25091 };
25092 setupDeprecationHandler(test, moment, 'locale');
25093 if (lifecycle && lifecycle.setup) {
25094 lifecycle.setup();
25095 }
25096 },
25097 afterEach : function () {
25098 moment.locale('en');
25099 teardownDeprecationHandler(test, moment, 'locale');
25100 if (lifecycle && lifecycle.teardown) {
25101 lifecycle.teardown();
25102 }
25103 }
25104 });
25105 defineCommonLocaleTests(name, -1, -1);
25106 }
25107
25108 localeModule('gl');
25109
25110 test('parse', function (assert) {
25111 var tests = 'xaneiro xan._febreiro feb._marzo mar._abril abr._maio mai._xuño xuñ._xullo xul._agosto ago._setembro set._outubro out._novembro nov._decembro dec.'.split('_'), i;
25112 function equalTest(input, mmm, i) {
25113 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
25114 }
25115 for (i = 0; i < 12; i++) {
25116 tests[i] = tests[i].split(' ');
25117 equalTest(tests[i][0], 'MMM', i);
25118 equalTest(tests[i][1], 'MMM', i);
25119 equalTest(tests[i][0], 'MMMM', i);
25120 equalTest(tests[i][1], 'MMMM', i);
25121 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
25122 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
25123 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
25124 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
25125 }
25126 });
25127
25128 test('format', function (assert) {
25129 var a = [
25130 ['dddd, MMMM Do YYYY, h:mm:ss a', 'domingo, febreiro 14º 2010, 3:25:50 pm'],
25131 ['ddd, hA', 'dom., 3PM'],
25132 ['M Mo MM MMMM MMM', '2 2º 02 febreiro feb.'],
25133 ['YYYY YY', '2010 10'],
25134 ['D Do DD', '14 14º 14'],
25135 ['d do dddd ddd dd', '0 0º domingo dom. do'],
25136 ['DDD DDDo DDDD', '45 45º 045'],
25137 ['w wo ww', '6 6º 06'],
25138 ['h hh', '3 03'],
25139 ['H HH', '15 15'],
25140 ['m mm', '25 25'],
25141 ['s ss', '50 50'],
25142 ['a A', 'pm PM'],
25143 ['[the] DDDo [day of the year]', 'the 45º day of the year'],
25144 ['LTS', '15:25:50'],
25145 ['L', '14/02/2010'],
25146 ['LL', '14 de febreiro de 2010'],
25147 ['LLL', '14 de febreiro de 2010 15:25'],
25148 ['LLLL', 'domingo, 14 de febreiro de 2010 15:25'],
25149 ['l', '14/2/2010'],
25150 ['ll', '14 de feb. de 2010'],
25151 ['lll', '14 de feb. de 2010 15:25'],
25152 ['llll', 'dom., 14 de feb. de 2010 15:25']
25153 ],
25154 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
25155 i;
25156 for (i = 0; i < a.length; i++) {
25157 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
25158 }
25159 });
25160
25161 test('format ordinal', function (assert) {
25162 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1º', '1º');
25163 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2º', '2º');
25164 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3º', '3º');
25165 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4º', '4º');
25166 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5º', '5º');
25167 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6º', '6º');
25168 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7º', '7º');
25169 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8º', '8º');
25170 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9º', '9º');
25171 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10º', '10º');
25172
25173 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11º', '11º');
25174 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12º', '12º');
25175 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13º', '13º');
25176 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14º', '14º');
25177 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15º', '15º');
25178 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16º', '16º');
25179 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17º', '17º');
25180 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18º', '18º');
25181 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19º', '19º');
25182 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20º', '20º');
25183
25184 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21º', '21º');
25185 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22º', '22º');
25186 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23º', '23º');
25187 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24º', '24º');
25188 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25º', '25º');
25189 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26º', '26º');
25190 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27º', '27º');
25191 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28º', '28º');
25192 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29º', '29º');
25193 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30º', '30º');
25194
25195 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31º', '31º');
25196 });
25197
25198 test('format month', function (assert) {
25199 var expected = 'xaneiro xan._febreiro feb._marzo mar._abril abr._maio mai._xuño xuñ._xullo xul._agosto ago._setembro set._outubro out._novembro nov._decembro dec.'.split('_'), i;
25200 for (i = 0; i < expected.length; i++) {
25201 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
25202 }
25203 });
25204
25205 test('format week', function (assert) {
25206 var expected = 'domingo dom. do_luns lun. lu_martes mar. ma_mércores mér. mé_xoves xov. xo_venres ven. ve_sábado sáb. sá'.split('_'),
25207 i;
25208 for (i = 0; i < expected.length; i++) {
25209 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
25210 }
25211 });
25212
25213 test('from', function (assert) {
25214 var start = moment([2007, 1, 28]);
25215
25216 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'uns segundos', '44 seconds = a few seconds');
25217 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'un minuto', '45 seconds = a minute');
25218 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'un minuto', '89 seconds = a minute');
25219 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutos', '90 seconds = 2 minutes');
25220 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutos', '44 minutes = 44 minutes');
25221 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'unha hora', '45 minutes = an hour');
25222 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'unha hora', '89 minutes = an hour');
25223 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 horas', '90 minutes = 2 hours');
25224 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 horas', '5 hours = 5 hours');
25225 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 horas', '21 hours = 21 hours');
25226 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un día', '22 hours = a day');
25227 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un día', '35 hours = a day');
25228 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 días', '36 hours = 2 days');
25229 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un día', '1 day = a day');
25230 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 días', '5 days = 5 days');
25231 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 días', '25 days = 25 days');
25232 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'un mes', '26 days = a month');
25233 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'un mes', '30 days = a month');
25234 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'un mes', '43 days = a month');
25235 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 meses', '46 days = 2 months');
25236 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 meses', '75 days = 2 months');
25237 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 meses', '76 days = 3 months');
25238 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'un mes', '1 month = a month');
25239 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 meses', '5 months = 5 months');
25240 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un ano', '345 days = a year');
25241 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 anos', '548 days = 2 years');
25242 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un ano', '1 year = a year');
25243 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 anos', '5 years = 5 years');
25244 });
25245
25246 test('suffix', function (assert) {
25247 assert.equal(moment(30000).from(0), 'nuns segundos', 'prefix');
25248 assert.equal(moment(0).from(30000), 'hai uns segundos', 'suffix');
25249 });
25250
25251 test('now from now', function (assert) {
25252 assert.equal(moment().fromNow(), 'hai uns segundos', 'now from now should display as in the past');
25253 });
25254
25255 test('fromNow', function (assert) {
25256 assert.equal(moment().add({s: 30}).fromNow(), 'nuns segundos', 'nuns segundos');
25257 assert.equal(moment().add({d: 5}).fromNow(), 'en 5 días', 'en 5 días');
25258 });
25259
25260 test('calendar day', function (assert) {
25261 var a = moment().hours(12).minutes(0).seconds(0);
25262
25263 assert.equal(moment(a).calendar(), 'hoxe ás 12:00', 'today at the same time');
25264 assert.equal(moment(a).add({m: 25}).calendar(), 'hoxe ás 12:25', 'Now plus 25 min');
25265 assert.equal(moment(a).add({h: 1}).calendar(), 'hoxe ás 13:00', 'Now plus 1 hour');
25266 assert.equal(moment(a).add({d: 1}).calendar(), 'mañá ás 12:00', 'tomorrow at the same time');
25267 assert.equal(moment(a).add({d: 1, h : -1}).calendar(), 'mañá ás 11:00', 'tomorrow minus 1 hour');
25268 assert.equal(moment(a).subtract({h: 1}).calendar(), 'hoxe ás 11:00', 'Now minus 1 hour');
25269 assert.equal(moment(a).subtract({d: 1}).calendar(), 'onte á 12:00', 'yesterday at the same time');
25270 });
25271
25272 test('calendar next week', function (assert) {
25273 var i, m;
25274
25275 for (i = 2; i < 7; i++) {
25276 m = moment().add({d: i});
25277 assert.equal(m.calendar(), m.format('dddd [' + ((m.hours() !== 1) ? 'ás' : 'a') + '] LT'), 'Today + ' + i + ' days current time');
25278 m.hours(0).minutes(0).seconds(0).milliseconds(0);
25279 assert.equal(m.calendar(), m.format('dddd [' + ((m.hours() !== 1) ? 'ás' : 'a') + '] LT'), 'Today + ' + i + ' days beginning of day');
25280 m.hours(23).minutes(59).seconds(59).milliseconds(999);
25281 assert.equal(m.calendar(), m.format('dddd [' + ((m.hours() !== 1) ? 'ás' : 'a') + '] LT'), 'Today + ' + i + ' days end of day');
25282 }
25283 });
25284
25285 test('calendar last week', function (assert) {
25286 var i, m;
25287 for (i = 2; i < 7; i++) {
25288 m = moment().subtract({d: i});
25289 assert.equal(m.calendar(), m.format('[o] dddd [pasado ' + ((m.hours() !== 1) ? 'ás' : 'a') + '] LT'), 'Today - ' + i + ' days current time');
25290 m.hours(0).minutes(0).seconds(0).milliseconds(0);
25291 assert.equal(m.calendar(), m.format('[o] dddd [pasado ' + ((m.hours() !== 1) ? 'ás' : 'a') + '] LT'), 'Today - ' + i + ' days beginning of day');
25292 m.hours(23).minutes(59).seconds(59).milliseconds(999);
25293 assert.equal(m.calendar(), m.format('[o] dddd [pasado ' + ((m.hours() !== 1) ? 'ás' : 'a') + '] LT'), 'Today - ' + i + ' days end of day');
25294 }
25295 });
25296
25297 test('calendar all else', function (assert) {
25298 var weeksAgo = moment().subtract({w: 1}),
25299 weeksFromNow = moment().add({w: 1});
25300
25301 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
25302 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
25303
25304 weeksAgo = moment().subtract({w: 2});
25305 weeksFromNow = moment().add({w: 2});
25306
25307 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
25308 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
25309 });
25310
25311 test('regression tests', function (assert) {
25312 var lastWeek = moment().subtract({d: 4}).hours(1);
25313 assert.equal(lastWeek.calendar(), lastWeek.format('[o] dddd [pasado a] LT'), '1 o\'clock bug');
25314 });
25315
25316 test('weeks year starting sunday formatted', function (assert) {
25317 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52º', 'Jan 1 2012 should be week 52');
25318 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1º', 'Jan 2 2012 should be week 1');
25319 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1º', 'Jan 8 2012 should be week 1');
25320 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2º', 'Jan 9 2012 should be week 2');
25321 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2º', 'Jan 15 2012 should be week 2');
25322 });
25323
25324})));
25325
25326
25327;(function (global, factory) {
25328 typeof exports === 'object' && typeof module !== 'undefined'
25329 && typeof require === 'function' ? factory(require('../../moment')) :
25330 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
25331 factory(global.moment)
25332}(this, (function (moment) { 'use strict';
25333
25334 function each(array, callback) {
25335 var i;
25336 for (i = 0; i < array.length; i++) {
25337 callback(array[i], i, array);
25338 }
25339 }
25340
25341 function setupDeprecationHandler(test, moment$$1, scope) {
25342 test._expectedDeprecations = null;
25343 test._observedDeprecations = null;
25344 test._oldSupress = moment$$1.suppressDeprecationWarnings;
25345 moment$$1.suppressDeprecationWarnings = true;
25346 test.expectedDeprecations = function () {
25347 test._expectedDeprecations = arguments;
25348 test._observedDeprecations = [];
25349 };
25350 moment$$1.deprecationHandler = function (name, msg) {
25351 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
25352 if (deprecationId === -1) {
25353 throw new Error('Unexpected deprecation thrown name=' +
25354 name + ' msg=' + msg);
25355 }
25356 test._observedDeprecations[deprecationId] = 1;
25357 };
25358 }
25359
25360 function teardownDeprecationHandler(test, moment$$1, scope) {
25361 moment$$1.suppressDeprecationWarnings = test._oldSupress;
25362
25363 if (test._expectedDeprecations != null) {
25364 var missedDeprecations = [];
25365 each(test._expectedDeprecations, function (deprecationPattern, id) {
25366 if (test._observedDeprecations[id] !== 1) {
25367 missedDeprecations.push(deprecationPattern);
25368 }
25369 });
25370 if (missedDeprecations.length !== 0) {
25371 throw new Error('Expected deprecation warnings did not happen: ' +
25372 missedDeprecations.join(' '));
25373 }
25374 }
25375 }
25376
25377 function matchedDeprecation(name, msg, deprecations) {
25378 if (deprecations == null) {
25379 return -1;
25380 }
25381 for (var i = 0; i < deprecations.length; ++i) {
25382 if (name != null && name === deprecations[i]) {
25383 return i;
25384 }
25385 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
25386 return i;
25387 }
25388 }
25389 return -1;
25390 }
25391
25392 /*global QUnit:false*/
25393
25394 var test = QUnit.test;
25395
25396 function objectKeys(obj) {
25397 if (Object.keys) {
25398 return Object.keys(obj);
25399 } else {
25400 // IE8
25401 var res = [], i;
25402 for (i in obj) {
25403 if (obj.hasOwnProperty(i)) {
25404 res.push(i);
25405 }
25406 }
25407 return res;
25408 }
25409 }
25410
25411 // Pick the first defined of two or three arguments.
25412
25413 function defineCommonLocaleTests(locale, options) {
25414 test('lenient day of month ordinal parsing', function (assert) {
25415 var i, ordinalStr, testMoment;
25416 for (i = 1; i <= 31; ++i) {
25417 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
25418 testMoment = moment(ordinalStr, 'YYYY MM Do');
25419 assert.equal(testMoment.year(), 2014,
25420 'lenient day of month ordinal parsing ' + i + ' year check');
25421 assert.equal(testMoment.month(), 0,
25422 'lenient day of month ordinal parsing ' + i + ' month check');
25423 assert.equal(testMoment.date(), i,
25424 'lenient day of month ordinal parsing ' + i + ' date check');
25425 }
25426 });
25427
25428 test('lenient day of month ordinal parsing of number', function (assert) {
25429 var i, testMoment;
25430 for (i = 1; i <= 31; ++i) {
25431 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
25432 assert.equal(testMoment.year(), 2014,
25433 'lenient day of month ordinal parsing of number ' + i + ' year check');
25434 assert.equal(testMoment.month(), 0,
25435 'lenient day of month ordinal parsing of number ' + i + ' month check');
25436 assert.equal(testMoment.date(), i,
25437 'lenient day of month ordinal parsing of number ' + i + ' date check');
25438 }
25439 });
25440
25441 test('strict day of month ordinal parsing', function (assert) {
25442 var i, ordinalStr, testMoment;
25443 for (i = 1; i <= 31; ++i) {
25444 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
25445 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
25446 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
25447 }
25448 });
25449
25450 test('meridiem invariant', function (assert) {
25451 var h, m, t1, t2;
25452 for (h = 0; h < 24; ++h) {
25453 for (m = 0; m < 60; m += 15) {
25454 t1 = moment.utc([2000, 0, 1, h, m]);
25455 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
25456 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
25457 'meridiem at ' + t1.format('HH:mm'));
25458 }
25459 }
25460 });
25461
25462 test('date format correctness', function (assert) {
25463 var data, tokens;
25464 data = moment.localeData()._longDateFormat;
25465 tokens = objectKeys(data);
25466 each(tokens, function (srchToken) {
25467 // Check each format string to make sure it does not contain any
25468 // tokens that need to be expanded.
25469 each(tokens, function (baseToken) {
25470 // strip escaped sequences
25471 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
25472 assert.equal(false, !!~format.indexOf(srchToken),
25473 'contains ' + srchToken + ' in ' + baseToken);
25474 });
25475 });
25476 });
25477
25478 test('month parsing correctness', function (assert) {
25479 var i, m;
25480
25481 if (locale === 'tr') {
25482 // I can't fix it :(
25483 assert.expect(0);
25484 return;
25485 }
25486 function tester(format) {
25487 var r;
25488 r = moment(m.format(format), format);
25489 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
25490 if (locale !== 'ka') {
25491 r = moment(m.format(format).toLocaleUpperCase(), format);
25492 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
25493 }
25494 r = moment(m.format(format).toLocaleLowerCase(), format);
25495 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
25496
25497 r = moment(m.format(format), format, true);
25498 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
25499 if (locale !== 'ka') {
25500 r = moment(m.format(format).toLocaleUpperCase(), format, true);
25501 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
25502 }
25503 r = moment(m.format(format).toLocaleLowerCase(), format, true);
25504 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
25505 }
25506
25507 for (i = 0; i < 12; ++i) {
25508 m = moment([2015, i, 15, 18]);
25509 tester('MMM');
25510 tester('MMM.');
25511 tester('MMMM');
25512 tester('MMMM.');
25513 }
25514 });
25515
25516 test('weekday parsing correctness', function (assert) {
25517 var i, m;
25518
25519 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
25520 // tr, az: There is a lower-case letter (ı), that converted to
25521 // upper then lower changes to i
25522 // ro: there is the letter ț which behaves weird under IE8
25523 // mt: letter Ħ
96d0d679 25524 // ga: month with spaces
c58511b9 25525 assert.expect(0);
db71a655
KM
25526 return;
25527 }
25528 function tester(format) {
25529 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
25530 r = moment(m.format(format), format);
25531 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
25532 if (locale !== 'ka') {
25533 r = moment(m.format(format).toLocaleUpperCase(), format);
25534 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
25535 }
db71a655
KM
25536 r = moment(m.format(format).toLocaleLowerCase(), format);
25537 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
25538 r = moment(m.format(format), format, true);
25539 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
25540 if (locale !== 'ka') {
25541 r = moment(m.format(format).toLocaleUpperCase(), format, true);
25542 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
25543 }
db71a655
KM
25544 r = moment(m.format(format).toLocaleLowerCase(), format, true);
25545 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
25546 }
25547
25548 for (i = 0; i < 7; ++i) {
25549 m = moment.utc([2015, 0, i + 1, 18]);
25550 tester('dd');
25551 tester('ddd');
25552 tester('dddd');
25553 }
25554 });
25555
25556 test('valid localeData', function (assert) {
25557 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
25558 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
25559 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
25560 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
25561 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
25562 });
96d0d679
KM
25563
25564 test('localeData weekdays can localeSort', function (assert) {
25565 var weekdays = moment().localeData().weekdays();
25566 var weekdaysShort = moment().localeData().weekdaysShort();
25567 var weekdaysMin = moment().localeData().weekdaysMin();
25568 var shift = moment().localeData()._week.dow;
25569 assert.deepEqual(
25570 moment().localeData().weekdays(true),
25571 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
25572 'weekdays should localeSort');
25573 assert.deepEqual(
25574 moment().localeData().weekdaysShort(true),
25575 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
25576 'weekdaysShort should localeSort');
25577 assert.deepEqual(
25578 moment().localeData().weekdaysMin(true),
25579 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
25580 'weekdaysMin should localeSort');
25581 });
db71a655
KM
25582 }
25583
db71a655
KM
25584 /*global QUnit:false*/
25585
db71a655
KM
25586 function localeModule (name, lifecycle) {
25587 QUnit.module('locale:' + name, {
c58511b9 25588 beforeEach : function () {
db71a655
KM
25589 moment.locale(name);
25590 moment.createFromInputFallback = function (config) {
25591 throw new Error('input not handled by moment: ' + config._i);
25592 };
25593 setupDeprecationHandler(test, moment, 'locale');
25594 if (lifecycle && lifecycle.setup) {
25595 lifecycle.setup();
25596 }
25597 },
c58511b9 25598 afterEach : function () {
db71a655
KM
25599 moment.locale('en');
25600 teardownDeprecationHandler(test, moment, 'locale');
25601 if (lifecycle && lifecycle.teardown) {
25602 lifecycle.teardown();
25603 }
25604 }
25605 });
25606 defineCommonLocaleTests(name, -1, -1);
25607 }
25608
96d0d679 25609 localeModule('gom-latn');
db71a655
KM
25610
25611 test('parse', function (assert) {
96d0d679
KM
25612 var i,
25613 tests = 'Janer Jan._Febrer Feb._Mars Mars_Abril Abr._Mai Mai_Jun Jun_Julai Jul._Agost Ago._Setembr Set._Otubr Otu._Novembr Nov._Dezembr Dez.'.split('_');
25614
db71a655
KM
25615 function equalTest(input, mmm, i) {
25616 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
25617 }
96d0d679 25618
db71a655
KM
25619 for (i = 0; i < 12; i++) {
25620 tests[i] = tests[i].split(' ');
25621 equalTest(tests[i][0], 'MMM', i);
25622 equalTest(tests[i][1], 'MMM', i);
25623 equalTest(tests[i][0], 'MMMM', i);
25624 equalTest(tests[i][1], 'MMMM', i);
25625 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
25626 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
25627 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
25628 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
25629 }
25630 });
25631
25632 test('format', function (assert) {
25633 var a = [
96d0d679
KM
25634 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Aitar, Febrer 14er 2010, 3:25:50 donparam'],
25635 ['ddd, hA', 'Ait., 3donparam'],
25636 ['M Mo MM MMMM MMM', '2 2 02 Febrer Feb.'],
db71a655 25637 ['YYYY YY', '2010 10'],
96d0d679
KM
25638 ['D Do DD', '14 14er 14'],
25639 ['d do dddd ddd dd', '0 0 Aitar Ait. Ai'],
25640 ['DDD DDDo DDDD', '45 45 045'],
25641 ['w wo ww', '6 6 06'],
db71a655
KM
25642 ['h hh', '3 03'],
25643 ['H HH', '15 15'],
25644 ['m mm', '25 25'],
25645 ['s ss', '50 50'],
96d0d679
KM
25646 ['a A', 'donparam donparam'],
25647 ['[the] DDDo [day of the year]', 'the 45 day of the year'],
25648 ['LTS', 'donparam 3:25:50 vazta'],
25649 ['L', '14-02-2010'],
25650 ['LL', '14 Febrer 2010'],
25651 ['LLL', '14 Febrer 2010 donparam 3:25 vazta'],
25652 ['LLLL', 'Aitar, Febrerachea 14er, 2010, donparam 3:25 vazta'],
25653 ['l', '14-2-2010'],
25654 ['ll', '14 Feb. 2010'],
25655 ['lll', '14 Feb. 2010 donparam 3:25 vazta'],
25656 ['llll', 'Ait., 14 Feb. 2010, donparam 3:25 vazta']
db71a655
KM
25657 ],
25658 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
25659 i;
96d0d679 25660
db71a655
KM
25661 for (i = 0; i < a.length; i++) {
25662 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
25663 }
25664 });
25665
25666 test('format ordinal', function (assert) {
96d0d679
KM
25667 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
25668 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
25669 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
25670 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
25671 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
25672 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
25673 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
25674 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
25675 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
25676 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
db71a655 25677
96d0d679
KM
25678 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
25679 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
25680 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
25681 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
25682 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
25683 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
25684 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
25685 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
25686 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
25687 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
db71a655 25688
96d0d679
KM
25689 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
25690 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
25691 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
25692 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
25693 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
25694 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
25695 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
25696 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
25697 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
25698 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
db71a655 25699
96d0d679 25700 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
db71a655
KM
25701 });
25702
25703 test('format month', function (assert) {
96d0d679
KM
25704 var i,
25705 expected = 'Janer Jan._Febrer Feb._Mars Mars_Abril Abr._Mai Mai_Jun Jun_Julai Jul._Agost Ago._Setembr Set._Otubr Otu._Novembr Nov._Dezembr Dez.'.split('_');
25706
db71a655
KM
25707 for (i = 0; i < expected.length; i++) {
25708 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
25709 }
25710 });
25711
25712 test('format week', function (assert) {
96d0d679
KM
25713 var i,
25714 expected = 'Aitar Ait. Ai_Somar Som. Sm_Mongllar Mon. Mo_Budvar Bud. Bu_Brestar Bre. Br_Sukrar Suk. Su_Son\'var Son. Sn'.split('_');
25715
db71a655
KM
25716 for (i = 0; i < expected.length; i++) {
25717 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
25718 }
25719 });
25720
25721 test('from', function (assert) {
25722 var start = moment([2007, 1, 28]);
25723
96d0d679
KM
25724 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'thodde secondanim', '44 seconds = a few seconds');
25725 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'eka mintan', '45 seconds = a minute');
25726 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'eka mintan', '89 seconds = a minute');
25727 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 mintanim', '90 seconds = 2 minutes');
25728 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 mintanim', '44 minutes = 44 minutes');
25729 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'eka voran', '45 minutes = an hour');
25730 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'eka voran', '89 minutes = an hour');
25731 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 voranim', '90 minutes = 2 hours');
25732 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 voranim', '5 hours = 5 hours');
25733 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 voranim', '21 hours = 21 hours');
25734 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'eka disan', '22 hours = a day');
25735 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'eka disan', '35 hours = a day');
25736 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 disanim', '36 hours = 2 days');
25737 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'eka disan', '1 day = a day');
25738 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 disanim', '5 days = 5 days');
25739 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 disanim', '25 days = 25 days');
25740 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'eka mhoinean', '26 days = a month');
25741 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'eka mhoinean', '30 days = a month');
25742 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'eka mhoinean', '43 days = a month');
25743 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mhoineanim', '46 days = 2 months');
25744 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mhoineanim', '75 days = 2 months');
25745 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mhoineanim', '76 days = 3 months');
25746 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'eka mhoinean', '1 month = a month');
25747 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mhoineanim', '5 months = 5 months');
25748 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'eka vorsan', '345 days = a year');
25749 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 vorsanim', '548 days = 2 years');
25750 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'eka vorsan', '1 year = a year');
25751 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 vorsanim', '5 years = 5 years');
db71a655
KM
25752 });
25753
25754 test('suffix', function (assert) {
96d0d679
KM
25755 assert.equal(moment(30000).from(0), 'thodde second', 'prefix');
25756 assert.equal(moment(0).from(30000), 'thodde second adim', 'suffix');
db71a655
KM
25757 });
25758
25759 test('now from now', function (assert) {
96d0d679 25760 assert.equal(moment().fromNow(), 'thodde second adim', 'now from now should display as in the past');
db71a655
KM
25761 });
25762
25763 test('fromNow', function (assert) {
96d0d679
KM
25764 assert.equal(moment().add({s: 30}).fromNow(), 'thodde second', 'in a few seconds');
25765 assert.equal(moment().add({d: 5}).fromNow(), '5 dis', 'in 5 days');
25766 });
25767
25768 test('ago', function (assert) {
25769 assert.equal(moment().subtract({h: 3}).fromNow(), '3 voram adim', '3 hours ago');
db71a655
KM
25770 });
25771
25772 test('calendar day', function (assert) {
25773 var a = moment().hours(12).minutes(0).seconds(0);
25774
96d0d679
KM
25775 assert.equal(moment(a).calendar(), 'Aiz donparam 12:00 vazta', 'today at the same time');
25776 assert.equal(moment(a).add({m: 25}).calendar(), 'Aiz donparam 12:25 vazta', 'Now plus 25 min');
25777 assert.equal(moment(a).add({h: 1}).calendar(), 'Aiz donparam 1:00 vazta', 'Now plus 1 hour');
25778 assert.equal(moment(a).add({d: 1}).calendar(), 'Faleam donparam 12:00 vazta', 'tomorrow at the same time');
25779 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Aiz sokalli 11:00 vazta', 'Now minus 1 hour');
25780 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Kal donparam 12:00 vazta', 'yesterday at the same time');
db71a655
KM
25781 });
25782
25783 test('calendar next week', function (assert) {
25784 var i, m;
25785
25786 for (i = 2; i < 7; i++) {
25787 m = moment().add({d: i});
96d0d679 25788 assert.equal(m.calendar(), m.format('[Ieta to] dddd[,] LT'), 'Today + ' + i + ' days current time');
db71a655 25789 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 25790 assert.equal(m.calendar(), m.format('[Ieta to] dddd[,] LT'), 'Today + ' + i + ' days beginning of day');
db71a655 25791 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 25792 assert.equal(m.calendar(), m.format('[Ieta to] dddd[,] LT'), 'Today + ' + i + ' days end of day');
73f3c911
IC
25793 }
25794 });
d6651c21 25795
db71a655 25796 test('calendar last week', function (assert) {
73f3c911 25797 var i, m;
96d0d679 25798
db71a655
KM
25799 for (i = 2; i < 7; i++) {
25800 m = moment().subtract({d: i});
96d0d679 25801 assert.equal(m.calendar(), m.format('[Fatlo] dddd[,] LT'), 'Today - ' + i + ' days current time');
db71a655 25802 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 25803 assert.equal(m.calendar(), m.format('[Fatlo] dddd[,] LT'), 'Today - ' + i + ' days beginning of day');
db71a655 25804 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 25805 assert.equal(m.calendar(), m.format('[Fatlo] dddd[,] LT'), 'Today - ' + i + ' days end of day');
d6651c21 25806 }
db71a655
KM
25807 });
25808
25809 test('calendar all else', function (assert) {
25810 var weeksAgo = moment().subtract({w: 1}),
25811 weeksFromNow = moment().add({w: 1});
25812
25813 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
25814 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
25815
25816 weeksAgo = moment().subtract({w: 2});
25817 weeksFromNow = moment().add({w: 2});
25818
25819 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
25820 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
25821 });
25822
96d0d679
KM
25823 test('weeks year starting sunday format', function (assert) {
25824 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52', 'Jan 1 2012 should be week 52');
25825 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1', 'Jan 2 2012 should be week 1');
25826 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1', 'Jan 8 2012 should be week 1');
25827 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2', 'Jan 14 2012 should be week 2');
25828 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2', 'Jan 15 2012 should be week 2');
db71a655
KM
25829 });
25830
25831})));
25832
25833
25834;(function (global, factory) {
25835 typeof exports === 'object' && typeof module !== 'undefined'
25836 && typeof require === 'function' ? factory(require('../../moment')) :
25837 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
25838 factory(global.moment)
25839}(this, (function (moment) { 'use strict';
25840
25841 function each(array, callback) {
25842 var i;
25843 for (i = 0; i < array.length; i++) {
25844 callback(array[i], i, array);
d6651c21 25845 }
db71a655 25846 }
b135bf1a 25847
c58511b9
KM
25848 function setupDeprecationHandler(test, moment$$1, scope) {
25849 test._expectedDeprecations = null;
25850 test._observedDeprecations = null;
25851 test._oldSupress = moment$$1.suppressDeprecationWarnings;
25852 moment$$1.suppressDeprecationWarnings = true;
25853 test.expectedDeprecations = function () {
25854 test._expectedDeprecations = arguments;
25855 test._observedDeprecations = [];
25856 };
25857 moment$$1.deprecationHandler = function (name, msg) {
25858 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
25859 if (deprecationId === -1) {
25860 throw new Error('Unexpected deprecation thrown name=' +
25861 name + ' msg=' + msg);
25862 }
25863 test._observedDeprecations[deprecationId] = 1;
25864 };
25865 }
25866
25867 function teardownDeprecationHandler(test, moment$$1, scope) {
25868 moment$$1.suppressDeprecationWarnings = test._oldSupress;
25869
25870 if (test._expectedDeprecations != null) {
25871 var missedDeprecations = [];
25872 each(test._expectedDeprecations, function (deprecationPattern, id) {
25873 if (test._observedDeprecations[id] !== 1) {
25874 missedDeprecations.push(deprecationPattern);
25875 }
25876 });
25877 if (missedDeprecations.length !== 0) {
25878 throw new Error('Expected deprecation warnings did not happen: ' +
25879 missedDeprecations.join(' '));
25880 }
25881 }
25882 }
25883
25884 function matchedDeprecation(name, msg, deprecations) {
25885 if (deprecations == null) {
25886 return -1;
25887 }
25888 for (var i = 0; i < deprecations.length; ++i) {
25889 if (name != null && name === deprecations[i]) {
25890 return i;
25891 }
25892 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
25893 return i;
25894 }
25895 }
25896 return -1;
25897 }
25898
25899 /*global QUnit:false*/
25900
25901 var test = QUnit.test;
25902
db71a655
KM
25903 function objectKeys(obj) {
25904 if (Object.keys) {
25905 return Object.keys(obj);
25906 } else {
25907 // IE8
25908 var res = [], i;
25909 for (i in obj) {
25910 if (obj.hasOwnProperty(i)) {
25911 res.push(i);
25912 }
25913 }
25914 return res;
73f3c911 25915 }
db71a655 25916 }
516f5f67 25917
db71a655 25918 // Pick the first defined of two or three arguments.
c74a101d 25919
db71a655
KM
25920 function defineCommonLocaleTests(locale, options) {
25921 test('lenient day of month ordinal parsing', function (assert) {
25922 var i, ordinalStr, testMoment;
25923 for (i = 1; i <= 31; ++i) {
25924 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
25925 testMoment = moment(ordinalStr, 'YYYY MM Do');
25926 assert.equal(testMoment.year(), 2014,
25927 'lenient day of month ordinal parsing ' + i + ' year check');
25928 assert.equal(testMoment.month(), 0,
25929 'lenient day of month ordinal parsing ' + i + ' month check');
25930 assert.equal(testMoment.date(), i,
25931 'lenient day of month ordinal parsing ' + i + ' date check');
516f5f67
IC
25932 }
25933 });
db71a655
KM
25934
25935 test('lenient day of month ordinal parsing of number', function (assert) {
25936 var i, testMoment;
25937 for (i = 1; i <= 31; ++i) {
25938 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
25939 assert.equal(testMoment.year(), 2014,
25940 'lenient day of month ordinal parsing of number ' + i + ' year check');
25941 assert.equal(testMoment.month(), 0,
25942 'lenient day of month ordinal parsing of number ' + i + ' month check');
25943 assert.equal(testMoment.date(), i,
25944 'lenient day of month ordinal parsing of number ' + i + ' date check');
25945 }
25946 });
25947
25948 test('strict day of month ordinal parsing', function (assert) {
25949 var i, ordinalStr, testMoment;
25950 for (i = 1; i <= 31; ++i) {
25951 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
25952 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
25953 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
25954 }
25955 });
25956
25957 test('meridiem invariant', function (assert) {
25958 var h, m, t1, t2;
25959 for (h = 0; h < 24; ++h) {
25960 for (m = 0; m < 60; m += 15) {
25961 t1 = moment.utc([2000, 0, 1, h, m]);
25962 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
25963 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
25964 'meridiem at ' + t1.format('HH:mm'));
25965 }
25966 }
25967 });
25968
25969 test('date format correctness', function (assert) {
25970 var data, tokens;
25971 data = moment.localeData()._longDateFormat;
25972 tokens = objectKeys(data);
25973 each(tokens, function (srchToken) {
25974 // Check each format string to make sure it does not contain any
25975 // tokens that need to be expanded.
25976 each(tokens, function (baseToken) {
25977 // strip escaped sequences
25978 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
25979 assert.equal(false, !!~format.indexOf(srchToken),
25980 'contains ' + srchToken + ' in ' + baseToken);
25981 });
25982 });
25983 });
25984
25985 test('month parsing correctness', function (assert) {
25986 var i, m;
25987
25988 if (locale === 'tr') {
25989 // I can't fix it :(
c58511b9 25990 assert.expect(0);
db71a655
KM
25991 return;
25992 }
25993 function tester(format) {
25994 var r;
25995 r = moment(m.format(format), format);
25996 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
25997 if (locale !== 'ka') {
25998 r = moment(m.format(format).toLocaleUpperCase(), format);
25999 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
26000 }
db71a655
KM
26001 r = moment(m.format(format).toLocaleLowerCase(), format);
26002 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
26003
26004 r = moment(m.format(format), format, true);
26005 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
26006 if (locale !== 'ka') {
26007 r = moment(m.format(format).toLocaleUpperCase(), format, true);
26008 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
26009 }
db71a655
KM
26010 r = moment(m.format(format).toLocaleLowerCase(), format, true);
26011 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
26012 }
26013
26014 for (i = 0; i < 12; ++i) {
26015 m = moment([2015, i, 15, 18]);
26016 tester('MMM');
26017 tester('MMM.');
26018 tester('MMMM');
26019 tester('MMMM.');
26020 }
26021 });
26022
26023 test('weekday parsing correctness', function (assert) {
26024 var i, m;
26025
96d0d679 26026 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
26027 // tr, az: There is a lower-case letter (ı), that converted to
26028 // upper then lower changes to i
26029 // ro: there is the letter ț which behaves weird under IE8
26030 // mt: letter Ħ
96d0d679 26031 // ga: month with spaces
c58511b9 26032 assert.expect(0);
db71a655
KM
26033 return;
26034 }
26035 function tester(format) {
26036 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
26037 r = moment(m.format(format), format);
26038 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
26039 if (locale !== 'ka') {
26040 r = moment(m.format(format).toLocaleUpperCase(), format);
26041 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
26042 }
db71a655
KM
26043 r = moment(m.format(format).toLocaleLowerCase(), format);
26044 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
26045 r = moment(m.format(format), format, true);
26046 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
26047 if (locale !== 'ka') {
26048 r = moment(m.format(format).toLocaleUpperCase(), format, true);
26049 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
26050 }
db71a655
KM
26051 r = moment(m.format(format).toLocaleLowerCase(), format, true);
26052 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
26053 }
26054
26055 for (i = 0; i < 7; ++i) {
26056 m = moment.utc([2015, 0, i + 1, 18]);
26057 tester('dd');
26058 tester('ddd');
26059 tester('dddd');
26060 }
26061 });
26062
26063 test('valid localeData', function (assert) {
26064 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
26065 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
26066 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
26067 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
26068 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
26069 });
96d0d679
KM
26070
26071 test('localeData weekdays can localeSort', function (assert) {
26072 var weekdays = moment().localeData().weekdays();
26073 var weekdaysShort = moment().localeData().weekdaysShort();
26074 var weekdaysMin = moment().localeData().weekdaysMin();
26075 var shift = moment().localeData()._week.dow;
26076 assert.deepEqual(
26077 moment().localeData().weekdays(true),
26078 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
26079 'weekdays should localeSort');
26080 assert.deepEqual(
26081 moment().localeData().weekdaysShort(true),
26082 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
26083 'weekdaysShort should localeSort');
26084 assert.deepEqual(
26085 moment().localeData().weekdaysMin(true),
26086 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
26087 'weekdaysMin should localeSort');
26088 });
516f5f67
IC
26089 }
26090
db71a655 26091 /*global QUnit:false*/
516f5f67 26092
db71a655
KM
26093 function localeModule (name, lifecycle) {
26094 QUnit.module('locale:' + name, {
c58511b9 26095 beforeEach : function () {
db71a655
KM
26096 moment.locale(name);
26097 moment.createFromInputFallback = function (config) {
26098 throw new Error('input not handled by moment: ' + config._i);
26099 };
26100 setupDeprecationHandler(test, moment, 'locale');
26101 if (lifecycle && lifecycle.setup) {
26102 lifecycle.setup();
26103 }
26104 },
c58511b9 26105 afterEach : function () {
db71a655
KM
26106 moment.locale('en');
26107 teardownDeprecationHandler(test, moment, 'locale');
26108 if (lifecycle && lifecycle.teardown) {
26109 lifecycle.teardown();
26110 }
73f3c911 26111 }
db71a655
KM
26112 });
26113 defineCommonLocaleTests(name, -1, -1);
26114 }
26115
96d0d679 26116 localeModule('gu');
db71a655
KM
26117
26118 test('parse', function (assert) {
96d0d679 26119 var tests = 'જાન્યુઆરી જાન્યુ._ફેબ્રુઆરી ફેબ્રુ._માર્ચ માર્ચ_એપ્રિલ એપ્રિ._મે મે_જૂન જૂન_જુલાઈ જુલા._ઑગસ્ટ ઑગ._સપ્ટેમ્બર સપ્ટે._ઑક્ટ્બર ઑક્ટ્._નવેમ્બર નવે._ડિસેમ્બર ડિસે..'.split('_'), i;
db71a655
KM
26120 function equalTest(input, mmm, i) {
26121 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
26122 }
db71a655
KM
26123 for (i = 0; i < 12; i++) {
26124 tests[i] = tests[i].split(' ');
26125 equalTest(tests[i][0], 'MMM', i);
26126 equalTest(tests[i][1], 'MMM', i);
26127 equalTest(tests[i][0], 'MMMM', i);
26128 equalTest(tests[i][1], 'MMMM', i);
26129 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
26130 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
26131 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
26132 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
26133 }
26134 });
26135
26136 test('format', function (assert) {
26137 var a = [
96d0d679
KM
26138 ['dddd, Do MMMM YYYY, a h:mm:ss વાગ્યે', 'રવિવાર, ૧૪ ફેબ્રુઆરી ૨૦૧૦, બપોર ૩:૨૫:૫૦ વાગ્યે'],
26139 ['ddd, a h વાગ્યે', 'રવિ, બપોર ૩ વાગ્યે'],
26140 ['M Mo MM MMMM MMM', '૨ ૨ ૦૨ ફેબ્રુઆરી ફેબ્રુ.'],
26141 ['YYYY YY', '૨૦૧૦ ૧૦'],
26142 ['D Do DD', '૧૪ ૧૪ ૧૪'],
26143 ['d do dddd ddd dd', '૦ ૦ રવિવાર રવિ ર'],
26144 ['DDD DDDo DDDD', '૪૫ ૪૫ ૦૪૫'],
26145 ['w wo ww', '૮ ૮ ૦૮'],
26146 ['h hh', '૩ ૦૩'],
26147 ['H HH', '૧૫ ૧૫'],
26148 ['m mm', '૨૫ ૨૫'],
26149 ['s ss', '૫૦ ૫૦'],
26150 ['a A', 'બપોર બપોર'],
26151 ['LTS', 'બપોર ૩:૨૫:૫૦ વાગ્યે'],
26152 ['L', '૧૪/૦૨/૨૦૧૦'],
26153 ['LL', '૧૪ ફેબ્રુઆરી ૨૦૧૦'],
26154 ['LLL', '૧૪ ફેબ્રુઆરી ૨૦૧૦, બપોર ૩:૨૫ વાગ્યે'],
26155 ['LLLL', 'રવિવાર, ૧૪ ફેબ્રુઆરી ૨૦૧૦, બપોર ૩:૨૫ વાગ્યે'],
26156 ['l', '૧૪/૨/૨૦૧૦'],
26157 ['ll', '૧૪ ફેબ્રુ. ૨૦૧૦'],
26158 ['lll', '૧૪ ફેબ્રુ. ૨૦૧૦, બપોર ૩:૨૫ વાગ્યે'],
26159 ['llll', 'રવિ, ૧૪ ફેબ્રુ. ૨૦૧૦, બપોર ૩:૨૫ વાગ્યે']
db71a655
KM
26160 ],
26161 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
26162 i;
db71a655
KM
26163 for (i = 0; i < a.length; i++) {
26164 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
26165 }
26166 });
26167
26168 test('format ordinal', function (assert) {
96d0d679
KM
26169 assert.equal(moment([2011, 0, 1]).format('DDDo'), '૧', '૧');
26170 assert.equal(moment([2011, 0, 2]).format('DDDo'), '૨', '૨');
26171 assert.equal(moment([2011, 0, 3]).format('DDDo'), '૩', '૩');
26172 assert.equal(moment([2011, 0, 4]).format('DDDo'), '૪', '૪');
26173 assert.equal(moment([2011, 0, 5]).format('DDDo'), '૫', '૫');
26174 assert.equal(moment([2011, 0, 6]).format('DDDo'), '૬', '૬');
26175 assert.equal(moment([2011, 0, 7]).format('DDDo'), '૭', '૭');
26176 assert.equal(moment([2011, 0, 8]).format('DDDo'), '૮', '૮');
26177 assert.equal(moment([2011, 0, 9]).format('DDDo'), '૯', '૯');
26178 assert.equal(moment([2011, 0, 10]).format('DDDo'), '૧૦', '૧૦');
db71a655 26179
96d0d679
KM
26180 assert.equal(moment([2011, 0, 11]).format('DDDo'), '૧૧', '૧૧');
26181 assert.equal(moment([2011, 0, 12]).format('DDDo'), '૧૨', '૧૨');
26182 assert.equal(moment([2011, 0, 13]).format('DDDo'), '૧૩', '૧૩');
26183 assert.equal(moment([2011, 0, 14]).format('DDDo'), '૧૪', '૧૪');
26184 assert.equal(moment([2011, 0, 15]).format('DDDo'), '૧૫', '૧૫');
26185 assert.equal(moment([2011, 0, 16]).format('DDDo'), '૧૬', '૧૬');
26186 assert.equal(moment([2011, 0, 17]).format('DDDo'), '૧૭', '૧૭');
26187 assert.equal(moment([2011, 0, 18]).format('DDDo'), '૧૮', '૧૮');
26188 assert.equal(moment([2011, 0, 19]).format('DDDo'), '૧૯', '૧૯');
26189 assert.equal(moment([2011, 0, 20]).format('DDDo'), '૨૦', '૨૦');
db71a655 26190
96d0d679
KM
26191 assert.equal(moment([2011, 0, 21]).format('DDDo'), '૨૧', '૨૧');
26192 assert.equal(moment([2011, 0, 22]).format('DDDo'), '૨૨', '૨૨');
26193 assert.equal(moment([2011, 0, 23]).format('DDDo'), '૨૩', '૨૩');
26194 assert.equal(moment([2011, 0, 24]).format('DDDo'), '૨૪', '૨૪');
26195 assert.equal(moment([2011, 0, 25]).format('DDDo'), '૨૫', '૨૫');
26196 assert.equal(moment([2011, 0, 26]).format('DDDo'), '૨૬', '૨૬');
26197 assert.equal(moment([2011, 0, 27]).format('DDDo'), '૨૭', '૨૭');
26198 assert.equal(moment([2011, 0, 28]).format('DDDo'), '૨૮', '૨૮');
26199 assert.equal(moment([2011, 0, 29]).format('DDDo'), '૨૯', '૨૯');
26200 assert.equal(moment([2011, 0, 30]).format('DDDo'), '૩૦', '૩૦');
db71a655 26201
96d0d679 26202 assert.equal(moment([2011, 0, 31]).format('DDDo'), '૩૧', '૩૧');
db71a655
KM
26203 });
26204
26205 test('format month', function (assert) {
96d0d679 26206 var expected = 'જાન્યુઆરી જાન્યુ._ફેબ્રુઆરી ફેબ્રુ._માર્ચ માર્ચ_એપ્રિલ એપ્રિ._મે મે_જૂન જૂન_જુલાઈ જુલા._ઑગસ્ટ ઑગ._સપ્ટેમ્બર સપ્ટે._ઑક્ટ્બર ઑક્ટ્._નવેમ્બર નવે._ડિસેમ્બર ડિસે.'.split('_'), i;
db71a655
KM
26207 for (i = 0; i < expected.length; i++) {
26208 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
26209 }
26210 });
26211
26212 test('format week', function (assert) {
96d0d679 26213 var expected = 'રવિવાર રવિ ર_સોમવાર સોમ સો_મંગળવાર મંગળ મં_બુધ્વાર બુધ્ બુ_ગુરુવાર ગુરુ ગુ_શુક્રવાર શુક્ર શુ_શનિવાર શનિ શ'.split('_'), i;
db71a655
KM
26214 for (i = 0; i < expected.length; i++) {
26215 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
26216 }
26217 });
26218
26219 test('from', function (assert) {
26220 var start = moment([2007, 1, 28]);
96d0d679
KM
26221 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'અમુક પળો', '44 seconds = a few seconds');
26222 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'એક મિનિટ', '45 seconds = a minute');
26223 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'એક મિનિટ', '89 seconds = a minute');
26224 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '૨ મિનિટ', '90 seconds = 2 minutes');
26225 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '૪૪ મિનિટ', '44 minutes = 44 minutes');
26226 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'એક કલાક', '45 minutes = an hour');
26227 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'એક કલાક', '89 minutes = an hour');
26228 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '૨ કલાક', '90 minutes = 2 hours');
26229 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '૫ કલાક', '5 hours = 5 hours');
26230 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '૨૧ કલાક', '21 hours = 21 hours');
26231 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'એક દિવસ', '22 hours = a day');
26232 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'એક દિવસ', '35 hours = a day');
26233 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '૨ દિવસ', '36 hours = 2 days');
26234 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'એક દિવસ', '1 day = a day');
26235 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '૫ દિવસ', '5 days = 5 days');
26236 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '૨૫ દિવસ', '25 days = 25 days');
26237 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'એક મહિનો', '26 days = a month');
26238 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'એક મહિનો', '30 days = a month');
26239 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'એક મહિનો', '43 days = a month');
26240 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '૨ મહિનો', '46 days = 2 months');
26241 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '૨ મહિનો', '75 days = 2 months');
26242 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '૩ મહિનો', '76 days = 3 months');
26243 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'એક મહિનો', '1 month = a month');
26244 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '૫ મહિનો', '5 months = 5 months');
26245 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'એક વર્ષ', '345 days = a year');
26246 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '૨ વર્ષ', '548 days = 2 years');
26247 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'એક વર્ષ', '1 year = a year');
26248 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '૫ વર્ષ', '5 years = 5 years');
db71a655
KM
26249 });
26250
26251 test('suffix', function (assert) {
96d0d679
KM
26252 assert.equal(moment(30000).from(0), 'અમુક પળો મા', 'prefix');
26253 assert.equal(moment(0).from(30000), 'અમુક પળો પેહલા', 'suffix');
db71a655
KM
26254 });
26255
26256 test('now from now', function (assert) {
96d0d679 26257 assert.equal(moment().fromNow(), 'અમુક પળો પેહલા', 'now from now should display as in the past');
db71a655
KM
26258 });
26259
26260 test('fromNow', function (assert) {
96d0d679
KM
26261 assert.equal(moment().add({s: 30}).fromNow(), 'અમુક પળો મા', 'અમુક પળો મા');
26262 assert.equal(moment().add({d: 5}).fromNow(), '૫ દિવસ મા', '૫ દિવસ મા');
db71a655
KM
26263 });
26264
26265 test('calendar day', function (assert) {
96d0d679 26266 var a = moment().hours(2).minutes(0).seconds(0);
db71a655 26267
96d0d679
KM
26268 assert.equal(moment(a).calendar(), 'આજ રાત ૨:૦૦ વાગ્યે', 'today at the same time');
26269 assert.equal(moment(a).add({m: 25}).calendar(), 'આજ રાત ૨:૨૫ વાગ્યે', 'Now plus 25 min');
26270 assert.equal(moment(a).add({h: 3}).calendar(), 'આજ સવાર ૫:૦૦ વાગ્યે', 'Now plus 3 hour');
26271 assert.equal(moment(a).add({d: 1}).calendar(), 'કાલે રાત ૨:૦૦ વાગ્યે', 'tomorrow at the same time');
26272 assert.equal(moment(a).subtract({h: 1}).calendar(), 'આજ રાત ૧:૦૦ વાગ્યે', 'Now minus 1 hour');
26273 assert.equal(moment(a).subtract({d: 1}).calendar(), 'ગઇકાલે રાત ૨:૦૦ વાગ્યે', 'yesterday at the same time');
db71a655
KM
26274 });
26275
26276 test('calendar next week', function (assert) {
26277 var i, m;
db71a655
KM
26278 for (i = 2; i < 7; i++) {
26279 m = moment().add({d: i});
96d0d679 26280 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days current time');
db71a655 26281 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 26282 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days beginning of day');
db71a655 26283 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 26284 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days end of day');
db71a655
KM
26285 }
26286 });
26287
26288 test('calendar last week', function (assert) {
26289 var i, m;
26290
26291 for (i = 2; i < 7; i++) {
26292 m = moment().subtract({d: i});
96d0d679 26293 assert.equal(m.calendar(), m.format('[પાછલા] dddd[,] LT'), 'Today - ' + i + ' days current time');
db71a655 26294 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 26295 assert.equal(m.calendar(), m.format('[પાછલા] dddd[,] LT'), 'Today - ' + i + ' days beginning of day');
db71a655 26296 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 26297 assert.equal(m.calendar(), m.format('[પાછલા] dddd[,] LT'), 'Today - ' + i + ' days end of day');
db71a655
KM
26298 }
26299 });
26300
26301 test('calendar all else', function (assert) {
26302 var weeksAgo = moment().subtract({w: 1}),
26303 weeksFromNow = moment().add({w: 1});
26304
26305 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
26306 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
26307
26308 weeksAgo = moment().subtract({w: 2});
26309 weeksFromNow = moment().add({w: 2});
26310
26311 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
26312 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
26313 });
26314
96d0d679
KM
26315 test('meridiem', function (assert) {
26316 assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), 'રાત', 'before dawn');
26317 assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), 'સવાર', 'morning');
26318 assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), 'બપોર', 'during day');
26319 assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), 'સાંજ', 'evening');
26320 assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), 'સાંજ', 'late evening');
26321 assert.equal(moment([2011, 2, 23, 21, 20]).format('a'), 'રાત', 'night');
26322
26323 assert.equal(moment([2011, 2, 23, 2, 30]).format('A'), 'રાત', 'before dawn');
26324 assert.equal(moment([2011, 2, 23, 9, 30]).format('A'), 'સવાર', 'morning');
26325 assert.equal(moment([2011, 2, 23, 14, 30]).format('A'), 'બપોર', ' during day');
26326 assert.equal(moment([2011, 2, 23, 17, 30]).format('A'), 'સાંજ', 'evening');
26327 assert.equal(moment([2011, 2, 23, 19, 30]).format('A'), 'સાંજ', 'late evening');
26328 assert.equal(moment([2011, 2, 23, 21, 20]).format('A'), 'રાત', 'night');
26329 });
26330
26331 test('weeks year starting sunday formatted', function (assert) {
26332 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '૧ ૦૧ ૧', 'Jan 1 2012 should be week 1');
26333 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '૧ ૦૧ ૧', 'Jan 7 2012 should be week 1');
26334 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '૨ ૦૨ ૨', 'Jan 8 2012 should be week 2');
26335 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '૨ ૦૨ ૨', 'Jan 14 2012 should be week 2');
26336 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '૩ ૦૩ ૩', 'Jan 15 2012 should be week 3');
db71a655 26337 });
73f3c911
IC
26338
26339})));
516f5f67 26340
516f5f67 26341
c74a101d
IC
26342;(function (global, factory) {
26343 typeof exports === 'object' && typeof module !== 'undefined'
26344 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
26345 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
26346 factory(global.moment)
73f3c911 26347}(this, (function (moment) { 'use strict';
516f5f67 26348
db71a655
KM
26349 function each(array, callback) {
26350 var i;
26351 for (i = 0; i < array.length; i++) {
26352 callback(array[i], i, array);
26353 }
b135bf1a
IC
26354 }
26355
c58511b9
KM
26356 function setupDeprecationHandler(test, moment$$1, scope) {
26357 test._expectedDeprecations = null;
26358 test._observedDeprecations = null;
26359 test._oldSupress = moment$$1.suppressDeprecationWarnings;
26360 moment$$1.suppressDeprecationWarnings = true;
26361 test.expectedDeprecations = function () {
26362 test._expectedDeprecations = arguments;
26363 test._observedDeprecations = [];
26364 };
26365 moment$$1.deprecationHandler = function (name, msg) {
26366 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
26367 if (deprecationId === -1) {
26368 throw new Error('Unexpected deprecation thrown name=' +
26369 name + ' msg=' + msg);
26370 }
26371 test._observedDeprecations[deprecationId] = 1;
26372 };
26373 }
26374
26375 function teardownDeprecationHandler(test, moment$$1, scope) {
26376 moment$$1.suppressDeprecationWarnings = test._oldSupress;
26377
26378 if (test._expectedDeprecations != null) {
26379 var missedDeprecations = [];
26380 each(test._expectedDeprecations, function (deprecationPattern, id) {
26381 if (test._observedDeprecations[id] !== 1) {
26382 missedDeprecations.push(deprecationPattern);
26383 }
26384 });
26385 if (missedDeprecations.length !== 0) {
26386 throw new Error('Expected deprecation warnings did not happen: ' +
26387 missedDeprecations.join(' '));
26388 }
26389 }
26390 }
26391
26392 function matchedDeprecation(name, msg, deprecations) {
26393 if (deprecations == null) {
26394 return -1;
26395 }
26396 for (var i = 0; i < deprecations.length; ++i) {
26397 if (name != null && name === deprecations[i]) {
26398 return i;
26399 }
26400 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
26401 return i;
26402 }
26403 }
26404 return -1;
26405 }
26406
26407 /*global QUnit:false*/
26408
26409 var test = QUnit.test;
26410
db71a655
KM
26411 function objectKeys(obj) {
26412 if (Object.keys) {
26413 return Object.keys(obj);
26414 } else {
26415 // IE8
26416 var res = [], i;
26417 for (i in obj) {
26418 if (obj.hasOwnProperty(i)) {
26419 res.push(i);
26420 }
b135bf1a 26421 }
db71a655 26422 return res;
b135bf1a 26423 }
b135bf1a
IC
26424 }
26425
db71a655 26426 // Pick the first defined of two or three arguments.
b135bf1a 26427
db71a655
KM
26428 function defineCommonLocaleTests(locale, options) {
26429 test('lenient day of month ordinal parsing', function (assert) {
26430 var i, ordinalStr, testMoment;
26431 for (i = 1; i <= 31; ++i) {
26432 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
26433 testMoment = moment(ordinalStr, 'YYYY MM Do');
26434 assert.equal(testMoment.year(), 2014,
26435 'lenient day of month ordinal parsing ' + i + ' year check');
26436 assert.equal(testMoment.month(), 0,
26437 'lenient day of month ordinal parsing ' + i + ' month check');
26438 assert.equal(testMoment.date(), i,
26439 'lenient day of month ordinal parsing ' + i + ' date check');
26440 }
26441 });
b135bf1a 26442
db71a655
KM
26443 test('lenient day of month ordinal parsing of number', function (assert) {
26444 var i, testMoment;
26445 for (i = 1; i <= 31; ++i) {
26446 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
26447 assert.equal(testMoment.year(), 2014,
26448 'lenient day of month ordinal parsing of number ' + i + ' year check');
26449 assert.equal(testMoment.month(), 0,
26450 'lenient day of month ordinal parsing of number ' + i + ' month check');
26451 assert.equal(testMoment.date(), i,
26452 'lenient day of month ordinal parsing of number ' + i + ' date check');
26453 }
26454 });
26455
26456 test('strict day of month ordinal parsing', function (assert) {
26457 var i, ordinalStr, testMoment;
26458 for (i = 1; i <= 31; ++i) {
26459 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
26460 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
26461 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
26462 }
26463 });
26464
26465 test('meridiem invariant', function (assert) {
26466 var h, m, t1, t2;
26467 for (h = 0; h < 24; ++h) {
26468 for (m = 0; m < 60; m += 15) {
26469 t1 = moment.utc([2000, 0, 1, h, m]);
26470 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
26471 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
26472 'meridiem at ' + t1.format('HH:mm'));
26473 }
26474 }
26475 });
26476
26477 test('date format correctness', function (assert) {
26478 var data, tokens;
26479 data = moment.localeData()._longDateFormat;
26480 tokens = objectKeys(data);
26481 each(tokens, function (srchToken) {
26482 // Check each format string to make sure it does not contain any
26483 // tokens that need to be expanded.
26484 each(tokens, function (baseToken) {
26485 // strip escaped sequences
26486 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
26487 assert.equal(false, !!~format.indexOf(srchToken),
26488 'contains ' + srchToken + ' in ' + baseToken);
26489 });
26490 });
26491 });
26492
26493 test('month parsing correctness', function (assert) {
26494 var i, m;
26495
26496 if (locale === 'tr') {
26497 // I can't fix it :(
c58511b9 26498 assert.expect(0);
db71a655
KM
26499 return;
26500 }
26501 function tester(format) {
26502 var r;
26503 r = moment(m.format(format), format);
26504 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
26505 if (locale !== 'ka') {
26506 r = moment(m.format(format).toLocaleUpperCase(), format);
26507 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
26508 }
db71a655
KM
26509 r = moment(m.format(format).toLocaleLowerCase(), format);
26510 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
26511
26512 r = moment(m.format(format), format, true);
26513 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
26514 if (locale !== 'ka') {
26515 r = moment(m.format(format).toLocaleUpperCase(), format, true);
26516 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
26517 }
db71a655
KM
26518 r = moment(m.format(format).toLocaleLowerCase(), format, true);
26519 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
26520 }
26521
26522 for (i = 0; i < 12; ++i) {
26523 m = moment([2015, i, 15, 18]);
26524 tester('MMM');
26525 tester('MMM.');
26526 tester('MMMM');
26527 tester('MMMM.');
26528 }
26529 });
26530
26531 test('weekday parsing correctness', function (assert) {
26532 var i, m;
26533
96d0d679 26534 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
26535 // tr, az: There is a lower-case letter (ı), that converted to
26536 // upper then lower changes to i
26537 // ro: there is the letter ț which behaves weird under IE8
26538 // mt: letter Ħ
96d0d679 26539 // ga: month with spaces
c58511b9 26540 assert.expect(0);
db71a655
KM
26541 return;
26542 }
26543 function tester(format) {
26544 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
26545 r = moment(m.format(format), format);
26546 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
26547 if (locale !== 'ka') {
26548 r = moment(m.format(format).toLocaleUpperCase(), format);
26549 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
26550 }
db71a655
KM
26551 r = moment(m.format(format).toLocaleLowerCase(), format);
26552 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
26553 r = moment(m.format(format), format, true);
26554 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
26555 if (locale !== 'ka') {
26556 r = moment(m.format(format).toLocaleUpperCase(), format, true);
26557 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
26558 }
db71a655
KM
26559 r = moment(m.format(format).toLocaleLowerCase(), format, true);
26560 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
26561 }
26562
26563 for (i = 0; i < 7; ++i) {
26564 m = moment.utc([2015, 0, i + 1, 18]);
26565 tester('dd');
26566 tester('ddd');
26567 tester('dddd');
26568 }
26569 });
26570
26571 test('valid localeData', function (assert) {
26572 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
26573 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
26574 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
26575 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
26576 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
26577 });
96d0d679
KM
26578
26579 test('localeData weekdays can localeSort', function (assert) {
26580 var weekdays = moment().localeData().weekdays();
26581 var weekdaysShort = moment().localeData().weekdaysShort();
26582 var weekdaysMin = moment().localeData().weekdaysMin();
26583 var shift = moment().localeData()._week.dow;
26584 assert.deepEqual(
26585 moment().localeData().weekdays(true),
26586 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
26587 'weekdays should localeSort');
26588 assert.deepEqual(
26589 moment().localeData().weekdaysShort(true),
26590 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
26591 'weekdaysShort should localeSort');
26592 assert.deepEqual(
26593 moment().localeData().weekdaysMin(true),
26594 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
26595 'weekdaysMin should localeSort');
26596 });
db71a655
KM
26597 }
26598
db71a655
KM
26599 /*global QUnit:false*/
26600
db71a655
KM
26601 function localeModule (name, lifecycle) {
26602 QUnit.module('locale:' + name, {
c58511b9 26603 beforeEach : function () {
db71a655
KM
26604 moment.locale(name);
26605 moment.createFromInputFallback = function (config) {
26606 throw new Error('input not handled by moment: ' + config._i);
26607 };
26608 setupDeprecationHandler(test, moment, 'locale');
26609 if (lifecycle && lifecycle.setup) {
26610 lifecycle.setup();
26611 }
26612 },
c58511b9 26613 afterEach : function () {
db71a655
KM
26614 moment.locale('en');
26615 teardownDeprecationHandler(test, moment, 'locale');
26616 if (lifecycle && lifecycle.teardown) {
26617 lifecycle.teardown();
26618 }
26619 }
26620 });
26621 defineCommonLocaleTests(name, -1, -1);
26622 }
26623
96d0d679 26624 localeModule('he');
db71a655
KM
26625
26626 test('parse', function (assert) {
96d0d679 26627 var tests = 'ינואר ינו׳_פברואר פבר׳_מרץ מרץ_אפריל אפר׳_מאי מאי_יוני יוני_יולי יולי_אוגוסט אוג׳_ספטמבר ספט׳_אוקטובר אוק׳_נובמבר נוב׳_דצמבר דצמ׳'.split('_'), i;
db71a655
KM
26628 function equalTest(input, mmm, i) {
26629 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
26630 }
26631 for (i = 0; i < 12; i++) {
26632 tests[i] = tests[i].split(' ');
26633 equalTest(tests[i][0], 'MMM', i);
26634 equalTest(tests[i][1], 'MMM', i);
26635 equalTest(tests[i][0], 'MMMM', i);
26636 equalTest(tests[i][1], 'MMMM', i);
26637 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
26638 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
26639 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
26640 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
26641 }
26642 });
26643
26644 test('format', function (assert) {
26645 var a = [
96d0d679
KM
26646 ['dddd, MMMM Do YYYY, h:mm:ss a', 'ראשון, פברואר 14 2010, 3:25:50 אחה"צ'],
26647 ['ddd, h A', 'א׳, 3 אחרי הצהריים'],
26648 ['M Mo MM MMMM MMM', '2 2 02 פברואר פבר׳'],
26649 ['YYYY YY', '2010 10'],
26650 ['D Do DD', '14 14 14'],
26651 ['d do dddd ddd dd', '0 0 ראשון א׳ א'],
26652 ['DDD DDDo DDDD', '45 45 045'],
26653 ['w wo ww', '8 8 08'],
26654 ['h hh', '3 03'],
26655 ['H HH', '15 15'],
26656 ['m mm', '25 25'],
26657 ['s ss', '50 50'],
26658 ['a A', 'אחה"צ אחרי הצהריים'],
26659 ['[the] DDDo [day of the year]', 'the 45 day of the year'],
26660 ['LTS', '15:25:50'],
26661 ['L', '14/02/2010'],
26662 ['LL', '14 בפברואר 2010'],
26663 ['LLL', '14 בפברואר 2010 15:25'],
26664 ['LLLL', 'ראשון, 14 בפברואר 2010 15:25'],
26665 ['l', '14/2/2010'],
26666 ['ll', '14 פבר׳ 2010'],
26667 ['lll', '14 פבר׳ 2010 15:25'],
26668 ['llll', 'א׳, 14 פבר׳ 2010 15:25']
db71a655
KM
26669 ],
26670 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
26671 i;
26672 for (i = 0; i < a.length; i++) {
26673 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
26674 }
26675 });
26676
db71a655 26677 test('format month', function (assert) {
96d0d679 26678 var expected = 'ינואר ינו׳_פברואר פבר׳_מרץ מרץ_אפריל אפר׳_מאי מאי_יוני יוני_יולי יולי_אוגוסט אוג׳_ספטמבר ספט׳_אוקטובר אוק׳_נובמבר נוב׳_דצמבר דצמ׳'.split('_'), i;
db71a655
KM
26679 for (i = 0; i < expected.length; i++) {
26680 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
26681 }
26682 });
26683
26684 test('format week', function (assert) {
96d0d679 26685 var expected = 'ראשון א׳ א|שני ב׳ ב|שלישי ג׳ ג|רביעי ד׳ ד|חמישי ה׳ ה|שישי ו׳ ו|שבת ש׳ ש'.split('|'), i;
db71a655
KM
26686 for (i = 0; i < expected.length; i++) {
26687 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
26688 }
26689 });
26690
26691 test('from', function (assert) {
26692 var start = moment([2007, 1, 28]);
96d0d679
KM
26693 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'מספר שניות', '44 seconds = a few seconds');
26694 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'דקה', '45 seconds = a minute');
26695 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'דקה', '89 seconds = a minute');
26696 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 דקות', '90 seconds = 2 minutes');
26697 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 דקות', '44 minutes = 44 minutes');
26698 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'שעה', '45 minutes = an hour');
26699 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'שעה', '89 minutes = an hour');
26700 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), 'שעתיים', '90 minutes = 2 hours');
26701 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 שעות', '5 hours = 5 hours');
26702 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 שעות', '21 hours = 21 hours');
26703 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'יום', '22 hours = a day');
26704 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'יום', '35 hours = a day');
26705 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), 'יומיים', '36 hours = 2 days');
26706 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'יום', '1 day = a day');
26707 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ימים', '5 days = 5 days');
26708 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ימים', '25 days = 25 days');
26709 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'חודש', '26 days = a month');
26710 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'חודש', '30 days = a month');
26711 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'חודש', '43 days = a month');
26712 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), 'חודשיים', '46 days = 2 months');
26713 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), 'חודשיים', '75 days = 2 months');
26714 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 חודשים', '76 days = 3 months');
26715 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'חודש', '1 month = a month');
26716 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 חודשים', '5 months = 5 months');
26717 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'שנה', '345 days = a year');
26718 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), 'שנתיים', '548 days = 2 years');
26719 assert.equal(start.from(moment([2007, 1, 28]).add({d: 3699}), true), '10 שנים', '345 days = 10 years');
26720 assert.equal(start.from(moment([2007, 1, 28]).add({d: 7340}), true), '20 שנה', '548 days = 20 years');
26721 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'שנה', '1 year = a year');
26722 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 שנים', '5 years = 5 years');
db71a655
KM
26723 });
26724
26725 test('suffix', function (assert) {
96d0d679
KM
26726 assert.equal(moment(30000).from(0), 'בעוד מספר שניות', 'prefix');
26727 assert.equal(moment(0).from(30000), 'לפני מספר שניות', 'suffix');
db71a655
KM
26728 });
26729
26730 test('now from now', function (assert) {
96d0d679 26731 assert.equal(moment().fromNow(), 'לפני מספר שניות', 'now from now should display as in the past');
db71a655
KM
26732 });
26733
26734 test('fromNow', function (assert) {
96d0d679
KM
26735 assert.equal(moment().add({s: 30}).fromNow(), 'בעוד מספר שניות', 'in a few seconds');
26736 assert.equal(moment().add({d: 5}).fromNow(), 'בעוד 5 ימים', 'in 5 days');
db71a655
KM
26737 });
26738
26739 test('calendar day', function (assert) {
96d0d679 26740 var a = moment().hours(12).minutes(0).seconds(0);
db71a655 26741
96d0d679
KM
26742 assert.equal(moment(a).calendar(), 'היום ב־12:00', 'today at the same time');
26743 assert.equal(moment(a).add({m: 25}).calendar(), 'היום ב־12:25', 'Now plus 25 min');
26744 assert.equal(moment(a).add({h: 1}).calendar(), 'היום ב־13:00', 'Now plus 1 hour');
26745 assert.equal(moment(a).add({d: 1}).calendar(), 'מחר ב־12:00', 'tomorrow at the same time');
26746 assert.equal(moment(a).subtract({h: 1}).calendar(), 'היום ב־11:00', 'Now minus 1 hour');
26747 assert.equal(moment(a).subtract({d: 1}).calendar(), 'אתמול ב־12:00', 'yesterday at the same time');
db71a655
KM
26748 });
26749
26750 test('calendar next week', function (assert) {
26751 var i, m;
26752 for (i = 2; i < 7; i++) {
26753 m = moment().add({d: i});
96d0d679 26754 assert.equal(m.calendar(), m.format('dddd [בשעה] LT'), 'Today + ' + i + ' days current time');
db71a655 26755 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 26756 assert.equal(m.calendar(), m.format('dddd [בשעה] LT'), 'Today + ' + i + ' days beginning of day');
db71a655 26757 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 26758 assert.equal(m.calendar(), m.format('dddd [בשעה] LT'), 'Today + ' + i + ' days end of day');
db71a655
KM
26759 }
26760 });
26761
26762 test('calendar last week', function (assert) {
26763 var i, m;
db71a655
KM
26764 for (i = 2; i < 7; i++) {
26765 m = moment().subtract({d: i});
96d0d679 26766 assert.equal(m.calendar(), m.format('[ביום] dddd [האחרון בשעה] LT'), 'Today - ' + i + ' days current time');
db71a655 26767 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 26768 assert.equal(m.calendar(), m.format('[ביום] dddd [האחרון בשעה] LT'), 'Today - ' + i + ' days beginning of day');
db71a655 26769 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 26770 assert.equal(m.calendar(), m.format('[ביום] dddd [האחרון בשעה] LT'), 'Today - ' + i + ' days end of day');
db71a655
KM
26771 }
26772 });
26773
26774 test('calendar all else', function (assert) {
26775 var weeksAgo = moment().subtract({w: 1}),
26776 weeksFromNow = moment().add({w: 1});
26777
26778 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
26779 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
26780
26781 weeksAgo = moment().subtract({w: 2});
26782 weeksFromNow = moment().add({w: 2});
26783
26784 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
26785 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
26786 });
26787
96d0d679
KM
26788 test('weeks year starting sunday format', function (assert) {
26789 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1');
26790 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1', 'Jan 7 2012 should be week 1');
26791 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2');
26792 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2', 'Jan 14 2012 should be week 2');
26793 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', 'Jan 15 2012 should be week 3');
db71a655
KM
26794 });
26795
26796})));
26797
26798
26799;(function (global, factory) {
26800 typeof exports === 'object' && typeof module !== 'undefined'
26801 && typeof require === 'function' ? factory(require('../../moment')) :
26802 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
26803 factory(global.moment)
26804}(this, (function (moment) { 'use strict';
26805
26806 function each(array, callback) {
26807 var i;
26808 for (i = 0; i < array.length; i++) {
26809 callback(array[i], i, array);
26810 }
26811 }
26812
c58511b9
KM
26813 function setupDeprecationHandler(test, moment$$1, scope) {
26814 test._expectedDeprecations = null;
26815 test._observedDeprecations = null;
26816 test._oldSupress = moment$$1.suppressDeprecationWarnings;
26817 moment$$1.suppressDeprecationWarnings = true;
26818 test.expectedDeprecations = function () {
26819 test._expectedDeprecations = arguments;
26820 test._observedDeprecations = [];
26821 };
26822 moment$$1.deprecationHandler = function (name, msg) {
26823 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
26824 if (deprecationId === -1) {
26825 throw new Error('Unexpected deprecation thrown name=' +
26826 name + ' msg=' + msg);
26827 }
26828 test._observedDeprecations[deprecationId] = 1;
26829 };
26830 }
26831
26832 function teardownDeprecationHandler(test, moment$$1, scope) {
26833 moment$$1.suppressDeprecationWarnings = test._oldSupress;
26834
26835 if (test._expectedDeprecations != null) {
26836 var missedDeprecations = [];
26837 each(test._expectedDeprecations, function (deprecationPattern, id) {
26838 if (test._observedDeprecations[id] !== 1) {
26839 missedDeprecations.push(deprecationPattern);
26840 }
26841 });
26842 if (missedDeprecations.length !== 0) {
26843 throw new Error('Expected deprecation warnings did not happen: ' +
26844 missedDeprecations.join(' '));
26845 }
26846 }
26847 }
26848
26849 function matchedDeprecation(name, msg, deprecations) {
26850 if (deprecations == null) {
26851 return -1;
26852 }
26853 for (var i = 0; i < deprecations.length; ++i) {
26854 if (name != null && name === deprecations[i]) {
26855 return i;
26856 }
26857 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
26858 return i;
26859 }
26860 }
26861 return -1;
26862 }
26863
26864 /*global QUnit:false*/
26865
26866 var test = QUnit.test;
26867
db71a655
KM
26868 function objectKeys(obj) {
26869 if (Object.keys) {
26870 return Object.keys(obj);
26871 } else {
26872 // IE8
26873 var res = [], i;
26874 for (i in obj) {
26875 if (obj.hasOwnProperty(i)) {
26876 res.push(i);
26877 }
26878 }
26879 return res;
26880 }
26881 }
26882
26883 // Pick the first defined of two or three arguments.
26884
26885 function defineCommonLocaleTests(locale, options) {
26886 test('lenient day of month ordinal parsing', function (assert) {
26887 var i, ordinalStr, testMoment;
26888 for (i = 1; i <= 31; ++i) {
26889 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
26890 testMoment = moment(ordinalStr, 'YYYY MM Do');
26891 assert.equal(testMoment.year(), 2014,
26892 'lenient day of month ordinal parsing ' + i + ' year check');
26893 assert.equal(testMoment.month(), 0,
26894 'lenient day of month ordinal parsing ' + i + ' month check');
26895 assert.equal(testMoment.date(), i,
26896 'lenient day of month ordinal parsing ' + i + ' date check');
26897 }
26898 });
26899
26900 test('lenient day of month ordinal parsing of number', function (assert) {
26901 var i, testMoment;
26902 for (i = 1; i <= 31; ++i) {
26903 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
26904 assert.equal(testMoment.year(), 2014,
26905 'lenient day of month ordinal parsing of number ' + i + ' year check');
26906 assert.equal(testMoment.month(), 0,
26907 'lenient day of month ordinal parsing of number ' + i + ' month check');
26908 assert.equal(testMoment.date(), i,
26909 'lenient day of month ordinal parsing of number ' + i + ' date check');
26910 }
26911 });
26912
26913 test('strict day of month ordinal parsing', function (assert) {
26914 var i, ordinalStr, testMoment;
26915 for (i = 1; i <= 31; ++i) {
26916 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
26917 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
26918 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
26919 }
26920 });
26921
26922 test('meridiem invariant', function (assert) {
26923 var h, m, t1, t2;
26924 for (h = 0; h < 24; ++h) {
26925 for (m = 0; m < 60; m += 15) {
26926 t1 = moment.utc([2000, 0, 1, h, m]);
26927 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
26928 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
26929 'meridiem at ' + t1.format('HH:mm'));
26930 }
26931 }
26932 });
26933
26934 test('date format correctness', function (assert) {
26935 var data, tokens;
26936 data = moment.localeData()._longDateFormat;
26937 tokens = objectKeys(data);
26938 each(tokens, function (srchToken) {
26939 // Check each format string to make sure it does not contain any
26940 // tokens that need to be expanded.
26941 each(tokens, function (baseToken) {
26942 // strip escaped sequences
26943 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
26944 assert.equal(false, !!~format.indexOf(srchToken),
26945 'contains ' + srchToken + ' in ' + baseToken);
26946 });
26947 });
26948 });
26949
26950 test('month parsing correctness', function (assert) {
26951 var i, m;
26952
26953 if (locale === 'tr') {
26954 // I can't fix it :(
c58511b9 26955 assert.expect(0);
db71a655
KM
26956 return;
26957 }
26958 function tester(format) {
26959 var r;
26960 r = moment(m.format(format), format);
26961 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
26962 if (locale !== 'ka') {
26963 r = moment(m.format(format).toLocaleUpperCase(), format);
26964 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
26965 }
db71a655
KM
26966 r = moment(m.format(format).toLocaleLowerCase(), format);
26967 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
26968
26969 r = moment(m.format(format), format, true);
26970 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
26971 if (locale !== 'ka') {
26972 r = moment(m.format(format).toLocaleUpperCase(), format, true);
26973 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
26974 }
db71a655
KM
26975 r = moment(m.format(format).toLocaleLowerCase(), format, true);
26976 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
26977 }
26978
26979 for (i = 0; i < 12; ++i) {
26980 m = moment([2015, i, 15, 18]);
26981 tester('MMM');
26982 tester('MMM.');
26983 tester('MMMM');
26984 tester('MMMM.');
26985 }
26986 });
26987
26988 test('weekday parsing correctness', function (assert) {
26989 var i, m;
26990
96d0d679 26991 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
26992 // tr, az: There is a lower-case letter (ı), that converted to
26993 // upper then lower changes to i
26994 // ro: there is the letter ț which behaves weird under IE8
26995 // mt: letter Ħ
96d0d679 26996 // ga: month with spaces
c58511b9 26997 assert.expect(0);
db71a655
KM
26998 return;
26999 }
27000 function tester(format) {
27001 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
27002 r = moment(m.format(format), format);
27003 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
27004 if (locale !== 'ka') {
27005 r = moment(m.format(format).toLocaleUpperCase(), format);
27006 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
27007 }
db71a655
KM
27008 r = moment(m.format(format).toLocaleLowerCase(), format);
27009 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
27010 r = moment(m.format(format), format, true);
27011 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
27012 if (locale !== 'ka') {
27013 r = moment(m.format(format).toLocaleUpperCase(), format, true);
27014 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
27015 }
db71a655
KM
27016 r = moment(m.format(format).toLocaleLowerCase(), format, true);
27017 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
27018 }
27019
27020 for (i = 0; i < 7; ++i) {
27021 m = moment.utc([2015, 0, i + 1, 18]);
27022 tester('dd');
27023 tester('ddd');
27024 tester('dddd');
27025 }
27026 });
27027
27028 test('valid localeData', function (assert) {
27029 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
27030 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
27031 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
27032 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
27033 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
27034 });
96d0d679
KM
27035
27036 test('localeData weekdays can localeSort', function (assert) {
27037 var weekdays = moment().localeData().weekdays();
27038 var weekdaysShort = moment().localeData().weekdaysShort();
27039 var weekdaysMin = moment().localeData().weekdaysMin();
27040 var shift = moment().localeData()._week.dow;
27041 assert.deepEqual(
27042 moment().localeData().weekdays(true),
27043 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
27044 'weekdays should localeSort');
27045 assert.deepEqual(
27046 moment().localeData().weekdaysShort(true),
27047 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
27048 'weekdaysShort should localeSort');
27049 assert.deepEqual(
27050 moment().localeData().weekdaysMin(true),
27051 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
27052 'weekdaysMin should localeSort');
27053 });
db71a655
KM
27054 }
27055
db71a655
KM
27056 /*global QUnit:false*/
27057
db71a655
KM
27058 function localeModule (name, lifecycle) {
27059 QUnit.module('locale:' + name, {
c58511b9 27060 beforeEach : function () {
db71a655
KM
27061 moment.locale(name);
27062 moment.createFromInputFallback = function (config) {
27063 throw new Error('input not handled by moment: ' + config._i);
27064 };
27065 setupDeprecationHandler(test, moment, 'locale');
27066 if (lifecycle && lifecycle.setup) {
27067 lifecycle.setup();
27068 }
27069 },
c58511b9 27070 afterEach : function () {
db71a655
KM
27071 moment.locale('en');
27072 teardownDeprecationHandler(test, moment, 'locale');
27073 if (lifecycle && lifecycle.teardown) {
27074 lifecycle.teardown();
27075 }
27076 }
27077 });
27078 defineCommonLocaleTests(name, -1, -1);
27079 }
27080
96d0d679 27081 localeModule('hi');
db71a655
KM
27082
27083 test('parse', function (assert) {
96d0d679 27084 var tests = 'जनवरी जन._फ़रवरी फ़र._मार्च मार्च_अप्रैल अप्रै._मई मई_जून जून_जुलाई जुल._अगस्त अग._सितम्बर सित._अक्टूबर अक्टू._नवम्बर नव._दिसम्बर दिस.'.split('_'), i;
db71a655
KM
27085 function equalTest(input, mmm, i) {
27086 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
27087 }
27088 for (i = 0; i < 12; i++) {
27089 tests[i] = tests[i].split(' ');
27090 equalTest(tests[i][0], 'MMM', i);
27091 equalTest(tests[i][1], 'MMM', i);
27092 equalTest(tests[i][0], 'MMMM', i);
27093 equalTest(tests[i][1], 'MMMM', i);
27094 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
27095 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
27096 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
27097 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
27098 }
27099 });
27100
27101 test('format', function (assert) {
27102 var a = [
96d0d679
KM
27103 ['dddd, Do MMMM YYYY, a h:mm:ss बजे', 'रविवार, १४ फ़रवरी २०१०, दोपहर ३:२५:५० बजे'],
27104 ['ddd, a h बजे', 'रवि, दोपहर ३ बजे'],
27105 ['M Mo MM MMMM MMM', '२ २ ०२ फ़रवरी फ़र.'],
27106 ['YYYY YY', '२०१० १०'],
27107 ['D Do DD', '१४ १४ १४'],
27108 ['d do dddd ddd dd', '० ० रविवार रवि र'],
27109 ['DDD DDDo DDDD', '४५ ४५ ०४५'],
27110 ['w wo ww', '८ ८ ०८'],
27111 ['h hh', '३ ०३'],
27112 ['H HH', '१५ १५'],
27113 ['m mm', '२५ २५'],
27114 ['s ss', '५० ५०'],
27115 ['a A', 'दोपहर दोपहर'],
27116 ['LTS', 'दोपहर ३:२५:५० बजे'],
27117 ['L', '१४/०२/२०१०'],
27118 ['LL', '१४ फ़रवरी २०१०'],
27119 ['LLL', '१४ फ़रवरी २०१०, दोपहर ३:२५ बजे'],
27120 ['LLLL', 'रविवार, १४ फ़रवरी २०१०, दोपहर ३:२५ बजे'],
27121 ['l', '१४/२/२०१०'],
27122 ['ll', '१४ फ़र. २०१०'],
27123 ['lll', '१४ फ़र. २०१०, दोपहर ३:२५ बजे'],
27124 ['llll', 'रवि, १४ फ़र. २०१०, दोपहर ३:२५ बजे']
db71a655
KM
27125 ],
27126 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
27127 i;
27128 for (i = 0; i < a.length; i++) {
27129 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
27130 }
27131 });
27132
96d0d679
KM
27133 test('format ordinal', function (assert) {
27134 assert.equal(moment([2011, 0, 1]).format('DDDo'), '१', '१');
27135 assert.equal(moment([2011, 0, 2]).format('DDDo'), '२', '२');
27136 assert.equal(moment([2011, 0, 3]).format('DDDo'), '३', '३');
27137 assert.equal(moment([2011, 0, 4]).format('DDDo'), '४', '४');
27138 assert.equal(moment([2011, 0, 5]).format('DDDo'), '५', '५');
27139 assert.equal(moment([2011, 0, 6]).format('DDDo'), '६', '६');
27140 assert.equal(moment([2011, 0, 7]).format('DDDo'), '७', '७');
27141 assert.equal(moment([2011, 0, 8]).format('DDDo'), '८', '८');
27142 assert.equal(moment([2011, 0, 9]).format('DDDo'), '९', '९');
27143 assert.equal(moment([2011, 0, 10]).format('DDDo'), '१०', '१०');
27144
27145 assert.equal(moment([2011, 0, 11]).format('DDDo'), '११', '११');
27146 assert.equal(moment([2011, 0, 12]).format('DDDo'), '१२', '१२');
27147 assert.equal(moment([2011, 0, 13]).format('DDDo'), '१३', '१३');
27148 assert.equal(moment([2011, 0, 14]).format('DDDo'), '१४', '१४');
27149 assert.equal(moment([2011, 0, 15]).format('DDDo'), '१५', '१५');
27150 assert.equal(moment([2011, 0, 16]).format('DDDo'), '१६', '१६');
27151 assert.equal(moment([2011, 0, 17]).format('DDDo'), '१७', '१७');
27152 assert.equal(moment([2011, 0, 18]).format('DDDo'), '१८', '१८');
27153 assert.equal(moment([2011, 0, 19]).format('DDDo'), '१९', '१९');
27154 assert.equal(moment([2011, 0, 20]).format('DDDo'), '२०', '२०');
27155
27156 assert.equal(moment([2011, 0, 21]).format('DDDo'), '२१', '२१');
27157 assert.equal(moment([2011, 0, 22]).format('DDDo'), '२२', '२२');
27158 assert.equal(moment([2011, 0, 23]).format('DDDo'), '२३', '२३');
27159 assert.equal(moment([2011, 0, 24]).format('DDDo'), '२४', '२४');
27160 assert.equal(moment([2011, 0, 25]).format('DDDo'), '२५', '२५');
27161 assert.equal(moment([2011, 0, 26]).format('DDDo'), '२६', '२६');
27162 assert.equal(moment([2011, 0, 27]).format('DDDo'), '२७', '२७');
27163 assert.equal(moment([2011, 0, 28]).format('DDDo'), '२८', '२८');
27164 assert.equal(moment([2011, 0, 29]).format('DDDo'), '२९', '२९');
27165 assert.equal(moment([2011, 0, 30]).format('DDDo'), '३०', '३०');
27166
27167 assert.equal(moment([2011, 0, 31]).format('DDDo'), '३१', '३१');
27168 });
27169
db71a655 27170 test('format month', function (assert) {
96d0d679 27171 var expected = 'जनवरी जन._फ़रवरी फ़र._मार्च मार्च_अप्रैल अप्रै._मई मई_जून जून_जुलाई जुल._अगस्त अग._सितम्बर सित._अक्टूबर अक्टू._नवम्बर नव._दिसम्बर दिस.'.split('_'), i;
db71a655
KM
27172 for (i = 0; i < expected.length; i++) {
27173 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
27174 }
27175 });
27176
27177 test('format week', function (assert) {
96d0d679 27178 var expected = 'रविवार रवि र_सोमवार सोम सो_मंगलवार मंगल मं_बुधवार बुध बु_गुरूवार गुरू गु_शुक्रवार शुक्र शु_शनिवार शनि श'.split('_'), i;
db71a655
KM
27179 for (i = 0; i < expected.length; i++) {
27180 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
27181 }
27182 });
27183
27184 test('from', function (assert) {
27185 var start = moment([2007, 1, 28]);
96d0d679
KM
27186 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'कुछ ही क्षण', '44 seconds = a few seconds');
27187 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'एक मिनट', '45 seconds = a minute');
27188 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'एक मिनट', '89 seconds = a minute');
27189 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '२ मिनट', '90 seconds = 2 minutes');
27190 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '४४ मिनट', '44 minutes = 44 minutes');
27191 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'एक घंटा', '45 minutes = an hour');
27192 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'एक घंटा', '89 minutes = an hour');
27193 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '२ घंटे', '90 minutes = 2 hours');
27194 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '५ घंटे', '5 hours = 5 hours');
27195 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '२१ घंटे', '21 hours = 21 hours');
27196 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'एक दिन', '22 hours = a day');
27197 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'एक दिन', '35 hours = a day');
27198 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '२ दिन', '36 hours = 2 days');
27199 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'एक दिन', '1 day = a day');
27200 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '५ दिन', '5 days = 5 days');
27201 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '२५ दिन', '25 days = 25 days');
27202 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'एक महीने', '26 days = a month');
27203 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'एक महीने', '30 days = a month');
27204 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'एक महीने', '43 days = a month');
27205 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '२ महीने', '46 days = 2 months');
27206 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '२ महीने', '75 days = 2 months');
27207 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '३ महीने', '76 days = 3 months');
27208 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'एक महीने', '1 month = a month');
27209 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '५ महीने', '5 months = 5 months');
27210 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'एक वर्ष', '345 days = a year');
27211 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '२ वर्ष', '548 days = 2 years');
27212 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'एक वर्ष', '1 year = a year');
27213 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '५ वर्ष', '5 years = 5 years');
db71a655
KM
27214 });
27215
27216 test('suffix', function (assert) {
96d0d679
KM
27217 assert.equal(moment(30000).from(0), 'कुछ ही क्षण में', 'prefix');
27218 assert.equal(moment(0).from(30000), 'कुछ ही क्षण पहले', 'suffix');
db71a655
KM
27219 });
27220
27221 test('now from now', function (assert) {
96d0d679 27222 assert.equal(moment().fromNow(), 'कुछ ही क्षण पहले', 'now from now should display as in the past');
db71a655
KM
27223 });
27224
27225 test('fromNow', function (assert) {
96d0d679
KM
27226 assert.equal(moment().add({s: 30}).fromNow(), 'कुछ ही क्षण में', 'कुछ ही क्षण में');
27227 assert.equal(moment().add({d: 5}).fromNow(), '५ दिन में', '५ दिन में');
db71a655
KM
27228 });
27229
27230 test('calendar day', function (assert) {
27231 var a = moment().hours(12).minutes(0).seconds(0);
27232
96d0d679
KM
27233 assert.equal(moment(a).calendar(), 'आज दोपहर १२:०० बजे', 'today at the same time');
27234 assert.equal(moment(a).add({m: 25}).calendar(), 'आज दोपहर १२:२५ बजे', 'Now plus 25 min');
27235 assert.equal(moment(a).add({h: 3}).calendar(), 'आज दोपहर ३:०० बजे', 'Now plus 3 hours');
27236 assert.equal(moment(a).add({d: 1}).calendar(), 'कल दोपहर १२:०० बजे', 'tomorrow at the same time');
27237 assert.equal(moment(a).subtract({h: 1}).calendar(), 'आज दोपहर ११:०० बजे', 'Now minus 1 hour');
27238 assert.equal(moment(a).subtract({d: 1}).calendar(), 'कल दोपहर १२:०० बजे', 'yesterday at the same time');
db71a655
KM
27239 });
27240
27241 test('calendar next week', function (assert) {
27242 var i, m;
27243 for (i = 2; i < 7; i++) {
27244 m = moment().add({d: i});
96d0d679 27245 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days current time');
db71a655 27246 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 27247 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days beginning of day');
db71a655 27248 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 27249 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days end of day');
db71a655
KM
27250 }
27251 });
27252
27253 test('calendar last week', function (assert) {
27254 var i, m;
96d0d679 27255
db71a655
KM
27256 for (i = 2; i < 7; i++) {
27257 m = moment().subtract({d: i});
96d0d679 27258 assert.equal(m.calendar(), m.format('[पिछले] dddd[,] LT'), 'Today - ' + i + ' days current time');
db71a655 27259 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 27260 assert.equal(m.calendar(), m.format('[पिछले] dddd[,] LT'), 'Today - ' + i + ' days beginning of day');
db71a655 27261 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 27262 assert.equal(m.calendar(), m.format('[पिछले] dddd[,] LT'), 'Today - ' + i + ' days end of day');
db71a655
KM
27263 }
27264 });
27265
27266 test('calendar all else', function (assert) {
27267 var weeksAgo = moment().subtract({w: 1}),
27268 weeksFromNow = moment().add({w: 1});
27269
27270 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
27271 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
27272
27273 weeksAgo = moment().subtract({w: 2});
27274 weeksFromNow = moment().add({w: 2});
27275
27276 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
27277 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
27278 });
27279
96d0d679
KM
27280 test('meridiem', function (assert) {
27281 assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), 'रात', 'before dawn');
27282 assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), 'सुबह', 'morning');
27283 assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), 'दोपहर', 'during day');
27284 assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), 'शाम', 'evening');
27285 assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), 'शाम', 'late evening');
27286 assert.equal(moment([2011, 2, 23, 21, 20]).format('a'), 'रात', 'night');
27287
27288 assert.equal(moment([2011, 2, 23, 2, 30]).format('A'), 'रात', 'before dawn');
27289 assert.equal(moment([2011, 2, 23, 9, 30]).format('A'), 'सुबह', 'morning');
27290 assert.equal(moment([2011, 2, 23, 14, 30]).format('A'), 'दोपहर', ' during day');
27291 assert.equal(moment([2011, 2, 23, 17, 30]).format('A'), 'शाम', 'evening');
27292 assert.equal(moment([2011, 2, 23, 19, 30]).format('A'), 'शाम', 'late evening');
27293 assert.equal(moment([2011, 2, 23, 21, 20]).format('A'), 'रात', 'night');
27294 });
27295
27296 test('weeks year starting sunday formatted', function (assert) {
27297 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '१ ०१ १', 'Jan 1 2012 should be week 1');
27298 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '१ ०१ १', 'Jan 7 2012 should be week 1');
27299 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '२ ०२ २', 'Jan 8 2012 should be week 2');
27300 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '२ ०२ २', 'Jan 14 2012 should be week 2');
27301 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '३ ०३ ३', 'Jan 15 2012 should be week 3');
db71a655
KM
27302 });
27303
27304})));
27305
27306
27307;(function (global, factory) {
27308 typeof exports === 'object' && typeof module !== 'undefined'
27309 && typeof require === 'function' ? factory(require('../../moment')) :
27310 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
27311 factory(global.moment)
27312}(this, (function (moment) { 'use strict';
27313
27314 function each(array, callback) {
27315 var i;
27316 for (i = 0; i < array.length; i++) {
27317 callback(array[i], i, array);
27318 }
27319 }
27320
c58511b9
KM
27321 function setupDeprecationHandler(test, moment$$1, scope) {
27322 test._expectedDeprecations = null;
27323 test._observedDeprecations = null;
27324 test._oldSupress = moment$$1.suppressDeprecationWarnings;
27325 moment$$1.suppressDeprecationWarnings = true;
27326 test.expectedDeprecations = function () {
27327 test._expectedDeprecations = arguments;
27328 test._observedDeprecations = [];
27329 };
27330 moment$$1.deprecationHandler = function (name, msg) {
27331 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
27332 if (deprecationId === -1) {
27333 throw new Error('Unexpected deprecation thrown name=' +
27334 name + ' msg=' + msg);
27335 }
27336 test._observedDeprecations[deprecationId] = 1;
27337 };
27338 }
27339
27340 function teardownDeprecationHandler(test, moment$$1, scope) {
27341 moment$$1.suppressDeprecationWarnings = test._oldSupress;
27342
27343 if (test._expectedDeprecations != null) {
27344 var missedDeprecations = [];
27345 each(test._expectedDeprecations, function (deprecationPattern, id) {
27346 if (test._observedDeprecations[id] !== 1) {
27347 missedDeprecations.push(deprecationPattern);
27348 }
27349 });
27350 if (missedDeprecations.length !== 0) {
27351 throw new Error('Expected deprecation warnings did not happen: ' +
27352 missedDeprecations.join(' '));
27353 }
27354 }
27355 }
27356
27357 function matchedDeprecation(name, msg, deprecations) {
27358 if (deprecations == null) {
27359 return -1;
27360 }
27361 for (var i = 0; i < deprecations.length; ++i) {
27362 if (name != null && name === deprecations[i]) {
27363 return i;
27364 }
27365 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
27366 return i;
27367 }
27368 }
27369 return -1;
27370 }
27371
27372 /*global QUnit:false*/
27373
27374 var test = QUnit.test;
27375
db71a655
KM
27376 function objectKeys(obj) {
27377 if (Object.keys) {
27378 return Object.keys(obj);
27379 } else {
27380 // IE8
27381 var res = [], i;
27382 for (i in obj) {
27383 if (obj.hasOwnProperty(i)) {
27384 res.push(i);
27385 }
27386 }
27387 return res;
27388 }
27389 }
27390
27391 // Pick the first defined of two or three arguments.
27392
27393 function defineCommonLocaleTests(locale, options) {
27394 test('lenient day of month ordinal parsing', function (assert) {
27395 var i, ordinalStr, testMoment;
27396 for (i = 1; i <= 31; ++i) {
27397 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
27398 testMoment = moment(ordinalStr, 'YYYY MM Do');
27399 assert.equal(testMoment.year(), 2014,
27400 'lenient day of month ordinal parsing ' + i + ' year check');
27401 assert.equal(testMoment.month(), 0,
27402 'lenient day of month ordinal parsing ' + i + ' month check');
27403 assert.equal(testMoment.date(), i,
27404 'lenient day of month ordinal parsing ' + i + ' date check');
27405 }
27406 });
27407
27408 test('lenient day of month ordinal parsing of number', function (assert) {
27409 var i, testMoment;
27410 for (i = 1; i <= 31; ++i) {
27411 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
27412 assert.equal(testMoment.year(), 2014,
27413 'lenient day of month ordinal parsing of number ' + i + ' year check');
27414 assert.equal(testMoment.month(), 0,
27415 'lenient day of month ordinal parsing of number ' + i + ' month check');
27416 assert.equal(testMoment.date(), i,
27417 'lenient day of month ordinal parsing of number ' + i + ' date check');
27418 }
27419 });
27420
27421 test('strict day of month ordinal parsing', function (assert) {
27422 var i, ordinalStr, testMoment;
27423 for (i = 1; i <= 31; ++i) {
27424 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
27425 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
27426 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
27427 }
27428 });
27429
27430 test('meridiem invariant', function (assert) {
27431 var h, m, t1, t2;
27432 for (h = 0; h < 24; ++h) {
27433 for (m = 0; m < 60; m += 15) {
27434 t1 = moment.utc([2000, 0, 1, h, m]);
27435 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
27436 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
27437 'meridiem at ' + t1.format('HH:mm'));
27438 }
27439 }
27440 });
27441
27442 test('date format correctness', function (assert) {
27443 var data, tokens;
27444 data = moment.localeData()._longDateFormat;
27445 tokens = objectKeys(data);
27446 each(tokens, function (srchToken) {
27447 // Check each format string to make sure it does not contain any
27448 // tokens that need to be expanded.
27449 each(tokens, function (baseToken) {
27450 // strip escaped sequences
27451 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
27452 assert.equal(false, !!~format.indexOf(srchToken),
27453 'contains ' + srchToken + ' in ' + baseToken);
27454 });
27455 });
27456 });
27457
27458 test('month parsing correctness', function (assert) {
27459 var i, m;
27460
27461 if (locale === 'tr') {
27462 // I can't fix it :(
c58511b9 27463 assert.expect(0);
db71a655
KM
27464 return;
27465 }
27466 function tester(format) {
27467 var r;
27468 r = moment(m.format(format), format);
27469 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
27470 if (locale !== 'ka') {
27471 r = moment(m.format(format).toLocaleUpperCase(), format);
27472 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
27473 }
db71a655
KM
27474 r = moment(m.format(format).toLocaleLowerCase(), format);
27475 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
27476
27477 r = moment(m.format(format), format, true);
27478 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
27479 if (locale !== 'ka') {
27480 r = moment(m.format(format).toLocaleUpperCase(), format, true);
27481 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
27482 }
db71a655
KM
27483 r = moment(m.format(format).toLocaleLowerCase(), format, true);
27484 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
27485 }
27486
27487 for (i = 0; i < 12; ++i) {
27488 m = moment([2015, i, 15, 18]);
27489 tester('MMM');
27490 tester('MMM.');
27491 tester('MMMM');
27492 tester('MMMM.');
27493 }
27494 });
27495
27496 test('weekday parsing correctness', function (assert) {
27497 var i, m;
27498
96d0d679 27499 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
27500 // tr, az: There is a lower-case letter (ı), that converted to
27501 // upper then lower changes to i
27502 // ro: there is the letter ț which behaves weird under IE8
27503 // mt: letter Ħ
96d0d679 27504 // ga: month with spaces
c58511b9 27505 assert.expect(0);
db71a655
KM
27506 return;
27507 }
27508 function tester(format) {
27509 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
27510 r = moment(m.format(format), format);
27511 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
27512 if (locale !== 'ka') {
27513 r = moment(m.format(format).toLocaleUpperCase(), format);
27514 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
27515 }
db71a655
KM
27516 r = moment(m.format(format).toLocaleLowerCase(), format);
27517 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
27518 r = moment(m.format(format), format, true);
27519 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
27520 if (locale !== 'ka') {
27521 r = moment(m.format(format).toLocaleUpperCase(), format, true);
27522 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
27523 }
db71a655
KM
27524 r = moment(m.format(format).toLocaleLowerCase(), format, true);
27525 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
27526 }
27527
27528 for (i = 0; i < 7; ++i) {
27529 m = moment.utc([2015, 0, i + 1, 18]);
27530 tester('dd');
27531 tester('ddd');
27532 tester('dddd');
27533 }
27534 });
27535
27536 test('valid localeData', function (assert) {
27537 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
27538 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
27539 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
27540 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
27541 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
27542 });
96d0d679
KM
27543
27544 test('localeData weekdays can localeSort', function (assert) {
27545 var weekdays = moment().localeData().weekdays();
27546 var weekdaysShort = moment().localeData().weekdaysShort();
27547 var weekdaysMin = moment().localeData().weekdaysMin();
27548 var shift = moment().localeData()._week.dow;
27549 assert.deepEqual(
27550 moment().localeData().weekdays(true),
27551 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
27552 'weekdays should localeSort');
27553 assert.deepEqual(
27554 moment().localeData().weekdaysShort(true),
27555 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
27556 'weekdaysShort should localeSort');
27557 assert.deepEqual(
27558 moment().localeData().weekdaysMin(true),
27559 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
27560 'weekdaysMin should localeSort');
27561 });
db71a655
KM
27562 }
27563
db71a655
KM
27564 /*global QUnit:false*/
27565
db71a655
KM
27566 function localeModule (name, lifecycle) {
27567 QUnit.module('locale:' + name, {
c58511b9 27568 beforeEach : function () {
db71a655
KM
27569 moment.locale(name);
27570 moment.createFromInputFallback = function (config) {
27571 throw new Error('input not handled by moment: ' + config._i);
27572 };
27573 setupDeprecationHandler(test, moment, 'locale');
27574 if (lifecycle && lifecycle.setup) {
27575 lifecycle.setup();
27576 }
27577 },
c58511b9 27578 afterEach : function () {
db71a655
KM
27579 moment.locale('en');
27580 teardownDeprecationHandler(test, moment, 'locale');
27581 if (lifecycle && lifecycle.teardown) {
27582 lifecycle.teardown();
27583 }
27584 }
27585 });
27586 defineCommonLocaleTests(name, -1, -1);
27587 }
27588
96d0d679 27589 localeModule('hr');
db71a655
KM
27590
27591 test('parse', function (assert) {
96d0d679 27592 var tests = 'siječanj sij._veljača velj._ožujak ožu._travanj tra._svibanj svi._lipanj lip._srpanj srp._kolovoz kol._rujan ruj._listopad lis._studeni stu._prosinac pro.'.split('_'), i;
db71a655
KM
27593 function equalTest(input, mmm, i) {
27594 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
27595 }
27596 for (i = 0; i < 12; i++) {
27597 tests[i] = tests[i].split(' ');
27598 equalTest(tests[i][0], 'MMM', i);
27599 equalTest(tests[i][1], 'MMM', i);
27600 equalTest(tests[i][0], 'MMMM', i);
27601 equalTest(tests[i][1], 'MMMM', i);
27602 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
27603 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
27604 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
27605 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
27606 }
27607 });
27608
27609 test('format', function (assert) {
27610 var a = [
96d0d679
KM
27611 ['dddd, Do MMMM YYYY, h:mm:ss a', 'nedjelja, 14. veljače 2010, 3:25:50 pm'],
27612 ['ddd, hA', 'ned., 3PM'],
27613 ['M Mo MM MMMM MMM', '2 2. 02 veljača velj.'],
27614 ['YYYY YY', '2010 10'],
27615 ['D Do DD', '14 14. 14'],
27616 ['d do dddd ddd dd', '0 0. nedjelja ned. ne'],
27617 ['DDD DDDo DDDD', '45 45. 045'],
27618 ['w wo ww', '7 7. 07'],
27619 ['h hh', '3 03'],
27620 ['H HH', '15 15'],
27621 ['m mm', '25 25'],
27622 ['s ss', '50 50'],
27623 ['a A', 'pm PM'],
27624 ['[the] DDDo [day of the year]', 'the 45. day of the year'],
27625 ['LTS', '15:25:50'],
27626 ['L', '14.02.2010'],
27627 ['LL', '14. veljača 2010'],
27628 ['LLL', '14. veljača 2010 15:25'],
27629 ['LLLL', 'nedjelja, 14. veljača 2010 15:25'],
27630 ['l', '14.2.2010'],
27631 ['ll', '14. velj. 2010'],
27632 ['lll', '14. velj. 2010 15:25'],
27633 ['llll', 'ned., 14. velj. 2010 15:25']
db71a655
KM
27634 ],
27635 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
27636 i;
27637 for (i = 0; i < a.length; i++) {
27638 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
27639 }
27640 });
27641
27642 test('format ordinal', function (assert) {
96d0d679
KM
27643 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
27644 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
27645 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
27646 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
27647 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
27648 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
27649 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
27650 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
27651 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
27652 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
db71a655 27653
96d0d679
KM
27654 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
27655 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
27656 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
27657 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
27658 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
27659 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
27660 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
27661 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
27662 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
27663 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
db71a655 27664
96d0d679
KM
27665 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
27666 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
27667 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
27668 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
27669 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
27670 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
27671 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
27672 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
27673 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
27674 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
db71a655 27675
96d0d679 27676 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
db71a655
KM
27677 });
27678
27679 test('format month', function (assert) {
96d0d679 27680 var expected = 'siječanj sij._veljača velj._ožujak ožu._travanj tra._svibanj svi._lipanj lip._srpanj srp._kolovoz kol._rujan ruj._listopad lis._studeni stu._prosinac pro.'.split('_'), i;
db71a655
KM
27681 for (i = 0; i < expected.length; i++) {
27682 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
27683 }
27684 });
27685
27686 test('format week', function (assert) {
96d0d679 27687 var expected = 'nedjelja ned. ne_ponedjeljak pon. po_utorak uto. ut_srijeda sri. sr_četvrtak čet. če_petak pet. pe_subota sub. su'.split('_'), i;
db71a655
KM
27688 for (i = 0; i < expected.length; i++) {
27689 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
27690 }
27691 });
27692
27693 test('from', function (assert) {
27694 var start = moment([2007, 1, 28]);
96d0d679
KM
27695 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'par sekundi', '44 seconds = a few seconds');
27696 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'jedna minuta', '45 seconds = a minute');
27697 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'jedna minuta', '89 seconds = a minute');
27698 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minute', '90 seconds = 2 minutes');
27699 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuta', '44 minutes = 44 minutes');
27700 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'jedan sat', '45 minutes = an hour');
27701 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'jedan sat', '89 minutes = an hour');
27702 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 sata', '90 minutes = 2 hours');
27703 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 sati', '5 hours = 5 hours');
27704 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 sati', '21 hours = 21 hours');
27705 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'dan', '22 hours = a day');
27706 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'dan', '35 hours = a day');
27707 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dana', '36 hours = 2 days');
27708 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'dan', '1 day = a day');
27709 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dana', '5 days = 5 days');
27710 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dana', '25 days = 25 days');
27711 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mjesec', '26 days = a month');
27712 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mjesec', '30 days = a month');
27713 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mjesec', '43 days = a month');
27714 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mjeseca', '46 days = 2 months');
27715 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mjeseca', '75 days = 2 months');
27716 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mjeseca', '76 days = 3 months');
27717 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mjesec', '1 month = a month');
27718 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mjeseci', '5 months = 5 months');
27719 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'godinu', '345 days = a year');
27720 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 godine', '548 days = 2 years');
27721 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'godinu', '1 year = a year');
27722 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 godina', '5 years = 5 years');
db71a655
KM
27723 });
27724
27725 test('suffix', function (assert) {
96d0d679
KM
27726 assert.equal(moment(30000).from(0), 'za par sekundi', 'prefix');
27727 assert.equal(moment(0).from(30000), 'prije par sekundi', 'prefix');
db71a655
KM
27728 });
27729
27730 test('now from now', function (assert) {
96d0d679 27731 assert.equal(moment().fromNow(), 'prije par sekundi', 'now from now should display as in the past');
db71a655
KM
27732 });
27733
27734 test('fromNow', function (assert) {
96d0d679
KM
27735 assert.equal(moment().add({s: 30}).fromNow(), 'za par sekundi', 'in a few seconds');
27736 assert.equal(moment().add({d: 5}).fromNow(), 'za 5 dana', 'in 5 days');
db71a655
KM
27737 });
27738
27739 test('calendar day', function (assert) {
27740 var a = moment().hours(12).minutes(0).seconds(0);
27741
96d0d679
KM
27742 assert.equal(moment(a).calendar(), 'danas u 12:00', 'today at the same time');
27743 assert.equal(moment(a).add({m: 25}).calendar(), 'danas u 12:25', 'Now plus 25 min');
27744 assert.equal(moment(a).add({h: 1}).calendar(), 'danas u 13:00', 'Now plus 1 hour');
27745 assert.equal(moment(a).add({d: 1}).calendar(), 'sutra u 12:00', 'tomorrow at the same time');
27746 assert.equal(moment(a).subtract({h: 1}).calendar(), 'danas u 11:00', 'Now minus 1 hour');
27747 assert.equal(moment(a).subtract({d: 1}).calendar(), 'jučer u 12:00', 'yesterday at the same time');
db71a655
KM
27748 });
27749
27750 test('calendar next week', function (assert) {
27751 var i, m;
96d0d679
KM
27752
27753 function makeFormat(d) {
27754 switch (d.day()) {
27755 case 0:
27756 return '[u] [nedjelju] [u] LT';
27757 case 3:
27758 return '[u] [srijedu] [u] LT';
27759 case 6:
27760 return '[u] [subotu] [u] LT';
27761 case 1:
27762 case 2:
27763 case 4:
27764 case 5:
27765 return '[u] dddd [u] LT';
27766 }
27767 }
27768
db71a655
KM
27769 for (i = 2; i < 7; i++) {
27770 m = moment().add({d: i});
96d0d679 27771 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time');
db71a655 27772 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 27773 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day');
db71a655 27774 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 27775 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day');
db71a655
KM
27776 }
27777 });
27778
27779 test('calendar last week', function (assert) {
27780 var i, m;
27781
96d0d679
KM
27782 function makeFormat(d) {
27783 switch (d.day()) {
27784 case 0:
27785 case 3:
27786 return '[prošlu] dddd [u] LT';
27787 case 6:
27788 return '[prošle] [subote] [u] LT';
27789 case 1:
27790 case 2:
27791 case 4:
27792 case 5:
27793 return '[prošli] dddd [u] LT';
27794 }
27795 }
27796
db71a655
KM
27797 for (i = 2; i < 7; i++) {
27798 m = moment().subtract({d: i});
96d0d679 27799 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time');
db71a655 27800 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 27801 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day');
db71a655 27802 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 27803 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day');
db71a655
KM
27804 }
27805 });
27806
27807 test('calendar all else', function (assert) {
27808 var weeksAgo = moment().subtract({w: 1}),
27809 weeksFromNow = moment().add({w: 1});
27810
27811 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
27812 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
27813
27814 weeksAgo = moment().subtract({w: 2});
27815 weeksFromNow = moment().add({w: 2});
27816
27817 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
27818 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
27819 });
27820
db71a655 27821 test('weeks year starting sunday formatted', function (assert) {
96d0d679
KM
27822 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', 'Dec 26 2011 should be week 1');
27823 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1.', 'Jan 1 2012 should be week 1');
27824 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2.', 'Jan 2 2012 should be week 2');
27825 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2.', 'Jan 8 2012 should be week 2');
27826 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3.', 'Jan 9 2012 should be week 3');
db71a655
KM
27827 });
27828
27829})));
27830
27831
27832;(function (global, factory) {
27833 typeof exports === 'object' && typeof module !== 'undefined'
27834 && typeof require === 'function' ? factory(require('../../moment')) :
27835 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
27836 factory(global.moment)
27837}(this, (function (moment) { 'use strict';
27838
27839 function each(array, callback) {
27840 var i;
27841 for (i = 0; i < array.length; i++) {
27842 callback(array[i], i, array);
27843 }
27844 }
27845
c58511b9
KM
27846 function setupDeprecationHandler(test, moment$$1, scope) {
27847 test._expectedDeprecations = null;
27848 test._observedDeprecations = null;
27849 test._oldSupress = moment$$1.suppressDeprecationWarnings;
27850 moment$$1.suppressDeprecationWarnings = true;
27851 test.expectedDeprecations = function () {
27852 test._expectedDeprecations = arguments;
27853 test._observedDeprecations = [];
27854 };
27855 moment$$1.deprecationHandler = function (name, msg) {
27856 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
27857 if (deprecationId === -1) {
27858 throw new Error('Unexpected deprecation thrown name=' +
27859 name + ' msg=' + msg);
27860 }
27861 test._observedDeprecations[deprecationId] = 1;
27862 };
27863 }
27864
27865 function teardownDeprecationHandler(test, moment$$1, scope) {
27866 moment$$1.suppressDeprecationWarnings = test._oldSupress;
27867
27868 if (test._expectedDeprecations != null) {
27869 var missedDeprecations = [];
27870 each(test._expectedDeprecations, function (deprecationPattern, id) {
27871 if (test._observedDeprecations[id] !== 1) {
27872 missedDeprecations.push(deprecationPattern);
27873 }
27874 });
27875 if (missedDeprecations.length !== 0) {
27876 throw new Error('Expected deprecation warnings did not happen: ' +
27877 missedDeprecations.join(' '));
27878 }
27879 }
27880 }
27881
27882 function matchedDeprecation(name, msg, deprecations) {
27883 if (deprecations == null) {
27884 return -1;
27885 }
27886 for (var i = 0; i < deprecations.length; ++i) {
27887 if (name != null && name === deprecations[i]) {
27888 return i;
27889 }
27890 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
27891 return i;
27892 }
27893 }
27894 return -1;
27895 }
27896
27897 /*global QUnit:false*/
27898
27899 var test = QUnit.test;
27900
db71a655
KM
27901 function objectKeys(obj) {
27902 if (Object.keys) {
27903 return Object.keys(obj);
27904 } else {
27905 // IE8
27906 var res = [], i;
27907 for (i in obj) {
27908 if (obj.hasOwnProperty(i)) {
27909 res.push(i);
27910 }
27911 }
27912 return res;
27913 }
27914 }
27915
27916 // Pick the first defined of two or three arguments.
27917
27918 function defineCommonLocaleTests(locale, options) {
27919 test('lenient day of month ordinal parsing', function (assert) {
27920 var i, ordinalStr, testMoment;
27921 for (i = 1; i <= 31; ++i) {
27922 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
27923 testMoment = moment(ordinalStr, 'YYYY MM Do');
27924 assert.equal(testMoment.year(), 2014,
27925 'lenient day of month ordinal parsing ' + i + ' year check');
27926 assert.equal(testMoment.month(), 0,
27927 'lenient day of month ordinal parsing ' + i + ' month check');
27928 assert.equal(testMoment.date(), i,
27929 'lenient day of month ordinal parsing ' + i + ' date check');
27930 }
27931 });
27932
27933 test('lenient day of month ordinal parsing of number', function (assert) {
27934 var i, testMoment;
27935 for (i = 1; i <= 31; ++i) {
27936 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
27937 assert.equal(testMoment.year(), 2014,
27938 'lenient day of month ordinal parsing of number ' + i + ' year check');
27939 assert.equal(testMoment.month(), 0,
27940 'lenient day of month ordinal parsing of number ' + i + ' month check');
27941 assert.equal(testMoment.date(), i,
27942 'lenient day of month ordinal parsing of number ' + i + ' date check');
27943 }
27944 });
27945
27946 test('strict day of month ordinal parsing', function (assert) {
27947 var i, ordinalStr, testMoment;
27948 for (i = 1; i <= 31; ++i) {
27949 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
27950 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
27951 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
27952 }
27953 });
27954
27955 test('meridiem invariant', function (assert) {
27956 var h, m, t1, t2;
27957 for (h = 0; h < 24; ++h) {
27958 for (m = 0; m < 60; m += 15) {
27959 t1 = moment.utc([2000, 0, 1, h, m]);
27960 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
27961 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
27962 'meridiem at ' + t1.format('HH:mm'));
27963 }
27964 }
27965 });
27966
27967 test('date format correctness', function (assert) {
27968 var data, tokens;
27969 data = moment.localeData()._longDateFormat;
27970 tokens = objectKeys(data);
27971 each(tokens, function (srchToken) {
27972 // Check each format string to make sure it does not contain any
27973 // tokens that need to be expanded.
27974 each(tokens, function (baseToken) {
27975 // strip escaped sequences
27976 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
27977 assert.equal(false, !!~format.indexOf(srchToken),
27978 'contains ' + srchToken + ' in ' + baseToken);
27979 });
27980 });
27981 });
27982
27983 test('month parsing correctness', function (assert) {
27984 var i, m;
27985
27986 if (locale === 'tr') {
27987 // I can't fix it :(
c58511b9 27988 assert.expect(0);
db71a655
KM
27989 return;
27990 }
27991 function tester(format) {
27992 var r;
27993 r = moment(m.format(format), format);
27994 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
27995 if (locale !== 'ka') {
27996 r = moment(m.format(format).toLocaleUpperCase(), format);
27997 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
27998 }
db71a655
KM
27999 r = moment(m.format(format).toLocaleLowerCase(), format);
28000 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
28001
28002 r = moment(m.format(format), format, true);
28003 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
28004 if (locale !== 'ka') {
28005 r = moment(m.format(format).toLocaleUpperCase(), format, true);
28006 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
28007 }
db71a655
KM
28008 r = moment(m.format(format).toLocaleLowerCase(), format, true);
28009 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
28010 }
28011
28012 for (i = 0; i < 12; ++i) {
28013 m = moment([2015, i, 15, 18]);
28014 tester('MMM');
28015 tester('MMM.');
28016 tester('MMMM');
28017 tester('MMMM.');
28018 }
28019 });
28020
28021 test('weekday parsing correctness', function (assert) {
28022 var i, m;
28023
96d0d679 28024 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
28025 // tr, az: There is a lower-case letter (ı), that converted to
28026 // upper then lower changes to i
28027 // ro: there is the letter ț which behaves weird under IE8
28028 // mt: letter Ħ
96d0d679 28029 // ga: month with spaces
c58511b9 28030 assert.expect(0);
db71a655
KM
28031 return;
28032 }
28033 function tester(format) {
28034 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
28035 r = moment(m.format(format), format);
28036 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
28037 if (locale !== 'ka') {
28038 r = moment(m.format(format).toLocaleUpperCase(), format);
28039 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
28040 }
db71a655
KM
28041 r = moment(m.format(format).toLocaleLowerCase(), format);
28042 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
28043 r = moment(m.format(format), format, true);
28044 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
28045 if (locale !== 'ka') {
28046 r = moment(m.format(format).toLocaleUpperCase(), format, true);
28047 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
28048 }
db71a655
KM
28049 r = moment(m.format(format).toLocaleLowerCase(), format, true);
28050 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
28051 }
28052
28053 for (i = 0; i < 7; ++i) {
28054 m = moment.utc([2015, 0, i + 1, 18]);
28055 tester('dd');
28056 tester('ddd');
28057 tester('dddd');
28058 }
28059 });
28060
28061 test('valid localeData', function (assert) {
28062 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
28063 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
28064 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
28065 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
28066 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
28067 });
96d0d679
KM
28068
28069 test('localeData weekdays can localeSort', function (assert) {
28070 var weekdays = moment().localeData().weekdays();
28071 var weekdaysShort = moment().localeData().weekdaysShort();
28072 var weekdaysMin = moment().localeData().weekdaysMin();
28073 var shift = moment().localeData()._week.dow;
28074 assert.deepEqual(
28075 moment().localeData().weekdays(true),
28076 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
28077 'weekdays should localeSort');
28078 assert.deepEqual(
28079 moment().localeData().weekdaysShort(true),
28080 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
28081 'weekdaysShort should localeSort');
28082 assert.deepEqual(
28083 moment().localeData().weekdaysMin(true),
28084 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
28085 'weekdaysMin should localeSort');
28086 });
db71a655
KM
28087 }
28088
db71a655
KM
28089 /*global QUnit:false*/
28090
db71a655
KM
28091 function localeModule (name, lifecycle) {
28092 QUnit.module('locale:' + name, {
c58511b9 28093 beforeEach : function () {
db71a655
KM
28094 moment.locale(name);
28095 moment.createFromInputFallback = function (config) {
28096 throw new Error('input not handled by moment: ' + config._i);
28097 };
28098 setupDeprecationHandler(test, moment, 'locale');
28099 if (lifecycle && lifecycle.setup) {
28100 lifecycle.setup();
28101 }
28102 },
c58511b9 28103 afterEach : function () {
db71a655
KM
28104 moment.locale('en');
28105 teardownDeprecationHandler(test, moment, 'locale');
28106 if (lifecycle && lifecycle.teardown) {
28107 lifecycle.teardown();
28108 }
28109 }
28110 });
28111 defineCommonLocaleTests(name, -1, -1);
28112 }
28113
96d0d679 28114 localeModule('hu');
db71a655
KM
28115
28116 test('parse', function (assert) {
96d0d679
KM
28117 var tests = 'január jan_február feb_március márc_április ápr_május máj_június jún_július júl_augusztus aug_szeptember szept_október okt_november nov_december dec'.split('_'),
28118 i;
db71a655
KM
28119 function equalTest(input, mmm, i) {
28120 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
28121 }
28122 for (i = 0; i < 12; i++) {
28123 tests[i] = tests[i].split(' ');
28124 equalTest(tests[i][0], 'MMM', i);
28125 equalTest(tests[i][1], 'MMM', i);
28126 equalTest(tests[i][0], 'MMMM', i);
28127 equalTest(tests[i][1], 'MMMM', i);
28128 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
28129 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
28130 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
28131 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
28132 }
28133 });
28134
28135 test('format', function (assert) {
28136 var a = [
96d0d679
KM
28137 ['dddd, MMMM Do YYYY, HH:mm:ss', 'vasárnap, február 14. 2010, 15:25:50'],
28138 ['ddd, HH', 'vas, 15'],
28139 ['M Mo MM MMMM MMM', '2 2. 02 február feb'],
db71a655
KM
28140 ['YYYY YY', '2010 10'],
28141 ['D Do DD', '14 14. 14'],
96d0d679 28142 ['d do dddd ddd dd', '0 0. vasárnap vas v'],
db71a655 28143 ['DDD DDDo DDDD', '45 45. 045'],
96d0d679 28144 ['w wo ww', '6 6. 06'],
db71a655
KM
28145 ['H HH', '15 15'],
28146 ['m mm', '25 25'],
28147 ['s ss', '50 50'],
96d0d679 28148 ['[az év] DDDo [napja]', 'az év 45. napja'],
db71a655 28149 ['LTS', '15:25:50'],
96d0d679
KM
28150 ['L', '2010.02.14.'],
28151 ['LL', '2010. február 14.'],
28152 ['LLL', '2010. február 14. 15:25'],
28153 ['LLLL', '2010. február 14., vasárnap 15:25'],
28154 ['l', '2010.2.14.'],
28155 ['ll', '2010. feb 14.'],
28156 ['lll', '2010. feb 14. 15:25'],
28157 ['llll', '2010. feb 14., vas 15:25']
db71a655
KM
28158 ],
28159 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
28160 i;
28161 for (i = 0; i < a.length; i++) {
28162 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
28163 }
28164 });
28165
96d0d679
KM
28166 test('meridiem', function (assert) {
28167 assert.equal(moment([2011, 2, 23, 0, 0]).format('a'), 'de', 'am');
28168 assert.equal(moment([2011, 2, 23, 11, 59]).format('a'), 'de', 'am');
28169 assert.equal(moment([2011, 2, 23, 12, 0]).format('a'), 'du', 'pm');
28170 assert.equal(moment([2011, 2, 23, 23, 59]).format('a'), 'du', 'pm');
28171
28172 assert.equal(moment([2011, 2, 23, 0, 0]).format('A'), 'DE', 'AM');
28173 assert.equal(moment([2011, 2, 23, 11, 59]).format('A'), 'DE', 'AM');
28174 assert.equal(moment([2011, 2, 23, 12, 0]).format('A'), 'DU', 'PM');
28175 assert.equal(moment([2011, 2, 23, 23, 59]).format('A'), 'DU', 'PM');
28176 });
28177
db71a655
KM
28178 test('format ordinal', function (assert) {
28179 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
28180 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
28181 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
28182 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
28183 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
28184 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
28185 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
28186 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
28187 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
28188 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
28189
28190 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
28191 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
28192 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
28193 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
28194 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
28195 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
28196 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
28197 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
28198 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
28199 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
28200
28201 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
28202 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
28203 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
28204 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
28205 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
28206 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
28207 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
28208 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
28209 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
28210 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
28211
28212 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
28213 });
28214
28215 test('format month', function (assert) {
96d0d679
KM
28216 var expected = 'január jan_február feb_március márc_április ápr_május máj_június jún_július júl_augusztus aug_szeptember szept_október okt_november nov_december dec'.split('_'),
28217 i;
db71a655
KM
28218 for (i = 0; i < expected.length; i++) {
28219 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
28220 }
28221 });
28222
28223 test('format week', function (assert) {
96d0d679
KM
28224 var expected = 'vasárnap vas_hétfő hét_kedd kedd_szerda sze_csütörtök csüt_péntek pén_szombat szo'.split('_'),
28225 i;
db71a655 28226 for (i = 0; i < expected.length; i++) {
96d0d679 28227 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd'), expected[i], expected[i]);
db71a655
KM
28228 }
28229 });
28230
28231 test('from', function (assert) {
28232 var start = moment([2007, 1, 28]);
96d0d679
KM
28233 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'néhány másodperc', '44 másodperc = néhány másodperc');
28234 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'egy perc', '45 másodperc = egy perc');
28235 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'egy perc', '89 másodperc = egy perc');
28236 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 perc', '90 másodperc = 2 perc');
28237 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 perc', '44 perc = 44 perc');
28238 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'egy óra', '45 perc = egy óra');
28239 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'egy óra', '89 perc = egy óra');
28240 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 óra', '90 perc = 2 óra');
28241 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 óra', '5 óra = 5 óra');
28242 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 óra', '21 óra = 21 óra');
28243 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'egy nap', '22 óra = egy nap');
28244 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'egy nap', '35 óra = egy nap');
28245 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 nap', '36 óra = 2 nap');
28246 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'egy nap', '1 nap = egy nap');
28247 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 nap', '5 nap = 5 nap');
28248 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 nap', '25 nap = 25 nap');
28249 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'egy hónap', '26 nap = egy hónap');
28250 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'egy hónap', '30 nap = egy hónap');
28251 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'egy hónap', '45 nap = egy hónap');
28252 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 hónap', '46 nap = 2 hónap');
28253 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 hónap', '75 nap = 2 hónap');
28254 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 hónap', '76 nap = 3 hónap');
28255 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'egy hónap', '1 hónap = egy hónap');
28256 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 hónap', '5 hónap = 5 hónap');
28257 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'egy év', '345 nap = egy év');
28258 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 év', '548 nap = 2 év');
28259 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'egy év', '1 év = egy év');
28260 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 év', '5 év = 5 év');
db71a655
KM
28261 });
28262
28263 test('suffix', function (assert) {
96d0d679
KM
28264 assert.equal(moment(30000).from(0), 'néhány másodperc múlva', 'prefix');
28265 assert.equal(moment(0).from(30000), 'néhány másodperce', 'suffix');
db71a655
KM
28266 });
28267
28268 test('now from now', function (assert) {
96d0d679 28269 assert.equal(moment().fromNow(), 'néhány másodperce', 'now from now should display as in the past');
db71a655
KM
28270 });
28271
28272 test('fromNow', function (assert) {
96d0d679
KM
28273 assert.equal(moment().add({s: 30}).fromNow(), 'néhány másodperc múlva', 'néhány másodperc múlva');
28274 assert.equal(moment().add({d: 5}).fromNow(), '5 nap múlva', '5 nap múlva');
db71a655
KM
28275 });
28276
28277 test('calendar day', function (assert) {
28278 var a = moment().hours(12).minutes(0).seconds(0);
28279
96d0d679
KM
28280 assert.equal(moment(a).calendar(), 'ma 12:00-kor', 'today at the same time');
28281 assert.equal(moment(a).add({m: 25}).calendar(), 'ma 12:25-kor', 'Now plus 25 min');
28282 assert.equal(moment(a).add({h: 1}).calendar(), 'ma 13:00-kor', 'Now plus 1 hour');
28283 assert.equal(moment(a).add({d: 1}).calendar(), 'holnap 12:00-kor', 'tomorrow at the same time');
28284 assert.equal(moment(a).subtract({h: 1}).calendar(), 'ma 11:00-kor', 'Now minus 1 hour');
28285 assert.equal(moment(a).subtract({d: 1}).calendar(), 'tegnap 12:00-kor', 'yesterday at the same time');
db71a655
KM
28286 });
28287
28288 test('calendar next week', function (assert) {
96d0d679 28289 var i, m, days = 'vasárnap_hétfőn_kedden_szerdán_csütörtökön_pénteken_szombaton'.split('_');
db71a655
KM
28290 for (i = 2; i < 7; i++) {
28291 m = moment().add({d: i});
96d0d679 28292 assert.equal(m.calendar(), m.format('[' + days[m.day()] + '] LT[-kor]'), 'today + ' + i + ' days current time');
db71a655 28293 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 28294 assert.equal(m.calendar(), m.format('[' + days[m.day()] + '] LT[-kor]'), 'today + ' + i + ' days beginning of day');
db71a655 28295 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 28296 assert.equal(m.calendar(), m.format('[' + days[m.day()] + '] LT[-kor]'), 'today + ' + i + ' days end of day');
db71a655
KM
28297 }
28298 });
28299
28300 test('calendar last week', function (assert) {
96d0d679 28301 var i, m, days = 'vasárnap_hétfőn_kedden_szerdán_csütörtökön_pénteken_szombaton'.split('_');
db71a655
KM
28302
28303 for (i = 2; i < 7; i++) {
28304 m = moment().subtract({d: i});
96d0d679 28305 assert.equal(m.calendar(), m.format('[múlt ' + days[m.day()] + '] LT[-kor]'), 'today - ' + i + ' days current time');
db71a655 28306 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 28307 assert.equal(m.calendar(), m.format('[múlt ' + days[m.day()] + '] LT[-kor]'), 'today - ' + i + ' days beginning of day');
db71a655 28308 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 28309 assert.equal(m.calendar(), m.format('[múlt ' + days[m.day()] + '] LT[-kor]'), 'today - ' + i + ' days end of day');
db71a655
KM
28310 }
28311 });
28312
28313 test('calendar all else', function (assert) {
28314 var weeksAgo = moment().subtract({w: 1}),
28315 weeksFromNow = moment().add({w: 1});
28316
96d0d679
KM
28317 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), 'egy héte');
28318 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'egy hét múlva');
db71a655
KM
28319
28320 weeksAgo = moment().subtract({w: 2});
28321 weeksFromNow = moment().add({w: 2});
28322
96d0d679
KM
28323 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 hete');
28324 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), '2 hét múlva');
db71a655
KM
28325 });
28326
28327 test('weeks year starting sunday formatted', function (assert) {
96d0d679
KM
28328 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '52 52 52.', 'Dec 26 2011 should be week 52');
28329 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
28330 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
28331 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
28332 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
db71a655
KM
28333 });
28334
28335})));
28336
28337
28338;(function (global, factory) {
28339 typeof exports === 'object' && typeof module !== 'undefined'
28340 && typeof require === 'function' ? factory(require('../../moment')) :
28341 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
28342 factory(global.moment)
28343}(this, (function (moment) { 'use strict';
28344
28345 function each(array, callback) {
28346 var i;
28347 for (i = 0; i < array.length; i++) {
28348 callback(array[i], i, array);
28349 }
28350 }
28351
c58511b9
KM
28352 function setupDeprecationHandler(test, moment$$1, scope) {
28353 test._expectedDeprecations = null;
28354 test._observedDeprecations = null;
28355 test._oldSupress = moment$$1.suppressDeprecationWarnings;
28356 moment$$1.suppressDeprecationWarnings = true;
28357 test.expectedDeprecations = function () {
28358 test._expectedDeprecations = arguments;
28359 test._observedDeprecations = [];
28360 };
28361 moment$$1.deprecationHandler = function (name, msg) {
28362 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
28363 if (deprecationId === -1) {
28364 throw new Error('Unexpected deprecation thrown name=' +
28365 name + ' msg=' + msg);
28366 }
28367 test._observedDeprecations[deprecationId] = 1;
28368 };
28369 }
28370
28371 function teardownDeprecationHandler(test, moment$$1, scope) {
28372 moment$$1.suppressDeprecationWarnings = test._oldSupress;
28373
28374 if (test._expectedDeprecations != null) {
28375 var missedDeprecations = [];
28376 each(test._expectedDeprecations, function (deprecationPattern, id) {
28377 if (test._observedDeprecations[id] !== 1) {
28378 missedDeprecations.push(deprecationPattern);
28379 }
28380 });
28381 if (missedDeprecations.length !== 0) {
28382 throw new Error('Expected deprecation warnings did not happen: ' +
28383 missedDeprecations.join(' '));
28384 }
28385 }
28386 }
28387
28388 function matchedDeprecation(name, msg, deprecations) {
28389 if (deprecations == null) {
28390 return -1;
28391 }
28392 for (var i = 0; i < deprecations.length; ++i) {
28393 if (name != null && name === deprecations[i]) {
28394 return i;
28395 }
28396 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
28397 return i;
28398 }
28399 }
28400 return -1;
28401 }
28402
28403 /*global QUnit:false*/
28404
28405 var test = QUnit.test;
28406
db71a655
KM
28407 function objectKeys(obj) {
28408 if (Object.keys) {
28409 return Object.keys(obj);
28410 } else {
28411 // IE8
28412 var res = [], i;
28413 for (i in obj) {
28414 if (obj.hasOwnProperty(i)) {
28415 res.push(i);
28416 }
28417 }
28418 return res;
28419 }
28420 }
28421
28422 // Pick the first defined of two or three arguments.
28423
28424 function defineCommonLocaleTests(locale, options) {
28425 test('lenient day of month ordinal parsing', function (assert) {
28426 var i, ordinalStr, testMoment;
28427 for (i = 1; i <= 31; ++i) {
28428 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
28429 testMoment = moment(ordinalStr, 'YYYY MM Do');
28430 assert.equal(testMoment.year(), 2014,
28431 'lenient day of month ordinal parsing ' + i + ' year check');
28432 assert.equal(testMoment.month(), 0,
28433 'lenient day of month ordinal parsing ' + i + ' month check');
28434 assert.equal(testMoment.date(), i,
28435 'lenient day of month ordinal parsing ' + i + ' date check');
28436 }
28437 });
28438
28439 test('lenient day of month ordinal parsing of number', function (assert) {
28440 var i, testMoment;
28441 for (i = 1; i <= 31; ++i) {
28442 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
28443 assert.equal(testMoment.year(), 2014,
28444 'lenient day of month ordinal parsing of number ' + i + ' year check');
28445 assert.equal(testMoment.month(), 0,
28446 'lenient day of month ordinal parsing of number ' + i + ' month check');
28447 assert.equal(testMoment.date(), i,
28448 'lenient day of month ordinal parsing of number ' + i + ' date check');
28449 }
28450 });
28451
28452 test('strict day of month ordinal parsing', function (assert) {
28453 var i, ordinalStr, testMoment;
28454 for (i = 1; i <= 31; ++i) {
28455 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
28456 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
28457 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
28458 }
28459 });
28460
28461 test('meridiem invariant', function (assert) {
28462 var h, m, t1, t2;
28463 for (h = 0; h < 24; ++h) {
28464 for (m = 0; m < 60; m += 15) {
28465 t1 = moment.utc([2000, 0, 1, h, m]);
28466 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
28467 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
28468 'meridiem at ' + t1.format('HH:mm'));
28469 }
28470 }
28471 });
28472
28473 test('date format correctness', function (assert) {
28474 var data, tokens;
28475 data = moment.localeData()._longDateFormat;
28476 tokens = objectKeys(data);
28477 each(tokens, function (srchToken) {
28478 // Check each format string to make sure it does not contain any
28479 // tokens that need to be expanded.
28480 each(tokens, function (baseToken) {
28481 // strip escaped sequences
28482 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
28483 assert.equal(false, !!~format.indexOf(srchToken),
28484 'contains ' + srchToken + ' in ' + baseToken);
28485 });
28486 });
28487 });
28488
28489 test('month parsing correctness', function (assert) {
28490 var i, m;
28491
28492 if (locale === 'tr') {
28493 // I can't fix it :(
c58511b9 28494 assert.expect(0);
db71a655
KM
28495 return;
28496 }
28497 function tester(format) {
28498 var r;
28499 r = moment(m.format(format), format);
28500 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
28501 if (locale !== 'ka') {
28502 r = moment(m.format(format).toLocaleUpperCase(), format);
28503 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
28504 }
db71a655
KM
28505 r = moment(m.format(format).toLocaleLowerCase(), format);
28506 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
28507
28508 r = moment(m.format(format), format, true);
28509 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
28510 if (locale !== 'ka') {
28511 r = moment(m.format(format).toLocaleUpperCase(), format, true);
28512 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
28513 }
db71a655
KM
28514 r = moment(m.format(format).toLocaleLowerCase(), format, true);
28515 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
28516 }
28517
28518 for (i = 0; i < 12; ++i) {
28519 m = moment([2015, i, 15, 18]);
28520 tester('MMM');
28521 tester('MMM.');
28522 tester('MMMM');
28523 tester('MMMM.');
28524 }
28525 });
28526
28527 test('weekday parsing correctness', function (assert) {
28528 var i, m;
28529
96d0d679 28530 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
28531 // tr, az: There is a lower-case letter (ı), that converted to
28532 // upper then lower changes to i
28533 // ro: there is the letter ț which behaves weird under IE8
28534 // mt: letter Ħ
96d0d679 28535 // ga: month with spaces
c58511b9 28536 assert.expect(0);
db71a655
KM
28537 return;
28538 }
28539 function tester(format) {
28540 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
28541 r = moment(m.format(format), format);
28542 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
28543 if (locale !== 'ka') {
28544 r = moment(m.format(format).toLocaleUpperCase(), format);
28545 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
28546 }
db71a655
KM
28547 r = moment(m.format(format).toLocaleLowerCase(), format);
28548 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
28549 r = moment(m.format(format), format, true);
28550 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
28551 if (locale !== 'ka') {
28552 r = moment(m.format(format).toLocaleUpperCase(), format, true);
28553 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
28554 }
db71a655
KM
28555 r = moment(m.format(format).toLocaleLowerCase(), format, true);
28556 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
28557 }
28558
28559 for (i = 0; i < 7; ++i) {
28560 m = moment.utc([2015, 0, i + 1, 18]);
28561 tester('dd');
28562 tester('ddd');
28563 tester('dddd');
28564 }
28565 });
28566
28567 test('valid localeData', function (assert) {
28568 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
28569 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
28570 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
28571 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
28572 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
28573 });
96d0d679
KM
28574
28575 test('localeData weekdays can localeSort', function (assert) {
28576 var weekdays = moment().localeData().weekdays();
28577 var weekdaysShort = moment().localeData().weekdaysShort();
28578 var weekdaysMin = moment().localeData().weekdaysMin();
28579 var shift = moment().localeData()._week.dow;
28580 assert.deepEqual(
28581 moment().localeData().weekdays(true),
28582 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
28583 'weekdays should localeSort');
28584 assert.deepEqual(
28585 moment().localeData().weekdaysShort(true),
28586 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
28587 'weekdaysShort should localeSort');
28588 assert.deepEqual(
28589 moment().localeData().weekdaysMin(true),
28590 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
28591 'weekdaysMin should localeSort');
28592 });
db71a655
KM
28593 }
28594
db71a655
KM
28595 /*global QUnit:false*/
28596
db71a655
KM
28597 function localeModule (name, lifecycle) {
28598 QUnit.module('locale:' + name, {
c58511b9 28599 beforeEach : function () {
db71a655
KM
28600 moment.locale(name);
28601 moment.createFromInputFallback = function (config) {
28602 throw new Error('input not handled by moment: ' + config._i);
28603 };
28604 setupDeprecationHandler(test, moment, 'locale');
28605 if (lifecycle && lifecycle.setup) {
28606 lifecycle.setup();
28607 }
28608 },
c58511b9 28609 afterEach : function () {
db71a655
KM
28610 moment.locale('en');
28611 teardownDeprecationHandler(test, moment, 'locale');
28612 if (lifecycle && lifecycle.teardown) {
28613 lifecycle.teardown();
28614 }
28615 }
28616 });
28617 defineCommonLocaleTests(name, -1, -1);
28618 }
28619
96d0d679 28620 localeModule('hy-am');
db71a655
KM
28621
28622 test('parse', function (assert) {
96d0d679 28623 var tests = 'հունվար հնվ_փետրվար փտր_մարտ մրտ_ապրիլ ապր_մայիս մյս_հունիս հնս_հուլիս հլս_օգոստոս օգս_սեպտեմբեր սպտ_հոկտեմբեր հկտ_նոյեմբեր նմբ_դեկտեմբեր դկտ'.split('_'), i;
db71a655
KM
28624 function equalTest(input, mmm, i) {
28625 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
28626 }
28627 for (i = 0; i < 12; i++) {
28628 tests[i] = tests[i].split(' ');
28629 equalTest(tests[i][0], 'MMM', i);
28630 equalTest(tests[i][1], 'MMM', i);
28631 equalTest(tests[i][0], 'MMMM', i);
28632 equalTest(tests[i][1], 'MMMM', i);
28633 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
28634 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
28635 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
28636 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
28637 }
28638 });
28639
96d0d679
KM
28640 test('parse exceptional case', function (assert) {
28641 assert.equal(moment('11 մայիսի 1989', ['DD MMMM YYYY']).format('DD-MM-YYYY'), '11-05-1989');
28642 });
28643
db71a655
KM
28644 test('format', function (assert) {
28645 var a = [
96d0d679
KM
28646 ['dddd, Do MMMM YYYY, HH:mm:ss', 'կիրակի, 14 փետրվարի 2010, 15:25:50'],
28647 ['ddd, h A', 'կրկ, 3 ցերեկվա'],
28648 ['M Mo MM MMMM MMM', '2 2 02 փետրվար փտր'],
db71a655 28649 ['YYYY YY', '2010 10'],
96d0d679
KM
28650 ['D Do DD', '14 14 14'],
28651 ['d do dddd ddd dd', '0 0 կիրակի կրկ կրկ'],
28652 ['DDD DDDo DDDD', '45 45-րդ 045'],
28653 ['w wo ww', '7 7-րդ 07'],
28654 ['h hh', '3 03'],
db71a655
KM
28655 ['H HH', '15 15'],
28656 ['m mm', '25 25'],
28657 ['s ss', '50 50'],
96d0d679
KM
28658 ['a A', 'ցերեկվա ցերեկվա'],
28659 ['[տարվա] DDDo [օրը]', 'տարվա 45-րդ օրը'],
db71a655 28660 ['LTS', '15:25:50'],
96d0d679
KM
28661 ['L', '14.02.2010'],
28662 ['LL', '14 փետրվարի 2010 թ.'],
28663 ['LLL', '14 փետրվարի 2010 թ., 15:25'],
28664 ['LLLL', 'կիրակի, 14 փետրվարի 2010 թ., 15:25'],
28665 ['l', '14.2.2010'],
28666 ['ll', '14 փտր 2010 թ.'],
28667 ['lll', '14 փտր 2010 թ., 15:25'],
28668 ['llll', 'կրկ, 14 փտր 2010 թ., 15:25']
db71a655
KM
28669 ],
28670 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
28671 i;
28672 for (i = 0; i < a.length; i++) {
28673 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
28674 }
28675 });
28676
96d0d679
KM
28677 test('format meridiem', function (assert) {
28678 assert.equal(moment([2012, 11, 28, 0, 0]).format('A'), 'գիշերվա', 'night');
28679 assert.equal(moment([2012, 11, 28, 3, 59]).format('A'), 'գիշերվա', 'night');
28680 assert.equal(moment([2012, 11, 28, 4, 0]).format('A'), 'առավոտվա', 'morning');
28681 assert.equal(moment([2012, 11, 28, 11, 59]).format('A'), 'առավոտվա', 'morning');
28682 assert.equal(moment([2012, 11, 28, 12, 0]).format('A'), 'ցերեկվա', 'afternoon');
28683 assert.equal(moment([2012, 11, 28, 16, 59]).format('A'), 'ցերեկվա', 'afternoon');
28684 assert.equal(moment([2012, 11, 28, 17, 0]).format('A'), 'երեկոյան', 'evening');
28685 assert.equal(moment([2012, 11, 28, 23, 59]).format('A'), 'երեկոյան', 'evening');
db71a655
KM
28686 });
28687
28688 test('format ordinal', function (assert) {
96d0d679
KM
28689 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-ին', '1-ին');
28690 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-րդ', '2-րդ');
28691 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-րդ', '3-րդ');
28692 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-րդ', '4-րդ');
28693 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-րդ', '5-րդ');
28694 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-րդ', '6-րդ');
28695 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-րդ', '7-րդ');
28696 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-րդ', '8-րդ');
28697 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-րդ', '9-րդ');
28698 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-րդ', '10-րդ');
db71a655 28699
96d0d679
KM
28700 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-րդ', '11-րդ');
28701 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-րդ', '12-րդ');
28702 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-րդ', '13-րդ');
28703 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-րդ', '14-րդ');
28704 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-րդ', '15-րդ');
28705 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-րդ', '16-րդ');
28706 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-րդ', '17-րդ');
28707 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-րդ', '18-րդ');
28708 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-րդ', '19-րդ');
28709 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-րդ', '20-րդ');
db71a655 28710
96d0d679
KM
28711 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-րդ', '21-րդ');
28712 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-րդ', '22-րդ');
28713 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-րդ', '23-րդ');
28714 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-րդ', '24-րդ');
28715 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-րդ', '25-րդ');
28716 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-րդ', '26-րդ');
28717 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-րդ', '27-րդ');
28718 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-րդ', '28-րդ');
28719 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-րդ', '29-րդ');
28720 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-րդ', '30-րդ');
db71a655 28721
96d0d679 28722 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-րդ', '31-րդ');
db71a655
KM
28723 });
28724
28725 test('format month', function (assert) {
96d0d679 28726 var expected = 'հունվար հնվ_փետրվար փտր_մարտ մրտ_ապրիլ ապր_մայիս մյս_հունիս հնս_հուլիս հլս_օգոստոս օգս_սեպտեմբեր սպտ_հոկտեմբեր հկտ_նոյեմբեր նմբ_դեկտեմբեր դկտ'.split('_'), i;
db71a655
KM
28727 for (i = 0; i < expected.length; i++) {
28728 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
28729 }
28730 });
28731
96d0d679
KM
28732 test('format month case', function (assert) {
28733 var months = {
28734 'nominative': 'հունվար_փետրվար_մարտ_ապրիլ_մայիս_հունիս_հուլիս_օգոստոս_սեպտեմբեր_հոկտեմբեր_նոյեմբեր_դեկտեմբեր'.split('_'),
28735 'accusative': 'հունվարի_փետրվարի_մարտի_ապրիլի_մայիսի_հունիսի_հուլիսի_օգոստոսի_սեպտեմբերի_հոկտեմբերի_նոյեմբերի_դեկտեմբերի'.split('_')
28736 }, i;
28737 for (i = 0; i < 12; i++) {
28738 assert.equal(moment([2011, i, 1]).format('D MMMM'), '1 ' + months.accusative[i], '1 ' + months.accusative[i]);
28739 assert.equal(moment([2011, i, 1]).format('MMMM'), months.nominative[i], '1 ' + months.nominative[i]);
28740 }
28741 });
28742
28743 test('format month short case', function (assert) {
28744 var monthsShort = {
28745 'nominative': 'հնվ_փտր_մրտ_ապր_մյս_հնս_հլս_օգս_սպտ_հկտ_նմբ_դկտ'.split('_'),
28746 'accusative': 'հնվ_փտր_մրտ_ապր_մյս_հնս_հլս_օգս_սպտ_հկտ_նմբ_դկտ'.split('_')
28747 }, i;
28748 for (i = 0; i < 12; i++) {
28749 assert.equal(moment([2011, i, 1]).format('D MMM'), '1 ' + monthsShort.accusative[i], '1 ' + monthsShort.accusative[i]);
28750 assert.equal(moment([2011, i, 1]).format('MMM'), monthsShort.nominative[i], '1 ' + monthsShort.nominative[i]);
28751 }
28752 });
28753
28754 test('format month case with escaped symbols', function (assert) {
28755 var months = {
28756 'nominative': 'հունվար_փետրվար_մարտ_ապրիլ_մայիս_հունիս_հուլիս_օգոստոս_սեպտեմբեր_հոկտեմբեր_նոյեմբեր_դեկտեմբեր'.split('_'),
28757 'accusative': 'հունվարի_փետրվարի_մարտի_ապրիլի_մայիսի_հունիսի_հուլիսի_օգոստոսի_սեպտեմբերի_հոկտեմբերի_նոյեմբերի_դեկտեմբերի'.split('_')
28758 }, i;
28759 for (i = 0; i < 12; i++) {
28760 assert.equal(moment([2013, i, 1]).format('D[] MMMM'), '1 ' + months.accusative[i], '1 ' + months.accusative[i]);
28761 assert.equal(moment([2013, i, 1]).format('[<i>]D[</i>] [<b>]MMMM[</b>]'), '<i>1</i> <b>' + months.accusative[i] + '</b>', '1 <b>' + months.accusative[i] + '</b>');
28762 assert.equal(moment([2013, i, 1]).format('D[-ին օրը] MMMM'), '1-ին օրը ' + months.accusative[i], '1-ին օրը ' + months.accusative[i]);
28763 assert.equal(moment([2013, i, 1]).format('D, MMMM'), '1, ' + months.nominative[i], '1, ' + months.nominative[i]);
28764 }
28765 });
28766
28767 test('format month short case with escaped symbols', function (assert) {
28768 var monthsShort = {
28769 'nominative': 'հնվ_փտր_մրտ_ապր_մյս_հնս_հլս_օգս_սպտ_հկտ_նմբ_դկտ'.split('_'),
28770 'accusative': 'հնվ_փտր_մրտ_ապր_մյս_հնս_հլս_օգս_սպտ_հկտ_նմբ_դկտ'.split('_')
28771 }, i;
28772 for (i = 0; i < 12; i++) {
28773 assert.equal(moment([2013, i, 1]).format('D[] MMM'), '1 ' + monthsShort.accusative[i], '1 ' + monthsShort.accusative[i]);
28774 assert.equal(moment([2013, i, 1]).format('[<i>]D[</i>] [<b>]MMM[</b>]'), '<i>1</i> <b>' + monthsShort.accusative[i] + '</b>', '1 <b>' + monthsShort.accusative[i] + '</b>');
28775 assert.equal(moment([2013, i, 1]).format('D[-ին օրը] MMM'), '1-ին օրը ' + monthsShort.accusative[i], '1-ին օրը ' + monthsShort.accusative[i]);
28776 assert.equal(moment([2013, i, 1]).format('D, MMM'), '1, ' + monthsShort.nominative[i], '1, ' + monthsShort.nominative[i]);
28777 }
28778 });
28779
db71a655 28780 test('format week', function (assert) {
96d0d679 28781 var expected = 'կիրակի կրկ կրկ_երկուշաբթի երկ երկ_երեքշաբթի երք երք_չորեքշաբթի չրք չրք_հինգշաբթի հնգ հնգ_ուրբաթ ուրբ ուրբ_շաբաթ շբթ շբթ'.split('_'), i;
db71a655 28782 for (i = 0; i < expected.length; i++) {
96d0d679 28783 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
db71a655
KM
28784 }
28785 });
28786
28787 test('from', function (assert) {
28788 var start = moment([2007, 1, 28]);
96d0d679
KM
28789 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'մի քանի վայրկյան', '44 seconds = seconds');
28790 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'րոպե', '45 seconds = a minute');
28791 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'րոպե', '89 seconds = a minute');
28792 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 րոպե', '90 seconds = 2 minutes');
28793 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 րոպե', '44 minutes = 44 minutes');
28794 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ժամ', '45 minutes = an hour');
28795 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ժամ', '89 minutes = an hour');
28796 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ժամ', '90 minutes = 2 hours');
28797 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ժամ', '5 hours = 5 hours');
28798 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ժամ', '21 hours = 21 hours');
28799 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'օր', '22 hours = a day');
28800 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'օր', '35 hours = a day');
28801 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 օր', '36 hours = 2 days');
28802 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'օր', '1 day = a day');
28803 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 օր', '5 days = 5 days');
28804 assert.equal(start.from(moment([2007, 1, 28]).add({d: 11}), true), '11 օր', '11 days = 11 days');
28805 assert.equal(start.from(moment([2007, 1, 28]).add({d: 21}), true), '21 օր', '21 days = 21 days');
28806 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 օր', '25 days = 25 days');
28807 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ամիս', '26 days = a month');
28808 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ամիս', '30 days = a month');
28809 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ամիս', '43 days = a month');
28810 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 ամիս', '46 days = 2 months');
28811 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 ամիս', '75 days = 2 months');
28812 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 ամիս', '76 days = 3 months');
28813 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ամիս', '1 month = a month');
28814 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 ամիս', '5 months = 5 months');
28815 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'տարի', '345 days = a year');
28816 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 տարի', '548 days = 2 years');
28817 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'տարի', '1 year = a year');
28818 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 տարի', '5 years = 5 years');
db71a655
KM
28819 });
28820
28821 test('suffix', function (assert) {
96d0d679
KM
28822 assert.equal(moment(30000).from(0), 'մի քանի վայրկյան հետո', 'prefix');
28823 assert.equal(moment(0).from(30000), 'մի քանի վայրկյան առաջ', 'suffix');
db71a655
KM
28824 });
28825
28826 test('fromNow', function (assert) {
96d0d679
KM
28827 assert.equal(moment().add({s: 30}).fromNow(), 'մի քանի վայրկյան հետո', 'in seconds');
28828 assert.equal(moment().add({d: 5}).fromNow(), '5 օր հետո', 'in 5 days');
db71a655
KM
28829 });
28830
28831 test('calendar day', function (assert) {
28832 var a = moment().hours(12).minutes(0).seconds(0);
28833
96d0d679
KM
28834 assert.equal(moment(a).calendar(), 'այսօր 12:00', 'today at the same time');
28835 assert.equal(moment(a).add({m: 25}).calendar(), 'այսօր 12:25', 'Now plus 25 min');
28836 assert.equal(moment(a).add({h: 1}).calendar(), 'այսօր 13:00', 'Now plus 1 hour');
28837 assert.equal(moment(a).add({d: 1}).calendar(), 'վաղը 12:00', 'tomorrow at the same time');
28838 assert.equal(moment(a).subtract({h: 1}).calendar(), 'այսօր 11:00', 'Now minus 1 hour');
28839 assert.equal(moment(a).subtract({d: 1}).calendar(), 'երեկ 12:00', 'yesterday at the same time');
db71a655
KM
28840 });
28841
28842 test('calendar next week', function (assert) {
96d0d679
KM
28843 var i, m;
28844 function makeFormat(d) {
28845 return 'dddd [օրը ժամը] LT';
28846 }
28847
db71a655
KM
28848 for (i = 2; i < 7; i++) {
28849 m = moment().add({d: i});
96d0d679 28850 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time');
db71a655 28851 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 28852 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day');
db71a655 28853 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 28854 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day');
db71a655
KM
28855 }
28856 });
28857
28858 test('calendar last week', function (assert) {
96d0d679
KM
28859 var i, m;
28860
28861 function makeFormat(d) {
28862 return '[անցած] dddd [օրը ժամը] LT';
28863 }
db71a655
KM
28864
28865 for (i = 2; i < 7; i++) {
28866 m = moment().subtract({d: i});
96d0d679 28867 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time');
db71a655 28868 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 28869 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day');
db71a655 28870 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 28871 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day');
db71a655
KM
28872 }
28873 });
28874
28875 test('calendar all else', function (assert) {
28876 var weeksAgo = moment().subtract({w: 1}),
28877 weeksFromNow = moment().add({w: 1});
28878
96d0d679
KM
28879 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
28880 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
db71a655
KM
28881
28882 weeksAgo = moment().subtract({w: 2});
28883 weeksFromNow = moment().add({w: 2});
28884
96d0d679
KM
28885 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
28886 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
db71a655
KM
28887 });
28888
28889 test('weeks year starting sunday formatted', function (assert) {
96d0d679
KM
28890 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-ին', 'Dec 26 2011 should be week 1');
28891 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-ին', 'Jan 1 2012 should be week 1');
28892 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-րդ', 'Jan 2 2012 should be week 2');
28893 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-րդ', 'Jan 8 2012 should be week 2');
28894 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-րդ', 'Jan 9 2012 should be week 3');
db71a655
KM
28895 });
28896
28897})));
28898
28899
28900;(function (global, factory) {
28901 typeof exports === 'object' && typeof module !== 'undefined'
28902 && typeof require === 'function' ? factory(require('../../moment')) :
28903 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
28904 factory(global.moment)
28905}(this, (function (moment) { 'use strict';
28906
28907 function each(array, callback) {
28908 var i;
28909 for (i = 0; i < array.length; i++) {
28910 callback(array[i], i, array);
28911 }
28912 }
28913
c58511b9
KM
28914 function setupDeprecationHandler(test, moment$$1, scope) {
28915 test._expectedDeprecations = null;
28916 test._observedDeprecations = null;
28917 test._oldSupress = moment$$1.suppressDeprecationWarnings;
28918 moment$$1.suppressDeprecationWarnings = true;
28919 test.expectedDeprecations = function () {
28920 test._expectedDeprecations = arguments;
28921 test._observedDeprecations = [];
28922 };
28923 moment$$1.deprecationHandler = function (name, msg) {
28924 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
28925 if (deprecationId === -1) {
28926 throw new Error('Unexpected deprecation thrown name=' +
28927 name + ' msg=' + msg);
28928 }
28929 test._observedDeprecations[deprecationId] = 1;
28930 };
28931 }
28932
28933 function teardownDeprecationHandler(test, moment$$1, scope) {
28934 moment$$1.suppressDeprecationWarnings = test._oldSupress;
28935
28936 if (test._expectedDeprecations != null) {
28937 var missedDeprecations = [];
28938 each(test._expectedDeprecations, function (deprecationPattern, id) {
28939 if (test._observedDeprecations[id] !== 1) {
28940 missedDeprecations.push(deprecationPattern);
28941 }
28942 });
28943 if (missedDeprecations.length !== 0) {
28944 throw new Error('Expected deprecation warnings did not happen: ' +
28945 missedDeprecations.join(' '));
28946 }
28947 }
28948 }
28949
28950 function matchedDeprecation(name, msg, deprecations) {
28951 if (deprecations == null) {
28952 return -1;
28953 }
28954 for (var i = 0; i < deprecations.length; ++i) {
28955 if (name != null && name === deprecations[i]) {
28956 return i;
28957 }
28958 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
28959 return i;
28960 }
28961 }
28962 return -1;
28963 }
28964
28965 /*global QUnit:false*/
28966
28967 var test = QUnit.test;
28968
db71a655
KM
28969 function objectKeys(obj) {
28970 if (Object.keys) {
28971 return Object.keys(obj);
28972 } else {
28973 // IE8
28974 var res = [], i;
28975 for (i in obj) {
28976 if (obj.hasOwnProperty(i)) {
28977 res.push(i);
28978 }
28979 }
28980 return res;
28981 }
28982 }
28983
28984 // Pick the first defined of two or three arguments.
28985
28986 function defineCommonLocaleTests(locale, options) {
28987 test('lenient day of month ordinal parsing', function (assert) {
28988 var i, ordinalStr, testMoment;
28989 for (i = 1; i <= 31; ++i) {
28990 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
28991 testMoment = moment(ordinalStr, 'YYYY MM Do');
28992 assert.equal(testMoment.year(), 2014,
28993 'lenient day of month ordinal parsing ' + i + ' year check');
28994 assert.equal(testMoment.month(), 0,
28995 'lenient day of month ordinal parsing ' + i + ' month check');
28996 assert.equal(testMoment.date(), i,
28997 'lenient day of month ordinal parsing ' + i + ' date check');
28998 }
28999 });
29000
29001 test('lenient day of month ordinal parsing of number', function (assert) {
29002 var i, testMoment;
29003 for (i = 1; i <= 31; ++i) {
29004 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
29005 assert.equal(testMoment.year(), 2014,
29006 'lenient day of month ordinal parsing of number ' + i + ' year check');
29007 assert.equal(testMoment.month(), 0,
29008 'lenient day of month ordinal parsing of number ' + i + ' month check');
29009 assert.equal(testMoment.date(), i,
29010 'lenient day of month ordinal parsing of number ' + i + ' date check');
29011 }
29012 });
29013
29014 test('strict day of month ordinal parsing', function (assert) {
29015 var i, ordinalStr, testMoment;
29016 for (i = 1; i <= 31; ++i) {
29017 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
29018 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
29019 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
29020 }
29021 });
29022
29023 test('meridiem invariant', function (assert) {
29024 var h, m, t1, t2;
29025 for (h = 0; h < 24; ++h) {
29026 for (m = 0; m < 60; m += 15) {
29027 t1 = moment.utc([2000, 0, 1, h, m]);
29028 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
29029 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
29030 'meridiem at ' + t1.format('HH:mm'));
29031 }
29032 }
29033 });
29034
29035 test('date format correctness', function (assert) {
29036 var data, tokens;
29037 data = moment.localeData()._longDateFormat;
29038 tokens = objectKeys(data);
29039 each(tokens, function (srchToken) {
29040 // Check each format string to make sure it does not contain any
29041 // tokens that need to be expanded.
29042 each(tokens, function (baseToken) {
29043 // strip escaped sequences
29044 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
29045 assert.equal(false, !!~format.indexOf(srchToken),
29046 'contains ' + srchToken + ' in ' + baseToken);
29047 });
29048 });
29049 });
29050
29051 test('month parsing correctness', function (assert) {
29052 var i, m;
29053
29054 if (locale === 'tr') {
29055 // I can't fix it :(
c58511b9 29056 assert.expect(0);
db71a655
KM
29057 return;
29058 }
29059 function tester(format) {
29060 var r;
29061 r = moment(m.format(format), format);
29062 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
29063 if (locale !== 'ka') {
29064 r = moment(m.format(format).toLocaleUpperCase(), format);
29065 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
29066 }
db71a655
KM
29067 r = moment(m.format(format).toLocaleLowerCase(), format);
29068 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
29069
29070 r = moment(m.format(format), format, true);
29071 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
29072 if (locale !== 'ka') {
29073 r = moment(m.format(format).toLocaleUpperCase(), format, true);
29074 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
29075 }
db71a655
KM
29076 r = moment(m.format(format).toLocaleLowerCase(), format, true);
29077 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
29078 }
29079
29080 for (i = 0; i < 12; ++i) {
29081 m = moment([2015, i, 15, 18]);
29082 tester('MMM');
29083 tester('MMM.');
29084 tester('MMMM');
29085 tester('MMMM.');
29086 }
29087 });
29088
29089 test('weekday parsing correctness', function (assert) {
29090 var i, m;
29091
96d0d679 29092 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
29093 // tr, az: There is a lower-case letter (ı), that converted to
29094 // upper then lower changes to i
29095 // ro: there is the letter ț which behaves weird under IE8
29096 // mt: letter Ħ
96d0d679 29097 // ga: month with spaces
c58511b9 29098 assert.expect(0);
db71a655
KM
29099 return;
29100 }
29101 function tester(format) {
29102 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
29103 r = moment(m.format(format), format);
29104 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
29105 if (locale !== 'ka') {
29106 r = moment(m.format(format).toLocaleUpperCase(), format);
29107 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
29108 }
db71a655
KM
29109 r = moment(m.format(format).toLocaleLowerCase(), format);
29110 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
29111 r = moment(m.format(format), format, true);
29112 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
29113 if (locale !== 'ka') {
29114 r = moment(m.format(format).toLocaleUpperCase(), format, true);
29115 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
29116 }
db71a655
KM
29117 r = moment(m.format(format).toLocaleLowerCase(), format, true);
29118 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
29119 }
29120
29121 for (i = 0; i < 7; ++i) {
29122 m = moment.utc([2015, 0, i + 1, 18]);
29123 tester('dd');
29124 tester('ddd');
29125 tester('dddd');
29126 }
29127 });
29128
29129 test('valid localeData', function (assert) {
29130 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
29131 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
29132 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
29133 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
29134 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
29135 });
96d0d679
KM
29136
29137 test('localeData weekdays can localeSort', function (assert) {
29138 var weekdays = moment().localeData().weekdays();
29139 var weekdaysShort = moment().localeData().weekdaysShort();
29140 var weekdaysMin = moment().localeData().weekdaysMin();
29141 var shift = moment().localeData()._week.dow;
29142 assert.deepEqual(
29143 moment().localeData().weekdays(true),
29144 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
29145 'weekdays should localeSort');
29146 assert.deepEqual(
29147 moment().localeData().weekdaysShort(true),
29148 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
29149 'weekdaysShort should localeSort');
29150 assert.deepEqual(
29151 moment().localeData().weekdaysMin(true),
29152 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
29153 'weekdaysMin should localeSort');
29154 });
db71a655
KM
29155 }
29156
db71a655
KM
29157 /*global QUnit:false*/
29158
db71a655
KM
29159 function localeModule (name, lifecycle) {
29160 QUnit.module('locale:' + name, {
c58511b9 29161 beforeEach : function () {
db71a655
KM
29162 moment.locale(name);
29163 moment.createFromInputFallback = function (config) {
29164 throw new Error('input not handled by moment: ' + config._i);
29165 };
29166 setupDeprecationHandler(test, moment, 'locale');
29167 if (lifecycle && lifecycle.setup) {
29168 lifecycle.setup();
29169 }
29170 },
c58511b9 29171 afterEach : function () {
db71a655
KM
29172 moment.locale('en');
29173 teardownDeprecationHandler(test, moment, 'locale');
29174 if (lifecycle && lifecycle.teardown) {
29175 lifecycle.teardown();
29176 }
29177 }
29178 });
29179 defineCommonLocaleTests(name, -1, -1);
29180 }
29181
96d0d679 29182 localeModule('id');
db71a655
KM
29183
29184 test('parse', function (assert) {
96d0d679 29185 var tests = 'Januari Jan_Februari Feb_Maret Mar_April Apr_Mei Mei_Juni Jun_Juli Jul_Agustus Agt_September Sep_Oktober Okt_November Nov_Desember Des'.split('_'), i;
db71a655
KM
29186 function equalTest(input, mmm, i) {
29187 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
29188 }
29189 for (i = 0; i < 12; i++) {
29190 tests[i] = tests[i].split(' ');
29191 equalTest(tests[i][0], 'MMM', i);
29192 equalTest(tests[i][1], 'MMM', i);
29193 equalTest(tests[i][0], 'MMMM', i);
29194 equalTest(tests[i][1], 'MMMM', i);
29195 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
29196 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
29197 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
29198 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
29199 }
29200 });
29201
db71a655
KM
29202 test('format', function (assert) {
29203 var a = [
96d0d679
KM
29204 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Minggu, Februari 14 2010, 3:25:50 sore'],
29205 ['ddd, hA', 'Min, 3sore'],
29206 ['M Mo MM MMMM MMM', '2 2 02 Februari Feb'],
db71a655
KM
29207 ['YYYY YY', '2010 10'],
29208 ['D Do DD', '14 14 14'],
96d0d679
KM
29209 ['d do dddd ddd dd', '0 0 Minggu Min Mg'],
29210 ['DDD DDDo DDDD', '45 45 045'],
29211 ['w wo ww', '7 7 07'],
db71a655
KM
29212 ['h hh', '3 03'],
29213 ['H HH', '15 15'],
29214 ['m mm', '25 25'],
29215 ['s ss', '50 50'],
96d0d679
KM
29216 ['a A', 'sore sore'],
29217 ['[the] DDDo [day of the year]', 'the 45 day of the year'],
29218 ['LTS', '15.25.50'],
29219 ['L', '14/02/2010'],
29220 ['LL', '14 Februari 2010'],
29221 ['LLL', '14 Februari 2010 pukul 15.25'],
29222 ['LLLL', 'Minggu, 14 Februari 2010 pukul 15.25'],
29223 ['l', '14/2/2010'],
29224 ['ll', '14 Feb 2010'],
29225 ['lll', '14 Feb 2010 pukul 15.25'],
29226 ['llll', 'Min, 14 Feb 2010 pukul 15.25']
db71a655
KM
29227 ],
29228 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
29229 i;
29230 for (i = 0; i < a.length; i++) {
29231 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
29232 }
29233 });
29234
db71a655 29235 test('format month', function (assert) {
96d0d679 29236 var expected = 'Januari Jan_Februari Feb_Maret Mar_April Apr_Mei Mei_Juni Jun_Juli Jul_Agustus Agt_September Sep_Oktober Okt_November Nov_Desember Des'.split('_'), i;
db71a655
KM
29237 for (i = 0; i < expected.length; i++) {
29238 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
29239 }
29240 });
29241
db71a655 29242 test('format week', function (assert) {
96d0d679 29243 var expected = 'Minggu Min Mg_Senin Sen Sn_Selasa Sel Sl_Rabu Rab Rb_Kamis Kam Km_Jumat Jum Jm_Sabtu Sab Sb'.split('_'), i;
db71a655
KM
29244 for (i = 0; i < expected.length; i++) {
29245 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
29246 }
29247 });
29248
29249 test('from', function (assert) {
29250 var start = moment([2007, 1, 28]);
96d0d679
KM
29251 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'beberapa detik', '44 seconds = a few seconds');
29252 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'semenit', '45 seconds = a minute');
29253 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'semenit', '89 seconds = a minute');
29254 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 menit', '90 seconds = 2 minutes');
29255 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 menit', '44 minutes = 44 minutes');
29256 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'sejam', '45 minutes = an hour');
29257 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'sejam', '89 minutes = an hour');
29258 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 jam', '90 minutes = 2 hours');
29259 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 jam', '5 hours = 5 hours');
29260 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 jam', '21 hours = 21 hours');
29261 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'sehari', '22 hours = a day');
29262 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'sehari', '35 hours = a day');
29263 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 hari', '36 hours = 2 days');
29264 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'sehari', '1 day = a day');
29265 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 hari', '5 days = 5 days');
29266 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 hari', '25 days = 25 days');
29267 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'sebulan', '26 days = a month');
29268 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'sebulan', '30 days = a month');
29269 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'sebulan', '43 days = a month');
29270 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 bulan', '46 days = 2 months');
29271 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 bulan', '75 days = 2 months');
29272 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 bulan', '76 days = 3 months');
29273 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'sebulan', '1 month = a month');
29274 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 bulan', '5 months = 5 months');
29275 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'setahun', '345 days = a year');
29276 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 tahun', '548 days = 2 years');
29277 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'setahun', '1 year = a year');
29278 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 tahun', '5 years = 5 years');
db71a655
KM
29279 });
29280
29281 test('suffix', function (assert) {
96d0d679
KM
29282 assert.equal(moment(30000).from(0), 'dalam beberapa detik', 'prefix');
29283 assert.equal(moment(0).from(30000), 'beberapa detik yang lalu', 'suffix');
29284 });
29285
29286 test('now from now', function (assert) {
29287 assert.equal(moment().fromNow(), 'beberapa detik yang lalu', 'now from now should display as in the past');
db71a655
KM
29288 });
29289
29290 test('fromNow', function (assert) {
96d0d679
KM
29291 assert.equal(moment().add({s: 30}).fromNow(), 'dalam beberapa detik', 'in a few seconds');
29292 assert.equal(moment().add({d: 5}).fromNow(), 'dalam 5 hari', 'in 5 days');
db71a655
KM
29293 });
29294
29295 test('calendar day', function (assert) {
29296 var a = moment().hours(12).minutes(0).seconds(0);
29297
96d0d679
KM
29298 assert.equal(moment(a).calendar(), 'Hari ini pukul 12.00', 'today at the same time');
29299 assert.equal(moment(a).add({m: 25}).calendar(), 'Hari ini pukul 12.25', 'Now plus 25 min');
29300 assert.equal(moment(a).add({h: 1}).calendar(), 'Hari ini pukul 13.00', 'Now plus 1 hour');
29301 assert.equal(moment(a).add({d: 1}).calendar(), 'Besok pukul 12.00', 'tomorrow at the same time');
29302 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Hari ini pukul 11.00', 'Now minus 1 hour');
29303 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Kemarin pukul 12.00', 'yesterday at the same time');
db71a655
KM
29304 });
29305
29306 test('calendar next week', function (assert) {
29307 var i, m;
db71a655
KM
29308 for (i = 2; i < 7; i++) {
29309 m = moment().add({d: i});
96d0d679 29310 assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Today + ' + i + ' days current time');
db71a655 29311 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 29312 assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Today + ' + i + ' days beginning of day');
db71a655 29313 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 29314 assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Today + ' + i + ' days end of day');
db71a655
KM
29315 }
29316 });
29317
29318 test('calendar last week', function (assert) {
29319 var i, m;
db71a655
KM
29320 for (i = 2; i < 7; i++) {
29321 m = moment().subtract({d: i});
96d0d679 29322 assert.equal(m.calendar(), m.format('dddd [lalu pukul] LT'), 'Today - ' + i + ' days current time');
db71a655 29323 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 29324 assert.equal(m.calendar(), m.format('dddd [lalu pukul] LT'), 'Today - ' + i + ' days beginning of day');
db71a655 29325 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 29326 assert.equal(m.calendar(), m.format('dddd [lalu pukul] LT'), 'Today - ' + i + ' days end of day');
db71a655
KM
29327 }
29328 });
29329
29330 test('calendar all else', function (assert) {
29331 var weeksAgo = moment().subtract({w: 1}),
29332 weeksFromNow = moment().add({w: 1});
29333
29334 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
29335 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
29336
29337 weeksAgo = moment().subtract({w: 2});
29338 weeksFromNow = moment().add({w: 2});
29339
29340 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
29341 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
29342 });
29343
29344 test('weeks year starting sunday formatted', function (assert) {
96d0d679
KM
29345 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1', 'Dec 26 2011 should be week 1');
29346 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1');
29347 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2', 'Jan 2 2012 should be week 2');
29348 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2');
29349 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3', 'Jan 9 2012 should be week 3');
db71a655
KM
29350 });
29351
29352})));
29353
29354
29355;(function (global, factory) {
29356 typeof exports === 'object' && typeof module !== 'undefined'
29357 && typeof require === 'function' ? factory(require('../../moment')) :
29358 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
29359 factory(global.moment)
29360}(this, (function (moment) { 'use strict';
29361
29362 function each(array, callback) {
29363 var i;
29364 for (i = 0; i < array.length; i++) {
29365 callback(array[i], i, array);
29366 }
29367 }
29368
c58511b9
KM
29369 function setupDeprecationHandler(test, moment$$1, scope) {
29370 test._expectedDeprecations = null;
29371 test._observedDeprecations = null;
29372 test._oldSupress = moment$$1.suppressDeprecationWarnings;
29373 moment$$1.suppressDeprecationWarnings = true;
29374 test.expectedDeprecations = function () {
29375 test._expectedDeprecations = arguments;
29376 test._observedDeprecations = [];
29377 };
29378 moment$$1.deprecationHandler = function (name, msg) {
29379 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
29380 if (deprecationId === -1) {
29381 throw new Error('Unexpected deprecation thrown name=' +
29382 name + ' msg=' + msg);
29383 }
29384 test._observedDeprecations[deprecationId] = 1;
29385 };
29386 }
29387
29388 function teardownDeprecationHandler(test, moment$$1, scope) {
29389 moment$$1.suppressDeprecationWarnings = test._oldSupress;
29390
29391 if (test._expectedDeprecations != null) {
29392 var missedDeprecations = [];
29393 each(test._expectedDeprecations, function (deprecationPattern, id) {
29394 if (test._observedDeprecations[id] !== 1) {
29395 missedDeprecations.push(deprecationPattern);
29396 }
29397 });
29398 if (missedDeprecations.length !== 0) {
29399 throw new Error('Expected deprecation warnings did not happen: ' +
29400 missedDeprecations.join(' '));
29401 }
29402 }
29403 }
29404
29405 function matchedDeprecation(name, msg, deprecations) {
29406 if (deprecations == null) {
29407 return -1;
29408 }
29409 for (var i = 0; i < deprecations.length; ++i) {
29410 if (name != null && name === deprecations[i]) {
29411 return i;
29412 }
29413 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
29414 return i;
29415 }
29416 }
29417 return -1;
29418 }
29419
29420 /*global QUnit:false*/
29421
29422 var test = QUnit.test;
29423
db71a655
KM
29424 function objectKeys(obj) {
29425 if (Object.keys) {
29426 return Object.keys(obj);
29427 } else {
29428 // IE8
29429 var res = [], i;
29430 for (i in obj) {
29431 if (obj.hasOwnProperty(i)) {
29432 res.push(i);
29433 }
29434 }
29435 return res;
29436 }
29437 }
29438
29439 // Pick the first defined of two or three arguments.
29440
29441 function defineCommonLocaleTests(locale, options) {
29442 test('lenient day of month ordinal parsing', function (assert) {
29443 var i, ordinalStr, testMoment;
29444 for (i = 1; i <= 31; ++i) {
29445 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
29446 testMoment = moment(ordinalStr, 'YYYY MM Do');
29447 assert.equal(testMoment.year(), 2014,
29448 'lenient day of month ordinal parsing ' + i + ' year check');
29449 assert.equal(testMoment.month(), 0,
29450 'lenient day of month ordinal parsing ' + i + ' month check');
29451 assert.equal(testMoment.date(), i,
29452 'lenient day of month ordinal parsing ' + i + ' date check');
29453 }
29454 });
29455
29456 test('lenient day of month ordinal parsing of number', function (assert) {
29457 var i, testMoment;
29458 for (i = 1; i <= 31; ++i) {
29459 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
29460 assert.equal(testMoment.year(), 2014,
29461 'lenient day of month ordinal parsing of number ' + i + ' year check');
29462 assert.equal(testMoment.month(), 0,
29463 'lenient day of month ordinal parsing of number ' + i + ' month check');
29464 assert.equal(testMoment.date(), i,
29465 'lenient day of month ordinal parsing of number ' + i + ' date check');
29466 }
29467 });
29468
29469 test('strict day of month ordinal parsing', function (assert) {
29470 var i, ordinalStr, testMoment;
29471 for (i = 1; i <= 31; ++i) {
29472 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
29473 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
29474 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
29475 }
29476 });
29477
29478 test('meridiem invariant', function (assert) {
29479 var h, m, t1, t2;
29480 for (h = 0; h < 24; ++h) {
29481 for (m = 0; m < 60; m += 15) {
29482 t1 = moment.utc([2000, 0, 1, h, m]);
29483 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
29484 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
29485 'meridiem at ' + t1.format('HH:mm'));
29486 }
29487 }
29488 });
29489
29490 test('date format correctness', function (assert) {
29491 var data, tokens;
29492 data = moment.localeData()._longDateFormat;
29493 tokens = objectKeys(data);
29494 each(tokens, function (srchToken) {
29495 // Check each format string to make sure it does not contain any
29496 // tokens that need to be expanded.
29497 each(tokens, function (baseToken) {
29498 // strip escaped sequences
29499 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
29500 assert.equal(false, !!~format.indexOf(srchToken),
29501 'contains ' + srchToken + ' in ' + baseToken);
29502 });
29503 });
29504 });
29505
29506 test('month parsing correctness', function (assert) {
29507 var i, m;
29508
29509 if (locale === 'tr') {
29510 // I can't fix it :(
c58511b9 29511 assert.expect(0);
db71a655
KM
29512 return;
29513 }
29514 function tester(format) {
29515 var r;
29516 r = moment(m.format(format), format);
29517 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
29518 if (locale !== 'ka') {
29519 r = moment(m.format(format).toLocaleUpperCase(), format);
29520 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
29521 }
db71a655
KM
29522 r = moment(m.format(format).toLocaleLowerCase(), format);
29523 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
29524
29525 r = moment(m.format(format), format, true);
29526 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
29527 if (locale !== 'ka') {
29528 r = moment(m.format(format).toLocaleUpperCase(), format, true);
29529 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
29530 }
db71a655
KM
29531 r = moment(m.format(format).toLocaleLowerCase(), format, true);
29532 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
29533 }
29534
29535 for (i = 0; i < 12; ++i) {
29536 m = moment([2015, i, 15, 18]);
29537 tester('MMM');
29538 tester('MMM.');
29539 tester('MMMM');
29540 tester('MMMM.');
29541 }
29542 });
29543
29544 test('weekday parsing correctness', function (assert) {
29545 var i, m;
29546
96d0d679 29547 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
29548 // tr, az: There is a lower-case letter (ı), that converted to
29549 // upper then lower changes to i
29550 // ro: there is the letter ț which behaves weird under IE8
29551 // mt: letter Ħ
96d0d679 29552 // ga: month with spaces
c58511b9 29553 assert.expect(0);
db71a655
KM
29554 return;
29555 }
29556 function tester(format) {
29557 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
29558 r = moment(m.format(format), format);
29559 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
29560 if (locale !== 'ka') {
29561 r = moment(m.format(format).toLocaleUpperCase(), format);
29562 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
29563 }
db71a655
KM
29564 r = moment(m.format(format).toLocaleLowerCase(), format);
29565 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
29566 r = moment(m.format(format), format, true);
29567 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
29568 if (locale !== 'ka') {
29569 r = moment(m.format(format).toLocaleUpperCase(), format, true);
29570 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
29571 }
db71a655
KM
29572 r = moment(m.format(format).toLocaleLowerCase(), format, true);
29573 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
29574 }
29575
29576 for (i = 0; i < 7; ++i) {
29577 m = moment.utc([2015, 0, i + 1, 18]);
29578 tester('dd');
29579 tester('ddd');
29580 tester('dddd');
29581 }
29582 });
29583
29584 test('valid localeData', function (assert) {
29585 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
29586 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
29587 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
29588 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
29589 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
29590 });
96d0d679
KM
29591
29592 test('localeData weekdays can localeSort', function (assert) {
29593 var weekdays = moment().localeData().weekdays();
29594 var weekdaysShort = moment().localeData().weekdaysShort();
29595 var weekdaysMin = moment().localeData().weekdaysMin();
29596 var shift = moment().localeData()._week.dow;
29597 assert.deepEqual(
29598 moment().localeData().weekdays(true),
29599 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
29600 'weekdays should localeSort');
29601 assert.deepEqual(
29602 moment().localeData().weekdaysShort(true),
29603 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
29604 'weekdaysShort should localeSort');
29605 assert.deepEqual(
29606 moment().localeData().weekdaysMin(true),
29607 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
29608 'weekdaysMin should localeSort');
29609 });
db71a655
KM
29610 }
29611
db71a655
KM
29612 /*global QUnit:false*/
29613
db71a655
KM
29614 function localeModule (name, lifecycle) {
29615 QUnit.module('locale:' + name, {
c58511b9 29616 beforeEach : function () {
db71a655
KM
29617 moment.locale(name);
29618 moment.createFromInputFallback = function (config) {
29619 throw new Error('input not handled by moment: ' + config._i);
29620 };
29621 setupDeprecationHandler(test, moment, 'locale');
29622 if (lifecycle && lifecycle.setup) {
29623 lifecycle.setup();
29624 }
29625 },
c58511b9 29626 afterEach : function () {
db71a655
KM
29627 moment.locale('en');
29628 teardownDeprecationHandler(test, moment, 'locale');
29629 if (lifecycle && lifecycle.teardown) {
29630 lifecycle.teardown();
29631 }
29632 }
29633 });
29634 defineCommonLocaleTests(name, -1, -1);
29635 }
29636
96d0d679 29637 localeModule('is');
db71a655
KM
29638
29639 test('parse', function (assert) {
96d0d679 29640 var tests = 'janúar jan_febrúar feb_mars mar_apríl apr_maí maí_júní jún_júlí júl_ágúst ágú_september sep_október okt_nóvember nóv_desember des'.split('_'), i;
db71a655
KM
29641 function equalTest(input, mmm, i) {
29642 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
29643 }
29644 for (i = 0; i < 12; i++) {
29645 tests[i] = tests[i].split(' ');
29646 equalTest(tests[i][0], 'MMM', i);
29647 equalTest(tests[i][1], 'MMM', i);
29648 equalTest(tests[i][0], 'MMMM', i);
29649 equalTest(tests[i][1], 'MMMM', i);
29650 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
29651 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
29652 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
29653 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
29654 }
29655 });
29656
29657 test('format', function (assert) {
29658 var a = [
96d0d679
KM
29659 ['dddd, Do MMMM YYYY, h:mm:ss a', 'sunnudagur, 14. febrúar 2010, 3:25:50 pm'],
29660 ['ddd, hA', 'sun, 3PM'],
29661 ['M Mo MM MMMM MMM', '2 2. 02 febrúar feb'],
db71a655 29662 ['YYYY YY', '2010 10'],
96d0d679
KM
29663 ['D Do DD', '14 14. 14'],
29664 ['d do dddd ddd dd', '0 0. sunnudagur sun Su'],
29665 ['DDD DDDo DDDD', '45 45. 045'],
29666 ['w wo ww', '6 6. 06'],
db71a655
KM
29667 ['h hh', '3 03'],
29668 ['H HH', '15 15'],
29669 ['m mm', '25 25'],
29670 ['s ss', '50 50'],
96d0d679
KM
29671 ['a A', 'pm PM'],
29672 ['[the] DDDo [day of the year]', 'the 45. day of the year'],
29673 ['LTS', '15:25:50'],
29674 ['L', '14.02.2010'],
29675 ['LL', '14. febrúar 2010'],
29676 ['LLL', '14. febrúar 2010 kl. 15:25'],
29677 ['LLLL', 'sunnudagur, 14. febrúar 2010 kl. 15:25'],
29678 ['l', '14.2.2010'],
29679 ['ll', '14. feb 2010'],
29680 ['lll', '14. feb 2010 kl. 15:25'],
29681 ['llll', 'sun, 14. feb 2010 kl. 15:25']
db71a655
KM
29682 ],
29683 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
29684 i;
29685 for (i = 0; i < a.length; i++) {
29686 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
29687 }
29688 });
29689
96d0d679
KM
29690 test('format ordinal', function (assert) {
29691 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
29692 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
29693 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
29694 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
29695 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
29696 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
29697 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
29698 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
29699 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
29700 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
29701
29702 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
29703 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
29704 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
29705 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
29706 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
29707 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
29708 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
29709 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
29710 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
29711 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
29712
29713 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
29714 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
29715 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
29716 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
29717 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
29718 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
29719 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
29720 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
29721 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
29722 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
29723
29724 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
29725 });
29726
db71a655 29727 test('format month', function (assert) {
96d0d679 29728 var expected = 'janúar jan_febrúar feb_mars mar_apríl apr_maí maí_júní jún_júlí júl_ágúst ágú_september sep_október okt_nóvember nóv_desember des'.split('_'), i;
db71a655
KM
29729 for (i = 0; i < expected.length; i++) {
29730 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
29731 }
29732 });
29733
29734 test('format week', function (assert) {
96d0d679 29735 var expected = 'sunnudagur sun Su_mánudagur mán Má_þriðjudagur þri Þr_miðvikudagur mið Mi_fimmtudagur fim Fi_föstudagur fös Fö_laugardagur lau La'.split('_'), i;
db71a655
KM
29736 for (i = 0; i < expected.length; i++) {
29737 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
29738 }
29739 });
29740
29741 test('from', function (assert) {
29742 var start = moment([2007, 1, 28]);
96d0d679
KM
29743 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'nokkrar sekúndur', '44 seconds = a few seconds');
29744 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'mínúta', '45 seconds = a minute');
29745 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'mínúta', '89 seconds = a minute');
29746 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 mínútur', '90 seconds = 2 minutes');
29747 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 mínútur', '44 minutes = 44 minutes');
29748 assert.equal(start.from(moment([2007, 1, 28]).add({m: 21}), true), '21 mínúta', '21 minutes = 21 minutes');
29749 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'klukkustund', '45 minutes = an hour');
29750 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'klukkustund', '89 minutes = an hour');
29751 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 klukkustundir', '90 minutes = 2 hours');
29752 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 klukkustundir', '5 hours = 5 hours');
29753 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 klukkustund', '21 hours = 21 hours');
29754 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'dagur', '22 hours = a day');
29755 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'dagur', '35 hours = a day');
29756 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dagar', '36 hours = 2 days');
29757 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'dagur', '1 day = a day');
29758 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dagar', '5 days = 5 days');
29759 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dagar', '25 days = 25 days');
29760 assert.equal(start.from(moment([2007, 1, 28]).add({d: 11}), true), '11 dagar', '11 days = 11 days');
29761 assert.equal(start.from(moment([2007, 1, 28]).add({d: 21}), true), '21 dagur', '21 days = 21 days');
29762 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mánuður', '26 days = a month');
29763 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mánuður', '30 days = a month');
29764 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mánuður', '43 days = a month');
29765 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mánuðir', '46 days = 2 months');
29766 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mánuðir', '75 days = 2 months');
29767 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mánuðir', '76 days = 3 months');
29768 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mánuður', '1 month = a month');
29769 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mánuðir', '5 months = 5 months');
29770 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ár', '345 days = a year');
29771 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ár', '548 days = 2 years');
29772 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ár', '1 year = a year');
29773 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ár', '5 years = 5 years');
29774 assert.equal(start.from(moment([2007, 1, 28]).add({y: 21}), true), '21 ár', '21 years = 21 years');
db71a655
KM
29775 });
29776
29777 test('suffix', function (assert) {
96d0d679
KM
29778 assert.equal(moment(30000).from(0), 'eftir nokkrar sekúndur', 'prefix');
29779 assert.equal(moment(0).from(30000), 'fyrir nokkrum sekúndum síðan', 'suffix');
29780 assert.equal(moment().subtract({m: 1}).fromNow(), 'fyrir mínútu síðan', 'a minute ago');
db71a655
KM
29781 });
29782
29783 test('now from now', function (assert) {
96d0d679 29784 assert.equal(moment().fromNow(), 'fyrir nokkrum sekúndum síðan', 'now from now should display as in the past');
db71a655
KM
29785 });
29786
29787 test('fromNow', function (assert) {
96d0d679
KM
29788 assert.equal(moment().add({s: 30}).fromNow(), 'eftir nokkrar sekúndur', 'in a few seconds');
29789 assert.equal(moment().add({m: 1}).fromNow(), 'eftir mínútu', 'in a minute');
29790 assert.equal(moment().add({d: 5}).fromNow(), 'eftir 5 daga', 'in 5 days');
db71a655
KM
29791 });
29792
29793 test('calendar day', function (assert) {
29794 var a = moment().hours(12).minutes(0).seconds(0);
29795
96d0d679
KM
29796 assert.equal(moment(a).calendar(), 'í dag kl. 12:00', 'today at the same time');
29797 assert.equal(moment(a).add({m: 25}).calendar(), 'í dag kl. 12:25', 'Now plus 25 min');
29798 assert.equal(moment(a).add({h: 1}).calendar(), 'í dag kl. 13:00', 'Now plus 1 hour');
29799 assert.equal(moment(a).add({d: 1}).calendar(), 'á morgun kl. 12:00', 'tomorrow at the same time');
29800 assert.equal(moment(a).subtract({h: 1}).calendar(), 'í dag kl. 11:00', 'Now minus 1 hour');
29801 assert.equal(moment(a).subtract({d: 1}).calendar(), 'í gær kl. 12:00', 'yesterday at the same time');
db71a655
KM
29802 });
29803
29804 test('calendar next week', function (assert) {
29805 var i, m;
29806 for (i = 2; i < 7; i++) {
29807 m = moment().add({d: i});
96d0d679 29808 assert.equal(m.calendar(), m.format('dddd [kl.] LT'), 'Today + ' + i + ' days current time');
db71a655 29809 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 29810 assert.equal(m.calendar(), m.format('dddd [kl.] LT'), 'Today + ' + i + ' days beginning of day');
db71a655 29811 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 29812 assert.equal(m.calendar(), m.format('dddd [kl.] LT'), 'Today + ' + i + ' days end of day');
db71a655
KM
29813 }
29814 });
29815
29816 test('calendar last week', function (assert) {
29817 var i, m;
96d0d679 29818
db71a655
KM
29819 for (i = 2; i < 7; i++) {
29820 m = moment().subtract({d: i});
96d0d679 29821 assert.equal(m.calendar(), m.format('[síðasta] dddd [kl.] LT'), 'Today - ' + i + ' days current time');
db71a655 29822 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 29823 assert.equal(m.calendar(), m.format('[síðasta] dddd [kl.] LT'), 'Today - ' + i + ' days beginning of day');
db71a655 29824 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 29825 assert.equal(m.calendar(), m.format('[síðasta] dddd [kl.] LT'), 'Today - ' + i + ' days end of day');
db71a655
KM
29826 }
29827 });
29828
29829 test('calendar all else', function (assert) {
29830 var weeksAgo = moment().subtract({w: 1}),
29831 weeksFromNow = moment().add({w: 1});
29832
29833 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
29834 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
29835
29836 weeksAgo = moment().subtract({w: 2});
29837 weeksFromNow = moment().add({w: 2});
29838
29839 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
29840 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
29841 });
29842
29843 test('weeks year starting sunday formatted', function (assert) {
96d0d679
KM
29844 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
29845 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
29846 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
29847 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
29848 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
db71a655
KM
29849 });
29850
29851})));
29852
29853
29854;(function (global, factory) {
29855 typeof exports === 'object' && typeof module !== 'undefined'
29856 && typeof require === 'function' ? factory(require('../../moment')) :
29857 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
29858 factory(global.moment)
29859}(this, (function (moment) { 'use strict';
29860
29861 function each(array, callback) {
29862 var i;
29863 for (i = 0; i < array.length; i++) {
29864 callback(array[i], i, array);
29865 }
29866 }
29867
c58511b9
KM
29868 function setupDeprecationHandler(test, moment$$1, scope) {
29869 test._expectedDeprecations = null;
29870 test._observedDeprecations = null;
29871 test._oldSupress = moment$$1.suppressDeprecationWarnings;
29872 moment$$1.suppressDeprecationWarnings = true;
29873 test.expectedDeprecations = function () {
29874 test._expectedDeprecations = arguments;
29875 test._observedDeprecations = [];
29876 };
29877 moment$$1.deprecationHandler = function (name, msg) {
29878 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
29879 if (deprecationId === -1) {
29880 throw new Error('Unexpected deprecation thrown name=' +
29881 name + ' msg=' + msg);
29882 }
29883 test._observedDeprecations[deprecationId] = 1;
29884 };
29885 }
29886
29887 function teardownDeprecationHandler(test, moment$$1, scope) {
29888 moment$$1.suppressDeprecationWarnings = test._oldSupress;
29889
29890 if (test._expectedDeprecations != null) {
29891 var missedDeprecations = [];
29892 each(test._expectedDeprecations, function (deprecationPattern, id) {
29893 if (test._observedDeprecations[id] !== 1) {
29894 missedDeprecations.push(deprecationPattern);
29895 }
29896 });
29897 if (missedDeprecations.length !== 0) {
29898 throw new Error('Expected deprecation warnings did not happen: ' +
29899 missedDeprecations.join(' '));
29900 }
29901 }
29902 }
29903
29904 function matchedDeprecation(name, msg, deprecations) {
29905 if (deprecations == null) {
29906 return -1;
29907 }
29908 for (var i = 0; i < deprecations.length; ++i) {
29909 if (name != null && name === deprecations[i]) {
29910 return i;
29911 }
29912 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
29913 return i;
29914 }
29915 }
29916 return -1;
29917 }
29918
29919 /*global QUnit:false*/
29920
29921 var test = QUnit.test;
29922
db71a655
KM
29923 function objectKeys(obj) {
29924 if (Object.keys) {
29925 return Object.keys(obj);
29926 } else {
29927 // IE8
29928 var res = [], i;
29929 for (i in obj) {
29930 if (obj.hasOwnProperty(i)) {
29931 res.push(i);
29932 }
29933 }
29934 return res;
29935 }
29936 }
29937
29938 // Pick the first defined of two or three arguments.
29939
29940 function defineCommonLocaleTests(locale, options) {
29941 test('lenient day of month ordinal parsing', function (assert) {
29942 var i, ordinalStr, testMoment;
29943 for (i = 1; i <= 31; ++i) {
29944 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
29945 testMoment = moment(ordinalStr, 'YYYY MM Do');
29946 assert.equal(testMoment.year(), 2014,
29947 'lenient day of month ordinal parsing ' + i + ' year check');
29948 assert.equal(testMoment.month(), 0,
29949 'lenient day of month ordinal parsing ' + i + ' month check');
29950 assert.equal(testMoment.date(), i,
29951 'lenient day of month ordinal parsing ' + i + ' date check');
29952 }
29953 });
29954
29955 test('lenient day of month ordinal parsing of number', function (assert) {
29956 var i, testMoment;
29957 for (i = 1; i <= 31; ++i) {
29958 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
29959 assert.equal(testMoment.year(), 2014,
29960 'lenient day of month ordinal parsing of number ' + i + ' year check');
29961 assert.equal(testMoment.month(), 0,
29962 'lenient day of month ordinal parsing of number ' + i + ' month check');
29963 assert.equal(testMoment.date(), i,
29964 'lenient day of month ordinal parsing of number ' + i + ' date check');
29965 }
29966 });
29967
29968 test('strict day of month ordinal parsing', function (assert) {
29969 var i, ordinalStr, testMoment;
29970 for (i = 1; i <= 31; ++i) {
29971 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
29972 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
29973 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
29974 }
29975 });
29976
29977 test('meridiem invariant', function (assert) {
29978 var h, m, t1, t2;
29979 for (h = 0; h < 24; ++h) {
29980 for (m = 0; m < 60; m += 15) {
29981 t1 = moment.utc([2000, 0, 1, h, m]);
29982 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
29983 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
29984 'meridiem at ' + t1.format('HH:mm'));
29985 }
29986 }
29987 });
29988
29989 test('date format correctness', function (assert) {
29990 var data, tokens;
29991 data = moment.localeData()._longDateFormat;
29992 tokens = objectKeys(data);
29993 each(tokens, function (srchToken) {
29994 // Check each format string to make sure it does not contain any
29995 // tokens that need to be expanded.
29996 each(tokens, function (baseToken) {
29997 // strip escaped sequences
29998 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
29999 assert.equal(false, !!~format.indexOf(srchToken),
30000 'contains ' + srchToken + ' in ' + baseToken);
30001 });
30002 });
30003 });
30004
30005 test('month parsing correctness', function (assert) {
30006 var i, m;
30007
30008 if (locale === 'tr') {
30009 // I can't fix it :(
c58511b9 30010 assert.expect(0);
db71a655
KM
30011 return;
30012 }
30013 function tester(format) {
30014 var r;
30015 r = moment(m.format(format), format);
30016 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
30017 if (locale !== 'ka') {
30018 r = moment(m.format(format).toLocaleUpperCase(), format);
30019 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
30020 }
db71a655
KM
30021 r = moment(m.format(format).toLocaleLowerCase(), format);
30022 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
30023
30024 r = moment(m.format(format), format, true);
30025 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
30026 if (locale !== 'ka') {
30027 r = moment(m.format(format).toLocaleUpperCase(), format, true);
30028 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
30029 }
db71a655
KM
30030 r = moment(m.format(format).toLocaleLowerCase(), format, true);
30031 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
30032 }
30033
30034 for (i = 0; i < 12; ++i) {
30035 m = moment([2015, i, 15, 18]);
30036 tester('MMM');
30037 tester('MMM.');
30038 tester('MMMM');
30039 tester('MMMM.');
30040 }
30041 });
30042
30043 test('weekday parsing correctness', function (assert) {
30044 var i, m;
30045
96d0d679 30046 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
30047 // tr, az: There is a lower-case letter (ı), that converted to
30048 // upper then lower changes to i
30049 // ro: there is the letter ț which behaves weird under IE8
30050 // mt: letter Ħ
96d0d679 30051 // ga: month with spaces
c58511b9 30052 assert.expect(0);
db71a655
KM
30053 return;
30054 }
30055 function tester(format) {
30056 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
30057 r = moment(m.format(format), format);
30058 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
30059 if (locale !== 'ka') {
30060 r = moment(m.format(format).toLocaleUpperCase(), format);
30061 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
30062 }
db71a655
KM
30063 r = moment(m.format(format).toLocaleLowerCase(), format);
30064 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
30065 r = moment(m.format(format), format, true);
30066 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
30067 if (locale !== 'ka') {
30068 r = moment(m.format(format).toLocaleUpperCase(), format, true);
30069 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
30070 }
db71a655
KM
30071 r = moment(m.format(format).toLocaleLowerCase(), format, true);
30072 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
30073 }
30074
30075 for (i = 0; i < 7; ++i) {
30076 m = moment.utc([2015, 0, i + 1, 18]);
30077 tester('dd');
30078 tester('ddd');
30079 tester('dddd');
30080 }
30081 });
30082
30083 test('valid localeData', function (assert) {
30084 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
30085 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
30086 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
30087 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
30088 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
30089 });
96d0d679
KM
30090
30091 test('localeData weekdays can localeSort', function (assert) {
30092 var weekdays = moment().localeData().weekdays();
30093 var weekdaysShort = moment().localeData().weekdaysShort();
30094 var weekdaysMin = moment().localeData().weekdaysMin();
30095 var shift = moment().localeData()._week.dow;
30096 assert.deepEqual(
30097 moment().localeData().weekdays(true),
30098 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
30099 'weekdays should localeSort');
30100 assert.deepEqual(
30101 moment().localeData().weekdaysShort(true),
30102 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
30103 'weekdaysShort should localeSort');
30104 assert.deepEqual(
30105 moment().localeData().weekdaysMin(true),
30106 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
30107 'weekdaysMin should localeSort');
30108 });
db71a655
KM
30109 }
30110
db71a655
KM
30111 /*global QUnit:false*/
30112
db71a655
KM
30113 function localeModule (name, lifecycle) {
30114 QUnit.module('locale:' + name, {
c58511b9 30115 beforeEach : function () {
db71a655
KM
30116 moment.locale(name);
30117 moment.createFromInputFallback = function (config) {
30118 throw new Error('input not handled by moment: ' + config._i);
30119 };
30120 setupDeprecationHandler(test, moment, 'locale');
30121 if (lifecycle && lifecycle.setup) {
30122 lifecycle.setup();
30123 }
30124 },
c58511b9 30125 afterEach : function () {
db71a655
KM
30126 moment.locale('en');
30127 teardownDeprecationHandler(test, moment, 'locale');
30128 if (lifecycle && lifecycle.teardown) {
30129 lifecycle.teardown();
30130 }
30131 }
30132 });
30133 defineCommonLocaleTests(name, -1, -1);
30134 }
30135
96d0d679 30136 localeModule('it-ch');
db71a655
KM
30137
30138 test('parse', function (assert) {
96d0d679 30139 var tests = 'gennaio gen_febbraio feb_marzo mar_aprile apr_maggio mag_giugno giu_luglio lug_agosto ago_settembre set_ottobre ott_novembre nov_dicembre dic'.split('_'), i;
db71a655
KM
30140 function equalTest(input, mmm, i) {
30141 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
30142 }
30143 for (i = 0; i < 12; i++) {
30144 tests[i] = tests[i].split(' ');
30145 equalTest(tests[i][0], 'MMM', i);
30146 equalTest(tests[i][1], 'MMM', i);
30147 equalTest(tests[i][0], 'MMMM', i);
30148 equalTest(tests[i][1], 'MMMM', i);
30149 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
30150 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
30151 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
30152 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
30153 }
30154 });
30155
30156 test('format', function (assert) {
30157 var a = [
96d0d679
KM
30158 ['dddd, MMMM Do YYYY, h:mm:ss a', 'domenica, febbraio 14º 2010, 3:25:50 pm'],
30159 ['ddd, hA', 'dom, 3PM'],
30160 ['M Mo MM MMMM MMM', '2 2º 02 febbraio feb'],
db71a655 30161 ['YYYY YY', '2010 10'],
96d0d679
KM
30162 ['D Do DD', '14 14º 14'],
30163 ['d do dddd ddd dd', '0 0º domenica dom do'],
30164 ['DDD DDDo DDDD', '45 45º 045'],
30165 ['w wo ww', '6 6º 06'],
db71a655
KM
30166 ['h hh', '3 03'],
30167 ['H HH', '15 15'],
30168 ['m mm', '25 25'],
30169 ['s ss', '50 50'],
30170 ['a A', 'pm PM'],
96d0d679 30171 ['[the] DDDo [day of the year]', 'the 45º day of the year'],
db71a655
KM
30172 ['LTS', '15:25:50'],
30173 ['L', '14.02.2010'],
96d0d679
KM
30174 ['LL', '14 febbraio 2010'],
30175 ['LLL', '14 febbraio 2010 15:25'],
30176 ['LLLL', 'domenica 14 febbraio 2010 15:25'],
db71a655 30177 ['l', '14.2.2010'],
96d0d679
KM
30178 ['ll', '14 feb 2010'],
30179 ['lll', '14 feb 2010 15:25'],
30180 ['llll', 'dom 14 feb 2010 15:25']
db71a655
KM
30181 ],
30182 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
30183 i;
30184 for (i = 0; i < a.length; i++) {
30185 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
30186 }
30187 });
30188
30189 test('format ordinal', function (assert) {
96d0d679
KM
30190 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1º', '1º');
30191 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2º', '2º');
30192 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3º', '3º');
30193 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4º', '4º');
30194 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5º', '5º');
30195 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6º', '6º');
30196 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7º', '7º');
30197 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8º', '8º');
30198 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9º', '9º');
30199 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10º', '10º');
db71a655 30200
96d0d679
KM
30201 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11º', '11º');
30202 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12º', '12º');
30203 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13º', '13º');
30204 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14º', '14º');
30205 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15º', '15º');
30206 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16º', '16º');
30207 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17º', '17º');
30208 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18º', '18º');
30209 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19º', '19º');
30210 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20º', '20º');
db71a655 30211
96d0d679
KM
30212 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21º', '21º');
30213 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22º', '22º');
30214 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23º', '23º');
30215 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24º', '24º');
30216 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25º', '25º');
30217 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26º', '26º');
30218 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27º', '27º');
30219 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28º', '28º');
30220 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29º', '29º');
30221 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30º', '30º');
db71a655 30222
96d0d679 30223 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31º', '31º');
db71a655
KM
30224 });
30225
30226 test('format month', function (assert) {
96d0d679 30227 var expected = 'gennaio gen_febbraio feb_marzo mar_aprile apr_maggio mag_giugno giu_luglio lug_agosto ago_settembre set_ottobre ott_novembre nov_dicembre dic'.split('_'), i;
db71a655
KM
30228 for (i = 0; i < expected.length; i++) {
30229 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
30230 }
30231 });
30232
30233 test('format week', function (assert) {
96d0d679 30234 var expected = 'domenica dom do_lunedì lun lu_martedì mar ma_mercoledì mer me_giovedì gio gi_venerdì ven ve_sabato sab sa'.split('_'), i;
db71a655
KM
30235 for (i = 0; i < expected.length; i++) {
30236 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
30237 }
30238 });
30239
30240 test('from', function (assert) {
30241 var start = moment([2007, 1, 28]);
96d0d679
KM
30242 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'alcuni secondi', '44 seconds = seconds');
30243 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'un minuto', '45 seconds = a minute');
30244 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'un minuto', '89 seconds = a minute');
30245 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuti', '90 seconds = 2 minutes');
30246 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuti', '44 minutes = 44 minutes');
30247 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'un\'ora', '45 minutes = an hour');
30248 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'un\'ora', '89 minutes = an hour');
30249 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ore', '90 minutes = 2 hours');
30250 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ore', '5 hours = 5 hours');
30251 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ore', '21 hours = 21 hours');
30252 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un giorno', '22 hours = a day');
30253 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un giorno', '35 hours = a day');
30254 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 giorni', '36 hours = 2 days');
30255 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un giorno', '1 day = a day');
30256 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 giorni', '5 days = 5 days');
30257 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 giorni', '25 days = 25 days');
30258 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'un mese', '26 days = a month');
30259 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'un mese', '30 days = a month');
30260 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'un mese', '43 days = a month');
30261 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mesi', '46 days = 2 months');
30262 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mesi', '75 days = 2 months');
30263 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mesi', '76 days = 3 months');
30264 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'un mese', '1 month = a month');
30265 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mesi', '5 months = 5 months');
30266 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un anno', '345 days = a year');
30267 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 anni', '548 days = 2 years');
30268 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un anno', '1 year = a year');
30269 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 anni', '5 years = 5 years');
db71a655
KM
30270 });
30271
30272 test('suffix', function (assert) {
96d0d679
KM
30273 assert.equal(moment(30000).from(0), 'in alcuni secondi', 'prefix');
30274 assert.equal(moment(0).from(30000), 'alcuni secondi fa', 'suffix');
db71a655
KM
30275 });
30276
30277 test('fromNow', function (assert) {
96d0d679
KM
30278 assert.equal(moment().add({s: 30}).fromNow(), 'in alcuni secondi', 'in seconds');
30279 assert.equal(moment().add({d: 5}).fromNow(), 'tra 5 giorni', 'in 5 days');
db71a655
KM
30280 });
30281
30282 test('calendar day', function (assert) {
30283 var a = moment().hours(12).minutes(0).seconds(0);
30284
96d0d679
KM
30285 assert.equal(moment(a).calendar(), 'Oggi alle 12:00', 'today at the same time');
30286 assert.equal(moment(a).add({m: 25}).calendar(), 'Oggi alle 12:25', 'Now plus 25 min');
30287 assert.equal(moment(a).add({h: 1}).calendar(), 'Oggi alle 13:00', 'Now plus 1 hour');
30288 assert.equal(moment(a).add({d: 1}).calendar(), 'Domani alle 12:00', 'tomorrow at the same time');
30289 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Oggi alle 11:00', 'Now minus 1 hour');
30290 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Ieri alle 12:00', 'yesterday at the same time');
db71a655
KM
30291 });
30292
30293 test('calendar next week', function (assert) {
30294 var i, m;
30295 for (i = 2; i < 7; i++) {
30296 m = moment().add({d: i});
96d0d679 30297 assert.equal(m.calendar(), m.format('dddd [alle] LT'), 'Today + ' + i + ' days current time');
db71a655 30298 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 30299 assert.equal(m.calendar(), m.format('dddd [alle] LT'), 'Today + ' + i + ' days beginning of day');
db71a655 30300 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 30301 assert.equal(m.calendar(), m.format('dddd [alle] LT'), 'Today + ' + i + ' days end of day');
db71a655
KM
30302 }
30303 });
30304
30305 test('calendar last week', function (assert) {
96d0d679 30306 var i, m, weekday, datestring;
db71a655
KM
30307 for (i = 2; i < 7; i++) {
30308 m = moment().subtract({d: i});
96d0d679
KM
30309 // Different date string
30310 weekday = parseInt(m.format('d'), 10);
30311 datestring = (weekday === 0) ? '[la scorsa] dddd [alle] LT' : '[lo scorso] dddd [alle] LT';
30312 assert.equal(m.calendar(), m.format(datestring), 'Today - ' + i + ' days current time');
db71a655 30313 m.hours(0).minutes(0).seconds(0).milliseconds(0);
96d0d679 30314 assert.equal(m.calendar(), m.format(datestring), 'Today - ' + i + ' days beginning of day');
db71a655 30315 m.hours(23).minutes(59).seconds(59).milliseconds(999);
96d0d679 30316 assert.equal(m.calendar(), m.format(datestring), 'Today - ' + i + ' days end of day');
db71a655
KM
30317 }
30318 });
30319
30320 test('calendar all else', function (assert) {
30321 var weeksAgo = moment().subtract({w: 1}),
30322 weeksFromNow = moment().add({w: 1});
30323
30324 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
30325 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
30326
30327 weeksAgo = moment().subtract({w: 2});
30328 weeksFromNow = moment().add({w: 2});
30329
30330 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
30331 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
30332 });
30333
30334 test('weeks year starting sunday formatted', function (assert) {
96d0d679
KM
30335 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52º', 'Jan 1 2012 should be week 52');
30336 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1º', 'Jan 2 2012 should be week 1');
30337 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1º', 'Jan 8 2012 should be week 1');
30338 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2º', 'Jan 9 2012 should be week 2');
30339 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2º', 'Jan 15 2012 should be week 2');
db71a655
KM
30340 });
30341
30342})));
30343
30344
30345;(function (global, factory) {
30346 typeof exports === 'object' && typeof module !== 'undefined'
30347 && typeof require === 'function' ? factory(require('../../moment')) :
30348 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
30349 factory(global.moment)
30350}(this, (function (moment) { 'use strict';
30351
30352 function each(array, callback) {
30353 var i;
30354 for (i = 0; i < array.length; i++) {
30355 callback(array[i], i, array);
30356 }
30357 }
30358
c58511b9
KM
30359 function setupDeprecationHandler(test, moment$$1, scope) {
30360 test._expectedDeprecations = null;
30361 test._observedDeprecations = null;
30362 test._oldSupress = moment$$1.suppressDeprecationWarnings;
30363 moment$$1.suppressDeprecationWarnings = true;
30364 test.expectedDeprecations = function () {
30365 test._expectedDeprecations = arguments;
30366 test._observedDeprecations = [];
30367 };
30368 moment$$1.deprecationHandler = function (name, msg) {
30369 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
30370 if (deprecationId === -1) {
30371 throw new Error('Unexpected deprecation thrown name=' +
30372 name + ' msg=' + msg);
30373 }
30374 test._observedDeprecations[deprecationId] = 1;
30375 };
30376 }
30377
30378 function teardownDeprecationHandler(test, moment$$1, scope) {
30379 moment$$1.suppressDeprecationWarnings = test._oldSupress;
30380
30381 if (test._expectedDeprecations != null) {
30382 var missedDeprecations = [];
30383 each(test._expectedDeprecations, function (deprecationPattern, id) {
30384 if (test._observedDeprecations[id] !== 1) {
30385 missedDeprecations.push(deprecationPattern);
30386 }
30387 });
30388 if (missedDeprecations.length !== 0) {
30389 throw new Error('Expected deprecation warnings did not happen: ' +
30390 missedDeprecations.join(' '));
30391 }
30392 }
30393 }
30394
30395 function matchedDeprecation(name, msg, deprecations) {
30396 if (deprecations == null) {
30397 return -1;
30398 }
30399 for (var i = 0; i < deprecations.length; ++i) {
30400 if (name != null && name === deprecations[i]) {
30401 return i;
30402 }
30403 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
30404 return i;
30405 }
30406 }
30407 return -1;
30408 }
30409
30410 /*global QUnit:false*/
30411
30412 var test = QUnit.test;
30413
db71a655
KM
30414 function objectKeys(obj) {
30415 if (Object.keys) {
30416 return Object.keys(obj);
30417 } else {
30418 // IE8
30419 var res = [], i;
30420 for (i in obj) {
30421 if (obj.hasOwnProperty(i)) {
30422 res.push(i);
30423 }
30424 }
30425 return res;
30426 }
30427 }
30428
30429 // Pick the first defined of two or three arguments.
30430
30431 function defineCommonLocaleTests(locale, options) {
30432 test('lenient day of month ordinal parsing', function (assert) {
30433 var i, ordinalStr, testMoment;
30434 for (i = 1; i <= 31; ++i) {
30435 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
30436 testMoment = moment(ordinalStr, 'YYYY MM Do');
30437 assert.equal(testMoment.year(), 2014,
30438 'lenient day of month ordinal parsing ' + i + ' year check');
30439 assert.equal(testMoment.month(), 0,
30440 'lenient day of month ordinal parsing ' + i + ' month check');
30441 assert.equal(testMoment.date(), i,
30442 'lenient day of month ordinal parsing ' + i + ' date check');
30443 }
30444 });
30445
30446 test('lenient day of month ordinal parsing of number', function (assert) {
30447 var i, testMoment;
30448 for (i = 1; i <= 31; ++i) {
30449 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
30450 assert.equal(testMoment.year(), 2014,
30451 'lenient day of month ordinal parsing of number ' + i + ' year check');
30452 assert.equal(testMoment.month(), 0,
30453 'lenient day of month ordinal parsing of number ' + i + ' month check');
30454 assert.equal(testMoment.date(), i,
30455 'lenient day of month ordinal parsing of number ' + i + ' date check');
30456 }
30457 });
30458
30459 test('strict day of month ordinal parsing', function (assert) {
30460 var i, ordinalStr, testMoment;
30461 for (i = 1; i <= 31; ++i) {
30462 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
30463 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
30464 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
30465 }
30466 });
30467
30468 test('meridiem invariant', function (assert) {
30469 var h, m, t1, t2;
30470 for (h = 0; h < 24; ++h) {
30471 for (m = 0; m < 60; m += 15) {
30472 t1 = moment.utc([2000, 0, 1, h, m]);
30473 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
30474 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
30475 'meridiem at ' + t1.format('HH:mm'));
30476 }
30477 }
30478 });
30479
30480 test('date format correctness', function (assert) {
30481 var data, tokens;
30482 data = moment.localeData()._longDateFormat;
30483 tokens = objectKeys(data);
30484 each(tokens, function (srchToken) {
30485 // Check each format string to make sure it does not contain any
30486 // tokens that need to be expanded.
30487 each(tokens, function (baseToken) {
30488 // strip escaped sequences
30489 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
30490 assert.equal(false, !!~format.indexOf(srchToken),
30491 'contains ' + srchToken + ' in ' + baseToken);
30492 });
30493 });
30494 });
30495
30496 test('month parsing correctness', function (assert) {
30497 var i, m;
30498
30499 if (locale === 'tr') {
30500 // I can't fix it :(
c58511b9 30501 assert.expect(0);
db71a655
KM
30502 return;
30503 }
30504 function tester(format) {
30505 var r;
30506 r = moment(m.format(format), format);
30507 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
30508 if (locale !== 'ka') {
30509 r = moment(m.format(format).toLocaleUpperCase(), format);
30510 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
30511 }
db71a655
KM
30512 r = moment(m.format(format).toLocaleLowerCase(), format);
30513 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
30514
30515 r = moment(m.format(format), format, true);
30516 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
30517 if (locale !== 'ka') {
30518 r = moment(m.format(format).toLocaleUpperCase(), format, true);
30519 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
30520 }
db71a655
KM
30521 r = moment(m.format(format).toLocaleLowerCase(), format, true);
30522 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
30523 }
30524
30525 for (i = 0; i < 12; ++i) {
30526 m = moment([2015, i, 15, 18]);
30527 tester('MMM');
30528 tester('MMM.');
30529 tester('MMMM');
30530 tester('MMMM.');
30531 }
30532 });
30533
30534 test('weekday parsing correctness', function (assert) {
30535 var i, m;
30536
96d0d679 30537 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
30538 // tr, az: There is a lower-case letter (ı), that converted to
30539 // upper then lower changes to i
30540 // ro: there is the letter ț which behaves weird under IE8
30541 // mt: letter Ħ
96d0d679 30542 // ga: month with spaces
c58511b9 30543 assert.expect(0);
db71a655
KM
30544 return;
30545 }
30546 function tester(format) {
30547 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
30548 r = moment(m.format(format), format);
30549 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
30550 if (locale !== 'ka') {
30551 r = moment(m.format(format).toLocaleUpperCase(), format);
30552 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
30553 }
db71a655
KM
30554 r = moment(m.format(format).toLocaleLowerCase(), format);
30555 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
30556 r = moment(m.format(format), format, true);
30557 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
30558 if (locale !== 'ka') {
30559 r = moment(m.format(format).toLocaleUpperCase(), format, true);
30560 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
30561 }
db71a655
KM
30562 r = moment(m.format(format).toLocaleLowerCase(), format, true);
30563 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
30564 }
30565
30566 for (i = 0; i < 7; ++i) {
30567 m = moment.utc([2015, 0, i + 1, 18]);
30568 tester('dd');
30569 tester('ddd');
30570 tester('dddd');
30571 }
30572 });
30573
30574 test('valid localeData', function (assert) {
30575 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
30576 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
30577 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
30578 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
30579 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
30580 });
96d0d679
KM
30581
30582 test('localeData weekdays can localeSort', function (assert) {
30583 var weekdays = moment().localeData().weekdays();
30584 var weekdaysShort = moment().localeData().weekdaysShort();
30585 var weekdaysMin = moment().localeData().weekdaysMin();
30586 var shift = moment().localeData()._week.dow;
30587 assert.deepEqual(
30588 moment().localeData().weekdays(true),
30589 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
30590 'weekdays should localeSort');
30591 assert.deepEqual(
30592 moment().localeData().weekdaysShort(true),
30593 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
30594 'weekdaysShort should localeSort');
30595 assert.deepEqual(
30596 moment().localeData().weekdaysMin(true),
30597 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
30598 'weekdaysMin should localeSort');
30599 });
db71a655
KM
30600 }
30601
db71a655
KM
30602 /*global QUnit:false*/
30603
db71a655
KM
30604 function localeModule (name, lifecycle) {
30605 QUnit.module('locale:' + name, {
c58511b9 30606 beforeEach : function () {
db71a655
KM
30607 moment.locale(name);
30608 moment.createFromInputFallback = function (config) {
30609 throw new Error('input not handled by moment: ' + config._i);
30610 };
30611 setupDeprecationHandler(test, moment, 'locale');
30612 if (lifecycle && lifecycle.setup) {
30613 lifecycle.setup();
30614 }
30615 },
c58511b9 30616 afterEach : function () {
db71a655
KM
30617 moment.locale('en');
30618 teardownDeprecationHandler(test, moment, 'locale');
30619 if (lifecycle && lifecycle.teardown) {
30620 lifecycle.teardown();
30621 }
30622 }
30623 });
30624 defineCommonLocaleTests(name, -1, -1);
30625 }
30626
30627 localeModule('it');
30628
30629 test('parse', function (assert) {
30630 var tests = 'gennaio gen_febbraio feb_marzo mar_aprile apr_maggio mag_giugno giu_luglio lug_agosto ago_settembre set_ottobre ott_novembre nov_dicembre dic'.split('_'), i;
30631 function equalTest(input, mmm, i) {
30632 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
30633 }
30634 for (i = 0; i < 12; i++) {
30635 tests[i] = tests[i].split(' ');
30636 equalTest(tests[i][0], 'MMM', i);
30637 equalTest(tests[i][1], 'MMM', i);
30638 equalTest(tests[i][0], 'MMMM', i);
30639 equalTest(tests[i][1], 'MMMM', i);
30640 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
30641 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
30642 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
30643 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
30644 }
30645 });
30646
30647 test('format', function (assert) {
30648 var a = [
30649 ['dddd, MMMM Do YYYY, h:mm:ss a', 'domenica, febbraio 14º 2010, 3:25:50 pm'],
30650 ['ddd, hA', 'dom, 3PM'],
30651 ['M Mo MM MMMM MMM', '2 2º 02 febbraio feb'],
30652 ['YYYY YY', '2010 10'],
30653 ['D Do DD', '14 14º 14'],
30654 ['d do dddd ddd dd', '0 0º domenica dom do'],
30655 ['DDD DDDo DDDD', '45 45º 045'],
30656 ['w wo ww', '6 6º 06'],
30657 ['h hh', '3 03'],
30658 ['H HH', '15 15'],
30659 ['m mm', '25 25'],
30660 ['s ss', '50 50'],
30661 ['a A', 'pm PM'],
30662 ['[the] DDDo [day of the year]', 'the 45º day of the year'],
30663 ['LTS', '15:25:50'],
30664 ['L', '14/02/2010'],
30665 ['LL', '14 febbraio 2010'],
30666 ['LLL', '14 febbraio 2010 15:25'],
30667 ['LLLL', 'domenica 14 febbraio 2010 15:25'],
30668 ['l', '14/2/2010'],
30669 ['ll', '14 feb 2010'],
30670 ['lll', '14 feb 2010 15:25'],
30671 ['llll', 'dom 14 feb 2010 15:25']
30672 ],
30673 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
30674 i;
30675 for (i = 0; i < a.length; i++) {
30676 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
30677 }
30678 });
30679
30680 test('format ordinal', function (assert) {
30681 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1º', '1º');
30682 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2º', '2º');
30683 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3º', '3º');
30684 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4º', '4º');
30685 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5º', '5º');
30686 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6º', '6º');
30687 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7º', '7º');
30688 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8º', '8º');
30689 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9º', '9º');
30690 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10º', '10º');
30691
30692 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11º', '11º');
30693 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12º', '12º');
30694 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13º', '13º');
30695 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14º', '14º');
30696 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15º', '15º');
30697 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16º', '16º');
30698 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17º', '17º');
30699 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18º', '18º');
30700 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19º', '19º');
30701 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20º', '20º');
30702
30703 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21º', '21º');
30704 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22º', '22º');
30705 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23º', '23º');
30706 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24º', '24º');
30707 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25º', '25º');
30708 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26º', '26º');
30709 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27º', '27º');
30710 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28º', '28º');
30711 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29º', '29º');
30712 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30º', '30º');
30713
30714 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31º', '31º');
30715 });
30716
30717 test('format month', function (assert) {
30718 var expected = 'gennaio gen_febbraio feb_marzo mar_aprile apr_maggio mag_giugno giu_luglio lug_agosto ago_settembre set_ottobre ott_novembre nov_dicembre dic'.split('_'), i;
30719 for (i = 0; i < expected.length; i++) {
30720 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
30721 }
30722 });
30723
30724 test('format week', function (assert) {
30725 var expected = 'domenica dom do_lunedì lun lu_martedì mar ma_mercoledì mer me_giovedì gio gi_venerdì ven ve_sabato sab sa'.split('_'), i;
30726 for (i = 0; i < expected.length; i++) {
30727 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
30728 }
30729 });
30730
30731 test('from', function (assert) {
30732 var start = moment([2007, 1, 28]);
30733 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'alcuni secondi', '44 seconds = seconds');
30734 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'un minuto', '45 seconds = a minute');
30735 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'un minuto', '89 seconds = a minute');
30736 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuti', '90 seconds = 2 minutes');
30737 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuti', '44 minutes = 44 minutes');
30738 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'un\'ora', '45 minutes = an hour');
30739 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'un\'ora', '89 minutes = an hour');
30740 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ore', '90 minutes = 2 hours');
30741 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ore', '5 hours = 5 hours');
30742 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ore', '21 hours = 21 hours');
30743 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un giorno', '22 hours = a day');
30744 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un giorno', '35 hours = a day');
30745 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 giorni', '36 hours = 2 days');
30746 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un giorno', '1 day = a day');
30747 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 giorni', '5 days = 5 days');
30748 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 giorni', '25 days = 25 days');
30749 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'un mese', '26 days = a month');
30750 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'un mese', '30 days = a month');
30751 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'un mese', '43 days = a month');
30752 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mesi', '46 days = 2 months');
30753 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mesi', '75 days = 2 months');
30754 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mesi', '76 days = 3 months');
30755 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'un mese', '1 month = a month');
30756 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mesi', '5 months = 5 months');
30757 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un anno', '345 days = a year');
30758 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 anni', '548 days = 2 years');
30759 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un anno', '1 year = a year');
30760 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 anni', '5 years = 5 years');
30761 });
30762
30763 test('suffix', function (assert) {
30764 assert.equal(moment(30000).from(0), 'in alcuni secondi', 'prefix');
30765 assert.equal(moment(0).from(30000), 'alcuni secondi fa', 'suffix');
30766 });
30767
30768 test('fromNow', function (assert) {
30769 assert.equal(moment().add({s: 30}).fromNow(), 'in alcuni secondi', 'in seconds');
30770 assert.equal(moment().add({d: 5}).fromNow(), 'tra 5 giorni', 'in 5 days');
30771 });
30772
30773 test('calendar day', function (assert) {
30774 var a = moment().hours(12).minutes(0).seconds(0);
30775
30776 assert.equal(moment(a).calendar(), 'Oggi alle 12:00', 'today at the same time');
30777 assert.equal(moment(a).add({m: 25}).calendar(), 'Oggi alle 12:25', 'Now plus 25 min');
30778 assert.equal(moment(a).add({h: 1}).calendar(), 'Oggi alle 13:00', 'Now plus 1 hour');
30779 assert.equal(moment(a).add({d: 1}).calendar(), 'Domani alle 12:00', 'tomorrow at the same time');
30780 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Oggi alle 11:00', 'Now minus 1 hour');
30781 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Ieri alle 12:00', 'yesterday at the same time');
30782 });
30783
30784 test('calendar next week', function (assert) {
30785 var i, m;
30786 for (i = 2; i < 7; i++) {
30787 m = moment().add({d: i});
30788 assert.equal(m.calendar(), m.format('dddd [alle] LT'), 'Today + ' + i + ' days current time');
30789 m.hours(0).minutes(0).seconds(0).milliseconds(0);
30790 assert.equal(m.calendar(), m.format('dddd [alle] LT'), 'Today + ' + i + ' days beginning of day');
30791 m.hours(23).minutes(59).seconds(59).milliseconds(999);
30792 assert.equal(m.calendar(), m.format('dddd [alle] LT'), 'Today + ' + i + ' days end of day');
30793 }
30794 });
30795
30796 test('calendar last week', function (assert) {
30797 var i, m, weekday, datestring;
30798 for (i = 2; i < 7; i++) {
30799 m = moment().subtract({d: i});
30800 // Different date string
30801 weekday = parseInt(m.format('d'), 10);
30802 datestring = (weekday === 0) ? '[la scorsa] dddd [alle] LT' : '[lo scorso] dddd [alle] LT';
30803 assert.equal(m.calendar(), m.format(datestring), 'Today - ' + i + ' days current time');
30804 m.hours(0).minutes(0).seconds(0).milliseconds(0);
30805 assert.equal(m.calendar(), m.format(datestring), 'Today - ' + i + ' days beginning of day');
30806 m.hours(23).minutes(59).seconds(59).milliseconds(999);
30807 assert.equal(m.calendar(), m.format(datestring), 'Today - ' + i + ' days end of day');
30808 }
30809 });
30810
30811 test('calendar all else', function (assert) {
30812 var weeksAgo = moment().subtract({w: 1}),
30813 weeksFromNow = moment().add({w: 1});
30814
30815 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
30816 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
30817
30818 weeksAgo = moment().subtract({w: 2});
30819 weeksFromNow = moment().add({w: 2});
30820
30821 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
30822 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
30823 });
30824
30825 test('weeks year starting sunday formatted', function (assert) {
30826 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52º', 'Jan 1 2012 should be week 52');
30827 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1º', 'Jan 2 2012 should be week 1');
30828 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1º', 'Jan 8 2012 should be week 1');
30829 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2º', 'Jan 9 2012 should be week 2');
30830 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2º', 'Jan 15 2012 should be week 2');
30831 });
30832
30833})));
30834
30835
30836;(function (global, factory) {
30837 typeof exports === 'object' && typeof module !== 'undefined'
30838 && typeof require === 'function' ? factory(require('../../moment')) :
30839 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
30840 factory(global.moment)
30841}(this, (function (moment) { 'use strict';
30842
30843 function each(array, callback) {
30844 var i;
30845 for (i = 0; i < array.length; i++) {
30846 callback(array[i], i, array);
30847 }
30848 }
30849
c58511b9
KM
30850 function setupDeprecationHandler(test, moment$$1, scope) {
30851 test._expectedDeprecations = null;
30852 test._observedDeprecations = null;
30853 test._oldSupress = moment$$1.suppressDeprecationWarnings;
30854 moment$$1.suppressDeprecationWarnings = true;
30855 test.expectedDeprecations = function () {
30856 test._expectedDeprecations = arguments;
30857 test._observedDeprecations = [];
30858 };
30859 moment$$1.deprecationHandler = function (name, msg) {
30860 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
30861 if (deprecationId === -1) {
30862 throw new Error('Unexpected deprecation thrown name=' +
30863 name + ' msg=' + msg);
30864 }
30865 test._observedDeprecations[deprecationId] = 1;
30866 };
30867 }
30868
30869 function teardownDeprecationHandler(test, moment$$1, scope) {
30870 moment$$1.suppressDeprecationWarnings = test._oldSupress;
30871
30872 if (test._expectedDeprecations != null) {
30873 var missedDeprecations = [];
30874 each(test._expectedDeprecations, function (deprecationPattern, id) {
30875 if (test._observedDeprecations[id] !== 1) {
30876 missedDeprecations.push(deprecationPattern);
30877 }
30878 });
30879 if (missedDeprecations.length !== 0) {
30880 throw new Error('Expected deprecation warnings did not happen: ' +
30881 missedDeprecations.join(' '));
30882 }
30883 }
30884 }
30885
30886 function matchedDeprecation(name, msg, deprecations) {
30887 if (deprecations == null) {
30888 return -1;
30889 }
30890 for (var i = 0; i < deprecations.length; ++i) {
30891 if (name != null && name === deprecations[i]) {
30892 return i;
30893 }
30894 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
30895 return i;
30896 }
30897 }
30898 return -1;
30899 }
30900
30901 /*global QUnit:false*/
30902
30903 var test = QUnit.test;
30904
db71a655
KM
30905 function objectKeys(obj) {
30906 if (Object.keys) {
30907 return Object.keys(obj);
30908 } else {
30909 // IE8
30910 var res = [], i;
30911 for (i in obj) {
30912 if (obj.hasOwnProperty(i)) {
30913 res.push(i);
30914 }
30915 }
30916 return res;
30917 }
30918 }
30919
30920 // Pick the first defined of two or three arguments.
30921
30922 function defineCommonLocaleTests(locale, options) {
30923 test('lenient day of month ordinal parsing', function (assert) {
30924 var i, ordinalStr, testMoment;
30925 for (i = 1; i <= 31; ++i) {
30926 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
30927 testMoment = moment(ordinalStr, 'YYYY MM Do');
30928 assert.equal(testMoment.year(), 2014,
30929 'lenient day of month ordinal parsing ' + i + ' year check');
30930 assert.equal(testMoment.month(), 0,
30931 'lenient day of month ordinal parsing ' + i + ' month check');
30932 assert.equal(testMoment.date(), i,
30933 'lenient day of month ordinal parsing ' + i + ' date check');
30934 }
30935 });
30936
30937 test('lenient day of month ordinal parsing of number', function (assert) {
30938 var i, testMoment;
30939 for (i = 1; i <= 31; ++i) {
30940 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
30941 assert.equal(testMoment.year(), 2014,
30942 'lenient day of month ordinal parsing of number ' + i + ' year check');
30943 assert.equal(testMoment.month(), 0,
30944 'lenient day of month ordinal parsing of number ' + i + ' month check');
30945 assert.equal(testMoment.date(), i,
30946 'lenient day of month ordinal parsing of number ' + i + ' date check');
30947 }
30948 });
30949
30950 test('strict day of month ordinal parsing', function (assert) {
30951 var i, ordinalStr, testMoment;
30952 for (i = 1; i <= 31; ++i) {
30953 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
30954 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
30955 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
30956 }
30957 });
30958
30959 test('meridiem invariant', function (assert) {
30960 var h, m, t1, t2;
30961 for (h = 0; h < 24; ++h) {
30962 for (m = 0; m < 60; m += 15) {
30963 t1 = moment.utc([2000, 0, 1, h, m]);
30964 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
30965 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
30966 'meridiem at ' + t1.format('HH:mm'));
30967 }
30968 }
30969 });
30970
30971 test('date format correctness', function (assert) {
30972 var data, tokens;
30973 data = moment.localeData()._longDateFormat;
30974 tokens = objectKeys(data);
30975 each(tokens, function (srchToken) {
30976 // Check each format string to make sure it does not contain any
30977 // tokens that need to be expanded.
30978 each(tokens, function (baseToken) {
30979 // strip escaped sequences
30980 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
30981 assert.equal(false, !!~format.indexOf(srchToken),
30982 'contains ' + srchToken + ' in ' + baseToken);
30983 });
30984 });
30985 });
30986
30987 test('month parsing correctness', function (assert) {
30988 var i, m;
30989
30990 if (locale === 'tr') {
30991 // I can't fix it :(
c58511b9 30992 assert.expect(0);
db71a655
KM
30993 return;
30994 }
30995 function tester(format) {
30996 var r;
30997 r = moment(m.format(format), format);
30998 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
30999 if (locale !== 'ka') {
31000 r = moment(m.format(format).toLocaleUpperCase(), format);
31001 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
31002 }
db71a655
KM
31003 r = moment(m.format(format).toLocaleLowerCase(), format);
31004 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
31005
31006 r = moment(m.format(format), format, true);
31007 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
31008 if (locale !== 'ka') {
31009 r = moment(m.format(format).toLocaleUpperCase(), format, true);
31010 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
31011 }
db71a655
KM
31012 r = moment(m.format(format).toLocaleLowerCase(), format, true);
31013 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
31014 }
31015
31016 for (i = 0; i < 12; ++i) {
31017 m = moment([2015, i, 15, 18]);
31018 tester('MMM');
31019 tester('MMM.');
31020 tester('MMMM');
31021 tester('MMMM.');
31022 }
31023 });
31024
31025 test('weekday parsing correctness', function (assert) {
31026 var i, m;
31027
96d0d679 31028 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
31029 // tr, az: There is a lower-case letter (ı), that converted to
31030 // upper then lower changes to i
31031 // ro: there is the letter ț which behaves weird under IE8
31032 // mt: letter Ħ
96d0d679 31033 // ga: month with spaces
c58511b9 31034 assert.expect(0);
db71a655
KM
31035 return;
31036 }
31037 function tester(format) {
31038 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
31039 r = moment(m.format(format), format);
31040 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
31041 if (locale !== 'ka') {
31042 r = moment(m.format(format).toLocaleUpperCase(), format);
31043 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
31044 }
db71a655
KM
31045 r = moment(m.format(format).toLocaleLowerCase(), format);
31046 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
31047 r = moment(m.format(format), format, true);
31048 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
31049 if (locale !== 'ka') {
31050 r = moment(m.format(format).toLocaleUpperCase(), format, true);
31051 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
31052 }
db71a655
KM
31053 r = moment(m.format(format).toLocaleLowerCase(), format, true);
31054 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
31055 }
31056
31057 for (i = 0; i < 7; ++i) {
31058 m = moment.utc([2015, 0, i + 1, 18]);
31059 tester('dd');
31060 tester('ddd');
31061 tester('dddd');
31062 }
31063 });
31064
31065 test('valid localeData', function (assert) {
31066 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
31067 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
31068 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
31069 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
31070 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
31071 });
96d0d679
KM
31072
31073 test('localeData weekdays can localeSort', function (assert) {
31074 var weekdays = moment().localeData().weekdays();
31075 var weekdaysShort = moment().localeData().weekdaysShort();
31076 var weekdaysMin = moment().localeData().weekdaysMin();
31077 var shift = moment().localeData()._week.dow;
31078 assert.deepEqual(
31079 moment().localeData().weekdays(true),
31080 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
31081 'weekdays should localeSort');
31082 assert.deepEqual(
31083 moment().localeData().weekdaysShort(true),
31084 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
31085 'weekdaysShort should localeSort');
31086 assert.deepEqual(
31087 moment().localeData().weekdaysMin(true),
31088 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
31089 'weekdaysMin should localeSort');
31090 });
db71a655
KM
31091 }
31092
db71a655
KM
31093 /*global QUnit:false*/
31094
db71a655
KM
31095 function localeModule (name, lifecycle) {
31096 QUnit.module('locale:' + name, {
c58511b9 31097 beforeEach : function () {
db71a655
KM
31098 moment.locale(name);
31099 moment.createFromInputFallback = function (config) {
31100 throw new Error('input not handled by moment: ' + config._i);
31101 };
31102 setupDeprecationHandler(test, moment, 'locale');
31103 if (lifecycle && lifecycle.setup) {
31104 lifecycle.setup();
31105 }
31106 },
c58511b9 31107 afterEach : function () {
db71a655
KM
31108 moment.locale('en');
31109 teardownDeprecationHandler(test, moment, 'locale');
31110 if (lifecycle && lifecycle.teardown) {
31111 lifecycle.teardown();
31112 }
31113 }
31114 });
31115 defineCommonLocaleTests(name, -1, -1);
31116 }
31117
31118 localeModule('ja');
31119
31120 test('parse', function (assert) {
31121 var tests = '1月 1月_2月 2月_3月 3月_4月 4月_5月 5月_6月 6月_7月 7月_8月 8月_9月 9月_10月 10月_11月 11月_12月 12月'.split('_'), i;
31122 function equalTest(input, mmm, i) {
31123 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
31124 }
31125 for (i = 0; i < 12; i++) {
31126 tests[i] = tests[i].split(' ');
31127 equalTest(tests[i][0], 'MMM', i);
31128 equalTest(tests[i][1], 'MMM', i);
31129 equalTest(tests[i][0], 'MMMM', i);
31130 equalTest(tests[i][1], 'MMMM', i);
31131 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
31132 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
31133 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
31134 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
31135 }
31136 });
31137
31138 test('format', function (assert) {
31139 var a = [
96d0d679 31140 ['dddd, MMMM Do YYYY, a h:mm:ss', '日曜日, 二月 14日 2010, 午後 3:25:50'],
db71a655 31141 ['ddd, Ah', '日, 午後3'],
96d0d679 31142 ['M Mo MM MMMM MMM', '2 2 02 二月 2月'],
db71a655
KM
31143 ['YYYY YY', '2010 10'],
31144 ['D Do DD', '14 14日 14'],
31145 ['d do dddd ddd dd', '0 0日 日曜日 日 日'],
31146 ['DDD DDDo DDDD', '45 45日 045'],
31147 ['w wo ww', '8 8 08'],
31148 ['h hh', '3 03'],
31149 ['H HH', '15 15'],
31150 ['m mm', '25 25'],
31151 ['s ss', '50 50'],
31152 ['a A', '午後 午後'],
31153 ['[the] DDDo [day of the year]', 'the 45日 day of the year'],
31154 ['LTS', '15:25:50'],
31155 ['L', '2010/02/14'],
31156 ['LL', '2010年2月14日'],
31157 ['LLL', '2010年2月14日 15:25'],
31158 ['LLLL', '2010年2月14日 日曜日 15:25'],
31159 ['l', '2010/02/14'],
31160 ['ll', '2010年2月14日'],
31161 ['lll', '2010年2月14日 15:25'],
31162 ['llll', '2010年2月14日(日) 15:25']
31163 ],
31164 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
31165 i;
31166 for (i = 0; i < a.length; i++) {
31167 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
31168 }
31169 });
31170
31171 test('format month', function (assert) {
96d0d679 31172 var expected = '一月 1月_二月 2月_三月 3月_四月 4月_五月 5月_六月 6月_七月 7月_八月 8月_九月 9月_十月 10月_十一月 11月_十二月 12月'.split('_'), i;
db71a655
KM
31173 for (i = 0; i < expected.length; i++) {
31174 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
31175 }
31176 });
31177
31178 test('format week', function (assert) {
31179 var expected = '日曜日 日 日_月曜日 月 月_火曜日 火 火_水曜日 水 水_木曜日 木 木_金曜日 金 金_土曜日 土 土'.split('_'), i;
31180 for (i = 0; i < expected.length; i++) {
31181 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
31182 }
31183 });
31184
31185 test('from', function (assert) {
31186 var start = moment([2007, 1, 28]);
31187 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), '数秒', '44 seconds = a few seconds');
31188 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '1分', '45 seconds = a minute');
31189 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '1分', '89 seconds = a minute');
31190 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2分', '90 seconds = 2 minutes');
31191 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44分', '44 minutes = 44 minutes');
31192 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '1時間', '45 minutes = an hour');
31193 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '1時間', '89 minutes = an hour');
31194 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2時間', '90 minutes = 2 hours');
31195 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5時間', '5 hours = 5 hours');
31196 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21時間', '21 hours = 21 hours');
31197 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '1日', '22 hours = a day');
31198 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '1日', '35 hours = a day');
31199 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2日', '36 hours = 2 days');
31200 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '1日', '1 day = a day');
31201 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5日', '5 days = 5 days');
31202 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25日', '25 days = 25 days');
31203 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '1ヶ月', '26 days = a month');
31204 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '1ヶ月', '30 days = a month');
31205 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '1ヶ月', '43 days = a month');
31206 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2ヶ月', '46 days = 2 months');
31207 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2ヶ月', '75 days = 2 months');
31208 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3ヶ月', '76 days = 3 months');
31209 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '1ヶ月', '1 month = a month');
31210 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5ヶ月', '5 months = 5 months');
31211 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '1年', '345 days = a year');
31212 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2年', '548 days = 2 years');
31213 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '1年', '1 year = a year');
31214 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5年', '5 years = 5 years');
31215 });
31216
31217 test('suffix', function (assert) {
31218 assert.equal(moment(30000).from(0), '数秒後', 'prefix');
31219 assert.equal(moment(0).from(30000), '数秒前', 'suffix');
31220 });
31221
31222 test('now from now', function (assert) {
31223 assert.equal(moment().fromNow(), '数秒前', 'now from now should display as in the past');
31224 });
31225
31226 test('fromNow', function (assert) {
31227 assert.equal(moment().add({s: 30}).fromNow(), '数秒後', 'in a few seconds');
31228 assert.equal(moment().add({d: 5}).fromNow(), '5日後', 'in 5 days');
31229 });
31230
31231 test('calendar day', function (assert) {
31232 var a = moment().hours(12).minutes(0).seconds(0);
31233
31234 assert.equal(moment(a).calendar(), '今日 12:00', 'today at the same time');
31235 assert.equal(moment(a).add({m: 25}).calendar(), '今日 12:25', 'Now plus 25 min');
31236 assert.equal(moment(a).add({h: 1}).calendar(), '今日 13:00', 'Now plus 1 hour');
31237 assert.equal(moment(a).add({d: 1}).calendar(), '明日 12:00', 'tomorrow at the same time');
31238 assert.equal(moment(a).subtract({h: 1}).calendar(), '今日 11:00', 'Now minus 1 hour');
31239 assert.equal(moment(a).subtract({d: 1}).calendar(), '昨日 12:00', 'yesterday at the same time');
31240 });
31241
31242 test('calendar next week', function (assert) {
31243 var i, m;
31244 var dow = moment().day();
31245 for (i = 2; i < 7; i++) {
31246 m = moment().add({d: i});
31247 if (dow + i < 7) {
31248 assert.equal(m.calendar(), m.format('dddd LT'), 'Today + ' + i + ' days current time');
31249 m.hours(0).minutes(0).seconds(0).milliseconds(0);
31250 assert.equal(m.calendar(), m.format('dddd LT'), 'Today + ' + i + ' days beginning of day');
31251 m.hours(23).minutes(59).seconds(59).milliseconds(999);
31252 assert.equal(m.calendar(), m.format('dddd LT'), 'Today + ' + i + ' days end of day');
31253 } else {
31254 assert.equal(m.calendar(), m.format('[来週]dddd LT'), 'Today + ' + i + ' days current time');
31255 m.hours(0).minutes(0).seconds(0).milliseconds(0);
31256 assert.equal(m.calendar(), m.format('[来週]dddd LT'), 'Today + ' + i + ' days beginning of day');
31257 m.hours(23).minutes(59).seconds(59).milliseconds(999);
31258 assert.equal(m.calendar(), m.format('[来週]dddd LT'), 'Today + ' + i + ' days end of day');
31259 }
31260 }
31261 });
31262
31263 test('calendar last week', function (assert) {
31264 var i, m;
31265 var dow = moment().day();
31266 for (i = 2; i < 7; i++) {
31267 m = moment().subtract({d: i});
31268 if (dow < i) {
31269 assert.equal(m.calendar(), m.format('[先週]dddd LT'), 'Today - ' + i + ' days current time');
31270 m.hours(0).minutes(0).seconds(0).milliseconds(0);
31271 assert.equal(m.calendar(), m.format('[先週]dddd LT'), 'Today - ' + i + ' days beginning of day');
31272 m.hours(23).minutes(59).seconds(59).milliseconds(999);
31273 assert.equal(m.calendar(), m.format('[先週]dddd LT'), 'Today - ' + i + ' days end of day');
31274 } else {
31275 assert.equal(m.calendar(), m.format('dddd LT'), 'Today - ' + i + ' days current time');
31276 m.hours(0).minutes(0).seconds(0).milliseconds(0);
31277 assert.equal(m.calendar(), m.format('dddd LT'), 'Today - ' + i + ' days beginning of day');
31278 m.hours(23).minutes(59).seconds(59).milliseconds(999);
31279 assert.equal(m.calendar(), m.format('dddd LT'), 'Today - ' + i + ' days end of day');
31280 }
31281 }
31282 });
31283
31284 test('calendar all else', function (assert) {
31285 var weeksAgo = moment().subtract({w: 1}),
31286 weeksFromNow = moment().add({w: 1});
31287
31288 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
31289 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
31290
31291 weeksAgo = moment().subtract({w: 2});
31292 weeksFromNow = moment().add({w: 2});
31293
31294 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
31295 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
31296 });
31297
31298 test('weeks year starting sunday format', function (assert) {
31299 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1');
31300 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1', 'Jan 7 2012 should be week 1');
31301 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2');
31302 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2', 'Jan 14 2012 should be week 2');
31303 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', 'Jan 15 2012 should be week 3');
31304 });
31305
31306 test('parse with japanese parentheses', function (assert) {
31307 assert.ok(moment('2016年5月18日(水)', 'YYYY年M月D日(dd)', true).isValid(), 'parse with japanese parentheses');
31308 });
31309
31310})));
31311
31312
31313;(function (global, factory) {
31314 typeof exports === 'object' && typeof module !== 'undefined'
31315 && typeof require === 'function' ? factory(require('../../moment')) :
31316 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
31317 factory(global.moment)
31318}(this, (function (moment) { 'use strict';
31319
31320 function each(array, callback) {
31321 var i;
31322 for (i = 0; i < array.length; i++) {
31323 callback(array[i], i, array);
31324 }
31325 }
31326
c58511b9
KM
31327 function setupDeprecationHandler(test, moment$$1, scope) {
31328 test._expectedDeprecations = null;
31329 test._observedDeprecations = null;
31330 test._oldSupress = moment$$1.suppressDeprecationWarnings;
31331 moment$$1.suppressDeprecationWarnings = true;
31332 test.expectedDeprecations = function () {
31333 test._expectedDeprecations = arguments;
31334 test._observedDeprecations = [];
31335 };
31336 moment$$1.deprecationHandler = function (name, msg) {
31337 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
31338 if (deprecationId === -1) {
31339 throw new Error('Unexpected deprecation thrown name=' +
31340 name + ' msg=' + msg);
31341 }
31342 test._observedDeprecations[deprecationId] = 1;
31343 };
31344 }
31345
31346 function teardownDeprecationHandler(test, moment$$1, scope) {
31347 moment$$1.suppressDeprecationWarnings = test._oldSupress;
31348
31349 if (test._expectedDeprecations != null) {
31350 var missedDeprecations = [];
31351 each(test._expectedDeprecations, function (deprecationPattern, id) {
31352 if (test._observedDeprecations[id] !== 1) {
31353 missedDeprecations.push(deprecationPattern);
31354 }
31355 });
31356 if (missedDeprecations.length !== 0) {
31357 throw new Error('Expected deprecation warnings did not happen: ' +
31358 missedDeprecations.join(' '));
31359 }
31360 }
31361 }
31362
31363 function matchedDeprecation(name, msg, deprecations) {
31364 if (deprecations == null) {
31365 return -1;
31366 }
31367 for (var i = 0; i < deprecations.length; ++i) {
31368 if (name != null && name === deprecations[i]) {
31369 return i;
31370 }
31371 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
31372 return i;
31373 }
31374 }
31375 return -1;
31376 }
31377
31378 /*global QUnit:false*/
31379
31380 var test = QUnit.test;
31381
db71a655
KM
31382 function objectKeys(obj) {
31383 if (Object.keys) {
31384 return Object.keys(obj);
31385 } else {
31386 // IE8
31387 var res = [], i;
31388 for (i in obj) {
31389 if (obj.hasOwnProperty(i)) {
31390 res.push(i);
31391 }
31392 }
31393 return res;
31394 }
31395 }
31396
31397 // Pick the first defined of two or three arguments.
31398
31399 function defineCommonLocaleTests(locale, options) {
31400 test('lenient day of month ordinal parsing', function (assert) {
31401 var i, ordinalStr, testMoment;
31402 for (i = 1; i <= 31; ++i) {
31403 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
31404 testMoment = moment(ordinalStr, 'YYYY MM Do');
31405 assert.equal(testMoment.year(), 2014,
31406 'lenient day of month ordinal parsing ' + i + ' year check');
31407 assert.equal(testMoment.month(), 0,
31408 'lenient day of month ordinal parsing ' + i + ' month check');
31409 assert.equal(testMoment.date(), i,
31410 'lenient day of month ordinal parsing ' + i + ' date check');
31411 }
31412 });
31413
31414 test('lenient day of month ordinal parsing of number', function (assert) {
31415 var i, testMoment;
31416 for (i = 1; i <= 31; ++i) {
31417 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
31418 assert.equal(testMoment.year(), 2014,
31419 'lenient day of month ordinal parsing of number ' + i + ' year check');
31420 assert.equal(testMoment.month(), 0,
31421 'lenient day of month ordinal parsing of number ' + i + ' month check');
31422 assert.equal(testMoment.date(), i,
31423 'lenient day of month ordinal parsing of number ' + i + ' date check');
31424 }
31425 });
31426
31427 test('strict day of month ordinal parsing', function (assert) {
31428 var i, ordinalStr, testMoment;
31429 for (i = 1; i <= 31; ++i) {
31430 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
31431 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
31432 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
31433 }
31434 });
31435
31436 test('meridiem invariant', function (assert) {
31437 var h, m, t1, t2;
31438 for (h = 0; h < 24; ++h) {
31439 for (m = 0; m < 60; m += 15) {
31440 t1 = moment.utc([2000, 0, 1, h, m]);
31441 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
31442 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
31443 'meridiem at ' + t1.format('HH:mm'));
31444 }
31445 }
31446 });
31447
31448 test('date format correctness', function (assert) {
31449 var data, tokens;
31450 data = moment.localeData()._longDateFormat;
31451 tokens = objectKeys(data);
31452 each(tokens, function (srchToken) {
31453 // Check each format string to make sure it does not contain any
31454 // tokens that need to be expanded.
31455 each(tokens, function (baseToken) {
31456 // strip escaped sequences
31457 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
31458 assert.equal(false, !!~format.indexOf(srchToken),
31459 'contains ' + srchToken + ' in ' + baseToken);
31460 });
31461 });
31462 });
31463
31464 test('month parsing correctness', function (assert) {
31465 var i, m;
31466
31467 if (locale === 'tr') {
31468 // I can't fix it :(
c58511b9 31469 assert.expect(0);
db71a655
KM
31470 return;
31471 }
31472 function tester(format) {
31473 var r;
31474 r = moment(m.format(format), format);
31475 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
31476 if (locale !== 'ka') {
31477 r = moment(m.format(format).toLocaleUpperCase(), format);
31478 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
31479 }
db71a655
KM
31480 r = moment(m.format(format).toLocaleLowerCase(), format);
31481 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
31482
31483 r = moment(m.format(format), format, true);
31484 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
31485 if (locale !== 'ka') {
31486 r = moment(m.format(format).toLocaleUpperCase(), format, true);
31487 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
31488 }
db71a655
KM
31489 r = moment(m.format(format).toLocaleLowerCase(), format, true);
31490 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
31491 }
31492
31493 for (i = 0; i < 12; ++i) {
31494 m = moment([2015, i, 15, 18]);
31495 tester('MMM');
31496 tester('MMM.');
31497 tester('MMMM');
31498 tester('MMMM.');
31499 }
31500 });
31501
31502 test('weekday parsing correctness', function (assert) {
31503 var i, m;
31504
96d0d679 31505 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
31506 // tr, az: There is a lower-case letter (ı), that converted to
31507 // upper then lower changes to i
31508 // ro: there is the letter ț which behaves weird under IE8
31509 // mt: letter Ħ
96d0d679 31510 // ga: month with spaces
c58511b9 31511 assert.expect(0);
db71a655
KM
31512 return;
31513 }
31514 function tester(format) {
31515 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
31516 r = moment(m.format(format), format);
31517 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
31518 if (locale !== 'ka') {
31519 r = moment(m.format(format).toLocaleUpperCase(), format);
31520 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
31521 }
db71a655
KM
31522 r = moment(m.format(format).toLocaleLowerCase(), format);
31523 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
31524 r = moment(m.format(format), format, true);
31525 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
31526 if (locale !== 'ka') {
31527 r = moment(m.format(format).toLocaleUpperCase(), format, true);
31528 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
31529 }
db71a655
KM
31530 r = moment(m.format(format).toLocaleLowerCase(), format, true);
31531 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
31532 }
31533
31534 for (i = 0; i < 7; ++i) {
31535 m = moment.utc([2015, 0, i + 1, 18]);
31536 tester('dd');
31537 tester('ddd');
31538 tester('dddd');
31539 }
31540 });
31541
31542 test('valid localeData', function (assert) {
31543 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
31544 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
31545 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
31546 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
31547 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
31548 });
96d0d679
KM
31549
31550 test('localeData weekdays can localeSort', function (assert) {
31551 var weekdays = moment().localeData().weekdays();
31552 var weekdaysShort = moment().localeData().weekdaysShort();
31553 var weekdaysMin = moment().localeData().weekdaysMin();
31554 var shift = moment().localeData()._week.dow;
31555 assert.deepEqual(
31556 moment().localeData().weekdays(true),
31557 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
31558 'weekdays should localeSort');
31559 assert.deepEqual(
31560 moment().localeData().weekdaysShort(true),
31561 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
31562 'weekdaysShort should localeSort');
31563 assert.deepEqual(
31564 moment().localeData().weekdaysMin(true),
31565 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
31566 'weekdaysMin should localeSort');
31567 });
db71a655
KM
31568 }
31569
db71a655
KM
31570 /*global QUnit:false*/
31571
db71a655
KM
31572 function localeModule (name, lifecycle) {
31573 QUnit.module('locale:' + name, {
c58511b9 31574 beforeEach : function () {
db71a655
KM
31575 moment.locale(name);
31576 moment.createFromInputFallback = function (config) {
31577 throw new Error('input not handled by moment: ' + config._i);
31578 };
31579 setupDeprecationHandler(test, moment, 'locale');
31580 if (lifecycle && lifecycle.setup) {
31581 lifecycle.setup();
31582 }
31583 },
c58511b9 31584 afterEach : function () {
db71a655
KM
31585 moment.locale('en');
31586 teardownDeprecationHandler(test, moment, 'locale');
31587 if (lifecycle && lifecycle.teardown) {
31588 lifecycle.teardown();
31589 }
31590 }
31591 });
31592 defineCommonLocaleTests(name, -1, -1);
31593 }
31594
31595 localeModule('jv');
31596
31597 test('parse', function (assert) {
31598 var tests = 'Januari Jan_Februari Feb_Maret Mar_April Apr_Mei Mei_Juni Jun_Juli Jul_Agustus Ags_September Sep_Oktober Okt_Nopember Nop_Desember Des'.split('_'), i;
31599 function equalTest(input, mmm, i) {
31600 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
31601 }
31602 for (i = 0; i < 12; i++) {
31603 tests[i] = tests[i].split(' ');
31604 equalTest(tests[i][0], 'MMM', i);
31605 equalTest(tests[i][1], 'MMM', i);
31606 equalTest(tests[i][0], 'MMMM', i);
31607 equalTest(tests[i][1], 'MMMM', i);
31608 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
31609 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
31610 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
31611 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
31612 }
31613 });
31614
31615 test('format', function (assert) {
31616 var a = [
31617 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Minggu, Februari 14 2010, 3:25:50 sonten'],
31618 ['ddd, hA', 'Min, 3sonten'],
31619 ['M Mo MM MMMM MMM', '2 2 02 Februari Feb'],
31620 ['YYYY YY', '2010 10'],
31621 ['D Do DD', '14 14 14'],
31622 ['d do dddd ddd dd', '0 0 Minggu Min Mg'],
31623 ['DDD DDDo DDDD', '45 45 045'],
31624 ['w wo ww', '7 7 07'],
31625 ['h hh', '3 03'],
31626 ['H HH', '15 15'],
31627 ['m mm', '25 25'],
31628 ['s ss', '50 50'],
31629 ['a A', 'sonten sonten'],
31630 ['[the] DDDo [day of the year]', 'the 45 day of the year'],
31631 ['LTS', '15.25.50'],
31632 ['L', '14/02/2010'],
31633 ['LL', '14 Februari 2010'],
31634 ['LLL', '14 Februari 2010 pukul 15.25'],
31635 ['LLLL', 'Minggu, 14 Februari 2010 pukul 15.25'],
31636 ['l', '14/2/2010'],
31637 ['ll', '14 Feb 2010'],
31638 ['lll', '14 Feb 2010 pukul 15.25'],
31639 ['llll', 'Min, 14 Feb 2010 pukul 15.25']
31640 ],
31641 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
31642 i;
31643 for (i = 0; i < a.length; i++) {
31644 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
31645 }
31646 });
31647
31648 test('format month', function (assert) {
31649 var expected = 'Januari Jan_Februari Feb_Maret Mar_April Apr_Mei Mei_Juni Jun_Juli Jul_Agustus Ags_September Sep_Oktober Okt_Nopember Nop_Desember Des'.split('_'), i;
31650 for (i = 0; i < expected.length; i++) {
31651 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
31652 }
31653 });
31654
31655 test('format week', function (assert) {
31656 var expected = 'Minggu Min Mg_Senen Sen Sn_Seloso Sel Sl_Rebu Reb Rb_Kemis Kem Km_Jemuwah Jem Jm_Septu Sep Sp'.split('_'), i;
31657 for (i = 0; i < expected.length; i++) {
31658 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
31659 }
31660 });
31661
31662 test('from', function (assert) {
31663 var start = moment([2007, 1, 28]);
31664 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'sawetawis detik', '44 seconds = a few seconds');
31665 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'setunggal menit', '45 seconds = a minute');
31666 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'setunggal menit', '89 seconds = a minute');
31667 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 menit', '90 seconds = 2 minutes');
31668 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 menit', '44 minutes = 44 minutes');
31669 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'setunggal jam', '45 minutes = an hour');
31670 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'setunggal jam', '89 minutes = an hour');
31671 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 jam', '90 minutes = 2 hours');
31672 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 jam', '5 hours = 5 hours');
31673 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 jam', '21 hours = 21 hours');
31674 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'sedinten', '22 hours = a day');
31675 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'sedinten', '35 hours = a day');
31676 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dinten', '36 hours = 2 days');
31677 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'sedinten', '1 day = a day');
31678 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dinten', '5 days = 5 days');
31679 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dinten', '25 days = 25 days');
31680 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'sewulan', '26 days = a month');
31681 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'sewulan', '30 days = a month');
31682 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'sewulan', '43 days = a month');
31683 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 wulan', '46 days = 2 months');
31684 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 wulan', '75 days = 2 months');
31685 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 wulan', '76 days = 3 months');
31686 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'sewulan', '1 month = a month');
31687 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 wulan', '5 months = 5 months');
31688 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'setaun', '345 days = a year');
31689 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 taun', '548 days = 2 years');
31690 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'setaun', '1 year = a year');
31691 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 taun', '5 years = 5 years');
31692 });
31693
31694 test('suffix', function (assert) {
31695 assert.equal(moment(30000).from(0), 'wonten ing sawetawis detik', 'prefix');
31696 assert.equal(moment(0).from(30000), 'sawetawis detik ingkang kepengker', 'suffix');
31697 });
31698
31699 test('now from now', function (assert) {
31700 assert.equal(moment().fromNow(), 'sawetawis detik ingkang kepengker', 'now from now should display as in the past');
31701 });
31702
31703 test('fromNow', function (assert) {
31704 assert.equal(moment().add({s: 30}).fromNow(), 'wonten ing sawetawis detik', 'in a few seconds');
31705 assert.equal(moment().add({d: 5}).fromNow(), 'wonten ing 5 dinten', 'in 5 days');
31706 });
31707
31708 test('calendar day', function (assert) {
31709 var a = moment().hours(12).minutes(0).seconds(0);
31710
31711 assert.equal(moment(a).calendar(), 'Dinten puniko pukul 12.00', 'today at the same time');
31712 assert.equal(moment(a).add({m: 25}).calendar(), 'Dinten puniko pukul 12.25', 'Now plus 25 min');
31713 assert.equal(moment(a).add({h: 1}).calendar(), 'Dinten puniko pukul 13.00', 'Now plus 1 hour');
31714 assert.equal(moment(a).add({d: 1}).calendar(), 'Mbenjang pukul 12.00', 'tomorrow at the same time');
31715 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Dinten puniko pukul 11.00', 'Now minus 1 hour');
31716 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Kala wingi pukul 12.00', 'yesterday at the same time');
31717 });
31718
31719 test('calendar next week', function (assert) {
31720 var i, m;
31721 for (i = 2; i < 7; i++) {
31722 m = moment().add({d: i});
31723 assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Today + ' + i + ' days current time');
31724 m.hours(0).minutes(0).seconds(0).milliseconds(0);
31725 assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Today + ' + i + ' days beginning of day');
31726 m.hours(23).minutes(59).seconds(59).milliseconds(999);
31727 assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Today + ' + i + ' days end of day');
31728 }
31729 });
31730
31731 test('calendar last week', function (assert) {
31732 var i, m;
31733 for (i = 2; i < 7; i++) {
31734 m = moment().subtract({d: i});
31735 assert.equal(m.calendar(), m.format('dddd [kepengker pukul] LT'), 'Today - ' + i + ' days current time');
31736 m.hours(0).minutes(0).seconds(0).milliseconds(0);
31737 assert.equal(m.calendar(), m.format('dddd [kepengker pukul] LT'), 'Today - ' + i + ' days beginning of day');
31738 m.hours(23).minutes(59).seconds(59).milliseconds(999);
31739 assert.equal(m.calendar(), m.format('dddd [kepengker pukul] LT'), 'Today - ' + i + ' days end of day');
31740 }
31741 });
31742
31743 test('calendar all else', function (assert) {
31744 var weeksAgo = moment().subtract({w: 1}),
31745 weeksFromNow = moment().add({w: 1});
31746
31747 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
31748 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
31749
31750 weeksAgo = moment().subtract({w: 2});
31751 weeksFromNow = moment().add({w: 2});
31752
31753 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
31754 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
31755 });
31756
31757 // Monday is the first day of the week.
31758 // The week that contains Jan 1st is the first week of the year.
31759
31760 test('weeks year starting sunday formatted', function (assert) {
31761 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1', 'Dec 26 2011 should be week 1');
31762 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1');
31763 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2', 'Jan 2 2012 should be week 2');
31764 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2');
31765 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3', 'Jan 9 2012 should be week 3');
31766 });
31767
31768})));
31769
31770
31771;(function (global, factory) {
31772 typeof exports === 'object' && typeof module !== 'undefined'
31773 && typeof require === 'function' ? factory(require('../../moment')) :
31774 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
31775 factory(global.moment)
31776}(this, (function (moment) { 'use strict';
31777
31778 function each(array, callback) {
31779 var i;
31780 for (i = 0; i < array.length; i++) {
31781 callback(array[i], i, array);
31782 }
31783 }
31784
c58511b9
KM
31785 function setupDeprecationHandler(test, moment$$1, scope) {
31786 test._expectedDeprecations = null;
31787 test._observedDeprecations = null;
31788 test._oldSupress = moment$$1.suppressDeprecationWarnings;
31789 moment$$1.suppressDeprecationWarnings = true;
31790 test.expectedDeprecations = function () {
31791 test._expectedDeprecations = arguments;
31792 test._observedDeprecations = [];
31793 };
31794 moment$$1.deprecationHandler = function (name, msg) {
31795 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
31796 if (deprecationId === -1) {
31797 throw new Error('Unexpected deprecation thrown name=' +
31798 name + ' msg=' + msg);
31799 }
31800 test._observedDeprecations[deprecationId] = 1;
31801 };
31802 }
31803
31804 function teardownDeprecationHandler(test, moment$$1, scope) {
31805 moment$$1.suppressDeprecationWarnings = test._oldSupress;
31806
31807 if (test._expectedDeprecations != null) {
31808 var missedDeprecations = [];
31809 each(test._expectedDeprecations, function (deprecationPattern, id) {
31810 if (test._observedDeprecations[id] !== 1) {
31811 missedDeprecations.push(deprecationPattern);
31812 }
31813 });
31814 if (missedDeprecations.length !== 0) {
31815 throw new Error('Expected deprecation warnings did not happen: ' +
31816 missedDeprecations.join(' '));
31817 }
31818 }
31819 }
31820
31821 function matchedDeprecation(name, msg, deprecations) {
31822 if (deprecations == null) {
31823 return -1;
31824 }
31825 for (var i = 0; i < deprecations.length; ++i) {
31826 if (name != null && name === deprecations[i]) {
31827 return i;
31828 }
31829 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
31830 return i;
31831 }
31832 }
31833 return -1;
31834 }
31835
31836 /*global QUnit:false*/
31837
31838 var test = QUnit.test;
31839
db71a655
KM
31840 function objectKeys(obj) {
31841 if (Object.keys) {
31842 return Object.keys(obj);
31843 } else {
31844 // IE8
31845 var res = [], i;
31846 for (i in obj) {
31847 if (obj.hasOwnProperty(i)) {
31848 res.push(i);
31849 }
31850 }
31851 return res;
31852 }
31853 }
31854
31855 // Pick the first defined of two or three arguments.
31856
31857 function defineCommonLocaleTests(locale, options) {
31858 test('lenient day of month ordinal parsing', function (assert) {
31859 var i, ordinalStr, testMoment;
31860 for (i = 1; i <= 31; ++i) {
31861 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
31862 testMoment = moment(ordinalStr, 'YYYY MM Do');
31863 assert.equal(testMoment.year(), 2014,
31864 'lenient day of month ordinal parsing ' + i + ' year check');
31865 assert.equal(testMoment.month(), 0,
31866 'lenient day of month ordinal parsing ' + i + ' month check');
31867 assert.equal(testMoment.date(), i,
31868 'lenient day of month ordinal parsing ' + i + ' date check');
31869 }
31870 });
31871
31872 test('lenient day of month ordinal parsing of number', function (assert) {
31873 var i, testMoment;
31874 for (i = 1; i <= 31; ++i) {
31875 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
31876 assert.equal(testMoment.year(), 2014,
31877 'lenient day of month ordinal parsing of number ' + i + ' year check');
31878 assert.equal(testMoment.month(), 0,
31879 'lenient day of month ordinal parsing of number ' + i + ' month check');
31880 assert.equal(testMoment.date(), i,
31881 'lenient day of month ordinal parsing of number ' + i + ' date check');
31882 }
31883 });
31884
31885 test('strict day of month ordinal parsing', function (assert) {
31886 var i, ordinalStr, testMoment;
31887 for (i = 1; i <= 31; ++i) {
31888 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
31889 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
31890 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
31891 }
31892 });
31893
31894 test('meridiem invariant', function (assert) {
31895 var h, m, t1, t2;
31896 for (h = 0; h < 24; ++h) {
31897 for (m = 0; m < 60; m += 15) {
31898 t1 = moment.utc([2000, 0, 1, h, m]);
31899 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
31900 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
31901 'meridiem at ' + t1.format('HH:mm'));
31902 }
31903 }
31904 });
31905
31906 test('date format correctness', function (assert) {
31907 var data, tokens;
31908 data = moment.localeData()._longDateFormat;
31909 tokens = objectKeys(data);
31910 each(tokens, function (srchToken) {
31911 // Check each format string to make sure it does not contain any
31912 // tokens that need to be expanded.
31913 each(tokens, function (baseToken) {
31914 // strip escaped sequences
31915 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
31916 assert.equal(false, !!~format.indexOf(srchToken),
31917 'contains ' + srchToken + ' in ' + baseToken);
31918 });
31919 });
31920 });
31921
31922 test('month parsing correctness', function (assert) {
31923 var i, m;
31924
31925 if (locale === 'tr') {
31926 // I can't fix it :(
c58511b9 31927 assert.expect(0);
db71a655
KM
31928 return;
31929 }
31930 function tester(format) {
31931 var r;
31932 r = moment(m.format(format), format);
31933 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
31934 if (locale !== 'ka') {
31935 r = moment(m.format(format).toLocaleUpperCase(), format);
31936 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
31937 }
db71a655
KM
31938 r = moment(m.format(format).toLocaleLowerCase(), format);
31939 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
31940
31941 r = moment(m.format(format), format, true);
31942 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
31943 if (locale !== 'ka') {
31944 r = moment(m.format(format).toLocaleUpperCase(), format, true);
31945 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
31946 }
db71a655
KM
31947 r = moment(m.format(format).toLocaleLowerCase(), format, true);
31948 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
31949 }
31950
31951 for (i = 0; i < 12; ++i) {
31952 m = moment([2015, i, 15, 18]);
31953 tester('MMM');
31954 tester('MMM.');
31955 tester('MMMM');
31956 tester('MMMM.');
31957 }
31958 });
31959
31960 test('weekday parsing correctness', function (assert) {
31961 var i, m;
31962
96d0d679 31963 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
31964 // tr, az: There is a lower-case letter (ı), that converted to
31965 // upper then lower changes to i
31966 // ro: there is the letter ț which behaves weird under IE8
31967 // mt: letter Ħ
96d0d679 31968 // ga: month with spaces
c58511b9 31969 assert.expect(0);
db71a655
KM
31970 return;
31971 }
31972 function tester(format) {
31973 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
31974 r = moment(m.format(format), format);
31975 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
31976 if (locale !== 'ka') {
31977 r = moment(m.format(format).toLocaleUpperCase(), format);
31978 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
31979 }
db71a655
KM
31980 r = moment(m.format(format).toLocaleLowerCase(), format);
31981 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
31982 r = moment(m.format(format), format, true);
31983 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
31984 if (locale !== 'ka') {
31985 r = moment(m.format(format).toLocaleUpperCase(), format, true);
31986 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
31987 }
db71a655
KM
31988 r = moment(m.format(format).toLocaleLowerCase(), format, true);
31989 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
31990 }
31991
31992 for (i = 0; i < 7; ++i) {
31993 m = moment.utc([2015, 0, i + 1, 18]);
31994 tester('dd');
31995 tester('ddd');
31996 tester('dddd');
31997 }
31998 });
31999
32000 test('valid localeData', function (assert) {
32001 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
32002 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
32003 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
32004 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
32005 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
32006 });
96d0d679
KM
32007
32008 test('localeData weekdays can localeSort', function (assert) {
32009 var weekdays = moment().localeData().weekdays();
32010 var weekdaysShort = moment().localeData().weekdaysShort();
32011 var weekdaysMin = moment().localeData().weekdaysMin();
32012 var shift = moment().localeData()._week.dow;
32013 assert.deepEqual(
32014 moment().localeData().weekdays(true),
32015 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
32016 'weekdays should localeSort');
32017 assert.deepEqual(
32018 moment().localeData().weekdaysShort(true),
32019 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
32020 'weekdaysShort should localeSort');
32021 assert.deepEqual(
32022 moment().localeData().weekdaysMin(true),
32023 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
32024 'weekdaysMin should localeSort');
32025 });
db71a655
KM
32026 }
32027
db71a655
KM
32028 /*global QUnit:false*/
32029
db71a655
KM
32030 function localeModule (name, lifecycle) {
32031 QUnit.module('locale:' + name, {
c58511b9 32032 beforeEach : function () {
db71a655
KM
32033 moment.locale(name);
32034 moment.createFromInputFallback = function (config) {
32035 throw new Error('input not handled by moment: ' + config._i);
32036 };
32037 setupDeprecationHandler(test, moment, 'locale');
32038 if (lifecycle && lifecycle.setup) {
32039 lifecycle.setup();
32040 }
32041 },
c58511b9 32042 afterEach : function () {
db71a655
KM
32043 moment.locale('en');
32044 teardownDeprecationHandler(test, moment, 'locale');
32045 if (lifecycle && lifecycle.teardown) {
32046 lifecycle.teardown();
32047 }
32048 }
32049 });
32050 defineCommonLocaleTests(name, -1, -1);
32051 }
32052
32053 localeModule('ka');
32054
32055 test('parse', function (assert) {
32056 var i,
32057 tests = 'იანვარი იან_თებერვალი თებ_მარტი მარ_აპრილი აპრ_მაისი მაი_ივნისი ივნ_ივლისი ივლ_აგვისტო აგვ_სექტემბერი სექ_ოქტომბერი ოქტ_ნოემბერი ნოე_დეკემბერი დეკ'.split('_');
32058
32059 function equalTest(input, mmm, i) {
b8f4fe2b 32060 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
db71a655
KM
32061 }
32062
32063 for (i = 0; i < 12; i++) {
32064 tests[i] = tests[i].split(' ');
32065 equalTest(tests[i][0], 'MMM', i);
32066 equalTest(tests[i][1], 'MMM', i);
32067 equalTest(tests[i][0], 'MMMM', i);
32068 equalTest(tests[i][1], 'MMMM', i);
32069 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
32070 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
b8f4fe2b
KM
32071 // the last two are broken until https://github.com/nodejs/node/issues/22518 is fixed
32072 // equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
32073 // equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
db71a655
KM
32074 }
32075 });
32076
32077 test('format', function (assert) {
32078 var a = [
32079 ['dddd, MMMM Do YYYY, h:mm:ss a', 'კვირა, თებერვალი მე-14 2010, 3:25:50 pm'],
32080 ['ddd, hA', 'კვი, 3PM'],
32081 ['M Mo MM MMMM MMM', '2 მე-2 02 თებერვალი თებ'],
32082 ['YYYY YY', '2010 10'],
32083 ['D Do DD', '14 მე-14 14'],
32084 ['d do dddd ddd dd', '0 0 კვირა კვი კვ'],
32085 ['DDD DDDo DDDD', '45 45-ე 045'],
32086 ['w wo ww', '7 მე-7 07'],
32087 ['h hh', '3 03'],
32088 ['H HH', '15 15'],
32089 ['m mm', '25 25'],
32090 ['s ss', '50 50'],
32091 ['a A', 'pm PM'],
32092 ['წლის DDDo დღე', 'წლის 45-ე დღე'],
32093 ['LTS', '3:25:50 PM'],
32094 ['L', '14/02/2010'],
32095 ['LL', '14 თებერვალს 2010'],
32096 ['LLL', '14 თებერვალს 2010 3:25 PM'],
32097 ['LLLL', 'კვირა, 14 თებერვალს 2010 3:25 PM'],
32098 ['l', '14/2/2010'],
32099 ['ll', '14 თებ 2010'],
32100 ['lll', '14 თებ 2010 3:25 PM'],
32101 ['llll', 'კვი, 14 თებ 2010 3:25 PM']
32102 ],
32103 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
32104 i;
32105
32106 for (i = 0; i < a.length; i++) {
32107 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
32108 }
32109 });
32110
32111 test('format ordinal', function (assert) {
32112 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-ლი', '1-ლი');
32113 assert.equal(moment([2011, 0, 2]).format('DDDo'), 'მე-2', 'მე-2');
32114 assert.equal(moment([2011, 0, 3]).format('DDDo'), 'მე-3', 'მე-3');
32115 assert.equal(moment([2011, 0, 4]).format('DDDo'), 'მე-4', 'მე-4');
32116 assert.equal(moment([2011, 0, 5]).format('DDDo'), 'მე-5', 'მე-5');
32117 assert.equal(moment([2011, 0, 6]).format('DDDo'), 'მე-6', 'მე-6');
32118 assert.equal(moment([2011, 0, 7]).format('DDDo'), 'მე-7', 'მე-7');
32119 assert.equal(moment([2011, 0, 8]).format('DDDo'), 'მე-8', 'მე-8');
32120 assert.equal(moment([2011, 0, 9]).format('DDDo'), 'მე-9', 'მე-9');
32121 assert.equal(moment([2011, 0, 10]).format('DDDo'), 'მე-10', 'მე-10');
32122
32123 assert.equal(moment([2011, 0, 11]).format('DDDo'), 'მე-11', 'მე-11');
32124 assert.equal(moment([2011, 0, 12]).format('DDDo'), 'მე-12', 'მე-12');
32125 assert.equal(moment([2011, 0, 13]).format('DDDo'), 'მე-13', 'მე-13');
32126 assert.equal(moment([2011, 0, 14]).format('DDDo'), 'მე-14', 'მე-14');
32127 assert.equal(moment([2011, 0, 15]).format('DDDo'), 'მე-15', 'მე-15');
32128 assert.equal(moment([2011, 0, 16]).format('DDDo'), 'მე-16', 'მე-16');
32129 assert.equal(moment([2011, 0, 17]).format('DDDo'), 'მე-17', 'მე-17');
32130 assert.equal(moment([2011, 0, 18]).format('DDDo'), 'მე-18', 'მე-18');
32131 assert.equal(moment([2011, 0, 19]).format('DDDo'), 'მე-19', 'მე-19');
32132 assert.equal(moment([2011, 0, 20]).format('DDDo'), 'მე-20', 'მე-20');
32133
32134 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-ე', '21-ე');
32135 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-ე', '22-ე');
32136 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-ე', '23-ე');
32137 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-ე', '24-ე');
32138 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-ე', '25-ე');
32139 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-ე', '26-ე');
32140 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-ე', '27-ე');
32141 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-ე', '28-ე');
32142 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-ე', '29-ე');
32143 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-ე', '30-ე');
32144
32145 assert.equal(moment('2011 40', 'YYYY DDD').format('DDDo'), 'მე-40', 'მე-40');
32146 assert.equal(moment('2011 50', 'YYYY DDD').format('DDDo'), '50-ე', '50-ე');
32147 assert.equal(moment('2011 60', 'YYYY DDD').format('DDDo'), 'მე-60', 'მე-60');
32148 assert.equal(moment('2011 100', 'YYYY DDD').format('DDDo'), 'მე-100', 'მე-100');
32149 assert.equal(moment('2011 101', 'YYYY DDD').format('DDDo'), '101-ე', '101-ე');
32150 });
32151
32152 test('format month', function (assert) {
32153 var i,
32154 expected = 'იანვარი იან_თებერვალი თებ_მარტი მარ_აპრილი აპრ_მაისი მაი_ივნისი ივნ_ივლისი ივლ_აგვისტო აგვ_სექტემბერი სექ_ოქტომბერი ოქტ_ნოემბერი ნოე_დეკემბერი დეკ'.split('_');
32155
32156 for (i = 0; i < expected.length; i++) {
32157 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
32158 }
32159 });
32160
32161 test('format week', function (assert) {
32162 var i,
32163 expected = 'კვირა კვი კვ_ორშაბათი ორშ ორ_სამშაბათი სამ სა_ოთხშაბათი ოთხ ოთ_ხუთშაბათი ხუთ ხუ_პარასკევი პარ პა_შაბათი შაბ შა'.split('_');
32164
32165 for (i = 0; i < expected.length; i++) {
32166 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
32167 }
32168 });
32169
32170 test('from', function (assert) {
32171 var start = moment([2007, 1, 28]);
32172
32173 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'რამდენიმე წამი', '44 წამი = რამდენიმე წამი');
32174 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'წუთი', '45 წამი = წუთი');
32175 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'წუთი', '89 წამი = წუთი');
32176 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 წუთი', '90 წამი = 2 წუთი');
32177 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 წუთი', '44 წამი = 44 წუთი');
32178 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'საათი', '45 წამი = საათი');
32179 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'საათი', '89 წამი = საათი');
32180 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 საათი', '90 წამი = 2 საათი');
32181 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 საათი', '5 საათი = 5 საათი');
32182 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 საათი', '21 საათი = 21 საათი');
32183 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'დღე', '22 საათი = დღე');
32184 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'დღე', '35 საათი = დღე');
32185 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 დღე', '36 საათი = 2 დღე');
32186 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'დღე', '1 დღე = დღე');
32187 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 დღე', '5 დღე = 5 დღე');
32188 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 დღე', '25 დღე = 25 დღე');
32189 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'თვე', '26 დღე = თვე');
32190 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'თვე', '30 დღე = თვე');
32191 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'თვე', '45 დღე = თვე');
32192 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 თვე', '46 დღე = 2 თვე');
32193 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 თვე', '75 დღე = 2 თვე');
32194 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 თვე', '76 დღე = 3 თვე');
32195 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'თვე', '1 თვე = თვე');
32196 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 თვე', '5 თვე = 5 თვე');
32197 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'წელი', '345 დღე = წელი');
32198 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 წელი', '548 დღე = 2 წელი');
32199 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'წელი', '1 წელი = წელი');
32200 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 წელი', '5 წელი = 5 წელი');
32201 });
32202
32203 test('suffix', function (assert) {
32204 assert.equal(moment(30000).from(0), 'რამდენიმე წამში', 'ში სუფიქსი');
32205 assert.equal(moment(0).from(30000), 'რამდენიმე წამის წინ', 'წინ სუფიქსი');
32206 });
32207
32208 test('now from now', function (assert) {
32209 assert.equal(moment().fromNow(), 'რამდენიმე წამის წინ', 'უნდა აჩვენოს როგორც წარსული');
32210 });
32211
32212 test('fromNow', function (assert) {
32213 assert.equal(moment().add({s: 30}).fromNow(), 'რამდენიმე წამში', 'რამდენიმე წამში');
32214 assert.equal(moment().add({d: 5}).fromNow(), '5 დღეში', '5 დღეში');
32215 });
32216
32217 test('calendar day', function (assert) {
32218 var a = moment().hours(12).minutes(0).seconds(0);
32219
32220 assert.equal(moment(a).calendar(), 'დღეს 12:00 PM-ზე', 'დღეს ამავე დროს');
32221 assert.equal(moment(a).add({m: 25}).calendar(), 'დღეს 12:25 PM-ზე', 'ახლანდელ დროს დამატებული 25 წუთი');
32222 assert.equal(moment(a).add({h: 1}).calendar(), 'დღეს 1:00 PM-ზე', 'ახლანდელ დროს დამატებული 1 საათი');
32223 assert.equal(moment(a).add({d: 1}).calendar(), 'ხვალ 12:00 PM-ზე', 'ხვალ ამავე დროს');
32224 assert.equal(moment(a).subtract({h: 1}).calendar(), 'დღეს 11:00 AM-ზე', 'ახლანდელ დროს გამოკლებული 1 საათი');
32225 assert.equal(moment(a).subtract({d: 1}).calendar(), 'გუშინ 12:00 PM-ზე', 'გუშინ ამავე დროს');
32226 });
32227
32228 test('calendar next week', function (assert) {
32229 var i, m;
32230 for (i = 2; i < 7; i++) {
32231 m = moment().add({d: i});
32232 assert.equal(m.calendar(), m.format('[შემდეგ] dddd LT[-ზე]'), 'დღეს + ' + i + ' დღე ახლანდელ დროს');
32233 m.hours(0).minutes(0).seconds(0).milliseconds(0);
32234 assert.equal(m.calendar(), m.format('[შემდეგ] dddd LT[-ზე]'), 'დღეს + ' + i + ' დღე დღის დასაწყისში');
32235 m.hours(23).minutes(59).seconds(59).milliseconds(999);
32236 assert.equal(m.calendar(), m.format('[შემდეგ] dddd LT[-ზე]'), 'დღეს + ' + i + ' დღე დღის დასასრულს');
32237 }
32238 });
32239
32240 test('calendar last week', function (assert) {
32241 var i, m;
32242 for (i = 2; i < 7; i++) {
32243 m = moment().subtract({d: i});
32244 assert.equal(m.calendar(), m.format('[წინა] dddd LT[-ზე]'), 'დღეს - ' + i + ' დღე ახლანდელ დროს');
32245 m.hours(0).minutes(0).seconds(0).milliseconds(0);
32246 assert.equal(m.calendar(), m.format('[წინა] dddd LT[-ზე]'), 'დღეს - ' + i + ' დღე დღის დასაწყისში');
32247 m.hours(23).minutes(59).seconds(59).milliseconds(999);
32248 assert.equal(m.calendar(), m.format('[წინა] dddd LT[-ზე]'), 'დღეს - ' + i + ' დღე დღის დასასრულს');
32249 }
32250 });
32251
32252 test('calendar all else', function (assert) {
32253 var weeksAgo = moment().subtract({w: 1}),
32254 weeksFromNow = moment().add({w: 1});
32255
32256 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 კვირის წინ');
32257 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), '1 კვირაში');
32258
32259 weeksAgo = moment().subtract({w: 2});
32260 weeksFromNow = moment().add({w: 2});
32261
32262 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 კვირის წინ');
32263 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), '2 კვირაში');
32264 });
32265
32266 test('weeks year starting sunday formatted', function (assert) {
32267 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-ლი', 'დეკ 26 2011 უნდა იყოს კვირა 1');
32268 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-ლი', 'იან 1 2012 უნდა იყოს კვირა 1');
32269 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 მე-2', 'იან 2 2012 უნდა იყოს კვირა 2');
32270 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 მე-2', 'იან 8 2012 უნდა იყოს კვირა 2');
32271 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 მე-3', 'იან 9 2012 უნდა იყოს კვირა 3');
32272 });
32273
32274})));
32275
32276
32277;(function (global, factory) {
32278 typeof exports === 'object' && typeof module !== 'undefined'
32279 && typeof require === 'function' ? factory(require('../../moment')) :
32280 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
32281 factory(global.moment)
32282}(this, (function (moment) { 'use strict';
32283
32284 function each(array, callback) {
32285 var i;
32286 for (i = 0; i < array.length; i++) {
32287 callback(array[i], i, array);
32288 }
32289 }
32290
c58511b9
KM
32291 function setupDeprecationHandler(test, moment$$1, scope) {
32292 test._expectedDeprecations = null;
32293 test._observedDeprecations = null;
32294 test._oldSupress = moment$$1.suppressDeprecationWarnings;
32295 moment$$1.suppressDeprecationWarnings = true;
32296 test.expectedDeprecations = function () {
32297 test._expectedDeprecations = arguments;
32298 test._observedDeprecations = [];
32299 };
32300 moment$$1.deprecationHandler = function (name, msg) {
32301 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
32302 if (deprecationId === -1) {
32303 throw new Error('Unexpected deprecation thrown name=' +
32304 name + ' msg=' + msg);
32305 }
32306 test._observedDeprecations[deprecationId] = 1;
32307 };
32308 }
32309
32310 function teardownDeprecationHandler(test, moment$$1, scope) {
32311 moment$$1.suppressDeprecationWarnings = test._oldSupress;
32312
32313 if (test._expectedDeprecations != null) {
32314 var missedDeprecations = [];
32315 each(test._expectedDeprecations, function (deprecationPattern, id) {
32316 if (test._observedDeprecations[id] !== 1) {
32317 missedDeprecations.push(deprecationPattern);
32318 }
32319 });
32320 if (missedDeprecations.length !== 0) {
32321 throw new Error('Expected deprecation warnings did not happen: ' +
32322 missedDeprecations.join(' '));
32323 }
32324 }
32325 }
32326
32327 function matchedDeprecation(name, msg, deprecations) {
32328 if (deprecations == null) {
32329 return -1;
32330 }
32331 for (var i = 0; i < deprecations.length; ++i) {
32332 if (name != null && name === deprecations[i]) {
32333 return i;
32334 }
32335 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
32336 return i;
32337 }
32338 }
32339 return -1;
32340 }
32341
32342 /*global QUnit:false*/
32343
32344 var test = QUnit.test;
32345
db71a655
KM
32346 function objectKeys(obj) {
32347 if (Object.keys) {
32348 return Object.keys(obj);
32349 } else {
32350 // IE8
32351 var res = [], i;
32352 for (i in obj) {
32353 if (obj.hasOwnProperty(i)) {
32354 res.push(i);
32355 }
32356 }
32357 return res;
32358 }
32359 }
32360
32361 // Pick the first defined of two or three arguments.
32362
32363 function defineCommonLocaleTests(locale, options) {
32364 test('lenient day of month ordinal parsing', function (assert) {
32365 var i, ordinalStr, testMoment;
32366 for (i = 1; i <= 31; ++i) {
32367 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
32368 testMoment = moment(ordinalStr, 'YYYY MM Do');
32369 assert.equal(testMoment.year(), 2014,
32370 'lenient day of month ordinal parsing ' + i + ' year check');
32371 assert.equal(testMoment.month(), 0,
32372 'lenient day of month ordinal parsing ' + i + ' month check');
32373 assert.equal(testMoment.date(), i,
32374 'lenient day of month ordinal parsing ' + i + ' date check');
32375 }
32376 });
32377
32378 test('lenient day of month ordinal parsing of number', function (assert) {
32379 var i, testMoment;
32380 for (i = 1; i <= 31; ++i) {
32381 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
32382 assert.equal(testMoment.year(), 2014,
32383 'lenient day of month ordinal parsing of number ' + i + ' year check');
32384 assert.equal(testMoment.month(), 0,
32385 'lenient day of month ordinal parsing of number ' + i + ' month check');
32386 assert.equal(testMoment.date(), i,
32387 'lenient day of month ordinal parsing of number ' + i + ' date check');
32388 }
32389 });
32390
32391 test('strict day of month ordinal parsing', function (assert) {
32392 var i, ordinalStr, testMoment;
32393 for (i = 1; i <= 31; ++i) {
32394 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
32395 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
32396 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
32397 }
32398 });
32399
32400 test('meridiem invariant', function (assert) {
32401 var h, m, t1, t2;
32402 for (h = 0; h < 24; ++h) {
32403 for (m = 0; m < 60; m += 15) {
32404 t1 = moment.utc([2000, 0, 1, h, m]);
32405 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
32406 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
32407 'meridiem at ' + t1.format('HH:mm'));
32408 }
32409 }
32410 });
32411
32412 test('date format correctness', function (assert) {
32413 var data, tokens;
32414 data = moment.localeData()._longDateFormat;
32415 tokens = objectKeys(data);
32416 each(tokens, function (srchToken) {
32417 // Check each format string to make sure it does not contain any
32418 // tokens that need to be expanded.
32419 each(tokens, function (baseToken) {
32420 // strip escaped sequences
32421 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
32422 assert.equal(false, !!~format.indexOf(srchToken),
32423 'contains ' + srchToken + ' in ' + baseToken);
32424 });
32425 });
32426 });
32427
32428 test('month parsing correctness', function (assert) {
32429 var i, m;
32430
32431 if (locale === 'tr') {
32432 // I can't fix it :(
c58511b9 32433 assert.expect(0);
db71a655
KM
32434 return;
32435 }
32436 function tester(format) {
32437 var r;
32438 r = moment(m.format(format), format);
32439 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
32440 if (locale !== 'ka') {
32441 r = moment(m.format(format).toLocaleUpperCase(), format);
32442 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
32443 }
db71a655
KM
32444 r = moment(m.format(format).toLocaleLowerCase(), format);
32445 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
32446
32447 r = moment(m.format(format), format, true);
32448 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
32449 if (locale !== 'ka') {
32450 r = moment(m.format(format).toLocaleUpperCase(), format, true);
32451 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
32452 }
db71a655
KM
32453 r = moment(m.format(format).toLocaleLowerCase(), format, true);
32454 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
32455 }
32456
32457 for (i = 0; i < 12; ++i) {
32458 m = moment([2015, i, 15, 18]);
32459 tester('MMM');
32460 tester('MMM.');
32461 tester('MMMM');
32462 tester('MMMM.');
32463 }
32464 });
32465
32466 test('weekday parsing correctness', function (assert) {
32467 var i, m;
32468
96d0d679 32469 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
32470 // tr, az: There is a lower-case letter (ı), that converted to
32471 // upper then lower changes to i
32472 // ro: there is the letter ț which behaves weird under IE8
32473 // mt: letter Ħ
96d0d679 32474 // ga: month with spaces
c58511b9 32475 assert.expect(0);
db71a655
KM
32476 return;
32477 }
32478 function tester(format) {
32479 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
32480 r = moment(m.format(format), format);
32481 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
32482 if (locale !== 'ka') {
32483 r = moment(m.format(format).toLocaleUpperCase(), format);
32484 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
32485 }
db71a655
KM
32486 r = moment(m.format(format).toLocaleLowerCase(), format);
32487 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
32488 r = moment(m.format(format), format, true);
32489 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
32490 if (locale !== 'ka') {
32491 r = moment(m.format(format).toLocaleUpperCase(), format, true);
32492 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
32493 }
db71a655
KM
32494 r = moment(m.format(format).toLocaleLowerCase(), format, true);
32495 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
32496 }
32497
32498 for (i = 0; i < 7; ++i) {
32499 m = moment.utc([2015, 0, i + 1, 18]);
32500 tester('dd');
32501 tester('ddd');
32502 tester('dddd');
32503 }
32504 });
32505
32506 test('valid localeData', function (assert) {
32507 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
32508 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
32509 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
32510 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
32511 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
32512 });
96d0d679
KM
32513
32514 test('localeData weekdays can localeSort', function (assert) {
32515 var weekdays = moment().localeData().weekdays();
32516 var weekdaysShort = moment().localeData().weekdaysShort();
32517 var weekdaysMin = moment().localeData().weekdaysMin();
32518 var shift = moment().localeData()._week.dow;
32519 assert.deepEqual(
32520 moment().localeData().weekdays(true),
32521 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
32522 'weekdays should localeSort');
32523 assert.deepEqual(
32524 moment().localeData().weekdaysShort(true),
32525 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
32526 'weekdaysShort should localeSort');
32527 assert.deepEqual(
32528 moment().localeData().weekdaysMin(true),
32529 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
32530 'weekdaysMin should localeSort');
32531 });
db71a655
KM
32532 }
32533
db71a655
KM
32534 /*global QUnit:false*/
32535
db71a655
KM
32536 function localeModule (name, lifecycle) {
32537 QUnit.module('locale:' + name, {
c58511b9 32538 beforeEach : function () {
db71a655
KM
32539 moment.locale(name);
32540 moment.createFromInputFallback = function (config) {
32541 throw new Error('input not handled by moment: ' + config._i);
32542 };
32543 setupDeprecationHandler(test, moment, 'locale');
32544 if (lifecycle && lifecycle.setup) {
32545 lifecycle.setup();
32546 }
32547 },
c58511b9 32548 afterEach : function () {
db71a655
KM
32549 moment.locale('en');
32550 teardownDeprecationHandler(test, moment, 'locale');
32551 if (lifecycle && lifecycle.teardown) {
32552 lifecycle.teardown();
32553 }
32554 }
32555 });
32556 defineCommonLocaleTests(name, -1, -1);
32557 }
32558
32559 localeModule('kk');
32560
32561 test('parse', function (assert) {
32562 var tests = 'қаңтар қаң_ақпан ақп_наурыз нау_сәуір сәу_мамыр мам_маусым мау_шілде шіл_тамыз там_қыркүйек қыр_қазан қаз_қараша қар_желтоқсан жел'.split('_'), i;
32563 function equalTest(input, mmm, i) {
32564 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
32565 }
32566 for (i = 0; i < 12; i++) {
32567 tests[i] = tests[i].split(' ');
32568 equalTest(tests[i][0], 'MMM', i);
32569 equalTest(tests[i][1], 'MMM', i);
32570 equalTest(tests[i][0], 'MMMM', i);
32571 equalTest(tests[i][1], 'MMMM', i);
32572 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
32573 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
32574 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
32575 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
32576 }
32577 });
32578
32579 test('format', function (assert) {
32580 var a = [
32581 ['dddd, Do MMMM YYYY, HH:mm:ss', 'жексенбі, 14-ші ақпан 2010, 15:25:50'],
32582 ['ddd, hA', 'жек, 3PM'],
32583 ['M Mo MM MMMM MMM', '2 2-ші 02 ақпан ақп'],
32584 ['YYYY YY', '2010 10'],
32585 ['D Do DD', '14 14-ші 14'],
32586 ['d do dddd ddd dd', '0 0-ші жексенбі жек жк'],
32587 ['DDD DDDo DDDD', '45 45-ші 045'],
32588 ['w wo ww', '7 7-ші 07'],
32589 ['h hh', '3 03'],
32590 ['H HH', '15 15'],
32591 ['m mm', '25 25'],
32592 ['s ss', '50 50'],
32593 ['a A', 'pm PM'],
32594 ['[жылдың] DDDo [күні]', 'жылдың 45-ші күні'],
32595 ['LTS', '15:25:50'],
32596 ['L', '14.02.2010'],
32597 ['LL', '14 ақпан 2010'],
32598 ['LLL', '14 ақпан 2010 15:25'],
32599 ['LLLL', 'жексенбі, 14 ақпан 2010 15:25'],
32600 ['l', '14.2.2010'],
32601 ['ll', '14 ақп 2010'],
32602 ['lll', '14 ақп 2010 15:25'],
32603 ['llll', 'жек, 14 ақп 2010 15:25']
32604 ],
32605 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
32606 i;
32607 for (i = 0; i < a.length; i++) {
32608 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
32609 }
32610 });
32611
32612 test('format ordinal', function (assert) {
32613 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-ші', '1st');
32614 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-ші', '2nd');
32615 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-ші', '3rd');
32616 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-ші', '4th');
32617 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-ші', '5th');
32618 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-шы', '6th');
32619 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-ші', '7th');
32620 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-ші', '8th');
32621 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-шы', '9th');
32622 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-шы', '10th');
32623
32624 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-ші', '11th');
32625 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-ші', '12th');
32626 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-ші', '13th');
32627 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-ші', '14th');
32628 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-ші', '15th');
32629 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-шы', '16th');
32630 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-ші', '17th');
32631 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-ші', '18th');
32632 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-шы', '19th');
32633 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-шы', '20th');
32634
32635 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-ші', '21st');
32636 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-ші', '22nd');
32637 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-ші', '23rd');
32638 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-ші', '24th');
32639 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-ші', '25th');
32640 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-шы', '26th');
32641 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-ші', '27th');
32642 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-ші', '28th');
32643 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-шы', '29th');
32644 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-шы', '30th');
32645
32646 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-ші', '31st');
32647 });
32648
32649 test('format month', function (assert) {
32650 var expected = 'қаңтар қаң_ақпан ақп_наурыз нау_сәуір сәу_мамыр мам_маусым мау_шілде шіл_тамыз там_қыркүйек қыр_қазан қаз_қараша қар_желтоқсан жел'.split('_'), i;
32651 for (i = 0; i < expected.length; i++) {
32652 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
32653 }
32654 });
32655
32656 test('format week', function (assert) {
32657 var expected = 'жексенбі жек жк_дүйсенбі дүй дй_сейсенбі сей сй_сәрсенбі сәр ср_бейсенбі бей бй_жұма жұм жм_сенбі сен сн'.split('_'), i;
32658 for (i = 0; i < expected.length; i++) {
32659 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
32660 }
32661 });
32662
32663 test('from', function (assert) {
32664 var start = moment([2007, 1, 28]);
32665 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'бірнеше секунд', '44 seconds = a few seconds');
32666 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'бір минут', '45 seconds = a minute');
32667 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'бір минут', '89 seconds = a minute');
32668 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 минут', '90 seconds = 2 minutes');
32669 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 минут', '44 minutes = 44 minutes');
32670 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'бір сағат', '45 minutes = an hour');
32671 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'бір сағат', '89 minutes = an hour');
32672 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 сағат', '90 minutes = 2 hours');
32673 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 сағат', '5 hours = 5 hours');
32674 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 сағат', '21 hours = 21 hours');
32675 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'бір күн', '22 hours = a day');
32676 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'бір күн', '35 hours = a day');
32677 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 күн', '36 hours = 2 days');
32678 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'бір күн', '1 day = a day');
32679 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 күн', '5 days = 5 days');
32680 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 күн', '25 days = 25 days');
32681 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'бір ай', '26 days = a month');
32682 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'бір ай', '30 days = a month');
32683 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'бір ай', '43 days = a month');
32684 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 ай', '46 days = 2 months');
32685 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 ай', '75 days = 2 months');
32686 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 ай', '76 days = 3 months');
32687 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'бір ай', '1 month = a month');
32688 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 ай', '5 months = 5 months');
32689 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'бір жыл', '345 days = a year');
32690 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 жыл', '548 days = 2 years');
32691 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'бір жыл', '1 year = a year');
32692 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 жыл', '5 years = 5 years');
32693 });
32694
32695 test('suffix', function (assert) {
32696 assert.equal(moment(30000).from(0), 'бірнеше секунд ішінде', 'prefix');
32697 assert.equal(moment(0).from(30000), 'бірнеше секунд бұрын', 'suffix');
32698 });
32699
32700 test('now from now', function (assert) {
32701 assert.equal(moment().fromNow(), 'бірнеше секунд бұрын', 'now from now should display as in the past');
32702 });
32703
32704 test('fromNow', function (assert) {
32705 assert.equal(moment().add({s: 30}).fromNow(), 'бірнеше секунд ішінде', 'in a few seconds');
32706 assert.equal(moment().add({d: 5}).fromNow(), '5 күн ішінде', 'in 5 days');
32707 });
32708
32709 test('calendar day', function (assert) {
32710 var a = moment().hours(12).minutes(0).seconds(0);
32711
32712 assert.equal(moment(a).calendar(), 'Бүгін сағат 12:00', 'today at the same time');
32713 assert.equal(moment(a).add({m: 25}).calendar(), 'Бүгін сағат 12:25', 'Now plus 25 min');
32714 assert.equal(moment(a).add({h: 1}).calendar(), 'Бүгін сағат 13:00', 'Now plus 1 hour');
32715 assert.equal(moment(a).add({d: 1}).calendar(), 'Ертең сағат 12:00', 'tomorrow at the same time');
32716 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Бүгін сағат 11:00', 'Now minus 1 hour');
32717 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Кеше сағат 12:00', 'yesterday at the same time');
32718 });
32719
32720 test('calendar next week', function (assert) {
32721 var i, m;
32722 for (i = 2; i < 7; i++) {
32723 m = moment().add({d: i});
32724 assert.equal(m.calendar(), m.format('dddd [сағат] LT'), 'Today + ' + i + ' days current time');
32725 m.hours(0).minutes(0).seconds(0).milliseconds(0);
32726 assert.equal(m.calendar(), m.format('dddd [сағат] LT'), 'Today + ' + i + ' days beginning of day');
32727 m.hours(23).minutes(59).seconds(59).milliseconds(999);
32728 assert.equal(m.calendar(), m.format('dddd [сағат] LT'), 'Today + ' + i + ' days end of day');
32729 }
32730 });
32731
32732 test('calendar last week', function (assert) {
32733 var i, m;
32734
32735 for (i = 2; i < 7; i++) {
32736 m = moment().subtract({d: i});
32737 assert.equal(m.calendar(), m.format('[Өткен аптаның] dddd [сағат] LT'), 'Today - ' + i + ' days current time');
32738 m.hours(0).minutes(0).seconds(0).milliseconds(0);
32739 assert.equal(m.calendar(), m.format('[Өткен аптаның] dddd [сағат] LT'), 'Today - ' + i + ' days beginning of day');
32740 m.hours(23).minutes(59).seconds(59).milliseconds(999);
32741 assert.equal(m.calendar(), m.format('[Өткен аптаның] dddd [сағат] LT'), 'Today - ' + i + ' days end of day');
32742 }
32743 });
32744
32745 test('calendar all else', function (assert) {
32746 var weeksAgo = moment().subtract({w: 1}),
32747 weeksFromNow = moment().add({w: 1});
32748
32749 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
32750 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
32751
32752 weeksAgo = moment().subtract({w: 2});
32753 weeksFromNow = moment().add({w: 2});
32754
32755 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
32756 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
32757 });
32758
32759 test('weeks year starting sunday formatted', function (assert) {
32760 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-ші', 'Jan 1 2012 should be week 1');
32761 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-ші', 'Jan 2 2012 should be week 2');
32762 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-ші', 'Jan 8 2012 should be week 2');
32763 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-ші', 'Jan 9 2012 should be week 3');
32764 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3-ші', 'Jan 15 2012 should be week 3');
32765 });
32766
32767})));
32768
32769
32770;(function (global, factory) {
32771 typeof exports === 'object' && typeof module !== 'undefined'
32772 && typeof require === 'function' ? factory(require('../../moment')) :
32773 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
32774 factory(global.moment)
32775}(this, (function (moment) { 'use strict';
32776
32777 function each(array, callback) {
32778 var i;
32779 for (i = 0; i < array.length; i++) {
32780 callback(array[i], i, array);
32781 }
32782 }
32783
c58511b9
KM
32784 function setupDeprecationHandler(test, moment$$1, scope) {
32785 test._expectedDeprecations = null;
32786 test._observedDeprecations = null;
32787 test._oldSupress = moment$$1.suppressDeprecationWarnings;
32788 moment$$1.suppressDeprecationWarnings = true;
32789 test.expectedDeprecations = function () {
32790 test._expectedDeprecations = arguments;
32791 test._observedDeprecations = [];
32792 };
32793 moment$$1.deprecationHandler = function (name, msg) {
32794 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
32795 if (deprecationId === -1) {
32796 throw new Error('Unexpected deprecation thrown name=' +
32797 name + ' msg=' + msg);
32798 }
32799 test._observedDeprecations[deprecationId] = 1;
32800 };
32801 }
32802
32803 function teardownDeprecationHandler(test, moment$$1, scope) {
32804 moment$$1.suppressDeprecationWarnings = test._oldSupress;
32805
32806 if (test._expectedDeprecations != null) {
32807 var missedDeprecations = [];
32808 each(test._expectedDeprecations, function (deprecationPattern, id) {
32809 if (test._observedDeprecations[id] !== 1) {
32810 missedDeprecations.push(deprecationPattern);
32811 }
32812 });
32813 if (missedDeprecations.length !== 0) {
32814 throw new Error('Expected deprecation warnings did not happen: ' +
32815 missedDeprecations.join(' '));
32816 }
32817 }
32818 }
32819
32820 function matchedDeprecation(name, msg, deprecations) {
32821 if (deprecations == null) {
32822 return -1;
32823 }
32824 for (var i = 0; i < deprecations.length; ++i) {
32825 if (name != null && name === deprecations[i]) {
32826 return i;
32827 }
32828 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
32829 return i;
32830 }
32831 }
32832 return -1;
32833 }
32834
32835 /*global QUnit:false*/
32836
32837 var test = QUnit.test;
32838
db71a655
KM
32839 function objectKeys(obj) {
32840 if (Object.keys) {
32841 return Object.keys(obj);
32842 } else {
32843 // IE8
32844 var res = [], i;
32845 for (i in obj) {
32846 if (obj.hasOwnProperty(i)) {
32847 res.push(i);
32848 }
32849 }
32850 return res;
32851 }
32852 }
32853
32854 // Pick the first defined of two or three arguments.
32855
32856 function defineCommonLocaleTests(locale, options) {
32857 test('lenient day of month ordinal parsing', function (assert) {
32858 var i, ordinalStr, testMoment;
32859 for (i = 1; i <= 31; ++i) {
32860 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
32861 testMoment = moment(ordinalStr, 'YYYY MM Do');
32862 assert.equal(testMoment.year(), 2014,
32863 'lenient day of month ordinal parsing ' + i + ' year check');
32864 assert.equal(testMoment.month(), 0,
32865 'lenient day of month ordinal parsing ' + i + ' month check');
32866 assert.equal(testMoment.date(), i,
32867 'lenient day of month ordinal parsing ' + i + ' date check');
32868 }
32869 });
32870
32871 test('lenient day of month ordinal parsing of number', function (assert) {
32872 var i, testMoment;
32873 for (i = 1; i <= 31; ++i) {
32874 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
32875 assert.equal(testMoment.year(), 2014,
32876 'lenient day of month ordinal parsing of number ' + i + ' year check');
32877 assert.equal(testMoment.month(), 0,
32878 'lenient day of month ordinal parsing of number ' + i + ' month check');
32879 assert.equal(testMoment.date(), i,
32880 'lenient day of month ordinal parsing of number ' + i + ' date check');
32881 }
32882 });
32883
32884 test('strict day of month ordinal parsing', function (assert) {
32885 var i, ordinalStr, testMoment;
32886 for (i = 1; i <= 31; ++i) {
32887 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
32888 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
32889 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
32890 }
32891 });
32892
32893 test('meridiem invariant', function (assert) {
32894 var h, m, t1, t2;
32895 for (h = 0; h < 24; ++h) {
32896 for (m = 0; m < 60; m += 15) {
32897 t1 = moment.utc([2000, 0, 1, h, m]);
32898 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
32899 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
32900 'meridiem at ' + t1.format('HH:mm'));
32901 }
32902 }
32903 });
32904
32905 test('date format correctness', function (assert) {
32906 var data, tokens;
32907 data = moment.localeData()._longDateFormat;
32908 tokens = objectKeys(data);
32909 each(tokens, function (srchToken) {
32910 // Check each format string to make sure it does not contain any
32911 // tokens that need to be expanded.
32912 each(tokens, function (baseToken) {
32913 // strip escaped sequences
32914 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
32915 assert.equal(false, !!~format.indexOf(srchToken),
32916 'contains ' + srchToken + ' in ' + baseToken);
32917 });
32918 });
32919 });
32920
32921 test('month parsing correctness', function (assert) {
32922 var i, m;
32923
32924 if (locale === 'tr') {
32925 // I can't fix it :(
c58511b9 32926 assert.expect(0);
db71a655
KM
32927 return;
32928 }
32929 function tester(format) {
32930 var r;
32931 r = moment(m.format(format), format);
32932 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
32933 if (locale !== 'ka') {
32934 r = moment(m.format(format).toLocaleUpperCase(), format);
32935 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
32936 }
db71a655
KM
32937 r = moment(m.format(format).toLocaleLowerCase(), format);
32938 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
32939
32940 r = moment(m.format(format), format, true);
32941 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
32942 if (locale !== 'ka') {
32943 r = moment(m.format(format).toLocaleUpperCase(), format, true);
32944 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
32945 }
db71a655
KM
32946 r = moment(m.format(format).toLocaleLowerCase(), format, true);
32947 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
32948 }
32949
32950 for (i = 0; i < 12; ++i) {
32951 m = moment([2015, i, 15, 18]);
32952 tester('MMM');
32953 tester('MMM.');
32954 tester('MMMM');
32955 tester('MMMM.');
32956 }
32957 });
32958
32959 test('weekday parsing correctness', function (assert) {
32960 var i, m;
32961
96d0d679 32962 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
32963 // tr, az: There is a lower-case letter (ı), that converted to
32964 // upper then lower changes to i
32965 // ro: there is the letter ț which behaves weird under IE8
32966 // mt: letter Ħ
96d0d679 32967 // ga: month with spaces
c58511b9 32968 assert.expect(0);
db71a655
KM
32969 return;
32970 }
32971 function tester(format) {
32972 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
32973 r = moment(m.format(format), format);
32974 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
32975 if (locale !== 'ka') {
32976 r = moment(m.format(format).toLocaleUpperCase(), format);
32977 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
32978 }
db71a655
KM
32979 r = moment(m.format(format).toLocaleLowerCase(), format);
32980 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
32981 r = moment(m.format(format), format, true);
32982 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
32983 if (locale !== 'ka') {
32984 r = moment(m.format(format).toLocaleUpperCase(), format, true);
32985 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
32986 }
db71a655
KM
32987 r = moment(m.format(format).toLocaleLowerCase(), format, true);
32988 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
32989 }
32990
32991 for (i = 0; i < 7; ++i) {
32992 m = moment.utc([2015, 0, i + 1, 18]);
32993 tester('dd');
32994 tester('ddd');
32995 tester('dddd');
32996 }
32997 });
32998
32999 test('valid localeData', function (assert) {
33000 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
33001 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
33002 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
33003 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
33004 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
33005 });
96d0d679
KM
33006
33007 test('localeData weekdays can localeSort', function (assert) {
33008 var weekdays = moment().localeData().weekdays();
33009 var weekdaysShort = moment().localeData().weekdaysShort();
33010 var weekdaysMin = moment().localeData().weekdaysMin();
33011 var shift = moment().localeData()._week.dow;
33012 assert.deepEqual(
33013 moment().localeData().weekdays(true),
33014 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
33015 'weekdays should localeSort');
33016 assert.deepEqual(
33017 moment().localeData().weekdaysShort(true),
33018 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
33019 'weekdaysShort should localeSort');
33020 assert.deepEqual(
33021 moment().localeData().weekdaysMin(true),
33022 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
33023 'weekdaysMin should localeSort');
33024 });
db71a655
KM
33025 }
33026
db71a655
KM
33027 /*global QUnit:false*/
33028
db71a655
KM
33029 function localeModule (name, lifecycle) {
33030 QUnit.module('locale:' + name, {
c58511b9 33031 beforeEach : function () {
db71a655
KM
33032 moment.locale(name);
33033 moment.createFromInputFallback = function (config) {
33034 throw new Error('input not handled by moment: ' + config._i);
33035 };
33036 setupDeprecationHandler(test, moment, 'locale');
33037 if (lifecycle && lifecycle.setup) {
33038 lifecycle.setup();
33039 }
33040 },
c58511b9 33041 afterEach : function () {
db71a655
KM
33042 moment.locale('en');
33043 teardownDeprecationHandler(test, moment, 'locale');
33044 if (lifecycle && lifecycle.teardown) {
33045 lifecycle.teardown();
33046 }
33047 }
33048 });
33049 defineCommonLocaleTests(name, -1, -1);
33050 }
33051
33052 localeModule('km');
33053
33054 test('parse', function (assert) {
33055 var tests = 'មករា មករា_កុម្ភៈ កុម្ភៈ_មីនា មីនា_មេសា មេសា_ឧសភា ឧសភា_មិថុនា មិថុនា_កក្កដា កក្កដា_សីហា សីហា_កញ្ញា កញ្ញា_តុលា តុលា_វិច្ឆិកា វិច្ឆិកា_ធ្នូ ធ្នូ'.split(
33056 '_'
33057 ),
33058 i;
33059
33060 function equalTest(input, mmm, i) {
33061 assert.equal(
33062 moment(input, mmm).month(),
33063 i,
33064 input + ' should be month ' + (i + 1)
33065 );
33066 }
33067 for (i = 0; i < 12; i++) {
33068 tests[i] = tests[i].split(' ');
33069 equalTest(tests[i][0], 'MMM', i);
33070 equalTest(tests[i][1], 'MMM', i);
33071 equalTest(tests[i][0], 'MMMM', i);
33072 equalTest(tests[i][1], 'MMMM', i);
33073 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
33074 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
33075 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
33076 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
33077 }
33078 });
33079
33080 test('format', function (assert) {
33081 var a = [
33082 [
33083 'dddd, MMMM Do YYYY, h:mm:ss a',
33084 'អាទិត្យ, កុម្ភៈ ទី១៤ ២០១០, ៣:២៥:៥០ ល្ងាច'
33085 ],
33086 ['ddd, hA', 'អា, ៣ល្ងាច'],
33087 ['M Mo MM MMMM MMM', '២ ទី២ ០២ កុម្ភៈ កុម្ភៈ'],
33088 ['YYYY YY', '២០១០ ១០'],
33089 ['D Do DD', '១៤ ទី១៤ ១៤'],
33090 ['d do dddd ddd dd', '០ ទី០ អាទិត្យ អា អា'],
33091 ['DDD DDDo DDDD', '៤៥ ទី៤៥ ០៤៥'],
33092 ['w wo ww', '៦ ទី៦ ០៦'],
33093 ['h hh', '៣ ០៣'],
33094 ['H HH', '១៥ ១៥'],
33095 ['m mm', '២៥ ២៥'],
33096 ['s ss', '៥០ ៥០'],
33097 ['a A', 'ល្ងាច ល្ងាច'],
33098 ['[the] DDDo [day of the year]', 'the ទី៤៥ day of the year'],
33099 ['LTS', '១៥:២៥:៥០'],
33100 ['L', '១៤/០២/២០១០'],
33101 ['LL', '១៤ កុម្ភៈ ២០១០'],
33102 ['LLL', '១៤ កុម្ភៈ ២០១០ ១៥:២៥'],
33103 ['LLLL', 'អាទិត្យ, ១៤ កុម្ភៈ ២០១០ ១៥:២៥'],
33104 ['l', '១៤/២/២០១០'],
33105 ['ll', '១៤ កុម្ភៈ ២០១០'],
33106 ['lll', '១៤ កុម្ភៈ ២០១០ ១៥:២៥'],
33107 ['llll', 'អា, ១៤ កុម្ភៈ ២០១០ ១៥:២៥']
33108 ],
33109 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
33110 i;
33111 for (i = 0; i < a.length; i++) {
33112 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
33113 }
33114 });
33115
33116 test('format ordinal', function (assert) {
33117 assert.equal(moment([2011, 0, 1]).format('DDDo'), 'ទី១', '1st');
33118 assert.equal(moment([2011, 0, 2]).format('DDDo'), 'ទី២', '2nd');
33119 assert.equal(moment([2011, 0, 3]).format('DDDo'), 'ទី៣', '3rd');
33120 assert.equal(moment([2011, 0, 4]).format('DDDo'), 'ទី៤', '4th');
33121 assert.equal(moment([2011, 0, 5]).format('DDDo'), 'ទី៥', '5th');
33122 assert.equal(moment([2011, 0, 6]).format('DDDo'), 'ទី៦', '6th');
33123 assert.equal(moment([2011, 0, 7]).format('DDDo'), 'ទី៧', '7th');
33124 assert.equal(moment([2011, 0, 8]).format('DDDo'), 'ទី៨', '8th');
33125 assert.equal(moment([2011, 0, 9]).format('DDDo'), 'ទី៩', '9th');
33126 assert.equal(moment([2011, 0, 10]).format('DDDo'), 'ទី១០', '10th');
33127
33128 assert.equal(moment([2011, 0, 11]).format('DDDo'), 'ទី១១', '11st');
33129 assert.equal(moment([2011, 0, 12]).format('DDDo'), 'ទី១២', '12nd');
33130 assert.equal(moment([2011, 0, 13]).format('DDDo'), 'ទី១៣', '13rd');
33131 assert.equal(moment([2011, 0, 14]).format('DDDo'), 'ទី១៤', '14th');
33132 assert.equal(moment([2011, 0, 15]).format('DDDo'), 'ទី១៥', '15th');
33133 assert.equal(moment([2011, 0, 16]).format('DDDo'), 'ទី១៦', '16th');
33134 assert.equal(moment([2011, 0, 17]).format('DDDo'), 'ទី១៧', '17th');
33135 assert.equal(moment([2011, 0, 18]).format('DDDo'), 'ទី១៨', '18th');
33136 assert.equal(moment([2011, 0, 19]).format('DDDo'), 'ទី១៩', '19th');
33137 assert.equal(moment([2011, 0, 20]).format('DDDo'), 'ទី២០', '20th');
33138
33139 assert.equal(moment([2011, 0, 21]).format('DDDo'), 'ទី២១', '21st');
33140 assert.equal(moment([2011, 0, 22]).format('DDDo'), 'ទី២២', '22nd');
33141 assert.equal(moment([2011, 0, 23]).format('DDDo'), 'ទី២៣', '23rd');
33142 assert.equal(moment([2011, 0, 24]).format('DDDo'), 'ទី២៤', '24th');
33143 assert.equal(moment([2011, 0, 25]).format('DDDo'), 'ទី២៥', '25th');
33144 assert.equal(moment([2011, 0, 26]).format('DDDo'), 'ទី២៦', '26th');
33145 assert.equal(moment([2011, 0, 27]).format('DDDo'), 'ទី២៧', '27th');
33146 assert.equal(moment([2011, 0, 28]).format('DDDo'), 'ទី២៨', '28th');
33147 assert.equal(moment([2011, 0, 29]).format('DDDo'), 'ទី២៩', '29th');
33148 assert.equal(moment([2011, 0, 30]).format('DDDo'), 'ទី៣០', '30th');
33149
33150 assert.equal(moment([2011, 0, 31]).format('DDDo'), 'ទី៣១', '31st');
33151 });
33152
33153 test('format month', function (assert) {
33154 var expected = 'មករា មករា_កុម្ភៈ កុម្ភៈ_មីនា មីនា_មេសា មេសា_ឧសភា ឧសភា_មិថុនា មិថុនា_កក្កដា កក្កដា_សីហា សីហា_កញ្ញា កញ្ញា_តុលា តុលា_វិច្ឆិកា វិច្ឆិកា_ធ្នូ ធ្នូ'.split(
33155 '_'
33156 ),
33157 i;
33158 for (i = 0; i < expected.length; i++) {
33159 assert.equal(
33160 moment([2011, i, 1]).format('MMMM MMM'),
33161 expected[i],
33162 expected[i]
33163 );
33164 }
33165 });
33166
33167 test('format week', function (assert) {
33168 var expected = 'អាទិត្យ អា អា_ច័ន្ទ ច ច_អង្គារ អ អ_ពុធ ព ព_ព្រហស្បតិ៍ ព្រ ព្រ_សុក្រ សុ សុ_សៅរ៍ ស ស'.split(
33169 '_'
33170 ),
33171 i;
33172 for (i = 0; i < expected.length; i++) {
33173 assert.equal(
33174 moment([2011, 0, 2 + i]).format('dddd ddd dd'),
33175 expected[i],
33176 expected[i]
33177 );
33178 }
33179 });
33180
33181 test('from', function (assert) {
33182 var start = moment([2007, 1, 28]);
33183 assert.equal(
33184 start.from(moment([2007, 1, 28]).add({s: 44}), true),
33185 'ប៉ុន្មានវិនាទី',
33186 '44 seconds = ប៉ុន្មានវិនាទី'
33187 );
33188 assert.equal(
33189 start.from(moment([2007, 1, 28]).add({s: 45}), true),
33190 'មួយនាទី',
33191 '45 seconds = មួយនាទី'
33192 );
33193 assert.equal(
33194 start.from(moment([2007, 1, 28]).add({s: 89}), true),
33195 'មួយនាទី',
33196 '89 seconds = មួយនាទី'
33197 );
33198 assert.equal(
33199 start.from(moment([2007, 1, 28]).add({s: 90}), true),
33200 '២ នាទី',
33201 '90 seconds = 2 នាទី'
33202 );
33203 assert.equal(
33204 start.from(moment([2007, 1, 28]).add({m: 44}), true),
33205 '៤៤ នាទី',
33206 '44 minutes = 44 នាទី'
33207 );
33208 assert.equal(
33209 start.from(moment([2007, 1, 28]).add({m: 45}), true),
33210 'មួយម៉ោង',
33211 '45 minutes = មួយម៉ោង'
33212 );
33213 assert.equal(
33214 start.from(moment([2007, 1, 28]).add({m: 89}), true),
33215 'មួយម៉ោង',
33216 '89 minutes = មួយម៉ោង'
33217 );
33218 assert.equal(
33219 start.from(moment([2007, 1, 28]).add({m: 90}), true),
33220 '២ ម៉ោង',
33221 '90 minutes = 2 ម៉ោង'
33222 );
33223 assert.equal(
33224 start.from(moment([2007, 1, 28]).add({h: 5}), true),
33225 '៥ ម៉ោង',
33226 '5 hours = 5 ម៉ោង'
33227 );
33228 assert.equal(
33229 start.from(moment([2007, 1, 28]).add({h: 21}), true),
33230 '២១ ម៉ោង',
33231 '21 hours = 21 ម៉ោង'
33232 );
33233 assert.equal(
33234 start.from(moment([2007, 1, 28]).add({h: 22}), true),
33235 'មួយថ្ងៃ',
33236 '22 hours = មួយថ្ងៃ'
33237 );
33238 assert.equal(
33239 start.from(moment([2007, 1, 28]).add({h: 35}), true),
33240 'មួយថ្ងៃ',
33241 '35 hours = មួយថ្ងៃ'
33242 );
33243 assert.equal(
33244 start.from(moment([2007, 1, 28]).add({h: 36}), true),
33245 '២ ថ្ងៃ',
33246 '36 hours = 2 ថ្ងៃ'
33247 );
33248 assert.equal(
33249 start.from(moment([2007, 1, 28]).add({d: 1}), true),
33250 'មួយថ្ងៃ',
33251 '1 day = មួយថ្ងៃ'
33252 );
33253 assert.equal(
33254 start.from(moment([2007, 1, 28]).add({d: 5}), true),
33255 '៥ ថ្ងៃ',
33256 '5 days = 5 ថ្ងៃ'
33257 );
33258 assert.equal(
33259 start.from(moment([2007, 1, 28]).add({d: 25}), true),
33260 '២៥ ថ្ងៃ',
33261 '25 days = 25 ថ្ងៃ'
33262 );
33263 assert.equal(
33264 start.from(moment([2007, 1, 28]).add({d: 26}), true),
33265 'មួយខែ',
33266 '26 days = មួយខែ'
33267 );
33268 assert.equal(
33269 start.from(moment([2007, 1, 28]).add({d: 30}), true),
33270 'មួយខែ',
33271 '30 days = មួយខែ'
33272 );
33273 assert.equal(
33274 start.from(moment([2007, 1, 28]).add({d: 43}), true),
33275 'មួយខែ',
33276 '43 days = មួយខែ'
33277 );
33278 assert.equal(
33279 start.from(moment([2007, 1, 28]).add({d: 46}), true),
33280 '២ ខែ',
33281 '46 days = 2 ខែ'
33282 );
33283 assert.equal(
33284 start.from(moment([2007, 1, 28]).add({d: 74}), true),
33285 '២ ខែ',
33286 '75 days = 2 ខែ'
33287 );
33288 assert.equal(
33289 start.from(moment([2007, 1, 28]).add({d: 76}), true),
33290 '៣ ខែ',
33291 '76 days = 3 ខែ'
33292 );
33293 assert.equal(
33294 start.from(moment([2007, 1, 28]).add({M: 1}), true),
33295 'មួយខែ',
33296 '1 month = មួយខែ'
33297 );
33298 assert.equal(
33299 start.from(moment([2007, 1, 28]).add({M: 5}), true),
33300 '៥ ខែ',
33301 '5 months = 5 ខែ'
33302 );
33303 assert.equal(
33304 start.from(moment([2007, 1, 28]).add({d: 345}), true),
33305 'មួយឆ្នាំ',
33306 '345 days = មួយឆ្នាំ'
33307 );
33308 assert.equal(
33309 start.from(moment([2007, 1, 28]).add({d: 548}), true),
33310 '២ ឆ្នាំ',
33311 '548 days = 2 ឆ្នាំ'
33312 );
33313 assert.equal(
33314 start.from(moment([2007, 1, 28]).add({y: 1}), true),
33315 'មួយឆ្នាំ',
33316 '1 year = មួយឆ្នាំ'
33317 );
33318 assert.equal(
33319 start.from(moment([2007, 1, 28]).add({y: 5}), true),
33320 '៥ ឆ្នាំ',
33321 '5 years = 5 ឆ្នាំ'
33322 );
33323 });
33324
33325 test('suffix', function (assert) {
33326 assert.equal(moment(30000).from(0), 'ប៉ុន្មានវិនាទីទៀត', 'prefix');
33327 assert.equal(moment(0).from(30000), 'ប៉ុន្មានវិនាទីមុន', 'suffix');
33328 });
33329
33330 test('now from now', function (assert) {
33331 assert.equal(
33332 moment().fromNow(),
33333 'ប៉ុន្មានវិនាទីមុន',
33334 'now from now should display as in the past'
33335 );
33336 });
33337
33338 test('fromNow', function (assert) {
33339 assert.equal(
33340 moment()
33341 .add({
33342 s: 30
33343 })
33344 .fromNow(),
33345 'ប៉ុន្មានវិនាទីទៀត',
33346 'in a few seconds'
33347 );
33348 assert.equal(
33349 moment()
33350 .add({
33351 d: 5
33352 })
33353 .fromNow(),
33354 '៥ ថ្ងៃទៀត',
33355 'in 5 days'
33356 );
33357 });
33358
33359 test('calendar day', function (assert) {
33360 var a = moment()
33361 .hours(12)
33362 .minutes(0)
33363 .seconds(0);
33364
33365 assert.equal(
33366 moment(a).calendar(),
33367 'ថ្ងៃនេះ ម៉ោង ១២:០០',
33368 'today at the same time'
33369 );
33370 assert.equal(
33371 moment(a)
33372 .add({m: 25})
33373 .calendar(),
33374 'ថ្ងៃនេះ ម៉ោង ១២:២៥',
33375 'Now plus 25 min'
33376 );
33377 assert.equal(
33378 moment(a)
33379 .add({h: 1})
33380 .calendar(),
33381 'ថ្ងៃនេះ ម៉ោង ១៣:០០',
33382 'Now plus 1 hour'
33383 );
33384 assert.equal(
33385 moment(a)
33386 .add({d: 1})
33387 .calendar(),
33388 'ស្អែក ម៉ោង ១២:០០',
33389 'tomorrow at the same time'
33390 );
33391 assert.equal(
33392 moment(a)
33393 .subtract({h: 1})
33394 .calendar(),
33395 'ថ្ងៃនេះ ម៉ោង ១១:០០',
33396 'Now minus 1 hour'
33397 );
33398 assert.equal(
33399 moment(a)
33400 .subtract({d: 1})
33401 .calendar(),
33402 'ម្សិលមិញ ម៉ោង ១២:០០',
33403 'yesterday at the same time'
33404 );
33405 });
33406
33407 test('calendar next week', function (assert) {
33408 var i, m;
33409 for (i = 2; i < 7; i++) {
33410 m = moment().add({
33411 d: i
33412 });
33413 assert.equal(
33414 m.calendar(),
33415 m.format('dddd [ម៉ោង] LT'),
33416 'Today + ' + i + ' days current time'
33417 );
33418 m
33419 .hours(0)
33420 .minutes(0)
33421 .seconds(0)
33422 .milliseconds(0);
33423 assert.equal(
33424 m.calendar(),
33425 m.format('dddd [ម៉ោង] LT'),
33426 'Today + ' + i + ' days beginning of day'
33427 );
33428 m
33429 .hours(23)
33430 .minutes(59)
33431 .seconds(59)
33432 .milliseconds(999);
33433 assert.equal(
33434 m.calendar(),
33435 m.format('dddd [ម៉ោង] LT'),
33436 'Today + ' + i + ' days end of day'
33437 );
33438 }
33439 });
33440
33441 test('calendar last week', function (assert) {
33442 var i, m;
33443
33444 for (i = 2; i < 7; i++) {
33445 m = moment().subtract({
33446 d: i
33447 });
33448 assert.equal(
33449 m.calendar(),
33450 m.format('dddd [សប្តាហ៍មុន] [ម៉ោង] LT'),
33451 'Today - ' + i + ' days current time'
33452 );
33453 m
33454 .hours(0)
33455 .minutes(0)
33456 .seconds(0)
33457 .milliseconds(0);
33458 assert.equal(
33459 m.calendar(),
33460 m.format('dddd [សប្តាហ៍មុន] [ម៉ោង] LT'),
33461 'Today - ' + i + ' days beginning of day'
33462 );
33463 m
33464 .hours(23)
33465 .minutes(59)
33466 .seconds(59)
33467 .milliseconds(999);
33468 assert.equal(
33469 m.calendar(),
33470 m.format('dddd [សប្តាហ៍មុន] [ម៉ោង] LT'),
33471 'Today - ' + i + ' days end of day'
33472 );
33473 }
33474 });
33475
33476 test('calendar all else', function (assert) {
33477 var weeksAgo = moment().subtract({
33478 w: 1
33479 }),
33480 weeksFromNow = moment().add({
33481 w: 1
33482 });
33483
33484 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
33485 assert.equal(
33486 weeksFromNow.calendar(),
33487 weeksFromNow.format('L'),
33488 'in 1 week'
33489 );
33490
33491 weeksAgo = moment().subtract({
33492 w: 2
33493 });
33494 weeksFromNow = moment().add({
33495 w: 2
33496 });
33497
33498 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
33499 assert.equal(
33500 weeksFromNow.calendar(),
33501 weeksFromNow.format('L'),
33502 'in 2 weeks'
33503 );
33504 });
33505
33506 test('weeks year starting sunday formatted', function (assert) {
33507 assert.equal(
33508 moment([2012, 0, 1]).format('w ww wo'),
33509 '៥២ ៥២ ទី៥២',
33510 'Jan 1 2012 should be week 52'
33511 );
33512 assert.equal(
33513 moment([2012, 0, 2]).format('w ww wo'),
33514 '១ ០១ ទី១',
33515 'Jan 2 2012 should be week 1'
33516 );
33517 assert.equal(
33518 moment([2012, 0, 8]).format('w ww wo'),
33519 '១ ០១ ទី១',
33520 'Jan 8 2012 should be week 1'
33521 );
33522 assert.equal(
33523 moment([2012, 0, 9]).format('w ww wo'),
33524 '២ ០២ ទី២',
33525 'Jan 9 2012 should be week 2'
33526 );
33527 assert.equal(
33528 moment([2012, 0, 15]).format('w ww wo'),
33529 '២ ០២ ទី២',
33530 'Jan 15 2012 should be week 2'
33531 );
33532 });
33533
33534})));
33535
33536
33537;(function (global, factory) {
33538 typeof exports === 'object' && typeof module !== 'undefined'
33539 && typeof require === 'function' ? factory(require('../../moment')) :
33540 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
33541 factory(global.moment)
33542}(this, (function (moment) { 'use strict';
33543
33544 function each(array, callback) {
33545 var i;
33546 for (i = 0; i < array.length; i++) {
33547 callback(array[i], i, array);
33548 }
33549 }
33550
c58511b9
KM
33551 function setupDeprecationHandler(test, moment$$1, scope) {
33552 test._expectedDeprecations = null;
33553 test._observedDeprecations = null;
33554 test._oldSupress = moment$$1.suppressDeprecationWarnings;
33555 moment$$1.suppressDeprecationWarnings = true;
33556 test.expectedDeprecations = function () {
33557 test._expectedDeprecations = arguments;
33558 test._observedDeprecations = [];
33559 };
33560 moment$$1.deprecationHandler = function (name, msg) {
33561 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
33562 if (deprecationId === -1) {
33563 throw new Error('Unexpected deprecation thrown name=' +
33564 name + ' msg=' + msg);
33565 }
33566 test._observedDeprecations[deprecationId] = 1;
33567 };
33568 }
33569
33570 function teardownDeprecationHandler(test, moment$$1, scope) {
33571 moment$$1.suppressDeprecationWarnings = test._oldSupress;
33572
33573 if (test._expectedDeprecations != null) {
33574 var missedDeprecations = [];
33575 each(test._expectedDeprecations, function (deprecationPattern, id) {
33576 if (test._observedDeprecations[id] !== 1) {
33577 missedDeprecations.push(deprecationPattern);
33578 }
33579 });
33580 if (missedDeprecations.length !== 0) {
33581 throw new Error('Expected deprecation warnings did not happen: ' +
33582 missedDeprecations.join(' '));
33583 }
33584 }
33585 }
33586
33587 function matchedDeprecation(name, msg, deprecations) {
33588 if (deprecations == null) {
33589 return -1;
33590 }
33591 for (var i = 0; i < deprecations.length; ++i) {
33592 if (name != null && name === deprecations[i]) {
33593 return i;
33594 }
33595 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
33596 return i;
33597 }
33598 }
33599 return -1;
33600 }
33601
33602 /*global QUnit:false*/
33603
33604 var test = QUnit.test;
33605
db71a655
KM
33606 function objectKeys(obj) {
33607 if (Object.keys) {
33608 return Object.keys(obj);
33609 } else {
33610 // IE8
33611 var res = [], i;
33612 for (i in obj) {
33613 if (obj.hasOwnProperty(i)) {
33614 res.push(i);
33615 }
33616 }
33617 return res;
33618 }
33619 }
33620
33621 // Pick the first defined of two or three arguments.
33622
33623 function defineCommonLocaleTests(locale, options) {
33624 test('lenient day of month ordinal parsing', function (assert) {
33625 var i, ordinalStr, testMoment;
33626 for (i = 1; i <= 31; ++i) {
33627 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
33628 testMoment = moment(ordinalStr, 'YYYY MM Do');
33629 assert.equal(testMoment.year(), 2014,
33630 'lenient day of month ordinal parsing ' + i + ' year check');
33631 assert.equal(testMoment.month(), 0,
33632 'lenient day of month ordinal parsing ' + i + ' month check');
33633 assert.equal(testMoment.date(), i,
33634 'lenient day of month ordinal parsing ' + i + ' date check');
33635 }
33636 });
33637
33638 test('lenient day of month ordinal parsing of number', function (assert) {
33639 var i, testMoment;
33640 for (i = 1; i <= 31; ++i) {
33641 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
33642 assert.equal(testMoment.year(), 2014,
33643 'lenient day of month ordinal parsing of number ' + i + ' year check');
33644 assert.equal(testMoment.month(), 0,
33645 'lenient day of month ordinal parsing of number ' + i + ' month check');
33646 assert.equal(testMoment.date(), i,
33647 'lenient day of month ordinal parsing of number ' + i + ' date check');
33648 }
33649 });
33650
33651 test('strict day of month ordinal parsing', function (assert) {
33652 var i, ordinalStr, testMoment;
33653 for (i = 1; i <= 31; ++i) {
33654 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
33655 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
33656 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
33657 }
33658 });
33659
33660 test('meridiem invariant', function (assert) {
33661 var h, m, t1, t2;
33662 for (h = 0; h < 24; ++h) {
33663 for (m = 0; m < 60; m += 15) {
33664 t1 = moment.utc([2000, 0, 1, h, m]);
33665 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
33666 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
33667 'meridiem at ' + t1.format('HH:mm'));
33668 }
33669 }
33670 });
33671
33672 test('date format correctness', function (assert) {
33673 var data, tokens;
33674 data = moment.localeData()._longDateFormat;
33675 tokens = objectKeys(data);
33676 each(tokens, function (srchToken) {
33677 // Check each format string to make sure it does not contain any
33678 // tokens that need to be expanded.
33679 each(tokens, function (baseToken) {
33680 // strip escaped sequences
33681 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
33682 assert.equal(false, !!~format.indexOf(srchToken),
33683 'contains ' + srchToken + ' in ' + baseToken);
33684 });
33685 });
33686 });
33687
33688 test('month parsing correctness', function (assert) {
33689 var i, m;
33690
33691 if (locale === 'tr') {
33692 // I can't fix it :(
c58511b9 33693 assert.expect(0);
db71a655
KM
33694 return;
33695 }
33696 function tester(format) {
33697 var r;
33698 r = moment(m.format(format), format);
33699 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
33700 if (locale !== 'ka') {
33701 r = moment(m.format(format).toLocaleUpperCase(), format);
33702 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
33703 }
db71a655
KM
33704 r = moment(m.format(format).toLocaleLowerCase(), format);
33705 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
33706
33707 r = moment(m.format(format), format, true);
33708 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
33709 if (locale !== 'ka') {
33710 r = moment(m.format(format).toLocaleUpperCase(), format, true);
33711 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
33712 }
db71a655
KM
33713 r = moment(m.format(format).toLocaleLowerCase(), format, true);
33714 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
33715 }
33716
33717 for (i = 0; i < 12; ++i) {
33718 m = moment([2015, i, 15, 18]);
33719 tester('MMM');
33720 tester('MMM.');
33721 tester('MMMM');
33722 tester('MMMM.');
33723 }
33724 });
33725
33726 test('weekday parsing correctness', function (assert) {
33727 var i, m;
33728
96d0d679 33729 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
33730 // tr, az: There is a lower-case letter (ı), that converted to
33731 // upper then lower changes to i
33732 // ro: there is the letter ț which behaves weird under IE8
33733 // mt: letter Ħ
96d0d679 33734 // ga: month with spaces
c58511b9 33735 assert.expect(0);
db71a655
KM
33736 return;
33737 }
33738 function tester(format) {
33739 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
33740 r = moment(m.format(format), format);
33741 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
33742 if (locale !== 'ka') {
33743 r = moment(m.format(format).toLocaleUpperCase(), format);
33744 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
33745 }
db71a655
KM
33746 r = moment(m.format(format).toLocaleLowerCase(), format);
33747 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
33748 r = moment(m.format(format), format, true);
33749 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
33750 if (locale !== 'ka') {
33751 r = moment(m.format(format).toLocaleUpperCase(), format, true);
33752 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
33753 }
db71a655
KM
33754 r = moment(m.format(format).toLocaleLowerCase(), format, true);
33755 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
33756 }
33757
33758 for (i = 0; i < 7; ++i) {
33759 m = moment.utc([2015, 0, i + 1, 18]);
33760 tester('dd');
33761 tester('ddd');
33762 tester('dddd');
33763 }
33764 });
33765
33766 test('valid localeData', function (assert) {
33767 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
33768 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
33769 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
33770 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
33771 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
33772 });
96d0d679
KM
33773
33774 test('localeData weekdays can localeSort', function (assert) {
33775 var weekdays = moment().localeData().weekdays();
33776 var weekdaysShort = moment().localeData().weekdaysShort();
33777 var weekdaysMin = moment().localeData().weekdaysMin();
33778 var shift = moment().localeData()._week.dow;
33779 assert.deepEqual(
33780 moment().localeData().weekdays(true),
33781 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
33782 'weekdays should localeSort');
33783 assert.deepEqual(
33784 moment().localeData().weekdaysShort(true),
33785 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
33786 'weekdaysShort should localeSort');
33787 assert.deepEqual(
33788 moment().localeData().weekdaysMin(true),
33789 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
33790 'weekdaysMin should localeSort');
33791 });
db71a655
KM
33792 }
33793
db71a655
KM
33794 /*global QUnit:false*/
33795
db71a655
KM
33796 function localeModule (name, lifecycle) {
33797 QUnit.module('locale:' + name, {
c58511b9 33798 beforeEach : function () {
db71a655
KM
33799 moment.locale(name);
33800 moment.createFromInputFallback = function (config) {
33801 throw new Error('input not handled by moment: ' + config._i);
33802 };
33803 setupDeprecationHandler(test, moment, 'locale');
33804 if (lifecycle && lifecycle.setup) {
33805 lifecycle.setup();
33806 }
33807 },
c58511b9 33808 afterEach : function () {
db71a655
KM
33809 moment.locale('en');
33810 teardownDeprecationHandler(test, moment, 'locale');
33811 if (lifecycle && lifecycle.teardown) {
33812 lifecycle.teardown();
33813 }
33814 }
33815 });
33816 defineCommonLocaleTests(name, -1, -1);
33817 }
33818
33819 localeModule('kn');
33820
33821 test('parse', function (assert) {
33822 var tests = 'ಜನವರಿ ಜನ_ಫೆಬ್ರವರಿ ಫೆಬ್ರ_ಮಾರ್ಚ್ ಮಾರ್ಚ್_ಏಪ್ರಿಲ್ ಏಪ್ರಿಲ್_ಮೇ ಮೇ_ಜೂನ್ ಜೂನ್_ಜುಲೈ ಜುಲೈ_ಆಗಸ್ಟ್ ಆಗಸ್ಟ್_ಸೆಪ್ಟೆಂ ಸೆಪ್ಟೆಂಬ_ಅಕ್ಟೋಬರ್ ಅಕ್ಟೋ_ನವೆಂಬರ್ ನವೆಂ_ಡಿಸೆಂಬರ್ ಡಿಸೆಂ'.split('_'), i;
33823 function equalTest(input, mmm, i) {
33824 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
33825 }
33826 for (i = 0; i < 12; i++) {
33827 tests[i] = tests[i].split(' ');
33828 equalTest(tests[i][0], 'MMM', i);
33829 equalTest(tests[i][1], 'MMM', i);
33830 equalTest(tests[i][0], 'MMMM', i);
33831 equalTest(tests[i][1], 'MMMM', i);
33832 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
33833 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
33834 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
33835 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
33836 }
33837 });
33838
33839 test('format', function (assert) {
33840 var a = [
33841 ['dddd, Do MMMM YYYY, a h:mm:ss', 'ಭಾನುವಾರ, ೧೪ನೇ ಫೆಬ್ರವರಿ ೨೦೧೦, ಮಧ್ಯಾಹ್ನ ೩:೨೫:೫೦'],
33842 ['ddd, a h ಗಂಟೆ', 'ಭಾನು, ಮಧ್ಯಾಹ್ನ ೩ ಗಂಟೆ'],
33843 ['M Mo MM MMMM MMM', '೨ ೨ನೇ ೦೨ ಫೆಬ್ರವರಿ ಫೆಬ್ರ'],
33844 ['YYYY YY', '೨೦೧೦ ೧೦'],
33845 ['D Do DD', '೧೪ ೧೪ನೇ ೧೪'],
33846 ['d do dddd ddd dd', '೦ ೦ನೇ ಭಾನುವಾರ ಭಾನು ಭಾ'],
33847 ['DDD DDDo DDDD', '೪೫ ೪೫ನೇ ೦೪೫'],
33848 ['w wo ww', '೮ ೮ನೇ ೦೮'],
33849 ['h hh', '೩ ೦೩'],
33850 ['H HH', '೧೫ ೧೫'],
33851 ['m mm', '೨೫ ೨೫'],
33852 ['s ss', '೫೦ ೫೦'],
33853 ['a A', 'ಮಧ್ಯಾಹ್ನ ಮಧ್ಯಾಹ್ನ'],
33854 ['LTS', 'ಮಧ್ಯಾಹ್ನ ೩:೨೫:೫೦'],
33855 ['L', '೧೪/೦೨/೨೦೧೦'],
33856 ['LL', '೧೪ ಫೆಬ್ರವರಿ ೨೦೧೦'],
33857 ['LLL', '೧೪ ಫೆಬ್ರವರಿ ೨೦೧೦, ಮಧ್ಯಾಹ್ನ ೩:೨೫'],
33858 ['LLLL', 'ಭಾನುವಾರ, ೧೪ ಫೆಬ್ರವರಿ ೨೦೧೦, ಮಧ್ಯಾಹ್ನ ೩:೨೫'],
33859 ['l', '೧೪/೨/೨೦೧೦'],
33860 ['ll', '೧೪ ಫೆಬ್ರ ೨೦೧೦'],
33861 ['lll', '೧೪ ಫೆಬ್ರ ೨೦೧೦, ಮಧ್ಯಾಹ್ನ ೩:೨೫'],
33862 ['llll', 'ಭಾನು, ೧೪ ಫೆಬ್ರ ೨೦೧೦, ಮಧ್ಯಾಹ್ನ ೩:೨೫']
33863 ],
33864 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
33865 i;
33866 for (i = 0; i < a.length; i++) {
33867 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
33868 }
33869 });
33870
33871 test('format ordinal', function (assert) {
33872 assert.equal(moment([2011, 0, 1]).format('DDDo'), '೧ನೇ', '೧ನೇ');
33873 assert.equal(moment([2011, 0, 2]).format('DDDo'), '೨ನೇ', '೨ನೇ');
33874 assert.equal(moment([2011, 0, 3]).format('DDDo'), '೩ನೇ', '೩ನೇ');
33875 assert.equal(moment([2011, 0, 4]).format('DDDo'), '೪ನೇ', '೪ನೇ');
33876 assert.equal(moment([2011, 0, 5]).format('DDDo'), '೫ನೇ', '೫ನೇ');
33877 assert.equal(moment([2011, 0, 6]).format('DDDo'), '೬ನೇ', '೬ನೇ');
33878 assert.equal(moment([2011, 0, 7]).format('DDDo'), '೭ನೇ', '೭ನೇ');
33879 assert.equal(moment([2011, 0, 8]).format('DDDo'), '೮ನೇ', '೮ನೇ');
33880 assert.equal(moment([2011, 0, 9]).format('DDDo'), '೯ನೇ', '೯ನೇ');
33881 assert.equal(moment([2011, 0, 10]).format('DDDo'), '೧೦ನೇ', '೧೦ನೇ');
33882
33883 assert.equal(moment([2011, 0, 11]).format('DDDo'), '೧೧ನೇ', '೧೧ನೇ');
33884 assert.equal(moment([2011, 0, 12]).format('DDDo'), '೧೨ನೇ', '೧೨ನೇ');
33885 assert.equal(moment([2011, 0, 13]).format('DDDo'), '೧೩ನೇ', '೧೩ನೇ');
33886 assert.equal(moment([2011, 0, 14]).format('DDDo'), '೧೪ನೇ', '೧೪ನೇ');
33887 assert.equal(moment([2011, 0, 15]).format('DDDo'), '೧೫ನೇ', '೧೫ನೇ');
33888 assert.equal(moment([2011, 0, 16]).format('DDDo'), '೧೬ನೇ', '೧೬ನೇ');
33889 assert.equal(moment([2011, 0, 17]).format('DDDo'), '೧೭ನೇ', '೧೭ನೇ');
33890 assert.equal(moment([2011, 0, 18]).format('DDDo'), '೧೮ನೇ', '೧೮ನೇ');
33891 assert.equal(moment([2011, 0, 19]).format('DDDo'), '೧೯ನೇ', '೧೯ನೇ');
33892 assert.equal(moment([2011, 0, 20]).format('DDDo'), '೨೦ನೇ', '೨೦ನೇ');
33893
33894 assert.equal(moment([2011, 0, 21]).format('DDDo'), '೨೧ನೇ', '೨೧ನೇ');
33895 assert.equal(moment([2011, 0, 22]).format('DDDo'), '೨೨ನೇ', '೨೨ನೇ');
33896 assert.equal(moment([2011, 0, 23]).format('DDDo'), '೨೩ನೇ', '೨೩ನೇ');
33897 assert.equal(moment([2011, 0, 24]).format('DDDo'), '೨೪ನೇ', '೨೪ನೇ');
33898 assert.equal(moment([2011, 0, 25]).format('DDDo'), '೨೫ನೇ', '೨೫ನೇ');
33899 assert.equal(moment([2011, 0, 26]).format('DDDo'), '೨೬ನೇ', '೨೬ನೇ');
33900 assert.equal(moment([2011, 0, 27]).format('DDDo'), '೨೭ನೇ', '೨೭ನೇ');
33901 assert.equal(moment([2011, 0, 28]).format('DDDo'), '೨೮ನೇ', '೨೮ನೇ');
33902 assert.equal(moment([2011, 0, 29]).format('DDDo'), '೨೯ನೇ', '೨೯ನೇ');
33903 assert.equal(moment([2011, 0, 30]).format('DDDo'), '೩೦ನೇ', '೩೦ನೇ');
33904
33905 assert.equal(moment([2011, 0, 31]).format('DDDo'), '೩೧ನೇ', '೩೧ನೇ');
33906 });
33907
33908 test('format month', function (assert) {
33909 var expected = 'ಜನವರಿ ಜನ_ಫೆಬ್ರವರಿ ಫೆಬ್ರ_ಮಾರ್ಚ್ ಮಾರ್ಚ್_ಏಪ್ರಿಲ್ ಏಪ್ರಿಲ್_ಮೇ ಮೇ_ಜೂನ್ ಜೂನ್_ಜುಲೈ ಜುಲೈ_ಆಗಸ್ಟ್ ಆಗಸ್ಟ್_ಸೆಪ್ಟೆಂಬರ್ ಸೆಪ್ಟೆಂ_ಅಕ್ಟೋಬರ್ ಅಕ್ಟೋ_ನವೆಂಬರ್ ನವೆಂ_ಡಿಸೆಂಬರ್ ಡಿಸೆಂ'.split('_'), i;
33910 for (i = 0; i < expected.length; i++) {
33911 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
33912 }
33913 });
33914
33915 test('format week', function (assert) {
33916 var expected = 'ಭಾನುವಾರ ಭಾನು ಭಾ_ಸೋಮವಾರ ಸೋಮ ಸೋ_ಮಂಗಳವಾರ ಮಂಗಳ ಮಂ_ಬುಧವಾರ ಬುಧ ಬು_ಗುರುವಾರ ಗುರು ಗು_ಶುಕ್ರವಾರ ಶುಕ್ರ ಶು_ಶನಿವಾರ ಶನಿ ಶ'.split('_'), i;
33917 for (i = 0; i < expected.length; i++) {
33918 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
33919 }
33920 });
33921
33922 test('from', function (assert) {
33923 var start = moment([2007, 1, 28]);
33924 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ಕೆಲವು ಕ್ಷಣಗಳು', '44 seconds = a few seconds');
33925 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ಒಂದು ನಿಮಿಷ', '45 seconds = a minute');
33926 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ಒಂದು ನಿಮಿಷ', '89 seconds = a minute');
33927 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '೨ ನಿಮಿಷ', '90 seconds = 2 minutes');
33928 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '೪೪ ನಿಮಿಷ', '44 minutes = 44 minutes');
33929 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ಒಂದು ಗಂಟೆ', '45 minutes = an hour');
33930 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ಒಂದು ಗಂಟೆ', '89 minutes = an hour');
33931 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '೨ ಗಂಟೆ', '90 minutes = 2 hours');
33932 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '೫ ಗಂಟೆ', '5 hours = 5 hours');
33933 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '೨೧ ಗಂಟೆ', '21 hours = 21 hours');
33934 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ಒಂದು ದಿನ', '22 hours = a day');
33935 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ಒಂದು ದಿನ', '35 hours = a day');
33936 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '೨ ದಿನ', '36 hours = 2 days');
33937 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ಒಂದು ದಿನ', '1 day = a day');
33938 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '೫ ದಿನ', '5 days = 5 days');
33939 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '೨೫ ದಿನ', '25 days = 25 days');
33940 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ಒಂದು ತಿಂಗಳು', '26 days = a month');
33941 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ಒಂದು ತಿಂಗಳು', '30 days = a month');
33942 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ಒಂದು ತಿಂಗಳು', '43 days = a month');
33943 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '೨ ತಿಂಗಳು', '46 days = 2 months');
33944 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '೨ ತಿಂಗಳು', '75 days = 2 months');
33945 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '೩ ತಿಂಗಳು', '76 days = 3 months');
33946 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ಒಂದು ತಿಂಗಳು', '1 month = a month');
33947 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '೫ ತಿಂಗಳು', '5 months = 5 months');
33948 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ಒಂದು ವರ್ಷ', '345 days = a year');
33949 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '೨ ವರ್ಷ', '548 days = 2 years');
33950 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ಒಂದು ವರ್ಷ', '1 year = a year');
33951 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '೫ ವರ್ಷ', '5 years = 5 years');
33952 });
33953
33954 test('suffix', function (assert) {
33955 assert.equal(moment(30000).from(0), 'ಕೆಲವು ಕ್ಷಣಗಳು ನಂತರ', 'prefix');
33956 assert.equal(moment(0).from(30000), 'ಕೆಲವು ಕ್ಷಣಗಳು ಹಿಂದೆ', 'suffix');
33957 });
33958
33959 test('now from now', function (assert) {
33960 assert.equal(moment().fromNow(), 'ಕೆಲವು ಕ್ಷಣಗಳು ಹಿಂದೆ', 'now from now should display as in the past');
33961 });
33962
33963 test('fromNow', function (assert) {
33964 assert.equal(moment().add({s: 30}).fromNow(), 'ಕೆಲವು ಕ್ಷಣಗಳು ನಂತರ', 'ಕೆಲವು ಕ್ಷಣಗಳು ನಂತರ');
33965 assert.equal(moment().add({d: 5}).fromNow(), '೫ ದಿನ ನಂತರ', '೫ ದಿನ ನಂತರ');
33966 });
33967
33968 test('calendar day', function (assert) {
33969 var a = moment().hours(12).minutes(0).seconds(0);
33970
33971 assert.equal(moment(a).calendar(), 'ಇಂದು ಮಧ್ಯಾಹ್ನ ೧೨:೦೦', 'today at the same time');
33972 assert.equal(moment(a).add({m: 25}).calendar(), 'ಇಂದು ಮಧ್ಯಾಹ್ನ ೧೨:೨೫', 'Now plus 25 min');
33973 assert.equal(moment(a).add({h: 3}).calendar(), 'ಇಂದು ಮಧ್ಯಾಹ್ನ ೩:೦೦', 'Now plus 3 hours');
33974 assert.equal(moment(a).add({d: 1}).calendar(), 'ನಾಳೆ ಮಧ್ಯಾಹ್ನ ೧೨:೦೦', 'tomorrow at the same time');
33975 assert.equal(moment(a).subtract({h: 1}).calendar(), 'ಇಂದು ಮಧ್ಯಾಹ್ನ ೧೧:೦೦', 'Now minus 1 hour');
33976 assert.equal(moment(a).subtract({d: 1}).calendar(), 'ನಿನ್ನೆ ಮಧ್ಯಾಹ್ನ ೧೨:೦೦', 'yesterday at the same time');
33977 });
33978
33979 test('calendar next week', function (assert) {
33980 var i, m;
33981 for (i = 2; i < 7; i++) {
33982 m = moment().add({d: i});
33983 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days current time');
33984 m.hours(0).minutes(0).seconds(0).milliseconds(0);
33985 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days beginning of day');
33986 m.hours(23).minutes(59).seconds(59).milliseconds(999);
33987 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days end of day');
73f3c911
IC
33988 }
33989 });
b135bf1a 33990
db71a655
KM
33991 test('calendar last week', function (assert) {
33992 var i, m;
33993
33994 for (i = 2; i < 7; i++) {
33995 m = moment().subtract({d: i});
33996 assert.equal(m.calendar(), m.format('[ಕೊನೆಯ] dddd[,] LT'), 'Today - ' + i + ' days current time');
33997 m.hours(0).minutes(0).seconds(0).milliseconds(0);
33998 assert.equal(m.calendar(), m.format('[ಕೊನೆಯ] dddd[,] LT'), 'Today - ' + i + ' days beginning of day');
33999 m.hours(23).minutes(59).seconds(59).milliseconds(999);
34000 assert.equal(m.calendar(), m.format('[ಕೊನೆಯ] dddd[,] LT'), 'Today - ' + i + ' days end of day');
73f3c911
IC
34001 }
34002 });
b135bf1a 34003
db71a655
KM
34004 test('calendar all else', function (assert) {
34005 var weeksAgo = moment().subtract({w: 1}),
34006 weeksFromNow = moment().add({w: 1});
34007
34008 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
34009 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
34010
34011 weeksAgo = moment().subtract({w: 2});
34012 weeksFromNow = moment().add({w: 2});
34013
34014 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
34015 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
34016 });
34017
34018 test('meridiem', function (assert) {
34019 assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), 'ರಾತ್ರಿ', 'before dawn');
34020 assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), 'ಬೆಳಿಗ್ಗೆ', 'morning');
34021 assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), 'ಮಧ್ಯಾಹ್ನ', 'during day');
34022 assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), 'ಸಂಜೆ', 'evening');
34023 assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), 'ಸಂಜೆ', 'late evening');
34024 assert.equal(moment([2011, 2, 23, 21, 20]).format('a'), 'ರಾತ್ರಿ', 'night');
34025
34026 assert.equal(moment([2011, 2, 23, 2, 30]).format('A'), 'ರಾತ್ರಿ', 'before dawn');
34027 assert.equal(moment([2011, 2, 23, 9, 30]).format('A'), 'ಬೆಳಿಗ್ಗೆ', 'morning');
34028 assert.equal(moment([2011, 2, 23, 14, 30]).format('A'), 'ಮಧ್ಯಾಹ್ನ', ' during day');
34029 assert.equal(moment([2011, 2, 23, 17, 30]).format('A'), 'ಸಂಜೆ', 'evening');
34030 assert.equal(moment([2011, 2, 23, 19, 30]).format('A'), 'ಸಂಜೆ', 'late evening');
34031 assert.equal(moment([2011, 2, 23, 21, 20]).format('A'), 'ರಾತ್ರಿ', 'night');
34032 });
34033
34034 test('weeks year starting sunday formatted', function (assert) {
34035 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '೧ ೦೧ ೧ನೇ', 'Jan 1 2012 should be week 1');
34036 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '೧ ೦೧ ೧ನೇ', 'Jan 7 2012 should be week 1');
34037 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '೨ ೦೨ ೨ನೇ', 'Jan 8 2012 should be week 2');
34038 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '೨ ೦೨ ೨ನೇ', 'Jan 14 2012 should be week 2');
34039 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '೩ ೦೩ ೩ನೇ', 'Jan 15 2012 should be week 3');
34040 });
34041
34042})));
34043
34044
34045;(function (global, factory) {
34046 typeof exports === 'object' && typeof module !== 'undefined'
34047 && typeof require === 'function' ? factory(require('../../moment')) :
34048 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
34049 factory(global.moment)
34050}(this, (function (moment) { 'use strict';
34051
34052 function each(array, callback) {
34053 var i;
34054 for (i = 0; i < array.length; i++) {
34055 callback(array[i], i, array);
34056 }
34057 }
34058
c58511b9
KM
34059 function setupDeprecationHandler(test, moment$$1, scope) {
34060 test._expectedDeprecations = null;
34061 test._observedDeprecations = null;
34062 test._oldSupress = moment$$1.suppressDeprecationWarnings;
34063 moment$$1.suppressDeprecationWarnings = true;
34064 test.expectedDeprecations = function () {
34065 test._expectedDeprecations = arguments;
34066 test._observedDeprecations = [];
34067 };
34068 moment$$1.deprecationHandler = function (name, msg) {
34069 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
34070 if (deprecationId === -1) {
34071 throw new Error('Unexpected deprecation thrown name=' +
34072 name + ' msg=' + msg);
34073 }
34074 test._observedDeprecations[deprecationId] = 1;
34075 };
34076 }
34077
34078 function teardownDeprecationHandler(test, moment$$1, scope) {
34079 moment$$1.suppressDeprecationWarnings = test._oldSupress;
34080
34081 if (test._expectedDeprecations != null) {
34082 var missedDeprecations = [];
34083 each(test._expectedDeprecations, function (deprecationPattern, id) {
34084 if (test._observedDeprecations[id] !== 1) {
34085 missedDeprecations.push(deprecationPattern);
34086 }
34087 });
34088 if (missedDeprecations.length !== 0) {
34089 throw new Error('Expected deprecation warnings did not happen: ' +
34090 missedDeprecations.join(' '));
34091 }
34092 }
34093 }
34094
34095 function matchedDeprecation(name, msg, deprecations) {
34096 if (deprecations == null) {
34097 return -1;
34098 }
34099 for (var i = 0; i < deprecations.length; ++i) {
34100 if (name != null && name === deprecations[i]) {
34101 return i;
34102 }
34103 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
34104 return i;
34105 }
34106 }
34107 return -1;
34108 }
34109
34110 /*global QUnit:false*/
34111
34112 var test = QUnit.test;
34113
db71a655
KM
34114 function objectKeys(obj) {
34115 if (Object.keys) {
34116 return Object.keys(obj);
34117 } else {
34118 // IE8
34119 var res = [], i;
34120 for (i in obj) {
34121 if (obj.hasOwnProperty(i)) {
34122 res.push(i);
34123 }
34124 }
34125 return res;
34126 }
34127 }
34128
34129 // Pick the first defined of two or three arguments.
34130
34131 function defineCommonLocaleTests(locale, options) {
34132 test('lenient day of month ordinal parsing', function (assert) {
34133 var i, ordinalStr, testMoment;
34134 for (i = 1; i <= 31; ++i) {
34135 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
34136 testMoment = moment(ordinalStr, 'YYYY MM Do');
34137 assert.equal(testMoment.year(), 2014,
34138 'lenient day of month ordinal parsing ' + i + ' year check');
34139 assert.equal(testMoment.month(), 0,
34140 'lenient day of month ordinal parsing ' + i + ' month check');
34141 assert.equal(testMoment.date(), i,
34142 'lenient day of month ordinal parsing ' + i + ' date check');
34143 }
34144 });
34145
34146 test('lenient day of month ordinal parsing of number', function (assert) {
34147 var i, testMoment;
34148 for (i = 1; i <= 31; ++i) {
34149 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
34150 assert.equal(testMoment.year(), 2014,
34151 'lenient day of month ordinal parsing of number ' + i + ' year check');
34152 assert.equal(testMoment.month(), 0,
34153 'lenient day of month ordinal parsing of number ' + i + ' month check');
34154 assert.equal(testMoment.date(), i,
34155 'lenient day of month ordinal parsing of number ' + i + ' date check');
34156 }
34157 });
34158
34159 test('strict day of month ordinal parsing', function (assert) {
34160 var i, ordinalStr, testMoment;
34161 for (i = 1; i <= 31; ++i) {
34162 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
34163 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
34164 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
34165 }
34166 });
34167
34168 test('meridiem invariant', function (assert) {
34169 var h, m, t1, t2;
34170 for (h = 0; h < 24; ++h) {
34171 for (m = 0; m < 60; m += 15) {
34172 t1 = moment.utc([2000, 0, 1, h, m]);
34173 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
34174 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
34175 'meridiem at ' + t1.format('HH:mm'));
34176 }
34177 }
34178 });
34179
34180 test('date format correctness', function (assert) {
34181 var data, tokens;
34182 data = moment.localeData()._longDateFormat;
34183 tokens = objectKeys(data);
34184 each(tokens, function (srchToken) {
34185 // Check each format string to make sure it does not contain any
34186 // tokens that need to be expanded.
34187 each(tokens, function (baseToken) {
34188 // strip escaped sequences
34189 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
34190 assert.equal(false, !!~format.indexOf(srchToken),
34191 'contains ' + srchToken + ' in ' + baseToken);
34192 });
b135bf1a
IC
34193 });
34194 });
d6651c21 34195
db71a655
KM
34196 test('month parsing correctness', function (assert) {
34197 var i, m;
34198
34199 if (locale === 'tr') {
34200 // I can't fix it :(
c58511b9 34201 assert.expect(0);
db71a655
KM
34202 return;
34203 }
34204 function tester(format) {
34205 var r;
34206 r = moment(m.format(format), format);
34207 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
34208 if (locale !== 'ka') {
34209 r = moment(m.format(format).toLocaleUpperCase(), format);
34210 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
34211 }
db71a655
KM
34212 r = moment(m.format(format).toLocaleLowerCase(), format);
34213 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
34214
34215 r = moment(m.format(format), format, true);
34216 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
34217 if (locale !== 'ka') {
34218 r = moment(m.format(format).toLocaleUpperCase(), format, true);
34219 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
34220 }
db71a655
KM
34221 r = moment(m.format(format).toLocaleLowerCase(), format, true);
34222 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
34223 }
34224
34225 for (i = 0; i < 12; ++i) {
34226 m = moment([2015, i, 15, 18]);
34227 tester('MMM');
34228 tester('MMM.');
34229 tester('MMMM');
34230 tester('MMMM.');
34231 }
34232 });
34233
34234 test('weekday parsing correctness', function (assert) {
34235 var i, m;
34236
96d0d679 34237 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
34238 // tr, az: There is a lower-case letter (ı), that converted to
34239 // upper then lower changes to i
34240 // ro: there is the letter ț which behaves weird under IE8
34241 // mt: letter Ħ
96d0d679 34242 // ga: month with spaces
c58511b9 34243 assert.expect(0);
db71a655
KM
34244 return;
34245 }
34246 function tester(format) {
34247 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
34248 r = moment(m.format(format), format);
34249 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
34250 if (locale !== 'ka') {
34251 r = moment(m.format(format).toLocaleUpperCase(), format);
34252 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
34253 }
db71a655
KM
34254 r = moment(m.format(format).toLocaleLowerCase(), format);
34255 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
34256 r = moment(m.format(format), format, true);
34257 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
34258 if (locale !== 'ka') {
34259 r = moment(m.format(format).toLocaleUpperCase(), format, true);
34260 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
34261 }
db71a655
KM
34262 r = moment(m.format(format).toLocaleLowerCase(), format, true);
34263 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
34264 }
34265
34266 for (i = 0; i < 7; ++i) {
34267 m = moment.utc([2015, 0, i + 1, 18]);
34268 tester('dd');
34269 tester('ddd');
34270 tester('dddd');
34271 }
34272 });
34273
34274 test('valid localeData', function (assert) {
34275 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
34276 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
34277 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
34278 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
34279 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
34280 });
96d0d679
KM
34281
34282 test('localeData weekdays can localeSort', function (assert) {
34283 var weekdays = moment().localeData().weekdays();
34284 var weekdaysShort = moment().localeData().weekdaysShort();
34285 var weekdaysMin = moment().localeData().weekdaysMin();
34286 var shift = moment().localeData()._week.dow;
34287 assert.deepEqual(
34288 moment().localeData().weekdays(true),
34289 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
34290 'weekdays should localeSort');
34291 assert.deepEqual(
34292 moment().localeData().weekdaysShort(true),
34293 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
34294 'weekdaysShort should localeSort');
34295 assert.deepEqual(
34296 moment().localeData().weekdaysMin(true),
34297 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
34298 'weekdaysMin should localeSort');
34299 });
db71a655 34300 }
d6651c21 34301
db71a655 34302 /*global QUnit:false*/
516f5f67 34303
db71a655
KM
34304 function localeModule (name, lifecycle) {
34305 QUnit.module('locale:' + name, {
c58511b9 34306 beforeEach : function () {
db71a655
KM
34307 moment.locale(name);
34308 moment.createFromInputFallback = function (config) {
34309 throw new Error('input not handled by moment: ' + config._i);
34310 };
34311 setupDeprecationHandler(test, moment, 'locale');
34312 if (lifecycle && lifecycle.setup) {
34313 lifecycle.setup();
34314 }
34315 },
c58511b9 34316 afterEach : function () {
db71a655
KM
34317 moment.locale('en');
34318 teardownDeprecationHandler(test, moment, 'locale');
34319 if (lifecycle && lifecycle.teardown) {
34320 lifecycle.teardown();
34321 }
516f5f67
IC
34322 }
34323 });
db71a655 34324 defineCommonLocaleTests(name, -1, -1);
516f5f67
IC
34325 }
34326
db71a655
KM
34327 localeModule('ko');
34328
34329 test('parse', function (assert) {
34330 var tests = '1월 1월_2월 2월_3월 3월_4월 4월_5월 5월_6월 6월_7월 7월_8월 8월_9월 9월_10월 10월_11월 11월_12월 12월'.split('_'), i;
34331 function equalTest(input, mmm, i) {
34332 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
516f5f67 34333 }
db71a655
KM
34334 for (i = 0; i < 12; i++) {
34335 tests[i] = tests[i].split(' ');
34336 equalTest(tests[i][0], 'MMM', i);
34337 equalTest(tests[i][1], 'MMM', i);
34338 equalTest(tests[i][0], 'MMMM', i);
34339 equalTest(tests[i][1], 'MMMM', i);
34340 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
34341 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
34342 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
34343 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
516f5f67 34344 }
db71a655
KM
34345 });
34346
34347 test('parse meridiem', function (assert) {
34348 var elements = [{
34349 expression : '1981년 9월 8일 오후 2시 30분',
34350 inputFormat : 'YYYY[년] M[월] D[일] A h[시] m[분]',
34351 outputFormat : 'A',
34352 expected : '오후'
34353 }, {
34354 expression : '1981년 9월 8일 오전 2시 30분',
34355 inputFormat : 'YYYY[년] M[월] D[일] A h[시] m[분]',
34356 outputFormat : 'A h시',
34357 expected : '오전 2시'
34358 }, {
34359 expression : '14시 30분',
34360 inputFormat : 'H[시] m[분]',
34361 outputFormat : 'A',
34362 expected : '오후'
34363 }, {
34364 expression : '오후 4시',
34365 inputFormat : 'A h[시]',
34366 outputFormat : 'H',
34367 expected : '16'
34368 }], i, l, it, actual;
34369
34370 for (i = 0, l = elements.length; i < l; ++i) {
34371 it = elements[i];
34372 actual = moment(it.expression, it.inputFormat).format(it.outputFormat);
34373
34374 assert.equal(
34375 actual,
34376 it.expected,
34377 '\'' + it.outputFormat + '\' of \'' + it.expression + '\' must be \'' + it.expected + '\' but was \'' + actual + '\'.'
34378 );
34379 }
34380 });
34381
34382 test('format', function (assert) {
34383 var a = [
34384 ['YYYY년 MMMM Do dddd a h:mm:ss', '2010년 2월 14일 일요일 오후 3:25:50'],
34385 ['ddd A h', '일 오후 3'],
34386 ['M Mo MM MMMM MMM', '2 2월 02 2월 2월'],
34387 ['YYYY YY', '2010 10'],
34388 ['D Do DD', '14 14일 14'],
34389 ['d do dddd ddd dd', '0 0일 일요일 일 일'],
34390 ['DDD DDDo DDDD', '45 45일 045'],
34391 ['w wo ww', '8 8주 08'],
34392 ['h hh', '3 03'],
34393 ['H HH', '15 15'],
34394 ['m mm', '25 25'],
34395 ['s ss', '50 50'],
34396 ['a A', '오후 오후'],
34397 ['일년 중 DDDo째 되는 날', '일년 중 45일째 되는 날'],
34398 ['LTS', '오후 3:25:50'],
34399 ['L', '2010.02.14.'],
34400 ['LL', '2010년 2월 14일'],
34401 ['LLL', '2010년 2월 14일 오후 3:25'],
34402 ['LLLL', '2010년 2월 14일 일요일 오후 3:25'],
34403 ['l', '2010.02.14.'],
34404 ['ll', '2010년 2월 14일'],
34405 ['lll', '2010년 2월 14일 오후 3:25'],
34406 ['llll', '2010년 2월 14일 일요일 오후 3:25']
34407 ],
34408 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
34409 i;
34410 for (i = 0; i < a.length; i++) {
34411 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
34412 }
34413 });
34414
34415 test('format ordinal', function (assert) {
34416 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1일', '1일');
34417 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2일', '2일');
34418 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3일', '3일');
34419 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4일', '4일');
34420 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5일', '5일');
34421 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6일', '6일');
34422 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7일', '7일');
34423 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8일', '8일');
34424 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9일', '9일');
34425 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10일', '10일');
34426
34427 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11일', '11일');
34428 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12일', '12일');
34429 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13일', '13일');
34430 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14일', '14일');
34431 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15일', '15일');
34432 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16일', '16일');
34433 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17일', '17일');
34434 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18일', '18일');
34435 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19일', '19일');
34436 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20일', '20일');
34437
34438 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21일', '21일');
34439 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22일', '22일');
34440 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23일', '23일');
34441 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24일', '24일');
34442 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25일', '25일');
34443 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26일', '26일');
34444 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27일', '27일');
34445 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28일', '28일');
34446 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29일', '29일');
34447 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30일', '30일');
34448
34449 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31일', '31일');
34450 });
34451
34452 test('format month', function (assert) {
34453 var expected = '1월 1월_2월 2월_3월 3월_4월 4월_5월 5월_6월 6월_7월 7월_8월 8월_9월 9월_10월 10월_11월 11월_12월 12월'.split('_'), i;
34454 for (i = 0; i < expected.length; i++) {
34455 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
34456 }
34457 });
34458
34459 test('format week', function (assert) {
34460 var expected = '일요일 일 일_월요일 월 월_화요일 화 화_수요일 수 수_목요일 목 목_금요일 금 금_토요일 토 토'.split('_'), i;
34461 for (i = 0; i < expected.length; i++) {
34462 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
34463 }
34464 });
34465
34466 test('from', function (assert) {
34467 var start = moment([2007, 1, 28]);
34468 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), '몇 초', '44초 = 몇 초');
34469 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '1분', '45초 = 1분');
34470 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '1분', '89초 = 1분');
34471 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2분', '90초 = 2분');
34472 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44분', '44분 = 44분');
34473 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '한 시간', '45분 = 한 시간');
34474 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '한 시간', '89분 = 한 시간');
34475 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2시간', '90분 = 2시간');
34476 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5시간', '5시간 = 5시간');
34477 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21시간', '21시간 = 21시간');
34478 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '하루', '22시간 = 하루');
34479 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '하루', '35시간 = 하루');
34480 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2일', '36시간 = 2일');
34481 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '하루', '하루 = 하루');
34482 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5일', '5일 = 5일');
34483 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25일', '25일 = 25일');
34484 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '한 달', '26일 = 한 달');
34485 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '한 달', '30일 = 한 달');
34486 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '한 달', '45일 = 한 달');
34487 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2달', '46일 = 2달');
34488 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2달', '75일 = 2달');
34489 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3달', '76일 = 3달');
34490 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '한 달', '1달 = 한 달');
34491 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5달', '5달 = 5달');
34492 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '일 년', '345일 = 일 년');
34493 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2년', '548일 = 2년');
34494 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '일 년', '일 년 = 일 년');
34495 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5년', '5년 = 5년');
34496 });
34497
34498 test('suffix', function (assert) {
34499 assert.equal(moment(30000).from(0), '몇 초 후', 'prefix');
34500 assert.equal(moment(0).from(30000), '몇 초 전', 'suffix');
34501 });
34502
34503 test('now from now', function (assert) {
34504 assert.equal(moment().fromNow(), '몇 초 전', 'now from now should display as in the past');
34505 });
34506
34507 test('fromNow', function (assert) {
34508 assert.equal(moment().add({s: 30}).fromNow(), '몇 초 후', 'in a few seconds');
34509 assert.equal(moment().add({d: 5}).fromNow(), '5일 후', 'in 5 days');
34510 });
34511
34512 test('calendar day', function (assert) {
34513 var a = moment().hours(12).minutes(0).seconds(0);
34514
34515 assert.equal(moment(a).calendar(), '오늘 오후 12:00', 'today at the same time');
34516 assert.equal(moment(a).add({m: 25}).calendar(), '오늘 오후 12:25', 'Now plus 25 min');
34517 assert.equal(moment(a).add({h: 1}).calendar(), '오늘 오후 1:00', 'Now plus 1 hour');
34518 assert.equal(moment(a).add({d: 1}).calendar(), '내일 오후 12:00', 'tomorrow at the same time');
34519 assert.equal(moment(a).subtract({h: 1}).calendar(), '오늘 오전 11:00', 'Now minus 1 hour');
34520 assert.equal(moment(a).subtract({d: 1}).calendar(), '어제 오후 12:00', 'yesterday at the same time');
34521 });
34522
34523 test('calendar next week', function (assert) {
34524 var i, m;
34525 for (i = 2; i < 7; i++) {
34526 m = moment().add({d: i});
34527 assert.equal(m.calendar(), m.format('dddd LT'), 'Today + ' + i + ' days current time');
34528 m.hours(0).minutes(0).seconds(0).milliseconds(0);
34529 assert.equal(m.calendar(), m.format('dddd LT'), 'Today + ' + i + ' days beginning of day');
34530 m.hours(23).minutes(59).seconds(59).milliseconds(999);
34531 assert.equal(m.calendar(), m.format('dddd LT'), 'Today + ' + i + ' days end of day');
34532 }
34533 });
516f5f67 34534
db71a655
KM
34535 test('calendar last week', function (assert) {
34536 var i, m;
34537 for (i = 2; i < 7; i++) {
34538 m = moment().subtract({d: i});
34539 assert.equal(m.calendar(), m.format('지난주 dddd LT'), 'Today - ' + i + ' days current time');
34540 m.hours(0).minutes(0).seconds(0).milliseconds(0);
34541 assert.equal(m.calendar(), m.format('지난주 dddd LT'), 'Today - ' + i + ' days beginning of day');
34542 m.hours(23).minutes(59).seconds(59).milliseconds(999);
34543 assert.equal(m.calendar(), m.format('지난주 dddd LT'), 'Today - ' + i + ' days end of day');
34544 }
34545 });
516f5f67 34546
db71a655
KM
34547 test('calendar all else', function (assert) {
34548 var weeksAgo = moment().subtract({w: 1}),
34549 weeksFromNow = moment().add({w: 1});
516f5f67 34550
db71a655
KM
34551 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
34552 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 34553
db71a655
KM
34554 weeksAgo = moment().subtract({w: 2});
34555 weeksFromNow = moment().add({w: 2});
f2af24d5 34556
db71a655
KM
34557 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
34558 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
34559 });
34560
34561 test('weeks year starting sunday format', function (assert) {
34562 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1주', 'Jan 1 2012 should be week 1');
34563 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1주', 'Jan 7 2012 should be week 1');
34564 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2주', 'Jan 8 2012 should be week 2');
34565 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2주', 'Jan 14 2012 should be week 2');
34566 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3주', 'Jan 15 2012 should be week 3');
34567 });
73f3c911
IC
34568
34569})));
34570
516f5f67 34571
c74a101d
IC
34572;(function (global, factory) {
34573 typeof exports === 'object' && typeof module !== 'undefined'
34574 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
34575 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
34576 factory(global.moment)
73f3c911 34577}(this, (function (moment) { 'use strict';
516f5f67 34578
db71a655
KM
34579 function each(array, callback) {
34580 var i;
34581 for (i = 0; i < array.length; i++) {
34582 callback(array[i], i, array);
34583 }
b135bf1a
IC
34584 }
34585
c58511b9
KM
34586 function setupDeprecationHandler(test, moment$$1, scope) {
34587 test._expectedDeprecations = null;
34588 test._observedDeprecations = null;
34589 test._oldSupress = moment$$1.suppressDeprecationWarnings;
34590 moment$$1.suppressDeprecationWarnings = true;
34591 test.expectedDeprecations = function () {
34592 test._expectedDeprecations = arguments;
34593 test._observedDeprecations = [];
34594 };
34595 moment$$1.deprecationHandler = function (name, msg) {
34596 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
34597 if (deprecationId === -1) {
34598 throw new Error('Unexpected deprecation thrown name=' +
34599 name + ' msg=' + msg);
34600 }
34601 test._observedDeprecations[deprecationId] = 1;
34602 };
34603 }
34604
34605 function teardownDeprecationHandler(test, moment$$1, scope) {
34606 moment$$1.suppressDeprecationWarnings = test._oldSupress;
34607
34608 if (test._expectedDeprecations != null) {
34609 var missedDeprecations = [];
34610 each(test._expectedDeprecations, function (deprecationPattern, id) {
34611 if (test._observedDeprecations[id] !== 1) {
34612 missedDeprecations.push(deprecationPattern);
34613 }
34614 });
34615 if (missedDeprecations.length !== 0) {
34616 throw new Error('Expected deprecation warnings did not happen: ' +
34617 missedDeprecations.join(' '));
34618 }
34619 }
34620 }
34621
34622 function matchedDeprecation(name, msg, deprecations) {
34623 if (deprecations == null) {
34624 return -1;
34625 }
34626 for (var i = 0; i < deprecations.length; ++i) {
34627 if (name != null && name === deprecations[i]) {
34628 return i;
34629 }
34630 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
34631 return i;
34632 }
34633 }
34634 return -1;
34635 }
34636
34637 /*global QUnit:false*/
34638
34639 var test = QUnit.test;
34640
db71a655
KM
34641 function objectKeys(obj) {
34642 if (Object.keys) {
34643 return Object.keys(obj);
34644 } else {
34645 // IE8
34646 var res = [], i;
34647 for (i in obj) {
34648 if (obj.hasOwnProperty(i)) {
34649 res.push(i);
34650 }
b135bf1a 34651 }
db71a655 34652 return res;
b135bf1a
IC
34653 }
34654 }
34655
db71a655 34656 // Pick the first defined of two or three arguments.
73f3c911 34657
db71a655
KM
34658 function defineCommonLocaleTests(locale, options) {
34659 test('lenient day of month ordinal parsing', function (assert) {
34660 var i, ordinalStr, testMoment;
34661 for (i = 1; i <= 31; ++i) {
34662 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
34663 testMoment = moment(ordinalStr, 'YYYY MM Do');
34664 assert.equal(testMoment.year(), 2014,
34665 'lenient day of month ordinal parsing ' + i + ' year check');
34666 assert.equal(testMoment.month(), 0,
34667 'lenient day of month ordinal parsing ' + i + ' month check');
34668 assert.equal(testMoment.date(), i,
34669 'lenient day of month ordinal parsing ' + i + ' date check');
34670 }
34671 });
73f3c911 34672
db71a655
KM
34673 test('lenient day of month ordinal parsing of number', function (assert) {
34674 var i, testMoment;
34675 for (i = 1; i <= 31; ++i) {
34676 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
34677 assert.equal(testMoment.year(), 2014,
34678 'lenient day of month ordinal parsing of number ' + i + ' year check');
34679 assert.equal(testMoment.month(), 0,
34680 'lenient day of month ordinal parsing of number ' + i + ' month check');
34681 assert.equal(testMoment.date(), i,
34682 'lenient day of month ordinal parsing of number ' + i + ' date check');
34683 }
34684 });
b135bf1a 34685
db71a655
KM
34686 test('strict day of month ordinal parsing', function (assert) {
34687 var i, ordinalStr, testMoment;
34688 for (i = 1; i <= 31; ++i) {
34689 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
34690 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
34691 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
34692 }
34693 });
b135bf1a 34694
db71a655
KM
34695 test('meridiem invariant', function (assert) {
34696 var h, m, t1, t2;
34697 for (h = 0; h < 24; ++h) {
34698 for (m = 0; m < 60; m += 15) {
34699 t1 = moment.utc([2000, 0, 1, h, m]);
34700 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
34701 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
34702 'meridiem at ' + t1.format('HH:mm'));
34703 }
34704 }
34705 });
34706
34707 test('date format correctness', function (assert) {
34708 var data, tokens;
34709 data = moment.localeData()._longDateFormat;
34710 tokens = objectKeys(data);
34711 each(tokens, function (srchToken) {
34712 // Check each format string to make sure it does not contain any
34713 // tokens that need to be expanded.
34714 each(tokens, function (baseToken) {
34715 // strip escaped sequences
34716 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
34717 assert.equal(false, !!~format.indexOf(srchToken),
34718 'contains ' + srchToken + ' in ' + baseToken);
34719 });
73f3c911 34720 });
b135bf1a
IC
34721 });
34722
db71a655
KM
34723 test('month parsing correctness', function (assert) {
34724 var i, m;
34725
34726 if (locale === 'tr') {
34727 // I can't fix it :(
c58511b9 34728 assert.expect(0);
db71a655
KM
34729 return;
34730 }
34731 function tester(format) {
34732 var r;
34733 r = moment(m.format(format), format);
34734 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
34735 if (locale !== 'ka') {
34736 r = moment(m.format(format).toLocaleUpperCase(), format);
34737 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
34738 }
db71a655
KM
34739 r = moment(m.format(format).toLocaleLowerCase(), format);
34740 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
34741
34742 r = moment(m.format(format), format, true);
34743 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
34744 if (locale !== 'ka') {
34745 r = moment(m.format(format).toLocaleUpperCase(), format, true);
34746 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
34747 }
db71a655
KM
34748 r = moment(m.format(format).toLocaleLowerCase(), format, true);
34749 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
34750 }
34751
34752 for (i = 0; i < 12; ++i) {
34753 m = moment([2015, i, 15, 18]);
34754 tester('MMM');
34755 tester('MMM.');
34756 tester('MMMM');
34757 tester('MMMM.');
34758 }
34759 });
b135bf1a 34760
db71a655
KM
34761 test('weekday parsing correctness', function (assert) {
34762 var i, m;
34763
96d0d679 34764 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
34765 // tr, az: There is a lower-case letter (ı), that converted to
34766 // upper then lower changes to i
34767 // ro: there is the letter ț which behaves weird under IE8
34768 // mt: letter Ħ
96d0d679 34769 // ga: month with spaces
c58511b9 34770 assert.expect(0);
db71a655
KM
34771 return;
34772 }
34773 function tester(format) {
34774 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
34775 r = moment(m.format(format), format);
34776 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
34777 if (locale !== 'ka') {
34778 r = moment(m.format(format).toLocaleUpperCase(), format);
34779 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
34780 }
db71a655
KM
34781 r = moment(m.format(format).toLocaleLowerCase(), format);
34782 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
34783 r = moment(m.format(format), format, true);
34784 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
34785 if (locale !== 'ka') {
34786 r = moment(m.format(format).toLocaleUpperCase(), format, true);
34787 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
34788 }
34789 r = moment(m.format(format).toLocaleLowerCase(), format, true);
34790 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
34791 }
34792
34793 for (i = 0; i < 7; ++i) {
34794 m = moment.utc([2015, 0, i + 1, 18]);
34795 tester('dd');
34796 tester('ddd');
34797 tester('dddd');
34798 }
34799 });
34800
34801 test('valid localeData', function (assert) {
34802 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
34803 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
34804 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
34805 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
34806 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
34807 });
96d0d679
KM
34808
34809 test('localeData weekdays can localeSort', function (assert) {
34810 var weekdays = moment().localeData().weekdays();
34811 var weekdaysShort = moment().localeData().weekdaysShort();
34812 var weekdaysMin = moment().localeData().weekdaysMin();
34813 var shift = moment().localeData()._week.dow;
34814 assert.deepEqual(
34815 moment().localeData().weekdays(true),
34816 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
34817 'weekdays should localeSort');
34818 assert.deepEqual(
34819 moment().localeData().weekdaysShort(true),
34820 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
34821 'weekdaysShort should localeSort');
34822 assert.deepEqual(
34823 moment().localeData().weekdaysMin(true),
34824 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
34825 'weekdaysMin should localeSort');
34826 });
b8f4fe2b
KM
34827 }
34828
34829 /*global QUnit:false*/
34830
34831 function localeModule (name, lifecycle) {
34832 QUnit.module('locale:' + name, {
34833 beforeEach : function () {
34834 moment.locale(name);
34835 moment.createFromInputFallback = function (config) {
34836 throw new Error('input not handled by moment: ' + config._i);
34837 };
34838 setupDeprecationHandler(test, moment, 'locale');
34839 if (lifecycle && lifecycle.setup) {
34840 lifecycle.setup();
34841 }
34842 },
34843 afterEach : function () {
34844 moment.locale('en');
34845 teardownDeprecationHandler(test, moment, 'locale');
34846 if (lifecycle && lifecycle.teardown) {
34847 lifecycle.teardown();
34848 }
34849 }
34850 });
34851 defineCommonLocaleTests(name, -1, -1);
34852 }
34853
34854 localeModule('ku');
34855
34856 var months = [
34857 'کانونی دووەم',
34858 'شوبات',
34859 'ئازار',
34860 'نیسان',
34861 'ئایار',
34862 'حوزەیران',
34863 'تەمموز',
34864 'ئاب',
34865 'ئەیلوول',
34866 'تشرینی یەكەم',
34867 'تشرینی دووەم',
34868 'كانونی یەکەم'
34869 ];
34870
34871 test('parse', function (assert) {
34872 var tests = months, i;
34873 function equalTest(input, mmm, i) {
34874 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1) + ' instead is month ' + moment(input, mmm).month());
34875 }
34876 for (i = 0; i < 12; i++) {
34877 equalTest(tests[i], 'MMM', i);
34878 equalTest(tests[i], 'MMM', i);
34879 equalTest(tests[i], 'MMMM', i);
34880 equalTest(tests[i], 'MMMM', i);
34881 equalTest(tests[i].toLocaleLowerCase(), 'MMMM', i);
34882 equalTest(tests[i].toLocaleLowerCase(), 'MMMM', i);
34883 equalTest(tests[i].toLocaleUpperCase(), 'MMMM', i);
34884 equalTest(tests[i].toLocaleUpperCase(), 'MMMM', i);
34885 }
34886 });
34887
34888 test('format', function (assert) {
34889 var a = [
34890 ['dddd, MMMM Do YYYY, h:mm:ss a', 'یه‌كشه‌ممه‌، شوبات ١٤ ٢٠١٠، ٣:٢٥:٥٠ ئێواره‌'],
34891 ['ddd, hA', 'یه‌كشه‌م، ٣ئێواره‌'],
34892 ['M Mo MM MMMM MMM', '٢ ٢ ٠٢ شوبات شوبات'],
34893 ['YYYY YY', '٢٠١٠ ١٠'],
34894 ['D Do DD', '١٤ ١٤ ١٤'],
34895 ['d do dddd ddd dd', '٠ ٠ یه‌كشه‌ممه‌ یه‌كشه‌م ی'],
34896 ['DDD DDDo DDDD', '٤٥ ٤٥ ٠٤٥'],
34897 ['w wo ww', '٨ ٨ ٠٨'],
34898 ['h hh', '٣ ٠٣'],
34899 ['H HH', '١٥ ١٥'],
34900 ['m mm', '٢٥ ٢٥'],
34901 ['s ss', '٥٠ ٥٠'],
34902 ['a A', 'ئێواره‌ ئێواره‌'],
34903 ['[the] DDDo [day of the year]', 'the ٤٥ day of the year'],
34904 ['LTS', '١٥:٢٥:٥٠'],
34905 ['L', '١٤/٠٢/٢٠١٠'],
34906 ['LL', '١٤ شوبات ٢٠١٠'],
34907 ['LLL', '١٤ شوبات ٢٠١٠ ١٥:٢٥'],
34908 ['LLLL', 'یه‌كشه‌ممه‌، ١٤ شوبات ٢٠١٠ ١٥:٢٥'],
34909 ['l', '١٤/٢/٢٠١٠'],
34910 ['ll', '١٤ شوبات ٢٠١٠'],
34911 ['lll', '١٤ شوبات ٢٠١٠ ١٥:٢٥'],
34912 ['llll', 'یه‌كشه‌م، ١٤ شوبات ٢٠١٠ ١٥:٢٥']
34913 ],
34914 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
34915 i;
34916 for (i = 0; i < a.length; i++) {
34917 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
34918 }
34919 });
34920
34921 test('format ordinal', function (assert) {
34922 assert.equal(moment([2011, 0, 1]).format('DDDo'), '١', '1');
34923 assert.equal(moment([2011, 0, 2]).format('DDDo'), '٢', '2');
34924 assert.equal(moment([2011, 0, 3]).format('DDDo'), '٣', '3');
34925 assert.equal(moment([2011, 0, 4]).format('DDDo'), '٤', '4');
34926 assert.equal(moment([2011, 0, 5]).format('DDDo'), '٥', '5');
34927 assert.equal(moment([2011, 0, 6]).format('DDDo'), '٦', '6');
34928 assert.equal(moment([2011, 0, 7]).format('DDDo'), '٧', '7');
34929 assert.equal(moment([2011, 0, 8]).format('DDDo'), '٨', '8');
34930 assert.equal(moment([2011, 0, 9]).format('DDDo'), '٩', '9');
34931 assert.equal(moment([2011, 0, 10]).format('DDDo'), '١٠', '10');
34932
34933 assert.equal(moment([2011, 0, 11]).format('DDDo'), '١١', '11');
34934 assert.equal(moment([2011, 0, 12]).format('DDDo'), '١٢', '12');
34935 assert.equal(moment([2011, 0, 13]).format('DDDo'), '١٣', '13');
34936 assert.equal(moment([2011, 0, 14]).format('DDDo'), '١٤', '14');
34937 assert.equal(moment([2011, 0, 15]).format('DDDo'), '١٥', '15');
34938 assert.equal(moment([2011, 0, 16]).format('DDDo'), '١٦', '16');
34939 assert.equal(moment([2011, 0, 17]).format('DDDo'), '١٧', '17');
34940 assert.equal(moment([2011, 0, 18]).format('DDDo'), '١٨', '18');
34941 assert.equal(moment([2011, 0, 19]).format('DDDo'), '١٩', '19');
34942 assert.equal(moment([2011, 0, 20]).format('DDDo'), '٢٠', '20');
34943
34944 assert.equal(moment([2011, 0, 21]).format('DDDo'), '٢١', '21');
34945 assert.equal(moment([2011, 0, 22]).format('DDDo'), '٢٢', '22');
34946 assert.equal(moment([2011, 0, 23]).format('DDDo'), '٢٣', '23');
34947 assert.equal(moment([2011, 0, 24]).format('DDDo'), '٢٤', '24');
34948 assert.equal(moment([2011, 0, 25]).format('DDDo'), '٢٥', '25');
34949 assert.equal(moment([2011, 0, 26]).format('DDDo'), '٢٦', '26');
34950 assert.equal(moment([2011, 0, 27]).format('DDDo'), '٢٧', '27');
34951 assert.equal(moment([2011, 0, 28]).format('DDDo'), '٢٨', '28');
34952 assert.equal(moment([2011, 0, 29]).format('DDDo'), '٢٩', '29');
34953 assert.equal(moment([2011, 0, 30]).format('DDDo'), '٣٠', '30');
34954 assert.equal(moment([2011, 0, 31]).format('DDDo'), '٣١', '31');
34955 });
34956 //ok
34957 test('format month', function (assert) {
34958 var expected = months, i;
34959 for (i = 0; i < expected.length; i++) {
34960 assert.equal(moment([2011, i, 1]).format('MMMM'), expected[i], expected[i]);
34961 assert.equal(moment([2011, i, 1]).format('MMM'), expected[i], expected[i]);
34962 }
34963 });
34964
34965 test('format week', function (assert) {
34966 var expected = 'یه‌كشه‌ممه‌ یه‌كشه‌م ی_دووشه‌ممه‌ دووشه‌م د_سێشه‌ممه‌ سێشه‌م س_چوارشه‌ممه‌ چوارشه‌م چ_پێنجشه‌ممه‌ پێنجشه‌م پ_هه‌ینی هه‌ینی ه_شه‌ممه‌ شه‌ممه‌ ش'.split('_'), i;
34967 for (i = 0; i < expected.length; i++) {
34968 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
34969 }
34970 });
34971
34972 test('from', function (assert) {
34973 var start = moment([2007, 1, 28]);
34974 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'چه‌ند چركه‌یه‌ك', '44 seconds = a few seconds');
34975 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'یه‌ك خوله‌ك', '45 seconds = a minute');
34976 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'یه‌ك خوله‌ك', '89 seconds = a minute');
34977 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '٢ خوله‌ك', '90 seconds = 2 minutes');
34978 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '٤٤ خوله‌ك', '44 minutes = 44 minutes');
34979 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'یه‌ك كاتژمێر', '45 minutes = an hour');
34980 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'یه‌ك كاتژمێر', '89 minutes = an hour');
34981 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '٢ كاتژمێر', '90 minutes = 2 hours');
34982 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '٥ كاتژمێر', '5 hours = 5 hours');
34983 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '٢١ كاتژمێر', '21 hours = 21 hours');
34984 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'یه‌ك ڕۆژ', '22 hours = a day');
34985 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'یه‌ك ڕۆژ', '35 hours = a day');
34986 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '٢ ڕۆژ', '36 hours = 2 days');
34987 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'یه‌ك ڕۆژ', '1 day = a day');
34988 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '٥ ڕۆژ', '5 days = 5 days');
34989 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '٢٥ ڕۆژ', '25 days = 25 days');
34990 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'یه‌ك مانگ', '26 days = a month');
34991 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'یه‌ك مانگ', '30 days = a month');
34992 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'یه‌ك مانگ', '43 days = a month');
34993 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '٢ مانگ', '46 days = 2 months');
34994 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '٢ مانگ', '75 days = 2 months');
34995 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '٣ مانگ', '76 days = 3 months');
34996 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'یه‌ك مانگ', '1 month = a month');
34997 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '٥ مانگ', '5 months = 5 months');
34998 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'یه‌ك ساڵ', '345 days = a year');
34999 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '٢ ساڵ', '548 days = 2 years');
35000 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'یه‌ك ساڵ', '1 year = a year');
35001 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '٥ ساڵ', '5 years = 5 years');
35002 });
35003
35004 test('suffix', function (assert) {
35005 assert.equal(moment(30000).from(0), 'له‌ چه‌ند چركه‌یه‌ك', 'prefix');
35006 assert.equal(moment(0).from(30000), 'چه‌ند چركه‌یه‌ك', 'suffix');
35007 });
35008
35009 test('now from now', function (assert) {
35010 assert.equal(moment().fromNow(), 'چه‌ند چركه‌یه‌ك', 'now from now should display as in the past');
35011 });
35012
35013 test('fromNow', function (assert) {
35014 assert.equal(moment().add({s: 30}).fromNow(), 'له‌ چه‌ند چركه‌یه‌ك', 'in a few seconds');
35015 assert.equal(moment().add({d: 5}).fromNow(), 'له‌ ٥ ڕۆژ', 'in 5 days');
35016 });
35017
35018 test('calendar day', function (assert) {
35019 var a = moment().hours(12).minutes(0).seconds(0);
35020
35021 assert.equal(moment(a).calendar(), 'ئه‌مرۆ كاتژمێر ١٢:٠٠', 'today at the same time');
35022 assert.equal(moment(a).add({m: 25}).calendar(), 'ئه‌مرۆ كاتژمێر ١٢:٢٥', 'Now plus 25 min');
35023 assert.equal(moment(a).add({h: 1}).calendar(), 'ئه‌مرۆ كاتژمێر ١٣:٠٠', 'Now plus 1 hour');
35024 assert.equal(moment(a).add({d: 1}).calendar(), 'به‌یانی كاتژمێر ١٢:٠٠', 'tomorrow at the same time');
35025 assert.equal(moment(a).subtract({h: 1}).calendar(), 'ئه‌مرۆ كاتژمێر ١١:٠٠', 'Now minus 1 hour');
35026 assert.equal(moment(a).subtract({d: 1}).calendar(), 'دوێنێ كاتژمێر ١٢:٠٠', 'yesterday at the same time');
35027 });
35028
35029 test('calendar next week', function (assert) {
35030 var i, m;
35031 for (i = 2; i < 7; i++) {
35032 m = moment().add({d: i});
35033 assert.equal(m.calendar(), m.format('dddd [كاتژمێر] LT'), 'Today + ' + i + ' days current time');
35034 m.hours(0).minutes(0).seconds(0).milliseconds(0);
35035 assert.equal(m.calendar(), m.format('dddd [كاتژمێر] LT'), 'Today + ' + i + ' days beginning of day');
35036 m.hours(23).minutes(59).seconds(59).milliseconds(999);
35037 assert.equal(m.calendar(), m.format('dddd [كاتژمێر] LT'), 'Today + ' + i + ' days end of day');
35038 }
35039 });
35040
35041 test('calendar last week', function (assert) {
35042 var i, m;
35043
35044 for (i = 2; i < 7; i++) {
35045 m = moment().subtract({d: i});
35046 assert.equal(m.calendar(), m.format('dddd [كاتژمێر] LT'), 'Today - ' + i + ' days current time');
35047 m.hours(0).minutes(0).seconds(0).milliseconds(0);
35048 assert.equal(m.calendar(), m.format('dddd [كاتژمێر] LT'), 'Today - ' + i + ' days beginning of day');
35049 m.hours(23).minutes(59).seconds(59).milliseconds(999);
35050 assert.equal(m.calendar(), m.format('dddd [كاتژمێر] LT'), 'Today - ' + i + ' days end of day');
35051 }
35052 });
35053
35054 test('calendar all else', function (assert) {
35055 var weeksAgo = moment().subtract({w: 1}),
35056 weeksFromNow = moment().add({w: 1});
35057
35058 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
35059 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
35060
35061 weeksAgo = moment().subtract({w: 2});
35062 weeksFromNow = moment().add({w: 2});
35063
35064 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
35065 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
35066 });
35067
35068 test('weeks year starting sunday formatted', function (assert) {
35069 assert.equal(moment([2011, 11, 31]).format('w ww wo'), '١ ٠١ ١', 'Dec 31 2011 should be week 1');
35070 assert.equal(moment([2012, 0, 6]).format('w ww wo'), '١ ٠١ ١', 'Jan 6 2012 should be week 1');
35071 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '٢ ٠٢ ٢', 'Jan 7 2012 should be week 2');
35072 assert.equal(moment([2012, 0, 13]).format('w ww wo'), '٢ ٠٢ ٢', 'Jan 13 2012 should be week 2');
35073 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '٣ ٠٣ ٣', 'Jan 14 2012 should be week 3');
35074 });
35075
35076
35077 // locale-specific
35078 test('ku strict mode parsing works', function (assert) {
35079 var m, formattedDate;
35080 m = moment().locale('ku');
35081 formattedDate = m.format('l');
35082 assert.equal(moment.utc(formattedDate, 'l', 'ku', false).isValid(), true, 'Non-strict parsing works');
35083 assert.equal(moment.utc(formattedDate, 'l', 'ku', true).isValid(), true,'Strict parsing must work');
35084 });
35085
35086})));
35087
35088
35089;(function (global, factory) {
35090 typeof exports === 'object' && typeof module !== 'undefined'
35091 && typeof require === 'function' ? factory(require('../../moment')) :
35092 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
35093 factory(global.moment)
35094}(this, (function (moment) { 'use strict';
35095
35096 function each(array, callback) {
35097 var i;
35098 for (i = 0; i < array.length; i++) {
35099 callback(array[i], i, array);
35100 }
35101 }
35102
35103 function setupDeprecationHandler(test, moment$$1, scope) {
35104 test._expectedDeprecations = null;
35105 test._observedDeprecations = null;
35106 test._oldSupress = moment$$1.suppressDeprecationWarnings;
35107 moment$$1.suppressDeprecationWarnings = true;
35108 test.expectedDeprecations = function () {
35109 test._expectedDeprecations = arguments;
35110 test._observedDeprecations = [];
35111 };
35112 moment$$1.deprecationHandler = function (name, msg) {
35113 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
35114 if (deprecationId === -1) {
35115 throw new Error('Unexpected deprecation thrown name=' +
35116 name + ' msg=' + msg);
35117 }
35118 test._observedDeprecations[deprecationId] = 1;
35119 };
35120 }
35121
35122 function teardownDeprecationHandler(test, moment$$1, scope) {
35123 moment$$1.suppressDeprecationWarnings = test._oldSupress;
35124
35125 if (test._expectedDeprecations != null) {
35126 var missedDeprecations = [];
35127 each(test._expectedDeprecations, function (deprecationPattern, id) {
35128 if (test._observedDeprecations[id] !== 1) {
35129 missedDeprecations.push(deprecationPattern);
35130 }
35131 });
35132 if (missedDeprecations.length !== 0) {
35133 throw new Error('Expected deprecation warnings did not happen: ' +
35134 missedDeprecations.join(' '));
35135 }
35136 }
35137 }
35138
35139 function matchedDeprecation(name, msg, deprecations) {
35140 if (deprecations == null) {
35141 return -1;
35142 }
35143 for (var i = 0; i < deprecations.length; ++i) {
35144 if (name != null && name === deprecations[i]) {
35145 return i;
35146 }
35147 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
35148 return i;
35149 }
35150 }
35151 return -1;
35152 }
35153
35154 /*global QUnit:false*/
35155
35156 var test = QUnit.test;
35157
35158 function objectKeys(obj) {
35159 if (Object.keys) {
35160 return Object.keys(obj);
35161 } else {
35162 // IE8
35163 var res = [], i;
35164 for (i in obj) {
35165 if (obj.hasOwnProperty(i)) {
35166 res.push(i);
35167 }
35168 }
35169 return res;
35170 }
35171 }
35172
35173 // Pick the first defined of two or three arguments.
35174
35175 function defineCommonLocaleTests(locale, options) {
35176 test('lenient day of month ordinal parsing', function (assert) {
35177 var i, ordinalStr, testMoment;
35178 for (i = 1; i <= 31; ++i) {
35179 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
35180 testMoment = moment(ordinalStr, 'YYYY MM Do');
35181 assert.equal(testMoment.year(), 2014,
35182 'lenient day of month ordinal parsing ' + i + ' year check');
35183 assert.equal(testMoment.month(), 0,
35184 'lenient day of month ordinal parsing ' + i + ' month check');
35185 assert.equal(testMoment.date(), i,
35186 'lenient day of month ordinal parsing ' + i + ' date check');
35187 }
35188 });
35189
35190 test('lenient day of month ordinal parsing of number', function (assert) {
35191 var i, testMoment;
35192 for (i = 1; i <= 31; ++i) {
35193 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
35194 assert.equal(testMoment.year(), 2014,
35195 'lenient day of month ordinal parsing of number ' + i + ' year check');
35196 assert.equal(testMoment.month(), 0,
35197 'lenient day of month ordinal parsing of number ' + i + ' month check');
35198 assert.equal(testMoment.date(), i,
35199 'lenient day of month ordinal parsing of number ' + i + ' date check');
35200 }
35201 });
35202
35203 test('strict day of month ordinal parsing', function (assert) {
35204 var i, ordinalStr, testMoment;
35205 for (i = 1; i <= 31; ++i) {
35206 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
35207 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
35208 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
35209 }
35210 });
35211
35212 test('meridiem invariant', function (assert) {
35213 var h, m, t1, t2;
35214 for (h = 0; h < 24; ++h) {
35215 for (m = 0; m < 60; m += 15) {
35216 t1 = moment.utc([2000, 0, 1, h, m]);
35217 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
35218 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
35219 'meridiem at ' + t1.format('HH:mm'));
35220 }
35221 }
35222 });
35223
35224 test('date format correctness', function (assert) {
35225 var data, tokens;
35226 data = moment.localeData()._longDateFormat;
35227 tokens = objectKeys(data);
35228 each(tokens, function (srchToken) {
35229 // Check each format string to make sure it does not contain any
35230 // tokens that need to be expanded.
35231 each(tokens, function (baseToken) {
35232 // strip escaped sequences
35233 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
35234 assert.equal(false, !!~format.indexOf(srchToken),
35235 'contains ' + srchToken + ' in ' + baseToken);
35236 });
35237 });
35238 });
35239
35240 test('month parsing correctness', function (assert) {
35241 var i, m;
35242
35243 if (locale === 'tr') {
35244 // I can't fix it :(
35245 assert.expect(0);
35246 return;
35247 }
35248 function tester(format) {
35249 var r;
35250 r = moment(m.format(format), format);
35251 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
35252 if (locale !== 'ka') {
35253 r = moment(m.format(format).toLocaleUpperCase(), format);
35254 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
35255 }
35256 r = moment(m.format(format).toLocaleLowerCase(), format);
35257 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
35258
35259 r = moment(m.format(format), format, true);
35260 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
35261 if (locale !== 'ka') {
35262 r = moment(m.format(format).toLocaleUpperCase(), format, true);
35263 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
35264 }
35265 r = moment(m.format(format).toLocaleLowerCase(), format, true);
35266 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
35267 }
35268
35269 for (i = 0; i < 12; ++i) {
35270 m = moment([2015, i, 15, 18]);
35271 tester('MMM');
35272 tester('MMM.');
35273 tester('MMMM');
35274 tester('MMMM.');
35275 }
35276 });
35277
35278 test('weekday parsing correctness', function (assert) {
35279 var i, m;
35280
96d0d679 35281 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
b8f4fe2b
KM
35282 // tr, az: There is a lower-case letter (ı), that converted to
35283 // upper then lower changes to i
35284 // ro: there is the letter ț which behaves weird under IE8
35285 // mt: letter Ħ
96d0d679 35286 // ga: month with spaces
b8f4fe2b
KM
35287 assert.expect(0);
35288 return;
35289 }
35290 function tester(format) {
35291 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
35292 r = moment(m.format(format), format);
35293 assert.equal(r.weekday(), m.weekday(), baseMsg);
35294 if (locale !== 'ka') {
35295 r = moment(m.format(format).toLocaleUpperCase(), format);
35296 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
35297 }
35298 r = moment(m.format(format).toLocaleLowerCase(), format);
35299 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
35300 r = moment(m.format(format), format, true);
35301 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
35302 if (locale !== 'ka') {
35303 r = moment(m.format(format).toLocaleUpperCase(), format, true);
35304 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
35305 }
db71a655
KM
35306 r = moment(m.format(format).toLocaleLowerCase(), format, true);
35307 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
35308 }
35309
35310 for (i = 0; i < 7; ++i) {
35311 m = moment.utc([2015, 0, i + 1, 18]);
35312 tester('dd');
35313 tester('ddd');
35314 tester('dddd');
35315 }
35316 });
b135bf1a 35317
db71a655
KM
35318 test('valid localeData', function (assert) {
35319 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
35320 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
35321 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
35322 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
35323 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
35324 });
96d0d679
KM
35325
35326 test('localeData weekdays can localeSort', function (assert) {
35327 var weekdays = moment().localeData().weekdays();
35328 var weekdaysShort = moment().localeData().weekdaysShort();
35329 var weekdaysMin = moment().localeData().weekdaysMin();
35330 var shift = moment().localeData()._week.dow;
35331 assert.deepEqual(
35332 moment().localeData().weekdays(true),
35333 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
35334 'weekdays should localeSort');
35335 assert.deepEqual(
35336 moment().localeData().weekdaysShort(true),
35337 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
35338 'weekdaysShort should localeSort');
35339 assert.deepEqual(
35340 moment().localeData().weekdaysMin(true),
35341 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
35342 'weekdaysMin should localeSort');
35343 });
db71a655 35344 }
d6651c21 35345
db71a655 35346 /*global QUnit:false*/
f2af24d5 35347
db71a655
KM
35348 function localeModule (name, lifecycle) {
35349 QUnit.module('locale:' + name, {
c58511b9 35350 beforeEach : function () {
db71a655
KM
35351 moment.locale(name);
35352 moment.createFromInputFallback = function (config) {
35353 throw new Error('input not handled by moment: ' + config._i);
35354 };
35355 setupDeprecationHandler(test, moment, 'locale');
35356 if (lifecycle && lifecycle.setup) {
35357 lifecycle.setup();
35358 }
35359 },
c58511b9 35360 afterEach : function () {
db71a655
KM
35361 moment.locale('en');
35362 teardownDeprecationHandler(test, moment, 'locale');
35363 if (lifecycle && lifecycle.teardown) {
35364 lifecycle.teardown();
35365 }
f2af24d5
IC
35366 }
35367 });
db71a655
KM
35368 defineCommonLocaleTests(name, -1, -1);
35369 }
35370
35371 localeModule('ky');
35372
35373 test('parse', function (assert) {
35374 var tests = 'январь янв_февраль фев_март март_апрель апр_май май_июнь июнь_июль июль_август авг_сентябрь сен_октябрь окт_ноябрь ноя_декабрь дек'.split('_'), i;
35375 function equalTest(input, mmm, i) {
35376 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
35377 }
35378 for (i = 0; i < 12; i++) {
35379 tests[i] = tests[i].split(' ');
35380 equalTest(tests[i][0], 'MMM', i);
35381 equalTest(tests[i][1], 'MMM', i);
35382 equalTest(tests[i][0], 'MMMM', i);
35383 equalTest(tests[i][1], 'MMMM', i);
35384 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
35385 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
35386 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
35387 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
35388 }
35389 });
35390
35391 test('format', function (assert) {
35392 var a = [
35393 ['dddd, Do MMMM YYYY, HH:mm:ss', 'Жекшемби, 14-чү февраль 2010, 15:25:50'],
35394 ['ddd, hA', 'Жек, 3PM'],
35395 ['M Mo MM MMMM MMM', '2 2-чи 02 февраль фев'],
35396 ['YYYY YY', '2010 10'],
35397 ['D Do DD', '14 14-чү 14'],
35398 ['d do dddd ddd dd', '0 0-чү Жекшемби Жек Жк'],
35399 ['DDD DDDo DDDD', '45 45-чи 045'],
35400 ['w wo ww', '7 7-чи 07'],
35401 ['h hh', '3 03'],
35402 ['H HH', '15 15'],
35403 ['m mm', '25 25'],
35404 ['s ss', '50 50'],
35405 ['a A', 'pm PM'],
35406 ['[жылдын] DDDo [күнү]', 'жылдын 45-чи күнү'],
35407 ['LTS', '15:25:50'],
35408 ['L', '14.02.2010'],
35409 ['LL', '14 февраль 2010'],
35410 ['LLL', '14 февраль 2010 15:25'],
35411 ['LLLL', 'Жекшемби, 14 февраль 2010 15:25'],
35412 ['l', '14.2.2010'],
35413 ['ll', '14 фев 2010'],
35414 ['lll', '14 фев 2010 15:25'],
35415 ['llll', 'Жек, 14 фев 2010 15:25']
35416 ],
35417 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
35418 i;
35419 for (i = 0; i < a.length; i++) {
35420 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
35421 }
35422 });
35423
35424 test('format ordinal', function (assert) {
35425 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-чи', '1st');
35426 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-чи', '2nd');
35427 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-чү', '3rd');
35428 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-чү', '4th');
35429 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-чи', '5th');
35430 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-чы', '6th');
35431 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-чи', '7th');
35432 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-чи', '8th');
35433 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-чу', '9th');
35434 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-чу', '10th');
35435
35436 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-чи', '11th');
35437 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-чи', '12th');
35438 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-чү', '13th');
35439 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-чү', '14th');
35440 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-чи', '15th');
35441 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-чы', '16th');
35442 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-чи', '17th');
35443 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-чи', '18th');
35444 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-чу', '19th');
35445 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-чы', '20th');
35446
35447 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-чи', '21st');
35448 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-чи', '22nd');
35449 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-чү', '23rd');
35450 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-чү', '24th');
35451 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-чи', '25th');
35452 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-чы', '26th');
35453 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-чи', '27th');
35454 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-чи', '28th');
35455 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-чу', '29th');
35456 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-чу', '30th');
35457
35458 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-чи', '31st');
35459 });
35460
35461 test('format month', function (assert) {
35462 var expected = 'январь янв_февраль фев_март март_апрель апр_май май_июнь июнь_июль июль_август авг_сентябрь сен_октябрь окт_ноябрь ноя_декабрь дек'.split('_'), i;
35463 for (i = 0; i < expected.length; i++) {
35464 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
35465 }
35466 });
35467
35468 test('format week', function (assert) {
35469 var expected = 'Жекшемби Жек Жк_Дүйшөмбү Дүй Дй_Шейшемби Шей Шй_Шаршемби Шар Шр_Бейшемби Бей Бй_Жума Жум Жм_Ишемби Ише Иш'.split('_'), i;
35470 for (i = 0; i < expected.length; i++) {
35471 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
35472 }
35473 });
35474
35475 test('from', function (assert) {
35476 var start = moment([2007, 1, 28]);
35477 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'бирнече секунд', '44 seconds = a few seconds');
35478 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'бир мүнөт', '45 seconds = a minute');
35479 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'бир мүнөт', '89 seconds = a minute');
35480 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 мүнөт', '90 seconds = 2 minutes');
35481 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 мүнөт', '44 minutes = 44 minutes');
35482 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'бир саат', '45 minutes = an hour');
35483 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'бир саат', '89 minutes = an hour');
35484 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 саат', '90 minutes = 2 hours');
35485 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 саат', '5 hours = 5 hours');
35486 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 саат', '21 hours = 21 hours');
35487 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'бир күн', '22 hours = a day');
35488 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'бир күн', '35 hours = a day');
35489 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 күн', '36 hours = 2 days');
35490 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'бир күн', '1 day = a day');
35491 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 күн', '5 days = 5 days');
35492 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 күн', '25 days = 25 days');
35493 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'бир ай', '26 days = a month');
35494 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'бир ай', '30 days = a month');
35495 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'бир ай', '43 days = a month');
35496 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 ай', '46 days = 2 months');
35497 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 ай', '75 days = 2 months');
35498 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 ай', '76 days = 3 months');
35499 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'бир ай', '1 month = a month');
35500 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 ай', '5 months = 5 months');
35501 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'бир жыл', '345 days = a year');
35502 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 жыл', '548 days = 2 years');
35503 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'бир жыл', '1 year = a year');
35504 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 жыл', '5 years = 5 years');
35505 });
35506
35507 test('suffix', function (assert) {
35508 assert.equal(moment(30000).from(0), 'бирнече секунд ичинде', 'prefix');
35509 assert.equal(moment(0).from(30000), 'бирнече секунд мурун', 'suffix');
35510 });
35511
35512 test('now from now', function (assert) {
35513 assert.equal(moment().fromNow(), 'бирнече секунд мурун', 'now from now should display as in the past');
35514 });
35515
35516 test('fromNow', function (assert) {
35517 assert.equal(moment().add({s: 30}).fromNow(), 'бирнече секунд ичинде', 'in a few seconds');
35518 assert.equal(moment().add({d: 5}).fromNow(), '5 күн ичинде', 'in 5 days');
35519 });
35520
35521 test('calendar day', function (assert) {
35522 var a = moment().hours(12).minutes(0).seconds(0);
35523
35524 assert.equal(moment(a).calendar(), 'Бүгүн саат 12:00', 'today at the same time');
35525 assert.equal(moment(a).add({m: 25}).calendar(), 'Бүгүн саат 12:25', 'Now plus 25 min');
35526 assert.equal(moment(a).add({h: 1}).calendar(), 'Бүгүн саат 13:00', 'Now plus 1 hour');
35527 assert.equal(moment(a).add({d: 1}).calendar(), 'Эртең саат 12:00', 'tomorrow at the same time');
35528 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Бүгүн саат 11:00', 'Now minus 1 hour');
b8f4fe2b 35529 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Кечээ саат 12:00', 'yesterday at the same time');
db71a655
KM
35530 });
35531
35532 test('calendar next week', function (assert) {
35533 var i, m;
35534 for (i = 2; i < 7; i++) {
35535 m = moment().add({d: i});
35536 assert.equal(m.calendar(), m.format('dddd [саат] LT'), 'Today + ' + i + ' days current time');
35537 m.hours(0).minutes(0).seconds(0).milliseconds(0);
35538 assert.equal(m.calendar(), m.format('dddd [саат] LT'), 'Today + ' + i + ' days beginning of day');
35539 m.hours(23).minutes(59).seconds(59).milliseconds(999);
35540 assert.equal(m.calendar(), m.format('dddd [саат] LT'), 'Today + ' + i + ' days end of day');
f2af24d5 35541 }
db71a655 35542 });
f2af24d5 35543
db71a655
KM
35544 test('calendar last week', function (assert) {
35545 var i, m;
35546
35547 for (i = 2; i < 7; i++) {
35548 m = moment().subtract({d: i});
b8f4fe2b 35549 assert.equal(m.calendar(), m.format('[Өткөн аптанын] dddd [күнү] [саат] LT'), 'Today - ' + i + ' days current time');
db71a655 35550 m.hours(0).minutes(0).seconds(0).milliseconds(0);
b8f4fe2b 35551 assert.equal(m.calendar(), m.format('[Өткөн аптанын] dddd [күнү] [саат] LT'), 'Today - ' + i + ' days beginning of day');
db71a655 35552 m.hours(23).minutes(59).seconds(59).milliseconds(999);
b8f4fe2b 35553 assert.equal(m.calendar(), m.format('[Өткөн аптанын] dddd [күнү] [саат] LT'), 'Today - ' + i + ' days end of day');
f2af24d5 35554 }
db71a655 35555 });
f2af24d5 35556
db71a655
KM
35557 test('calendar all else', function (assert) {
35558 var weeksAgo = moment().subtract({w: 1}),
35559 weeksFromNow = moment().add({w: 1});
f2af24d5 35560
db71a655
KM
35561 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
35562 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
f2af24d5 35563
db71a655
KM
35564 weeksAgo = moment().subtract({w: 2});
35565 weeksFromNow = moment().add({w: 2});
f2af24d5 35566
db71a655
KM
35567 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
35568 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
35569 });
35570
35571 test('weeks year starting sunday formatted', function (assert) {
35572 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-чи', 'Jan 1 2012 should be week 1');
35573 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-чи', 'Jan 2 2012 should be week 2');
35574 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-чи', 'Jan 8 2012 should be week 2');
35575 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-чү', 'Jan 9 2012 should be week 3');
35576 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3-чү', 'Jan 15 2012 should be week 3');
35577 });
f2af24d5
IC
35578
35579})));
35580
35581
35582;(function (global, factory) {
35583 typeof exports === 'object' && typeof module !== 'undefined'
35584 && typeof require === 'function' ? factory(require('../../moment')) :
35585 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
35586 factory(global.moment)
35587}(this, (function (moment) { 'use strict';
35588
db71a655
KM
35589 function each(array, callback) {
35590 var i;
35591 for (i = 0; i < array.length; i++) {
35592 callback(array[i], i, array);
35593 }
f2af24d5 35594 }
f2af24d5 35595
c58511b9
KM
35596 function setupDeprecationHandler(test, moment$$1, scope) {
35597 test._expectedDeprecations = null;
35598 test._observedDeprecations = null;
35599 test._oldSupress = moment$$1.suppressDeprecationWarnings;
35600 moment$$1.suppressDeprecationWarnings = true;
35601 test.expectedDeprecations = function () {
35602 test._expectedDeprecations = arguments;
35603 test._observedDeprecations = [];
35604 };
35605 moment$$1.deprecationHandler = function (name, msg) {
35606 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
35607 if (deprecationId === -1) {
35608 throw new Error('Unexpected deprecation thrown name=' +
35609 name + ' msg=' + msg);
35610 }
35611 test._observedDeprecations[deprecationId] = 1;
35612 };
35613 }
35614
35615 function teardownDeprecationHandler(test, moment$$1, scope) {
35616 moment$$1.suppressDeprecationWarnings = test._oldSupress;
35617
35618 if (test._expectedDeprecations != null) {
35619 var missedDeprecations = [];
35620 each(test._expectedDeprecations, function (deprecationPattern, id) {
35621 if (test._observedDeprecations[id] !== 1) {
35622 missedDeprecations.push(deprecationPattern);
35623 }
35624 });
35625 if (missedDeprecations.length !== 0) {
35626 throw new Error('Expected deprecation warnings did not happen: ' +
35627 missedDeprecations.join(' '));
35628 }
35629 }
35630 }
35631
35632 function matchedDeprecation(name, msg, deprecations) {
35633 if (deprecations == null) {
35634 return -1;
35635 }
35636 for (var i = 0; i < deprecations.length; ++i) {
35637 if (name != null && name === deprecations[i]) {
35638 return i;
35639 }
35640 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
35641 return i;
35642 }
35643 }
35644 return -1;
35645 }
35646
35647 /*global QUnit:false*/
35648
35649 var test = QUnit.test;
35650
db71a655
KM
35651 function objectKeys(obj) {
35652 if (Object.keys) {
35653 return Object.keys(obj);
35654 } else {
35655 // IE8
35656 var res = [], i;
35657 for (i in obj) {
35658 if (obj.hasOwnProperty(i)) {
35659 res.push(i);
35660 }
f2af24d5 35661 }
db71a655 35662 return res;
f2af24d5 35663 }
f2af24d5 35664 }
f2af24d5 35665
db71a655 35666 // Pick the first defined of two or three arguments.
f2af24d5 35667
db71a655
KM
35668 function defineCommonLocaleTests(locale, options) {
35669 test('lenient day of month ordinal parsing', function (assert) {
35670 var i, ordinalStr, testMoment;
35671 for (i = 1; i <= 31; ++i) {
35672 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
35673 testMoment = moment(ordinalStr, 'YYYY MM Do');
35674 assert.equal(testMoment.year(), 2014,
35675 'lenient day of month ordinal parsing ' + i + ' year check');
35676 assert.equal(testMoment.month(), 0,
35677 'lenient day of month ordinal parsing ' + i + ' month check');
35678 assert.equal(testMoment.date(), i,
35679 'lenient day of month ordinal parsing ' + i + ' date check');
35680 }
35681 });
35682
35683 test('lenient day of month ordinal parsing of number', function (assert) {
35684 var i, testMoment;
35685 for (i = 1; i <= 31; ++i) {
35686 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
35687 assert.equal(testMoment.year(), 2014,
35688 'lenient day of month ordinal parsing of number ' + i + ' year check');
35689 assert.equal(testMoment.month(), 0,
35690 'lenient day of month ordinal parsing of number ' + i + ' month check');
35691 assert.equal(testMoment.date(), i,
35692 'lenient day of month ordinal parsing of number ' + i + ' date check');
35693 }
35694 });
35695
35696 test('strict day of month ordinal parsing', function (assert) {
35697 var i, ordinalStr, testMoment;
35698 for (i = 1; i <= 31; ++i) {
35699 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
35700 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
35701 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
35702 }
35703 });
35704
35705 test('meridiem invariant', function (assert) {
35706 var h, m, t1, t2;
35707 for (h = 0; h < 24; ++h) {
35708 for (m = 0; m < 60; m += 15) {
35709 t1 = moment.utc([2000, 0, 1, h, m]);
35710 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
35711 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
35712 'meridiem at ' + t1.format('HH:mm'));
35713 }
35714 }
35715 });
35716
35717 test('date format correctness', function (assert) {
35718 var data, tokens;
35719 data = moment.localeData()._longDateFormat;
35720 tokens = objectKeys(data);
35721 each(tokens, function (srchToken) {
35722 // Check each format string to make sure it does not contain any
35723 // tokens that need to be expanded.
35724 each(tokens, function (baseToken) {
35725 // strip escaped sequences
35726 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
35727 assert.equal(false, !!~format.indexOf(srchToken),
35728 'contains ' + srchToken + ' in ' + baseToken);
35729 });
35730 });
35731 });
35732
35733 test('month parsing correctness', function (assert) {
35734 var i, m;
35735
35736 if (locale === 'tr') {
35737 // I can't fix it :(
c58511b9 35738 assert.expect(0);
db71a655
KM
35739 return;
35740 }
35741 function tester(format) {
35742 var r;
35743 r = moment(m.format(format), format);
35744 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
35745 if (locale !== 'ka') {
35746 r = moment(m.format(format).toLocaleUpperCase(), format);
35747 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
35748 }
db71a655
KM
35749 r = moment(m.format(format).toLocaleLowerCase(), format);
35750 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
35751
35752 r = moment(m.format(format), format, true);
35753 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
35754 if (locale !== 'ka') {
35755 r = moment(m.format(format).toLocaleUpperCase(), format, true);
35756 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
35757 }
db71a655
KM
35758 r = moment(m.format(format).toLocaleLowerCase(), format, true);
35759 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
35760 }
35761
35762 for (i = 0; i < 12; ++i) {
35763 m = moment([2015, i, 15, 18]);
35764 tester('MMM');
35765 tester('MMM.');
35766 tester('MMMM');
35767 tester('MMMM.');
35768 }
35769 });
35770
35771 test('weekday parsing correctness', function (assert) {
35772 var i, m;
35773
96d0d679 35774 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
35775 // tr, az: There is a lower-case letter (ı), that converted to
35776 // upper then lower changes to i
35777 // ro: there is the letter ț which behaves weird under IE8
35778 // mt: letter Ħ
96d0d679 35779 // ga: month with spaces
c58511b9 35780 assert.expect(0);
db71a655
KM
35781 return;
35782 }
35783 function tester(format) {
35784 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
35785 r = moment(m.format(format), format);
35786 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
35787 if (locale !== 'ka') {
35788 r = moment(m.format(format).toLocaleUpperCase(), format);
35789 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
35790 }
db71a655
KM
35791 r = moment(m.format(format).toLocaleLowerCase(), format);
35792 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
35793 r = moment(m.format(format), format, true);
35794 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
35795 if (locale !== 'ka') {
35796 r = moment(m.format(format).toLocaleUpperCase(), format, true);
35797 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
35798 }
db71a655
KM
35799 r = moment(m.format(format).toLocaleLowerCase(), format, true);
35800 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
35801 }
35802
35803 for (i = 0; i < 7; ++i) {
35804 m = moment.utc([2015, 0, i + 1, 18]);
35805 tester('dd');
35806 tester('ddd');
35807 tester('dddd');
35808 }
35809 });
35810
35811 test('valid localeData', function (assert) {
35812 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
35813 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
35814 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
35815 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
35816 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
35817 });
96d0d679
KM
35818
35819 test('localeData weekdays can localeSort', function (assert) {
35820 var weekdays = moment().localeData().weekdays();
35821 var weekdaysShort = moment().localeData().weekdaysShort();
35822 var weekdaysMin = moment().localeData().weekdaysMin();
35823 var shift = moment().localeData()._week.dow;
35824 assert.deepEqual(
35825 moment().localeData().weekdays(true),
35826 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
35827 'weekdays should localeSort');
35828 assert.deepEqual(
35829 moment().localeData().weekdaysShort(true),
35830 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
35831 'weekdaysShort should localeSort');
35832 assert.deepEqual(
35833 moment().localeData().weekdaysMin(true),
35834 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
35835 'weekdaysMin should localeSort');
35836 });
db71a655
KM
35837 }
35838
db71a655
KM
35839 /*global QUnit:false*/
35840
db71a655
KM
35841 function localeModule (name, lifecycle) {
35842 QUnit.module('locale:' + name, {
c58511b9 35843 beforeEach : function () {
db71a655
KM
35844 moment.locale(name);
35845 moment.createFromInputFallback = function (config) {
35846 throw new Error('input not handled by moment: ' + config._i);
35847 };
35848 setupDeprecationHandler(test, moment, 'locale');
35849 if (lifecycle && lifecycle.setup) {
35850 lifecycle.setup();
35851 }
35852 },
c58511b9 35853 afterEach : function () {
db71a655
KM
35854 moment.locale('en');
35855 teardownDeprecationHandler(test, moment, 'locale');
35856 if (lifecycle && lifecycle.teardown) {
35857 lifecycle.teardown();
35858 }
35859 }
35860 });
35861 defineCommonLocaleTests(name, -1, -1);
35862 }
35863
35864 localeModule('lb');
35865
35866 test('parse', function (assert) {
35867 var tests = 'Januar Jan._Februar Febr._Mäerz Mrz._Abrëll Abr._Mee Mee_Juni Jun._Juli Jul._August Aug._September Sept._Oktober Okt._November Nov._Dezember Dez.'.split('_'), i;
35868
35869 function equalTest(input, mmm, i) {
35870 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
35871 }
35872
35873 for (i = 0; i < 12; i++) {
35874 tests[i] = tests[i].split(' ');
35875 equalTest(tests[i][0], 'MMM', i);
35876 equalTest(tests[i][1], 'MMM', i);
35877 equalTest(tests[i][0], 'MMMM', i);
35878 equalTest(tests[i][1], 'MMMM', i);
35879 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
35880 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
35881 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
35882 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
35883 }
35884 });
35885
35886 test('format', function (assert) {
35887 var a = [
35888 ['dddd, Do MMMM YYYY, HH:mm:ss', 'Sonndeg, 14. Februar 2010, 15:25:50'],
35889 ['ddd, HH:mm', 'So., 15:25'],
35890 ['M Mo MM MMMM MMM', '2 2. 02 Februar Febr.'],
35891 ['YYYY YY', '2010 10'],
35892 ['D Do DD', '14 14. 14'],
35893 ['d do dddd ddd dd', '0 0. Sonndeg So. So'],
35894 ['DDD DDDo DDDD', '45 45. 045'],
35895 ['w wo ww', '6 6. 06'],
35896 ['h hh', '3 03'],
35897 ['H HH', '15 15'],
35898 ['m mm', '25 25'],
35899 ['s ss', '50 50'],
35900 ['a A', 'pm PM'],
35901 ['[the] DDDo [day of the year]', 'the 45. day of the year'],
35902 ['LTS', '15:25:50 Auer'],
35903 ['L', '14.02.2010'],
35904 ['LL', '14. Februar 2010'],
35905 ['LLL', '14. Februar 2010 15:25 Auer'],
35906 ['LLLL', 'Sonndeg, 14. Februar 2010 15:25 Auer'],
35907 ['l', '14.2.2010'],
35908 ['ll', '14. Febr. 2010'],
35909 ['lll', '14. Febr. 2010 15:25 Auer'],
35910 ['llll', 'So., 14. Febr. 2010 15:25 Auer']
35911 ],
35912 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
35913 i;
35914 for (i = 0; i < a.length; i++) {
35915 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
35916 }
35917 });
35918
35919 test('format month', function (assert) {
35920 var expected = 'Januar Jan._Februar Febr._Mäerz Mrz._Abrëll Abr._Mee Mee_Juni Jun._Juli Jul._August Aug._September Sept._Oktober Okt._November Nov._Dezember Dez.'.split('_'), i;
35921 for (i = 0; i < expected.length; i++) {
35922 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
35923 }
35924 });
35925
35926 test('format week', function (assert) {
35927 var expected = 'Sonndeg So. So_Méindeg Mé. Mé_Dënschdeg Dë. Dë_Mëttwoch Më. Më_Donneschdeg Do. Do_Freideg Fr. Fr_Samschdeg Sa. Sa'.split('_'), i;
35928 for (i = 0; i < expected.length; i++) {
35929 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
35930 }
35931 });
35932
35933 test('from', function (assert) {
35934 var start = moment([2007, 1, 28]);
35935 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'e puer Sekonnen', '44 seconds = a few seconds');
35936 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'eng Minutt', '45 seconds = a minute');
35937 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'eng Minutt', '89 seconds = a minute');
35938 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 Minutten', '90 seconds = 2 minutes');
35939 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 Minutten', '44 minutes = 44 minutes');
35940 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'eng Stonn', '45 minutes = an hour');
35941 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'eng Stonn', '89 minutes = an hour');
35942 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 Stonnen', '90 minutes = 2 hours');
35943 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 Stonnen', '5 hours = 5 hours');
35944 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 Stonnen', '21 hours = 21 hours');
35945 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'een Dag', '22 hours = a day');
35946 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'een Dag', '35 hours = a day');
35947 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 Deeg', '36 hours = 2 days');
35948 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'een Dag', '1 day = a day');
35949 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 Deeg', '5 days = 5 days');
35950 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 Deeg', '25 days = 25 days');
35951 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ee Mount', '26 days = a month');
35952 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ee Mount', '30 days = a month');
35953 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ee Mount', '43 days = a month');
35954 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 Méint', '46 days = 2 months');
35955 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 Méint', '75 days = 2 months');
35956 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 Méint', '76 days = 3 months');
35957 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ee Mount', '1 month = a month');
35958 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 Méint', '5 months = 5 months');
35959 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ee Joer', '345 days = a year');
35960 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 Joer', '548 days = 2 years');
35961 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ee Joer', '1 year = a year');
35962 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 Joer', '5 years = 5 years');
35963 });
35964
35965 test('suffix', function (assert) {
35966 assert.equal(moment(30000).from(0), 'an e puer Sekonnen', 'prefix');
35967 assert.equal(moment(0).from(30000), 'virun e puer Sekonnen', 'suffix');
35968 });
35969
35970 test('fromNow', function (assert) {
35971 assert.equal(moment().add({s: 30}).fromNow(), 'an e puer Sekonnen', 'in a few seconds');
35972 assert.equal(moment().add({d: 1}).fromNow(), 'an engem Dag', 'in one day');
35973 assert.equal(moment().add({d: 2}).fromNow(), 'an 2 Deeg', 'in 2 days');
35974 assert.equal(moment().add({d: 3}).fromNow(), 'an 3 Deeg', 'in 3 days');
35975 assert.equal(moment().add({d: 4}).fromNow(), 'a 4 Deeg', 'in 4 days');
35976 assert.equal(moment().add({d: 5}).fromNow(), 'a 5 Deeg', 'in 5 days');
35977 assert.equal(moment().add({d: 6}).fromNow(), 'a 6 Deeg', 'in 6 days');
35978 assert.equal(moment().add({d: 7}).fromNow(), 'a 7 Deeg', 'in 7 days');
35979 assert.equal(moment().add({d: 8}).fromNow(), 'an 8 Deeg', 'in 8 days');
35980 assert.equal(moment().add({d: 9}).fromNow(), 'an 9 Deeg', 'in 9 days');
35981 assert.equal(moment().add({d: 10}).fromNow(), 'an 10 Deeg', 'in 10 days');
35982 assert.equal(moment().add({y: 100}).fromNow(), 'an 100 Joer', 'in 100 years');
35983 assert.equal(moment().add({y: 400}).fromNow(), 'a 400 Joer', 'in 400 years');
35984 });
35985
35986 test('calendar day', function (assert) {
35987 var a = moment().hours(12).minutes(0).seconds(0);
35988
35989 assert.equal(moment(a).calendar(), 'Haut um 12:00 Auer', 'today at the same time');
35990 assert.equal(moment(a).add({m: 25}).calendar(), 'Haut um 12:25 Auer', 'Now plus 25 min');
35991 assert.equal(moment(a).add({h: 1}).calendar(), 'Haut um 13:00 Auer', 'Now plus 1 hour');
35992 assert.equal(moment(a).add({d: 1}).calendar(), 'Muer um 12:00 Auer', 'tomorrow at the same time');
35993 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Haut um 11:00 Auer', 'Now minus 1 hour');
35994 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Gëschter um 12:00 Auer', 'yesterday at the same time');
35995 });
35996
35997 test('calendar next week', function (assert) {
35998 var i, m;
35999
36000 for (i = 2; i < 7; i++) {
36001 m = moment().add({d: i});
36002 assert.equal(m.calendar(), m.format('dddd [um] LT'), 'Today + ' + i + ' days current time');
36003 m.hours(0).minutes(0).seconds(0).milliseconds(0);
36004 assert.equal(m.calendar(), m.format('dddd [um] LT'), 'Today + ' + i + ' days beginning of day');
36005 m.hours(23).minutes(59).seconds(59).milliseconds(999);
36006 assert.equal(m.calendar(), m.format('dddd [um] LT'), 'Today + ' + i + ' days end of day');
f2af24d5
IC
36007 }
36008 });
36009
db71a655
KM
36010 test('calendar last week', function (assert) {
36011 var i, m, weekday, datestring;
36012 for (i = 2; i < 7; i++) {
36013 m = moment().subtract({d: i});
36014
36015 // Different date string for 'Dënschdeg' (Tuesday) and 'Donneschdeg' (Thursday)
36016 weekday = parseInt(m.format('d'), 10);
36017 datestring = (weekday === 2 || weekday === 4 ? '[Leschten] dddd [um] LT' : '[Leschte] dddd [um] LT');
36018
36019 assert.equal(m.calendar(), m.format(datestring), 'Today + ' + i + ' days current time');
36020 m.hours(0).minutes(0).seconds(0).milliseconds(0);
36021 assert.equal(m.calendar(), m.format(datestring), 'Today + ' + i + ' days beginning of day');
36022 m.hours(23).minutes(59).seconds(59).milliseconds(999);
36023 assert.equal(m.calendar(), m.format(datestring), 'Today + ' + i + ' days end of day');
f2af24d5
IC
36024 }
36025 });
36026
db71a655
KM
36027 test('calendar all else', function (assert) {
36028 var weeksAgo = moment().subtract({w: 1}),
36029 weeksFromNow = moment().add({w: 1});
f2af24d5 36030
db71a655
KM
36031 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
36032 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
f2af24d5 36033
db71a655
KM
36034 weeksAgo = moment().subtract({w: 2});
36035 weeksFromNow = moment().add({w: 2});
f2af24d5 36036
db71a655
KM
36037 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
36038 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
36039 });
f2af24d5 36040
db71a655
KM
36041 test('weeks year starting sunday format', function (assert) {
36042 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
36043 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1.', 'Jan 7 2012 should be week 1');
36044 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
36045 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2.', 'Jan 14 2012 should be week 2');
36046 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
f2af24d5
IC
36047 });
36048
db71a655 36049})));
f2af24d5 36050
db71a655
KM
36051
36052;(function (global, factory) {
36053 typeof exports === 'object' && typeof module !== 'undefined'
36054 && typeof require === 'function' ? factory(require('../../moment')) :
36055 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
36056 factory(global.moment)
36057}(this, (function (moment) { 'use strict';
36058
36059 function each(array, callback) {
36060 var i;
36061 for (i = 0; i < array.length; i++) {
36062 callback(array[i], i, array);
f2af24d5 36063 }
db71a655 36064 }
f2af24d5 36065
c58511b9
KM
36066 function setupDeprecationHandler(test, moment$$1, scope) {
36067 test._expectedDeprecations = null;
36068 test._observedDeprecations = null;
36069 test._oldSupress = moment$$1.suppressDeprecationWarnings;
36070 moment$$1.suppressDeprecationWarnings = true;
36071 test.expectedDeprecations = function () {
36072 test._expectedDeprecations = arguments;
36073 test._observedDeprecations = [];
36074 };
36075 moment$$1.deprecationHandler = function (name, msg) {
36076 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
36077 if (deprecationId === -1) {
36078 throw new Error('Unexpected deprecation thrown name=' +
36079 name + ' msg=' + msg);
36080 }
36081 test._observedDeprecations[deprecationId] = 1;
36082 };
36083 }
36084
36085 function teardownDeprecationHandler(test, moment$$1, scope) {
36086 moment$$1.suppressDeprecationWarnings = test._oldSupress;
36087
36088 if (test._expectedDeprecations != null) {
36089 var missedDeprecations = [];
36090 each(test._expectedDeprecations, function (deprecationPattern, id) {
36091 if (test._observedDeprecations[id] !== 1) {
36092 missedDeprecations.push(deprecationPattern);
36093 }
36094 });
36095 if (missedDeprecations.length !== 0) {
36096 throw new Error('Expected deprecation warnings did not happen: ' +
36097 missedDeprecations.join(' '));
36098 }
36099 }
36100 }
36101
36102 function matchedDeprecation(name, msg, deprecations) {
36103 if (deprecations == null) {
36104 return -1;
36105 }
36106 for (var i = 0; i < deprecations.length; ++i) {
36107 if (name != null && name === deprecations[i]) {
36108 return i;
36109 }
36110 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
36111 return i;
36112 }
36113 }
36114 return -1;
36115 }
36116
36117 /*global QUnit:false*/
36118
36119 var test = QUnit.test;
36120
db71a655
KM
36121 function objectKeys(obj) {
36122 if (Object.keys) {
36123 return Object.keys(obj);
36124 } else {
36125 // IE8
36126 var res = [], i;
36127 for (i in obj) {
36128 if (obj.hasOwnProperty(i)) {
36129 res.push(i);
36130 }
36131 }
36132 return res;
73f3c911 36133 }
db71a655 36134 }
516f5f67 36135
db71a655 36136 // Pick the first defined of two or three arguments.
c74a101d 36137
db71a655
KM
36138 function defineCommonLocaleTests(locale, options) {
36139 test('lenient day of month ordinal parsing', function (assert) {
36140 var i, ordinalStr, testMoment;
36141 for (i = 1; i <= 31; ++i) {
36142 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
36143 testMoment = moment(ordinalStr, 'YYYY MM Do');
36144 assert.equal(testMoment.year(), 2014,
36145 'lenient day of month ordinal parsing ' + i + ' year check');
36146 assert.equal(testMoment.month(), 0,
36147 'lenient day of month ordinal parsing ' + i + ' month check');
36148 assert.equal(testMoment.date(), i,
36149 'lenient day of month ordinal parsing ' + i + ' date check');
516f5f67
IC
36150 }
36151 });
db71a655
KM
36152
36153 test('lenient day of month ordinal parsing of number', function (assert) {
36154 var i, testMoment;
36155 for (i = 1; i <= 31; ++i) {
36156 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
36157 assert.equal(testMoment.year(), 2014,
36158 'lenient day of month ordinal parsing of number ' + i + ' year check');
36159 assert.equal(testMoment.month(), 0,
36160 'lenient day of month ordinal parsing of number ' + i + ' month check');
36161 assert.equal(testMoment.date(), i,
36162 'lenient day of month ordinal parsing of number ' + i + ' date check');
36163 }
36164 });
36165
36166 test('strict day of month ordinal parsing', function (assert) {
36167 var i, ordinalStr, testMoment;
36168 for (i = 1; i <= 31; ++i) {
36169 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
36170 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
36171 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
36172 }
36173 });
36174
36175 test('meridiem invariant', function (assert) {
36176 var h, m, t1, t2;
36177 for (h = 0; h < 24; ++h) {
36178 for (m = 0; m < 60; m += 15) {
36179 t1 = moment.utc([2000, 0, 1, h, m]);
36180 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
36181 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
36182 'meridiem at ' + t1.format('HH:mm'));
36183 }
36184 }
36185 });
36186
36187 test('date format correctness', function (assert) {
36188 var data, tokens;
36189 data = moment.localeData()._longDateFormat;
36190 tokens = objectKeys(data);
36191 each(tokens, function (srchToken) {
36192 // Check each format string to make sure it does not contain any
36193 // tokens that need to be expanded.
36194 each(tokens, function (baseToken) {
36195 // strip escaped sequences
36196 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
36197 assert.equal(false, !!~format.indexOf(srchToken),
36198 'contains ' + srchToken + ' in ' + baseToken);
36199 });
36200 });
36201 });
36202
36203 test('month parsing correctness', function (assert) {
36204 var i, m;
36205
36206 if (locale === 'tr') {
36207 // I can't fix it :(
c58511b9 36208 assert.expect(0);
db71a655
KM
36209 return;
36210 }
36211 function tester(format) {
36212 var r;
36213 r = moment(m.format(format), format);
36214 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
36215 if (locale !== 'ka') {
36216 r = moment(m.format(format).toLocaleUpperCase(), format);
36217 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
36218 }
db71a655
KM
36219 r = moment(m.format(format).toLocaleLowerCase(), format);
36220 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
36221
36222 r = moment(m.format(format), format, true);
36223 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
36224 if (locale !== 'ka') {
36225 r = moment(m.format(format).toLocaleUpperCase(), format, true);
36226 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
36227 }
db71a655
KM
36228 r = moment(m.format(format).toLocaleLowerCase(), format, true);
36229 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
36230 }
36231
36232 for (i = 0; i < 12; ++i) {
36233 m = moment([2015, i, 15, 18]);
36234 tester('MMM');
36235 tester('MMM.');
36236 tester('MMMM');
36237 tester('MMMM.');
36238 }
36239 });
36240
36241 test('weekday parsing correctness', function (assert) {
36242 var i, m;
36243
96d0d679 36244 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
36245 // tr, az: There is a lower-case letter (ı), that converted to
36246 // upper then lower changes to i
36247 // ro: there is the letter ț which behaves weird under IE8
36248 // mt: letter Ħ
96d0d679 36249 // ga: month with spaces
c58511b9 36250 assert.expect(0);
db71a655
KM
36251 return;
36252 }
36253 function tester(format) {
36254 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
36255 r = moment(m.format(format), format);
36256 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
36257 if (locale !== 'ka') {
36258 r = moment(m.format(format).toLocaleUpperCase(), format);
36259 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
36260 }
db71a655
KM
36261 r = moment(m.format(format).toLocaleLowerCase(), format);
36262 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
36263 r = moment(m.format(format), format, true);
36264 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
36265 if (locale !== 'ka') {
36266 r = moment(m.format(format).toLocaleUpperCase(), format, true);
36267 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
36268 }
db71a655
KM
36269 r = moment(m.format(format).toLocaleLowerCase(), format, true);
36270 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
36271 }
36272
36273 for (i = 0; i < 7; ++i) {
36274 m = moment.utc([2015, 0, i + 1, 18]);
36275 tester('dd');
36276 tester('ddd');
36277 tester('dddd');
36278 }
36279 });
36280
36281 test('valid localeData', function (assert) {
36282 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
36283 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
36284 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
36285 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
36286 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
36287 });
96d0d679
KM
36288
36289 test('localeData weekdays can localeSort', function (assert) {
36290 var weekdays = moment().localeData().weekdays();
36291 var weekdaysShort = moment().localeData().weekdaysShort();
36292 var weekdaysMin = moment().localeData().weekdaysMin();
36293 var shift = moment().localeData()._week.dow;
36294 assert.deepEqual(
36295 moment().localeData().weekdays(true),
36296 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
36297 'weekdays should localeSort');
36298 assert.deepEqual(
36299 moment().localeData().weekdaysShort(true),
36300 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
36301 'weekdaysShort should localeSort');
36302 assert.deepEqual(
36303 moment().localeData().weekdaysMin(true),
36304 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
36305 'weekdaysMin should localeSort');
36306 });
516f5f67
IC
36307 }
36308
db71a655 36309 /*global QUnit:false*/
516f5f67 36310
db71a655
KM
36311 function localeModule (name, lifecycle) {
36312 QUnit.module('locale:' + name, {
c58511b9 36313 beforeEach : function () {
db71a655
KM
36314 moment.locale(name);
36315 moment.createFromInputFallback = function (config) {
36316 throw new Error('input not handled by moment: ' + config._i);
36317 };
36318 setupDeprecationHandler(test, moment, 'locale');
36319 if (lifecycle && lifecycle.setup) {
36320 lifecycle.setup();
36321 }
36322 },
c58511b9 36323 afterEach : function () {
db71a655
KM
36324 moment.locale('en');
36325 teardownDeprecationHandler(test, moment, 'locale');
36326 if (lifecycle && lifecycle.teardown) {
36327 lifecycle.teardown();
36328 }
73f3c911 36329 }
db71a655
KM
36330 });
36331 defineCommonLocaleTests(name, -1, -1);
36332 }
36333
36334 localeModule('lo');
36335
36336 test('parse', function (assert) {
36337 var tests = 'ມັງກອນ ມັງກອນ_ກຸມພາ ກຸມພາ_ມີນາ ມີນາ_ເມສາ ເມສາ_ພຶດສະພາ ພຶດສະພາ_ມິຖຸນາ ມິຖຸນາ_ກໍລະກົດ ກໍລະກົດ_ສິງຫາ ສິງຫາ_ກັນຍາ ກັນຍາ_ຕຸລາ ຕຸລາ_ພະຈິກ ພະຈິກ_ທັນວາ ທັນວາ'.split('_'), i;
36338 function equalTest(input, mmm, i) {
36339 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
36340 }
36341 for (i = 0; i < 12; i++) {
36342 tests[i] = tests[i].split(' ');
36343 equalTest(tests[i][0], 'MMM', i);
36344 equalTest(tests[i][1], 'MMM', i);
36345 equalTest(tests[i][0], 'MMMM', i);
36346 equalTest(tests[i][1], 'MMMM', i);
36347 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
36348 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
36349 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
36350 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
36351 }
36352 });
36353
36354 test('format', function (assert) {
36355 var a = [
36356 ['dddd, MMMM Do YYYY, h:mm:ss a', 'ອາທິດ, ກຸມພາ ທີ່14 2010, 3:25:50 ຕອນແລງ'],
36357 ['ddd, hA', 'ທິດ, 3ຕອນແລງ'],
36358 ['M Mo MM MMMM MMM', '2 ທີ່2 02 ກຸມພາ ກຸມພາ'],
36359 ['YYYY YY', '2010 10'],
36360 ['D Do DD', '14 ທີ່14 14'],
36361 ['d do dddd ddd dd', '0 ທີ່0 ອາທິດ ທິດ ທ'],
36362 ['DDD DDDo DDDD', '45 ທີ່45 045'],
36363 ['w wo ww', '8 ທີ່8 08'],
36364 ['h hh', '3 03'],
36365 ['H HH', '15 15'],
36366 ['m mm', '25 25'],
36367 ['s ss', '50 50'],
36368 ['a A', 'ຕອນແລງ ຕອນແລງ'],
36369 ['[ວັນ]DDDo [ຂອງປີ]', 'ວັນທີ່45 ຂອງປີ'],
36370 ['LTS', '15:25:50'],
36371 ['L', '14/02/2010'],
36372 ['LL', '14 ກຸມພາ 2010'],
36373 ['LLL', '14 ກຸມພາ 2010 15:25'],
36374 ['LLLL', 'ວັນອາທິດ 14 ກຸມພາ 2010 15:25'],
36375 ['l', '14/2/2010'],
36376 ['ll', '14 ກຸມພາ 2010'],
36377 ['lll', '14 ກຸມພາ 2010 15:25'],
36378 ['llll', 'ວັນທິດ 14 ກຸມພາ 2010 15:25']
36379 ],
36380 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
36381 i;
36382 for (i = 0; i < a.length; i++) {
36383 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
36384 }
36385 });
36386
36387 test('format ordinal', function (assert) {
36388 assert.equal(moment([2011, 0, 1]).format('DDDo'), 'ທີ່1', 'ທີ່1');
36389 assert.equal(moment([2011, 0, 2]).format('DDDo'), 'ທີ່2', 'ທີ່2');
36390 assert.equal(moment([2011, 0, 3]).format('DDDo'), 'ທີ່3', 'ທີ່3');
36391 assert.equal(moment([2011, 0, 4]).format('DDDo'), 'ທີ່4', 'ທີ່4');
36392 assert.equal(moment([2011, 0, 5]).format('DDDo'), 'ທີ່5', 'ທີ່5');
36393 assert.equal(moment([2011, 0, 6]).format('DDDo'), 'ທີ່6', 'ທີ່6');
36394 assert.equal(moment([2011, 0, 7]).format('DDDo'), 'ທີ່7', 'ທີ່7');
36395 assert.equal(moment([2011, 0, 8]).format('DDDo'), 'ທີ່8', 'ທີ່8');
36396 assert.equal(moment([2011, 0, 9]).format('DDDo'), 'ທີ່9', 'ທີ່9');
36397 assert.equal(moment([2011, 0, 10]).format('DDDo'), 'ທີ່10', 'ທີ່10');
36398
36399 assert.equal(moment([2011, 0, 11]).format('DDDo'), 'ທີ່11', 'ທີ່11');
36400 assert.equal(moment([2011, 0, 12]).format('DDDo'), 'ທີ່12', 'ທີ່12');
36401 assert.equal(moment([2011, 0, 13]).format('DDDo'), 'ທີ່13', 'ທີ່13');
36402 assert.equal(moment([2011, 0, 14]).format('DDDo'), 'ທີ່14', 'ທີ່14');
36403 assert.equal(moment([2011, 0, 15]).format('DDDo'), 'ທີ່15', 'ທີ່15');
36404 assert.equal(moment([2011, 0, 16]).format('DDDo'), 'ທີ່16', 'ທີ່16');
36405 assert.equal(moment([2011, 0, 17]).format('DDDo'), 'ທີ່17', 'ທີ່17');
36406 assert.equal(moment([2011, 0, 18]).format('DDDo'), 'ທີ່18', 'ທີ່18');
36407 assert.equal(moment([2011, 0, 19]).format('DDDo'), 'ທີ່19', 'ທີ່19');
36408 assert.equal(moment([2011, 0, 20]).format('DDDo'), 'ທີ່20', 'ທີ່20');
36409
36410 assert.equal(moment([2011, 0, 21]).format('DDDo'), 'ທີ່21', 'ທີ່21');
36411 assert.equal(moment([2011, 0, 22]).format('DDDo'), 'ທີ່22', 'ທີ່22');
36412 assert.equal(moment([2011, 0, 23]).format('DDDo'), 'ທີ່23', 'ທີ່23');
36413 assert.equal(moment([2011, 0, 24]).format('DDDo'), 'ທີ່24', 'ທີ່24');
36414 assert.equal(moment([2011, 0, 25]).format('DDDo'), 'ທີ່25', 'ທີ່25');
36415 assert.equal(moment([2011, 0, 26]).format('DDDo'), 'ທີ່26', 'ທີ່26');
36416 assert.equal(moment([2011, 0, 27]).format('DDDo'), 'ທີ່27', 'ທີ່27');
36417 assert.equal(moment([2011, 0, 28]).format('DDDo'), 'ທີ່28', 'ທີ່28');
36418 assert.equal(moment([2011, 0, 29]).format('DDDo'), 'ທີ່29', 'ທີ່29');
36419 assert.equal(moment([2011, 0, 30]).format('DDDo'), 'ທີ່30', 'ທີ່30');
36420
36421 assert.equal(moment([2011, 0, 31]).format('DDDo'), 'ທີ່31', 'ທີ່31');
36422 });
36423
36424 test('format month', function (assert) {
36425 var expected = 'ມັງກອນ ມັງກອນ_ກຸມພາ ກຸມພາ_ມີນາ ມີນາ_ເມສາ ເມສາ_ພຶດສະພາ ພຶດສະພາ_ມິຖຸນາ ມິຖຸນາ_ກໍລະກົດ ກໍລະກົດ_ສິງຫາ ສິງຫາ_ກັນຍາ ກັນຍາ_ຕຸລາ ຕຸລາ_ພະຈິກ ພະຈິກ_ທັນວາ ທັນວາ'.split('_'), i;
36426 for (i = 0; i < expected.length; i++) {
36427 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
36428 }
36429 });
36430
36431 test('format week', function (assert) {
36432 var expected = 'ອາທິດ ທິດ ທ_ຈັນ ຈັນ ຈ_ອັງຄານ ອັງຄານ ອຄ_ພຸດ ພຸດ ພ_ພະຫັດ ພະຫັດ ພຫ_ສຸກ ສຸກ ສກ_ເສົາ ເສົາ ສ'.split('_'), i;
36433 for (i = 0; i < expected.length; i++) {
36434 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
36435 }
36436 });
36437
36438 test('from', function (assert) {
36439 var start = moment([2007, 1, 28]);
36440 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ບໍ່ເທົ່າໃດວິນາທີ', '44 seconds = a few seconds');
36441 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '1 ນາທີ', '45 seconds = a minute');
36442 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '1 ນາທີ', '89 seconds = a minute');
36443 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 ນາທີ', '90 seconds = 2 minutes');
36444 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 ນາທີ', '44 minutes = 44 minutes');
36445 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '1 ຊົ່ວໂມງ', '45 minutes = an hour');
36446 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '1 ຊົ່ວໂມງ', '89 minutes = an hour');
36447 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ຊົ່ວໂມງ', '90 minutes = 2 hours');
36448 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ຊົ່ວໂມງ', '5 hours = 5 hours');
36449 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ຊົ່ວໂມງ', '21 hours = 21 hours');
36450 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '1 ມື້', '22 hours = a day');
36451 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '1 ມື້', '35 hours = a day');
36452 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 ມື້', '36 hours = 2 days');
36453 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '1 ມື້', '1 day = a day');
36454 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ມື້', '5 days = 5 days');
36455 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ມື້', '25 days = 25 days');
36456 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '1 ເດືອນ', '26 days = a month');
36457 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '1 ເດືອນ', '30 days = a month');
36458 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '1 ເດືອນ', '43 days = a month');
36459 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 ເດືອນ', '46 days = 2 months');
36460 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 ເດືອນ', '75 days = 2 months');
36461 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 ເດືອນ', '76 days = 3 months');
36462 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '1 ເດືອນ', '1 month = a month');
36463 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 ເດືອນ', '5 months = 5 months');
36464 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '1 ປີ', '345 days = a year');
36465 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ປີ', '548 days = 2 years');
36466 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '1 ປີ', '1 year = a year');
36467 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ປີ', '5 years = 5 years');
36468 });
36469
36470 test('suffix', function (assert) {
36471 assert.equal(moment(30000).from(0), 'ອີກ ບໍ່ເທົ່າໃດວິນາທີ', 'prefix');
36472 assert.equal(moment(0).from(30000), 'ບໍ່ເທົ່າໃດວິນາທີຜ່ານມາ', 'suffix');
36473 });
36474
36475 test('now from now', function (assert) {
36476 assert.equal(moment().fromNow(), 'ບໍ່ເທົ່າໃດວິນາທີຜ່ານມາ', 'now from now should display as in the past');
36477 });
36478
36479 test('fromNow', function (assert) {
36480 assert.equal(moment().add({s: 30}).fromNow(), 'ອີກ ບໍ່ເທົ່າໃດວິນາທີ', 'in a few seconds');
36481 assert.equal(moment().add({d: 5}).fromNow(), 'ອີກ 5 ມື້', 'in 5 days');
36482 });
36483
36484 test('calendar day', function (assert) {
36485 var a = moment().hours(12).minutes(0).seconds(0);
36486
36487 assert.equal(moment(a).calendar(), 'ມື້ນີ້ເວລາ 12:00', 'today at the same time');
36488 assert.equal(moment(a).add({m: 25}).calendar(), 'ມື້ນີ້ເວລາ 12:25', 'Now plus 25 min');
36489 assert.equal(moment(a).add({h: 1}).calendar(), 'ມື້ນີ້ເວລາ 13:00', 'Now plus 1 hour');
36490 assert.equal(moment(a).add({d: 1}).calendar(), 'ມື້ອື່ນເວລາ 12:00', 'tomorrow at the same time');
36491 assert.equal(moment(a).subtract({h: 1}).calendar(), 'ມື້ນີ້ເວລາ 11:00', 'Now minus 1 hour');
36492 assert.equal(moment(a).subtract({d: 1}).calendar(), 'ມື້ວານນີ້ເວລາ 12:00', 'yesterday at the same time');
36493 });
36494
36495 test('calendar next week', function (assert) {
36496 var i, m;
36497 for (i = 2; i < 7; i++) {
36498 m = moment().add({d: i});
36499 assert.equal(m.calendar(), m.format('[ວັນ]dddd[ໜ້າເວລາ] LT'), 'Today + ' + i + ' days current time');
36500 m.hours(0).minutes(0).seconds(0).milliseconds(0);
36501 assert.equal(m.calendar(), m.format('[ວັນ]dddd[ໜ້າເວລາ] LT'), 'Today + ' + i + ' days beginning of day');
36502 m.hours(23).minutes(59).seconds(59).milliseconds(999);
36503 assert.equal(m.calendar(), m.format('[ວັນ]dddd[ໜ້າເວລາ] LT'), 'Today + ' + i + ' days end of day');
36504 }
36505 });
36506
36507 test('calendar last week', function (assert) {
36508 var i, m;
36509
36510 for (i = 2; i < 7; i++) {
36511 m = moment().subtract({d: i});
36512 assert.equal(m.calendar(), m.format('[ວັນ]dddd[ແລ້ວນີ້ເວລາ] LT'), 'Today - ' + i + ' days current time');
36513 m.hours(0).minutes(0).seconds(0).milliseconds(0);
36514 assert.equal(m.calendar(), m.format('[ວັນ]dddd[ແລ້ວນີ້ເວລາ] LT'), 'Today - ' + i + ' days beginning of day');
36515 m.hours(23).minutes(59).seconds(59).milliseconds(999);
36516 assert.equal(m.calendar(), m.format('[ວັນ]dddd[ແລ້ວນີ້ເວລາ] LT'), 'Today - ' + i + ' days end of day');
36517 }
36518 });
36519
36520 test('calendar all else', function (assert) {
36521 var weeksAgo = moment().subtract({w: 1}),
36522 weeksFromNow = moment().add({w: 1});
36523
36524 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
36525 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
36526
36527 weeksAgo = moment().subtract({w: 2});
36528 weeksFromNow = moment().add({w: 2});
36529
36530 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
36531 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
36532 });
36533
36534 test('weeks year starting sunday format', function (assert) {
36535 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 ທີ່1', 'Jan 1 2012 should be week 1');
36536 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 ທີ່1', 'Jan 7 2012 should be week 1');
36537 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 ທີ່2', 'Jan 8 2012 should be week 2');
36538 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 ທີ່2', 'Jan 14 2012 should be week 2');
36539 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 ທີ່3', 'Jan 15 2012 should be week 3');
36540 });
73f3c911
IC
36541
36542})));
516f5f67 36543
516f5f67 36544
b135bf1a
IC
36545;(function (global, factory) {
36546 typeof exports === 'object' && typeof module !== 'undefined'
36547 && typeof require === 'function' ? factory(require('../../moment')) :
36548 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
36549 factory(global.moment)
73f3c911 36550}(this, (function (moment) { 'use strict';
b135bf1a 36551
db71a655
KM
36552 function each(array, callback) {
36553 var i;
36554 for (i = 0; i < array.length; i++) {
36555 callback(array[i], i, array);
36556 }
b135bf1a 36557 }
516f5f67 36558
c58511b9
KM
36559 function setupDeprecationHandler(test, moment$$1, scope) {
36560 test._expectedDeprecations = null;
36561 test._observedDeprecations = null;
36562 test._oldSupress = moment$$1.suppressDeprecationWarnings;
36563 moment$$1.suppressDeprecationWarnings = true;
36564 test.expectedDeprecations = function () {
36565 test._expectedDeprecations = arguments;
36566 test._observedDeprecations = [];
36567 };
36568 moment$$1.deprecationHandler = function (name, msg) {
36569 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
36570 if (deprecationId === -1) {
36571 throw new Error('Unexpected deprecation thrown name=' +
36572 name + ' msg=' + msg);
36573 }
36574 test._observedDeprecations[deprecationId] = 1;
36575 };
36576 }
36577
36578 function teardownDeprecationHandler(test, moment$$1, scope) {
36579 moment$$1.suppressDeprecationWarnings = test._oldSupress;
36580
36581 if (test._expectedDeprecations != null) {
36582 var missedDeprecations = [];
36583 each(test._expectedDeprecations, function (deprecationPattern, id) {
36584 if (test._observedDeprecations[id] !== 1) {
36585 missedDeprecations.push(deprecationPattern);
36586 }
36587 });
36588 if (missedDeprecations.length !== 0) {
36589 throw new Error('Expected deprecation warnings did not happen: ' +
36590 missedDeprecations.join(' '));
36591 }
36592 }
36593 }
36594
36595 function matchedDeprecation(name, msg, deprecations) {
36596 if (deprecations == null) {
36597 return -1;
36598 }
36599 for (var i = 0; i < deprecations.length; ++i) {
36600 if (name != null && name === deprecations[i]) {
36601 return i;
36602 }
36603 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
36604 return i;
36605 }
36606 }
36607 return -1;
36608 }
36609
36610 /*global QUnit:false*/
36611
36612 var test = QUnit.test;
36613
db71a655
KM
36614 function objectKeys(obj) {
36615 if (Object.keys) {
36616 return Object.keys(obj);
36617 } else {
36618 // IE8
36619 var res = [], i;
36620 for (i in obj) {
36621 if (obj.hasOwnProperty(i)) {
36622 res.push(i);
36623 }
c74a101d 36624 }
db71a655 36625 return res;
c74a101d 36626 }
b135bf1a 36627 }
c74a101d 36628
db71a655 36629 // Pick the first defined of two or three arguments.
73f3c911 36630
db71a655
KM
36631 function defineCommonLocaleTests(locale, options) {
36632 test('lenient day of month ordinal parsing', function (assert) {
36633 var i, ordinalStr, testMoment;
36634 for (i = 1; i <= 31; ++i) {
36635 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
36636 testMoment = moment(ordinalStr, 'YYYY MM Do');
36637 assert.equal(testMoment.year(), 2014,
36638 'lenient day of month ordinal parsing ' + i + ' year check');
36639 assert.equal(testMoment.month(), 0,
36640 'lenient day of month ordinal parsing ' + i + ' month check');
36641 assert.equal(testMoment.date(), i,
36642 'lenient day of month ordinal parsing ' + i + ' date check');
36643 }
36644 });
73f3c911 36645
db71a655
KM
36646 test('lenient day of month ordinal parsing of number', function (assert) {
36647 var i, testMoment;
36648 for (i = 1; i <= 31; ++i) {
36649 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
36650 assert.equal(testMoment.year(), 2014,
36651 'lenient day of month ordinal parsing of number ' + i + ' year check');
36652 assert.equal(testMoment.month(), 0,
36653 'lenient day of month ordinal parsing of number ' + i + ' month check');
36654 assert.equal(testMoment.date(), i,
36655 'lenient day of month ordinal parsing of number ' + i + ' date check');
36656 }
36657 });
516f5f67 36658
db71a655
KM
36659 test('strict day of month ordinal parsing', function (assert) {
36660 var i, ordinalStr, testMoment;
36661 for (i = 1; i <= 31; ++i) {
36662 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
36663 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
36664 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
36665 }
36666 });
516f5f67 36667
db71a655
KM
36668 test('meridiem invariant', function (assert) {
36669 var h, m, t1, t2;
36670 for (h = 0; h < 24; ++h) {
36671 for (m = 0; m < 60; m += 15) {
36672 t1 = moment.utc([2000, 0, 1, h, m]);
36673 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
36674 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
36675 'meridiem at ' + t1.format('HH:mm'));
36676 }
36677 }
36678 });
36679
36680 test('date format correctness', function (assert) {
36681 var data, tokens;
36682 data = moment.localeData()._longDateFormat;
36683 tokens = objectKeys(data);
36684 each(tokens, function (srchToken) {
36685 // Check each format string to make sure it does not contain any
36686 // tokens that need to be expanded.
36687 each(tokens, function (baseToken) {
36688 // strip escaped sequences
36689 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
36690 assert.equal(false, !!~format.indexOf(srchToken),
36691 'contains ' + srchToken + ' in ' + baseToken);
36692 });
73f3c911 36693 });
b135bf1a
IC
36694 });
36695
db71a655
KM
36696 test('month parsing correctness', function (assert) {
36697 var i, m;
36698
36699 if (locale === 'tr') {
36700 // I can't fix it :(
c58511b9 36701 assert.expect(0);
db71a655
KM
36702 return;
36703 }
36704 function tester(format) {
36705 var r;
36706 r = moment(m.format(format), format);
36707 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
36708 if (locale !== 'ka') {
36709 r = moment(m.format(format).toLocaleUpperCase(), format);
36710 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
36711 }
db71a655
KM
36712 r = moment(m.format(format).toLocaleLowerCase(), format);
36713 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
36714
36715 r = moment(m.format(format), format, true);
36716 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
36717 if (locale !== 'ka') {
36718 r = moment(m.format(format).toLocaleUpperCase(), format, true);
36719 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
36720 }
db71a655
KM
36721 r = moment(m.format(format).toLocaleLowerCase(), format, true);
36722 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
36723 }
36724
36725 for (i = 0; i < 12; ++i) {
36726 m = moment([2015, i, 15, 18]);
36727 tester('MMM');
36728 tester('MMM.');
36729 tester('MMMM');
36730 tester('MMMM.');
36731 }
36732 });
b135bf1a 36733
db71a655
KM
36734 test('weekday parsing correctness', function (assert) {
36735 var i, m;
36736
96d0d679 36737 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
36738 // tr, az: There is a lower-case letter (ı), that converted to
36739 // upper then lower changes to i
36740 // ro: there is the letter ț which behaves weird under IE8
36741 // mt: letter Ħ
96d0d679 36742 // ga: month with spaces
c58511b9 36743 assert.expect(0);
db71a655
KM
36744 return;
36745 }
36746 function tester(format) {
36747 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
36748 r = moment(m.format(format), format);
36749 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
36750 if (locale !== 'ka') {
36751 r = moment(m.format(format).toLocaleUpperCase(), format);
36752 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
36753 }
db71a655
KM
36754 r = moment(m.format(format).toLocaleLowerCase(), format);
36755 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
36756 r = moment(m.format(format), format, true);
36757 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
36758 if (locale !== 'ka') {
36759 r = moment(m.format(format).toLocaleUpperCase(), format, true);
36760 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
36761 }
db71a655
KM
36762 r = moment(m.format(format).toLocaleLowerCase(), format, true);
36763 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
36764 }
36765
36766 for (i = 0; i < 7; ++i) {
36767 m = moment.utc([2015, 0, i + 1, 18]);
36768 tester('dd');
36769 tester('ddd');
36770 tester('dddd');
36771 }
36772 });
b135bf1a 36773
db71a655
KM
36774 test('valid localeData', function (assert) {
36775 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
36776 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
36777 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
36778 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
36779 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
36780 });
96d0d679
KM
36781
36782 test('localeData weekdays can localeSort', function (assert) {
36783 var weekdays = moment().localeData().weekdays();
36784 var weekdaysShort = moment().localeData().weekdaysShort();
36785 var weekdaysMin = moment().localeData().weekdaysMin();
36786 var shift = moment().localeData()._week.dow;
36787 assert.deepEqual(
36788 moment().localeData().weekdays(true),
36789 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
36790 'weekdays should localeSort');
36791 assert.deepEqual(
36792 moment().localeData().weekdaysShort(true),
36793 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
36794 'weekdaysShort should localeSort');
36795 assert.deepEqual(
36796 moment().localeData().weekdaysMin(true),
36797 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
36798 'weekdaysMin should localeSort');
36799 });
db71a655 36800 }
d6651c21 36801
db71a655
KM
36802 /*global QUnit:false*/
36803
db71a655
KM
36804 function localeModule (name, lifecycle) {
36805 QUnit.module('locale:' + name, {
c58511b9 36806 beforeEach : function () {
db71a655
KM
36807 moment.locale(name);
36808 moment.createFromInputFallback = function (config) {
36809 throw new Error('input not handled by moment: ' + config._i);
36810 };
36811 setupDeprecationHandler(test, moment, 'locale');
36812 if (lifecycle && lifecycle.setup) {
36813 lifecycle.setup();
36814 }
36815 },
c58511b9 36816 afterEach : function () {
db71a655
KM
36817 moment.locale('en');
36818 teardownDeprecationHandler(test, moment, 'locale');
36819 if (lifecycle && lifecycle.teardown) {
36820 lifecycle.teardown();
36821 }
d6651c21 36822 }
73f3c911 36823 });
db71a655
KM
36824 defineCommonLocaleTests(name, -1, -1);
36825 }
36826
36827 localeModule('lt');
36828
36829 test('parse', function (assert) {
36830 var tests = 'sausis sau_vasaris vas_kovas kov_balandis bal_gegužė geg_birželis bir_liepa lie_rugpjūtis rgp_rugsėjis rgs_spalis spa_lapkritis lap_gruodis grd'.split('_'), i;
36831 function equalTest(input, mmm, i) {
36832 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
36833 }
36834 for (i = 0; i < 12; i++) {
36835 tests[i] = tests[i].split(' ');
36836 equalTest(tests[i][0], 'MMM', i);
36837 equalTest(tests[i][1], 'MMM', i);
36838 equalTest(tests[i][0], 'MMMM', i);
36839 equalTest(tests[i][1], 'MMMM', i);
36840 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
36841 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
36842 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
36843 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
36844 }
36845 });
36846
36847 test('format', function (assert) {
36848 var a = [
36849 ['dddd, Do MMMM YYYY, h:mm:ss a', 'sekmadienis, 14-oji vasario 2010, 3:25:50 pm'],
36850 ['ddd, hA', 'Sek, 3PM'],
36851 ['M Mo MM MMMM MMM', '2 2-oji 02 vasaris vas'],
36852 ['YYYY YY', '2010 10'],
36853 ['D Do DD', '14 14-oji 14'],
36854 ['d do dddd ddd dd', '0 0-oji sekmadienis Sek S'],
36855 ['DDD DDDo DDDD', '45 45-oji 045'],
36856 ['w wo ww', '6 6-oji 06'],
36857 ['h hh', '3 03'],
36858 ['H HH', '15 15'],
36859 ['m mm', '25 25'],
36860 ['s ss', '50 50'],
36861 ['a A', 'pm PM'],
36862 ['DDDo [metų diena]', '45-oji metų diena'],
36863 ['LTS', '15:25:50'],
36864 ['L', '2010-02-14'],
36865 ['LL', '2010 m. vasario 14 d.'],
36866 ['LLL', '2010 m. vasario 14 d., 15:25 val.'],
36867 ['LLLL', '2010 m. vasario 14 d., sekmadienis, 15:25 val.'],
36868 ['l', '2010-02-14'],
36869 ['ll', '2010 m. vasario 14 d.'],
36870 ['lll', '2010 m. vasario 14 d., 15:25 val.'],
36871 ['llll', '2010 m. vasario 14 d., Sek, 15:25 val.']
36872 ],
36873 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
36874 i;
36875 for (i = 0; i < a.length; i++) {
36876 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
36877 }
36878 });
36879
36880 test('format ordinal', function (assert) {
36881 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-oji', '1-oji');
36882 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-oji', '2-oji');
36883 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-oji', '3-oji');
36884 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-oji', '4-oji');
36885 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-oji', '5-oji');
36886 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-oji', '6-oji');
36887 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-oji', '7-oji');
36888 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-oji', '8-oji');
36889 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-oji', '9-oji');
36890 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-oji', '10-oji');
36891
36892 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-oji', '11-oji');
36893 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-oji', '12-oji');
36894 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-oji', '13-oji');
36895 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-oji', '14-oji');
36896 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-oji', '15-oji');
36897 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-oji', '16-oji');
36898 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-oji', '17-oji');
36899 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-oji', '18-oji');
36900 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-oji', '19-oji');
36901 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-oji', '20-oji');
36902
36903 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-oji', '21-oji');
36904 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-oji', '22-oji');
36905 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-oji', '23-oji');
36906 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-oji', '24-oji');
36907 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-oji', '25-oji');
36908 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-oji', '26-oji');
36909 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-oji', '27-oji');
36910 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-oji', '28-oji');
36911 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-oji', '29-oji');
36912 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-oji', '30-oji');
36913
36914 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-oji', '31-oji');
36915 });
36916
36917 test('format month', function (assert) {
36918 var expected = 'sausis sau_vasaris vas_kovas kov_balandis bal_gegužė geg_birželis bir_liepa lie_rugpjūtis rgp_rugsėjis rgs_spalis spa_lapkritis lap_gruodis grd'.split('_'), i;
36919 for (i = 0; i < expected.length; i++) {
36920 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
36921 }
36922 });
36923
36924 test('format week', function (assert) {
36925 var expected = 'sekmadienis Sek S_pirmadienis Pir P_antradienis Ant A_trečiadienis Tre T_ketvirtadienis Ket K_penktadienis Pen Pn_šeštadienis Šeš Š'.split('_'), i;
36926 for (i = 0; i < expected.length; i++) {
36927 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
36928 }
36929 });
36930
36931 test('format week on US calendar', function (assert) {
36932 // Tests, whether the weekday names are correct, even if the week does not start on Monday
36933 moment.updateLocale('lt', {week: {dow: 0, doy: 6}});
36934 var expected = 'sekmadienis Sek S_pirmadienis Pir P_antradienis Ant A_trečiadienis Tre T_ketvirtadienis Ket K_penktadienis Pen Pn_šeštadienis Šeš Š'.split('_'), i;
36935 for (i = 0; i < expected.length; i++) {
36936 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
36937 }
36938 moment.updateLocale('lt', null);
36939 });
36940
36941 test('from', function (assert) {
36942 var start = moment([2007, 1, 28]);
36943 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'kelios sekundės', '44 seconds = seconds');
36944 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minutė', '45 seconds = a minute');
36945 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minutė', '89 seconds = a minute');
36946 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutės', '90 seconds = 2 minutes');
36947 assert.equal(start.from(moment([2007, 1, 28]).add({m: 10}), true), '10 minučių', '10 minutes = 10 minutes');
36948 assert.equal(start.from(moment([2007, 1, 28]).add({m: 11}), true), '11 minučių', '11 minutes = 11 minutes');
36949 assert.equal(start.from(moment([2007, 1, 28]).add({m: 19}), true), '19 minučių', '19 minutes = 19 minutes');
36950 assert.equal(start.from(moment([2007, 1, 28]).add({m: 20}), true), '20 minučių', '20 minutes = 20 minutes');
36951 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutės', '44 minutes = 44 minutes');
36952 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'valanda', '45 minutes = an hour');
36953 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'valanda', '89 minutes = an hour');
36954 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 valandos', '90 minutes = 2 hours');
36955 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 valandos', '5 hours = 5 hours');
36956 assert.equal(start.from(moment([2007, 1, 28]).add({h: 10}), true), '10 valandų', '10 hours = 10 hours');
36957 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 valandos', '21 hours = 21 hours');
36958 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'diena', '22 hours = a day');
36959 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'diena', '35 hours = a day');
36960 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dienos', '36 hours = 2 days');
36961 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'diena', '1 day = a day');
36962 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dienos', '5 days = 5 days');
36963 assert.equal(start.from(moment([2007, 1, 28]).add({d: 10}), true), '10 dienų', '10 days = 10 days');
36964 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dienos', '25 days = 25 days');
36965 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mėnuo', '26 days = a month');
36966 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mėnuo', '30 days = a month');
36967 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mėnuo', '43 days = a month');
36968 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mėnesiai', '46 days = 2 months');
36969 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mėnesiai', '75 days = 2 months');
36970 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mėnesiai', '76 days = 3 months');
36971 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mėnuo', '1 month = a month');
36972 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mėnesiai', '5 months = 5 months');
36973 assert.equal(start.from(moment([2007, 1, 28]).add({M: 10}), true), '10 mėnesių', '10 months = 10 months');
36974 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'metai', '345 days = a year');
36975 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 metai', '548 days = 2 years');
36976 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'metai', '1 year = a year');
36977 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 metai', '5 years = 5 years');
36978 });
36979
36980 test('suffix', function (assert) {
36981 assert.equal(moment(30000).from(0), 'po kelių sekundžių', 'prefix');
36982 assert.equal(moment(0).from(30000), 'prieš kelias sekundes', 'suffix');
36983 });
36984
36985 test('now from now', function (assert) {
36986 assert.equal(moment().fromNow(), 'prieš kelias sekundes', 'now from now should display as in the past');
36987 });
36988
36989 test('fromNow', function (assert) {
36990 assert.equal(moment().add({s: 30}).fromNow(), 'po kelių sekundžių', 'in seconds');
36991 assert.equal(moment().add({d: 5}).fromNow(), 'po 5 dienų', 'in 5 days');
36992 });
36993
36994 test('calendar day', function (assert) {
36995 var a = moment().hours(12).minutes(0).seconds(0);
36996
36997 assert.equal(moment(a).calendar(), 'Šiandien 12:00', 'today at the same time');
36998 assert.equal(moment(a).add({m: 25}).calendar(), 'Šiandien 12:25', 'Now plus 25 min');
36999 assert.equal(moment(a).add({h: 1}).calendar(), 'Šiandien 13:00', 'Now plus 1 hour');
37000 assert.equal(moment(a).add({d: 1}).calendar(), 'Rytoj 12:00', 'tomorrow at the same time');
37001 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Šiandien 11:00', 'Now minus 1 hour');
37002 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Vakar 12:00', 'yesterday at the same time');
37003 });
37004
37005 test('calendar next week', function (assert) {
37006 var i, m;
37007 for (i = 2; i < 7; i++) {
37008 m = moment().add({d: i});
37009 assert.equal(m.calendar(), m.format('dddd LT'), 'Today + ' + i + ' days current time');
37010 m.hours(0).minutes(0).seconds(0).milliseconds(0);
37011 assert.equal(m.calendar(), m.format('dddd LT'), 'Today + ' + i + ' days beginning of day');
37012 m.hours(23).minutes(59).seconds(59).milliseconds(999);
37013 assert.equal(m.calendar(), m.format('dddd LT'), 'Today + ' + i + ' days end of day');
d6651c21 37014 }
db71a655 37015 });
73f3c911 37016
db71a655
KM
37017 test('calendar last week', function (assert) {
37018 var i, m;
37019 for (i = 2; i < 7; i++) {
37020 m = moment().subtract({d: i});
37021 assert.equal(m.calendar(), m.format('[Praėjusį] dddd LT'), 'Today - ' + i + ' days current time');
37022 m.hours(0).minutes(0).seconds(0).milliseconds(0);
37023 assert.equal(m.calendar(), m.format('[Praėjusį] dddd LT'), 'Today - ' + i + ' days beginning of day');
37024 m.hours(23).minutes(59).seconds(59).milliseconds(999);
37025 assert.equal(m.calendar(), m.format('[Praėjusį] dddd LT'), 'Today - ' + i + ' days end of day');
73f3c911 37026 }
db71a655 37027 });
516f5f67 37028
db71a655
KM
37029 test('calendar all else', function (assert) {
37030 var weeksAgo = moment().subtract({w: 1}),
37031 weeksFromNow = moment().add({w: 1});
516f5f67 37032
db71a655
KM
37033 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
37034 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 37035
db71a655
KM
37036 weeksAgo = moment().subtract({w: 2});
37037 weeksFromNow = moment().add({w: 2});
c74a101d 37038
db71a655
KM
37039 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
37040 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
37041 });
37042
37043 test('weeks year starting sunday formatted', function (assert) {
37044 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52-oji', 'Jan 1 2012 should be week 52');
37045 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1-oji', 'Jan 2 2012 should be week 1');
37046 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1-oji', 'Jan 8 2012 should be week 1');
37047 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2-oji', 'Jan 9 2012 should be week 2');
37048 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2-oji', 'Jan 15 2012 should be week 2');
37049 });
37050
37051 test('month cases', function (assert) {
37052 assert.equal(moment([2015, 4, 1]).format('LL'), '2015 m. gegužės 1 d.', 'uses format instead of standalone form');
37053 });
73f3c911
IC
37054
37055})));
37056
37057
37058;(function (global, factory) {
37059 typeof exports === 'object' && typeof module !== 'undefined'
37060 && typeof require === 'function' ? factory(require('../../moment')) :
37061 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
37062 factory(global.moment)
37063}(this, (function (moment) { 'use strict';
c74a101d 37064
db71a655
KM
37065 function each(array, callback) {
37066 var i;
37067 for (i = 0; i < array.length; i++) {
37068 callback(array[i], i, array);
37069 }
73f3c911 37070 }
73f3c911 37071
c58511b9
KM
37072 function setupDeprecationHandler(test, moment$$1, scope) {
37073 test._expectedDeprecations = null;
37074 test._observedDeprecations = null;
37075 test._oldSupress = moment$$1.suppressDeprecationWarnings;
37076 moment$$1.suppressDeprecationWarnings = true;
37077 test.expectedDeprecations = function () {
37078 test._expectedDeprecations = arguments;
37079 test._observedDeprecations = [];
37080 };
37081 moment$$1.deprecationHandler = function (name, msg) {
37082 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
37083 if (deprecationId === -1) {
37084 throw new Error('Unexpected deprecation thrown name=' +
37085 name + ' msg=' + msg);
37086 }
37087 test._observedDeprecations[deprecationId] = 1;
37088 };
37089 }
37090
37091 function teardownDeprecationHandler(test, moment$$1, scope) {
37092 moment$$1.suppressDeprecationWarnings = test._oldSupress;
37093
37094 if (test._expectedDeprecations != null) {
37095 var missedDeprecations = [];
37096 each(test._expectedDeprecations, function (deprecationPattern, id) {
37097 if (test._observedDeprecations[id] !== 1) {
37098 missedDeprecations.push(deprecationPattern);
37099 }
37100 });
37101 if (missedDeprecations.length !== 0) {
37102 throw new Error('Expected deprecation warnings did not happen: ' +
37103 missedDeprecations.join(' '));
37104 }
37105 }
37106 }
37107
37108 function matchedDeprecation(name, msg, deprecations) {
37109 if (deprecations == null) {
37110 return -1;
37111 }
37112 for (var i = 0; i < deprecations.length; ++i) {
37113 if (name != null && name === deprecations[i]) {
37114 return i;
37115 }
37116 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
37117 return i;
37118 }
37119 }
37120 return -1;
37121 }
37122
37123 /*global QUnit:false*/
37124
37125 var test = QUnit.test;
37126
db71a655
KM
37127 function objectKeys(obj) {
37128 if (Object.keys) {
37129 return Object.keys(obj);
37130 } else {
37131 // IE8
37132 var res = [], i;
37133 for (i in obj) {
37134 if (obj.hasOwnProperty(i)) {
37135 res.push(i);
37136 }
c74a101d 37137 }
db71a655 37138 return res;
c74a101d 37139 }
73f3c911 37140 }
c74a101d 37141
db71a655 37142 // Pick the first defined of two or three arguments.
73f3c911 37143
db71a655
KM
37144 function defineCommonLocaleTests(locale, options) {
37145 test('lenient day of month ordinal parsing', function (assert) {
37146 var i, ordinalStr, testMoment;
37147 for (i = 1; i <= 31; ++i) {
37148 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
37149 testMoment = moment(ordinalStr, 'YYYY MM Do');
37150 assert.equal(testMoment.year(), 2014,
37151 'lenient day of month ordinal parsing ' + i + ' year check');
37152 assert.equal(testMoment.month(), 0,
37153 'lenient day of month ordinal parsing ' + i + ' month check');
37154 assert.equal(testMoment.date(), i,
37155 'lenient day of month ordinal parsing ' + i + ' date check');
37156 }
37157 });
516f5f67 37158
db71a655
KM
37159 test('lenient day of month ordinal parsing of number', function (assert) {
37160 var i, testMoment;
37161 for (i = 1; i <= 31; ++i) {
37162 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
37163 assert.equal(testMoment.year(), 2014,
37164 'lenient day of month ordinal parsing of number ' + i + ' year check');
37165 assert.equal(testMoment.month(), 0,
37166 'lenient day of month ordinal parsing of number ' + i + ' month check');
37167 assert.equal(testMoment.date(), i,
37168 'lenient day of month ordinal parsing of number ' + i + ' date check');
37169 }
37170 });
37171
37172 test('strict day of month ordinal parsing', function (assert) {
37173 var i, ordinalStr, testMoment;
37174 for (i = 1; i <= 31; ++i) {
37175 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
37176 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
37177 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
37178 }
37179 });
c74a101d 37180
db71a655
KM
37181 test('meridiem invariant', function (assert) {
37182 var h, m, t1, t2;
37183 for (h = 0; h < 24; ++h) {
37184 for (m = 0; m < 60; m += 15) {
37185 t1 = moment.utc([2000, 0, 1, h, m]);
37186 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
37187 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
37188 'meridiem at ' + t1.format('HH:mm'));
37189 }
37190 }
37191 });
516f5f67 37192
db71a655
KM
37193 test('date format correctness', function (assert) {
37194 var data, tokens;
37195 data = moment.localeData()._longDateFormat;
37196 tokens = objectKeys(data);
37197 each(tokens, function (srchToken) {
37198 // Check each format string to make sure it does not contain any
37199 // tokens that need to be expanded.
37200 each(tokens, function (baseToken) {
37201 // strip escaped sequences
37202 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
37203 assert.equal(false, !!~format.indexOf(srchToken),
37204 'contains ' + srchToken + ' in ' + baseToken);
37205 });
73f3c911
IC
37206 });
37207 });
516f5f67 37208
db71a655
KM
37209 test('month parsing correctness', function (assert) {
37210 var i, m;
37211
37212 if (locale === 'tr') {
37213 // I can't fix it :(
c58511b9 37214 assert.expect(0);
db71a655
KM
37215 return;
37216 }
37217 function tester(format) {
37218 var r;
37219 r = moment(m.format(format), format);
37220 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
37221 if (locale !== 'ka') {
37222 r = moment(m.format(format).toLocaleUpperCase(), format);
37223 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
37224 }
db71a655
KM
37225 r = moment(m.format(format).toLocaleLowerCase(), format);
37226 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
37227
37228 r = moment(m.format(format), format, true);
37229 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
37230 if (locale !== 'ka') {
37231 r = moment(m.format(format).toLocaleUpperCase(), format, true);
37232 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
37233 }
db71a655
KM
37234 r = moment(m.format(format).toLocaleLowerCase(), format, true);
37235 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
37236 }
37237
37238 for (i = 0; i < 12; ++i) {
37239 m = moment([2015, i, 15, 18]);
37240 tester('MMM');
37241 tester('MMM.');
37242 tester('MMMM');
37243 tester('MMMM.');
37244 }
37245 });
516f5f67 37246
db71a655
KM
37247 test('weekday parsing correctness', function (assert) {
37248 var i, m;
37249
96d0d679 37250 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
37251 // tr, az: There is a lower-case letter (ı), that converted to
37252 // upper then lower changes to i
37253 // ro: there is the letter ț which behaves weird under IE8
37254 // mt: letter Ħ
96d0d679 37255 // ga: month with spaces
c58511b9 37256 assert.expect(0);
db71a655
KM
37257 return;
37258 }
37259 function tester(format) {
37260 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
37261 r = moment(m.format(format), format);
37262 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
37263 if (locale !== 'ka') {
37264 r = moment(m.format(format).toLocaleUpperCase(), format);
37265 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
37266 }
db71a655
KM
37267 r = moment(m.format(format).toLocaleLowerCase(), format);
37268 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
37269 r = moment(m.format(format), format, true);
37270 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
37271 if (locale !== 'ka') {
37272 r = moment(m.format(format).toLocaleUpperCase(), format, true);
37273 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
37274 }
db71a655
KM
37275 r = moment(m.format(format).toLocaleLowerCase(), format, true);
37276 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
37277 }
37278
37279 for (i = 0; i < 7; ++i) {
37280 m = moment.utc([2015, 0, i + 1, 18]);
37281 tester('dd');
37282 tester('ddd');
37283 tester('dddd');
37284 }
37285 });
516f5f67 37286
db71a655
KM
37287 test('valid localeData', function (assert) {
37288 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
37289 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
37290 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
37291 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
37292 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
37293 });
96d0d679
KM
37294
37295 test('localeData weekdays can localeSort', function (assert) {
37296 var weekdays = moment().localeData().weekdays();
37297 var weekdaysShort = moment().localeData().weekdaysShort();
37298 var weekdaysMin = moment().localeData().weekdaysMin();
37299 var shift = moment().localeData()._week.dow;
37300 assert.deepEqual(
37301 moment().localeData().weekdays(true),
37302 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
37303 'weekdays should localeSort');
37304 assert.deepEqual(
37305 moment().localeData().weekdaysShort(true),
37306 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
37307 'weekdaysShort should localeSort');
37308 assert.deepEqual(
37309 moment().localeData().weekdaysMin(true),
37310 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
37311 'weekdaysMin should localeSort');
37312 });
db71a655 37313 }
516f5f67 37314
db71a655 37315 /*global QUnit:false*/
73f3c911 37316
db71a655
KM
37317 function localeModule (name, lifecycle) {
37318 QUnit.module('locale:' + name, {
c58511b9 37319 beforeEach : function () {
db71a655
KM
37320 moment.locale(name);
37321 moment.createFromInputFallback = function (config) {
37322 throw new Error('input not handled by moment: ' + config._i);
37323 };
37324 setupDeprecationHandler(test, moment, 'locale');
37325 if (lifecycle && lifecycle.setup) {
37326 lifecycle.setup();
37327 }
37328 },
c58511b9 37329 afterEach : function () {
db71a655
KM
37330 moment.locale('en');
37331 teardownDeprecationHandler(test, moment, 'locale');
37332 if (lifecycle && lifecycle.teardown) {
37333 lifecycle.teardown();
37334 }
b135bf1a 37335 }
73f3c911 37336 });
db71a655
KM
37337 defineCommonLocaleTests(name, -1, -1);
37338 }
37339
37340 localeModule('lv');
37341
37342 test('parse', function (assert) {
37343 var tests = 'janvāris jan_februāris feb_marts mar_aprīlis apr_maijs mai_jūnijs jūn_jūlijs jūl_augusts aug_septembris sep_oktobris okt_novembris nov_decembris dec'.split('_'), i;
37344 function equalTest(input, mmm, i) {
37345 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
37346 }
37347 for (i = 0; i < 12; i++) {
37348 tests[i] = tests[i].split(' ');
37349 equalTest(tests[i][0], 'MMM', i);
37350 equalTest(tests[i][1], 'MMM', i);
37351 equalTest(tests[i][0], 'MMMM', i);
37352 equalTest(tests[i][1], 'MMMM', i);
37353 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
37354 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
37355 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
37356 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
37357 }
37358 });
37359
37360 test('format', function (assert) {
37361 var a = [
37362 ['dddd, Do MMMM YYYY, h:mm:ss a', 'svētdiena, 14. februāris 2010, 3:25:50 pm'],
37363 ['ddd, hA', 'Sv, 3PM'],
37364 ['M Mo MM MMMM MMM', '2 2. 02 februāris feb'],
37365 ['YYYY YY', '2010 10'],
37366 ['D Do DD', '14 14. 14'],
37367 ['d do dddd ddd dd', '0 0. svētdiena Sv Sv'],
37368 ['DDD DDDo DDDD', '45 45. 045'],
37369 ['w wo ww', '6 6. 06'],
37370 ['h hh', '3 03'],
37371 ['H HH', '15 15'],
37372 ['m mm', '25 25'],
37373 ['s ss', '50 50'],
37374 ['a A', 'pm PM'],
37375 ['[the] DDDo [day of the year]', 'the 45. day of the year'],
37376 ['LTS', '15:25:50'],
37377 ['L', '14.02.2010.'],
37378 ['LL', '2010. gada 14. februāris'],
37379 ['LLL', '2010. gada 14. februāris, 15:25'],
37380 ['LLLL', '2010. gada 14. februāris, svētdiena, 15:25'],
37381 ['l', '14.2.2010.'],
37382 ['ll', '2010. gada 14. feb'],
37383 ['lll', '2010. gada 14. feb, 15:25'],
37384 ['llll', '2010. gada 14. feb, Sv, 15:25']
37385 ],
37386 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
37387 i;
37388 for (i = 0; i < a.length; i++) {
37389 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
37390 }
37391 });
37392
37393 test('format ordinal', function (assert) {
37394 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
37395 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
37396 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
37397 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
37398 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
37399 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
37400 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
37401 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
37402 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
37403 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
37404
37405 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
37406 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
37407 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
37408 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
37409 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
37410 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
37411 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
37412 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
37413 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
37414 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
37415
37416 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
37417 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
37418 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
37419 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
37420 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
37421 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
37422 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
37423 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
37424 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
37425 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
37426
37427 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
37428 });
37429
37430 test('format month', function (assert) {
37431 var expected = 'janvāris jan_februāris feb_marts mar_aprīlis apr_maijs mai_jūnijs jūn_jūlijs jūl_augusts aug_septembris sep_oktobris okt_novembris nov_decembris dec'.split('_'), i;
37432 for (i = 0; i < expected.length; i++) {
37433 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
37434 }
37435 });
37436
37437 test('format week', function (assert) {
37438 var expected = 'svētdiena Sv Sv_pirmdiena P P_otrdiena O O_trešdiena T T_ceturtdiena C C_piektdiena Pk Pk_sestdiena S S'.split('_'), i;
37439 for (i = 0; i < expected.length; i++) {
37440 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
37441 }
37442 });
37443
37444 // Includes testing the cases of withoutSuffix = true and false.
37445 test('from', function (assert) {
37446 var start = moment([2007, 1, 28]);
37447 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'dažas sekundes', '44 seconds = seconds');
37448 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), false), 'pirms dažām sekundēm', '44 seconds with suffix = seconds ago');
37449 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minūte', '45 seconds = a minute');
37450 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), false), 'pirms minūtes', '45 seconds with suffix = a minute ago');
37451 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minūte', '89 seconds = a minute');
37452 assert.equal(start.from(moment([2007, 1, 28]).add({s: -89}), false), 'pēc minūtes', '89 seconds with suffix/prefix = in a minute');
37453 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minūtes', '90 seconds = 2 minutes');
37454 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), false), 'pirms 2 minūtēm', '90 seconds with suffix = 2 minutes ago');
37455 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minūtes', '44 minutes = 44 minutes');
37456 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), false), 'pirms 44 minūtēm', '44 minutes with suffix = 44 minutes ago');
37457 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'stunda', '45 minutes = an hour');
37458 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), false), 'pirms stundas', '45 minutes with suffix = an hour ago');
37459 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'stunda', '89 minutes = an hour');
37460 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 stundas', '90 minutes = 2 hours');
37461 assert.equal(start.from(moment([2007, 1, 28]).add({m: -90}), false), 'pēc 2 stundām', '90 minutes with suffix = in 2 hours');
37462 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 stundas', '5 hours = 5 hours');
37463 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), false), 'pirms 5 stundām', '5 hours with suffix = 5 hours ago');
37464 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 stunda', '21 hours = 21 hours');
37465 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), false), 'pirms 21 stundas', '21 hours with suffix = 21 hours ago');
37466 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'diena', '22 hours = a day');
37467 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), false), 'pirms dienas', '22 hours with suffix = a day ago');
37468 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'diena', '35 hours = a day');
37469 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dienas', '36 hours = 2 days');
37470 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), false), 'pirms 2 dienām', '36 hours with suffix = 2 days ago');
37471 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'diena', '1 day = a day');
37472 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dienas', '5 days = 5 days');
37473 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), false), 'pirms 5 dienām', '5 days with suffix = 5 days ago');
37474 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dienas', '25 days = 25 days');
37475 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), false), 'pirms 25 dienām', '25 days with suffix = 25 days ago');
37476 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mēnesis', '26 days = a month');
37477 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), false), 'pirms mēneša', '26 days with suffix = a month ago');
37478 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mēnesis', '30 days = a month');
37479 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mēnesis', '43 days = a month');
37480 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mēneši', '46 days = 2 months');
37481 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), false), 'pirms 2 mēnešiem', '46 days with suffix = 2 months ago');
37482 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mēneši', '75 days = 2 months');
37483 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mēneši', '76 days = 3 months');
37484 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), false), 'pirms 3 mēnešiem', '76 days with suffix = 3 months ago');
37485 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mēnesis', '1 month = a month');
37486 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mēneši', '5 months = 5 months');
37487 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), false), 'pirms 5 mēnešiem', '5 months with suffix = 5 months ago');
37488 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'gads', '345 days = a year');
37489 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), false), 'pirms gada', '345 days with suffix = a year ago');
37490 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 gadi', '548 days = 2 years');
37491 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), false), 'pirms 2 gadiem', '548 days with suffix = 2 years ago');
37492 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'gads', '1 year = a year');
37493 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 gadi', '5 years = 5 years');
37494 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), false), 'pirms 5 gadiem', '5 years with suffix = 5 years ago');
37495
37496 // test that numbers ending with 1 are singular except for when they end with 11 in which case they are plural
37497 assert.equal(start.from(moment([2007, 1, 28]).add({y: 11}), true), '11 gadi', '11 years = 11 years');
37498 assert.equal(start.from(moment([2007, 1, 28]).add({y: 21}), true), '21 gads', '21 year = 21 year');
37499 assert.equal(start.from(moment([2007, 1, 28]).add({y: 211}), true), '211 gadi', '211 years = 211 years');
37500 assert.equal(start.from(moment([2007, 1, 28]).add({y: 221}), false), 'pirms 221 gada', '221 year with suffix = 221 years ago');
37501 });
37502
37503 test('suffix', function (assert) {
37504 assert.equal(moment(30000).from(0), 'pēc dažām sekundēm', 'prefix');
37505 assert.equal(moment(0).from(30000), 'pirms dažām sekundēm', 'suffix');
37506 });
37507
37508 test('now from now', function (assert) {
37509 assert.equal(moment().fromNow(), 'pirms dažām sekundēm', 'now from now should display as in the past');
37510 });
37511
37512 test('fromNow', function (assert) {
37513 assert.equal(moment().add({s: 30}).fromNow(), 'pēc dažām sekundēm', 'in seconds');
37514 assert.equal(moment().add({d: 5}).fromNow(), 'pēc 5 dienām', 'in 5 days');
37515 });
37516
37517 test('calendar day', function (assert) {
37518 var a = moment().hours(12).minutes(0).seconds(0);
37519
37520 assert.equal(moment(a).calendar(), 'Šodien pulksten 12:00', 'today at the same time');
37521 assert.equal(moment(a).add({m: 25}).calendar(), 'Šodien pulksten 12:25', 'Now plus 25 min');
37522 assert.equal(moment(a).add({h: 1}).calendar(), 'Šodien pulksten 13:00', 'Now plus 1 hour');
37523 assert.equal(moment(a).add({d: 1}).calendar(), 'Rīt pulksten 12:00', 'tomorrow at the same time');
37524 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Šodien pulksten 11:00', 'Now minus 1 hour');
37525 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Vakar pulksten 12:00', 'yesterday at the same time');
37526 });
37527
37528 test('calendar next week', function (assert) {
37529 var i, m;
37530 for (i = 2; i < 7; i++) {
37531 m = moment().add({d: i});
37532 assert.equal(m.calendar(), m.format('dddd [pulksten] LT'), 'Today + ' + i + ' days current time');
37533 m.hours(0).minutes(0).seconds(0).milliseconds(0);
37534 assert.equal(m.calendar(), m.format('dddd [pulksten] LT'), 'Today + ' + i + ' days beginning of day');
37535 m.hours(23).minutes(59).seconds(59).milliseconds(999);
37536 assert.equal(m.calendar(), m.format('dddd [pulksten] LT'), 'Today + ' + i + ' days end of day');
b135bf1a 37537 }
db71a655 37538 });
b135bf1a 37539
db71a655
KM
37540 test('calendar last week', function (assert) {
37541 var i, m;
37542 for (i = 2; i < 7; i++) {
37543 m = moment().subtract({d: i});
37544 assert.equal(m.calendar(), m.format('[Pagājušā] dddd [pulksten] LT'), 'Today - ' + i + ' days current time');
37545 m.hours(0).minutes(0).seconds(0).milliseconds(0);
37546 assert.equal(m.calendar(), m.format('[Pagājušā] dddd [pulksten] LT'), 'Today - ' + i + ' days beginning of day');
37547 m.hours(23).minutes(59).seconds(59).milliseconds(999);
37548 assert.equal(m.calendar(), m.format('[Pagājušā] dddd [pulksten] LT'), 'Today - ' + i + ' days end of day');
b135bf1a 37549 }
db71a655 37550 });
b135bf1a 37551
db71a655
KM
37552 test('calendar all else', function (assert) {
37553 var weeksAgo = moment().subtract({w: 1}),
37554 weeksFromNow = moment().add({w: 1});
b135bf1a 37555
db71a655
KM
37556 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
37557 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
b135bf1a 37558
db71a655
KM
37559 weeksAgo = moment().subtract({w: 2});
37560 weeksFromNow = moment().add({w: 2});
b135bf1a 37561
db71a655
KM
37562 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
37563 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
37564 });
37565
37566 test('weeks year starting sunday formatted', function (assert) {
37567 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
37568 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
37569 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
37570 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
37571 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
37572 });
9483e2a4
IC
37573
37574})));
37575
37576
37577;(function (global, factory) {
37578 typeof exports === 'object' && typeof module !== 'undefined'
37579 && typeof require === 'function' ? factory(require('../../moment')) :
37580 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
37581 factory(global.moment)
37582}(this, (function (moment) { 'use strict';
37583
db71a655
KM
37584 function each(array, callback) {
37585 var i;
37586 for (i = 0; i < array.length; i++) {
37587 callback(array[i], i, array);
37588 }
9483e2a4 37589 }
9483e2a4 37590
c58511b9
KM
37591 function setupDeprecationHandler(test, moment$$1, scope) {
37592 test._expectedDeprecations = null;
37593 test._observedDeprecations = null;
37594 test._oldSupress = moment$$1.suppressDeprecationWarnings;
37595 moment$$1.suppressDeprecationWarnings = true;
37596 test.expectedDeprecations = function () {
37597 test._expectedDeprecations = arguments;
37598 test._observedDeprecations = [];
37599 };
37600 moment$$1.deprecationHandler = function (name, msg) {
37601 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
37602 if (deprecationId === -1) {
37603 throw new Error('Unexpected deprecation thrown name=' +
37604 name + ' msg=' + msg);
37605 }
37606 test._observedDeprecations[deprecationId] = 1;
37607 };
37608 }
37609
37610 function teardownDeprecationHandler(test, moment$$1, scope) {
37611 moment$$1.suppressDeprecationWarnings = test._oldSupress;
37612
37613 if (test._expectedDeprecations != null) {
37614 var missedDeprecations = [];
37615 each(test._expectedDeprecations, function (deprecationPattern, id) {
37616 if (test._observedDeprecations[id] !== 1) {
37617 missedDeprecations.push(deprecationPattern);
37618 }
37619 });
37620 if (missedDeprecations.length !== 0) {
37621 throw new Error('Expected deprecation warnings did not happen: ' +
37622 missedDeprecations.join(' '));
37623 }
37624 }
37625 }
37626
37627 function matchedDeprecation(name, msg, deprecations) {
37628 if (deprecations == null) {
37629 return -1;
37630 }
37631 for (var i = 0; i < deprecations.length; ++i) {
37632 if (name != null && name === deprecations[i]) {
37633 return i;
37634 }
37635 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
37636 return i;
37637 }
37638 }
37639 return -1;
37640 }
37641
37642 /*global QUnit:false*/
37643
37644 var test = QUnit.test;
37645
db71a655
KM
37646 function objectKeys(obj) {
37647 if (Object.keys) {
37648 return Object.keys(obj);
37649 } else {
37650 // IE8
37651 var res = [], i;
37652 for (i in obj) {
37653 if (obj.hasOwnProperty(i)) {
37654 res.push(i);
37655 }
9483e2a4 37656 }
db71a655 37657 return res;
9483e2a4 37658 }
9483e2a4 37659 }
9483e2a4 37660
db71a655 37661 // Pick the first defined of two or three arguments.
9483e2a4 37662
db71a655
KM
37663 function defineCommonLocaleTests(locale, options) {
37664 test('lenient day of month ordinal parsing', function (assert) {
37665 var i, ordinalStr, testMoment;
37666 for (i = 1; i <= 31; ++i) {
37667 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
37668 testMoment = moment(ordinalStr, 'YYYY MM Do');
37669 assert.equal(testMoment.year(), 2014,
37670 'lenient day of month ordinal parsing ' + i + ' year check');
37671 assert.equal(testMoment.month(), 0,
37672 'lenient day of month ordinal parsing ' + i + ' month check');
37673 assert.equal(testMoment.date(), i,
37674 'lenient day of month ordinal parsing ' + i + ' date check');
37675 }
37676 });
9483e2a4 37677
db71a655
KM
37678 test('lenient day of month ordinal parsing of number', function (assert) {
37679 var i, testMoment;
37680 for (i = 1; i <= 31; ++i) {
37681 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
37682 assert.equal(testMoment.year(), 2014,
37683 'lenient day of month ordinal parsing of number ' + i + ' year check');
37684 assert.equal(testMoment.month(), 0,
37685 'lenient day of month ordinal parsing of number ' + i + ' month check');
37686 assert.equal(testMoment.date(), i,
37687 'lenient day of month ordinal parsing of number ' + i + ' date check');
37688 }
37689 });
9483e2a4 37690
db71a655
KM
37691 test('strict day of month ordinal parsing', function (assert) {
37692 var i, ordinalStr, testMoment;
37693 for (i = 1; i <= 31; ++i) {
37694 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
37695 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
37696 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
37697 }
37698 });
9483e2a4 37699
db71a655
KM
37700 test('meridiem invariant', function (assert) {
37701 var h, m, t1, t2;
37702 for (h = 0; h < 24; ++h) {
37703 for (m = 0; m < 60; m += 15) {
37704 t1 = moment.utc([2000, 0, 1, h, m]);
37705 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
37706 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
37707 'meridiem at ' + t1.format('HH:mm'));
37708 }
37709 }
37710 });
37711
37712 test('date format correctness', function (assert) {
37713 var data, tokens;
37714 data = moment.localeData()._longDateFormat;
37715 tokens = objectKeys(data);
37716 each(tokens, function (srchToken) {
37717 // Check each format string to make sure it does not contain any
37718 // tokens that need to be expanded.
37719 each(tokens, function (baseToken) {
37720 // strip escaped sequences
37721 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
37722 assert.equal(false, !!~format.indexOf(srchToken),
37723 'contains ' + srchToken + ' in ' + baseToken);
37724 });
9483e2a4
IC
37725 });
37726 });
9483e2a4 37727
db71a655
KM
37728 test('month parsing correctness', function (assert) {
37729 var i, m;
37730
37731 if (locale === 'tr') {
37732 // I can't fix it :(
c58511b9 37733 assert.expect(0);
db71a655
KM
37734 return;
37735 }
37736 function tester(format) {
37737 var r;
37738 r = moment(m.format(format), format);
37739 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
37740 if (locale !== 'ka') {
37741 r = moment(m.format(format).toLocaleUpperCase(), format);
37742 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
37743 }
db71a655
KM
37744 r = moment(m.format(format).toLocaleLowerCase(), format);
37745 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
37746
37747 r = moment(m.format(format), format, true);
37748 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
37749 if (locale !== 'ka') {
37750 r = moment(m.format(format).toLocaleUpperCase(), format, true);
37751 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
37752 }
db71a655
KM
37753 r = moment(m.format(format).toLocaleLowerCase(), format, true);
37754 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
37755 }
37756
37757 for (i = 0; i < 12; ++i) {
37758 m = moment([2015, i, 15, 18]);
37759 tester('MMM');
37760 tester('MMM.');
37761 tester('MMMM');
37762 tester('MMMM.');
37763 }
37764 });
9483e2a4 37765
db71a655
KM
37766 test('weekday parsing correctness', function (assert) {
37767 var i, m;
37768
96d0d679 37769 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
37770 // tr, az: There is a lower-case letter (ı), that converted to
37771 // upper then lower changes to i
37772 // ro: there is the letter ț which behaves weird under IE8
37773 // mt: letter Ħ
96d0d679 37774 // ga: month with spaces
c58511b9 37775 assert.expect(0);
db71a655
KM
37776 return;
37777 }
37778 function tester(format) {
37779 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
37780 r = moment(m.format(format), format);
37781 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
37782 if (locale !== 'ka') {
37783 r = moment(m.format(format).toLocaleUpperCase(), format);
37784 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
37785 }
db71a655
KM
37786 r = moment(m.format(format).toLocaleLowerCase(), format);
37787 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
37788 r = moment(m.format(format), format, true);
37789 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
37790 if (locale !== 'ka') {
37791 r = moment(m.format(format).toLocaleUpperCase(), format, true);
37792 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
37793 }
db71a655
KM
37794 r = moment(m.format(format).toLocaleLowerCase(), format, true);
37795 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
37796 }
37797
37798 for (i = 0; i < 7; ++i) {
37799 m = moment.utc([2015, 0, i + 1, 18]);
37800 tester('dd');
37801 tester('ddd');
37802 tester('dddd');
37803 }
37804 });
9483e2a4 37805
db71a655
KM
37806 test('valid localeData', function (assert) {
37807 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
37808 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
37809 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
37810 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
37811 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
37812 });
96d0d679
KM
37813
37814 test('localeData weekdays can localeSort', function (assert) {
37815 var weekdays = moment().localeData().weekdays();
37816 var weekdaysShort = moment().localeData().weekdaysShort();
37817 var weekdaysMin = moment().localeData().weekdaysMin();
37818 var shift = moment().localeData()._week.dow;
37819 assert.deepEqual(
37820 moment().localeData().weekdays(true),
37821 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
37822 'weekdays should localeSort');
37823 assert.deepEqual(
37824 moment().localeData().weekdaysShort(true),
37825 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
37826 'weekdaysShort should localeSort');
37827 assert.deepEqual(
37828 moment().localeData().weekdaysMin(true),
37829 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
37830 'weekdaysMin should localeSort');
37831 });
db71a655 37832 }
9483e2a4 37833
db71a655
KM
37834 /*global QUnit:false*/
37835
db71a655
KM
37836 function localeModule (name, lifecycle) {
37837 QUnit.module('locale:' + name, {
c58511b9 37838 beforeEach : function () {
db71a655
KM
37839 moment.locale(name);
37840 moment.createFromInputFallback = function (config) {
37841 throw new Error('input not handled by moment: ' + config._i);
37842 };
37843 setupDeprecationHandler(test, moment, 'locale');
37844 if (lifecycle && lifecycle.setup) {
37845 lifecycle.setup();
37846 }
37847 },
c58511b9 37848 afterEach : function () {
db71a655
KM
37849 moment.locale('en');
37850 teardownDeprecationHandler(test, moment, 'locale');
37851 if (lifecycle && lifecycle.teardown) {
37852 lifecycle.teardown();
37853 }
9483e2a4
IC
37854 }
37855 });
db71a655
KM
37856 defineCommonLocaleTests(name, -1, -1);
37857 }
37858
37859 localeModule('me');
37860
37861 test('parse', function (assert) {
37862 var tests = 'januar jan._februar feb._mart mar._april apr._maj maj_jun jun_jul jul_avgust avg._septembar sep._oktobar okt._novembar nov._decembar dec.'.split('_'),
37863 i;
37864 function equalTest(input, mmm, i) {
37865 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
37866 }
37867 for (i = 0; i < 12; i++) {
37868 tests[i] = tests[i].split(' ');
37869 equalTest(tests[i][0], 'MMM', i);
37870 equalTest(tests[i][1], 'MMM', i);
37871 equalTest(tests[i][0], 'MMMM', i);
37872 equalTest(tests[i][1], 'MMMM', i);
37873 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
37874 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
37875 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
37876 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
37877 }
37878 });
37879
37880 test('format', function (assert) {
37881 var a = [
37882 ['dddd, Do MMMM YYYY, h:mm:ss a', 'nedjelja, 14. februar 2010, 3:25:50 pm'],
37883 ['ddd, hA', 'ned., 3PM'],
37884 ['M Mo MM MMMM MMM', '2 2. 02 februar feb.'],
37885 ['YYYY YY', '2010 10'],
37886 ['D Do DD', '14 14. 14'],
37887 ['d do dddd ddd dd', '0 0. nedjelja ned. ne'],
37888 ['DDD DDDo DDDD', '45 45. 045'],
37889 ['w wo ww', '7 7. 07'],
37890 ['h hh', '3 03'],
37891 ['H HH', '15 15'],
37892 ['m mm', '25 25'],
37893 ['s ss', '50 50'],
37894 ['a A', 'pm PM'],
37895 ['[the] DDDo [day of the year]', 'the 45. day of the year'],
37896 ['LTS', '15:25:50'],
37897 ['L', '14.02.2010'],
37898 ['LL', '14. februar 2010'],
37899 ['LLL', '14. februar 2010 15:25'],
37900 ['LLLL', 'nedjelja, 14. februar 2010 15:25'],
37901 ['l', '14.2.2010'],
37902 ['ll', '14. feb. 2010'],
37903 ['lll', '14. feb. 2010 15:25'],
37904 ['llll', 'ned., 14. feb. 2010 15:25']
37905 ],
37906 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
37907 i;
37908 for (i = 0; i < a.length; i++) {
37909 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
37910 }
37911 });
37912
37913 test('format ordinal', function (assert) {
37914 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
37915 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
37916 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
37917 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
37918 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
37919 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
37920 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
37921 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
37922 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
37923 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
37924
37925 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
37926 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
37927 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
37928 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
37929 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
37930 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
37931 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
37932 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
37933 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
37934 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
37935
37936 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
37937 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
37938 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
37939 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
37940 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
37941 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
37942 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
37943 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
37944 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
37945 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
37946
37947 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
37948 });
37949
37950 test('format month', function (assert) {
37951 var expected = 'januar jan._februar feb._mart mar._april apr._maj maj_jun jun_jul jul_avgust avg._septembar sep._oktobar okt._novembar nov._decembar dec.'.split('_'),
37952 i;
37953 for (i = 0; i < expected.length; i++) {
37954 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
37955 }
37956 });
37957
37958 test('format week', function (assert) {
37959 var expected = 'nedjelja ned. ne_ponedjeljak pon. po_utorak uto. ut_srijeda sri. sr_četvrtak čet. če_petak pet. pe_subota sub. su'.split('_'),
37960 i;
37961 for (i = 0; i < expected.length; i++) {
37962 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
37963 }
37964 });
37965
37966 test('from', function (assert) {
37967 var start = moment([2007, 1, 28]);
37968 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'nekoliko sekundi', '44 seconds = a few seconds');
37969 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'jedan minut', '45 seconds = a minute');
37970 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'jedan minut', '89 seconds = a minute');
37971 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuta', '90 seconds = 2 minutes');
37972 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuta', '44 minutes = 44 minutes');
37973 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'jedan sat', '45 minutes = an hour');
37974 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'jedan sat', '89 minutes = an hour');
37975 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 sata', '90 minutes = 2 hours');
37976 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 sati', '5 hours = 5 hours');
37977 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 sati', '21 hours = 21 hours');
37978 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'dan', '22 hours = a day');
37979 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'dan', '35 hours = a day');
37980 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dana', '36 hours = 2 days');
37981 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'dan', '1 day = a day');
37982 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dana', '5 days = 5 days');
37983 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dana', '25 days = 25 days');
37984 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mjesec', '26 days = a month');
37985 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mjesec', '30 days = a month');
37986 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mjesec', '43 days = a month');
37987 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mjeseca', '46 days = 2 months');
37988 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mjeseca', '75 days = 2 months');
37989 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mjeseca', '76 days = 3 months');
37990 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mjesec', '1 month = a month');
37991 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mjeseci', '5 months = 5 months');
37992 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'godinu', '345 days = a year');
37993 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 godine', '548 days = 2 years');
37994 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'godinu', '1 year = a year');
37995 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 godina', '5 years = 5 years');
37996 });
37997
37998 test('suffix', function (assert) {
37999 assert.equal(moment(30000).from(0), 'za nekoliko sekundi', 'prefix');
38000 assert.equal(moment(0).from(30000), 'prije nekoliko sekundi', 'prefix');
38001 });
38002
38003 test('now from now', function (assert) {
38004 assert.equal(moment().fromNow(), 'prije nekoliko sekundi', 'now from now should display as in the past');
38005 });
38006
38007 test('fromNow', function (assert) {
38008 assert.equal(moment().add({s: 30}).fromNow(), 'za nekoliko sekundi', 'in a few seconds');
38009 assert.equal(moment().add({d: 5}).fromNow(), 'za 5 dana', 'in 5 days');
38010 });
38011
38012 test('calendar day', function (assert) {
38013 var a = moment().hours(12).minutes(0).seconds(0);
38014
38015 assert.equal(moment(a).calendar(), 'danas u 12:00', 'today at the same time');
38016 assert.equal(moment(a).add({m: 25}).calendar(), 'danas u 12:25', 'Now plus 25 min');
38017 assert.equal(moment(a).add({h: 1}).calendar(), 'danas u 13:00', 'Now plus 1 hour');
38018 assert.equal(moment(a).add({d: 1}).calendar(), 'sjutra u 12:00', 'tomorrow at the same time');
38019 assert.equal(moment(a).subtract({h: 1}).calendar(), 'danas u 11:00', 'Now minus 1 hour');
38020 assert.equal(moment(a).subtract({d: 1}).calendar(), 'juče u 12:00', 'yesterday at the same time');
38021 });
38022
38023 test('calendar next week', function (assert) {
38024 var i, m;
9483e2a4 38025
db71a655
KM
38026 function makeFormat(d) {
38027 switch (d.day()) {
38028 case 0:
38029 return '[u] [nedjelju] [u] LT';
38030 case 3:
38031 return '[u] [srijedu] [u] LT';
38032 case 6:
38033 return '[u] [subotu] [u] LT';
38034 case 1:
38035 case 2:
38036 case 4:
38037 case 5:
38038 return '[u] dddd [u] LT';
38039 }
9483e2a4 38040 }
db71a655
KM
38041
38042 for (i = 2; i < 7; i++) {
38043 m = moment().add({d: i});
38044 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time');
38045 m.hours(0).minutes(0).seconds(0).milliseconds(0);
38046 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day');
38047 m.hours(23).minutes(59).seconds(59).milliseconds(999);
38048 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day');
9483e2a4 38049 }
db71a655 38050 });
9483e2a4 38051
db71a655
KM
38052 test('calendar last week', function (assert) {
38053 var i, m;
9483e2a4 38054
db71a655
KM
38055 function makeFormat(d) {
38056 var lastWeekDay = [
38057 '[prošle] [nedjelje] [u] LT',
38058 '[prošlog] [ponedjeljka] [u] LT',
38059 '[prošlog] [utorka] [u] LT',
38060 '[prošle] [srijede] [u] LT',
38061 '[prošlog] [četvrtka] [u] LT',
38062 '[prošlog] [petka] [u] LT',
38063 '[prošle] [subote] [u] LT'
38064 ];
9483e2a4 38065
db71a655
KM
38066 return lastWeekDay[d.day()];
38067 }
9483e2a4 38068
db71a655
KM
38069 for (i = 2; i < 7; i++) {
38070 m = moment().subtract({d: i});
38071 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time');
38072 m.hours(0).minutes(0).seconds(0).milliseconds(0);
38073 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day');
38074 m.hours(23).minutes(59).seconds(59).milliseconds(999);
38075 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day');
9483e2a4
IC
38076 }
38077 });
9483e2a4 38078
db71a655
KM
38079 test('calendar all else', function (assert) {
38080 var weeksAgo = moment().subtract({w: 1}),
38081 weeksFromNow = moment().add({w: 1});
9483e2a4 38082
db71a655
KM
38083 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
38084 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
9483e2a4 38085
db71a655
KM
38086 weeksAgo = moment().subtract({w: 2});
38087 weeksFromNow = moment().add({w: 2});
38088
38089 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
38090 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
38091 });
38092
38093 // Monday is the first day of the week.
38094 // The week that contains Jan 1st is the first week of the year.
38095
38096 test('weeks year starting sunday formatted', function (assert) {
38097 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', 'Dec 26 2011 should be week 1');
38098 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1.', 'Jan 1 2012 should be week 1');
38099 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2.', 'Jan 2 2012 should be week 2');
38100 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2.', 'Jan 8 2012 should be week 2');
38101 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3.', 'Jan 9 2012 should be week 3');
38102 });
73f3c911
IC
38103
38104})));
b135bf1a 38105
516f5f67 38106
73f3c911
IC
38107;(function (global, factory) {
38108 typeof exports === 'object' && typeof module !== 'undefined'
38109 && typeof require === 'function' ? factory(require('../../moment')) :
38110 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
38111 factory(global.moment)
38112}(this, (function (moment) { 'use strict';
516f5f67 38113
db71a655
KM
38114 function each(array, callback) {
38115 var i;
38116 for (i = 0; i < array.length; i++) {
38117 callback(array[i], i, array);
38118 }
73f3c911 38119 }
c74a101d 38120
c58511b9
KM
38121 function setupDeprecationHandler(test, moment$$1, scope) {
38122 test._expectedDeprecations = null;
38123 test._observedDeprecations = null;
38124 test._oldSupress = moment$$1.suppressDeprecationWarnings;
38125 moment$$1.suppressDeprecationWarnings = true;
38126 test.expectedDeprecations = function () {
38127 test._expectedDeprecations = arguments;
38128 test._observedDeprecations = [];
38129 };
38130 moment$$1.deprecationHandler = function (name, msg) {
38131 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
38132 if (deprecationId === -1) {
38133 throw new Error('Unexpected deprecation thrown name=' +
38134 name + ' msg=' + msg);
38135 }
38136 test._observedDeprecations[deprecationId] = 1;
38137 };
38138 }
38139
38140 function teardownDeprecationHandler(test, moment$$1, scope) {
38141 moment$$1.suppressDeprecationWarnings = test._oldSupress;
38142
38143 if (test._expectedDeprecations != null) {
38144 var missedDeprecations = [];
38145 each(test._expectedDeprecations, function (deprecationPattern, id) {
38146 if (test._observedDeprecations[id] !== 1) {
38147 missedDeprecations.push(deprecationPattern);
38148 }
38149 });
38150 if (missedDeprecations.length !== 0) {
38151 throw new Error('Expected deprecation warnings did not happen: ' +
38152 missedDeprecations.join(' '));
38153 }
38154 }
38155 }
38156
38157 function matchedDeprecation(name, msg, deprecations) {
38158 if (deprecations == null) {
38159 return -1;
38160 }
38161 for (var i = 0; i < deprecations.length; ++i) {
38162 if (name != null && name === deprecations[i]) {
38163 return i;
38164 }
38165 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
38166 return i;
38167 }
38168 }
38169 return -1;
38170 }
38171
38172 /*global QUnit:false*/
38173
38174 var test = QUnit.test;
38175
db71a655
KM
38176 function objectKeys(obj) {
38177 if (Object.keys) {
38178 return Object.keys(obj);
38179 } else {
38180 // IE8
38181 var res = [], i;
38182 for (i in obj) {
38183 if (obj.hasOwnProperty(i)) {
38184 res.push(i);
38185 }
516f5f67 38186 }
db71a655 38187 return res;
73f3c911 38188 }
516f5f67
IC
38189 }
38190
db71a655 38191 // Pick the first defined of two or three arguments.
c74a101d 38192
db71a655
KM
38193 function defineCommonLocaleTests(locale, options) {
38194 test('lenient day of month ordinal parsing', function (assert) {
38195 var i, ordinalStr, testMoment;
38196 for (i = 1; i <= 31; ++i) {
38197 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
38198 testMoment = moment(ordinalStr, 'YYYY MM Do');
38199 assert.equal(testMoment.year(), 2014,
38200 'lenient day of month ordinal parsing ' + i + ' year check');
38201 assert.equal(testMoment.month(), 0,
38202 'lenient day of month ordinal parsing ' + i + ' month check');
38203 assert.equal(testMoment.date(), i,
38204 'lenient day of month ordinal parsing ' + i + ' date check');
38205 }
38206 });
516f5f67 38207
db71a655
KM
38208 test('lenient day of month ordinal parsing of number', function (assert) {
38209 var i, testMoment;
38210 for (i = 1; i <= 31; ++i) {
38211 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
38212 assert.equal(testMoment.year(), 2014,
38213 'lenient day of month ordinal parsing of number ' + i + ' year check');
38214 assert.equal(testMoment.month(), 0,
38215 'lenient day of month ordinal parsing of number ' + i + ' month check');
38216 assert.equal(testMoment.date(), i,
38217 'lenient day of month ordinal parsing of number ' + i + ' date check');
38218 }
38219 });
516f5f67 38220
db71a655
KM
38221 test('strict day of month ordinal parsing', function (assert) {
38222 var i, ordinalStr, testMoment;
38223 for (i = 1; i <= 31; ++i) {
38224 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
38225 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
38226 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
38227 }
38228 });
516f5f67 38229
db71a655
KM
38230 test('meridiem invariant', function (assert) {
38231 var h, m, t1, t2;
38232 for (h = 0; h < 24; ++h) {
38233 for (m = 0; m < 60; m += 15) {
38234 t1 = moment.utc([2000, 0, 1, h, m]);
38235 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
38236 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
38237 'meridiem at ' + t1.format('HH:mm'));
38238 }
38239 }
38240 });
38241
38242 test('date format correctness', function (assert) {
38243 var data, tokens;
38244 data = moment.localeData()._longDateFormat;
38245 tokens = objectKeys(data);
38246 each(tokens, function (srchToken) {
38247 // Check each format string to make sure it does not contain any
38248 // tokens that need to be expanded.
38249 each(tokens, function (baseToken) {
38250 // strip escaped sequences
38251 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
38252 assert.equal(false, !!~format.indexOf(srchToken),
38253 'contains ' + srchToken + ' in ' + baseToken);
38254 });
73f3c911
IC
38255 });
38256 });
516f5f67 38257
db71a655
KM
38258 test('month parsing correctness', function (assert) {
38259 var i, m;
38260
38261 if (locale === 'tr') {
38262 // I can't fix it :(
c58511b9 38263 assert.expect(0);
db71a655
KM
38264 return;
38265 }
38266 function tester(format) {
38267 var r;
38268 r = moment(m.format(format), format);
38269 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
38270 if (locale !== 'ka') {
38271 r = moment(m.format(format).toLocaleUpperCase(), format);
38272 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
38273 }
db71a655
KM
38274 r = moment(m.format(format).toLocaleLowerCase(), format);
38275 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
38276
38277 r = moment(m.format(format), format, true);
38278 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
38279 if (locale !== 'ka') {
38280 r = moment(m.format(format).toLocaleUpperCase(), format, true);
38281 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
38282 }
db71a655
KM
38283 r = moment(m.format(format).toLocaleLowerCase(), format, true);
38284 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
38285 }
38286
38287 for (i = 0; i < 12; ++i) {
38288 m = moment([2015, i, 15, 18]);
38289 tester('MMM');
38290 tester('MMM.');
38291 tester('MMMM');
38292 tester('MMMM.');
38293 }
38294 });
38295
38296 test('weekday parsing correctness', function (assert) {
38297 var i, m;
38298
96d0d679 38299 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
38300 // tr, az: There is a lower-case letter (ı), that converted to
38301 // upper then lower changes to i
38302 // ro: there is the letter ț which behaves weird under IE8
38303 // mt: letter Ħ
96d0d679 38304 // ga: month with spaces
c58511b9 38305 assert.expect(0);
db71a655
KM
38306 return;
38307 }
38308 function tester(format) {
38309 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
38310 r = moment(m.format(format), format);
38311 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
38312 if (locale !== 'ka') {
38313 r = moment(m.format(format).toLocaleUpperCase(), format);
38314 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
38315 }
db71a655
KM
38316 r = moment(m.format(format).toLocaleLowerCase(), format);
38317 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
38318 r = moment(m.format(format), format, true);
38319 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
38320 if (locale !== 'ka') {
38321 r = moment(m.format(format).toLocaleUpperCase(), format, true);
38322 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
38323 }
db71a655
KM
38324 r = moment(m.format(format).toLocaleLowerCase(), format, true);
38325 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
38326 }
38327
38328 for (i = 0; i < 7; ++i) {
38329 m = moment.utc([2015, 0, i + 1, 18]);
38330 tester('dd');
38331 tester('ddd');
38332 tester('dddd');
38333 }
38334 });
38335
38336 test('valid localeData', function (assert) {
38337 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
38338 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
38339 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
38340 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
38341 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
38342 });
96d0d679
KM
38343
38344 test('localeData weekdays can localeSort', function (assert) {
38345 var weekdays = moment().localeData().weekdays();
38346 var weekdaysShort = moment().localeData().weekdaysShort();
38347 var weekdaysMin = moment().localeData().weekdaysMin();
38348 var shift = moment().localeData()._week.dow;
38349 assert.deepEqual(
38350 moment().localeData().weekdays(true),
38351 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
38352 'weekdays should localeSort');
38353 assert.deepEqual(
38354 moment().localeData().weekdaysShort(true),
38355 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
38356 'weekdaysShort should localeSort');
38357 assert.deepEqual(
38358 moment().localeData().weekdaysMin(true),
38359 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
38360 'weekdaysMin should localeSort');
38361 });
db71a655 38362 }
516f5f67 38363
db71a655
KM
38364 /*global QUnit:false*/
38365
db71a655
KM
38366 function localeModule (name, lifecycle) {
38367 QUnit.module('locale:' + name, {
c58511b9 38368 beforeEach : function () {
db71a655
KM
38369 moment.locale(name);
38370 moment.createFromInputFallback = function (config) {
38371 throw new Error('input not handled by moment: ' + config._i);
38372 };
38373 setupDeprecationHandler(test, moment, 'locale');
38374 if (lifecycle && lifecycle.setup) {
38375 lifecycle.setup();
38376 }
38377 },
c58511b9 38378 afterEach : function () {
db71a655
KM
38379 moment.locale('en');
38380 teardownDeprecationHandler(test, moment, 'locale');
38381 if (lifecycle && lifecycle.teardown) {
38382 lifecycle.teardown();
38383 }
b135bf1a 38384 }
73f3c911 38385 });
db71a655
KM
38386 defineCommonLocaleTests(name, -1, -1);
38387 }
38388
38389 localeModule('mi');
38390
38391 test('parse', function (assert) {
38392 var tests = 'Kohi-tāte Kohi_Hui-tanguru Hui_Poutū-te-rangi Pou_Paenga-whāwhā Pae_Haratua Hara_Pipiri Pipi_Hōngoingoi Hōngoi_Here-turi-kōkā Here_Mahuru Mahu_Whiringa-ā-nuku Whi-nu_Whiringa-ā-rangi Whi-ra_Hakihea Haki'.split('_'), i;
38393 function equalTest(input, mmm, i) {
38394 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
38395 }
38396 for (i = 0; i < 12; i++) {
38397 tests[i] = tests[i].split(' ');
38398 equalTest(tests[i][0], 'MMM', i);
38399 equalTest(tests[i][1], 'MMM', i);
38400 equalTest(tests[i][0], 'MMMM', i);
38401 equalTest(tests[i][1], 'MMMM', i);
38402 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
38403 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
38404 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
38405 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
38406 }
38407 });
38408
38409 test('format', function (assert) {
38410 var a = [
38411 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Rātapu, Hui-tanguru 14º 2010, 3:25:50 pm'],
38412 ['ddd, hA', 'Ta, 3PM'],
38413 ['M Mo MM MMMM MMM', '2 2º 02 Hui-tanguru Hui'],
38414 ['YYYY YY', '2010 10'],
38415 ['D Do DD', '14 14º 14'],
38416 ['d do dddd ddd dd', '0 0º Rātapu Ta Ta'],
38417 ['DDD DDDo DDDD', '45 45º 045'],
38418 ['w wo ww', '6 6º 06'],
38419 ['h hh', '3 03'],
38420 ['H HH', '15 15'],
38421 ['m mm', '25 25'],
38422 ['s ss', '50 50'],
38423 ['a A', 'pm PM'],
38424 ['[the] DDDo [day of the year]', 'the 45º day of the year'],
38425 ['LTS', '15:25:50'],
38426 ['L', '14/02/2010'],
38427 ['LL', '14 Hui-tanguru 2010'],
38428 ['LLL', '14 Hui-tanguru 2010 i 15:25'],
38429 ['LLLL', 'Rātapu, 14 Hui-tanguru 2010 i 15:25'],
38430 ['l', '14/2/2010'],
38431 ['ll', '14 Hui 2010'],
38432 ['lll', '14 Hui 2010 i 15:25'],
38433 ['llll', 'Ta, 14 Hui 2010 i 15:25']
38434 ],
38435 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
38436 i;
38437 for (i = 0; i < a.length; i++) {
38438 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
38439 }
38440 });
38441
38442 test('format ordinal', function (assert) {
38443 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1º', '1º');
38444 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2º', '2º');
38445 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3º', '3º');
38446 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4º', '4º');
38447 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5º', '5º');
38448 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6º', '6º');
38449 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7º', '7º');
38450 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8º', '8º');
38451 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9º', '9º');
38452 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10º', '10º');
38453
38454 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11º', '11º');
38455 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12º', '12º');
38456 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13º', '13º');
38457 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14º', '14º');
38458 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15º', '15º');
38459 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16º', '16º');
38460 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17º', '17º');
38461 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18º', '18º');
38462 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19º', '19º');
38463 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20º', '20º');
38464
38465 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21º', '21º');
38466 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22º', '22º');
38467 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23º', '23º');
38468 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24º', '24º');
38469 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25º', '25º');
38470 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26º', '26º');
38471 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27º', '27º');
38472 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28º', '28º');
38473 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29º', '29º');
38474 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30º', '30º');
38475
38476 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31º', '31º');
38477 });
38478
38479 test('format month', function (assert) {
38480 var expected = 'Kohi-tāte Kohi_Hui-tanguru Hui_Poutū-te-rangi Pou_Paenga-whāwhā Pae_Haratua Hara_Pipiri Pipi_Hōngoingoi Hōngoi_Here-turi-kōkā Here_Mahuru Mahu_Whiringa-ā-nuku Whi-nu_Whiringa-ā-rangi Whi-ra_Hakihea Haki'.split('_'), i;
38481 for (i = 0; i < expected.length; i++) {
38482 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
38483 }
38484 });
38485
38486 test('format week', function (assert) {
38487 var expected = 'Rātapu Ta Ta_Mane Ma Ma_Tūrei Tū Tū_Wenerei We We_Tāite Tāi Tāi_Paraire Pa Pa_Hātarei Hā Hā'.split('_'), i;
38488 for (i = 0; i < expected.length; i++) {
38489 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
38490 }
38491 });
38492
38493 test('from', function (assert) {
38494 var start = moment([2007, 1, 28]);
38495 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'te hēkona ruarua', '44 seconds = a few seconds');
38496 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'he meneti', '45 seconds = a minute');
38497 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'he meneti', '89 seconds = a minute');
38498 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 meneti', '90 seconds = 2 minutes');
38499 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 meneti', '44 minutes = 44 minutes');
38500 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'te haora', '45 minutes = an hour');
38501 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'te haora', '89 minutes = an hour');
38502 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 haora', '90 minutes = 2 hours');
38503 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 haora', '5 hours = 5 hours');
38504 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 haora', '21 hours = 21 hours');
38505 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'he ra', '22 hours = a day');
38506 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'he ra', '35 hours = a day');
38507 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 ra', '36 hours = 2 days');
38508 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'he ra', '1 day = a day');
38509 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ra', '5 days = 5 days');
38510 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ra', '25 days = 25 days');
38511 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'he marama', '26 days = a month');
38512 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'he marama', '30 days = a month');
38513 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'he marama', '43 days = a month');
38514 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 marama', '46 days = 2 months');
38515 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 marama', '75 days = 2 months');
38516 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 marama', '76 days = 3 months');
38517 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'he marama', '1 month = a month');
38518 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 marama', '5 months = 5 months');
38519 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'he tau', '345 days = a year');
38520 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 tau', '548 days = 2 years');
38521 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'he tau', '1 year = a year');
38522 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 tau', '5 years = 5 years');
38523 });
38524
38525 test('suffix', function (assert) {
38526 assert.equal(moment(30000).from(0), 'i roto i te hēkona ruarua', 'prefix');
38527 assert.equal(moment(0).from(30000), 'te hēkona ruarua i mua', 'suffix');
38528 });
38529
38530 test('now from now', function (assert) {
38531 assert.equal(moment().fromNow(), 'te hēkona ruarua i mua', 'now from now should display as in the past');
38532 });
38533
38534 test('fromNow', function (assert) {
38535 assert.equal(moment().add({s: 30}).fromNow(), 'i roto i te hēkona ruarua', 'in a few seconds');
38536 assert.equal(moment().add({d: 5}).fromNow(), 'i roto i 5 ra', 'in 5 days');
38537 });
38538
38539 test('calendar day', function (assert) {
38540 var a = moment().hours(12).minutes(0).seconds(0);
38541
38542 assert.equal(moment(a).calendar(), 'i teie mahana, i 12:00', 'today at the same time');
38543 assert.equal(moment(a).add({m: 25}).calendar(), 'i teie mahana, i 12:25', 'Now plus 25 min');
38544 assert.equal(moment(a).add({h: 1}).calendar(), 'i teie mahana, i 13:00', 'Now plus 1 hour');
38545 assert.equal(moment(a).add({d: 1}).calendar(), 'apopo i 12:00', 'tomorrow at the same time');
38546 assert.equal(moment(a).subtract({h: 1}).calendar(), 'i teie mahana, i 11:00', 'Now minus 1 hour');
38547 assert.equal(moment(a).subtract({d: 1}).calendar(), 'inanahi i 12:00', 'yesterday at the same time');
38548 });
38549
38550 test('calendar next week', function (assert) {
38551 var i, m;
38552 for (i = 2; i < 7; i++) {
38553 m = moment().add({d: i});
38554 assert.equal(m.calendar(), m.format('dddd [i] LT'), 'Today + ' + i + ' days current time');
38555 m.hours(0).minutes(0).seconds(0).milliseconds(0);
38556 assert.equal(m.calendar(), m.format('dddd [i] LT'), 'Today + ' + i + ' days beginning of day');
38557 m.hours(23).minutes(59).seconds(59).milliseconds(999);
38558 assert.equal(m.calendar(), m.format('dddd [i] LT'), 'Today + ' + i + ' days end of day');
b135bf1a 38559 }
db71a655 38560 });
b135bf1a 38561
db71a655
KM
38562 test('calendar last week', function (assert) {
38563 var i, m;
38564
38565 for (i = 2; i < 7; i++) {
38566 m = moment().subtract({d: i});
38567 assert.equal(m.calendar(), m.format('dddd [whakamutunga i] LT'), 'Today - ' + i + ' days current time');
38568 m.hours(0).minutes(0).seconds(0).milliseconds(0);
38569 assert.equal(m.calendar(), m.format('dddd [whakamutunga i] LT'), 'Today - ' + i + ' days beginning of day');
38570 m.hours(23).minutes(59).seconds(59).milliseconds(999);
38571 assert.equal(m.calendar(), m.format('dddd [whakamutunga i] LT'), 'Today - ' + i + ' days end of day');
b135bf1a 38572 }
db71a655 38573 });
b135bf1a 38574
db71a655
KM
38575 test('calendar all else', function (assert) {
38576 var weeksAgo = moment().subtract({w: 1}),
38577 weeksFromNow = moment().add({w: 1});
b135bf1a 38578
db71a655
KM
38579 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
38580 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
b135bf1a 38581
db71a655
KM
38582 weeksAgo = moment().subtract({w: 2});
38583 weeksFromNow = moment().add({w: 2});
b135bf1a 38584
db71a655
KM
38585 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
38586 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
38587 });
38588
38589 test('weeks year starting sunday formatted', function (assert) {
38590 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52º', 'Jan 1 2012 should be week 52');
38591 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1º', 'Jan 2 2012 should be week 1');
38592 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1º', 'Jan 8 2012 should be week 1');
38593 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2º', 'Jan 9 2012 should be week 2');
38594 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2º', 'Jan 15 2012 should be week 2');
38595 });
73f3c911
IC
38596
38597})));
d6651c21 38598
d6651c21 38599
73f3c911
IC
38600;(function (global, factory) {
38601 typeof exports === 'object' && typeof module !== 'undefined'
38602 && typeof require === 'function' ? factory(require('../../moment')) :
38603 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
38604 factory(global.moment)
38605}(this, (function (moment) { 'use strict';
d6651c21 38606
db71a655
KM
38607 function each(array, callback) {
38608 var i;
38609 for (i = 0; i < array.length; i++) {
38610 callback(array[i], i, array);
38611 }
d6651c21
IC
38612 }
38613
c58511b9
KM
38614 function setupDeprecationHandler(test, moment$$1, scope) {
38615 test._expectedDeprecations = null;
38616 test._observedDeprecations = null;
38617 test._oldSupress = moment$$1.suppressDeprecationWarnings;
38618 moment$$1.suppressDeprecationWarnings = true;
38619 test.expectedDeprecations = function () {
38620 test._expectedDeprecations = arguments;
38621 test._observedDeprecations = [];
38622 };
38623 moment$$1.deprecationHandler = function (name, msg) {
38624 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
38625 if (deprecationId === -1) {
38626 throw new Error('Unexpected deprecation thrown name=' +
38627 name + ' msg=' + msg);
38628 }
38629 test._observedDeprecations[deprecationId] = 1;
38630 };
38631 }
38632
38633 function teardownDeprecationHandler(test, moment$$1, scope) {
38634 moment$$1.suppressDeprecationWarnings = test._oldSupress;
38635
38636 if (test._expectedDeprecations != null) {
38637 var missedDeprecations = [];
38638 each(test._expectedDeprecations, function (deprecationPattern, id) {
38639 if (test._observedDeprecations[id] !== 1) {
38640 missedDeprecations.push(deprecationPattern);
38641 }
38642 });
38643 if (missedDeprecations.length !== 0) {
38644 throw new Error('Expected deprecation warnings did not happen: ' +
38645 missedDeprecations.join(' '));
38646 }
38647 }
38648 }
38649
38650 function matchedDeprecation(name, msg, deprecations) {
38651 if (deprecations == null) {
38652 return -1;
38653 }
38654 for (var i = 0; i < deprecations.length; ++i) {
38655 if (name != null && name === deprecations[i]) {
38656 return i;
38657 }
38658 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
38659 return i;
38660 }
38661 }
38662 return -1;
38663 }
38664
38665 /*global QUnit:false*/
38666
38667 var test = QUnit.test;
38668
db71a655
KM
38669 function objectKeys(obj) {
38670 if (Object.keys) {
38671 return Object.keys(obj);
38672 } else {
38673 // IE8
38674 var res = [], i;
38675 for (i in obj) {
38676 if (obj.hasOwnProperty(i)) {
38677 res.push(i);
38678 }
d6651c21 38679 }
db71a655 38680 return res;
d6651c21 38681 }
b135bf1a
IC
38682 }
38683
db71a655 38684 // Pick the first defined of two or three arguments.
516f5f67 38685
db71a655
KM
38686 function defineCommonLocaleTests(locale, options) {
38687 test('lenient day of month ordinal parsing', function (assert) {
38688 var i, ordinalStr, testMoment;
38689 for (i = 1; i <= 31; ++i) {
38690 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
38691 testMoment = moment(ordinalStr, 'YYYY MM Do');
38692 assert.equal(testMoment.year(), 2014,
38693 'lenient day of month ordinal parsing ' + i + ' year check');
38694 assert.equal(testMoment.month(), 0,
38695 'lenient day of month ordinal parsing ' + i + ' month check');
38696 assert.equal(testMoment.date(), i,
38697 'lenient day of month ordinal parsing ' + i + ' date check');
38698 }
38699 });
516f5f67 38700
db71a655
KM
38701 test('lenient day of month ordinal parsing of number', function (assert) {
38702 var i, testMoment;
38703 for (i = 1; i <= 31; ++i) {
38704 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
38705 assert.equal(testMoment.year(), 2014,
38706 'lenient day of month ordinal parsing of number ' + i + ' year check');
38707 assert.equal(testMoment.month(), 0,
38708 'lenient day of month ordinal parsing of number ' + i + ' month check');
38709 assert.equal(testMoment.date(), i,
38710 'lenient day of month ordinal parsing of number ' + i + ' date check');
38711 }
38712 });
c74a101d 38713
db71a655
KM
38714 test('strict day of month ordinal parsing', function (assert) {
38715 var i, ordinalStr, testMoment;
38716 for (i = 1; i <= 31; ++i) {
38717 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
38718 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
38719 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
38720 }
38721 });
516f5f67 38722
db71a655
KM
38723 test('meridiem invariant', function (assert) {
38724 var h, m, t1, t2;
38725 for (h = 0; h < 24; ++h) {
38726 for (m = 0; m < 60; m += 15) {
38727 t1 = moment.utc([2000, 0, 1, h, m]);
38728 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
38729 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
38730 'meridiem at ' + t1.format('HH:mm'));
38731 }
38732 }
38733 });
38734
38735 test('date format correctness', function (assert) {
38736 var data, tokens;
38737 data = moment.localeData()._longDateFormat;
38738 tokens = objectKeys(data);
38739 each(tokens, function (srchToken) {
38740 // Check each format string to make sure it does not contain any
38741 // tokens that need to be expanded.
38742 each(tokens, function (baseToken) {
38743 // strip escaped sequences
38744 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
38745 assert.equal(false, !!~format.indexOf(srchToken),
38746 'contains ' + srchToken + ' in ' + baseToken);
38747 });
73f3c911 38748 });
516f5f67 38749 });
516f5f67 38750
db71a655
KM
38751 test('month parsing correctness', function (assert) {
38752 var i, m;
38753
38754 if (locale === 'tr') {
38755 // I can't fix it :(
c58511b9 38756 assert.expect(0);
db71a655
KM
38757 return;
38758 }
38759 function tester(format) {
38760 var r;
38761 r = moment(m.format(format), format);
38762 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
38763 if (locale !== 'ka') {
38764 r = moment(m.format(format).toLocaleUpperCase(), format);
38765 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
38766 }
db71a655
KM
38767 r = moment(m.format(format).toLocaleLowerCase(), format);
38768 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
38769
38770 r = moment(m.format(format), format, true);
38771 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
38772 if (locale !== 'ka') {
38773 r = moment(m.format(format).toLocaleUpperCase(), format, true);
38774 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
38775 }
db71a655
KM
38776 r = moment(m.format(format).toLocaleLowerCase(), format, true);
38777 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
38778 }
38779
38780 for (i = 0; i < 12; ++i) {
38781 m = moment([2015, i, 15, 18]);
38782 tester('MMM');
38783 tester('MMM.');
38784 tester('MMMM');
38785 tester('MMMM.');
38786 }
38787 });
c74a101d 38788
db71a655
KM
38789 test('weekday parsing correctness', function (assert) {
38790 var i, m;
38791
96d0d679 38792 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
38793 // tr, az: There is a lower-case letter (ı), that converted to
38794 // upper then lower changes to i
38795 // ro: there is the letter ț which behaves weird under IE8
38796 // mt: letter Ħ
96d0d679 38797 // ga: month with spaces
c58511b9 38798 assert.expect(0);
db71a655
KM
38799 return;
38800 }
38801 function tester(format) {
38802 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
38803 r = moment(m.format(format), format);
38804 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
38805 if (locale !== 'ka') {
38806 r = moment(m.format(format).toLocaleUpperCase(), format);
38807 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
38808 }
db71a655
KM
38809 r = moment(m.format(format).toLocaleLowerCase(), format);
38810 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
38811 r = moment(m.format(format), format, true);
38812 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
38813 if (locale !== 'ka') {
38814 r = moment(m.format(format).toLocaleUpperCase(), format, true);
38815 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
38816 }
db71a655
KM
38817 r = moment(m.format(format).toLocaleLowerCase(), format, true);
38818 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
38819 }
38820
38821 for (i = 0; i < 7; ++i) {
38822 m = moment.utc([2015, 0, i + 1, 18]);
38823 tester('dd');
38824 tester('ddd');
38825 tester('dddd');
38826 }
38827 });
c74a101d 38828
db71a655
KM
38829 test('valid localeData', function (assert) {
38830 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
38831 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
38832 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
38833 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
38834 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
38835 });
96d0d679
KM
38836
38837 test('localeData weekdays can localeSort', function (assert) {
38838 var weekdays = moment().localeData().weekdays();
38839 var weekdaysShort = moment().localeData().weekdaysShort();
38840 var weekdaysMin = moment().localeData().weekdaysMin();
38841 var shift = moment().localeData()._week.dow;
38842 assert.deepEqual(
38843 moment().localeData().weekdays(true),
38844 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
38845 'weekdays should localeSort');
38846 assert.deepEqual(
38847 moment().localeData().weekdaysShort(true),
38848 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
38849 'weekdaysShort should localeSort');
38850 assert.deepEqual(
38851 moment().localeData().weekdaysMin(true),
38852 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
38853 'weekdaysMin should localeSort');
38854 });
db71a655 38855 }
c74a101d 38856
db71a655
KM
38857 /*global QUnit:false*/
38858
db71a655
KM
38859 function localeModule (name, lifecycle) {
38860 QUnit.module('locale:' + name, {
c58511b9 38861 beforeEach : function () {
db71a655
KM
38862 moment.locale(name);
38863 moment.createFromInputFallback = function (config) {
38864 throw new Error('input not handled by moment: ' + config._i);
38865 };
38866 setupDeprecationHandler(test, moment, 'locale');
38867 if (lifecycle && lifecycle.setup) {
38868 lifecycle.setup();
38869 }
38870 },
c58511b9 38871 afterEach : function () {
db71a655
KM
38872 moment.locale('en');
38873 teardownDeprecationHandler(test, moment, 'locale');
38874 if (lifecycle && lifecycle.teardown) {
38875 lifecycle.teardown();
38876 }
b135bf1a 38877 }
73f3c911 38878 });
db71a655
KM
38879 defineCommonLocaleTests(name, -1, -1);
38880 }
38881
38882 localeModule('mk');
38883
38884 test('parse', function (assert) {
38885 var tests = 'јануари јан_февруари фев_март мар_април апр_мај мај_јуни јун_јули јул_август авг_септември сеп_октомври окт_ноември ное_декември дек'.split('_'), i;
38886 function equalTest(input, mmm, i) {
38887 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
38888 }
38889 for (i = 0; i < 12; i++) {
38890 tests[i] = tests[i].split(' ');
38891 equalTest(tests[i][0], 'MMM', i);
38892 equalTest(tests[i][1], 'MMM', i);
38893 equalTest(tests[i][0], 'MMMM', i);
38894 equalTest(tests[i][1], 'MMMM', i);
38895 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
38896 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
38897 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
38898 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
38899 }
38900 });
38901
38902 test('format', function (assert) {
38903 var a = [
38904 ['dddd, MMMM Do YYYY, H:mm:ss', 'недела, февруари 14-ти 2010, 15:25:50'],
38905 ['ddd, hA', 'нед, 3PM'],
38906 ['M Mo MM MMMM MMM', '2 2-ри 02 февруари фев'],
38907 ['YYYY YY', '2010 10'],
38908 ['D Do DD', '14 14-ти 14'],
38909 ['d do dddd ddd dd', '0 0-ев недела нед нe'],
38910 ['DDD DDDo DDDD', '45 45-ти 045'],
38911 ['w wo ww', '7 7-ми 07'],
38912 ['h hh', '3 03'],
38913 ['H HH', '15 15'],
38914 ['m mm', '25 25'],
38915 ['s ss', '50 50'],
38916 ['a A', 'pm PM'],
38917 ['[the] DDDo [day of the year]', 'the 45-ти day of the year'],
38918 ['LTS', '15:25:50'],
38919 ['L', '14.02.2010'],
38920 ['LL', '14 февруари 2010'],
38921 ['LLL', '14 февруари 2010 15:25'],
38922 ['LLLL', 'недела, 14 февруари 2010 15:25'],
38923 ['l', '14.2.2010'],
38924 ['ll', '14 фев 2010'],
38925 ['lll', '14 фев 2010 15:25'],
38926 ['llll', 'нед, 14 фев 2010 15:25']
38927 ],
38928 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
38929 i;
38930 for (i = 0; i < a.length; i++) {
38931 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
38932 }
38933 });
38934
38935 test('format ordinal', function (assert) {
38936 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-ви', '1-ви');
38937 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-ри', '2-ри');
38938 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-ти', '3-ти');
38939 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-ти', '4-ти');
38940 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-ти', '5-ти');
38941 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-ти', '6-ти');
38942 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-ми', '7-ми');
38943 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-ми', '8-ми');
38944 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-ти', '9-ти');
38945 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-ти', '10-ти');
38946
38947 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-ти', '11-ти');
38948 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-ти', '12-ти');
38949 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-ти', '13-ти');
38950 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-ти', '14-ти');
38951 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-ти', '15-ти');
38952 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-ти', '16-ти');
38953 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-ти', '17-ти');
38954 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-ти', '18-ти');
38955 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-ти', '19-ти');
38956 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-ти', '20-ти');
38957
38958 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-ви', '21-ви');
38959 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-ри', '22-ри');
38960 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-ти', '23-ти');
38961 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-ти', '24-ти');
38962 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-ти', '25-ти');
38963 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-ти', '26-ти');
38964 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-ми', '27-ми');
38965 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-ми', '28-ми');
38966 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-ти', '29-ти');
38967 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-ти', '30-ти');
38968
38969 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-ви', '31-ви');
38970 });
38971
38972 test('format month', function (assert) {
38973 var expected = 'јануари јан_февруари фев_март мар_април апр_мај мај_јуни јун_јули јул_август авг_септември сеп_октомври окт_ноември ное_декември дек'.split('_'), i;
38974 for (i = 0; i < expected.length; i++) {
38975 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
38976 }
38977 });
38978
38979 test('format week', function (assert) {
38980 var expected = 'недела нед нe_понеделник пон пo_вторник вто вт_среда сре ср_четврток чет че_петок пет пе_сабота саб сa'.split('_'), i;
38981 for (i = 0; i < expected.length; i++) {
38982 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
38983 }
38984 });
38985
38986 test('from', function (assert) {
38987 var start = moment([2007, 1, 28]);
38988 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'неколку секунди', '44 seconds = a few seconds');
38989 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'минута', '45 seconds = a minute');
38990 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'минута', '89 seconds = a minute');
38991 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 минути', '90 seconds = 2 minutes');
38992 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 минути', '44 minutes = 44 minutes');
38993 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'час', '45 minutes = an hour');
38994 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'час', '89 minutes = an hour');
38995 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 часа', '90 minutes = 2 hours');
38996 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 часа', '5 hours = 5 hours');
38997 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 часа', '21 hours = 21 hours');
38998 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ден', '22 hours = a day');
38999 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ден', '35 hours = a day');
39000 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 дена', '36 hours = 2 days');
39001 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ден', '1 day = a day');
39002 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 дена', '5 days = 5 days');
39003 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 дена', '25 days = 25 days');
39004 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'месец', '26 days = a month');
39005 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'месец', '30 days = a month');
39006 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'месец', '43 days = a month');
39007 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 месеци', '46 days = 2 months');
39008 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 месеци', '75 days = 2 months');
39009 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 месеци', '76 days = 3 months');
39010 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'месец', '1 month = a month');
39011 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 месеци', '5 months = 5 months');
39012 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'година', '345 days = a year');
39013 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 години', '548 days = 2 years');
39014 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'година', '1 year = a year');
39015 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 години', '5 years = 5 years');
39016 });
39017
39018 test('suffix', function (assert) {
39019 assert.equal(moment(30000).from(0), 'после неколку секунди', 'prefix');
39020 assert.equal(moment(0).from(30000), 'пред неколку секунди', 'suffix');
39021 });
39022
39023 test('now from now', function (assert) {
39024 assert.equal(moment().fromNow(), 'пред неколку секунди', 'now from now should display as in the past');
39025 });
39026
39027 test('fromNow', function (assert) {
39028 assert.equal(moment().add({s: 30}).fromNow(), 'после неколку секунди', 'in a few seconds');
39029 assert.equal(moment().add({d: 5}).fromNow(), 'после 5 дена', 'in 5 days');
39030 });
39031
39032 test('calendar day', function (assert) {
39033 var a = moment().hours(12).minutes(0).seconds(0);
39034
39035 assert.equal(moment(a).calendar(), 'Денес во 12:00', 'today at the same time');
39036 assert.equal(moment(a).add({m: 25}).calendar(), 'Денес во 12:25', 'Now plus 25 min');
39037 assert.equal(moment(a).add({h: 1}).calendar(), 'Денес во 13:00', 'Now plus 1 hour');
39038 assert.equal(moment(a).add({d: 1}).calendar(), 'Утре во 12:00', 'tomorrow at the same time');
39039 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Денес во 11:00', 'Now minus 1 hour');
39040 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Вчера во 12:00', 'yesterday at the same time');
39041 });
39042
39043 test('calendar next week', function (assert) {
39044 var i, m;
39045 for (i = 2; i < 7; i++) {
39046 m = moment().add({d: i});
39047 assert.equal(m.calendar(), m.format('[Во] dddd [во] LT'), 'Today + ' + i + ' days current time');
39048 m.hours(0).minutes(0).seconds(0).milliseconds(0);
39049 assert.equal(m.calendar(), m.format('[Во] dddd [во] LT'), 'Today + ' + i + ' days beginning of day');
39050 m.hours(23).minutes(59).seconds(59).milliseconds(999);
39051 assert.equal(m.calendar(), m.format('[Во] dddd [во] LT'), 'Today + ' + i + ' days end of day');
b135bf1a 39052 }
db71a655 39053 });
b135bf1a 39054
db71a655
KM
39055 test('calendar last week', function (assert) {
39056 var i, m;
39057
39058 function makeFormat(d) {
39059 switch (d.day()) {
39060 case 0:
39061 case 3:
39062 case 6:
39063 return '[Изминатата] dddd [во] LT';
39064 case 1:
39065 case 2:
39066 case 4:
39067 case 5:
39068 return '[Изминатиот] dddd [во] LT';
39069 }
b135bf1a 39070 }
db71a655
KM
39071
39072 for (i = 2; i < 7; i++) {
39073 m = moment().subtract({d: i});
39074 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time');
39075 m.hours(0).minutes(0).seconds(0).milliseconds(0);
39076 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day');
39077 m.hours(23).minutes(59).seconds(59).milliseconds(999);
39078 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day');
b135bf1a 39079 }
db71a655 39080 });
b135bf1a 39081
db71a655
KM
39082 test('calendar all else', function (assert) {
39083 var weeksAgo = moment().subtract({w: 1}),
39084 weeksFromNow = moment().add({w: 1});
b135bf1a 39085
db71a655
KM
39086 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
39087 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
b135bf1a 39088
db71a655
KM
39089 weeksAgo = moment().subtract({w: 2});
39090 weeksFromNow = moment().add({w: 2});
b135bf1a 39091
db71a655
KM
39092 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
39093 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
39094 });
39095
39096 test('weeks year starting sunday formatted', function (assert) {
39097 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-ви', 'Dec 26 2011 should be week 1');
39098 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-ви', 'Jan 1 2012 should be week 1');
39099 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-ри', 'Jan 2 2012 should be week 2');
39100 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-ри', 'Jan 8 2012 should be week 2');
39101 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-ти', 'Jan 9 2012 should be week 3');
39102 });
73f3c911
IC
39103
39104})));
d6651c21 39105
d6651c21 39106
73f3c911
IC
39107;(function (global, factory) {
39108 typeof exports === 'object' && typeof module !== 'undefined'
39109 && typeof require === 'function' ? factory(require('../../moment')) :
39110 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
39111 factory(global.moment)
39112}(this, (function (moment) { 'use strict';
d6651c21 39113
db71a655
KM
39114 function each(array, callback) {
39115 var i;
39116 for (i = 0; i < array.length; i++) {
39117 callback(array[i], i, array);
39118 }
d6651c21
IC
39119 }
39120
c58511b9
KM
39121 function setupDeprecationHandler(test, moment$$1, scope) {
39122 test._expectedDeprecations = null;
39123 test._observedDeprecations = null;
39124 test._oldSupress = moment$$1.suppressDeprecationWarnings;
39125 moment$$1.suppressDeprecationWarnings = true;
39126 test.expectedDeprecations = function () {
39127 test._expectedDeprecations = arguments;
39128 test._observedDeprecations = [];
39129 };
39130 moment$$1.deprecationHandler = function (name, msg) {
39131 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
39132 if (deprecationId === -1) {
39133 throw new Error('Unexpected deprecation thrown name=' +
39134 name + ' msg=' + msg);
39135 }
39136 test._observedDeprecations[deprecationId] = 1;
39137 };
39138 }
39139
39140 function teardownDeprecationHandler(test, moment$$1, scope) {
39141 moment$$1.suppressDeprecationWarnings = test._oldSupress;
39142
39143 if (test._expectedDeprecations != null) {
39144 var missedDeprecations = [];
39145 each(test._expectedDeprecations, function (deprecationPattern, id) {
39146 if (test._observedDeprecations[id] !== 1) {
39147 missedDeprecations.push(deprecationPattern);
39148 }
39149 });
39150 if (missedDeprecations.length !== 0) {
39151 throw new Error('Expected deprecation warnings did not happen: ' +
39152 missedDeprecations.join(' '));
39153 }
39154 }
39155 }
39156
39157 function matchedDeprecation(name, msg, deprecations) {
39158 if (deprecations == null) {
39159 return -1;
39160 }
39161 for (var i = 0; i < deprecations.length; ++i) {
39162 if (name != null && name === deprecations[i]) {
39163 return i;
39164 }
39165 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
39166 return i;
39167 }
39168 }
39169 return -1;
39170 }
39171
39172 /*global QUnit:false*/
39173
39174 var test = QUnit.test;
39175
db71a655
KM
39176 function objectKeys(obj) {
39177 if (Object.keys) {
39178 return Object.keys(obj);
39179 } else {
39180 // IE8
39181 var res = [], i;
39182 for (i in obj) {
39183 if (obj.hasOwnProperty(i)) {
39184 res.push(i);
39185 }
d6651c21 39186 }
db71a655 39187 return res;
d6651c21 39188 }
b135bf1a
IC
39189 }
39190
db71a655 39191 // Pick the first defined of two or three arguments.
516f5f67 39192
db71a655
KM
39193 function defineCommonLocaleTests(locale, options) {
39194 test('lenient day of month ordinal parsing', function (assert) {
39195 var i, ordinalStr, testMoment;
39196 for (i = 1; i <= 31; ++i) {
39197 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
39198 testMoment = moment(ordinalStr, 'YYYY MM Do');
39199 assert.equal(testMoment.year(), 2014,
39200 'lenient day of month ordinal parsing ' + i + ' year check');
39201 assert.equal(testMoment.month(), 0,
39202 'lenient day of month ordinal parsing ' + i + ' month check');
39203 assert.equal(testMoment.date(), i,
39204 'lenient day of month ordinal parsing ' + i + ' date check');
39205 }
39206 });
516f5f67 39207
db71a655
KM
39208 test('lenient day of month ordinal parsing of number', function (assert) {
39209 var i, testMoment;
39210 for (i = 1; i <= 31; ++i) {
39211 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
39212 assert.equal(testMoment.year(), 2014,
39213 'lenient day of month ordinal parsing of number ' + i + ' year check');
39214 assert.equal(testMoment.month(), 0,
39215 'lenient day of month ordinal parsing of number ' + i + ' month check');
39216 assert.equal(testMoment.date(), i,
39217 'lenient day of month ordinal parsing of number ' + i + ' date check');
39218 }
39219 });
516f5f67 39220
db71a655
KM
39221 test('strict day of month ordinal parsing', function (assert) {
39222 var i, ordinalStr, testMoment;
39223 for (i = 1; i <= 31; ++i) {
39224 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
39225 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
39226 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
39227 }
39228 });
516f5f67 39229
db71a655
KM
39230 test('meridiem invariant', function (assert) {
39231 var h, m, t1, t2;
39232 for (h = 0; h < 24; ++h) {
39233 for (m = 0; m < 60; m += 15) {
39234 t1 = moment.utc([2000, 0, 1, h, m]);
39235 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
39236 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
39237 'meridiem at ' + t1.format('HH:mm'));
39238 }
39239 }
39240 });
39241
39242 test('date format correctness', function (assert) {
39243 var data, tokens;
39244 data = moment.localeData()._longDateFormat;
39245 tokens = objectKeys(data);
39246 each(tokens, function (srchToken) {
39247 // Check each format string to make sure it does not contain any
39248 // tokens that need to be expanded.
39249 each(tokens, function (baseToken) {
39250 // strip escaped sequences
39251 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
39252 assert.equal(false, !!~format.indexOf(srchToken),
39253 'contains ' + srchToken + ' in ' + baseToken);
39254 });
73f3c911
IC
39255 });
39256 });
516f5f67 39257
db71a655
KM
39258 test('month parsing correctness', function (assert) {
39259 var i, m;
39260
39261 if (locale === 'tr') {
39262 // I can't fix it :(
c58511b9 39263 assert.expect(0);
db71a655
KM
39264 return;
39265 }
39266 function tester(format) {
39267 var r;
39268 r = moment(m.format(format), format);
39269 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
39270 if (locale !== 'ka') {
39271 r = moment(m.format(format).toLocaleUpperCase(), format);
39272 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
39273 }
db71a655
KM
39274 r = moment(m.format(format).toLocaleLowerCase(), format);
39275 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
39276
39277 r = moment(m.format(format), format, true);
39278 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
39279 if (locale !== 'ka') {
39280 r = moment(m.format(format).toLocaleUpperCase(), format, true);
39281 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
39282 }
db71a655
KM
39283 r = moment(m.format(format).toLocaleLowerCase(), format, true);
39284 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
39285 }
39286
39287 for (i = 0; i < 12; ++i) {
39288 m = moment([2015, i, 15, 18]);
39289 tester('MMM');
39290 tester('MMM.');
39291 tester('MMMM');
39292 tester('MMMM.');
39293 }
39294 });
516f5f67 39295
db71a655
KM
39296 test('weekday parsing correctness', function (assert) {
39297 var i, m;
39298
96d0d679 39299 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
39300 // tr, az: There is a lower-case letter (ı), that converted to
39301 // upper then lower changes to i
39302 // ro: there is the letter ț which behaves weird under IE8
39303 // mt: letter Ħ
96d0d679 39304 // ga: month with spaces
c58511b9 39305 assert.expect(0);
db71a655
KM
39306 return;
39307 }
39308 function tester(format) {
39309 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
39310 r = moment(m.format(format), format);
39311 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
39312 if (locale !== 'ka') {
39313 r = moment(m.format(format).toLocaleUpperCase(), format);
39314 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
39315 }
db71a655
KM
39316 r = moment(m.format(format).toLocaleLowerCase(), format);
39317 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
39318 r = moment(m.format(format), format, true);
39319 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
39320 if (locale !== 'ka') {
39321 r = moment(m.format(format).toLocaleUpperCase(), format, true);
39322 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
39323 }
db71a655
KM
39324 r = moment(m.format(format).toLocaleLowerCase(), format, true);
39325 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
39326 }
39327
39328 for (i = 0; i < 7; ++i) {
39329 m = moment.utc([2015, 0, i + 1, 18]);
39330 tester('dd');
39331 tester('ddd');
39332 tester('dddd');
39333 }
39334 });
516f5f67 39335
db71a655
KM
39336 test('valid localeData', function (assert) {
39337 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
39338 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
39339 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
39340 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
39341 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
39342 });
96d0d679
KM
39343
39344 test('localeData weekdays can localeSort', function (assert) {
39345 var weekdays = moment().localeData().weekdays();
39346 var weekdaysShort = moment().localeData().weekdaysShort();
39347 var weekdaysMin = moment().localeData().weekdaysMin();
39348 var shift = moment().localeData()._week.dow;
39349 assert.deepEqual(
39350 moment().localeData().weekdays(true),
39351 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
39352 'weekdays should localeSort');
39353 assert.deepEqual(
39354 moment().localeData().weekdaysShort(true),
39355 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
39356 'weekdaysShort should localeSort');
39357 assert.deepEqual(
39358 moment().localeData().weekdaysMin(true),
39359 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
39360 'weekdaysMin should localeSort');
39361 });
db71a655 39362 }
516f5f67 39363
db71a655 39364 /*global QUnit:false*/
73f3c911 39365
db71a655
KM
39366 function localeModule (name, lifecycle) {
39367 QUnit.module('locale:' + name, {
c58511b9 39368 beforeEach : function () {
db71a655
KM
39369 moment.locale(name);
39370 moment.createFromInputFallback = function (config) {
39371 throw new Error('input not handled by moment: ' + config._i);
39372 };
39373 setupDeprecationHandler(test, moment, 'locale');
39374 if (lifecycle && lifecycle.setup) {
39375 lifecycle.setup();
39376 }
39377 },
c58511b9 39378 afterEach : function () {
db71a655
KM
39379 moment.locale('en');
39380 teardownDeprecationHandler(test, moment, 'locale');
39381 if (lifecycle && lifecycle.teardown) {
39382 lifecycle.teardown();
39383 }
c74a101d 39384 }
73f3c911 39385 });
db71a655
KM
39386 defineCommonLocaleTests(name, -1, -1);
39387 }
39388
39389 localeModule('ml');
39390
39391 test('parse', function (assert) {
39392 var tests = 'ജനുവരി ജനു._ഫെബ്രുവരി ഫെബ്രു._മാർച്ച് മാർ._ഏപ്രിൽ ഏപ്രി._മേയ് മേയ്_ജൂൺ ജൂൺ_ജൂലൈ ജൂലൈ._ഓഗസ്റ്റ് ഓഗ._സെപ്റ്റംബർ സെപ്റ്റ._ഒക്ടോബർ ഒക്ടോ._നവംബർ നവം._ഡിസംബർ ഡിസം.'.split('_'), i;
39393 function equalTest(input, mmm, i) {
39394 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
39395 }
39396 for (i = 0; i < 12; i++) {
39397 tests[i] = tests[i].split(' ');
39398 equalTest(tests[i][0], 'MMM', i);
39399 equalTest(tests[i][1], 'MMM', i);
39400 equalTest(tests[i][0], 'MMMM', i);
39401 equalTest(tests[i][1], 'MMMM', i);
39402 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
39403 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
39404 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
39405 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
39406 }
39407 });
39408
39409 test('format', function (assert) {
39410 var a = [
39411 ['dddd, Do MMMM YYYY, a h:mm:ss -നു', 'ഞായറാഴ്ച, 14 ഫെബ്രുവരി 2010, ഉച്ച കഴിഞ്ഞ് 3:25:50 -നു'],
39412 ['ddd, a h -നു', 'ഞായർ, ഉച്ച കഴിഞ്ഞ് 3 -നു'],
39413 ['M Mo MM MMMM MMM', '2 2 02 ഫെബ്രുവരി ഫെബ്രു.'],
39414 ['YYYY YY', '2010 10'],
39415 ['D Do DD', '14 14 14'],
39416 ['d do dddd ddd dd', '0 0 ഞായറാഴ്ച ഞായർ ഞാ'],
39417 ['DDD DDDo DDDD', '45 45 045'],
39418 ['w wo ww', '8 8 08'],
39419 ['h hh', '3 03'],
39420 ['H HH', '15 15'],
39421 ['m mm', '25 25'],
39422 ['s ss', '50 50'],
39423 ['a A', 'ഉച്ച കഴിഞ്ഞ് ഉച്ച കഴിഞ്ഞ്'],
39424 ['LTS', 'ഉച്ച കഴിഞ്ഞ് 3:25:50 -നു'],
39425 ['L', '14/02/2010'],
39426 ['LL', '14 ഫെബ്രുവരി 2010'],
39427 ['LLL', '14 ഫെബ്രുവരി 2010, ഉച്ച കഴിഞ്ഞ് 3:25 -നു'],
39428 ['LLLL', 'ഞായറാഴ്ച, 14 ഫെബ്രുവരി 2010, ഉച്ച കഴിഞ്ഞ് 3:25 -നു'],
39429 ['l', '14/2/2010'],
39430 ['ll', '14 ഫെബ്രു. 2010'],
39431 ['lll', '14 ഫെബ്രു. 2010, ഉച്ച കഴിഞ്ഞ് 3:25 -നു'],
39432 ['llll', 'ഞായർ, 14 ഫെബ്രു. 2010, ഉച്ച കഴിഞ്ഞ് 3:25 -നു']
39433 ],
39434 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
39435 i;
39436 for (i = 0; i < a.length; i++) {
39437 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
39438 }
39439 });
39440
39441 test('format ordinal', function (assert) {
39442 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
39443 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
39444 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
39445 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
39446 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
39447 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
39448 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
39449 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
39450 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
39451 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
39452
39453 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
39454 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
39455 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
39456 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
39457 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
39458 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
39459 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
39460 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
39461 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
39462 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
39463
39464 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
39465 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
39466 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
39467 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
39468 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
39469 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
39470 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
39471 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
39472 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
39473 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
39474
39475 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
39476 });
39477
39478 test('format month', function (assert) {
39479 var expected = 'ജനുവരി ജനു._ഫെബ്രുവരി ഫെബ്രു._മാർച്ച് മാർ._ഏപ്രിൽ ഏപ്രി._മേയ് മേയ്_ജൂൺ ജൂൺ_ജൂലൈ ജൂലൈ._ഓഗസ്റ്റ് ഓഗ._സെപ്റ്റംബർ സെപ്റ്റ._ഒക്ടോബർ ഒക്ടോ._നവംബർ നവം._ഡിസംബർ ഡിസം.'.split('_'), i;
39480 for (i = 0; i < expected.length; i++) {
39481 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
39482 }
39483 });
39484
39485 test('format week', function (assert) {
39486 var expected = 'ഞായറാഴ്ച ഞായർ ഞാ_തിങ്കളാഴ്ച തിങ്കൾ തി_ചൊവ്വാഴ്ച ചൊവ്വ ചൊ_ബുധനാഴ്ച ബുധൻ ബു_വ്യാഴാഴ്ച വ്യാഴം വ്യാ_വെള്ളിയാഴ്ച വെള്ളി വെ_ശനിയാഴ്ച ശനി ശ'.split('_'), i;
39487 for (i = 0; i < expected.length; i++) {
39488 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
39489 }
39490 });
39491
39492 test('from', function (assert) {
39493 var start = moment([2007, 1, 28]);
39494 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'അൽപ നിമിഷങ്ങൾ', '44 seconds = a few seconds');
39495 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ഒരു മിനിറ്റ്', '45 seconds = a minute');
39496 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ഒരു മിനിറ്റ്', '89 seconds = a minute');
39497 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 മിനിറ്റ്', '90 seconds = 2 minutes');
39498 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 മിനിറ്റ്', '44 minutes = 44 minutes');
39499 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ഒരു മണിക്കൂർ', '45 minutes = an hour');
39500 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ഒരു മണിക്കൂർ', '89 minutes = an hour');
39501 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 മണിക്കൂർ', '90 minutes = 2 hours');
39502 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 മണിക്കൂർ', '5 hours = 5 hours');
39503 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 മണിക്കൂർ', '21 hours = 21 hours');
39504 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ഒരു ദിവസം', '22 hours = a day');
39505 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ഒരു ദിവസം', '35 hours = a day');
39506 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 ദിവസം', '36 hours = 2 days');
39507 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ഒരു ദിവസം', '1 day = a day');
39508 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ദിവസം', '5 days = 5 days');
39509 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ദിവസം', '25 days = 25 days');
39510 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ഒരു മാസം', '26 days = a month');
39511 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ഒരു മാസം', '30 days = a month');
39512 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ഒരു മാസം', '43 days = a month');
39513 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 മാസം', '46 days = 2 months');
39514 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 മാസം', '75 days = 2 months');
39515 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 മാസം', '76 days = 3 months');
39516 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ഒരു മാസം', '1 month = a month');
39517 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 മാസം', '5 months = 5 months');
39518 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ഒരു വർഷം', '345 days = a year');
39519 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 വർഷം', '548 days = 2 years');
39520 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ഒരു വർഷം', '1 year = a year');
39521 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 വർഷം', '5 years = 5 years');
39522 });
39523
39524 test('suffix', function (assert) {
39525 assert.equal(moment(30000).from(0), 'അൽപ നിമിഷങ്ങൾ കഴിഞ്ഞ്', 'prefix');
39526 assert.equal(moment(0).from(30000), 'അൽപ നിമിഷങ്ങൾ മുൻപ്', 'suffix');
39527 });
39528
39529 test('now from now', function (assert) {
39530 assert.equal(moment().fromNow(), 'അൽപ നിമിഷങ്ങൾ മുൻപ്', 'now from now should display as in the past');
39531 });
39532
39533 test('fromNow', function (assert) {
39534 assert.equal(moment().add({s: 30}).fromNow(), 'അൽപ നിമിഷങ്ങൾ കഴിഞ്ഞ്', 'അൽപ നിമിഷങ്ങൾ കഴിഞ്ഞ്');
39535 assert.equal(moment().add({d: 5}).fromNow(), '5 ദിവസം കഴിഞ്ഞ്', '5 ദിവസം കഴിഞ്ഞ്');
39536 });
39537
39538 test('calendar day', function (assert) {
39539 var a = moment().hours(12).minutes(0).seconds(0);
39540
39541 assert.equal(moment(a).calendar(), 'ഇന്ന് ഉച്ച കഴിഞ്ഞ് 12:00 -നു', 'today at the same time');
39542 assert.equal(moment(a).add({m: 25}).calendar(), 'ഇന്ന് ഉച്ച കഴിഞ്ഞ് 12:25 -നു', 'Now plus 25 min');
39543 assert.equal(moment(a).add({h: 3}).calendar(), 'ഇന്ന് ഉച്ച കഴിഞ്ഞ് 3:00 -നു', 'Now plus 3 hours');
39544 assert.equal(moment(a).add({d: 1}).calendar(), 'നാളെ ഉച്ച കഴിഞ്ഞ് 12:00 -നു', 'tomorrow at the same time');
39545 assert.equal(moment(a).subtract({h: 1}).calendar(), 'ഇന്ന് രാവിലെ 11:00 -നു', 'Now minus 1 hour');
39546 assert.equal(moment(a).subtract({d: 1}).calendar(), 'ഇന്നലെ ഉച്ച കഴിഞ്ഞ് 12:00 -നു', 'yesterday at the same time');
39547 });
39548
39549 test('calendar next week', function (assert) {
39550 var i, m;
39551 for (i = 2; i < 7; i++) {
39552 m = moment().add({d: i});
39553 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days current time');
39554 m.hours(0).minutes(0).seconds(0).milliseconds(0);
39555 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days beginning of day');
39556 m.hours(23).minutes(59).seconds(59).milliseconds(999);
39557 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days end of day');
c74a101d 39558 }
db71a655 39559 });
c74a101d 39560
db71a655
KM
39561 test('calendar last week', function (assert) {
39562 var i, m;
39563
39564 for (i = 2; i < 7; i++) {
39565 m = moment().subtract({d: i});
39566 assert.equal(m.calendar(), m.format('[കഴിഞ്ഞ] dddd[,] LT'), 'Today - ' + i + ' days current time');
39567 m.hours(0).minutes(0).seconds(0).milliseconds(0);
39568 assert.equal(m.calendar(), m.format('[കഴിഞ്ഞ] dddd[,] LT'), 'Today - ' + i + ' days beginning of day');
39569 m.hours(23).minutes(59).seconds(59).milliseconds(999);
39570 assert.equal(m.calendar(), m.format('[കഴിഞ്ഞ] dddd[,] LT'), 'Today - ' + i + ' days end of day');
b135bf1a 39571 }
db71a655 39572 });
516f5f67 39573
db71a655
KM
39574 test('calendar all else', function (assert) {
39575 var weeksAgo = moment().subtract({w: 1}),
39576 weeksFromNow = moment().add({w: 1});
b135bf1a 39577
db71a655
KM
39578 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
39579 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
b135bf1a 39580
db71a655
KM
39581 weeksAgo = moment().subtract({w: 2});
39582 weeksFromNow = moment().add({w: 2});
b135bf1a 39583
db71a655
KM
39584 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
39585 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
39586 });
39587
39588 test('meridiem', function (assert) {
39589 assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), 'രാത്രി', 'before dawn');
39590 assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), 'രാവിലെ', 'morning');
39591 assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), 'ഉച്ച കഴിഞ്ഞ്', 'during day');
39592 assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), 'വൈകുന്നേരം', 'evening');
39593 assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), 'വൈകുന്നേരം', 'late evening');
39594 assert.equal(moment([2011, 2, 23, 21, 20]).format('a'), 'രാത്രി', 'night');
39595
39596 assert.equal(moment([2011, 2, 23, 2, 30]).format('A'), 'രാത്രി', 'before dawn');
39597 assert.equal(moment([2011, 2, 23, 9, 30]).format('A'), 'രാവിലെ', 'morning');
39598 assert.equal(moment([2011, 2, 23, 14, 30]).format('A'), 'ഉച്ച കഴിഞ്ഞ്', ' during day');
39599 assert.equal(moment([2011, 2, 23, 17, 30]).format('A'), 'വൈകുന്നേരം', 'evening');
39600 assert.equal(moment([2011, 2, 23, 19, 30]).format('A'), 'വൈകുന്നേരം', 'late evening');
39601 assert.equal(moment([2011, 2, 23, 21, 20]).format('A'), 'രാത്രി', 'night');
39602 });
39603
39604 test('weeks year starting sunday formatted', function (assert) {
39605 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1');
39606 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1', 'Jan 7 2012 should be week 1');
39607 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2');
39608 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2', 'Jan 14 2012 should be week 2');
39609 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', 'Jan 15 2012 should be week 3');
39610 });
73f3c911
IC
39611
39612})));
d6651c21 39613
d6651c21 39614
73f3c911
IC
39615;(function (global, factory) {
39616 typeof exports === 'object' && typeof module !== 'undefined'
39617 && typeof require === 'function' ? factory(require('../../moment')) :
39618 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
39619 factory(global.moment)
39620}(this, (function (moment) { 'use strict';
d6651c21 39621
db71a655
KM
39622 function each(array, callback) {
39623 var i;
39624 for (i = 0; i < array.length; i++) {
39625 callback(array[i], i, array);
39626 }
d6651c21
IC
39627 }
39628
c58511b9
KM
39629 function setupDeprecationHandler(test, moment$$1, scope) {
39630 test._expectedDeprecations = null;
39631 test._observedDeprecations = null;
39632 test._oldSupress = moment$$1.suppressDeprecationWarnings;
39633 moment$$1.suppressDeprecationWarnings = true;
39634 test.expectedDeprecations = function () {
39635 test._expectedDeprecations = arguments;
39636 test._observedDeprecations = [];
39637 };
39638 moment$$1.deprecationHandler = function (name, msg) {
39639 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
39640 if (deprecationId === -1) {
39641 throw new Error('Unexpected deprecation thrown name=' +
39642 name + ' msg=' + msg);
39643 }
39644 test._observedDeprecations[deprecationId] = 1;
39645 };
39646 }
39647
39648 function teardownDeprecationHandler(test, moment$$1, scope) {
39649 moment$$1.suppressDeprecationWarnings = test._oldSupress;
39650
39651 if (test._expectedDeprecations != null) {
39652 var missedDeprecations = [];
39653 each(test._expectedDeprecations, function (deprecationPattern, id) {
39654 if (test._observedDeprecations[id] !== 1) {
39655 missedDeprecations.push(deprecationPattern);
39656 }
39657 });
39658 if (missedDeprecations.length !== 0) {
39659 throw new Error('Expected deprecation warnings did not happen: ' +
39660 missedDeprecations.join(' '));
39661 }
39662 }
39663 }
39664
39665 function matchedDeprecation(name, msg, deprecations) {
39666 if (deprecations == null) {
39667 return -1;
39668 }
39669 for (var i = 0; i < deprecations.length; ++i) {
39670 if (name != null && name === deprecations[i]) {
39671 return i;
39672 }
39673 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
39674 return i;
39675 }
39676 }
39677 return -1;
39678 }
39679
39680 /*global QUnit:false*/
39681
39682 var test = QUnit.test;
39683
db71a655
KM
39684 function objectKeys(obj) {
39685 if (Object.keys) {
39686 return Object.keys(obj);
39687 } else {
39688 // IE8
39689 var res = [], i;
39690 for (i in obj) {
39691 if (obj.hasOwnProperty(i)) {
39692 res.push(i);
39693 }
d6651c21 39694 }
db71a655 39695 return res;
d6651c21 39696 }
b135bf1a 39697 }
516f5f67 39698
db71a655 39699 // Pick the first defined of two or three arguments.
516f5f67 39700
db71a655
KM
39701 function defineCommonLocaleTests(locale, options) {
39702 test('lenient day of month ordinal parsing', function (assert) {
39703 var i, ordinalStr, testMoment;
39704 for (i = 1; i <= 31; ++i) {
39705 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
39706 testMoment = moment(ordinalStr, 'YYYY MM Do');
39707 assert.equal(testMoment.year(), 2014,
39708 'lenient day of month ordinal parsing ' + i + ' year check');
39709 assert.equal(testMoment.month(), 0,
39710 'lenient day of month ordinal parsing ' + i + ' month check');
39711 assert.equal(testMoment.date(), i,
39712 'lenient day of month ordinal parsing ' + i + ' date check');
39713 }
39714 });
516f5f67 39715
db71a655
KM
39716 test('lenient day of month ordinal parsing of number', function (assert) {
39717 var i, testMoment;
39718 for (i = 1; i <= 31; ++i) {
39719 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
39720 assert.equal(testMoment.year(), 2014,
39721 'lenient day of month ordinal parsing of number ' + i + ' year check');
39722 assert.equal(testMoment.month(), 0,
39723 'lenient day of month ordinal parsing of number ' + i + ' month check');
39724 assert.equal(testMoment.date(), i,
39725 'lenient day of month ordinal parsing of number ' + i + ' date check');
39726 }
39727 });
c74a101d 39728
db71a655
KM
39729 test('strict day of month ordinal parsing', function (assert) {
39730 var i, ordinalStr, testMoment;
39731 for (i = 1; i <= 31; ++i) {
39732 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
39733 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
39734 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
39735 }
39736 });
516f5f67 39737
db71a655
KM
39738 test('meridiem invariant', function (assert) {
39739 var h, m, t1, t2;
39740 for (h = 0; h < 24; ++h) {
39741 for (m = 0; m < 60; m += 15) {
39742 t1 = moment.utc([2000, 0, 1, h, m]);
39743 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
39744 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
39745 'meridiem at ' + t1.format('HH:mm'));
39746 }
39747 }
39748 });
39749
39750 test('date format correctness', function (assert) {
39751 var data, tokens;
39752 data = moment.localeData()._longDateFormat;
39753 tokens = objectKeys(data);
39754 each(tokens, function (srchToken) {
39755 // Check each format string to make sure it does not contain any
39756 // tokens that need to be expanded.
39757 each(tokens, function (baseToken) {
39758 // strip escaped sequences
39759 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
39760 assert.equal(false, !!~format.indexOf(srchToken),
39761 'contains ' + srchToken + ' in ' + baseToken);
39762 });
73f3c911 39763 });
516f5f67 39764 });
516f5f67 39765
db71a655
KM
39766 test('month parsing correctness', function (assert) {
39767 var i, m;
39768
39769 if (locale === 'tr') {
39770 // I can't fix it :(
c58511b9 39771 assert.expect(0);
db71a655
KM
39772 return;
39773 }
39774 function tester(format) {
39775 var r;
39776 r = moment(m.format(format), format);
39777 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
39778 if (locale !== 'ka') {
39779 r = moment(m.format(format).toLocaleUpperCase(), format);
39780 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
39781 }
db71a655
KM
39782 r = moment(m.format(format).toLocaleLowerCase(), format);
39783 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
39784
39785 r = moment(m.format(format), format, true);
39786 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
39787 if (locale !== 'ka') {
39788 r = moment(m.format(format).toLocaleUpperCase(), format, true);
39789 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
39790 }
db71a655
KM
39791 r = moment(m.format(format).toLocaleLowerCase(), format, true);
39792 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
39793 }
39794
39795 for (i = 0; i < 12; ++i) {
39796 m = moment([2015, i, 15, 18]);
39797 tester('MMM');
39798 tester('MMM.');
39799 tester('MMMM');
39800 tester('MMMM.');
39801 }
39802 });
c74a101d 39803
db71a655
KM
39804 test('weekday parsing correctness', function (assert) {
39805 var i, m;
39806
96d0d679 39807 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
39808 // tr, az: There is a lower-case letter (ı), that converted to
39809 // upper then lower changes to i
39810 // ro: there is the letter ț which behaves weird under IE8
39811 // mt: letter Ħ
96d0d679 39812 // ga: month with spaces
c58511b9 39813 assert.expect(0);
db71a655
KM
39814 return;
39815 }
39816 function tester(format) {
39817 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
39818 r = moment(m.format(format), format);
39819 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
39820 if (locale !== 'ka') {
39821 r = moment(m.format(format).toLocaleUpperCase(), format);
39822 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
39823 }
db71a655
KM
39824 r = moment(m.format(format).toLocaleLowerCase(), format);
39825 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
39826 r = moment(m.format(format), format, true);
39827 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
39828 if (locale !== 'ka') {
39829 r = moment(m.format(format).toLocaleUpperCase(), format, true);
39830 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
39831 }
db71a655
KM
39832 r = moment(m.format(format).toLocaleLowerCase(), format, true);
39833 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
39834 }
39835
39836 for (i = 0; i < 7; ++i) {
39837 m = moment.utc([2015, 0, i + 1, 18]);
39838 tester('dd');
39839 tester('ddd');
39840 tester('dddd');
39841 }
39842 });
516f5f67 39843
db71a655
KM
39844 test('valid localeData', function (assert) {
39845 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
39846 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
39847 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
39848 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
39849 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
39850 });
96d0d679
KM
39851
39852 test('localeData weekdays can localeSort', function (assert) {
39853 var weekdays = moment().localeData().weekdays();
39854 var weekdaysShort = moment().localeData().weekdaysShort();
39855 var weekdaysMin = moment().localeData().weekdaysMin();
39856 var shift = moment().localeData()._week.dow;
39857 assert.deepEqual(
39858 moment().localeData().weekdays(true),
39859 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
39860 'weekdays should localeSort');
39861 assert.deepEqual(
39862 moment().localeData().weekdaysShort(true),
39863 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
39864 'weekdaysShort should localeSort');
39865 assert.deepEqual(
39866 moment().localeData().weekdaysMin(true),
39867 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
39868 'weekdaysMin should localeSort');
39869 });
db71a655 39870 }
516f5f67 39871
db71a655
KM
39872 /*global QUnit:false*/
39873
db71a655
KM
39874 function localeModule (name, lifecycle) {
39875 QUnit.module('locale:' + name, {
c58511b9 39876 beforeEach : function () {
db71a655
KM
39877 moment.locale(name);
39878 moment.createFromInputFallback = function (config) {
39879 throw new Error('input not handled by moment: ' + config._i);
39880 };
39881 setupDeprecationHandler(test, moment, 'locale');
39882 if (lifecycle && lifecycle.setup) {
39883 lifecycle.setup();
39884 }
39885 },
c58511b9 39886 afterEach : function () {
db71a655
KM
39887 moment.locale('en');
39888 teardownDeprecationHandler(test, moment, 'locale');
39889 if (lifecycle && lifecycle.teardown) {
39890 lifecycle.teardown();
39891 }
b135bf1a 39892 }
73f3c911 39893 });
db71a655 39894 defineCommonLocaleTests(name, -1, -1);
b135bf1a
IC
39895 }
39896
db71a655
KM
39897 localeModule('mn');
39898
39899 test('parse', function (assert) {
39900 var i,
39901 tests = 'Нэгдүгээр сар-1 сар_Хоёрдугаар сар-2 сар_Гуравдугаар сар-3 сар_Дөрөвдүгээр сар-4 сар_Тавдугаар сар-5 сар_Зургадугаар сар-6 сар_Долдугаар сар-7 сар_Наймдугаар сар-8 сар_Есдүгээр сар-9 сар_Аравдугаар сар-10 сар_Арван нэгдүгээр сар-11 сар_Арван хоёрдугаар сар-12 сар'.split('_');
39902
39903 function equalTest(input, mmm, i) {
39904 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
39905 }
39906
39907 for (i = 0; i < 12; i++) {
39908 tests[i] = tests[i].split('-');
39909 equalTest(tests[i][0], 'MMM', i);
39910 equalTest(tests[i][1], 'MMM', i);
39911 equalTest(tests[i][0], 'MMMM', i);
39912 equalTest(tests[i][1], 'MMMM', i);
39913 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
39914 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
39915 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
39916 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
39917 }
39918
39919 assert.equal(moment('5 сар 11 1989', ['MMM DD YYYY']).format('YYYY-MM-DD'), '1989-05-11');
39920 assert.equal(moment('1989 он, Арван хоёрдугаар сар 11', ['YYYY [он], MMMM DD']).format('YYYY-MM-DD'), '1989-12-11');
39921 assert.equal(moment('1989 оны 11 сарын 2', ['YYYY [оны] MMMM[ын] DD']).format('YYYY-MM-D'), '1989-11-2');
39922 assert.equal(moment('1989 оны 5 сарын 11 өдөр', ['YYYY [оны] MMMM[ын] Do']).format('YYYY-MM-DD'), '1989-05-11');
39923 assert.equal(moment('1989 оны 5 сарын 11 өдөр 11:25 ҮӨ', ['YYYY [оны] MMM[ын] Do h:mm a']).format('YYYY-MM-DD h:mm a'), '1989-05-11 11:25 ҮӨ');
39924 assert.equal(moment('2003 оны Дөрөвдүгээр сарын 11 өдөр 17:25 ҮХ', ['YYYY [оны] MMMM[ын] Do HH:mm a']).format('YYYY-MM-DD HH:mm a'), '2003-04-11 17:25 ҮХ');
39925 });
39926
39927 test('format', function (assert) {
39928 var a = [
39929 ['dddd, MMMM[ын] Do YYYY, h:mm:ss a', 'Ням, Хоёрдугаар сарын 14 өдөр 2010, 3:25:50 ҮХ'],
39930 ['ddd, hA', 'Ням, 3ҮХ'],
39931 ['M Mo MM MMMM MMM', '2 2 02 Хоёрдугаар сар 2 сар'],
39932 ['YYYY YY', '2010 10'],
39933 ['D Do DD', '14 14 өдөр 14'],
39934 ['d do dddd ddd dd', '0 0 өдөр Ням Ням Ня'],
39935 ['DDD DDDo DDDD', '45 45 өдөр 045'],
39936 ['w wo ww', '8 8 08'],
39937 ['h hh', '3 03'],
39938 ['H HH', '15 15'],
39939 ['m mm', '25 25'],
39940 ['s ss', '50 50'],
39941 ['a A', 'ҮХ ҮХ'],
39942 ['[the] DDDo [day of the year]', 'the 45 өдөр day of the year'],
39943 ['LTS', '15:25:50'],
39944 ['L', '2010-02-14'],
39945 ['LL', '2010 оны Хоёрдугаар сарын 14'],
39946 ['LLL', '2010 оны Хоёрдугаар сарын 14 15:25'],
39947 ['LLLL', 'Ням, 2010 оны Хоёрдугаар сарын 14 15:25'],
39948 ['l', '2010-2-14'],
39949 ['ll', '2010 оны 2 сарын 14'],
39950 ['lll', '2010 оны 2 сарын 14 15:25'],
39951 ['llll', 'Ням, 2010 оны 2 сарын 14 15:25']
39952 ],
39953 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
39954 i;
39955
39956 for (i = 0; i < a.length; i++) {
39957 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
39958 }
39959 });
39960
39961 test('format meridiem', function (assert) {
39962 assert.equal(moment([2012, 11, 28, 0, 0]).format('A'), 'ҮӨ', 'AM');
39963 assert.equal(moment([2012, 11, 28, 11, 59]).format('A'), 'ҮӨ', 'AM');
39964 assert.equal(moment([2012, 11, 28, 12, 0]).format('A'), 'ҮХ', 'PM');
39965 assert.equal(moment([2012, 11, 28, 23, 59]).format('A'), 'ҮХ', 'PM');
39966 });
39967
39968 test('format ordinal', function (assert) {
39969 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1 өдөр', '1st');
39970 });
39971
39972 test('format month', function (assert) {
39973 var i,
39974 expected = 'Нэгдүгээр сар 1 сар_Хоёрдугаар сар 2 сар_Гуравдугаар сар 3 сар_Дөрөвдүгээр сар 4 сар_Тавдугаар сар 5 сар_Зургадугаар сар 6 сар_Долдугаар сар 7 сар_Наймдугаар сар 8 сар_Есдүгээр сар 9 сар_Аравдугаар сар 10 сар_Арван нэгдүгээр сар 11 сар_Арван хоёрдугаар сар 12 сар'.split('_');
39975
39976 for (i = 0; i < expected.length; i++) {
39977 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
39978 }
39979 });
39980
39981 test('format week', function (assert) {
39982 var i,
39983 expected = 'Ням Ням Ня_Даваа Дав Да_Мягмар Мяг Мя_Лхагва Лха Лх_Пүрэв Пүр Пү_Баасан Баа Ба_Бямба Бям Бя'.split('_');
39984
39985 for (i = 0; i < expected.length; i++) {
39986 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
39987 }
39988 });
39989
39990 test('from', function (assert) {
39991 var start = moment([2007, 1, 28]);
39992 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'хэдхэн секунд', '44 seconds = a few seconds');
39993 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '1 минут', '45 seconds = a minute');
39994 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '1 минут', '89 seconds = a minute');
39995 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 минут', '90 seconds = 2 minutes');
39996 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 минут', '44 minutes = 44 minutes');
39997 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '1 цаг', '45 minutes = an hour');
39998 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '1 цаг', '89 minutes = an hour');
39999 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 цаг', '90 minutes = 2 hours');
40000 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 цаг', '5 hours = 5 hours');
40001 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 цаг', '21 hours = 21 hours');
40002 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '1 өдөр', '22 hours = a day');
40003 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '1 өдөр', '35 hours = a day');
40004 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 өдөр', '36 hours = 2 days');
40005 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '1 өдөр', '1 day = a day');
40006 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 өдөр', '5 days = 5 days');
40007 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 өдөр', '25 days = 25 days');
40008 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '1 сар', '26 days = a month');
40009 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '1 сар', '30 days = a month');
40010 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '1 сар', '43 days = a month');
40011 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 сар', '46 days = 2 months');
40012 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 сар', '75 days = 2 months');
40013 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 сар', '76 days = 3 months');
40014 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '1 сар', '1 month = a month');
40015 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 сар', '5 months = 5 months');
40016 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '1 жил', '345 days = a year');
40017 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 жил', '548 days = 2 years');
40018 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '1 жил', '1 year = a year');
40019 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 жил', '5 years = 5 years');
40020 });
40021
40022 test('suffix', function (assert) {
40023 assert.equal(moment(30000).from(0), 'хэдхэн секундын дараа', 'prefix');
40024 assert.equal(moment(0).from(30000), 'хэдхэн секундын өмнө', 'suffix');
40025 });
40026
40027 test('now from now', function (assert) {
40028 assert.equal(moment().fromNow(), 'хэдхэн секундын өмнө', 'now from now should display as in the past');
40029 });
40030
40031 test('fromNow', function (assert) {
40032 assert.equal(moment().add({s: 30}).fromNow(), 'хэдхэн секундын дараа', 'in a few seconds');
40033 assert.equal(moment().add({s: 50}).fromNow(), '1 минутын дараа', 'in a minute');
40034 assert.equal(moment().add({m: 5}).fromNow(), '5 минутын дараа', 'in 5 minutes');
40035 assert.equal(moment().add({h: 2}).fromNow(), '2 цагийн дараа', 'in 2 hours');
40036 assert.equal(moment().add({d: 5}).fromNow(), '5 өдрийн дараа', 'in 5 days');
40037 assert.equal(moment().add({M: 2}).fromNow(), '2 сарын дараа', 'in 2 months');
40038 assert.equal(moment().add({M: 15}).fromNow(), '1 жилийн дараа', 'in a year');
40039 assert.equal(moment().add({M: 16}).fromNow(), '1 жилийн дараа', 'in a year');
40040 assert.equal(moment().add({M: 23}).fromNow(), '2 жилийн дараа', 'in 2 years');
40041 assert.equal(moment().add({y: 7}).fromNow(), '7 жилийн дараа', 'in 7 years');
40042
40043 assert.equal(moment().subtract({s: 30}).fromNow(), 'хэдхэн секундын өмнө', 'a few seconds ago');
40044 assert.equal(moment().subtract({s: 50}).fromNow(), '1 минутын өмнө', 'a minute ago');
40045 assert.equal(moment().subtract({m: 5}).fromNow(), '5 минутын өмнө', '5 minutes ago');
40046 assert.equal(moment().subtract({h: 2}).fromNow(), '2 цагийн өмнө', '2 hours ago');
40047 assert.equal(moment().subtract({d: 5}).fromNow(), '5 өдрийн өмнө', '5 days ago');
40048 assert.equal(moment().subtract({M: 2}).fromNow(), '2 сарын өмнө', '2 months ago');
40049 assert.equal(moment().subtract({M: 15}).fromNow(), '1 жилийн өмнө', 'a year ago');
40050 assert.equal(moment().subtract({M: 16}).fromNow(), '1 жилийн өмнө', 'a year ago');
40051 assert.equal(moment().subtract({M: 23}).fromNow(), '2 жилийн өмнө', '2 years ago');
40052 assert.equal(moment().subtract({y: 7}).fromNow(), '7 жилийн өмнө', '7 years ago');
40053 });
40054
40055 test('calendar day', function (assert) {
40056 var a = moment().hours(12).minutes(0).seconds(0);
40057
40058 assert.equal(moment(a).calendar(), 'Өнөөдөр 12:00', 'today at the same time');
40059 assert.equal(moment(a).add({m: 25}).calendar(), 'Өнөөдөр 12:25', 'Now plus 25 min');
40060 assert.equal(moment(a).add({h: 1}).calendar(), 'Өнөөдөр 13:00', 'Now plus 1 hour');
40061 assert.equal(moment(a).add({d: 1}).calendar(), 'Маргааш 12:00', 'tomorrow at the same time');
40062 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Өнөөдөр 11:00', 'Now minus 1 hour');
40063 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Өчигдөр 12:00', 'yesterday at the same time');
40064 });
40065
40066 test('calendar next week', function (assert) {
40067 var i, m;
40068
40069 for (i = 2; i < 7; i++) {
40070 m = moment().add({d: i});
40071 assert.equal(m.calendar(), m.format('[Ирэх] dddd LT'), 'Today + ' + i + ' days current time');
40072 m.hours(0).minutes(0).seconds(0).milliseconds(0);
40073 assert.equal(m.calendar(), m.format('[Ирэх] dddd LT'), 'Today + ' + i + ' days beginning of day');
40074 m.hours(23).minutes(59).seconds(59).milliseconds(999);
40075 assert.equal(m.calendar(), m.format('[Ирэх] dddd LT'), 'Today + ' + i + ' days end of day');
b135bf1a 40076 }
db71a655
KM
40077 });
40078
40079 test('calendar last week', function (assert) {
40080 var i, m;
40081
40082 for (i = 2; i < 7; i++) {
40083 m = moment().subtract({d: i});
40084 assert.equal(m.calendar(), m.format('[Өнгөрсөн] dddd LT'), 'Today - ' + i + ' days current time');
40085 m.hours(0).minutes(0).seconds(0).milliseconds(0);
40086 assert.equal(m.calendar(), m.format('[Өнгөрсөн] dddd LT'), 'Today - ' + i + ' days beginning of day');
40087 m.hours(23).minutes(59).seconds(59).milliseconds(999);
40088 assert.equal(m.calendar(), m.format('[Өнгөрсөн] dddd LT'), 'Today - ' + i + ' days end of day');
b135bf1a 40089 }
db71a655 40090 });
b135bf1a 40091
db71a655
KM
40092 test('calendar all else', function (assert) {
40093 var weeksAgo = moment().subtract({w: 1}),
40094 weeksFromNow = moment().add({w: 1});
b135bf1a 40095
db71a655
KM
40096 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
40097 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
b135bf1a 40098
db71a655
KM
40099 weeksAgo = moment().subtract({w: 2});
40100 weeksFromNow = moment().add({w: 2});
b135bf1a 40101
db71a655
KM
40102 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
40103 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
40104 });
40105
40106 test('weeks year starting sunday format', function (assert) {
40107 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1');
40108 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1', 'Jan 7 2012 should be week 1');
40109 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2');
40110 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2', 'Jan 14 2012 should be week 2');
40111 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', 'Jan 15 2012 should be week 3');
40112 });
73f3c911
IC
40113
40114})));
d6651c21 40115
d6651c21 40116
73f3c911
IC
40117;(function (global, factory) {
40118 typeof exports === 'object' && typeof module !== 'undefined'
40119 && typeof require === 'function' ? factory(require('../../moment')) :
40120 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
40121 factory(global.moment)
40122}(this, (function (moment) { 'use strict';
d6651c21 40123
db71a655
KM
40124 function each(array, callback) {
40125 var i;
40126 for (i = 0; i < array.length; i++) {
40127 callback(array[i], i, array);
40128 }
73f3c911 40129 }
d6651c21 40130
c58511b9
KM
40131 function setupDeprecationHandler(test, moment$$1, scope) {
40132 test._expectedDeprecations = null;
40133 test._observedDeprecations = null;
40134 test._oldSupress = moment$$1.suppressDeprecationWarnings;
40135 moment$$1.suppressDeprecationWarnings = true;
40136 test.expectedDeprecations = function () {
40137 test._expectedDeprecations = arguments;
40138 test._observedDeprecations = [];
40139 };
40140 moment$$1.deprecationHandler = function (name, msg) {
40141 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
40142 if (deprecationId === -1) {
40143 throw new Error('Unexpected deprecation thrown name=' +
40144 name + ' msg=' + msg);
40145 }
40146 test._observedDeprecations[deprecationId] = 1;
40147 };
40148 }
40149
40150 function teardownDeprecationHandler(test, moment$$1, scope) {
40151 moment$$1.suppressDeprecationWarnings = test._oldSupress;
40152
40153 if (test._expectedDeprecations != null) {
40154 var missedDeprecations = [];
40155 each(test._expectedDeprecations, function (deprecationPattern, id) {
40156 if (test._observedDeprecations[id] !== 1) {
40157 missedDeprecations.push(deprecationPattern);
40158 }
40159 });
40160 if (missedDeprecations.length !== 0) {
40161 throw new Error('Expected deprecation warnings did not happen: ' +
40162 missedDeprecations.join(' '));
40163 }
40164 }
40165 }
40166
40167 function matchedDeprecation(name, msg, deprecations) {
40168 if (deprecations == null) {
40169 return -1;
40170 }
40171 for (var i = 0; i < deprecations.length; ++i) {
40172 if (name != null && name === deprecations[i]) {
40173 return i;
40174 }
40175 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
40176 return i;
40177 }
40178 }
40179 return -1;
40180 }
40181
40182 /*global QUnit:false*/
40183
40184 var test = QUnit.test;
40185
db71a655
KM
40186 function objectKeys(obj) {
40187 if (Object.keys) {
40188 return Object.keys(obj);
40189 } else {
40190 // IE8
40191 var res = [], i;
40192 for (i in obj) {
40193 if (obj.hasOwnProperty(i)) {
40194 res.push(i);
40195 }
d6651c21 40196 }
db71a655 40197 return res;
d6651c21
IC
40198 }
40199 }
40200
db71a655 40201 // Pick the first defined of two or three arguments.
b135bf1a 40202
db71a655
KM
40203 function defineCommonLocaleTests(locale, options) {
40204 test('lenient day of month ordinal parsing', function (assert) {
40205 var i, ordinalStr, testMoment;
40206 for (i = 1; i <= 31; ++i) {
40207 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
40208 testMoment = moment(ordinalStr, 'YYYY MM Do');
40209 assert.equal(testMoment.year(), 2014,
40210 'lenient day of month ordinal parsing ' + i + ' year check');
40211 assert.equal(testMoment.month(), 0,
40212 'lenient day of month ordinal parsing ' + i + ' month check');
40213 assert.equal(testMoment.date(), i,
40214 'lenient day of month ordinal parsing ' + i + ' date check');
40215 }
40216 });
25cc720f 40217
db71a655
KM
40218 test('lenient day of month ordinal parsing of number', function (assert) {
40219 var i, testMoment;
40220 for (i = 1; i <= 31; ++i) {
40221 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
40222 assert.equal(testMoment.year(), 2014,
40223 'lenient day of month ordinal parsing of number ' + i + ' year check');
40224 assert.equal(testMoment.month(), 0,
40225 'lenient day of month ordinal parsing of number ' + i + ' month check');
40226 assert.equal(testMoment.date(), i,
40227 'lenient day of month ordinal parsing of number ' + i + ' date check');
40228 }
40229 });
25cc720f 40230
db71a655
KM
40231 test('strict day of month ordinal parsing', function (assert) {
40232 var i, ordinalStr, testMoment;
40233 for (i = 1; i <= 31; ++i) {
40234 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
40235 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
40236 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
40237 }
40238 });
c74a101d 40239
db71a655
KM
40240 test('meridiem invariant', function (assert) {
40241 var h, m, t1, t2;
40242 for (h = 0; h < 24; ++h) {
40243 for (m = 0; m < 60; m += 15) {
40244 t1 = moment.utc([2000, 0, 1, h, m]);
40245 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
40246 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
40247 'meridiem at ' + t1.format('HH:mm'));
40248 }
40249 }
40250 });
40251
40252 test('date format correctness', function (assert) {
40253 var data, tokens;
40254 data = moment.localeData()._longDateFormat;
40255 tokens = objectKeys(data);
40256 each(tokens, function (srchToken) {
40257 // Check each format string to make sure it does not contain any
40258 // tokens that need to be expanded.
40259 each(tokens, function (baseToken) {
40260 // strip escaped sequences
40261 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
40262 assert.equal(false, !!~format.indexOf(srchToken),
40263 'contains ' + srchToken + ' in ' + baseToken);
40264 });
73f3c911 40265 });
25cc720f 40266 });
25cc720f 40267
db71a655
KM
40268 test('month parsing correctness', function (assert) {
40269 var i, m;
40270
40271 if (locale === 'tr') {
40272 // I can't fix it :(
c58511b9 40273 assert.expect(0);
db71a655
KM
40274 return;
40275 }
40276 function tester(format) {
40277 var r;
40278 r = moment(m.format(format), format);
40279 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
40280 if (locale !== 'ka') {
40281 r = moment(m.format(format).toLocaleUpperCase(), format);
40282 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
40283 }
db71a655
KM
40284 r = moment(m.format(format).toLocaleLowerCase(), format);
40285 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
40286
40287 r = moment(m.format(format), format, true);
40288 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
40289 if (locale !== 'ka') {
40290 r = moment(m.format(format).toLocaleUpperCase(), format, true);
40291 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
40292 }
db71a655
KM
40293 r = moment(m.format(format).toLocaleLowerCase(), format, true);
40294 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
40295 }
40296
40297 for (i = 0; i < 12; ++i) {
40298 m = moment([2015, i, 15, 18]);
40299 tester('MMM');
40300 tester('MMM.');
40301 tester('MMMM');
40302 tester('MMMM.');
40303 }
40304 });
73f3c911 40305
db71a655
KM
40306 test('weekday parsing correctness', function (assert) {
40307 var i, m;
40308
96d0d679 40309 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
40310 // tr, az: There is a lower-case letter (ı), that converted to
40311 // upper then lower changes to i
40312 // ro: there is the letter ț which behaves weird under IE8
40313 // mt: letter Ħ
96d0d679 40314 // ga: month with spaces
c58511b9 40315 assert.expect(0);
db71a655
KM
40316 return;
40317 }
40318 function tester(format) {
40319 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
40320 r = moment(m.format(format), format);
40321 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
40322 if (locale !== 'ka') {
40323 r = moment(m.format(format).toLocaleUpperCase(), format);
40324 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
40325 }
db71a655
KM
40326 r = moment(m.format(format).toLocaleLowerCase(), format);
40327 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
40328 r = moment(m.format(format), format, true);
40329 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
40330 if (locale !== 'ka') {
40331 r = moment(m.format(format).toLocaleUpperCase(), format, true);
40332 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
40333 }
db71a655
KM
40334 r = moment(m.format(format).toLocaleLowerCase(), format, true);
40335 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
40336 }
40337
40338 for (i = 0; i < 7; ++i) {
40339 m = moment.utc([2015, 0, i + 1, 18]);
40340 tester('dd');
40341 tester('ddd');
40342 tester('dddd');
40343 }
40344 });
25cc720f 40345
db71a655
KM
40346 test('valid localeData', function (assert) {
40347 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
40348 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
40349 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
40350 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
40351 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
40352 });
96d0d679
KM
40353
40354 test('localeData weekdays can localeSort', function (assert) {
40355 var weekdays = moment().localeData().weekdays();
40356 var weekdaysShort = moment().localeData().weekdaysShort();
40357 var weekdaysMin = moment().localeData().weekdaysMin();
40358 var shift = moment().localeData()._week.dow;
40359 assert.deepEqual(
40360 moment().localeData().weekdays(true),
40361 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
40362 'weekdays should localeSort');
40363 assert.deepEqual(
40364 moment().localeData().weekdaysShort(true),
40365 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
40366 'weekdaysShort should localeSort');
40367 assert.deepEqual(
40368 moment().localeData().weekdaysMin(true),
40369 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
40370 'weekdaysMin should localeSort');
40371 });
db71a655 40372 }
25cc720f 40373
db71a655 40374 /*global QUnit:false*/
b135bf1a 40375
db71a655
KM
40376 function localeModule (name, lifecycle) {
40377 QUnit.module('locale:' + name, {
c58511b9 40378 beforeEach : function () {
db71a655
KM
40379 moment.locale(name);
40380 moment.createFromInputFallback = function (config) {
40381 throw new Error('input not handled by moment: ' + config._i);
40382 };
40383 setupDeprecationHandler(test, moment, 'locale');
40384 if (lifecycle && lifecycle.setup) {
40385 lifecycle.setup();
40386 }
40387 },
c58511b9 40388 afterEach : function () {
db71a655
KM
40389 moment.locale('en');
40390 teardownDeprecationHandler(test, moment, 'locale');
40391 if (lifecycle && lifecycle.teardown) {
40392 lifecycle.teardown();
40393 }
b135bf1a 40394 }
73f3c911 40395 });
db71a655
KM
40396 defineCommonLocaleTests(name, -1, -1);
40397 }
40398
40399 localeModule('mr');
40400
40401 test('parse', function (assert) {
40402 var tests = 'जानेवारी जाने._फेब्रुवारी फेब्रु._मार्च मार्च._एप्रिल एप्रि._मे मे._जून जून._जुलै जुलै._ऑगस्ट ऑग._सप्टेंबर सप्टें._ऑक्टोबर ऑक्टो._नोव्हेंबर नोव्हें._डिसेंबर डिसें.'.split('_'), i;
40403 function equalTest(input, mmm, i) {
40404 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
40405 }
40406 for (i = 0; i < 12; i++) {
40407 tests[i] = tests[i].split(' ');
40408 equalTest(tests[i][0], 'MMM', i);
40409 equalTest(tests[i][1], 'MMM', i);
40410 equalTest(tests[i][0], 'MMMM', i);
40411 equalTest(tests[i][1], 'MMMM', i);
40412 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
40413 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
40414 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
40415 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
40416 }
40417 });
40418
40419 test('format', function (assert) {
40420 var a = [
40421 ['dddd, Do MMMM YYYY, a h:mm:ss वाजता', 'रविवार, १४ फेब्रुवारी २०१०, दुपारी ३:२५:५० वाजता'],
40422 ['ddd, a h वाजता', 'रवि, दुपारी ३ वाजता'],
40423 ['M Mo MM MMMM MMM', '२ २ ०२ फेब्रुवारी फेब्रु.'],
40424 ['YYYY YY', '२०१० १०'],
40425 ['D Do DD', '१४ १४ १४'],
40426 ['d do dddd ddd dd', '० ० रविवार रवि र'],
40427 ['DDD DDDo DDDD', '४५ ४५ ०४५'],
40428 ['w wo ww', '८ ८ ०८'],
40429 ['h hh', '३ ०३'],
40430 ['H HH', '१५ १५'],
40431 ['m mm', '२५ २५'],
40432 ['s ss', '५० ५०'],
40433 ['a A', 'दुपारी दुपारी'],
40434 ['LTS', 'दुपारी ३:२५:५० वाजता'],
40435 ['L', '१४/०२/२०१०'],
40436 ['LL', '१४ फेब्रुवारी २०१०'],
40437 ['LLL', '१४ फेब्रुवारी २०१०, दुपारी ३:२५ वाजता'],
40438 ['LLLL', 'रविवार, १४ फेब्रुवारी २०१०, दुपारी ३:२५ वाजता'],
40439 ['l', '१४/२/२०१०'],
40440 ['ll', '१४ फेब्रु. २०१०'],
40441 ['lll', '१४ फेब्रु. २०१०, दुपारी ३:२५ वाजता'],
40442 ['llll', 'रवि, १४ फेब्रु. २०१०, दुपारी ३:२५ वाजता']
40443 ],
40444 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
40445 i;
40446 for (i = 0; i < a.length; i++) {
40447 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
40448 }
40449 });
40450
40451 test('format ordinal', function (assert) {
40452 assert.equal(moment([2011, 0, 1]).format('DDDo'), '१', '१');
40453 assert.equal(moment([2011, 0, 2]).format('DDDo'), '२', '२');
40454 assert.equal(moment([2011, 0, 3]).format('DDDo'), '३', '३');
40455 assert.equal(moment([2011, 0, 4]).format('DDDo'), '४', '४');
40456 assert.equal(moment([2011, 0, 5]).format('DDDo'), '५', '५');
40457 assert.equal(moment([2011, 0, 6]).format('DDDo'), '६', '६');
40458 assert.equal(moment([2011, 0, 7]).format('DDDo'), '७', '७');
40459 assert.equal(moment([2011, 0, 8]).format('DDDo'), '८', '८');
40460 assert.equal(moment([2011, 0, 9]).format('DDDo'), '९', '९');
40461 assert.equal(moment([2011, 0, 10]).format('DDDo'), '१०', '१०');
40462
40463 assert.equal(moment([2011, 0, 11]).format('DDDo'), '११', '११');
40464 assert.equal(moment([2011, 0, 12]).format('DDDo'), '१२', '१२');
40465 assert.equal(moment([2011, 0, 13]).format('DDDo'), '१३', '१३');
40466 assert.equal(moment([2011, 0, 14]).format('DDDo'), '१४', '१४');
40467 assert.equal(moment([2011, 0, 15]).format('DDDo'), '१५', '१५');
40468 assert.equal(moment([2011, 0, 16]).format('DDDo'), '१६', '१६');
40469 assert.equal(moment([2011, 0, 17]).format('DDDo'), '१७', '१७');
40470 assert.equal(moment([2011, 0, 18]).format('DDDo'), '१८', '१८');
40471 assert.equal(moment([2011, 0, 19]).format('DDDo'), '१९', '१९');
40472 assert.equal(moment([2011, 0, 20]).format('DDDo'), '२०', '२०');
40473
40474 assert.equal(moment([2011, 0, 21]).format('DDDo'), '२१', '२१');
40475 assert.equal(moment([2011, 0, 22]).format('DDDo'), '२२', '२२');
40476 assert.equal(moment([2011, 0, 23]).format('DDDo'), '२३', '२३');
40477 assert.equal(moment([2011, 0, 24]).format('DDDo'), '२४', '२४');
40478 assert.equal(moment([2011, 0, 25]).format('DDDo'), '२५', '२५');
40479 assert.equal(moment([2011, 0, 26]).format('DDDo'), '२६', '२६');
40480 assert.equal(moment([2011, 0, 27]).format('DDDo'), '२७', '२७');
40481 assert.equal(moment([2011, 0, 28]).format('DDDo'), '२८', '२८');
40482 assert.equal(moment([2011, 0, 29]).format('DDDo'), '२९', '२९');
40483 assert.equal(moment([2011, 0, 30]).format('DDDo'), '३०', '३०');
40484
40485 assert.equal(moment([2011, 0, 31]).format('DDDo'), '३१', '३१');
40486 });
40487
40488 test('format month', function (assert) {
40489 var expected = 'जानेवारी जाने._फेब्रुवारी फेब्रु._मार्च मार्च._एप्रिल एप्रि._मे मे._जून जून._जुलै जुलै._ऑगस्ट ऑग._सप्टेंबर सप्टें._ऑक्टोबर ऑक्टो._नोव्हेंबर नोव्हें._डिसेंबर डिसें.'.split('_'), i;
40490 for (i = 0; i < expected.length; i++) {
40491 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
40492 }
40493 });
40494
40495 test('format week', function (assert) {
40496 var expected = 'रविवार रवि र_सोमवार सोम सो_मंगळवार मंगळ मं_बुधवार बुध बु_गुरूवार गुरू गु_शुक्रवार शुक्र शु_शनिवार शनि श'.split('_'), i;
40497 for (i = 0; i < expected.length; i++) {
40498 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
40499 }
40500 });
40501
40502 test('from', function (assert) {
40503 var start = moment([2007, 1, 28]);
40504 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'काही सेकंद', '44 seconds = a few seconds');
40505 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'एक मिनिट', '45 seconds = a minute');
40506 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'एक मिनिट', '89 seconds = a minute');
40507 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '२ मिनिटे', '90 seconds = 2 minutes');
40508 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '४४ मिनिटे', '44 minutes = 44 minutes');
40509 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'एक तास', '45 minutes = an hour');
40510 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'एक तास', '89 minutes = an hour');
40511 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '२ तास', '90 minutes = 2 hours');
40512 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '५ तास', '5 hours = 5 hours');
40513 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '२१ तास', '21 hours = 21 hours');
40514 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'एक दिवस', '22 hours = a day');
40515 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'एक दिवस', '35 hours = a day');
40516 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '२ दिवस', '36 hours = 2 days');
40517 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'एक दिवस', '1 day = a day');
40518 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '५ दिवस', '5 days = 5 days');
40519 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '२५ दिवस', '25 days = 25 days');
40520 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'एक महिना', '26 days = a month');
40521 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'एक महिना', '30 days = a month');
40522 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'एक महिना', '43 days = a month');
40523 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '२ महिने', '46 days = 2 months');
40524 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '२ महिने', '75 days = 2 months');
40525 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '३ महिने', '76 days = 3 months');
40526 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'एक महिना', '1 month = a month');
40527 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '५ महिने', '5 months = 5 months');
40528 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'एक वर्ष', '345 days = a year');
40529 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '२ वर्षे', '548 days = 2 years');
40530 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'एक वर्ष', '1 year = a year');
40531 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '५ वर्षे', '5 years = 5 years');
40532 });
40533
40534 test('suffix', function (assert) {
40535 assert.equal(moment(30000).from(0), 'काही सेकंदांमध्ये', 'prefix');
40536 assert.equal(moment(0).from(30000), 'काही सेकंदांपूर्वी', 'suffix');
40537 });
40538
40539 test('now from now', function (assert) {
40540 assert.equal(moment().fromNow(), 'काही सेकंदांपूर्वी', 'now from now should display as in the past');
40541 });
40542
40543 test('fromNow', function (assert) {
40544 assert.equal(moment().add({s: 30}).fromNow(), 'काही सेकंदांमध्ये', 'in a few seconds');
40545 assert.equal(moment().add({d: 5}).fromNow(), '५ दिवसांमध्ये', 'in 5 days');
40546 });
40547
40548 test('calendar day', function (assert) {
40549 var a = moment().hours(12).minutes(0).seconds(0);
40550
40551 assert.equal(moment(a).calendar(), 'आज दुपारी १२:०० वाजता', 'today at the same time');
40552 assert.equal(moment(a).add({m: 25}).calendar(), 'आज दुपारी १२:२५ वाजता', 'Now plus 25 min');
40553 assert.equal(moment(a).add({h: 3}).calendar(), 'आज दुपारी ३:०० वाजता', 'Now plus 3 hours');
40554 assert.equal(moment(a).add({d: 1}).calendar(), 'उद्या दुपारी १२:०० वाजता', 'tomorrow at the same time');
40555 assert.equal(moment(a).subtract({h: 1}).calendar(), 'आज दुपारी ११:०० वाजता', 'Now minus 1 hour');
40556 assert.equal(moment(a).subtract({d: 1}).calendar(), 'काल दुपारी १२:०० वाजता', 'yesterday at the same time');
40557 });
40558
40559 test('calendar next week', function (assert) {
40560 var i, m;
40561 for (i = 2; i < 7; i++) {
40562 m = moment().add({d: i});
40563 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days current time');
40564 m.hours(0).minutes(0).seconds(0).milliseconds(0);
40565 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days beginning of day');
40566 m.hours(23).minutes(59).seconds(59).milliseconds(999);
40567 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days end of day');
b135bf1a 40568 }
db71a655 40569 });
b135bf1a 40570
db71a655
KM
40571 test('calendar last week', function (assert) {
40572 var i, m;
40573
40574 for (i = 2; i < 7; i++) {
40575 m = moment().subtract({d: i});
40576 assert.equal(m.calendar(), m.format('[मागील] dddd[,] LT'), 'Today - ' + i + ' days current time');
40577 m.hours(0).minutes(0).seconds(0).milliseconds(0);
40578 assert.equal(m.calendar(), m.format('[मागील] dddd[,] LT'), 'Today - ' + i + ' days beginning of day');
40579 m.hours(23).minutes(59).seconds(59).milliseconds(999);
40580 assert.equal(m.calendar(), m.format('[मागील] dddd[,] LT'), 'Today - ' + i + ' days end of day');
b135bf1a 40581 }
db71a655 40582 });
b135bf1a 40583
db71a655
KM
40584 test('calendar all else', function (assert) {
40585 var weeksAgo = moment().subtract({w: 1}),
40586 weeksFromNow = moment().add({w: 1});
b135bf1a 40587
db71a655
KM
40588 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
40589 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
b135bf1a 40590
db71a655
KM
40591 weeksAgo = moment().subtract({w: 2});
40592 weeksFromNow = moment().add({w: 2});
b135bf1a 40593
db71a655
KM
40594 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
40595 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
40596 });
40597
40598 test('meridiem', function (assert) {
40599 assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), 'रात्री', 'before dawn');
40600 assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), 'सकाळी', 'morning');
40601 assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), 'दुपारी', 'during day');
40602 assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), 'सायंकाळी', 'evening');
40603 assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), 'सायंकाळी', 'late evening');
40604 assert.equal(moment([2011, 2, 23, 21, 20]).format('a'), 'रात्री', 'night');
40605
40606 assert.equal(moment([2011, 2, 23, 2, 30]).format('A'), 'रात्री', 'before dawn');
40607 assert.equal(moment([2011, 2, 23, 9, 30]).format('A'), 'सकाळी', 'morning');
40608 assert.equal(moment([2011, 2, 23, 14, 30]).format('A'), 'दुपारी', ' during day');
40609 assert.equal(moment([2011, 2, 23, 17, 30]).format('A'), 'सायंकाळी', 'evening');
40610 assert.equal(moment([2011, 2, 23, 19, 30]).format('A'), 'सायंकाळी', 'late evening');
40611 assert.equal(moment([2011, 2, 23, 21, 20]).format('A'), 'रात्री', 'night');
40612 });
40613
40614 test('weeks year starting sunday formatted', function (assert) {
40615 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '१ ०१ १', 'Jan 1 2012 should be week 1');
40616 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '१ ०१ १', 'Jan 7 2012 should be week 1');
40617 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '२ ०२ २', 'Jan 8 2012 should be week 2');
40618 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '२ ०२ २', 'Jan 14 2012 should be week 2');
40619 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '३ ०३ ३', 'Jan 15 2012 should be week 3');
40620 });
0e67426b 40621
73f3c911 40622})));
d6651c21 40623
d6651c21 40624
73f3c911
IC
40625;(function (global, factory) {
40626 typeof exports === 'object' && typeof module !== 'undefined'
40627 && typeof require === 'function' ? factory(require('../../moment')) :
40628 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
40629 factory(global.moment)
40630}(this, (function (moment) { 'use strict';
d6651c21 40631
db71a655
KM
40632 function each(array, callback) {
40633 var i;
40634 for (i = 0; i < array.length; i++) {
40635 callback(array[i], i, array);
40636 }
d6651c21
IC
40637 }
40638
c58511b9
KM
40639 function setupDeprecationHandler(test, moment$$1, scope) {
40640 test._expectedDeprecations = null;
40641 test._observedDeprecations = null;
40642 test._oldSupress = moment$$1.suppressDeprecationWarnings;
40643 moment$$1.suppressDeprecationWarnings = true;
40644 test.expectedDeprecations = function () {
40645 test._expectedDeprecations = arguments;
40646 test._observedDeprecations = [];
40647 };
40648 moment$$1.deprecationHandler = function (name, msg) {
40649 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
40650 if (deprecationId === -1) {
40651 throw new Error('Unexpected deprecation thrown name=' +
40652 name + ' msg=' + msg);
40653 }
40654 test._observedDeprecations[deprecationId] = 1;
40655 };
40656 }
40657
40658 function teardownDeprecationHandler(test, moment$$1, scope) {
40659 moment$$1.suppressDeprecationWarnings = test._oldSupress;
40660
40661 if (test._expectedDeprecations != null) {
40662 var missedDeprecations = [];
40663 each(test._expectedDeprecations, function (deprecationPattern, id) {
40664 if (test._observedDeprecations[id] !== 1) {
40665 missedDeprecations.push(deprecationPattern);
40666 }
40667 });
40668 if (missedDeprecations.length !== 0) {
40669 throw new Error('Expected deprecation warnings did not happen: ' +
40670 missedDeprecations.join(' '));
40671 }
40672 }
40673 }
40674
40675 function matchedDeprecation(name, msg, deprecations) {
40676 if (deprecations == null) {
40677 return -1;
40678 }
40679 for (var i = 0; i < deprecations.length; ++i) {
40680 if (name != null && name === deprecations[i]) {
40681 return i;
40682 }
40683 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
40684 return i;
40685 }
40686 }
40687 return -1;
40688 }
40689
40690 /*global QUnit:false*/
40691
40692 var test = QUnit.test;
40693
db71a655
KM
40694 function objectKeys(obj) {
40695 if (Object.keys) {
40696 return Object.keys(obj);
40697 } else {
40698 // IE8
40699 var res = [], i;
40700 for (i in obj) {
40701 if (obj.hasOwnProperty(i)) {
40702 res.push(i);
40703 }
d6651c21 40704 }
db71a655 40705 return res;
d6651c21 40706 }
b135bf1a
IC
40707 }
40708
db71a655 40709 // Pick the first defined of two or three arguments.
516f5f67 40710
db71a655
KM
40711 function defineCommonLocaleTests(locale, options) {
40712 test('lenient day of month ordinal parsing', function (assert) {
40713 var i, ordinalStr, testMoment;
40714 for (i = 1; i <= 31; ++i) {
40715 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
40716 testMoment = moment(ordinalStr, 'YYYY MM Do');
40717 assert.equal(testMoment.year(), 2014,
40718 'lenient day of month ordinal parsing ' + i + ' year check');
40719 assert.equal(testMoment.month(), 0,
40720 'lenient day of month ordinal parsing ' + i + ' month check');
40721 assert.equal(testMoment.date(), i,
40722 'lenient day of month ordinal parsing ' + i + ' date check');
40723 }
40724 });
516f5f67 40725
db71a655
KM
40726 test('lenient day of month ordinal parsing of number', function (assert) {
40727 var i, testMoment;
40728 for (i = 1; i <= 31; ++i) {
40729 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
40730 assert.equal(testMoment.year(), 2014,
40731 'lenient day of month ordinal parsing of number ' + i + ' year check');
40732 assert.equal(testMoment.month(), 0,
40733 'lenient day of month ordinal parsing of number ' + i + ' month check');
40734 assert.equal(testMoment.date(), i,
40735 'lenient day of month ordinal parsing of number ' + i + ' date check');
40736 }
40737 });
516f5f67 40738
db71a655
KM
40739 test('strict day of month ordinal parsing', function (assert) {
40740 var i, ordinalStr, testMoment;
40741 for (i = 1; i <= 31; ++i) {
40742 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
40743 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
40744 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
40745 }
40746 });
516f5f67 40747
db71a655
KM
40748 test('meridiem invariant', function (assert) {
40749 var h, m, t1, t2;
40750 for (h = 0; h < 24; ++h) {
40751 for (m = 0; m < 60; m += 15) {
40752 t1 = moment.utc([2000, 0, 1, h, m]);
40753 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
40754 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
40755 'meridiem at ' + t1.format('HH:mm'));
40756 }
40757 }
40758 });
40759
40760 test('date format correctness', function (assert) {
40761 var data, tokens;
40762 data = moment.localeData()._longDateFormat;
40763 tokens = objectKeys(data);
40764 each(tokens, function (srchToken) {
40765 // Check each format string to make sure it does not contain any
40766 // tokens that need to be expanded.
40767 each(tokens, function (baseToken) {
40768 // strip escaped sequences
40769 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
40770 assert.equal(false, !!~format.indexOf(srchToken),
40771 'contains ' + srchToken + ' in ' + baseToken);
40772 });
73f3c911
IC
40773 });
40774 });
516f5f67 40775
db71a655
KM
40776 test('month parsing correctness', function (assert) {
40777 var i, m;
40778
40779 if (locale === 'tr') {
40780 // I can't fix it :(
c58511b9 40781 assert.expect(0);
db71a655
KM
40782 return;
40783 }
40784 function tester(format) {
40785 var r;
40786 r = moment(m.format(format), format);
40787 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
40788 if (locale !== 'ka') {
40789 r = moment(m.format(format).toLocaleUpperCase(), format);
40790 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
40791 }
db71a655
KM
40792 r = moment(m.format(format).toLocaleLowerCase(), format);
40793 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
40794
40795 r = moment(m.format(format), format, true);
40796 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
40797 if (locale !== 'ka') {
40798 r = moment(m.format(format).toLocaleUpperCase(), format, true);
40799 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
40800 }
db71a655
KM
40801 r = moment(m.format(format).toLocaleLowerCase(), format, true);
40802 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
40803 }
40804
40805 for (i = 0; i < 12; ++i) {
40806 m = moment([2015, i, 15, 18]);
40807 tester('MMM');
40808 tester('MMM.');
40809 tester('MMMM');
40810 tester('MMMM.');
40811 }
40812 });
516f5f67 40813
db71a655
KM
40814 test('weekday parsing correctness', function (assert) {
40815 var i, m;
40816
96d0d679 40817 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
40818 // tr, az: There is a lower-case letter (ı), that converted to
40819 // upper then lower changes to i
40820 // ro: there is the letter ț which behaves weird under IE8
40821 // mt: letter Ħ
96d0d679 40822 // ga: month with spaces
c58511b9 40823 assert.expect(0);
db71a655
KM
40824 return;
40825 }
40826 function tester(format) {
40827 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
40828 r = moment(m.format(format), format);
40829 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
40830 if (locale !== 'ka') {
40831 r = moment(m.format(format).toLocaleUpperCase(), format);
40832 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
40833 }
db71a655
KM
40834 r = moment(m.format(format).toLocaleLowerCase(), format);
40835 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
40836 r = moment(m.format(format), format, true);
40837 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
40838 if (locale !== 'ka') {
40839 r = moment(m.format(format).toLocaleUpperCase(), format, true);
40840 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
40841 }
db71a655
KM
40842 r = moment(m.format(format).toLocaleLowerCase(), format, true);
40843 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
40844 }
40845
40846 for (i = 0; i < 7; ++i) {
40847 m = moment.utc([2015, 0, i + 1, 18]);
40848 tester('dd');
40849 tester('ddd');
40850 tester('dddd');
40851 }
40852 });
516f5f67 40853
db71a655
KM
40854 test('valid localeData', function (assert) {
40855 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
40856 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
40857 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
40858 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
40859 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
40860 });
96d0d679
KM
40861
40862 test('localeData weekdays can localeSort', function (assert) {
40863 var weekdays = moment().localeData().weekdays();
40864 var weekdaysShort = moment().localeData().weekdaysShort();
40865 var weekdaysMin = moment().localeData().weekdaysMin();
40866 var shift = moment().localeData()._week.dow;
40867 assert.deepEqual(
40868 moment().localeData().weekdays(true),
40869 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
40870 'weekdays should localeSort');
40871 assert.deepEqual(
40872 moment().localeData().weekdaysShort(true),
40873 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
40874 'weekdaysShort should localeSort');
40875 assert.deepEqual(
40876 moment().localeData().weekdaysMin(true),
40877 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
40878 'weekdaysMin should localeSort');
40879 });
db71a655 40880 }
516f5f67 40881
db71a655
KM
40882 /*global QUnit:false*/
40883
db71a655
KM
40884 function localeModule (name, lifecycle) {
40885 QUnit.module('locale:' + name, {
c58511b9 40886 beforeEach : function () {
db71a655
KM
40887 moment.locale(name);
40888 moment.createFromInputFallback = function (config) {
40889 throw new Error('input not handled by moment: ' + config._i);
40890 };
40891 setupDeprecationHandler(test, moment, 'locale');
40892 if (lifecycle && lifecycle.setup) {
40893 lifecycle.setup();
40894 }
40895 },
c58511b9 40896 afterEach : function () {
db71a655
KM
40897 moment.locale('en');
40898 teardownDeprecationHandler(test, moment, 'locale');
40899 if (lifecycle && lifecycle.teardown) {
40900 lifecycle.teardown();
40901 }
b135bf1a 40902 }
73f3c911 40903 });
db71a655
KM
40904 defineCommonLocaleTests(name, -1, -1);
40905 }
40906
40907 localeModule('ms-my');
40908
40909 test('parse', function (assert) {
40910 var i,
40911 tests = 'Januari Jan_Februari Feb_Mac Mac_April Apr_Mei Mei_Jun Jun_Julai Jul_Ogos Ogs_September Sep_Oktober Okt_November Nov_Disember Dis'.split('_');
40912
40913 function equalTest(input, mmm, i) {
40914 assert.equal(moment(input, mmm).month(), i, input + ' sepatutnya bulan ' + (i + 1));
40915 }
40916
40917 for (i = 0; i < 12; i++) {
40918 tests[i] = tests[i].split(' ');
40919 equalTest(tests[i][0], 'MMM', i);
40920 equalTest(tests[i][1], 'MMM', i);
40921 equalTest(tests[i][0], 'MMMM', i);
40922 equalTest(tests[i][1], 'MMMM', i);
40923 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
40924 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
40925 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
40926 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
40927 }
40928 });
40929
40930 test('format', function (assert) {
40931 var a = [
40932 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Ahad, Februari 14 2010, 3:25:50 petang'],
40933 ['ddd, hA', 'Ahd, 3petang'],
40934 ['M Mo MM MMMM MMM', '2 2 02 Februari Feb'],
40935 ['YYYY YY', '2010 10'],
40936 ['D Do DD', '14 14 14'],
40937 ['d do dddd ddd dd', '0 0 Ahad Ahd Ah'],
40938 ['DDD DDDo DDDD', '45 45 045'],
40939 ['w wo ww', '7 7 07'],
40940 ['h hh', '3 03'],
40941 ['H HH', '15 15'],
40942 ['m mm', '25 25'],
40943 ['s ss', '50 50'],
40944 ['a A', 'petang petang'],
40945 ['[hari] [ke] DDDo [tahun] ini', 'hari ke 45 tahun ini'],
40946 ['LTS', '15.25.50'],
40947 ['L', '14/02/2010'],
40948 ['LL', '14 Februari 2010'],
40949 ['LLL', '14 Februari 2010 pukul 15.25'],
40950 ['LLLL', 'Ahad, 14 Februari 2010 pukul 15.25'],
40951 ['l', '14/2/2010'],
40952 ['ll', '14 Feb 2010'],
40953 ['lll', '14 Feb 2010 pukul 15.25'],
40954 ['llll', 'Ahd, 14 Feb 2010 pukul 15.25']
40955 ],
40956 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
40957 i;
40958
40959 for (i = 0; i < a.length; i++) {
40960 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
40961 }
40962 });
40963
40964 test('format ordinal', function (assert) {
40965 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
40966 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
40967 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
40968 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
40969 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
40970 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
40971 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
40972 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
40973 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
40974 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
40975
40976 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
40977 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
40978 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
40979 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
40980 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
40981 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
40982 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
40983 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
40984 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
40985 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
40986
40987 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
40988 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
40989 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
40990 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
40991 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
40992 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
40993 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
40994 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
40995 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
40996 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
40997
40998 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
40999 });
41000
41001 test('format month', function (assert) {
41002 var i,
41003 expected = 'Januari Jan_Februari Feb_Mac Mac_April Apr_Mei Mei_Jun Jun_Julai Jul_Ogos Ogs_September Sep_Oktober Okt_November Nov_Disember Dis'.split('_');
41004
41005 for (i = 0; i < expected.length; i++) {
41006 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
41007 }
41008 });
41009
41010 test('format week', function (assert) {
41011 var i,
41012 expected = 'Ahad Ahd Ah_Isnin Isn Is_Selasa Sel Sl_Rabu Rab Rb_Khamis Kha Km_Jumaat Jum Jm_Sabtu Sab Sb'.split('_');
41013
41014 for (i = 0; i < expected.length; i++) {
41015 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
41016 }
41017 });
41018
41019 test('from', function (assert) {
41020 var start = moment([2007, 1, 28]);
41021
41022 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'beberapa saat', '44 saat = beberapa saat');
41023 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'seminit', '45 saat = seminit');
41024 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'seminit', '89 saat = seminit');
41025 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minit', '90 saat = 2 minit');
41026 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minit', '44 minit = 44 minit');
41027 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'sejam', '45 minit = sejam');
41028 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'sejam', '89 minit = sejam');
41029 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 jam', '90 minit = 2 jam');
41030 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 jam', '5 jam = 5 jam');
41031 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 jam', '21 jam = 21 jam');
41032 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'sehari', '22 jam = sehari');
41033 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'sehari', '35 jam = sehari');
41034 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 hari', '36 jam = 2 hari');
41035 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'sehari', '1 hari = sehari');
41036 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 hari', '5 hari = 5 hari');
41037 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 hari', '25 hari = 25 hari');
41038 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'sebulan', '26 hari = sebulan');
41039 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'sebulan', '30 hari = sebulan');
41040 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'sebulan', '45 hari = sebulan');
41041 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 bulan', '46 hari = 2 bulan');
41042 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 bulan', '75 hari = 2 bulan');
41043 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 bulan', '76 hari = 3 bulan');
41044 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'sebulan', '1 bulan = sebulan');
41045 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 bulan', '5 bulan = 5 bulan');
41046 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'setahun', '345 hari = setahun');
41047 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 tahun', '548 hari = 2 tahun');
41048 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'setahun', '1 tahun = setahun');
41049 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 tahun', '5 tahun = 5 tahun');
41050 });
41051
41052 test('suffix', function (assert) {
41053 assert.equal(moment(30000).from(0), 'dalam beberapa saat', 'prefix');
41054 assert.equal(moment(0).from(30000), 'beberapa saat yang lepas', 'suffix');
41055 });
41056
41057 test('now from now', function (assert) {
41058 assert.equal(moment().fromNow(), 'beberapa saat yang lepas', 'waktu sekarang dari sekarang sepatutnya menunjukkan sebagai telah lepas');
41059 });
41060
41061 test('fromNow', function (assert) {
41062 assert.equal(moment().add({s: 30}).fromNow(), 'dalam beberapa saat', 'dalam beberapa saat');
41063 assert.equal(moment().add({d: 5}).fromNow(), 'dalam 5 hari', 'dalam 5 hari');
41064 });
41065
41066 test('calendar day', function (assert) {
41067 var a = moment().hours(12).minutes(0).seconds(0);
41068
41069 assert.equal(moment(a).calendar(), 'Hari ini pukul 12.00', 'hari ini pada waktu yang sama');
41070 assert.equal(moment(a).add({m: 25}).calendar(), 'Hari ini pukul 12.25', 'Sekarang tambah 25 minit');
41071 assert.equal(moment(a).add({h: 1}).calendar(), 'Hari ini pukul 13.00', 'Sekarang tambah 1 jam');
41072 assert.equal(moment(a).add({d: 1}).calendar(), 'Esok pukul 12.00', 'esok pada waktu yang sama');
41073 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Hari ini pukul 11.00', 'Sekarang tolak 1 jam');
41074 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Kelmarin pukul 12.00', 'kelmarin pada waktu yang sama');
41075 });
41076
41077 test('calendar next week', function (assert) {
41078 var i, m;
41079 for (i = 2; i < 7; i++) {
41080 m = moment().add({d: i});
41081 assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Hari ini + ' + i + ' hari waktu sekarang');
41082 m.hours(0).minutes(0).seconds(0).milliseconds(0);
41083 assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Hari ini + ' + i + ' hari permulaan hari');
41084 m.hours(23).minutes(59).seconds(59).milliseconds(999);
41085 assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Hari ini + ' + i + ' hari tamat hari');
b135bf1a 41086 }
db71a655 41087 });
b135bf1a 41088
db71a655
KM
41089 test('calendar last week', function (assert) {
41090 var i, m;
41091 for (i = 2; i < 7; i++) {
41092 m = moment().subtract({d: i});
41093 assert.equal(m.calendar(), m.format('dddd [lepas] [pukul] LT'), 'Hari ini - ' + i + ' hari waktu sekarang');
41094 m.hours(0).minutes(0).seconds(0).milliseconds(0);
41095 assert.equal(m.calendar(), m.format('dddd [lepas] [pukul] LT'), 'Hari ini - ' + i + ' hari permulaan hari');
41096 m.hours(23).minutes(59).seconds(59).milliseconds(999);
41097 assert.equal(m.calendar(), m.format('dddd [lepas] [pukul] LT'), 'Hari ini - ' + i + ' hari tamat hari');
b135bf1a 41098 }
db71a655 41099 });
b135bf1a 41100
db71a655
KM
41101 test('calendar all else', function (assert) {
41102 var weeksAgo = moment().subtract({w: 1}),
41103 weeksFromNow = moment().add({w: 1});
b135bf1a 41104
db71a655
KM
41105 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 minggu lepas');
41106 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'dalam 1 minggu');
b135bf1a 41107
db71a655
KM
41108 weeksAgo = moment().subtract({w: 2});
41109 weeksFromNow = moment().add({w: 2});
b135bf1a 41110
db71a655
KM
41111 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 minggu lepas');
41112 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'dalam 2 minggu');
41113 });
41114
41115 test('weeks year starting sunday format', function (assert) {
41116 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 sepatutnya minggu 1');
41117 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '2 02 2', 'Jan 7 2012 sepatutnya minggu 2');
41118 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 sepatutnya minggu 2');
41119 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '3 03 3', 'Jan 14 2012 sepatutnya minggu 3');
41120 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', 'Jan 15 2012 sepatutnya minggu 3');
41121 });
73f3c911
IC
41122
41123})));
d6651c21 41124
d6651c21 41125
73f3c911
IC
41126;(function (global, factory) {
41127 typeof exports === 'object' && typeof module !== 'undefined'
41128 && typeof require === 'function' ? factory(require('../../moment')) :
41129 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
41130 factory(global.moment)
41131}(this, (function (moment) { 'use strict';
d6651c21 41132
db71a655
KM
41133 function each(array, callback) {
41134 var i;
41135 for (i = 0; i < array.length; i++) {
41136 callback(array[i], i, array);
41137 }
d6651c21
IC
41138 }
41139
c58511b9
KM
41140 function setupDeprecationHandler(test, moment$$1, scope) {
41141 test._expectedDeprecations = null;
41142 test._observedDeprecations = null;
41143 test._oldSupress = moment$$1.suppressDeprecationWarnings;
41144 moment$$1.suppressDeprecationWarnings = true;
41145 test.expectedDeprecations = function () {
41146 test._expectedDeprecations = arguments;
41147 test._observedDeprecations = [];
41148 };
41149 moment$$1.deprecationHandler = function (name, msg) {
41150 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
41151 if (deprecationId === -1) {
41152 throw new Error('Unexpected deprecation thrown name=' +
41153 name + ' msg=' + msg);
41154 }
41155 test._observedDeprecations[deprecationId] = 1;
41156 };
41157 }
41158
41159 function teardownDeprecationHandler(test, moment$$1, scope) {
41160 moment$$1.suppressDeprecationWarnings = test._oldSupress;
41161
41162 if (test._expectedDeprecations != null) {
41163 var missedDeprecations = [];
41164 each(test._expectedDeprecations, function (deprecationPattern, id) {
41165 if (test._observedDeprecations[id] !== 1) {
41166 missedDeprecations.push(deprecationPattern);
41167 }
41168 });
41169 if (missedDeprecations.length !== 0) {
41170 throw new Error('Expected deprecation warnings did not happen: ' +
41171 missedDeprecations.join(' '));
41172 }
41173 }
41174 }
41175
41176 function matchedDeprecation(name, msg, deprecations) {
41177 if (deprecations == null) {
41178 return -1;
41179 }
41180 for (var i = 0; i < deprecations.length; ++i) {
41181 if (name != null && name === deprecations[i]) {
41182 return i;
41183 }
41184 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
41185 return i;
41186 }
41187 }
41188 return -1;
41189 }
41190
41191 /*global QUnit:false*/
41192
41193 var test = QUnit.test;
41194
db71a655
KM
41195 function objectKeys(obj) {
41196 if (Object.keys) {
41197 return Object.keys(obj);
41198 } else {
41199 // IE8
41200 var res = [], i;
41201 for (i in obj) {
41202 if (obj.hasOwnProperty(i)) {
41203 res.push(i);
41204 }
d6651c21 41205 }
db71a655 41206 return res;
d6651c21 41207 }
b135bf1a
IC
41208 }
41209
db71a655 41210 // Pick the first defined of two or three arguments.
c74a101d 41211
db71a655
KM
41212 function defineCommonLocaleTests(locale, options) {
41213 test('lenient day of month ordinal parsing', function (assert) {
41214 var i, ordinalStr, testMoment;
41215 for (i = 1; i <= 31; ++i) {
41216 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
41217 testMoment = moment(ordinalStr, 'YYYY MM Do');
41218 assert.equal(testMoment.year(), 2014,
41219 'lenient day of month ordinal parsing ' + i + ' year check');
41220 assert.equal(testMoment.month(), 0,
41221 'lenient day of month ordinal parsing ' + i + ' month check');
41222 assert.equal(testMoment.date(), i,
41223 'lenient day of month ordinal parsing ' + i + ' date check');
41224 }
41225 });
516f5f67 41226
db71a655
KM
41227 test('lenient day of month ordinal parsing of number', function (assert) {
41228 var i, testMoment;
41229 for (i = 1; i <= 31; ++i) {
41230 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
41231 assert.equal(testMoment.year(), 2014,
41232 'lenient day of month ordinal parsing of number ' + i + ' year check');
41233 assert.equal(testMoment.month(), 0,
41234 'lenient day of month ordinal parsing of number ' + i + ' month check');
41235 assert.equal(testMoment.date(), i,
41236 'lenient day of month ordinal parsing of number ' + i + ' date check');
41237 }
41238 });
516f5f67 41239
db71a655
KM
41240 test('strict day of month ordinal parsing', function (assert) {
41241 var i, ordinalStr, testMoment;
41242 for (i = 1; i <= 31; ++i) {
41243 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
41244 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
41245 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
41246 }
41247 });
516f5f67 41248
db71a655
KM
41249 test('meridiem invariant', function (assert) {
41250 var h, m, t1, t2;
41251 for (h = 0; h < 24; ++h) {
41252 for (m = 0; m < 60; m += 15) {
41253 t1 = moment.utc([2000, 0, 1, h, m]);
41254 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
41255 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
41256 'meridiem at ' + t1.format('HH:mm'));
41257 }
41258 }
41259 });
41260
41261 test('date format correctness', function (assert) {
41262 var data, tokens;
41263 data = moment.localeData()._longDateFormat;
41264 tokens = objectKeys(data);
41265 each(tokens, function (srchToken) {
41266 // Check each format string to make sure it does not contain any
41267 // tokens that need to be expanded.
41268 each(tokens, function (baseToken) {
41269 // strip escaped sequences
41270 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
41271 assert.equal(false, !!~format.indexOf(srchToken),
41272 'contains ' + srchToken + ' in ' + baseToken);
41273 });
73f3c911
IC
41274 });
41275 });
516f5f67 41276
db71a655
KM
41277 test('month parsing correctness', function (assert) {
41278 var i, m;
41279
41280 if (locale === 'tr') {
41281 // I can't fix it :(
c58511b9 41282 assert.expect(0);
db71a655
KM
41283 return;
41284 }
41285 function tester(format) {
41286 var r;
41287 r = moment(m.format(format), format);
41288 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
41289 if (locale !== 'ka') {
41290 r = moment(m.format(format).toLocaleUpperCase(), format);
41291 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
41292 }
db71a655
KM
41293 r = moment(m.format(format).toLocaleLowerCase(), format);
41294 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
41295
41296 r = moment(m.format(format), format, true);
41297 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
41298 if (locale !== 'ka') {
41299 r = moment(m.format(format).toLocaleUpperCase(), format, true);
41300 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
41301 }
db71a655
KM
41302 r = moment(m.format(format).toLocaleLowerCase(), format, true);
41303 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
41304 }
41305
41306 for (i = 0; i < 12; ++i) {
41307 m = moment([2015, i, 15, 18]);
41308 tester('MMM');
41309 tester('MMM.');
41310 tester('MMMM');
41311 tester('MMMM.');
41312 }
41313 });
b135bf1a 41314
db71a655
KM
41315 test('weekday parsing correctness', function (assert) {
41316 var i, m;
41317
96d0d679 41318 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
41319 // tr, az: There is a lower-case letter (ı), that converted to
41320 // upper then lower changes to i
41321 // ro: there is the letter ț which behaves weird under IE8
41322 // mt: letter Ħ
96d0d679 41323 // ga: month with spaces
c58511b9 41324 assert.expect(0);
db71a655
KM
41325 return;
41326 }
41327 function tester(format) {
41328 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
41329 r = moment(m.format(format), format);
41330 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
41331 if (locale !== 'ka') {
41332 r = moment(m.format(format).toLocaleUpperCase(), format);
41333 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
41334 }
db71a655
KM
41335 r = moment(m.format(format).toLocaleLowerCase(), format);
41336 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
41337 r = moment(m.format(format), format, true);
41338 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
41339 if (locale !== 'ka') {
41340 r = moment(m.format(format).toLocaleUpperCase(), format, true);
41341 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
41342 }
db71a655
KM
41343 r = moment(m.format(format).toLocaleLowerCase(), format, true);
41344 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
41345 }
41346
41347 for (i = 0; i < 7; ++i) {
41348 m = moment.utc([2015, 0, i + 1, 18]);
41349 tester('dd');
41350 tester('ddd');
41351 tester('dddd');
41352 }
41353 });
516f5f67 41354
db71a655
KM
41355 test('valid localeData', function (assert) {
41356 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
41357 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
41358 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
41359 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
41360 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
41361 });
96d0d679
KM
41362
41363 test('localeData weekdays can localeSort', function (assert) {
41364 var weekdays = moment().localeData().weekdays();
41365 var weekdaysShort = moment().localeData().weekdaysShort();
41366 var weekdaysMin = moment().localeData().weekdaysMin();
41367 var shift = moment().localeData()._week.dow;
41368 assert.deepEqual(
41369 moment().localeData().weekdays(true),
41370 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
41371 'weekdays should localeSort');
41372 assert.deepEqual(
41373 moment().localeData().weekdaysShort(true),
41374 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
41375 'weekdaysShort should localeSort');
41376 assert.deepEqual(
41377 moment().localeData().weekdaysMin(true),
41378 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
41379 'weekdaysMin should localeSort');
41380 });
db71a655 41381 }
c74a101d 41382
db71a655
KM
41383 /*global QUnit:false*/
41384
db71a655
KM
41385 function localeModule (name, lifecycle) {
41386 QUnit.module('locale:' + name, {
c58511b9 41387 beforeEach : function () {
db71a655
KM
41388 moment.locale(name);
41389 moment.createFromInputFallback = function (config) {
41390 throw new Error('input not handled by moment: ' + config._i);
41391 };
41392 setupDeprecationHandler(test, moment, 'locale');
41393 if (lifecycle && lifecycle.setup) {
41394 lifecycle.setup();
41395 }
41396 },
c58511b9 41397 afterEach : function () {
db71a655
KM
41398 moment.locale('en');
41399 teardownDeprecationHandler(test, moment, 'locale');
41400 if (lifecycle && lifecycle.teardown) {
41401 lifecycle.teardown();
41402 }
d6651c21
IC
41403 }
41404 });
db71a655
KM
41405 defineCommonLocaleTests(name, -1, -1);
41406 }
41407
41408 localeModule('ms');
41409
41410 test('parse', function (assert) {
41411 var i,
41412 tests = 'Januari Jan_Februari Feb_Mac Mac_April Apr_Mei Mei_Jun Jun_Julai Jul_Ogos Ogs_September Sep_Oktober Okt_November Nov_Disember Dis'.split('_');
41413
41414 function equalTest(input, mmm, i) {
41415 assert.equal(moment(input, mmm).month(), i, input + ' sepatutnya bulan ' + (i + 1));
41416 }
41417
41418 for (i = 0; i < 12; i++) {
41419 tests[i] = tests[i].split(' ');
41420 equalTest(tests[i][0], 'MMM', i);
41421 equalTest(tests[i][1], 'MMM', i);
41422 equalTest(tests[i][0], 'MMMM', i);
41423 equalTest(tests[i][1], 'MMMM', i);
41424 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
41425 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
41426 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
41427 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
41428 }
41429 });
41430
41431 test('format', function (assert) {
41432 var a = [
41433 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Ahad, Februari 14 2010, 3:25:50 petang'],
41434 ['ddd, hA', 'Ahd, 3petang'],
41435 ['M Mo MM MMMM MMM', '2 2 02 Februari Feb'],
41436 ['YYYY YY', '2010 10'],
41437 ['D Do DD', '14 14 14'],
41438 ['d do dddd ddd dd', '0 0 Ahad Ahd Ah'],
41439 ['DDD DDDo DDDD', '45 45 045'],
41440 ['w wo ww', '7 7 07'],
41441 ['h hh', '3 03'],
41442 ['H HH', '15 15'],
41443 ['m mm', '25 25'],
41444 ['s ss', '50 50'],
41445 ['a A', 'petang petang'],
41446 ['[hari] [ke] DDDo [tahun] ini', 'hari ke 45 tahun ini'],
41447 ['LTS', '15.25.50'],
41448 ['L', '14/02/2010'],
41449 ['LL', '14 Februari 2010'],
41450 ['LLL', '14 Februari 2010 pukul 15.25'],
41451 ['LLLL', 'Ahad, 14 Februari 2010 pukul 15.25'],
41452 ['l', '14/2/2010'],
41453 ['ll', '14 Feb 2010'],
41454 ['lll', '14 Feb 2010 pukul 15.25'],
41455 ['llll', 'Ahd, 14 Feb 2010 pukul 15.25']
41456 ],
41457 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
41458 i;
41459
41460 for (i = 0; i < a.length; i++) {
41461 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
41462 }
41463 });
41464
41465 test('format ordinal', function (assert) {
41466 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
41467 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
41468 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
41469 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
41470 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
41471 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
41472 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
41473 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
41474 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
41475 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
41476
41477 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
41478 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
41479 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
41480 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
41481 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
41482 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
41483 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
41484 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
41485 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
41486 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
41487
41488 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
41489 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
41490 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
41491 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
41492 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
41493 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
41494 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
41495 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
41496 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
41497 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
41498
41499 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
41500 });
41501
41502 test('format month', function (assert) {
41503 var i,
41504 expected = 'Januari Jan_Februari Feb_Mac Mac_April Apr_Mei Mei_Jun Jun_Julai Jul_Ogos Ogs_September Sep_Oktober Okt_November Nov_Disember Dis'.split('_');
41505
41506 for (i = 0; i < expected.length; i++) {
41507 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
41508 }
41509 });
41510
41511 test('format week', function (assert) {
41512 var i,
41513 expected = 'Ahad Ahd Ah_Isnin Isn Is_Selasa Sel Sl_Rabu Rab Rb_Khamis Kha Km_Jumaat Jum Jm_Sabtu Sab Sb'.split('_');
41514
41515 for (i = 0; i < expected.length; i++) {
41516 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
41517 }
41518 });
41519
41520 test('from', function (assert) {
41521 var start = moment([2007, 1, 28]);
41522
41523 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'beberapa saat', '44 saat = beberapa saat');
41524 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'seminit', '45 saat = seminit');
41525 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'seminit', '89 saat = seminit');
41526 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minit', '90 saat = 2 minit');
41527 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minit', '44 minit = 44 minit');
41528 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'sejam', '45 minit = sejam');
41529 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'sejam', '89 minit = sejam');
41530 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 jam', '90 minit = 2 jam');
41531 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 jam', '5 jam = 5 jam');
41532 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 jam', '21 jam = 21 jam');
41533 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'sehari', '22 jam = sehari');
41534 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'sehari', '35 jam = sehari');
41535 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 hari', '36 jam = 2 hari');
41536 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'sehari', '1 hari = sehari');
41537 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 hari', '5 hari = 5 hari');
41538 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 hari', '25 hari = 25 hari');
41539 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'sebulan', '26 hari = sebulan');
41540 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'sebulan', '30 hari = sebulan');
41541 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'sebulan', '45 hari = sebulan');
41542 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 bulan', '46 hari = 2 bulan');
41543 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 bulan', '75 hari = 2 bulan');
41544 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 bulan', '76 hari = 3 bulan');
41545 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'sebulan', '1 bulan = sebulan');
41546 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 bulan', '5 bulan = 5 bulan');
41547 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'setahun', '345 hari = setahun');
41548 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 tahun', '548 hari = 2 tahun');
41549 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'setahun', '1 tahun = setahun');
41550 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 tahun', '5 tahun = 5 tahun');
41551 });
41552
41553 test('suffix', function (assert) {
41554 assert.equal(moment(30000).from(0), 'dalam beberapa saat', 'prefix');
41555 assert.equal(moment(0).from(30000), 'beberapa saat yang lepas', 'suffix');
41556 });
41557
41558 test('now from now', function (assert) {
41559 assert.equal(moment().fromNow(), 'beberapa saat yang lepas', 'waktu sekarang dari sekarang sepatutnya menunjukkan sebagai telah lepas');
41560 });
41561
41562 test('fromNow', function (assert) {
41563 assert.equal(moment().add({s: 30}).fromNow(), 'dalam beberapa saat', 'dalam beberapa saat');
41564 assert.equal(moment().add({d: 5}).fromNow(), 'dalam 5 hari', 'dalam 5 hari');
41565 });
41566
41567 test('calendar day', function (assert) {
41568 var a = moment().hours(12).minutes(0).seconds(0);
41569
41570 assert.equal(moment(a).calendar(), 'Hari ini pukul 12.00', 'hari ini pada waktu yang sama');
41571 assert.equal(moment(a).add({m: 25}).calendar(), 'Hari ini pukul 12.25', 'Sekarang tambah 25 minit');
41572 assert.equal(moment(a).add({h: 1}).calendar(), 'Hari ini pukul 13.00', 'Sekarang tambah 1 jam');
41573 assert.equal(moment(a).add({d: 1}).calendar(), 'Esok pukul 12.00', 'esok pada waktu yang sama');
41574 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Hari ini pukul 11.00', 'Sekarang tolak 1 jam');
41575 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Kelmarin pukul 12.00', 'kelmarin pada waktu yang sama');
41576 });
41577
41578 test('calendar next week', function (assert) {
41579 var i, m;
41580 for (i = 2; i < 7; i++) {
41581 m = moment().add({d: i});
41582 assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Hari ini + ' + i + ' hari waktu sekarang');
41583 m.hours(0).minutes(0).seconds(0).milliseconds(0);
41584 assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Hari ini + ' + i + ' hari permulaan hari');
41585 m.hours(23).minutes(59).seconds(59).milliseconds(999);
41586 assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Hari ini + ' + i + ' hari tamat hari');
d6651c21 41587 }
db71a655 41588 });
d6651c21 41589
db71a655
KM
41590 test('calendar last week', function (assert) {
41591 var i, m;
41592 for (i = 2; i < 7; i++) {
41593 m = moment().subtract({d: i});
41594 assert.equal(m.calendar(), m.format('dddd [lepas] [pukul] LT'), 'Hari ini - ' + i + ' hari waktu sekarang');
41595 m.hours(0).minutes(0).seconds(0).milliseconds(0);
41596 assert.equal(m.calendar(), m.format('dddd [lepas] [pukul] LT'), 'Hari ini - ' + i + ' hari permulaan hari');
41597 m.hours(23).minutes(59).seconds(59).milliseconds(999);
41598 assert.equal(m.calendar(), m.format('dddd [lepas] [pukul] LT'), 'Hari ini - ' + i + ' hari tamat hari');
73f3c911 41599 }
db71a655 41600 });
516f5f67 41601
db71a655
KM
41602 test('calendar all else', function (assert) {
41603 var weeksAgo = moment().subtract({w: 1}),
41604 weeksFromNow = moment().add({w: 1});
c74a101d 41605
db71a655
KM
41606 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 minggu lepas');
41607 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'dalam 1 minggu');
516f5f67 41608
db71a655
KM
41609 weeksAgo = moment().subtract({w: 2});
41610 weeksFromNow = moment().add({w: 2});
c74a101d 41611
db71a655
KM
41612 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 minggu lepas');
41613 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'dalam 2 minggu');
41614 });
c74a101d 41615
db71a655
KM
41616 test('weeks year starting sunday format', function (assert) {
41617 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 sepatutnya minggu 1');
41618 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '2 02 2', 'Jan 7 2012 sepatutnya minggu 2');
41619 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 sepatutnya minggu 2');
41620 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '3 03 3', 'Jan 14 2012 sepatutnya minggu 3');
41621 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', 'Jan 15 2012 sepatutnya minggu 3');
41622 });
73f3c911
IC
41623
41624})));
c74a101d 41625
516f5f67 41626
c74a101d
IC
41627;(function (global, factory) {
41628 typeof exports === 'object' && typeof module !== 'undefined'
41629 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
41630 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
41631 factory(global.moment)
73f3c911 41632}(this, (function (moment) { 'use strict';
516f5f67 41633
db71a655
KM
41634 function each(array, callback) {
41635 var i;
41636 for (i = 0; i < array.length; i++) {
41637 callback(array[i], i, array);
b135bf1a 41638 }
b135bf1a 41639 }
b135bf1a 41640
c58511b9
KM
41641 function setupDeprecationHandler(test, moment$$1, scope) {
41642 test._expectedDeprecations = null;
41643 test._observedDeprecations = null;
41644 test._oldSupress = moment$$1.suppressDeprecationWarnings;
41645 moment$$1.suppressDeprecationWarnings = true;
41646 test.expectedDeprecations = function () {
41647 test._expectedDeprecations = arguments;
41648 test._observedDeprecations = [];
41649 };
41650 moment$$1.deprecationHandler = function (name, msg) {
41651 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
41652 if (deprecationId === -1) {
41653 throw new Error('Unexpected deprecation thrown name=' +
41654 name + ' msg=' + msg);
41655 }
41656 test._observedDeprecations[deprecationId] = 1;
41657 };
41658 }
41659
41660 function teardownDeprecationHandler(test, moment$$1, scope) {
41661 moment$$1.suppressDeprecationWarnings = test._oldSupress;
41662
41663 if (test._expectedDeprecations != null) {
41664 var missedDeprecations = [];
41665 each(test._expectedDeprecations, function (deprecationPattern, id) {
41666 if (test._observedDeprecations[id] !== 1) {
41667 missedDeprecations.push(deprecationPattern);
41668 }
41669 });
41670 if (missedDeprecations.length !== 0) {
41671 throw new Error('Expected deprecation warnings did not happen: ' +
41672 missedDeprecations.join(' '));
41673 }
41674 }
41675 }
41676
41677 function matchedDeprecation(name, msg, deprecations) {
41678 if (deprecations == null) {
41679 return -1;
41680 }
41681 for (var i = 0; i < deprecations.length; ++i) {
41682 if (name != null && name === deprecations[i]) {
41683 return i;
41684 }
41685 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
41686 return i;
41687 }
41688 }
41689 return -1;
41690 }
41691
41692 /*global QUnit:false*/
41693
41694 var test = QUnit.test;
41695
db71a655
KM
41696 function objectKeys(obj) {
41697 if (Object.keys) {
41698 return Object.keys(obj);
41699 } else {
41700 // IE8
41701 var res = [], i;
41702 for (i in obj) {
41703 if (obj.hasOwnProperty(i)) {
41704 res.push(i);
41705 }
41706 }
41707 return res;
73f3c911 41708 }
db71a655 41709 }
b135bf1a 41710
db71a655 41711 // Pick the first defined of two or three arguments.
b135bf1a 41712
db71a655
KM
41713 function defineCommonLocaleTests(locale, options) {
41714 test('lenient day of month ordinal parsing', function (assert) {
41715 var i, ordinalStr, testMoment;
41716 for (i = 1; i <= 31; ++i) {
41717 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
41718 testMoment = moment(ordinalStr, 'YYYY MM Do');
41719 assert.equal(testMoment.year(), 2014,
41720 'lenient day of month ordinal parsing ' + i + ' year check');
41721 assert.equal(testMoment.month(), 0,
41722 'lenient day of month ordinal parsing ' + i + ' month check');
41723 assert.equal(testMoment.date(), i,
41724 'lenient day of month ordinal parsing ' + i + ' date check');
41725 }
b135bf1a 41726 });
d6651c21 41727
db71a655
KM
41728 test('lenient day of month ordinal parsing of number', function (assert) {
41729 var i, testMoment;
41730 for (i = 1; i <= 31; ++i) {
41731 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
41732 assert.equal(testMoment.year(), 2014,
41733 'lenient day of month ordinal parsing of number ' + i + ' year check');
41734 assert.equal(testMoment.month(), 0,
41735 'lenient day of month ordinal parsing of number ' + i + ' month check');
41736 assert.equal(testMoment.date(), i,
41737 'lenient day of month ordinal parsing of number ' + i + ' date check');
41738 }
41739 });
d6651c21 41740
db71a655
KM
41741 test('strict day of month ordinal parsing', function (assert) {
41742 var i, ordinalStr, testMoment;
41743 for (i = 1; i <= 31; ++i) {
41744 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
41745 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
41746 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
41747 }
41748 });
d6651c21 41749
db71a655
KM
41750 test('meridiem invariant', function (assert) {
41751 var h, m, t1, t2;
41752 for (h = 0; h < 24; ++h) {
41753 for (m = 0; m < 60; m += 15) {
41754 t1 = moment.utc([2000, 0, 1, h, m]);
41755 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
41756 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
41757 'meridiem at ' + t1.format('HH:mm'));
41758 }
41759 }
41760 });
d6651c21 41761
db71a655
KM
41762 test('date format correctness', function (assert) {
41763 var data, tokens;
41764 data = moment.localeData()._longDateFormat;
41765 tokens = objectKeys(data);
41766 each(tokens, function (srchToken) {
41767 // Check each format string to make sure it does not contain any
41768 // tokens that need to be expanded.
41769 each(tokens, function (baseToken) {
41770 // strip escaped sequences
41771 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
41772 assert.equal(false, !!~format.indexOf(srchToken),
41773 'contains ' + srchToken + ' in ' + baseToken);
41774 });
41775 });
41776 });
73f3c911 41777
db71a655
KM
41778 test('month parsing correctness', function (assert) {
41779 var i, m;
41780
41781 if (locale === 'tr') {
41782 // I can't fix it :(
c58511b9 41783 assert.expect(0);
db71a655
KM
41784 return;
41785 }
41786 function tester(format) {
41787 var r;
41788 r = moment(m.format(format), format);
41789 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
41790 if (locale !== 'ka') {
41791 r = moment(m.format(format).toLocaleUpperCase(), format);
41792 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
41793 }
db71a655
KM
41794 r = moment(m.format(format).toLocaleLowerCase(), format);
41795 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
41796
41797 r = moment(m.format(format), format, true);
41798 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
41799 if (locale !== 'ka') {
41800 r = moment(m.format(format).toLocaleUpperCase(), format, true);
41801 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
41802 }
db71a655
KM
41803 r = moment(m.format(format).toLocaleLowerCase(), format, true);
41804 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
41805 }
41806
41807 for (i = 0; i < 12; ++i) {
41808 m = moment([2015, i, 15, 18]);
41809 tester('MMM');
41810 tester('MMM.');
41811 tester('MMMM');
41812 tester('MMMM.');
41813 }
41814 });
d6651c21 41815
db71a655
KM
41816 test('weekday parsing correctness', function (assert) {
41817 var i, m;
41818
96d0d679 41819 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
41820 // tr, az: There is a lower-case letter (ı), that converted to
41821 // upper then lower changes to i
41822 // ro: there is the letter ț which behaves weird under IE8
41823 // mt: letter Ħ
96d0d679 41824 // ga: month with spaces
c58511b9 41825 assert.expect(0);
db71a655
KM
41826 return;
41827 }
41828 function tester(format) {
41829 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
41830 r = moment(m.format(format), format);
41831 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
41832 if (locale !== 'ka') {
41833 r = moment(m.format(format).toLocaleUpperCase(), format);
41834 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
41835 }
db71a655
KM
41836 r = moment(m.format(format).toLocaleLowerCase(), format);
41837 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
41838 r = moment(m.format(format), format, true);
41839 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
41840 if (locale !== 'ka') {
41841 r = moment(m.format(format).toLocaleUpperCase(), format, true);
41842 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
41843 }
db71a655
KM
41844 r = moment(m.format(format).toLocaleLowerCase(), format, true);
41845 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
41846 }
41847
41848 for (i = 0; i < 7; ++i) {
41849 m = moment.utc([2015, 0, i + 1, 18]);
41850 tester('dd');
41851 tester('ddd');
41852 tester('dddd');
41853 }
41854 });
b135bf1a 41855
db71a655
KM
41856 test('valid localeData', function (assert) {
41857 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
41858 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
41859 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
41860 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
41861 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
41862 });
96d0d679
KM
41863
41864 test('localeData weekdays can localeSort', function (assert) {
41865 var weekdays = moment().localeData().weekdays();
41866 var weekdaysShort = moment().localeData().weekdaysShort();
41867 var weekdaysMin = moment().localeData().weekdaysMin();
41868 var shift = moment().localeData()._week.dow;
41869 assert.deepEqual(
41870 moment().localeData().weekdays(true),
41871 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
41872 'weekdays should localeSort');
41873 assert.deepEqual(
41874 moment().localeData().weekdaysShort(true),
41875 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
41876 'weekdaysShort should localeSort');
41877 assert.deepEqual(
41878 moment().localeData().weekdaysMin(true),
41879 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
41880 'weekdaysMin should localeSort');
41881 });
db71a655
KM
41882 }
41883
db71a655 41884 /*global QUnit:false*/
516f5f67 41885
db71a655
KM
41886 function localeModule (name, lifecycle) {
41887 QUnit.module('locale:' + name, {
c58511b9 41888 beforeEach : function () {
db71a655
KM
41889 moment.locale(name);
41890 moment.createFromInputFallback = function (config) {
41891 throw new Error('input not handled by moment: ' + config._i);
41892 };
41893 setupDeprecationHandler(test, moment, 'locale');
41894 if (lifecycle && lifecycle.setup) {
41895 lifecycle.setup();
41896 }
41897 },
c58511b9 41898 afterEach : function () {
db71a655
KM
41899 moment.locale('en');
41900 teardownDeprecationHandler(test, moment, 'locale');
41901 if (lifecycle && lifecycle.teardown) {
41902 lifecycle.teardown();
41903 }
73f3c911 41904 }
db71a655
KM
41905 });
41906 defineCommonLocaleTests(name, -1, -1);
41907 }
41908
41909 localeModule('mt');
41910
41911 test('parse', function (assert) {
41912 var tests = 'Jannar Jan_Frar Fra_Marzu Mar_April Apr_Mejju Mej_Ġunju Ġun_Lulju Lul_Awwissu Aww_Settembru Set_Ottubru Ott_Novembru Nov_Diċembru Diċ'.split('_'), i;
41913 function equalTest(input, mmm, i) {
41914 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
41915 }
41916 for (i = 0; i < 12; i++) {
41917 tests[i] = tests[i].split(' ');
41918 equalTest(tests[i][0], 'MMM', i);
41919 equalTest(tests[i][1], 'MMM', i);
41920 equalTest(tests[i][0], 'MMMM', i);
41921 equalTest(tests[i][1], 'MMMM', i);
41922 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
41923 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
41924 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
41925 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
41926 }
41927 });
41928
41929 test('format', function (assert) {
41930 var a = [
41931 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Il-Ħadd, Frar 14º 2010, 3:25:50 pm'],
41932 ['ddd, hA', 'Ħad, 3PM'],
41933 ['M Mo MM MMMM MMM', '2 2º 02 Frar Fra'],
41934 ['YYYY YY', '2010 10'],
41935 ['D Do DD', '14 14º 14'],
41936 ['d do dddd ddd dd', '0 0º Il-Ħadd Ħad Ħa'],
41937 ['DDD DDDo DDDD', '45 45º 045'],
41938 ['w wo ww', '6 6º 06'],
41939 ['h hh', '3 03'],
41940 ['H HH', '15 15'],
41941 ['m mm', '25 25'],
41942 ['s ss', '50 50'],
41943 ['a A', 'pm PM'],
41944 ['[the] DDDo [day of the year]', 'the 45º day of the year'],
41945 ['LTS', '15:25:50'],
41946 ['L', '14/02/2010'],
41947 ['LL', '14 Frar 2010'],
41948 ['LLL', '14 Frar 2010 15:25'],
41949 ['LLLL', 'Il-Ħadd, 14 Frar 2010 15:25'],
41950 ['l', '14/2/2010'],
41951 ['ll', '14 Fra 2010'],
41952 ['lll', '14 Fra 2010 15:25'],
41953 ['llll', 'Ħad, 14 Fra 2010 15:25']
41954 ],
41955 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
41956 i;
41957 for (i = 0; i < a.length; i++) {
41958 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
41959 }
41960 });
41961
41962 test('format ordinal', function (assert) {
41963 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1º', '1º');
41964 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2º', '2º');
41965 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3º', '3º');
41966 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4º', '4º');
41967 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5º', '5º');
41968 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6º', '6º');
41969 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7º', '7º');
41970 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8º', '8º');
41971 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9º', '9º');
41972 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10º', '10º');
41973
41974 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11º', '11º');
41975 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12º', '12º');
41976 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13º', '13º');
41977 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14º', '14º');
41978 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15º', '15º');
41979 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16º', '16º');
41980 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17º', '17º');
41981 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18º', '18º');
41982 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19º', '19º');
41983 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20º', '20º');
41984
41985 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21º', '21º');
41986 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22º', '22º');
41987 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23º', '23º');
41988 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24º', '24º');
41989 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25º', '25º');
41990 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26º', '26º');
41991 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27º', '27º');
41992 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28º', '28º');
41993 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29º', '29º');
41994 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30º', '30º');
41995
41996 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31º', '31º');
41997 });
41998
41999 test('format month', function (assert) {
42000 var expected = 'Jannar Jan_Frar Fra_Marzu Mar_April Apr_Mejju Mej_Ġunju Ġun_Lulju Lul_Awwissu Aww_Settembru Set_Ottubru Ott_Novembru Nov_Diċembru Diċ'.split('_'), i;
42001 for (i = 0; i < expected.length; i++) {
42002 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
42003 }
42004 });
42005
42006 test('format week', function (assert) {
42007 var expected = 'Il-Ħadd Ħad Ħa_It-Tnejn Tne Tn_It-Tlieta Tli Tl_L-Erbgħa Erb Er_Il-Ħamis Ħam Ħa_Il-Ġimgħa Ġim Ġi_Is-Sibt Sib Si'.split('_'), i;
42008 for (i = 0; i < expected.length; i++) {
42009 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
42010 }
42011 });
42012
42013 test('from', function (assert) {
42014 var start = moment([2007, 1, 28]);
42015 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ftit sekondi', '44 seconds = a few seconds');
42016 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minuta', '45 seconds = a minute');
42017 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minuta', '89 seconds = a minute');
42018 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuti', '90 seconds = 2 minutes');
42019 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuti', '44 minutes = 44 minutes');
42020 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'siegħa', '45 minutes = an hour');
42021 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'siegħa', '89 minutes = an hour');
42022 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 siegħat', '90 minutes = 2 hours');
42023 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 siegħat', '5 hours = 5 hours');
42024 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 siegħat', '21 hours = 21 hours');
42025 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ġurnata', '22 hours = a day');
42026 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ġurnata', '35 hours = a day');
42027 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 ġranet', '36 hours = 2 days');
42028 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ġurnata', '1 day = a day');
42029 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ġranet', '5 days = 5 days');
42030 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ġranet', '25 days = 25 days');
42031 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'xahar', '26 days = a month');
42032 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'xahar', '30 days = a month');
42033 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'xahar', '43 days = a month');
42034 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 xhur', '46 days = 2 months');
42035 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 xhur', '75 days = 2 months');
42036 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 xhur', '76 days = 3 months');
42037 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'xahar', '1 month = a month');
42038 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 xhur', '5 months = 5 months');
42039 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'sena', '345 days = a year');
42040 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 sni', '548 days = 2 years');
42041 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'sena', '1 year = a year');
42042 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 sni', '5 years = 5 years');
42043 });
42044
42045 test('suffix', function (assert) {
42046 assert.equal(moment(30000).from(0), 'f’ ftit sekondi', 'prefix');
42047 assert.equal(moment(0).from(30000), 'ftit sekondi ilu', 'suffix');
42048 });
42049
42050 test('now from now', function (assert) {
42051 assert.equal(moment().fromNow(), 'ftit sekondi ilu', 'now from now should display as in the past');
42052 });
42053
42054 test('fromNow', function (assert) {
42055 assert.equal(moment().add({s: 30}).fromNow(), 'f’ ftit sekondi', 'in a few seconds');
42056 assert.equal(moment().add({d: 5}).fromNow(), 'f’ 5 ġranet', 'in 5 days');
42057 });
42058
42059 test('calendar day', function (assert) {
42060 var a = moment().hours(12).minutes(0).seconds(0);
42061
42062 assert.equal(moment(a).calendar(), 'Illum fil-12:00', 'today at the same time');
42063 assert.equal(moment(a).add({m: 25}).calendar(), 'Illum fil-12:25', 'Now plus 25 min');
42064 assert.equal(moment(a).add({h: 1}).calendar(), 'Illum fil-13:00', 'Now plus 1 hour');
42065 assert.equal(moment(a).add({d: 1}).calendar(), 'Għada fil-12:00', 'tomorrow at the same time');
42066 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Illum fil-11:00', 'Now minus 1 hour');
42067 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Il-bieraħ fil-12:00', 'yesterday at the same time');
42068 });
42069
42070 test('calendar next week', function (assert) {
42071 var i, m;
42072 for (i = 2; i < 7; i++) {
42073 m = moment().add({d: i});
42074 assert.equal(m.calendar(), m.format('dddd [fil-]LT'), 'Today + ' + i + ' days current time');
42075 m.hours(0).minutes(0).seconds(0).milliseconds(0);
42076 assert.equal(m.calendar(), m.format('dddd [fil-]LT'), 'Today + ' + i + ' days beginning of day');
42077 m.hours(23).minutes(59).seconds(59).milliseconds(999);
42078 assert.equal(m.calendar(), m.format('dddd [fil-]LT'), 'Today + ' + i + ' days end of day');
42079 }
42080 });
42081
42082 test('calendar last week', function (assert) {
42083 var i, m;
42084
42085 for (i = 2; i < 7; i++) {
42086 m = moment().subtract({d: i});
42087 assert.equal(m.calendar(), m.format('dddd [li għadda] [fil-]LT'), 'Today - ' + i + ' days current time');
42088 m.hours(0).minutes(0).seconds(0).milliseconds(0);
42089 assert.equal(m.calendar(), m.format('dddd [li għadda] [fil-]LT'), 'Today - ' + i + ' days beginning of day');
42090 m.hours(23).minutes(59).seconds(59).milliseconds(999);
42091 assert.equal(m.calendar(), m.format('dddd [li għadda] [fil-]LT'), 'Today - ' + i + ' days end of day');
42092 }
42093 });
42094
42095 test('calendar all else', function (assert) {
42096 var weeksAgo = moment().subtract({w: 1}),
42097 weeksFromNow = moment().add({w: 1});
42098
42099 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
42100 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
42101
42102 weeksAgo = moment().subtract({w: 2});
42103 weeksFromNow = moment().add({w: 2});
42104
42105 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
42106 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
42107 });
42108
42109 test('weeks year starting sunday formatted', function (assert) {
42110 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52º', 'Jan 1 2012 should be week 52');
42111 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1º', 'Jan 2 2012 should be week 1');
42112 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1º', 'Jan 8 2012 should be week 1');
42113 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2º', 'Jan 9 2012 should be week 2');
42114 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2º', 'Jan 15 2012 should be week 2');
42115 });
73f3c911
IC
42116
42117})));
42118
516f5f67 42119
c74a101d
IC
42120;(function (global, factory) {
42121 typeof exports === 'object' && typeof module !== 'undefined'
42122 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
42123 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
42124 factory(global.moment)
73f3c911 42125}(this, (function (moment) { 'use strict';
516f5f67 42126
db71a655
KM
42127 function each(array, callback) {
42128 var i;
42129 for (i = 0; i < array.length; i++) {
42130 callback(array[i], i, array);
42131 }
b135bf1a
IC
42132 }
42133
c58511b9
KM
42134 function setupDeprecationHandler(test, moment$$1, scope) {
42135 test._expectedDeprecations = null;
42136 test._observedDeprecations = null;
42137 test._oldSupress = moment$$1.suppressDeprecationWarnings;
42138 moment$$1.suppressDeprecationWarnings = true;
42139 test.expectedDeprecations = function () {
42140 test._expectedDeprecations = arguments;
42141 test._observedDeprecations = [];
42142 };
42143 moment$$1.deprecationHandler = function (name, msg) {
42144 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
42145 if (deprecationId === -1) {
42146 throw new Error('Unexpected deprecation thrown name=' +
42147 name + ' msg=' + msg);
42148 }
42149 test._observedDeprecations[deprecationId] = 1;
42150 };
42151 }
42152
42153 function teardownDeprecationHandler(test, moment$$1, scope) {
42154 moment$$1.suppressDeprecationWarnings = test._oldSupress;
42155
42156 if (test._expectedDeprecations != null) {
42157 var missedDeprecations = [];
42158 each(test._expectedDeprecations, function (deprecationPattern, id) {
42159 if (test._observedDeprecations[id] !== 1) {
42160 missedDeprecations.push(deprecationPattern);
42161 }
42162 });
42163 if (missedDeprecations.length !== 0) {
42164 throw new Error('Expected deprecation warnings did not happen: ' +
42165 missedDeprecations.join(' '));
42166 }
42167 }
42168 }
42169
42170 function matchedDeprecation(name, msg, deprecations) {
42171 if (deprecations == null) {
42172 return -1;
42173 }
42174 for (var i = 0; i < deprecations.length; ++i) {
42175 if (name != null && name === deprecations[i]) {
42176 return i;
42177 }
42178 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
42179 return i;
42180 }
42181 }
42182 return -1;
42183 }
42184
42185 /*global QUnit:false*/
42186
42187 var test = QUnit.test;
42188
db71a655
KM
42189 function objectKeys(obj) {
42190 if (Object.keys) {
42191 return Object.keys(obj);
42192 } else {
42193 // IE8
42194 var res = [], i;
42195 for (i in obj) {
42196 if (obj.hasOwnProperty(i)) {
42197 res.push(i);
42198 }
b135bf1a 42199 }
db71a655 42200 return res;
b135bf1a
IC
42201 }
42202 }
73f3c911 42203
db71a655 42204 // Pick the first defined of two or three arguments.
b135bf1a 42205
db71a655
KM
42206 function defineCommonLocaleTests(locale, options) {
42207 test('lenient day of month ordinal parsing', function (assert) {
42208 var i, ordinalStr, testMoment;
42209 for (i = 1; i <= 31; ++i) {
42210 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
42211 testMoment = moment(ordinalStr, 'YYYY MM Do');
42212 assert.equal(testMoment.year(), 2014,
42213 'lenient day of month ordinal parsing ' + i + ' year check');
42214 assert.equal(testMoment.month(), 0,
42215 'lenient day of month ordinal parsing ' + i + ' month check');
42216 assert.equal(testMoment.date(), i,
42217 'lenient day of month ordinal parsing ' + i + ' date check');
42218 }
42219 });
b135bf1a 42220
db71a655
KM
42221 test('lenient day of month ordinal parsing of number', function (assert) {
42222 var i, testMoment;
42223 for (i = 1; i <= 31; ++i) {
42224 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
42225 assert.equal(testMoment.year(), 2014,
42226 'lenient day of month ordinal parsing of number ' + i + ' year check');
42227 assert.equal(testMoment.month(), 0,
42228 'lenient day of month ordinal parsing of number ' + i + ' month check');
42229 assert.equal(testMoment.date(), i,
42230 'lenient day of month ordinal parsing of number ' + i + ' date check');
42231 }
b135bf1a
IC
42232 });
42233
db71a655
KM
42234 test('strict day of month ordinal parsing', function (assert) {
42235 var i, ordinalStr, testMoment;
42236 for (i = 1; i <= 31; ++i) {
42237 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
42238 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
42239 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
42240 }
42241 });
b135bf1a 42242
db71a655
KM
42243 test('meridiem invariant', function (assert) {
42244 var h, m, t1, t2;
42245 for (h = 0; h < 24; ++h) {
42246 for (m = 0; m < 60; m += 15) {
42247 t1 = moment.utc([2000, 0, 1, h, m]);
42248 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
42249 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
42250 'meridiem at ' + t1.format('HH:mm'));
42251 }
42252 }
42253 });
b135bf1a 42254
db71a655
KM
42255 test('date format correctness', function (assert) {
42256 var data, tokens;
42257 data = moment.localeData()._longDateFormat;
42258 tokens = objectKeys(data);
42259 each(tokens, function (srchToken) {
42260 // Check each format string to make sure it does not contain any
42261 // tokens that need to be expanded.
42262 each(tokens, function (baseToken) {
42263 // strip escaped sequences
42264 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
42265 assert.equal(false, !!~format.indexOf(srchToken),
42266 'contains ' + srchToken + ' in ' + baseToken);
42267 });
42268 });
42269 });
d6651c21 42270
db71a655
KM
42271 test('month parsing correctness', function (assert) {
42272 var i, m;
42273
42274 if (locale === 'tr') {
42275 // I can't fix it :(
c58511b9 42276 assert.expect(0);
db71a655
KM
42277 return;
42278 }
42279 function tester(format) {
42280 var r;
42281 r = moment(m.format(format), format);
42282 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
42283 if (locale !== 'ka') {
42284 r = moment(m.format(format).toLocaleUpperCase(), format);
42285 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
42286 }
db71a655
KM
42287 r = moment(m.format(format).toLocaleLowerCase(), format);
42288 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
42289
42290 r = moment(m.format(format), format, true);
42291 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
42292 if (locale !== 'ka') {
42293 r = moment(m.format(format).toLocaleUpperCase(), format, true);
42294 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
42295 }
db71a655
KM
42296 r = moment(m.format(format).toLocaleLowerCase(), format, true);
42297 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
42298 }
42299
42300 for (i = 0; i < 12; ++i) {
42301 m = moment([2015, i, 15, 18]);
42302 tester('MMM');
42303 tester('MMM.');
42304 tester('MMMM');
42305 tester('MMMM.');
42306 }
42307 });
d6651c21 42308
db71a655
KM
42309 test('weekday parsing correctness', function (assert) {
42310 var i, m;
42311
96d0d679 42312 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
42313 // tr, az: There is a lower-case letter (ı), that converted to
42314 // upper then lower changes to i
42315 // ro: there is the letter ț which behaves weird under IE8
42316 // mt: letter Ħ
96d0d679 42317 // ga: month with spaces
c58511b9 42318 assert.expect(0);
db71a655
KM
42319 return;
42320 }
42321 function tester(format) {
42322 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
42323 r = moment(m.format(format), format);
42324 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
42325 if (locale !== 'ka') {
42326 r = moment(m.format(format).toLocaleUpperCase(), format);
42327 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
42328 }
db71a655
KM
42329 r = moment(m.format(format).toLocaleLowerCase(), format);
42330 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
42331 r = moment(m.format(format), format, true);
42332 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
42333 if (locale !== 'ka') {
42334 r = moment(m.format(format).toLocaleUpperCase(), format, true);
42335 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
42336 }
db71a655
KM
42337 r = moment(m.format(format).toLocaleLowerCase(), format, true);
42338 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
42339 }
42340
42341 for (i = 0; i < 7; ++i) {
42342 m = moment.utc([2015, 0, i + 1, 18]);
42343 tester('dd');
42344 tester('ddd');
42345 tester('dddd');
42346 }
42347 });
d6651c21 42348
db71a655
KM
42349 test('valid localeData', function (assert) {
42350 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
42351 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
42352 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
42353 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
42354 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
42355 });
96d0d679
KM
42356
42357 test('localeData weekdays can localeSort', function (assert) {
42358 var weekdays = moment().localeData().weekdays();
42359 var weekdaysShort = moment().localeData().weekdaysShort();
42360 var weekdaysMin = moment().localeData().weekdaysMin();
42361 var shift = moment().localeData()._week.dow;
42362 assert.deepEqual(
42363 moment().localeData().weekdays(true),
42364 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
42365 'weekdays should localeSort');
42366 assert.deepEqual(
42367 moment().localeData().weekdaysShort(true),
42368 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
42369 'weekdaysShort should localeSort');
42370 assert.deepEqual(
42371 moment().localeData().weekdaysMin(true),
42372 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
42373 'weekdaysMin should localeSort');
42374 });
db71a655 42375 }
d6651c21 42376
db71a655 42377 /*global QUnit:false*/
516f5f67 42378
db71a655
KM
42379 function localeModule (name, lifecycle) {
42380 QUnit.module('locale:' + name, {
c58511b9 42381 beforeEach : function () {
db71a655
KM
42382 moment.locale(name);
42383 moment.createFromInputFallback = function (config) {
42384 throw new Error('input not handled by moment: ' + config._i);
42385 };
42386 setupDeprecationHandler(test, moment, 'locale');
42387 if (lifecycle && lifecycle.setup) {
42388 lifecycle.setup();
42389 }
42390 },
c58511b9 42391 afterEach : function () {
db71a655
KM
42392 moment.locale('en');
42393 teardownDeprecationHandler(test, moment, 'locale');
42394 if (lifecycle && lifecycle.teardown) {
42395 lifecycle.teardown();
42396 }
516f5f67 42397 }
db71a655
KM
42398 });
42399 defineCommonLocaleTests(name, -1, -1);
42400 }
42401
42402 localeModule('my');
42403
42404 test('parse', function (assert) {
42405 var tests = 'ဇန်နဝါရီ ဇန်_ဖေဖော်ဝါရီ ဖေ_မတ် မတ်_ဧပြီ ပြီ_မေ မေ_ဇွန် ဇွန်_ဇူလိုင် လိုင်_သြဂုတ် သြ_စက်တင်ဘာ စက်_အောက်တိုဘာ အောက်_နိုဝင်ဘာ နို_ဒီဇင်ဘာ ဒီ'.split('_'),
42406 i;
42407
42408 function equalTest (input, mmm, i) {
42409 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
42410 }
42411 for (i = 0; i < 12; i++) {
42412 tests[i] = tests[i].split(' ');
42413 equalTest(tests[i][0], 'MMM', i);
42414 equalTest(tests[i][1], 'MMM', i);
42415 equalTest(tests[i][0], 'MMMM', i);
42416 equalTest(tests[i][1], 'MMMM', i);
42417 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
42418 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
42419 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
42420 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
42421 }
42422 });
42423
42424 test('format', function (assert) {
42425 var a = [
42426 ['dddd, MMMM Do YYYY, h:mm:ss a', 'တနင်္ဂနွေ, ဖေဖော်ဝါရီ ၁၄ ၂၀၁၀, ၃:၂၅:၅၀ pm'],
42427 ['ddd, hA', 'နွေ, ၃PM'],
42428 ['M Mo MM MMMM MMM', '၂ ၂ ၀၂ ဖေဖော်ဝါရီ ဖေ'],
42429 ['YYYY YY', '၂၀၁၀ ၁၀'],
42430 ['D Do DD', '၁၄ ၁၄ ၁၄'],
42431 ['d do dddd ddd dd', '၀ ၀ တနင်္ဂနွေ နွေ နွေ'],
42432 ['DDD DDDo DDDD', '၄၅ ၄၅ ၀၄၅'],
42433 ['w wo ww', '၆ ၆ ၀၆'],
42434 ['h hh', '၃ ၀၃'],
42435 ['H HH', '၁၅ ၁၅'],
42436 ['m mm', '၂၅ ၂၅'],
42437 ['s ss', '၅၀ ၅၀'],
42438 ['a A', 'pm PM'],
42439 ['[နှစ်၏] DDDo [ရက်မြောက်]', 'နှစ်၏ ၄၅ ရက်မြောက်'],
42440 ['LTS', '၁၅:၂၅:၅၀'],
42441 ['L', '၁၄/၀၂/၂၀၁၀'],
42442 ['LL', '၁၄ ဖေဖော်ဝါရီ ၂၀၁၀'],
42443 ['LLL', '၁၄ ဖေဖော်ဝါရီ ၂၀၁၀ ၁၅:၂၅'],
42444 ['LLLL', 'တနင်္ဂနွေ ၁၄ ဖေဖော်ဝါရီ ၂၀၁၀ ၁၅:၂၅'],
42445 ['l', '၁၄/၂/၂၀၁၀'],
42446 ['ll', '၁၄ ဖေ ၂၀၁၀'],
42447 ['lll', '၁၄ ဖေ ၂၀၁၀ ၁၅:၂၅'],
42448 ['llll', 'နွေ ၁၄ ဖေ ၂၀၁၀ ၁၅:၂၅']
42449 ],
42450 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
42451 i;
42452 for (i = 0; i < a.length; i++) {
42453 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
42454 }
42455 });
42456
42457 test('format ordinal', function (assert) {
42458 assert.equal(moment([2011, 0, 1]).format('DDDo'), '၁', '၁');
42459 assert.equal(moment([2011, 0, 2]).format('DDDo'), '၂', '၂');
42460 assert.equal(moment([2011, 0, 3]).format('DDDo'), '၃', '၃');
42461 assert.equal(moment([2011, 0, 4]).format('DDDo'), '၄', '၄');
42462 assert.equal(moment([2011, 0, 5]).format('DDDo'), '၅', '၅');
42463 assert.equal(moment([2011, 0, 6]).format('DDDo'), '၆', '၆');
42464 assert.equal(moment([2011, 0, 7]).format('DDDo'), '၇', '၇');
42465 assert.equal(moment([2011, 0, 8]).format('DDDo'), '၈', '၈');
42466 assert.equal(moment([2011, 0, 9]).format('DDDo'), '၉', '၉');
42467 assert.equal(moment([2011, 0, 10]).format('DDDo'), '၁၀', '၁၀');
42468
42469 assert.equal(moment([2011, 0, 11]).format('DDDo'), '၁၁', '၁၁');
42470 assert.equal(moment([2011, 0, 12]).format('DDDo'), '၁၂', '၁၂');
42471 assert.equal(moment([2011, 0, 13]).format('DDDo'), '၁၃', '၁၃');
42472 assert.equal(moment([2011, 0, 14]).format('DDDo'), '၁၄', '၁၄');
42473 assert.equal(moment([2011, 0, 15]).format('DDDo'), '၁၅', '၁၅');
42474 assert.equal(moment([2011, 0, 16]).format('DDDo'), '၁၆', '၁၆');
42475 assert.equal(moment([2011, 0, 17]).format('DDDo'), '၁၇', '၁၇');
42476 assert.equal(moment([2011, 0, 18]).format('DDDo'), '၁၈', '၁၈');
42477 assert.equal(moment([2011, 0, 19]).format('DDDo'), '၁၉', '၁၉');
42478 assert.equal(moment([2011, 0, 20]).format('DDDo'), '၂၀', '၂၀');
42479
42480 assert.equal(moment([2011, 0, 21]).format('DDDo'), '၂၁', '၂၁');
42481 assert.equal(moment([2011, 0, 22]).format('DDDo'), '၂၂', '၂၂');
42482 assert.equal(moment([2011, 0, 23]).format('DDDo'), '၂၃', '၂၃');
42483 assert.equal(moment([2011, 0, 24]).format('DDDo'), '၂၄', '၂၄');
42484 assert.equal(moment([2011, 0, 25]).format('DDDo'), '၂၅', '၂၅');
42485 assert.equal(moment([2011, 0, 26]).format('DDDo'), '၂၆', '၂၆');
42486 assert.equal(moment([2011, 0, 27]).format('DDDo'), '၂၇', '၂၇');
42487 assert.equal(moment([2011, 0, 28]).format('DDDo'), '၂၈', '၂၈');
42488 assert.equal(moment([2011, 0, 29]).format('DDDo'), '၂၉', '၂၉');
42489 assert.equal(moment([2011, 0, 30]).format('DDDo'), '၃၀', '၃၀');
42490
42491 assert.equal(moment([2011, 0, 31]).format('DDDo'), '၃၁', '၃၁');
42492 });
42493
42494 test('format month', function (assert) {
42495 var expected = 'ဇန်နဝါရီ ဇန်_ဖေဖော်ဝါရီ ဖေ_မတ် မတ်_ဧပြီ ပြီ_မေ မေ_ဇွန် ဇွန်_ဇူလိုင် လိုင်_သြဂုတ် သြ_စက်တင်ဘာ စက်_အောက်တိုဘာ အောက်_နိုဝင်ဘာ နို_ဒီဇင်ဘာ ဒီ'.split('_'),
42496 i;
42497 for (i = 0; i < expected.length; i++) {
42498 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
42499 }
42500 });
42501
42502 test('format week', function (assert) {
42503 var expected = 'တနင်္ဂနွေ နွေ နွေ_တနင်္လာ လာ လာ_အင်္ဂါ ဂါ ဂါ_ဗုဒ္ဓဟူး ဟူး ဟူး_ကြာသပတေး ကြာ ကြာ_သောကြာ သော သော_စနေ နေ နေ'.split('_'),
42504 i;
42505
42506 for (i = 0; i < expected.length; i++) {
42507 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
42508 }
42509 });
42510
42511 test('from', function (assert) {
42512 var start = moment([2007, 1, 28]);
42513 assert.equal(start.from(moment([2007, 1, 28]).add({
42514 s: 44
42515 }), true), 'စက္ကန်.အနည်းငယ်', '၄၄ စက္ကန်. = စက္ကန်.အနည်းငယ်');
42516 assert.equal(start.from(moment([2007, 1, 28]).add({
42517 s: 45
42518 }), true), 'တစ်မိနစ်', '၄၅ စက္ကန်. = တစ်မိနစ်');
42519 assert.equal(start.from(moment([2007, 1, 28]).add({
42520 s: 89
42521 }), true), 'တစ်မိနစ်', '၈၉ စက္ကန်. = တစ်မိနစ်');
42522 assert.equal(start.from(moment([2007, 1, 28]).add({
42523 s: 90
42524 }), true), '၂ မိနစ်', '၉၀ စက္ကန်. = ၂ မိနစ်');
42525 assert.equal(start.from(moment([2007, 1, 28]).add({
42526 m: 44
42527 }), true), '၄၄ မိနစ်', '၄၄ မိနစ် = ၄၄ မိနစ်');
42528 assert.equal(start.from(moment([2007, 1, 28]).add({
42529 m: 45
42530 }), true), 'တစ်နာရီ', '၄၅ မိနစ် = ၁ နာရီ');
42531 assert.equal(start.from(moment([2007, 1, 28]).add({
42532 m: 89
42533 }), true), 'တစ်နာရီ', '၈၉ မိနစ် = တစ်နာရီ');
42534 assert.equal(start.from(moment([2007, 1, 28]).add({
42535 m: 90
42536 }), true), '၂ နာရီ', 'မိနစ် ၉၀= ၂ နာရီ');
42537 assert.equal(start.from(moment([2007, 1, 28]).add({
42538 h: 5
42539 }), true), '၅ နာရီ', '၅ နာရီ= ၅ နာရီ');
42540 assert.equal(start.from(moment([2007, 1, 28]).add({
42541 h: 21
42542 }), true), '၂၁ နာရီ', '၂၁ နာရီ =၂၁ နာရီ');
42543 assert.equal(start.from(moment([2007, 1, 28]).add({
42544 h: 22
42545 }), true), 'တစ်ရက်', '၂၂ နာရီ =တစ်ရက်');
42546 assert.equal(start.from(moment([2007, 1, 28]).add({
42547 h: 35
42548 }), true), 'တစ်ရက်', '၃၅ နာရီ =တစ်ရက်');
42549 assert.equal(start.from(moment([2007, 1, 28]).add({
42550 h: 36
42551 }), true), '၂ ရက်', '၃၆ နာရီ = ၂ ရက်');
42552 assert.equal(start.from(moment([2007, 1, 28]).add({
42553 d: 1
42554 }), true), 'တစ်ရက်', '၁ ရက်= တစ်ရက်');
42555 assert.equal(start.from(moment([2007, 1, 28]).add({
42556 d: 5
42557 }), true), '၅ ရက်', '၅ ရက် = ၅ ရက်');
42558 assert.equal(start.from(moment([2007, 1, 28]).add({
42559 d: 25
42560 }), true), '၂၅ ရက်', '၂၅ ရက်= ၂၅ ရက်');
42561 assert.equal(start.from(moment([2007, 1, 28]).add({
42562 d: 26
42563 }), true), 'တစ်လ', '၂၆ ရက် = တစ်လ');
42564 assert.equal(start.from(moment([2007, 1, 28]).add({
42565 d: 30
42566 }), true), 'တစ်လ', 'ရက် ၃၀ = တစ်လ');
42567 assert.equal(start.from(moment([2007, 1, 28]).add({
42568 d: 43
42569 }), true), 'တစ်လ', '၄၃ ရက် = တစ်လ');
42570 assert.equal(start.from(moment([2007, 1, 28]).add({
42571 d: 46
42572 }), true), '၂ လ', '၄၆ ရက် = ၂ လ');
42573 assert.equal(start.from(moment([2007, 1, 28]).add({
42574 d: 74
42575 }), true), '၂ လ', '၇၅ ရက်= ၂ လ');
42576 assert.equal(start.from(moment([2007, 1, 28]).add({
42577 d: 76
42578 }), true), '၃ လ', '၇၆ ရက် = ၃ လ');
42579 assert.equal(start.from(moment([2007, 1, 28]).add({
42580 M: 1
42581 }), true), 'တစ်လ', '၁ လ = တစ်လ');
42582 assert.equal(start.from(moment([2007, 1, 28]).add({
42583 M: 5
42584 }), true), '၅ လ', '၅ လ = ၅ လ');
42585 assert.equal(start.from(moment([2007, 1, 28]).add({
42586 d: 345
42587 }), true), 'တစ်နှစ်', '၃၄၅ ရက် = တစ်နှစ်');
42588 assert.equal(start.from(moment([2007, 1, 28]).add({
42589 d: 548
42590 }), true), '၂ နှစ်', '၅၄၈ ရက် = ၂ နှစ်');
42591 assert.equal(start.from(moment([2007, 1, 28]).add({
42592 y: 1
42593 }), true), 'တစ်နှစ်', '၁ နှစ် = တစ်နှစ်');
42594 assert.equal(start.from(moment([2007, 1, 28]).add({
42595 y: 5
42596 }), true), '၅ နှစ်', '၅ နှစ် = ၅ နှစ်');
42597 });
42598
42599 test('suffix', function (assert) {
42600 assert.equal(moment(30000).from(0), 'လာမည့် စက္ကန်.အနည်းငယ် မှာ', 'prefix');
42601 assert.equal(moment(0).from(30000), 'လွန်ခဲ့သော စက္ကန်.အနည်းငယ် က', 'suffix');
42602 });
42603
42604 test('now from now', function (assert) {
42605 assert.equal(moment().fromNow(), 'လွန်ခဲ့သော စက္ကန်.အနည်းငယ် က', 'ယခုမှစပြီး အတိတ်တွင်ဖော်ပြသလိုဖော်ပြမည်');
42606 });
42607
42608 test('fromNow', function (assert) {
42609 assert.equal(moment().add({
42610 s: 30
42611 }).fromNow(), 'လာမည့် စက္ကန်.အနည်းငယ် မှာ', 'လာမည့် စက္ကန်.အနည်းငယ် မှာ');
42612 assert.equal(moment().add({
42613 d: 5
42614 }).fromNow(), 'လာမည့် ၅ ရက် မှာ', 'လာမည့် ၅ ရက် မှာ');
42615 });
42616
42617 test('calendar day', function (assert) {
42618 var a = moment().hours(12).minutes(0).seconds(0);
42619
42620 assert.equal(moment(a).calendar(), 'ယနေ. ၁၂:၀၀ မှာ', 'ယနေ. ဒီအချိန်');
42621 assert.equal(moment(a).add({m: 25}).calendar(), 'ယနေ. ၁၂:၂၅ မှာ', 'ယခုမှ ၂၅ မိနစ်ပေါင်းထည့်');
42622 assert.equal(moment(a).add({h: 1}).calendar(), 'ယနေ. ၁၃:၀၀ မှာ', 'ယခုမှ ၁ နာရီပေါင်းထည့်');
42623 assert.equal(moment(a).add({d: 1}).calendar(), 'မနက်ဖြန် ၁၂:၀၀ မှာ', 'မနက်ဖြန် ဒီအချိန်');
42624 assert.equal(moment(a).subtract({h: 1}).calendar(), 'ယနေ. ၁၁:၀၀ မှာ', 'ယခုမှ ၁ နာရီနှုတ်');
42625 assert.equal(moment(a).subtract({d: 1}).calendar(), 'မနေ.က ၁၂:၀၀ မှာ', 'မနေ.က ဒီအချိန်');
42626 });
42627
42628 test('calendar next week', function (assert) {
42629 var i, m;
42630 for (i = 2; i < 7; i++) {
42631 m = moment().add({
42632 d: i
42633 });
42634 assert.equal(m.calendar(), m.format('dddd LT [မှာ]'), 'Today + ' + i + ' days current time');
42635 m.hours(0).minutes(0).seconds(0).milliseconds(0);
42636 assert.equal(m.calendar(), m.format('dddd LT [မှာ]'), 'Today + ' + i + ' days beginning of day');
42637 m.hours(23).minutes(59).seconds(59).milliseconds(999);
42638 assert.equal(m.calendar(), m.format('dddd LT [မှာ]'), 'Today + ' + i + ' days end of day');
516f5f67
IC
42639 }
42640 });
42641
db71a655
KM
42642 test('calendar last week', function (assert) {
42643 var i, m;
516f5f67 42644
db71a655
KM
42645 for (i = 2; i < 7; i++) {
42646 m = moment().subtract({
42647 d: i
42648 });
42649 assert.equal(m.calendar(), m.format('[ပြီးခဲ့သော] dddd LT [မှာ]'), 'Today - ' + i + ' days current time');
42650 m.hours(0).minutes(0).seconds(0).milliseconds(0);
42651 assert.equal(m.calendar(), m.format('[ပြီးခဲ့သော] dddd LT [မှာ]'), 'Today - ' + i + ' days beginning of day');
42652 m.hours(23).minutes(59).seconds(59).milliseconds(999);
42653 assert.equal(m.calendar(), m.format('[ပြီးခဲ့သော] dddd LT [မှာ]'), 'Today - ' + i + ' days end of day');
42654 }
42655 });
516f5f67 42656
db71a655
KM
42657 test('calendar all else', function (assert) {
42658 var weeksAgo = moment().subtract({
42659 w: 1
42660 }),
42661 weeksFromNow = moment().add({
42662 w: 1
42663 });
516f5f67 42664
db71a655
KM
42665 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), 'လွန်ခဲ့သော ၁ ပတ်က');
42666 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), '၁ ပတ်အတွင်း');
42667
42668 weeksAgo = moment().subtract({
42669 w: 2
42670 });
c74a101d 42671 weeksFromNow = moment().add({
db71a655 42672 w: 2
c74a101d 42673 });
516f5f67 42674
db71a655
KM
42675 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '၂ ပတ် အရင်က');
42676 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), '၂ ပတ် အတွင်း');
73f3c911 42677 });
73f3c911 42678
db71a655
KM
42679 test('weeks year starting sunday formatted', function (assert) {
42680 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '၅၂ ၅၂ ၅၂', 'Jan 1 2012 should be week 52');
42681 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '၁ ၀၁ ၁', 'Jan 2 2012 should be week 1');
42682 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '၁ ၀၁ ၁', 'Jan 8 2012 should be week 1');
42683 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '၂ ၀၂ ၂', 'Jan 9 2012 should be week 2');
42684 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '၂ ၀၂ ၂', 'Jan 15 2012 should be week 2');
42685 });
73f3c911
IC
42686
42687})));
42688
516f5f67 42689
c74a101d
IC
42690;(function (global, factory) {
42691 typeof exports === 'object' && typeof module !== 'undefined'
42692 && typeof require === 'function' ? factory(require('../../moment')) :
25cc720f
IC
42693 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
42694 factory(global.moment)
73f3c911 42695}(this, (function (moment) { 'use strict';
25cc720f 42696
db71a655
KM
42697 function each(array, callback) {
42698 var i;
42699 for (i = 0; i < array.length; i++) {
42700 callback(array[i], i, array);
b135bf1a 42701 }
b135bf1a 42702 }
f2af24d5 42703
c58511b9
KM
42704 function setupDeprecationHandler(test, moment$$1, scope) {
42705 test._expectedDeprecations = null;
42706 test._observedDeprecations = null;
42707 test._oldSupress = moment$$1.suppressDeprecationWarnings;
42708 moment$$1.suppressDeprecationWarnings = true;
42709 test.expectedDeprecations = function () {
42710 test._expectedDeprecations = arguments;
42711 test._observedDeprecations = [];
42712 };
42713 moment$$1.deprecationHandler = function (name, msg) {
42714 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
42715 if (deprecationId === -1) {
42716 throw new Error('Unexpected deprecation thrown name=' +
42717 name + ' msg=' + msg);
42718 }
42719 test._observedDeprecations[deprecationId] = 1;
42720 };
42721 }
42722
42723 function teardownDeprecationHandler(test, moment$$1, scope) {
42724 moment$$1.suppressDeprecationWarnings = test._oldSupress;
42725
42726 if (test._expectedDeprecations != null) {
42727 var missedDeprecations = [];
42728 each(test._expectedDeprecations, function (deprecationPattern, id) {
42729 if (test._observedDeprecations[id] !== 1) {
42730 missedDeprecations.push(deprecationPattern);
42731 }
42732 });
42733 if (missedDeprecations.length !== 0) {
42734 throw new Error('Expected deprecation warnings did not happen: ' +
42735 missedDeprecations.join(' '));
42736 }
42737 }
42738 }
42739
42740 function matchedDeprecation(name, msg, deprecations) {
42741 if (deprecations == null) {
42742 return -1;
42743 }
42744 for (var i = 0; i < deprecations.length; ++i) {
42745 if (name != null && name === deprecations[i]) {
42746 return i;
42747 }
42748 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
42749 return i;
42750 }
42751 }
42752 return -1;
42753 }
42754
42755 /*global QUnit:false*/
42756
42757 var test = QUnit.test;
42758
db71a655
KM
42759 function objectKeys(obj) {
42760 if (Object.keys) {
42761 return Object.keys(obj);
42762 } else {
42763 // IE8
42764 var res = [], i;
42765 for (i in obj) {
42766 if (obj.hasOwnProperty(i)) {
42767 res.push(i);
42768 }
42769 }
42770 return res;
f2af24d5 42771 }
db71a655 42772 }
f2af24d5 42773
db71a655
KM
42774 // Pick the first defined of two or three arguments.
42775
42776 function defineCommonLocaleTests(locale, options) {
42777 test('lenient day of month ordinal parsing', function (assert) {
42778 var i, ordinalStr, testMoment;
42779 for (i = 1; i <= 31; ++i) {
42780 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
42781 testMoment = moment(ordinalStr, 'YYYY MM Do');
42782 assert.equal(testMoment.year(), 2014,
42783 'lenient day of month ordinal parsing ' + i + ' year check');
42784 assert.equal(testMoment.month(), 0,
42785 'lenient day of month ordinal parsing ' + i + ' month check');
42786 assert.equal(testMoment.date(), i,
42787 'lenient day of month ordinal parsing ' + i + ' date check');
42788 }
f2af24d5 42789 });
f2af24d5 42790
db71a655
KM
42791 test('lenient day of month ordinal parsing of number', function (assert) {
42792 var i, testMoment;
42793 for (i = 1; i <= 31; ++i) {
42794 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
42795 assert.equal(testMoment.year(), 2014,
42796 'lenient day of month ordinal parsing of number ' + i + ' year check');
42797 assert.equal(testMoment.month(), 0,
42798 'lenient day of month ordinal parsing of number ' + i + ' month check');
42799 assert.equal(testMoment.date(), i,
42800 'lenient day of month ordinal parsing of number ' + i + ' date check');
42801 }
42802 });
f2af24d5 42803
db71a655
KM
42804 test('strict day of month ordinal parsing', function (assert) {
42805 var i, ordinalStr, testMoment;
42806 for (i = 1; i <= 31; ++i) {
42807 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
42808 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
42809 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
42810 }
42811 });
f2af24d5 42812
db71a655
KM
42813 test('meridiem invariant', function (assert) {
42814 var h, m, t1, t2;
42815 for (h = 0; h < 24; ++h) {
42816 for (m = 0; m < 60; m += 15) {
42817 t1 = moment.utc([2000, 0, 1, h, m]);
42818 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
42819 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
42820 'meridiem at ' + t1.format('HH:mm'));
42821 }
42822 }
42823 });
f2af24d5 42824
db71a655
KM
42825 test('date format correctness', function (assert) {
42826 var data, tokens;
42827 data = moment.localeData()._longDateFormat;
42828 tokens = objectKeys(data);
42829 each(tokens, function (srchToken) {
42830 // Check each format string to make sure it does not contain any
42831 // tokens that need to be expanded.
42832 each(tokens, function (baseToken) {
42833 // strip escaped sequences
42834 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
42835 assert.equal(false, !!~format.indexOf(srchToken),
42836 'contains ' + srchToken + ' in ' + baseToken);
42837 });
42838 });
42839 });
f2af24d5 42840
db71a655
KM
42841 test('month parsing correctness', function (assert) {
42842 var i, m;
42843
42844 if (locale === 'tr') {
42845 // I can't fix it :(
c58511b9 42846 assert.expect(0);
db71a655
KM
42847 return;
42848 }
42849 function tester(format) {
42850 var r;
42851 r = moment(m.format(format), format);
42852 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
42853 if (locale !== 'ka') {
42854 r = moment(m.format(format).toLocaleUpperCase(), format);
42855 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
42856 }
db71a655
KM
42857 r = moment(m.format(format).toLocaleLowerCase(), format);
42858 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
42859
42860 r = moment(m.format(format), format, true);
42861 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
42862 if (locale !== 'ka') {
42863 r = moment(m.format(format).toLocaleUpperCase(), format, true);
42864 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
42865 }
db71a655
KM
42866 r = moment(m.format(format).toLocaleLowerCase(), format, true);
42867 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
42868 }
42869
42870 for (i = 0; i < 12; ++i) {
42871 m = moment([2015, i, 15, 18]);
42872 tester('MMM');
42873 tester('MMM.');
42874 tester('MMMM');
42875 tester('MMMM.');
42876 }
42877 });
f2af24d5 42878
db71a655
KM
42879 test('weekday parsing correctness', function (assert) {
42880 var i, m;
42881
96d0d679 42882 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
42883 // tr, az: There is a lower-case letter (ı), that converted to
42884 // upper then lower changes to i
42885 // ro: there is the letter ț which behaves weird under IE8
42886 // mt: letter Ħ
96d0d679 42887 // ga: month with spaces
c58511b9 42888 assert.expect(0);
db71a655
KM
42889 return;
42890 }
42891 function tester(format) {
42892 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
42893 r = moment(m.format(format), format);
42894 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
42895 if (locale !== 'ka') {
42896 r = moment(m.format(format).toLocaleUpperCase(), format);
42897 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
42898 }
db71a655
KM
42899 r = moment(m.format(format).toLocaleLowerCase(), format);
42900 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
42901 r = moment(m.format(format), format, true);
42902 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
42903 if (locale !== 'ka') {
42904 r = moment(m.format(format).toLocaleUpperCase(), format, true);
42905 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
42906 }
db71a655
KM
42907 r = moment(m.format(format).toLocaleLowerCase(), format, true);
42908 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
42909 }
42910
42911 for (i = 0; i < 7; ++i) {
42912 m = moment.utc([2015, 0, i + 1, 18]);
42913 tester('dd');
42914 tester('ddd');
42915 tester('dddd');
42916 }
42917 });
f2af24d5 42918
db71a655
KM
42919 test('valid localeData', function (assert) {
42920 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
42921 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
42922 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
42923 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
42924 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
42925 });
96d0d679
KM
42926
42927 test('localeData weekdays can localeSort', function (assert) {
42928 var weekdays = moment().localeData().weekdays();
42929 var weekdaysShort = moment().localeData().weekdaysShort();
42930 var weekdaysMin = moment().localeData().weekdaysMin();
42931 var shift = moment().localeData()._week.dow;
42932 assert.deepEqual(
42933 moment().localeData().weekdays(true),
42934 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
42935 'weekdays should localeSort');
42936 assert.deepEqual(
42937 moment().localeData().weekdaysShort(true),
42938 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
42939 'weekdaysShort should localeSort');
42940 assert.deepEqual(
42941 moment().localeData().weekdaysMin(true),
42942 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
42943 'weekdaysMin should localeSort');
42944 });
db71a655 42945 }
f2af24d5 42946
db71a655 42947 /*global QUnit:false*/
f2af24d5 42948
db71a655
KM
42949 function localeModule (name, lifecycle) {
42950 QUnit.module('locale:' + name, {
c58511b9 42951 beforeEach : function () {
db71a655
KM
42952 moment.locale(name);
42953 moment.createFromInputFallback = function (config) {
42954 throw new Error('input not handled by moment: ' + config._i);
42955 };
42956 setupDeprecationHandler(test, moment, 'locale');
42957 if (lifecycle && lifecycle.setup) {
42958 lifecycle.setup();
42959 }
42960 },
c58511b9 42961 afterEach : function () {
db71a655
KM
42962 moment.locale('en');
42963 teardownDeprecationHandler(test, moment, 'locale');
42964 if (lifecycle && lifecycle.teardown) {
42965 lifecycle.teardown();
42966 }
f2af24d5 42967 }
db71a655
KM
42968 });
42969 defineCommonLocaleTests(name, -1, -1);
42970 }
42971
42972 localeModule('nb');
42973
42974 test('parse', function (assert) {
42975 var tests = 'januar jan._februar feb._mars mars_april april_mai mai_juni juni_juli juli_august aug._september sep._oktober okt._november nov._desember des.'.split('_'),
42976 i;
42977 function equalTest(input, mmm, i) {
42978 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
42979 }
42980 for (i = 0; i < 12; i++) {
42981 tests[i] = tests[i].split(' ');
42982 equalTest(tests[i][0], 'MMM', i);
42983 equalTest(tests[i][1], 'MMM', i);
42984 equalTest(tests[i][0], 'MMMM', i);
42985 equalTest(tests[i][1], 'MMMM', i);
42986 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
42987 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
42988 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
42989 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
42990 }
42991 });
42992
42993 test('format', function (assert) {
42994 var a = [
42995 ['dddd, MMMM Do YYYY, h:mm:ss a', 'søndag, februar 14. 2010, 3:25:50 pm'],
42996 ['ddd, hA', 'sø., 3PM'],
42997 ['M Mo MM MMMM MMM', '2 2. 02 februar feb.'],
42998 ['YYYY YY', '2010 10'],
42999 ['D Do DD', '14 14. 14'],
43000 ['d do dddd ddd dd', '0 0. søndag sø. sø'],
43001 ['DDD DDDo DDDD', '45 45. 045'],
43002 ['w wo ww', '6 6. 06'],
43003 ['h hh', '3 03'],
43004 ['H HH', '15 15'],
43005 ['m mm', '25 25'],
43006 ['s ss', '50 50'],
43007 ['a A', 'pm PM'],
43008 ['[den] DDDo [dagen i året]', 'den 45. dagen i året'],
43009 ['LTS', '15:25:50'],
43010 ['L', '14.02.2010'],
43011 ['LL', '14. februar 2010'],
43012 ['LLL', '14. februar 2010 kl. 15:25'],
43013 ['LLLL', 'søndag 14. februar 2010 kl. 15:25'],
43014 ['l', '14.2.2010'],
43015 ['ll', '14. feb. 2010'],
43016 ['lll', '14. feb. 2010 kl. 15:25'],
43017 ['llll', 'sø. 14. feb. 2010 kl. 15:25']
43018 ],
43019 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
43020 i;
43021 for (i = 0; i < a.length; i++) {
43022 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
43023 }
43024 });
43025
43026 test('format ordinal', function (assert) {
43027 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
43028 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
43029 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
43030 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
43031 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
43032 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
43033 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
43034 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
43035 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
43036 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
43037
43038 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
43039 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
43040 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
43041 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
43042 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
43043 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
43044 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
43045 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
43046 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
43047 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
43048
43049 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
43050 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
43051 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
43052 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
43053 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
43054 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
43055 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
43056 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
43057 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
43058 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
43059
43060 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
43061 });
43062
43063 test('format month', function (assert) {
43064 var expected = 'januar jan._februar feb._mars mars_april april_mai mai_juni juni_juli juli_august aug._september sep._oktober okt._november nov._desember des.'.split('_'), i;
43065 for (i = 0; i < expected.length; i++) {
43066 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
43067 }
43068 });
43069
43070 test('format week', function (assert) {
43071 var expected = 'søndag sø. sø_mandag ma. ma_tirsdag ti. ti_onsdag on. on_torsdag to. to_fredag fr. fr_lørdag lø. lø'.split('_'), i;
43072 for (i = 0; i < expected.length; i++) {
43073 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
43074 }
43075 });
43076
43077 test('from', function (assert) {
43078 var start = moment([2007, 1, 28]);
43079 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'noen sekunder', '44 sekunder = a few seconds');
43080 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ett minutt', '45 seconds = a minute');
43081 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ett minutt', '89 seconds = a minute');
43082 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutter', '90 seconds = 2 minutes');
43083 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutter', '44 minutes = 44 minutes');
43084 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'en time', '45 minutes = an hour');
43085 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'en time', '89 minutes = an hour');
43086 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 timer', '90 minutes = 2 hours');
43087 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 timer', '5 hours = 5 hours');
43088 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 timer', '21 hours = 21 hours');
43089 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'en dag', '22 hours = a day');
43090 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'en dag', '35 hours = a day');
43091 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dager', '36 hours = 2 days');
43092 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'en dag', '1 day = a day');
43093 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dager', '5 days = 5 days');
43094 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dager', '25 days = 25 days');
43095 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'en måned', '26 days = a month');
43096 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'en måned', '30 days = a month');
43097 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'en måned', '43 days = a month');
43098 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 måneder', '46 days = 2 months');
43099 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 måneder', '75 days = 2 months');
43100 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 måneder', '76 days = 3 months');
43101 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'en måned', '1 month = a month');
43102 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 måneder', '5 months = 5 months');
43103 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ett år', '345 days = a year');
43104 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 år', '548 days = 2 years');
43105 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ett år', '1 year = a year');
43106 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 år', '5 years = 5 years');
43107 });
43108
43109 test('suffix', function (assert) {
43110 assert.equal(moment(30000).from(0), 'om noen sekunder', 'prefix');
43111 assert.equal(moment(0).from(30000), 'noen sekunder siden', 'suffix');
43112 });
43113
43114 test('now from now', function (assert) {
43115 assert.equal(moment().fromNow(), 'noen sekunder siden', 'now from now should display as in the past');
43116 });
43117
43118 test('fromNow', function (assert) {
43119 assert.equal(moment().add({s: 30}).fromNow(), 'om noen sekunder', 'in a few seconds');
43120 assert.equal(moment().add({d: 5}).fromNow(), 'om 5 dager', 'in 5 days');
43121 });
43122
43123 test('calendar day', function (assert) {
43124 var a = moment().hours(12).minutes(0).seconds(0);
43125
43126 assert.equal(moment(a).calendar(), 'i dag kl. 12:00', 'today at the same time');
43127 assert.equal(moment(a).add({m: 25}).calendar(), 'i dag kl. 12:25', 'Now plus 25 min');
43128 assert.equal(moment(a).add({h: 1}).calendar(), 'i dag kl. 13:00', 'Now plus 1 hour');
43129 assert.equal(moment(a).add({d: 1}).calendar(), 'i morgen kl. 12:00', 'tomorrow at the same time');
43130 assert.equal(moment(a).subtract({h: 1}).calendar(), 'i dag kl. 11:00', 'Now minus 1 hour');
43131 assert.equal(moment(a).subtract({d: 1}).calendar(), 'i går kl. 12:00', 'yesterday at the same time');
43132 });
43133
43134 test('calendar next week', function (assert) {
43135 var i, m;
43136 for (i = 2; i < 7; i++) {
43137 m = moment().add({d: i});
43138 assert.equal(m.calendar(), m.format('dddd [kl.] LT'), 'Today + ' + i + ' days current time');
43139 m.hours(0).minutes(0).seconds(0).milliseconds(0);
43140 assert.equal(m.calendar(), m.format('dddd [kl.] LT'), 'Today + ' + i + ' days beginning of day');
43141 m.hours(23).minutes(59).seconds(59).milliseconds(999);
43142 assert.equal(m.calendar(), m.format('dddd [kl.] LT'), 'Today + ' + i + ' days end of day');
43143 }
43144 });
43145
43146 test('calendar last week', function (assert) {
43147 var i, m;
43148 for (i = 2; i < 7; i++) {
43149 m = moment().subtract({d: i});
43150 assert.equal(m.calendar(), m.format('[forrige] dddd [kl.] LT'), 'Today - ' + i + ' days current time');
43151 m.hours(0).minutes(0).seconds(0).milliseconds(0);
43152 assert.equal(m.calendar(), m.format('[forrige] dddd [kl.] LT'), 'Today - ' + i + ' days beginning of day');
43153 m.hours(23).minutes(59).seconds(59).milliseconds(999);
43154 assert.equal(m.calendar(), m.format('[forrige] dddd [kl.] LT'), 'Today - ' + i + ' days end of day');
43155 }
43156 });
43157
43158 test('calendar all else', function (assert) {
43159 var weeksAgo = moment().subtract({w: 1}),
43160 weeksFromNow = moment().add({w: 1});
43161
43162 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
43163 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
43164
43165 weeksAgo = moment().subtract({w: 2});
43166 weeksFromNow = moment().add({w: 2});
43167
43168 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
43169 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
43170 });
43171
43172 test('weeks year starting sunday formatted', function (assert) {
43173 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
43174 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
43175 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
43176 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
43177 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
43178 });
f2af24d5
IC
43179
43180})));
43181
43182
43183;(function (global, factory) {
43184 typeof exports === 'object' && typeof module !== 'undefined'
43185 && typeof require === 'function' ? factory(require('../../moment')) :
43186 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
43187 factory(global.moment)
43188}(this, (function (moment) { 'use strict';
43189
db71a655
KM
43190 function each(array, callback) {
43191 var i;
43192 for (i = 0; i < array.length; i++) {
43193 callback(array[i], i, array);
43194 }
f2af24d5 43195 }
f2af24d5 43196
c58511b9
KM
43197 function setupDeprecationHandler(test, moment$$1, scope) {
43198 test._expectedDeprecations = null;
43199 test._observedDeprecations = null;
43200 test._oldSupress = moment$$1.suppressDeprecationWarnings;
43201 moment$$1.suppressDeprecationWarnings = true;
43202 test.expectedDeprecations = function () {
43203 test._expectedDeprecations = arguments;
43204 test._observedDeprecations = [];
43205 };
43206 moment$$1.deprecationHandler = function (name, msg) {
43207 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
43208 if (deprecationId === -1) {
43209 throw new Error('Unexpected deprecation thrown name=' +
43210 name + ' msg=' + msg);
43211 }
43212 test._observedDeprecations[deprecationId] = 1;
43213 };
43214 }
43215
43216 function teardownDeprecationHandler(test, moment$$1, scope) {
43217 moment$$1.suppressDeprecationWarnings = test._oldSupress;
43218
43219 if (test._expectedDeprecations != null) {
43220 var missedDeprecations = [];
43221 each(test._expectedDeprecations, function (deprecationPattern, id) {
43222 if (test._observedDeprecations[id] !== 1) {
43223 missedDeprecations.push(deprecationPattern);
43224 }
43225 });
43226 if (missedDeprecations.length !== 0) {
43227 throw new Error('Expected deprecation warnings did not happen: ' +
43228 missedDeprecations.join(' '));
43229 }
43230 }
43231 }
43232
43233 function matchedDeprecation(name, msg, deprecations) {
43234 if (deprecations == null) {
43235 return -1;
43236 }
43237 for (var i = 0; i < deprecations.length; ++i) {
43238 if (name != null && name === deprecations[i]) {
43239 return i;
43240 }
43241 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
43242 return i;
43243 }
43244 }
43245 return -1;
43246 }
43247
43248 /*global QUnit:false*/
43249
43250 var test = QUnit.test;
43251
db71a655
KM
43252 function objectKeys(obj) {
43253 if (Object.keys) {
43254 return Object.keys(obj);
43255 } else {
43256 // IE8
43257 var res = [], i;
43258 for (i in obj) {
43259 if (obj.hasOwnProperty(i)) {
43260 res.push(i);
43261 }
f2af24d5 43262 }
db71a655 43263 return res;
f2af24d5 43264 }
f2af24d5 43265 }
f2af24d5 43266
db71a655 43267 // Pick the first defined of two or three arguments.
f2af24d5 43268
db71a655
KM
43269 function defineCommonLocaleTests(locale, options) {
43270 test('lenient day of month ordinal parsing', function (assert) {
43271 var i, ordinalStr, testMoment;
43272 for (i = 1; i <= 31; ++i) {
43273 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
43274 testMoment = moment(ordinalStr, 'YYYY MM Do');
43275 assert.equal(testMoment.year(), 2014,
43276 'lenient day of month ordinal parsing ' + i + ' year check');
43277 assert.equal(testMoment.month(), 0,
43278 'lenient day of month ordinal parsing ' + i + ' month check');
43279 assert.equal(testMoment.date(), i,
43280 'lenient day of month ordinal parsing ' + i + ' date check');
43281 }
43282 });
b135bf1a 43283
db71a655
KM
43284 test('lenient day of month ordinal parsing of number', function (assert) {
43285 var i, testMoment;
43286 for (i = 1; i <= 31; ++i) {
43287 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
43288 assert.equal(testMoment.year(), 2014,
43289 'lenient day of month ordinal parsing of number ' + i + ' year check');
43290 assert.equal(testMoment.month(), 0,
43291 'lenient day of month ordinal parsing of number ' + i + ' month check');
43292 assert.equal(testMoment.date(), i,
43293 'lenient day of month ordinal parsing of number ' + i + ' date check');
43294 }
43295 });
b135bf1a 43296
db71a655
KM
43297 test('strict day of month ordinal parsing', function (assert) {
43298 var i, ordinalStr, testMoment;
43299 for (i = 1; i <= 31; ++i) {
43300 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
43301 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
43302 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
43303 }
43304 });
b135bf1a 43305
db71a655
KM
43306 test('meridiem invariant', function (assert) {
43307 var h, m, t1, t2;
43308 for (h = 0; h < 24; ++h) {
43309 for (m = 0; m < 60; m += 15) {
43310 t1 = moment.utc([2000, 0, 1, h, m]);
43311 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
43312 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
43313 'meridiem at ' + t1.format('HH:mm'));
43314 }
43315 }
43316 });
43317
43318 test('date format correctness', function (assert) {
43319 var data, tokens;
43320 data = moment.localeData()._longDateFormat;
43321 tokens = objectKeys(data);
43322 each(tokens, function (srchToken) {
43323 // Check each format string to make sure it does not contain any
43324 // tokens that need to be expanded.
43325 each(tokens, function (baseToken) {
43326 // strip escaped sequences
43327 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
43328 assert.equal(false, !!~format.indexOf(srchToken),
43329 'contains ' + srchToken + ' in ' + baseToken);
43330 });
b135bf1a
IC
43331 });
43332 });
d6651c21 43333
db71a655
KM
43334 test('month parsing correctness', function (assert) {
43335 var i, m;
43336
43337 if (locale === 'tr') {
43338 // I can't fix it :(
c58511b9 43339 assert.expect(0);
db71a655
KM
43340 return;
43341 }
43342 function tester(format) {
43343 var r;
43344 r = moment(m.format(format), format);
43345 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
43346 if (locale !== 'ka') {
43347 r = moment(m.format(format).toLocaleUpperCase(), format);
43348 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
43349 }
db71a655
KM
43350 r = moment(m.format(format).toLocaleLowerCase(), format);
43351 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
43352
43353 r = moment(m.format(format), format, true);
43354 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
43355 if (locale !== 'ka') {
43356 r = moment(m.format(format).toLocaleUpperCase(), format, true);
43357 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
43358 }
db71a655
KM
43359 r = moment(m.format(format).toLocaleLowerCase(), format, true);
43360 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
43361 }
43362
43363 for (i = 0; i < 12; ++i) {
43364 m = moment([2015, i, 15, 18]);
43365 tester('MMM');
43366 tester('MMM.');
43367 tester('MMMM');
43368 tester('MMMM.');
43369 }
43370 });
d6651c21 43371
db71a655
KM
43372 test('weekday parsing correctness', function (assert) {
43373 var i, m;
43374
96d0d679 43375 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
43376 // tr, az: There is a lower-case letter (ı), that converted to
43377 // upper then lower changes to i
43378 // ro: there is the letter ț which behaves weird under IE8
43379 // mt: letter Ħ
96d0d679 43380 // ga: month with spaces
c58511b9 43381 assert.expect(0);
db71a655
KM
43382 return;
43383 }
43384 function tester(format) {
43385 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
43386 r = moment(m.format(format), format);
43387 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
43388 if (locale !== 'ka') {
43389 r = moment(m.format(format).toLocaleUpperCase(), format);
43390 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
43391 }
db71a655
KM
43392 r = moment(m.format(format).toLocaleLowerCase(), format);
43393 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
43394 r = moment(m.format(format), format, true);
43395 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
43396 if (locale !== 'ka') {
43397 r = moment(m.format(format).toLocaleUpperCase(), format, true);
43398 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
43399 }
db71a655
KM
43400 r = moment(m.format(format).toLocaleLowerCase(), format, true);
43401 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
43402 }
43403
43404 for (i = 0; i < 7; ++i) {
43405 m = moment.utc([2015, 0, i + 1, 18]);
43406 tester('dd');
43407 tester('ddd');
43408 tester('dddd');
43409 }
43410 });
d6651c21 43411
db71a655
KM
43412 test('valid localeData', function (assert) {
43413 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
43414 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
43415 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
43416 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
43417 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
43418 });
96d0d679
KM
43419
43420 test('localeData weekdays can localeSort', function (assert) {
43421 var weekdays = moment().localeData().weekdays();
43422 var weekdaysShort = moment().localeData().weekdaysShort();
43423 var weekdaysMin = moment().localeData().weekdaysMin();
43424 var shift = moment().localeData()._week.dow;
43425 assert.deepEqual(
43426 moment().localeData().weekdays(true),
43427 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
43428 'weekdays should localeSort');
43429 assert.deepEqual(
43430 moment().localeData().weekdaysShort(true),
43431 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
43432 'weekdaysShort should localeSort');
43433 assert.deepEqual(
43434 moment().localeData().weekdaysMin(true),
43435 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
43436 'weekdaysMin should localeSort');
43437 });
db71a655 43438 }
d6651c21 43439
db71a655
KM
43440 /*global QUnit:false*/
43441
db71a655
KM
43442 function localeModule (name, lifecycle) {
43443 QUnit.module('locale:' + name, {
c58511b9 43444 beforeEach : function () {
db71a655
KM
43445 moment.locale(name);
43446 moment.createFromInputFallback = function (config) {
43447 throw new Error('input not handled by moment: ' + config._i);
43448 };
43449 setupDeprecationHandler(test, moment, 'locale');
43450 if (lifecycle && lifecycle.setup) {
43451 lifecycle.setup();
43452 }
43453 },
c58511b9 43454 afterEach : function () {
db71a655
KM
43455 moment.locale('en');
43456 teardownDeprecationHandler(test, moment, 'locale');
43457 if (lifecycle && lifecycle.teardown) {
43458 lifecycle.teardown();
43459 }
25cc720f
IC
43460 }
43461 });
db71a655
KM
43462 defineCommonLocaleTests(name, -1, -1);
43463 }
43464
43465 localeModule('ne');
43466
43467 test('parse', function (assert) {
43468 var tests = 'जनवरी जन._फेब्रुवरी फेब्रु._मार्च मार्च_अप्रिल अप्रि._मई मई_जुन जुन_जुलाई जुलाई._अगष्ट अग._सेप्टेम्बर सेप्ट._अक्टोबर अक्टो._नोभेम्बर नोभे._डिसेम्बर डिसे.'.split('_'), i;
43469 function equalTest(input, mmm, i) {
43470 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
43471 }
43472 for (i = 0; i < 12; i++) {
43473 tests[i] = tests[i].split(' ');
43474 equalTest(tests[i][0], 'MMM', i);
43475 equalTest(tests[i][1], 'MMM', i);
43476 equalTest(tests[i][0], 'MMMM', i);
43477 equalTest(tests[i][1], 'MMMM', i);
43478 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
43479 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
43480 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
43481 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
43482 }
43483 });
43484
43485 test('format', function (assert) {
43486 var a = [
43487 ['dddd, Do MMMM YYYY, aको h:mm:ss बजे', 'आइतबार, १४ फेब्रुवरी २०१०, दिउँसोको ३:२५:५० बजे'],
43488 ['ddd, aको h बजे', 'आइत., दिउँसोको ३ बजे'],
43489 ['M Mo MM MMMM MMM', '२ २ ०२ फेब्रुवरी फेब्रु.'],
43490 ['YYYY YY', '२०१० १०'],
43491 ['D Do DD', '१४ १४ १४'],
43492 ['d do dddd ddd dd', '० ० आइतबार आइत. आ.'],
43493 ['DDD DDDo DDDD', '४५ ४५ ०४५'],
43494 ['w wo ww', '८ ८ ०८'],
43495 ['h hh', '३ ०३'],
43496 ['H HH', '१५ १५'],
43497 ['m mm', '२५ २५'],
43498 ['s ss', '५० ५०'],
43499 ['a A', 'दिउँसो दिउँसो'],
43500 ['LTS', 'दिउँसोको ३:२५:५० बजे'],
43501 ['L', '१४/०२/२०१०'],
43502 ['LL', '१४ फेब्रुवरी २०१०'],
43503 ['LLL', '१४ फेब्रुवरी २०१०, दिउँसोको ३:२५ बजे'],
43504 ['LLLL', 'आइतबार, १४ फेब्रुवरी २०१०, दिउँसोको ३:२५ बजे'],
43505 ['l', '१४/२/२०१०'],
43506 ['ll', '१४ फेब्रु. २०१०'],
43507 ['lll', '१४ फेब्रु. २०१०, दिउँसोको ३:२५ बजे'],
43508 ['llll', 'आइत., १४ फेब्रु. २०१०, दिउँसोको ३:२५ बजे']
43509 ],
43510 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
43511 i;
43512 for (i = 0; i < a.length; i++) {
43513 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
43514 }
43515 });
43516
43517 test('format ordinal', function (assert) {
43518 assert.equal(moment([2011, 0, 1]).format('DDDo'), '१', '१');
43519 assert.equal(moment([2011, 0, 2]).format('DDDo'), '२', '२');
43520 assert.equal(moment([2011, 0, 3]).format('DDDo'), '३', '३');
43521 assert.equal(moment([2011, 0, 4]).format('DDDo'), '४', '४');
43522 assert.equal(moment([2011, 0, 5]).format('DDDo'), '५', '५');
43523 assert.equal(moment([2011, 0, 6]).format('DDDo'), '६', '६');
43524 assert.equal(moment([2011, 0, 7]).format('DDDo'), '७', '७');
43525 assert.equal(moment([2011, 0, 8]).format('DDDo'), '८', '८');
43526 assert.equal(moment([2011, 0, 9]).format('DDDo'), '९', '९');
43527 assert.equal(moment([2011, 0, 10]).format('DDDo'), '१०', '१०');
43528
43529 assert.equal(moment([2011, 0, 11]).format('DDDo'), '११', '११');
43530 assert.equal(moment([2011, 0, 12]).format('DDDo'), '१२', '१२');
43531 assert.equal(moment([2011, 0, 13]).format('DDDo'), '१३', '१३');
43532 assert.equal(moment([2011, 0, 14]).format('DDDo'), '१४', '१४');
43533 assert.equal(moment([2011, 0, 15]).format('DDDo'), '१५', '१५');
43534 assert.equal(moment([2011, 0, 16]).format('DDDo'), '१६', '१६');
43535 assert.equal(moment([2011, 0, 17]).format('DDDo'), '१७', '१७');
43536 assert.equal(moment([2011, 0, 18]).format('DDDo'), '१८', '१८');
43537 assert.equal(moment([2011, 0, 19]).format('DDDo'), '१९', '१९');
43538 assert.equal(moment([2011, 0, 20]).format('DDDo'), '२०', '२०');
43539
43540 assert.equal(moment([2011, 0, 21]).format('DDDo'), '२१', '२१');
43541 assert.equal(moment([2011, 0, 22]).format('DDDo'), '२२', '२२');
43542 assert.equal(moment([2011, 0, 23]).format('DDDo'), '२३', '२३');
43543 assert.equal(moment([2011, 0, 24]).format('DDDo'), '२४', '२४');
43544 assert.equal(moment([2011, 0, 25]).format('DDDo'), '२५', '२५');
43545 assert.equal(moment([2011, 0, 26]).format('DDDo'), '२६', '२६');
43546 assert.equal(moment([2011, 0, 27]).format('DDDo'), '२७', '२७');
43547 assert.equal(moment([2011, 0, 28]).format('DDDo'), '२८', '२८');
43548 assert.equal(moment([2011, 0, 29]).format('DDDo'), '२९', '२९');
43549 assert.equal(moment([2011, 0, 30]).format('DDDo'), '३०', '३०');
43550
43551 assert.equal(moment([2011, 0, 31]).format('DDDo'), '३१', '३१');
43552 });
43553
43554 test('format month', function (assert) {
43555 var expected = 'जनवरी जन._फेब्रुवरी फेब्रु._मार्च मार्च_अप्रिल अप्रि._मई मई_जुन जुन_जुलाई जुलाई._अगष्ट अग._सेप्टेम्बर सेप्ट._अक्टोबर अक्टो._नोभेम्बर नोभे._डिसेम्बर डिसे.'.split('_'), i;
43556 for (i = 0; i < expected.length; i++) {
43557 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
43558 }
43559 });
43560
43561 test('format week', function (assert) {
43562 var expected = 'आइतबार आइत. आ._सोमबार सोम. सो._मङ्गलबार मङ्गल. मं._बुधबार बुध. बु._बिहिबार बिहि. बि._शुक्रबार शुक्र. शु._शनिबार शनि. श.'.split('_'), i;
43563 for (i = 0; i < expected.length; i++) {
43564 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
43565 }
43566 });
43567
43568 test('from', function (assert) {
43569 var start = moment([2007, 1, 28]);
43570 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'केही क्षण', '44 seconds = a few seconds');
43571 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'एक मिनेट', '45 seconds = a minute');
43572 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'एक मिनेट', '89 seconds = a minute');
43573 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '२ मिनेट', '90 seconds = 2 minutes');
43574 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '४४ मिनेट', '44 minutes = 44 minutes');
43575 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'एक घण्टा', '45 minutes = an hour');
43576 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'एक घण्टा', '89 minutes = an hour');
43577 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '२ घण्टा', '90 minutes = 2 hours');
43578 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '५ घण्टा', '5 hours = 5 hours');
43579 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '२१ घण्टा', '21 hours = 21 hours');
43580 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'एक दिन', '22 hours = a day');
43581 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'एक दिन', '35 hours = a day');
43582 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '२ दिन', '36 hours = 2 days');
43583 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'एक दिन', '1 day = a day');
43584 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '५ दिन', '5 days = 5 days');
43585 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '२५ दिन', '25 days = 25 days');
43586 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'एक महिना', '26 days = a month');
43587 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'एक महिना', '30 days = a month');
43588 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'एक महिना', '43 days = a month');
43589 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '२ महिना', '46 days = 2 months');
43590 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '२ महिना', '75 days = 2 months');
43591 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '३ महिना', '76 days = 3 months');
43592 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'एक महिना', '1 month = a month');
43593 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '५ महिना', '5 months = 5 months');
43594 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'एक बर्ष', '345 days = a year');
43595 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '२ बर्ष', '548 days = 2 years');
43596 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'एक बर्ष', '1 year = a year');
43597 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '५ बर्ष', '5 years = 5 years');
43598 });
43599
43600 test('suffix', function (assert) {
43601 assert.equal(moment(30000).from(0), 'केही क्षणमा', 'prefix');
43602 assert.equal(moment(0).from(30000), 'केही क्षण अगाडि', 'suffix');
43603 });
43604
43605 test('now from now', function (assert) {
43606 assert.equal(moment().fromNow(), 'केही क्षण अगाडि', 'now from now should display as in the past');
43607 });
43608
43609 test('fromNow', function (assert) {
43610 assert.equal(moment().add({s: 30}).fromNow(), 'केही क्षणमा', 'केही क्षणमा');
43611 assert.equal(moment().add({d: 5}).fromNow(), '५ दिनमा', '५ दिनमा');
43612 });
43613
43614 test('calendar day', function (assert) {
43615 var a = moment().hours(12).minutes(0).seconds(0);
43616
43617 assert.equal(moment(a).calendar(), 'आज दिउँसोको १२:०० बजे', 'today at the same time');
43618 assert.equal(moment(a).add({m: 25}).calendar(), 'आज दिउँसोको १२:२५ बजे', 'Now plus 25 min');
43619 assert.equal(moment(a).add({h: 1}).calendar(), 'आज दिउँसोको १:०० बजे', 'Now plus 1 hour');
43620 assert.equal(moment(a).add({d: 1}).calendar(), 'भोलि दिउँसोको १२:०० बजे', 'tomorrow at the same time');
43621 assert.equal(moment(a).subtract({h: 1}).calendar(), 'आज बिहानको ११:०० बजे', 'Now minus 1 hour');
43622 assert.equal(moment(a).subtract({d: 1}).calendar(), 'हिजो दिउँसोको १२:०० बजे', 'yesterday at the same time');
43623 });
43624
43625 test('calendar next week', function (assert) {
43626 var i, m;
43627 for (i = 2; i < 7; i++) {
43628 m = moment().add({d: i});
43629 assert.equal(m.calendar(), m.format('[आउँदो] dddd[,] LT'), 'Today + ' + i + ' days current time');
43630 m.hours(0).minutes(0).seconds(0).milliseconds(0);
43631 assert.equal(m.calendar(), m.format('[आउँदो] dddd[,] LT'), 'Today + ' + i + ' days beginning of day');
43632 m.hours(23).minutes(59).seconds(59).milliseconds(999);
43633 assert.equal(m.calendar(), m.format('[आउँदो] dddd[,] LT'), 'Today + ' + i + ' days end of day');
73f3c911 43634 }
db71a655 43635 });
25cc720f 43636
db71a655
KM
43637 test('calendar last week', function (assert) {
43638 var i, m;
43639 for (i = 2; i < 7; i++) {
43640 m = moment().subtract({d: i});
43641 assert.equal(m.calendar(), m.format('[गएको] dddd[,] LT'), 'Today - ' + i + ' days current time');
43642 m.hours(0).minutes(0).seconds(0).milliseconds(0);
43643 assert.equal(m.calendar(), m.format('[गएको] dddd[,] LT'), 'Today - ' + i + ' days beginning of day');
43644 m.hours(23).minutes(59).seconds(59).milliseconds(999);
43645 assert.equal(m.calendar(), m.format('[गएको] dddd[,] LT'), 'Today - ' + i + ' days end of day');
25cc720f 43646 }
db71a655 43647 });
25cc720f 43648
db71a655
KM
43649 test('calendar all else', function (assert) {
43650 var weeksAgo = moment().subtract({w: 1}),
43651 weeksFromNow = moment().add({w: 1});
25cc720f 43652
db71a655
KM
43653 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
43654 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
25cc720f 43655
db71a655
KM
43656 weeksAgo = moment().subtract({w: 2});
43657 weeksFromNow = moment().add({w: 2});
25cc720f 43658
db71a655
KM
43659 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
43660 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
43661 });
25cc720f 43662
db71a655
KM
43663 test('meridiem', function (assert) {
43664 assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), 'राति', 'before dawn');
43665 assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), 'बिहान', 'morning');
43666 assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), 'दिउँसो', 'during day');
43667 assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), 'साँझ', 'evening');
43668 assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), 'साँझ', 'late evening');
43669 assert.equal(moment([2011, 2, 23, 21, 20]).format('a'), 'राति', 'night');
43670
43671 assert.equal(moment([2011, 2, 23, 2, 30]).format('A'), 'राति', 'before dawn');
43672 assert.equal(moment([2011, 2, 23, 9, 30]).format('A'), 'बिहान', 'morning');
43673 assert.equal(moment([2011, 2, 23, 14, 30]).format('A'), 'दिउँसो', 'during day');
43674 assert.equal(moment([2011, 2, 23, 17, 30]).format('A'), 'साँझ', 'evening');
43675 assert.equal(moment([2011, 2, 23, 19, 30]).format('A'), 'साँझ', 'late evening');
43676 assert.equal(moment([2011, 2, 23, 21, 20]).format('A'), 'राति', 'night');
43677 });
43678
43679 test('weeks year starting sunday formatted', function (assert) {
43680 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '५३ ५३ ५३', 'Dec 26 2011 should be week 53');
43681 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '१ ०१ १', 'Jan 1 2012 should be week 1');
43682 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '१ ०१ १', 'Jan 2 2012 should be week 1');
43683 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '२ ०२ २', 'Jan 8 2012 should be week 2');
43684 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '२ ०२ २', 'Jan 9 2012 should be week 2');
43685 });
73f3c911
IC
43686
43687})));
25cc720f 43688
25cc720f 43689
c74a101d
IC
43690;(function (global, factory) {
43691 typeof exports === 'object' && typeof module !== 'undefined'
43692 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
43693 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
43694 factory(global.moment)
73f3c911 43695}(this, (function (moment) { 'use strict';
516f5f67 43696
db71a655
KM
43697 function each(array, callback) {
43698 var i;
43699 for (i = 0; i < array.length; i++) {
43700 callback(array[i], i, array);
43701 }
b135bf1a
IC
43702 }
43703
c58511b9
KM
43704 function setupDeprecationHandler(test, moment$$1, scope) {
43705 test._expectedDeprecations = null;
43706 test._observedDeprecations = null;
43707 test._oldSupress = moment$$1.suppressDeprecationWarnings;
43708 moment$$1.suppressDeprecationWarnings = true;
43709 test.expectedDeprecations = function () {
43710 test._expectedDeprecations = arguments;
43711 test._observedDeprecations = [];
43712 };
43713 moment$$1.deprecationHandler = function (name, msg) {
43714 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
43715 if (deprecationId === -1) {
43716 throw new Error('Unexpected deprecation thrown name=' +
43717 name + ' msg=' + msg);
43718 }
43719 test._observedDeprecations[deprecationId] = 1;
43720 };
43721 }
43722
43723 function teardownDeprecationHandler(test, moment$$1, scope) {
43724 moment$$1.suppressDeprecationWarnings = test._oldSupress;
43725
43726 if (test._expectedDeprecations != null) {
43727 var missedDeprecations = [];
43728 each(test._expectedDeprecations, function (deprecationPattern, id) {
43729 if (test._observedDeprecations[id] !== 1) {
43730 missedDeprecations.push(deprecationPattern);
43731 }
43732 });
43733 if (missedDeprecations.length !== 0) {
43734 throw new Error('Expected deprecation warnings did not happen: ' +
43735 missedDeprecations.join(' '));
43736 }
43737 }
43738 }
43739
43740 function matchedDeprecation(name, msg, deprecations) {
43741 if (deprecations == null) {
43742 return -1;
43743 }
43744 for (var i = 0; i < deprecations.length; ++i) {
43745 if (name != null && name === deprecations[i]) {
43746 return i;
43747 }
43748 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
43749 return i;
43750 }
43751 }
43752 return -1;
43753 }
43754
43755 /*global QUnit:false*/
43756
43757 var test = QUnit.test;
43758
db71a655
KM
43759 function objectKeys(obj) {
43760 if (Object.keys) {
43761 return Object.keys(obj);
43762 } else {
43763 // IE8
43764 var res = [], i;
43765 for (i in obj) {
43766 if (obj.hasOwnProperty(i)) {
43767 res.push(i);
43768 }
b135bf1a 43769 }
db71a655 43770 return res;
b135bf1a 43771 }
b135bf1a
IC
43772 }
43773
db71a655 43774 // Pick the first defined of two or three arguments.
b135bf1a 43775
db71a655
KM
43776 function defineCommonLocaleTests(locale, options) {
43777 test('lenient day of month ordinal parsing', function (assert) {
43778 var i, ordinalStr, testMoment;
43779 for (i = 1; i <= 31; ++i) {
43780 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
43781 testMoment = moment(ordinalStr, 'YYYY MM Do');
43782 assert.equal(testMoment.year(), 2014,
43783 'lenient day of month ordinal parsing ' + i + ' year check');
43784 assert.equal(testMoment.month(), 0,
43785 'lenient day of month ordinal parsing ' + i + ' month check');
43786 assert.equal(testMoment.date(), i,
43787 'lenient day of month ordinal parsing ' + i + ' date check');
43788 }
43789 });
b135bf1a 43790
db71a655
KM
43791 test('lenient day of month ordinal parsing of number', function (assert) {
43792 var i, testMoment;
43793 for (i = 1; i <= 31; ++i) {
43794 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
43795 assert.equal(testMoment.year(), 2014,
43796 'lenient day of month ordinal parsing of number ' + i + ' year check');
43797 assert.equal(testMoment.month(), 0,
43798 'lenient day of month ordinal parsing of number ' + i + ' month check');
43799 assert.equal(testMoment.date(), i,
43800 'lenient day of month ordinal parsing of number ' + i + ' date check');
43801 }
43802 });
b135bf1a 43803
db71a655
KM
43804 test('strict day of month ordinal parsing', function (assert) {
43805 var i, ordinalStr, testMoment;
43806 for (i = 1; i <= 31; ++i) {
43807 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
43808 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
43809 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
43810 }
43811 });
b135bf1a 43812
db71a655
KM
43813 test('meridiem invariant', function (assert) {
43814 var h, m, t1, t2;
43815 for (h = 0; h < 24; ++h) {
43816 for (m = 0; m < 60; m += 15) {
43817 t1 = moment.utc([2000, 0, 1, h, m]);
43818 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
43819 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
43820 'meridiem at ' + t1.format('HH:mm'));
43821 }
43822 }
43823 });
43824
43825 test('date format correctness', function (assert) {
43826 var data, tokens;
43827 data = moment.localeData()._longDateFormat;
43828 tokens = objectKeys(data);
43829 each(tokens, function (srchToken) {
43830 // Check each format string to make sure it does not contain any
43831 // tokens that need to be expanded.
43832 each(tokens, function (baseToken) {
43833 // strip escaped sequences
43834 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
43835 assert.equal(false, !!~format.indexOf(srchToken),
43836 'contains ' + srchToken + ' in ' + baseToken);
43837 });
b135bf1a
IC
43838 });
43839 });
d6651c21 43840
db71a655
KM
43841 test('month parsing correctness', function (assert) {
43842 var i, m;
43843
43844 if (locale === 'tr') {
43845 // I can't fix it :(
c58511b9 43846 assert.expect(0);
db71a655
KM
43847 return;
43848 }
43849 function tester(format) {
43850 var r;
43851 r = moment(m.format(format), format);
43852 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
43853 if (locale !== 'ka') {
43854 r = moment(m.format(format).toLocaleUpperCase(), format);
43855 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
43856 }
db71a655
KM
43857 r = moment(m.format(format).toLocaleLowerCase(), format);
43858 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
43859
43860 r = moment(m.format(format), format, true);
43861 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
43862 if (locale !== 'ka') {
43863 r = moment(m.format(format).toLocaleUpperCase(), format, true);
43864 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
43865 }
db71a655
KM
43866 r = moment(m.format(format).toLocaleLowerCase(), format, true);
43867 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
43868 }
43869
43870 for (i = 0; i < 12; ++i) {
43871 m = moment([2015, i, 15, 18]);
43872 tester('MMM');
43873 tester('MMM.');
43874 tester('MMMM');
43875 tester('MMMM.');
43876 }
43877 });
43878
43879 test('weekday parsing correctness', function (assert) {
43880 var i, m;
43881
96d0d679 43882 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
43883 // tr, az: There is a lower-case letter (ı), that converted to
43884 // upper then lower changes to i
43885 // ro: there is the letter ț which behaves weird under IE8
43886 // mt: letter Ħ
96d0d679 43887 // ga: month with spaces
c58511b9 43888 assert.expect(0);
db71a655
KM
43889 return;
43890 }
43891 function tester(format) {
43892 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
43893 r = moment(m.format(format), format);
43894 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
43895 if (locale !== 'ka') {
43896 r = moment(m.format(format).toLocaleUpperCase(), format);
43897 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
43898 }
db71a655
KM
43899 r = moment(m.format(format).toLocaleLowerCase(), format);
43900 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
43901 r = moment(m.format(format), format, true);
43902 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
43903 if (locale !== 'ka') {
43904 r = moment(m.format(format).toLocaleUpperCase(), format, true);
43905 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
43906 }
db71a655
KM
43907 r = moment(m.format(format).toLocaleLowerCase(), format, true);
43908 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
43909 }
43910
43911 for (i = 0; i < 7; ++i) {
43912 m = moment.utc([2015, 0, i + 1, 18]);
43913 tester('dd');
43914 tester('ddd');
43915 tester('dddd');
43916 }
43917 });
43918
43919 test('valid localeData', function (assert) {
43920 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
43921 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
43922 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
43923 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
43924 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
43925 });
96d0d679
KM
43926
43927 test('localeData weekdays can localeSort', function (assert) {
43928 var weekdays = moment().localeData().weekdays();
43929 var weekdaysShort = moment().localeData().weekdaysShort();
43930 var weekdaysMin = moment().localeData().weekdaysMin();
43931 var shift = moment().localeData()._week.dow;
43932 assert.deepEqual(
43933 moment().localeData().weekdays(true),
43934 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
43935 'weekdays should localeSort');
43936 assert.deepEqual(
43937 moment().localeData().weekdaysShort(true),
43938 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
43939 'weekdaysShort should localeSort');
43940 assert.deepEqual(
43941 moment().localeData().weekdaysMin(true),
43942 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
43943 'weekdaysMin should localeSort');
43944 });
db71a655 43945 }
d6651c21 43946
db71a655
KM
43947 /*global QUnit:false*/
43948
db71a655
KM
43949 function localeModule (name, lifecycle) {
43950 QUnit.module('locale:' + name, {
c58511b9 43951 beforeEach : function () {
db71a655
KM
43952 moment.locale(name);
43953 moment.createFromInputFallback = function (config) {
43954 throw new Error('input not handled by moment: ' + config._i);
43955 };
43956 setupDeprecationHandler(test, moment, 'locale');
43957 if (lifecycle && lifecycle.setup) {
43958 lifecycle.setup();
43959 }
43960 },
c58511b9 43961 afterEach : function () {
db71a655
KM
43962 moment.locale('en');
43963 teardownDeprecationHandler(test, moment, 'locale');
43964 if (lifecycle && lifecycle.teardown) {
43965 lifecycle.teardown();
43966 }
516f5f67
IC
43967 }
43968 });
db71a655
KM
43969 defineCommonLocaleTests(name, -1, -1);
43970 }
43971
43972 localeModule('nl-be');
43973
43974 test('parse', function (assert) {
43975 var tests = 'januari jan._februari feb._maart mrt._april apr._mei mei._juni jun._juli jul._augustus aug._september sep._oktober okt._november nov._december dec.'.split('_'), i;
43976 function equalTest(input, mmm, i) {
43977 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
43978 }
43979 for (i = 0; i < 12; i++) {
43980 tests[i] = tests[i].split(' ');
43981 equalTest(tests[i][0], 'MMM', i);
43982 equalTest(tests[i][1], 'MMM', i);
43983 equalTest(tests[i][0], 'MMMM', i);
43984 equalTest(tests[i][1], 'MMMM', i);
43985 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
43986 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
43987 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
43988 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
43989 }
43990 });
43991
43992 test('format', function (assert) {
43993 var a = [
43994 ['dddd, MMMM Do YYYY, HH:mm:ss', 'zondag, februari 14de 2010, 15:25:50'],
43995 ['ddd, HH', 'zo., 15'],
43996 ['M Mo MM MMMM MMM', '2 2de 02 februari feb.'],
43997 ['YYYY YY', '2010 10'],
43998 ['D Do DD', '14 14de 14'],
43999 ['d do dddd ddd dd', '0 0de zondag zo. zo'],
44000 ['DDD DDDo DDDD', '45 45ste 045'],
44001 ['w wo ww', '6 6de 06'],
44002 ['h hh', '3 03'],
44003 ['H HH', '15 15'],
44004 ['m mm', '25 25'],
44005 ['s ss', '50 50'],
44006 ['a A', 'pm PM'],
44007 ['[the] DDDo [day of the year]', 'the 45ste day of the year'],
44008 ['LTS', '15:25:50'],
44009 ['L', '14/02/2010'],
44010 ['LL', '14 februari 2010'],
44011 ['LLL', '14 februari 2010 15:25'],
44012 ['LLLL', 'zondag 14 februari 2010 15:25'],
44013 ['l', '14/2/2010'],
44014 ['ll', '14 feb. 2010'],
44015 ['lll', '14 feb. 2010 15:25'],
44016 ['llll', 'zo. 14 feb. 2010 15:25']
44017 ],
44018 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
44019 i;
44020 for (i = 0; i < a.length; i++) {
44021 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
44022 }
44023 });
44024
44025 test('format ordinal', function (assert) {
44026 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1ste', '1ste');
44027 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2de', '2de');
44028 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3de', '3de');
44029 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4de', '4de');
44030 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5de', '5de');
44031 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6de', '6de');
44032 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7de', '7de');
44033 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8ste', '8ste');
44034 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9de', '9de');
44035 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10de', '10de');
44036
44037 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11de', '11de');
44038 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12de', '12de');
44039 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13de', '13de');
44040 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14de', '14de');
44041 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15de', '15de');
44042 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16de', '16de');
44043 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17de', '17de');
44044 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18de', '18de');
44045 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19de', '19de');
44046 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20ste', '20ste');
44047
44048 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21ste', '21ste');
44049 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22ste', '22ste');
44050 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23ste', '23ste');
44051 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24ste', '24ste');
44052 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25ste', '25ste');
44053 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26ste', '26ste');
44054 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27ste', '27ste');
44055 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28ste', '28ste');
44056 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29ste', '29ste');
44057 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30ste', '30ste');
44058
44059 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31ste', '31ste');
44060 });
44061
44062 test('format month', function (assert) {
44063 var expected = 'januari jan._februari feb._maart mrt._april apr._mei mei_juni jun._juli jul._augustus aug._september sep._oktober okt._november nov._december dec.'.split('_'), i;
44064 for (i = 0; i < expected.length; i++) {
44065 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
44066 }
44067 });
44068
44069 test('format week', function (assert) {
44070 var expected = 'zondag zo. zo_maandag ma. ma_dinsdag di. di_woensdag wo. wo_donderdag do. do_vrijdag vr. vr_zaterdag za. za'.split('_'), i;
44071 for (i = 0; i < expected.length; i++) {
44072 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
44073 }
44074 });
44075
44076 test('from', function (assert) {
44077 var start = moment([2007, 1, 28]);
44078 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'een paar seconden', '44 seconds = a few seconds');
44079 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'één minuut', '45 seconds = a minute');
44080 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'één minuut', '89 seconds = a minute');
44081 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuten', '90 seconds = 2 minutes');
44082 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuten', '44 minutes = 44 minutes');
44083 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'één uur', '45 minutes = an hour');
44084 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'één uur', '89 minutes = an hour');
44085 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 uur', '90 minutes = 2 hours');
44086 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 uur', '5 hours = 5 hours');
44087 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 uur', '21 hours = 21 hours');
44088 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'één dag', '22 hours = a day');
44089 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'één dag', '35 hours = a day');
44090 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dagen', '36 hours = 2 days');
44091 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'één dag', '1 day = a day');
44092 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dagen', '5 days = 5 days');
44093 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dagen', '25 days = 25 days');
44094 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'één maand', '26 days = a month');
44095 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'één maand', '30 days = a month');
44096 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'één maand', '43 days = a month');
44097 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 maanden', '46 days = 2 months');
44098 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 maanden', '75 days = 2 months');
44099 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 maanden', '76 days = 3 months');
44100 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'één maand', '1 month = a month');
44101 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 maanden', '5 months = 5 months');
44102 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'één jaar', '345 days = a year');
44103 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 jaar', '548 days = 2 years');
44104 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'één jaar', '1 year = a year');
44105 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 jaar', '5 years = 5 years');
44106 });
44107
44108 test('suffix', function (assert) {
44109 assert.equal(moment(30000).from(0), 'over een paar seconden', 'prefix');
44110 assert.equal(moment(0).from(30000), 'een paar seconden geleden', 'suffix');
44111 });
44112
44113 test('now from now', function (assert) {
44114 assert.equal(moment().fromNow(), 'een paar seconden geleden', 'now from now should display as in the past');
44115 });
44116
44117 test('fromNow', function (assert) {
44118 assert.equal(moment().add({s: 30}).fromNow(), 'over een paar seconden', 'in a few seconds');
44119 assert.equal(moment().add({d: 5}).fromNow(), 'over 5 dagen', 'in 5 days');
44120 });
44121
44122 test('calendar day', function (assert) {
44123 var a = moment().hours(12).minutes(0).seconds(0);
44124
44125 assert.equal(moment(a).calendar(), 'vandaag om 12:00', 'today at the same time');
44126 assert.equal(moment(a).add({m: 25}).calendar(), 'vandaag om 12:25', 'Now plus 25 min');
44127 assert.equal(moment(a).add({h: 1}).calendar(), 'vandaag om 13:00', 'Now plus 1 hour');
44128 assert.equal(moment(a).add({d: 1}).calendar(), 'morgen om 12:00', 'tomorrow at the same time');
44129 assert.equal(moment(a).subtract({h: 1}).calendar(), 'vandaag om 11:00', 'Now minus 1 hour');
44130 assert.equal(moment(a).subtract({d: 1}).calendar(), 'gisteren om 12:00', 'yesterday at the same time');
44131 });
44132
44133 test('calendar next week', function (assert) {
44134 var i, m;
44135 for (i = 2; i < 7; i++) {
44136 m = moment().add({d: i});
44137 assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days current time');
44138 m.hours(0).minutes(0).seconds(0).milliseconds(0);
44139 assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days beginning of day');
44140 m.hours(23).minutes(59).seconds(59).milliseconds(999);
44141 assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days end of day');
73f3c911 44142 }
db71a655 44143 });
516f5f67 44144
db71a655
KM
44145 test('calendar last week', function (assert) {
44146 var i, m;
44147 for (i = 2; i < 7; i++) {
44148 m = moment().subtract({d: i});
44149 assert.equal(m.calendar(), m.format('[afgelopen] dddd [om] LT'), 'Today - ' + i + ' days current time');
44150 m.hours(0).minutes(0).seconds(0).milliseconds(0);
44151 assert.equal(m.calendar(), m.format('[afgelopen] dddd [om] LT'), 'Today - ' + i + ' days beginning of day');
44152 m.hours(23).minutes(59).seconds(59).milliseconds(999);
44153 assert.equal(m.calendar(), m.format('[afgelopen] dddd [om] LT'), 'Today - ' + i + ' days end of day');
516f5f67 44154 }
db71a655 44155 });
516f5f67 44156
db71a655
KM
44157 test('calendar all else', function (assert) {
44158 var weeksAgo = moment().subtract({w: 1}),
44159 weeksFromNow = moment().add({w: 1});
d6651c21 44160
db71a655
KM
44161 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
44162 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
d6651c21 44163
db71a655
KM
44164 weeksAgo = moment().subtract({w: 2});
44165 weeksFromNow = moment().add({w: 2});
d6651c21 44166
db71a655
KM
44167 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
44168 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
44169 });
44170
44171 test('month abbreviation', function (assert) {
44172 assert.equal(moment([2012, 5, 23]).format('D-MMM-YYYY'), '23-jun-2012', 'format month abbreviation surrounded by dashes should not include a dot');
44173 assert.equal(moment([2012, 5, 23]).unix(), moment('23-jun-2012', 'D-MMM-YYYY').unix(), 'parse month abbreviation surrounded by dashes without dot');
44174 assert.equal(moment([2012, 5, 23]).format('D MMM YYYY'), '23 jun. 2012', 'format month abbreviation not surrounded by dashes should include a dot');
44175 assert.equal(moment([2012, 5, 23]).unix(), moment('23 jun. 2012', 'D MMM YYYY').unix(), 'parse month abbreviation not surrounded by dashes with dot');
44176 });
44177
44178 test('weeks year starting sunday formatted', function (assert) {
44179 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52ste', 'Jan 1 2012 should be week 52');
44180 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1ste', 'Jan 2 2012 should be week 1');
44181 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1ste', 'Jan 8 2012 should be week 1');
44182 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2de', 'Jan 9 2012 should be week 2');
44183 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2de', 'Jan 15 2012 should be week 2');
44184 });
73f3c911
IC
44185
44186})));
44187
516f5f67 44188
c74a101d
IC
44189;(function (global, factory) {
44190 typeof exports === 'object' && typeof module !== 'undefined'
44191 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
44192 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
44193 factory(global.moment)
73f3c911 44194}(this, (function (moment) { 'use strict';
516f5f67 44195
db71a655
KM
44196 function each(array, callback) {
44197 var i;
44198 for (i = 0; i < array.length; i++) {
44199 callback(array[i], i, array);
44200 }
b135bf1a
IC
44201 }
44202
c58511b9
KM
44203 function setupDeprecationHandler(test, moment$$1, scope) {
44204 test._expectedDeprecations = null;
44205 test._observedDeprecations = null;
44206 test._oldSupress = moment$$1.suppressDeprecationWarnings;
44207 moment$$1.suppressDeprecationWarnings = true;
44208 test.expectedDeprecations = function () {
44209 test._expectedDeprecations = arguments;
44210 test._observedDeprecations = [];
44211 };
44212 moment$$1.deprecationHandler = function (name, msg) {
44213 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
44214 if (deprecationId === -1) {
44215 throw new Error('Unexpected deprecation thrown name=' +
44216 name + ' msg=' + msg);
44217 }
44218 test._observedDeprecations[deprecationId] = 1;
44219 };
44220 }
44221
44222 function teardownDeprecationHandler(test, moment$$1, scope) {
44223 moment$$1.suppressDeprecationWarnings = test._oldSupress;
44224
44225 if (test._expectedDeprecations != null) {
44226 var missedDeprecations = [];
44227 each(test._expectedDeprecations, function (deprecationPattern, id) {
44228 if (test._observedDeprecations[id] !== 1) {
44229 missedDeprecations.push(deprecationPattern);
44230 }
44231 });
44232 if (missedDeprecations.length !== 0) {
44233 throw new Error('Expected deprecation warnings did not happen: ' +
44234 missedDeprecations.join(' '));
44235 }
44236 }
44237 }
44238
44239 function matchedDeprecation(name, msg, deprecations) {
44240 if (deprecations == null) {
44241 return -1;
44242 }
44243 for (var i = 0; i < deprecations.length; ++i) {
44244 if (name != null && name === deprecations[i]) {
44245 return i;
44246 }
44247 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
44248 return i;
44249 }
44250 }
44251 return -1;
44252 }
44253
44254 /*global QUnit:false*/
44255
44256 var test = QUnit.test;
44257
db71a655
KM
44258 function objectKeys(obj) {
44259 if (Object.keys) {
44260 return Object.keys(obj);
44261 } else {
44262 // IE8
44263 var res = [], i;
44264 for (i in obj) {
44265 if (obj.hasOwnProperty(i)) {
44266 res.push(i);
44267 }
b135bf1a 44268 }
db71a655 44269 return res;
b135bf1a 44270 }
b135bf1a 44271 }
b135bf1a 44272
db71a655 44273 // Pick the first defined of two or three arguments.
b135bf1a 44274
db71a655
KM
44275 function defineCommonLocaleTests(locale, options) {
44276 test('lenient day of month ordinal parsing', function (assert) {
44277 var i, ordinalStr, testMoment;
44278 for (i = 1; i <= 31; ++i) {
44279 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
44280 testMoment = moment(ordinalStr, 'YYYY MM Do');
44281 assert.equal(testMoment.year(), 2014,
44282 'lenient day of month ordinal parsing ' + i + ' year check');
44283 assert.equal(testMoment.month(), 0,
44284 'lenient day of month ordinal parsing ' + i + ' month check');
44285 assert.equal(testMoment.date(), i,
44286 'lenient day of month ordinal parsing ' + i + ' date check');
44287 }
44288 });
b135bf1a 44289
db71a655
KM
44290 test('lenient day of month ordinal parsing of number', function (assert) {
44291 var i, testMoment;
44292 for (i = 1; i <= 31; ++i) {
44293 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
44294 assert.equal(testMoment.year(), 2014,
44295 'lenient day of month ordinal parsing of number ' + i + ' year check');
44296 assert.equal(testMoment.month(), 0,
44297 'lenient day of month ordinal parsing of number ' + i + ' month check');
44298 assert.equal(testMoment.date(), i,
44299 'lenient day of month ordinal parsing of number ' + i + ' date check');
44300 }
b135bf1a 44301 });
d6651c21 44302
db71a655
KM
44303 test('strict day of month ordinal parsing', function (assert) {
44304 var i, ordinalStr, testMoment;
44305 for (i = 1; i <= 31; ++i) {
44306 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
44307 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
44308 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
44309 }
44310 });
c587bf00 44311
db71a655
KM
44312 test('meridiem invariant', function (assert) {
44313 var h, m, t1, t2;
44314 for (h = 0; h < 24; ++h) {
44315 for (m = 0; m < 60; m += 15) {
44316 t1 = moment.utc([2000, 0, 1, h, m]);
44317 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
44318 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
44319 'meridiem at ' + t1.format('HH:mm'));
44320 }
44321 }
44322 });
c587bf00 44323
db71a655
KM
44324 test('date format correctness', function (assert) {
44325 var data, tokens;
44326 data = moment.localeData()._longDateFormat;
44327 tokens = objectKeys(data);
44328 each(tokens, function (srchToken) {
44329 // Check each format string to make sure it does not contain any
44330 // tokens that need to be expanded.
44331 each(tokens, function (baseToken) {
44332 // strip escaped sequences
44333 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
44334 assert.equal(false, !!~format.indexOf(srchToken),
44335 'contains ' + srchToken + ' in ' + baseToken);
44336 });
44337 });
44338 });
c587bf00 44339
db71a655
KM
44340 test('month parsing correctness', function (assert) {
44341 var i, m;
44342
44343 if (locale === 'tr') {
44344 // I can't fix it :(
c58511b9 44345 assert.expect(0);
db71a655
KM
44346 return;
44347 }
44348 function tester(format) {
44349 var r;
44350 r = moment(m.format(format), format);
44351 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
44352 if (locale !== 'ka') {
44353 r = moment(m.format(format).toLocaleUpperCase(), format);
44354 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
44355 }
db71a655
KM
44356 r = moment(m.format(format).toLocaleLowerCase(), format);
44357 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
44358
44359 r = moment(m.format(format), format, true);
44360 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
44361 if (locale !== 'ka') {
44362 r = moment(m.format(format).toLocaleUpperCase(), format, true);
44363 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
44364 }
db71a655
KM
44365 r = moment(m.format(format).toLocaleLowerCase(), format, true);
44366 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
44367 }
44368
44369 for (i = 0; i < 12; ++i) {
44370 m = moment([2015, i, 15, 18]);
44371 tester('MMM');
44372 tester('MMM.');
44373 tester('MMMM');
44374 tester('MMMM.');
44375 }
44376 });
73f3c911 44377
db71a655
KM
44378 test('weekday parsing correctness', function (assert) {
44379 var i, m;
44380
96d0d679 44381 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
44382 // tr, az: There is a lower-case letter (ı), that converted to
44383 // upper then lower changes to i
44384 // ro: there is the letter ț which behaves weird under IE8
44385 // mt: letter Ħ
96d0d679 44386 // ga: month with spaces
c58511b9 44387 assert.expect(0);
db71a655
KM
44388 return;
44389 }
44390 function tester(format) {
44391 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
44392 r = moment(m.format(format), format);
44393 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
44394 if (locale !== 'ka') {
44395 r = moment(m.format(format).toLocaleUpperCase(), format);
44396 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
44397 }
db71a655
KM
44398 r = moment(m.format(format).toLocaleLowerCase(), format);
44399 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
44400 r = moment(m.format(format), format, true);
44401 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
44402 if (locale !== 'ka') {
44403 r = moment(m.format(format).toLocaleUpperCase(), format, true);
44404 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
44405 }
db71a655
KM
44406 r = moment(m.format(format).toLocaleLowerCase(), format, true);
44407 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
44408 }
44409
44410 for (i = 0; i < 7; ++i) {
44411 m = moment.utc([2015, 0, i + 1, 18]);
44412 tester('dd');
44413 tester('ddd');
44414 tester('dddd');
44415 }
44416 });
c587bf00 44417
db71a655
KM
44418 test('valid localeData', function (assert) {
44419 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
44420 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
44421 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
44422 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
44423 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
44424 });
96d0d679
KM
44425
44426 test('localeData weekdays can localeSort', function (assert) {
44427 var weekdays = moment().localeData().weekdays();
44428 var weekdaysShort = moment().localeData().weekdaysShort();
44429 var weekdaysMin = moment().localeData().weekdaysMin();
44430 var shift = moment().localeData()._week.dow;
44431 assert.deepEqual(
44432 moment().localeData().weekdays(true),
44433 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
44434 'weekdays should localeSort');
44435 assert.deepEqual(
44436 moment().localeData().weekdaysShort(true),
44437 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
44438 'weekdaysShort should localeSort');
44439 assert.deepEqual(
44440 moment().localeData().weekdaysMin(true),
44441 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
44442 'weekdaysMin should localeSort');
44443 });
db71a655 44444 }
c587bf00 44445
db71a655 44446 /*global QUnit:false*/
c587bf00 44447
db71a655
KM
44448 function localeModule (name, lifecycle) {
44449 QUnit.module('locale:' + name, {
c58511b9 44450 beforeEach : function () {
db71a655
KM
44451 moment.locale(name);
44452 moment.createFromInputFallback = function (config) {
44453 throw new Error('input not handled by moment: ' + config._i);
44454 };
44455 setupDeprecationHandler(test, moment, 'locale');
44456 if (lifecycle && lifecycle.setup) {
44457 lifecycle.setup();
44458 }
44459 },
c58511b9 44460 afterEach : function () {
db71a655
KM
44461 moment.locale('en');
44462 teardownDeprecationHandler(test, moment, 'locale');
44463 if (lifecycle && lifecycle.teardown) {
44464 lifecycle.teardown();
44465 }
73f3c911 44466 }
db71a655
KM
44467 });
44468 defineCommonLocaleTests(name, -1, -1);
44469 }
44470
44471 localeModule('nl');
44472
44473 test('parse', function (assert) {
44474 var tests = 'januari jan._februari feb._maart mrt._april apr._mei mei._juni jun._juli jul._augustus aug._september sep._oktober okt._november nov._december dec.'.split('_'), i;
44475 function equalTest(input, mmm, i) {
44476 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
44477 }
44478 for (i = 0; i < 12; i++) {
44479 tests[i] = tests[i].split(' ');
44480 equalTest(tests[i][0], 'MMM', i);
44481 equalTest(tests[i][1], 'MMM', i);
44482 equalTest(tests[i][0], 'MMMM', i);
44483 equalTest(tests[i][1], 'MMMM', i);
44484 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
44485 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
44486 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
44487 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
44488 }
44489 });
44490
44491 test('format', function (assert) {
44492 var a = [
44493 ['dddd, MMMM Do YYYY, HH:mm:ss', 'zondag, februari 14de 2010, 15:25:50'],
44494 ['ddd, HH', 'zo., 15'],
44495 ['M Mo MM MMMM MMM', '2 2de 02 februari feb.'],
44496 ['YYYY YY', '2010 10'],
44497 ['D Do DD', '14 14de 14'],
44498 ['d do dddd ddd dd', '0 0de zondag zo. zo'],
44499 ['DDD DDDo DDDD', '45 45ste 045'],
44500 ['w wo ww', '6 6de 06'],
44501 ['h hh', '3 03'],
44502 ['H HH', '15 15'],
44503 ['m mm', '25 25'],
44504 ['s ss', '50 50'],
44505 ['a A', 'pm PM'],
44506 ['[the] DDDo [day of the year]', 'the 45ste day of the year'],
44507 ['LTS', '15:25:50'],
44508 ['L', '14-02-2010'],
44509 ['LL', '14 februari 2010'],
44510 ['LLL', '14 februari 2010 15:25'],
44511 ['LLLL', 'zondag 14 februari 2010 15:25'],
44512 ['l', '14-2-2010'],
44513 ['ll', '14 feb. 2010'],
44514 ['lll', '14 feb. 2010 15:25'],
44515 ['llll', 'zo. 14 feb. 2010 15:25']
44516 ],
44517 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
44518 i;
44519 for (i = 0; i < a.length; i++) {
44520 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
44521 }
44522 });
44523
44524 test('format ordinal', function (assert) {
44525 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1ste', '1ste');
44526 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2de', '2de');
44527 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3de', '3de');
44528 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4de', '4de');
44529 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5de', '5de');
44530 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6de', '6de');
44531 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7de', '7de');
44532 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8ste', '8ste');
44533 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9de', '9de');
44534 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10de', '10de');
44535
44536 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11de', '11de');
44537 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12de', '12de');
44538 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13de', '13de');
44539 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14de', '14de');
44540 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15de', '15de');
44541 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16de', '16de');
44542 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17de', '17de');
44543 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18de', '18de');
44544 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19de', '19de');
44545 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20ste', '20ste');
44546
44547 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21ste', '21ste');
44548 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22ste', '22ste');
44549 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23ste', '23ste');
44550 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24ste', '24ste');
44551 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25ste', '25ste');
44552 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26ste', '26ste');
44553 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27ste', '27ste');
44554 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28ste', '28ste');
44555 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29ste', '29ste');
44556 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30ste', '30ste');
44557
44558 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31ste', '31ste');
44559 });
44560
44561 test('format month', function (assert) {
44562 var expected = 'januari jan._februari feb._maart mrt._april apr._mei mei_juni jun._juli jul._augustus aug._september sep._oktober okt._november nov._december dec.'.split('_'), i;
44563 for (i = 0; i < expected.length; i++) {
44564 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
44565 }
44566 });
44567
44568 test('format week', function (assert) {
44569 var expected = 'zondag zo. zo_maandag ma. ma_dinsdag di. di_woensdag wo. wo_donderdag do. do_vrijdag vr. vr_zaterdag za. za'.split('_'), i;
44570 for (i = 0; i < expected.length; i++) {
44571 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
44572 }
44573 });
44574
44575 test('from', function (assert) {
44576 var start = moment([2007, 1, 28]);
44577 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'een paar seconden', '44 seconds = a few seconds');
44578 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'één minuut', '45 seconds = a minute');
44579 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'één minuut', '89 seconds = a minute');
44580 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuten', '90 seconds = 2 minutes');
44581 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuten', '44 minutes = 44 minutes');
44582 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'één uur', '45 minutes = an hour');
44583 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'één uur', '89 minutes = an hour');
44584 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 uur', '90 minutes = 2 hours');
44585 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 uur', '5 hours = 5 hours');
44586 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 uur', '21 hours = 21 hours');
44587 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'één dag', '22 hours = a day');
44588 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'één dag', '35 hours = a day');
44589 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dagen', '36 hours = 2 days');
44590 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'één dag', '1 day = a day');
44591 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dagen', '5 days = 5 days');
44592 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dagen', '25 days = 25 days');
44593 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'één maand', '26 days = a month');
44594 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'één maand', '30 days = a month');
44595 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'één maand', '43 days = a month');
44596 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 maanden', '46 days = 2 months');
44597 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 maanden', '75 days = 2 months');
44598 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 maanden', '76 days = 3 months');
44599 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'één maand', '1 month = a month');
44600 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 maanden', '5 months = 5 months');
44601 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'één jaar', '345 days = a year');
44602 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 jaar', '548 days = 2 years');
44603 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'één jaar', '1 year = a year');
44604 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 jaar', '5 years = 5 years');
44605 });
44606
44607 test('suffix', function (assert) {
44608 assert.equal(moment(30000).from(0), 'over een paar seconden', 'prefix');
44609 assert.equal(moment(0).from(30000), 'een paar seconden geleden', 'suffix');
44610 });
44611
44612 test('now from now', function (assert) {
44613 assert.equal(moment().fromNow(), 'een paar seconden geleden', 'now from now should display as in the past');
44614 });
44615
44616 test('fromNow', function (assert) {
44617 assert.equal(moment().add({s: 30}).fromNow(), 'over een paar seconden', 'in a few seconds');
44618 assert.equal(moment().add({d: 5}).fromNow(), 'over 5 dagen', 'in 5 days');
44619 });
44620
44621 test('calendar day', function (assert) {
44622 var a = moment().hours(12).minutes(0).seconds(0);
44623
44624 assert.equal(moment(a).calendar(), 'vandaag om 12:00', 'today at the same time');
44625 assert.equal(moment(a).add({m: 25}).calendar(), 'vandaag om 12:25', 'Now plus 25 min');
44626 assert.equal(moment(a).add({h: 1}).calendar(), 'vandaag om 13:00', 'Now plus 1 hour');
44627 assert.equal(moment(a).add({d: 1}).calendar(), 'morgen om 12:00', 'tomorrow at the same time');
44628 assert.equal(moment(a).subtract({h: 1}).calendar(), 'vandaag om 11:00', 'Now minus 1 hour');
44629 assert.equal(moment(a).subtract({d: 1}).calendar(), 'gisteren om 12:00', 'yesterday at the same time');
44630 });
44631
44632 test('calendar next week', function (assert) {
44633 var i, m;
44634 for (i = 2; i < 7; i++) {
44635 m = moment().add({d: i});
44636 assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days current time');
44637 m.hours(0).minutes(0).seconds(0).milliseconds(0);
44638 assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days beginning of day');
44639 m.hours(23).minutes(59).seconds(59).milliseconds(999);
44640 assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days end of day');
c587bf00
IC
44641 }
44642 });
44643
db71a655
KM
44644 test('calendar last week', function (assert) {
44645 var i, m;
44646 for (i = 2; i < 7; i++) {
44647 m = moment().subtract({d: i});
44648 assert.equal(m.calendar(), m.format('[afgelopen] dddd [om] LT'), 'Today - ' + i + ' days current time');
44649 m.hours(0).minutes(0).seconds(0).milliseconds(0);
44650 assert.equal(m.calendar(), m.format('[afgelopen] dddd [om] LT'), 'Today - ' + i + ' days beginning of day');
44651 m.hours(23).minutes(59).seconds(59).milliseconds(999);
44652 assert.equal(m.calendar(), m.format('[afgelopen] dddd [om] LT'), 'Today - ' + i + ' days end of day');
44653 }
44654 });
c587bf00 44655
db71a655
KM
44656 test('calendar all else', function (assert) {
44657 var weeksAgo = moment().subtract({w: 1}),
44658 weeksFromNow = moment().add({w: 1});
c587bf00 44659
db71a655
KM
44660 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
44661 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
c587bf00 44662
db71a655
KM
44663 weeksAgo = moment().subtract({w: 2});
44664 weeksFromNow = moment().add({w: 2});
c587bf00 44665
db71a655
KM
44666 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
44667 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
44668 });
44669
44670 test('month abbreviation', function (assert) {
44671 assert.equal(moment([2012, 5, 23]).format('D-MMM-YYYY'), '23-jun-2012', 'format month abbreviation surrounded by dashes should not include a dot');
44672 assert.equal(moment([2012, 5, 23]).unix(), moment('23-jun-2012', 'D-MMM-YYYY').unix(), 'parse month abbreviation surrounded by dashes without dot');
44673 assert.equal(moment([2012, 5, 23]).format('D MMM YYYY'), '23 jun. 2012', 'format month abbreviation not surrounded by dashes should include a dot');
44674 assert.equal(moment([2012, 5, 23]).unix(), moment('23 jun. 2012', 'D MMM YYYY').unix(), 'parse month abbreviation not surrounded by dashes with dot');
44675 });
44676
44677 test('weeks year starting sunday formatted', function (assert) {
44678 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52ste', 'Jan 1 2012 should be week 52');
44679 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1ste', 'Jan 2 2012 should be week 1');
44680 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1ste', 'Jan 8 2012 should be week 1');
44681 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2de', 'Jan 9 2012 should be week 2');
44682 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2de', 'Jan 15 2012 should be week 2');
44683 });
73f3c911
IC
44684
44685})));
c587bf00 44686
c587bf00
IC
44687
44688;(function (global, factory) {
44689 typeof exports === 'object' && typeof module !== 'undefined'
44690 && typeof require === 'function' ? factory(require('../../moment')) :
44691 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
44692 factory(global.moment)
73f3c911 44693}(this, (function (moment) { 'use strict';
c587bf00 44694
db71a655
KM
44695 function each(array, callback) {
44696 var i;
44697 for (i = 0; i < array.length; i++) {
44698 callback(array[i], i, array);
44699 }
c587bf00
IC
44700 }
44701
c58511b9
KM
44702 function setupDeprecationHandler(test, moment$$1, scope) {
44703 test._expectedDeprecations = null;
44704 test._observedDeprecations = null;
44705 test._oldSupress = moment$$1.suppressDeprecationWarnings;
44706 moment$$1.suppressDeprecationWarnings = true;
44707 test.expectedDeprecations = function () {
44708 test._expectedDeprecations = arguments;
44709 test._observedDeprecations = [];
44710 };
44711 moment$$1.deprecationHandler = function (name, msg) {
44712 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
44713 if (deprecationId === -1) {
44714 throw new Error('Unexpected deprecation thrown name=' +
44715 name + ' msg=' + msg);
44716 }
44717 test._observedDeprecations[deprecationId] = 1;
44718 };
44719 }
44720
44721 function teardownDeprecationHandler(test, moment$$1, scope) {
44722 moment$$1.suppressDeprecationWarnings = test._oldSupress;
44723
44724 if (test._expectedDeprecations != null) {
44725 var missedDeprecations = [];
44726 each(test._expectedDeprecations, function (deprecationPattern, id) {
44727 if (test._observedDeprecations[id] !== 1) {
44728 missedDeprecations.push(deprecationPattern);
44729 }
44730 });
44731 if (missedDeprecations.length !== 0) {
44732 throw new Error('Expected deprecation warnings did not happen: ' +
44733 missedDeprecations.join(' '));
44734 }
44735 }
44736 }
44737
44738 function matchedDeprecation(name, msg, deprecations) {
44739 if (deprecations == null) {
44740 return -1;
44741 }
44742 for (var i = 0; i < deprecations.length; ++i) {
44743 if (name != null && name === deprecations[i]) {
44744 return i;
44745 }
44746 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
44747 return i;
44748 }
44749 }
44750 return -1;
44751 }
44752
44753 /*global QUnit:false*/
44754
44755 var test = QUnit.test;
44756
db71a655
KM
44757 function objectKeys(obj) {
44758 if (Object.keys) {
44759 return Object.keys(obj);
44760 } else {
44761 // IE8
44762 var res = [], i;
44763 for (i in obj) {
44764 if (obj.hasOwnProperty(i)) {
44765 res.push(i);
44766 }
c587bf00 44767 }
db71a655 44768 return res;
c587bf00 44769 }
c587bf00
IC
44770 }
44771
db71a655 44772 // Pick the first defined of two or three arguments.
c587bf00 44773
db71a655
KM
44774 function defineCommonLocaleTests(locale, options) {
44775 test('lenient day of month ordinal parsing', function (assert) {
44776 var i, ordinalStr, testMoment;
44777 for (i = 1; i <= 31; ++i) {
44778 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
44779 testMoment = moment(ordinalStr, 'YYYY MM Do');
44780 assert.equal(testMoment.year(), 2014,
44781 'lenient day of month ordinal parsing ' + i + ' year check');
44782 assert.equal(testMoment.month(), 0,
44783 'lenient day of month ordinal parsing ' + i + ' month check');
44784 assert.equal(testMoment.date(), i,
44785 'lenient day of month ordinal parsing ' + i + ' date check');
44786 }
44787 });
c587bf00 44788
db71a655
KM
44789 test('lenient day of month ordinal parsing of number', function (assert) {
44790 var i, testMoment;
44791 for (i = 1; i <= 31; ++i) {
44792 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
44793 assert.equal(testMoment.year(), 2014,
44794 'lenient day of month ordinal parsing of number ' + i + ' year check');
44795 assert.equal(testMoment.month(), 0,
44796 'lenient day of month ordinal parsing of number ' + i + ' month check');
44797 assert.equal(testMoment.date(), i,
44798 'lenient day of month ordinal parsing of number ' + i + ' date check');
44799 }
44800 });
c587bf00 44801
db71a655
KM
44802 test('strict day of month ordinal parsing', function (assert) {
44803 var i, ordinalStr, testMoment;
44804 for (i = 1; i <= 31; ++i) {
44805 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
44806 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
44807 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
44808 }
44809 });
c587bf00 44810
db71a655
KM
44811 test('meridiem invariant', function (assert) {
44812 var h, m, t1, t2;
44813 for (h = 0; h < 24; ++h) {
44814 for (m = 0; m < 60; m += 15) {
44815 t1 = moment.utc([2000, 0, 1, h, m]);
44816 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
44817 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
44818 'meridiem at ' + t1.format('HH:mm'));
44819 }
44820 }
44821 });
44822
44823 test('date format correctness', function (assert) {
44824 var data, tokens;
44825 data = moment.localeData()._longDateFormat;
44826 tokens = objectKeys(data);
44827 each(tokens, function (srchToken) {
44828 // Check each format string to make sure it does not contain any
44829 // tokens that need to be expanded.
44830 each(tokens, function (baseToken) {
44831 // strip escaped sequences
44832 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
44833 assert.equal(false, !!~format.indexOf(srchToken),
44834 'contains ' + srchToken + ' in ' + baseToken);
44835 });
c587bf00
IC
44836 });
44837 });
44838
db71a655
KM
44839 test('month parsing correctness', function (assert) {
44840 var i, m;
44841
44842 if (locale === 'tr') {
44843 // I can't fix it :(
c58511b9 44844 assert.expect(0);
db71a655
KM
44845 return;
44846 }
44847 function tester(format) {
44848 var r;
44849 r = moment(m.format(format), format);
44850 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
44851 if (locale !== 'ka') {
44852 r = moment(m.format(format).toLocaleUpperCase(), format);
44853 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
44854 }
db71a655
KM
44855 r = moment(m.format(format).toLocaleLowerCase(), format);
44856 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
44857
44858 r = moment(m.format(format), format, true);
44859 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
44860 if (locale !== 'ka') {
44861 r = moment(m.format(format).toLocaleUpperCase(), format, true);
44862 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
44863 }
db71a655
KM
44864 r = moment(m.format(format).toLocaleLowerCase(), format, true);
44865 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
44866 }
44867
44868 for (i = 0; i < 12; ++i) {
44869 m = moment([2015, i, 15, 18]);
44870 tester('MMM');
44871 tester('MMM.');
44872 tester('MMMM');
44873 tester('MMMM.');
44874 }
44875 });
d6651c21 44876
db71a655
KM
44877 test('weekday parsing correctness', function (assert) {
44878 var i, m;
44879
96d0d679 44880 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
44881 // tr, az: There is a lower-case letter (ı), that converted to
44882 // upper then lower changes to i
44883 // ro: there is the letter ț which behaves weird under IE8
44884 // mt: letter Ħ
96d0d679 44885 // ga: month with spaces
c58511b9 44886 assert.expect(0);
db71a655
KM
44887 return;
44888 }
44889 function tester(format) {
44890 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
44891 r = moment(m.format(format), format);
44892 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
44893 if (locale !== 'ka') {
44894 r = moment(m.format(format).toLocaleUpperCase(), format);
44895 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
44896 }
db71a655
KM
44897 r = moment(m.format(format).toLocaleLowerCase(), format);
44898 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
44899 r = moment(m.format(format), format, true);
44900 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
44901 if (locale !== 'ka') {
44902 r = moment(m.format(format).toLocaleUpperCase(), format, true);
44903 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
44904 }
db71a655
KM
44905 r = moment(m.format(format).toLocaleLowerCase(), format, true);
44906 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
44907 }
44908
44909 for (i = 0; i < 7; ++i) {
44910 m = moment.utc([2015, 0, i + 1, 18]);
44911 tester('dd');
44912 tester('ddd');
44913 tester('dddd');
44914 }
44915 });
d6651c21 44916
db71a655
KM
44917 test('valid localeData', function (assert) {
44918 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
44919 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
44920 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
44921 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
44922 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
44923 });
96d0d679
KM
44924
44925 test('localeData weekdays can localeSort', function (assert) {
44926 var weekdays = moment().localeData().weekdays();
44927 var weekdaysShort = moment().localeData().weekdaysShort();
44928 var weekdaysMin = moment().localeData().weekdaysMin();
44929 var shift = moment().localeData()._week.dow;
44930 assert.deepEqual(
44931 moment().localeData().weekdays(true),
44932 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
44933 'weekdays should localeSort');
44934 assert.deepEqual(
44935 moment().localeData().weekdaysShort(true),
44936 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
44937 'weekdaysShort should localeSort');
44938 assert.deepEqual(
44939 moment().localeData().weekdaysMin(true),
44940 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
44941 'weekdaysMin should localeSort');
44942 });
db71a655 44943 }
d6651c21 44944
db71a655 44945 /*global QUnit:false*/
b135bf1a 44946
db71a655
KM
44947 function localeModule (name, lifecycle) {
44948 QUnit.module('locale:' + name, {
c58511b9 44949 beforeEach : function () {
db71a655
KM
44950 moment.locale(name);
44951 moment.createFromInputFallback = function (config) {
44952 throw new Error('input not handled by moment: ' + config._i);
44953 };
44954 setupDeprecationHandler(test, moment, 'locale');
44955 if (lifecycle && lifecycle.setup) {
44956 lifecycle.setup();
44957 }
44958 },
c58511b9 44959 afterEach : function () {
db71a655
KM
44960 moment.locale('en');
44961 teardownDeprecationHandler(test, moment, 'locale');
44962 if (lifecycle && lifecycle.teardown) {
44963 lifecycle.teardown();
44964 }
516f5f67
IC
44965 }
44966 });
db71a655
KM
44967 defineCommonLocaleTests(name, -1, -1);
44968 }
44969
44970 localeModule('nn');
44971
44972 test('parse', function (assert) {
44973 var tests = 'januar jan_februar feb_mars mar_april apr_mai mai_juni jun_juli jul_august aug_september sep_oktober okt_november nov_desember des'.split('_'), i;
44974 function equalTest(input, mmm, i) {
44975 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
44976 }
44977 for (i = 0; i < 12; i++) {
44978 tests[i] = tests[i].split(' ');
44979 equalTest(tests[i][0], 'MMM', i);
44980 equalTest(tests[i][1], 'MMM', i);
44981 equalTest(tests[i][0], 'MMMM', i);
44982 equalTest(tests[i][1], 'MMMM', i);
44983 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
44984 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
44985 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
44986 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
44987 }
44988 });
44989
44990 test('format', function (assert) {
44991 var a = [
44992 ['dddd, MMMM Do YYYY, h:mm:ss a', 'sundag, februar 14. 2010, 3:25:50 pm'],
44993 ['ddd, hA', 'sun, 3PM'],
44994 ['M Mo MM MMMM MMM', '2 2. 02 februar feb'],
44995 ['YYYY YY', '2010 10'],
44996 ['D Do DD', '14 14. 14'],
44997 ['d do dddd ddd dd', '0 0. sundag sun su'],
44998 ['DDD DDDo DDDD', '45 45. 045'],
44999 ['w wo ww', '6 6. 06'],
45000 ['h hh', '3 03'],
45001 ['H HH', '15 15'],
45002 ['m mm', '25 25'],
45003 ['s ss', '50 50'],
45004 ['a A', 'pm PM'],
45005 ['[the] DDDo [day of the year]', 'the 45. day of the year'],
45006 ['LTS', '15:25:50'],
45007 ['L', '14.02.2010'],
45008 ['LL', '14. februar 2010'],
45009 ['LLL', '14. februar 2010 kl. 15:25'],
45010 ['LLLL', 'sundag 14. februar 2010 kl. 15:25'],
45011 ['l', '14.2.2010'],
45012 ['ll', '14. feb 2010'],
45013 ['lll', '14. feb 2010 kl. 15:25'],
45014 ['llll', 'sun 14. feb 2010 kl. 15:25']
45015 ],
45016 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
45017 i;
45018 for (i = 0; i < a.length; i++) {
45019 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
45020 }
45021 });
45022
45023 test('format ordinal', function (assert) {
45024 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
45025 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
45026 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
45027 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
45028 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
45029 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
45030 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
45031 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
45032 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
45033 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
45034
45035 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
45036 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
45037 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
45038 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
45039 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
45040 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
45041 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
45042 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
45043 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
45044 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
45045
45046 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
45047 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
45048 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
45049 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
45050 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
45051 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
45052 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
45053 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
45054 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
45055 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
45056
45057 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
45058 });
45059
45060 test('format month', function (assert) {
45061 var expected = 'januar jan_februar feb_mars mar_april apr_mai mai_juni jun_juli jul_august aug_september sep_oktober okt_november nov_desember des'.split('_'), i;
45062 for (i = 0; i < expected.length; i++) {
45063 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
45064 }
45065 });
45066
45067 test('format week', function (assert) {
45068 var expected = 'sundag sun su_måndag mån må_tysdag tys ty_onsdag ons on_torsdag tor to_fredag fre fr_laurdag lau lø'.split('_'), i;
45069 for (i = 0; i < expected.length; i++) {
45070 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
45071 }
45072 });
45073
45074 test('from', function (assert) {
45075 var start = moment([2007, 1, 28]);
45076 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'nokre sekund', '44 sekunder = a few seconds');
45077 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'eit minutt', '45 seconds = a minute');
45078 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'eit minutt', '89 seconds = a minute');
45079 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutt', '90 seconds = 2 minutes');
45080 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutt', '44 minutes = 44 minutes');
45081 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ein time', '45 minutes = an hour');
45082 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ein time', '89 minutes = an hour');
45083 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 timar', '90 minutes = 2 hours');
45084 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 timar', '5 hours = 5 hours');
45085 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 timar', '21 hours = 21 hours');
45086 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ein dag', '22 hours = a day');
45087 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ein dag', '35 hours = a day');
45088 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dagar', '36 hours = 2 days');
45089 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ein dag', '1 day = a day');
45090 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dagar', '5 days = 5 days');
45091 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dagar', '25 days = 25 days');
45092 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ein månad', '26 days = a month');
45093 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ein månad', '30 days = a month');
45094 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ein månad', '43 days = a month');
45095 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 månader', '46 days = 2 months');
45096 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 månader', '75 days = 2 months');
45097 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 månader', '76 days = 3 months');
45098 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ein månad', '1 month = a month');
45099 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 månader', '5 months = 5 months');
45100 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'eit år', '345 days = a year');
45101 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 år', '548 days = 2 years');
45102 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'eit år', '1 year = a year');
45103 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 år', '5 years = 5 years');
45104 });
45105
45106 test('suffix', function (assert) {
45107 assert.equal(moment(30000).from(0), 'om nokre sekund', 'prefix');
45108 assert.equal(moment(0).from(30000), 'nokre sekund sidan', 'suffix');
45109 });
45110
45111 test('now from now', function (assert) {
45112 assert.equal(moment().fromNow(), 'nokre sekund sidan', 'now from now should display as in the past');
45113 });
45114
45115 test('fromNow', function (assert) {
45116 assert.equal(moment().add({s: 30}).fromNow(), 'om nokre sekund', 'in a few seconds');
45117 assert.equal(moment().add({d: 5}).fromNow(), 'om 5 dagar', 'in 5 days');
45118 });
45119
45120 test('calendar day', function (assert) {
45121 var a = moment().hours(12).minutes(0).seconds(0);
45122
45123 assert.equal(moment(a).calendar(), 'I dag klokka 12:00', 'today at the same time');
45124 assert.equal(moment(a).add({m: 25}).calendar(), 'I dag klokka 12:25', 'Now plus 25 min');
45125 assert.equal(moment(a).add({h: 1}).calendar(), 'I dag klokka 13:00', 'Now plus 1 hour');
45126 assert.equal(moment(a).add({d: 1}).calendar(), 'I morgon klokka 12:00', 'tomorrow at the same time');
45127 assert.equal(moment(a).subtract({h: 1}).calendar(), 'I dag klokka 11:00', 'Now minus 1 hour');
45128 assert.equal(moment(a).subtract({d: 1}).calendar(), 'I går klokka 12:00', 'yesterday at the same time');
45129 });
45130
45131 test('calendar next week', function (assert) {
45132 var i, m;
45133 for (i = 2; i < 7; i++) {
45134 m = moment().add({d: i});
45135 assert.equal(m.calendar(), m.format('dddd [klokka] LT'), 'Today + ' + i + ' days current time');
45136 m.hours(0).minutes(0).seconds(0).milliseconds(0);
45137 assert.equal(m.calendar(), m.format('dddd [klokka] LT'), 'Today + ' + i + ' days beginning of day');
45138 m.hours(23).minutes(59).seconds(59).milliseconds(999);
45139 assert.equal(m.calendar(), m.format('dddd [klokka] LT'), 'Today + ' + i + ' days end of day');
73f3c911 45140 }
db71a655 45141 });
516f5f67 45142
db71a655
KM
45143 test('calendar last week', function (assert) {
45144 var i, m;
45145 for (i = 2; i < 7; i++) {
45146 m = moment().subtract({d: i});
45147 assert.equal(m.calendar(), m.format('[Føregåande] dddd [klokka] LT'), 'Today - ' + i + ' days current time');
45148 m.hours(0).minutes(0).seconds(0).milliseconds(0);
45149 assert.equal(m.calendar(), m.format('[Føregåande] dddd [klokka] LT'), 'Today - ' + i + ' days beginning of day');
45150 m.hours(23).minutes(59).seconds(59).milliseconds(999);
45151 assert.equal(m.calendar(), m.format('[Føregåande] dddd [klokka] LT'), 'Today - ' + i + ' days end of day');
d6651c21 45152 }
db71a655 45153 });
d6651c21 45154
db71a655
KM
45155 test('calendar all else', function (assert) {
45156 var weeksAgo = moment().subtract({w: 1}),
45157 weeksFromNow = moment().add({w: 1});
d6651c21 45158
db71a655
KM
45159 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
45160 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
d6651c21 45161
db71a655
KM
45162 weeksAgo = moment().subtract({w: 2});
45163 weeksFromNow = moment().add({w: 2});
d6651c21 45164
db71a655
KM
45165 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
45166 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
45167 });
45168
45169 test('weeks year starting sunday formatted', function (assert) {
45170 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
45171 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
45172 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
45173 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
45174 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
45175 });
73f3c911
IC
45176
45177})));
45178
d6651c21
IC
45179
45180;(function (global, factory) {
45181 typeof exports === 'object' && typeof module !== 'undefined'
45182 && typeof require === 'function' ? factory(require('../../moment')) :
45183 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
45184 factory(global.moment)
73f3c911 45185}(this, (function (moment) { 'use strict';
d6651c21 45186
db71a655
KM
45187 function each(array, callback) {
45188 var i;
45189 for (i = 0; i < array.length; i++) {
45190 callback(array[i], i, array);
45191 }
d6651c21
IC
45192 }
45193
c58511b9
KM
45194 function setupDeprecationHandler(test, moment$$1, scope) {
45195 test._expectedDeprecations = null;
45196 test._observedDeprecations = null;
45197 test._oldSupress = moment$$1.suppressDeprecationWarnings;
45198 moment$$1.suppressDeprecationWarnings = true;
45199 test.expectedDeprecations = function () {
45200 test._expectedDeprecations = arguments;
45201 test._observedDeprecations = [];
45202 };
45203 moment$$1.deprecationHandler = function (name, msg) {
45204 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
45205 if (deprecationId === -1) {
45206 throw new Error('Unexpected deprecation thrown name=' +
45207 name + ' msg=' + msg);
45208 }
45209 test._observedDeprecations[deprecationId] = 1;
45210 };
45211 }
45212
45213 function teardownDeprecationHandler(test, moment$$1, scope) {
45214 moment$$1.suppressDeprecationWarnings = test._oldSupress;
45215
45216 if (test._expectedDeprecations != null) {
45217 var missedDeprecations = [];
45218 each(test._expectedDeprecations, function (deprecationPattern, id) {
45219 if (test._observedDeprecations[id] !== 1) {
45220 missedDeprecations.push(deprecationPattern);
45221 }
45222 });
45223 if (missedDeprecations.length !== 0) {
45224 throw new Error('Expected deprecation warnings did not happen: ' +
45225 missedDeprecations.join(' '));
45226 }
45227 }
45228 }
45229
45230 function matchedDeprecation(name, msg, deprecations) {
45231 if (deprecations == null) {
45232 return -1;
45233 }
45234 for (var i = 0; i < deprecations.length; ++i) {
45235 if (name != null && name === deprecations[i]) {
45236 return i;
45237 }
45238 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
45239 return i;
45240 }
45241 }
45242 return -1;
45243 }
45244
45245 /*global QUnit:false*/
45246
45247 var test = QUnit.test;
45248
db71a655
KM
45249 function objectKeys(obj) {
45250 if (Object.keys) {
45251 return Object.keys(obj);
45252 } else {
45253 // IE8
45254 var res = [], i;
45255 for (i in obj) {
45256 if (obj.hasOwnProperty(i)) {
45257 res.push(i);
45258 }
d6651c21 45259 }
db71a655 45260 return res;
d6651c21 45261 }
d6651c21
IC
45262 }
45263
db71a655 45264 // Pick the first defined of two or three arguments.
d6651c21 45265
db71a655
KM
45266 function defineCommonLocaleTests(locale, options) {
45267 test('lenient day of month ordinal parsing', function (assert) {
45268 var i, ordinalStr, testMoment;
45269 for (i = 1; i <= 31; ++i) {
45270 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
45271 testMoment = moment(ordinalStr, 'YYYY MM Do');
45272 assert.equal(testMoment.year(), 2014,
45273 'lenient day of month ordinal parsing ' + i + ' year check');
45274 assert.equal(testMoment.month(), 0,
45275 'lenient day of month ordinal parsing ' + i + ' month check');
45276 assert.equal(testMoment.date(), i,
45277 'lenient day of month ordinal parsing ' + i + ' date check');
45278 }
45279 });
d6651c21 45280
db71a655
KM
45281 test('lenient day of month ordinal parsing of number', function (assert) {
45282 var i, testMoment;
45283 for (i = 1; i <= 31; ++i) {
45284 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
45285 assert.equal(testMoment.year(), 2014,
45286 'lenient day of month ordinal parsing of number ' + i + ' year check');
45287 assert.equal(testMoment.month(), 0,
45288 'lenient day of month ordinal parsing of number ' + i + ' month check');
45289 assert.equal(testMoment.date(), i,
45290 'lenient day of month ordinal parsing of number ' + i + ' date check');
45291 }
d6651c21
IC
45292 });
45293
db71a655
KM
45294 test('strict day of month ordinal parsing', function (assert) {
45295 var i, ordinalStr, testMoment;
45296 for (i = 1; i <= 31; ++i) {
45297 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
45298 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
45299 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
45300 }
45301 });
d6651c21 45302
db71a655
KM
45303 test('meridiem invariant', function (assert) {
45304 var h, m, t1, t2;
45305 for (h = 0; h < 24; ++h) {
45306 for (m = 0; m < 60; m += 15) {
45307 t1 = moment.utc([2000, 0, 1, h, m]);
45308 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
45309 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
45310 'meridiem at ' + t1.format('HH:mm'));
45311 }
45312 }
45313 });
d6651c21 45314
db71a655
KM
45315 test('date format correctness', function (assert) {
45316 var data, tokens;
45317 data = moment.localeData()._longDateFormat;
45318 tokens = objectKeys(data);
45319 each(tokens, function (srchToken) {
45320 // Check each format string to make sure it does not contain any
45321 // tokens that need to be expanded.
45322 each(tokens, function (baseToken) {
45323 // strip escaped sequences
45324 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
45325 assert.equal(false, !!~format.indexOf(srchToken),
45326 'contains ' + srchToken + ' in ' + baseToken);
45327 });
45328 });
45329 });
d6651c21 45330
db71a655
KM
45331 test('month parsing correctness', function (assert) {
45332 var i, m;
45333
45334 if (locale === 'tr') {
45335 // I can't fix it :(
c58511b9 45336 assert.expect(0);
db71a655
KM
45337 return;
45338 }
45339 function tester(format) {
45340 var r;
45341 r = moment(m.format(format), format);
45342 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
45343 if (locale !== 'ka') {
45344 r = moment(m.format(format).toLocaleUpperCase(), format);
45345 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
45346 }
db71a655
KM
45347 r = moment(m.format(format).toLocaleLowerCase(), format);
45348 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
45349
45350 r = moment(m.format(format), format, true);
45351 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
45352 if (locale !== 'ka') {
45353 r = moment(m.format(format).toLocaleUpperCase(), format, true);
45354 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
45355 }
db71a655
KM
45356 r = moment(m.format(format).toLocaleLowerCase(), format, true);
45357 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
45358 }
45359
45360 for (i = 0; i < 12; ++i) {
45361 m = moment([2015, i, 15, 18]);
45362 tester('MMM');
45363 tester('MMM.');
45364 tester('MMMM');
45365 tester('MMMM.');
45366 }
45367 });
d6651c21 45368
db71a655
KM
45369 test('weekday parsing correctness', function (assert) {
45370 var i, m;
45371
96d0d679 45372 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
45373 // tr, az: There is a lower-case letter (ı), that converted to
45374 // upper then lower changes to i
45375 // ro: there is the letter ț which behaves weird under IE8
45376 // mt: letter Ħ
96d0d679 45377 // ga: month with spaces
c58511b9 45378 assert.expect(0);
db71a655
KM
45379 return;
45380 }
45381 function tester(format) {
45382 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
45383 r = moment(m.format(format), format);
45384 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
45385 if (locale !== 'ka') {
45386 r = moment(m.format(format).toLocaleUpperCase(), format);
45387 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
45388 }
db71a655
KM
45389 r = moment(m.format(format).toLocaleLowerCase(), format);
45390 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
45391 r = moment(m.format(format), format, true);
45392 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
45393 if (locale !== 'ka') {
45394 r = moment(m.format(format).toLocaleUpperCase(), format, true);
45395 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
45396 }
db71a655
KM
45397 r = moment(m.format(format).toLocaleLowerCase(), format, true);
45398 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
45399 }
45400
45401 for (i = 0; i < 7; ++i) {
45402 m = moment.utc([2015, 0, i + 1, 18]);
45403 tester('dd');
45404 tester('ddd');
45405 tester('dddd');
45406 }
45407 });
73f3c911 45408
db71a655
KM
45409 test('valid localeData', function (assert) {
45410 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
45411 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
45412 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
45413 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
45414 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
45415 });
96d0d679
KM
45416
45417 test('localeData weekdays can localeSort', function (assert) {
45418 var weekdays = moment().localeData().weekdays();
45419 var weekdaysShort = moment().localeData().weekdaysShort();
45420 var weekdaysMin = moment().localeData().weekdaysMin();
45421 var shift = moment().localeData()._week.dow;
45422 assert.deepEqual(
45423 moment().localeData().weekdays(true),
45424 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
45425 'weekdays should localeSort');
45426 assert.deepEqual(
45427 moment().localeData().weekdaysShort(true),
45428 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
45429 'weekdaysShort should localeSort');
45430 assert.deepEqual(
45431 moment().localeData().weekdaysMin(true),
45432 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
45433 'weekdaysMin should localeSort');
45434 });
db71a655 45435 }
d6651c21 45436
db71a655 45437 /*global QUnit:false*/
516f5f67 45438
db71a655
KM
45439 function localeModule (name, lifecycle) {
45440 QUnit.module('locale:' + name, {
c58511b9 45441 beforeEach : function () {
db71a655
KM
45442 moment.locale(name);
45443 moment.createFromInputFallback = function (config) {
45444 throw new Error('input not handled by moment: ' + config._i);
45445 };
45446 setupDeprecationHandler(test, moment, 'locale');
45447 if (lifecycle && lifecycle.setup) {
45448 lifecycle.setup();
45449 }
45450 },
c58511b9 45451 afterEach : function () {
db71a655
KM
45452 moment.locale('en');
45453 teardownDeprecationHandler(test, moment, 'locale');
45454 if (lifecycle && lifecycle.teardown) {
45455 lifecycle.teardown();
45456 }
73f3c911 45457 }
db71a655
KM
45458 });
45459 defineCommonLocaleTests(name, -1, -1);
45460 }
45461
45462 localeModule('pa-in');
45463
45464 test('parse', function (assert) {
45465 var tests = 'ਜਨਵਰੀ ਜਨਵਰੀ_ਫ਼ਰਵਰੀ ਫ਼ਰਵਰੀ_ਮਾਰਚ ਮਾਰਚ_ਅਪ੍ਰੈਲ ਅਪ੍ਰੈਲ_ਮਈ ਮਈ_ਜੂਨ ਜੂਨ_ਜੁਲਾਈ ਜੁਲਾਈ_ਅਗਸਤ ਅਗਸਤ_ਸਤੰਬਰ ਸਤੰਬਰ_ਅਕਤੂਬਰ ਅਕਤੂਬਰ_ਨਵੰਬਰ ਨਵੰਬਰ_ਦਸੰਬਰ ਦਸੰਬਰ'.split('_'), i;
45466 function equalTest(input, mmm, i) {
45467 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
45468 }
45469 for (i = 0; i < 12; i++) {
45470 tests[i] = tests[i].split(' ');
45471 equalTest(tests[i][0], 'MMM', i);
45472 equalTest(tests[i][1], 'MMM', i);
45473 equalTest(tests[i][0], 'MMMM', i);
45474 equalTest(tests[i][1], 'MMMM', i);
45475 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
45476 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
45477 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
45478 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
45479 }
45480 });
45481
45482 test('format', function (assert) {
45483 var a = [
45484 ['dddd, Do MMMM YYYY, a h:mm:ss ਵਜੇ', 'ਐਤਵਾਰ, ੧੪ ਫ਼ਰਵਰੀ ੨੦੧੦, ਦੁਪਹਿਰ ੩:੨੫:੫੦ ਵਜੇ'],
45485 ['ddd, a h ਵਜੇ', 'ਐਤ, ਦੁਪਹਿਰ ੩ ਵਜੇ'],
45486 ['M Mo MM MMMM MMM', '੨ ੨ ੦੨ ਫ਼ਰਵਰੀ ਫ਼ਰਵਰੀ'],
45487 ['YYYY YY', '੨੦੧੦ ੧੦'],
45488 ['D Do DD', '੧੪ ੧੪ ੧੪'],
45489 ['d do dddd ddd dd', '੦ ੦ ਐਤਵਾਰ ਐਤ ਐਤ'],
45490 ['DDD DDDo DDDD', '੪੫ ੪੫ ੦੪੫'],
45491 ['w wo ww', '੮ ੮ ੦੮'],
45492 ['h hh', '੩ ੦੩'],
45493 ['H HH', '੧੫ ੧੫'],
45494 ['m mm', '੨੫ ੨੫'],
45495 ['s ss', '੫੦ ੫੦'],
45496 ['a A', 'ਦੁਪਹਿਰ ਦੁਪਹਿਰ'],
45497 ['LTS', 'ਦੁਪਹਿਰ ੩:੨੫:੫੦ ਵਜੇ'],
45498 ['L', '੧੪/੦੨/੨੦੧੦'],
45499 ['LL', '੧੪ ਫ਼ਰਵਰੀ ੨੦੧੦'],
45500 ['LLL', '੧੪ ਫ਼ਰਵਰੀ ੨੦੧੦, ਦੁਪਹਿਰ ੩:੨੫ ਵਜੇ'],
45501 ['LLLL', 'ਐਤਵਾਰ, ੧੪ ਫ਼ਰਵਰੀ ੨੦੧੦, ਦੁਪਹਿਰ ੩:੨੫ ਵਜੇ'],
45502 ['l', '੧੪/੨/੨੦੧੦'],
45503 ['ll', '੧੪ ਫ਼ਰਵਰੀ ੨੦੧੦'],
45504 ['lll', '੧੪ ਫ਼ਰਵਰੀ ੨੦੧੦, ਦੁਪਹਿਰ ੩:੨੫ ਵਜੇ'],
45505 ['llll', 'ਐਤ, ੧੪ ਫ਼ਰਵਰੀ ੨੦੧੦, ਦੁਪਹਿਰ ੩:੨੫ ਵਜੇ']
45506 ],
45507 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
45508 i;
45509 for (i = 0; i < a.length; i++) {
45510 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
45511 }
45512 });
45513
45514 test('format ordinal', function (assert) {
45515 assert.equal(moment([2011, 0, 1]).format('DDDo'), '੧', '੧');
45516 assert.equal(moment([2011, 0, 2]).format('DDDo'), '੨', '੨');
45517 assert.equal(moment([2011, 0, 3]).format('DDDo'), '੩', '੩');
45518 assert.equal(moment([2011, 0, 4]).format('DDDo'), '੪', '੪');
45519 assert.equal(moment([2011, 0, 5]).format('DDDo'), '੫', '੫');
45520 assert.equal(moment([2011, 0, 6]).format('DDDo'), '੬', '੬');
45521 assert.equal(moment([2011, 0, 7]).format('DDDo'), '੭', '੭');
45522 assert.equal(moment([2011, 0, 8]).format('DDDo'), '੮', '੮');
45523 assert.equal(moment([2011, 0, 9]).format('DDDo'), '੯', '੯');
45524 assert.equal(moment([2011, 0, 10]).format('DDDo'), '੧੦', '੧੦');
45525
45526 assert.equal(moment([2011, 0, 11]).format('DDDo'), '੧੧', '੧੧');
45527 assert.equal(moment([2011, 0, 12]).format('DDDo'), '੧੨', '੧੨');
45528 assert.equal(moment([2011, 0, 13]).format('DDDo'), '੧੩', '੧੩');
45529 assert.equal(moment([2011, 0, 14]).format('DDDo'), '੧੪', '੧੪');
45530 assert.equal(moment([2011, 0, 15]).format('DDDo'), '੧੫', '੧੫');
45531 assert.equal(moment([2011, 0, 16]).format('DDDo'), '੧੬', '੧੬');
45532 assert.equal(moment([2011, 0, 17]).format('DDDo'), '੧੭', '੧੭');
45533 assert.equal(moment([2011, 0, 18]).format('DDDo'), '੧੮', '੧੮');
45534 assert.equal(moment([2011, 0, 19]).format('DDDo'), '੧੯', '੧੯');
45535 assert.equal(moment([2011, 0, 20]).format('DDDo'), '੨੦', '੨੦');
45536
45537 assert.equal(moment([2011, 0, 21]).format('DDDo'), '੨੧', '੨੧');
45538 assert.equal(moment([2011, 0, 22]).format('DDDo'), '੨੨', '੨੨');
45539 assert.equal(moment([2011, 0, 23]).format('DDDo'), '੨੩', '੨੩');
45540 assert.equal(moment([2011, 0, 24]).format('DDDo'), '੨੪', '੨੪');
45541 assert.equal(moment([2011, 0, 25]).format('DDDo'), '੨੫', '੨੫');
45542 assert.equal(moment([2011, 0, 26]).format('DDDo'), '੨੬', '੨੬');
45543 assert.equal(moment([2011, 0, 27]).format('DDDo'), '੨੭', '੨੭');
45544 assert.equal(moment([2011, 0, 28]).format('DDDo'), '੨੮', '੨੮');
45545 assert.equal(moment([2011, 0, 29]).format('DDDo'), '੨੯', '੨੯');
45546 assert.equal(moment([2011, 0, 30]).format('DDDo'), '੩੦', '੩੦');
45547
45548 assert.equal(moment([2011, 0, 31]).format('DDDo'), '੩੧', '੩੧');
45549 });
45550
45551 test('format month', function (assert) {
45552 var expected = 'ਜਨਵਰੀ ਜਨਵਰੀ_ਫ਼ਰਵਰੀ ਫ਼ਰਵਰੀ_ਮਾਰਚ ਮਾਰਚ_ਅਪ੍ਰੈਲ ਅਪ੍ਰੈਲ_ਮਈ ਮਈ_ਜੂਨ ਜੂਨ_ਜੁਲਾਈ ਜੁਲਾਈ_ਅਗਸਤ ਅਗਸਤ_ਸਤੰਬਰ ਸਤੰਬਰ_ਅਕਤੂਬਰ ਅਕਤੂਬਰ_ਨਵੰਬਰ ਨਵੰਬਰ_ਦਸੰਬਰ ਦਸੰਬਰ'.split('_'), i;
45553 for (i = 0; i < expected.length; i++) {
45554 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
45555 }
45556 });
45557
45558 test('format week', function (assert) {
45559 var expected = 'ਐਤਵਾਰ ਐਤ ਐਤ_ਸੋਮਵਾਰ ਸੋਮ ਸੋਮ_ਮੰਗਲਵਾਰ ਮੰਗਲ ਮੰਗਲ_ਬੁਧਵਾਰ ਬੁਧ ਬੁਧ_ਵੀਰਵਾਰ ਵੀਰ ਵੀਰ_ਸ਼ੁੱਕਰਵਾਰ ਸ਼ੁਕਰ ਸ਼ੁਕਰ_ਸ਼ਨੀਚਰਵਾਰ ਸ਼ਨੀ ਸ਼ਨੀ'.split('_'), i;
45560 for (i = 0; i < expected.length; i++) {
45561 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
45562 }
45563 });
45564
45565 test('from', function (assert) {
45566 var start = moment([2007, 1, 28]);
45567 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ਕੁਝ ਸਕਿੰਟ', '44 seconds = a few seconds');
45568 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ਇਕ ਮਿੰਟ', '45 seconds = a minute');
45569 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ਇਕ ਮਿੰਟ', '89 seconds = a minute');
45570 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '੨ ਮਿੰਟ', '90 seconds = 2 minutes');
45571 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '੪੪ ਮਿੰਟ', '44 minutes = 44 minutes');
45572 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ਇੱਕ ਘੰਟਾ', '45 minutes = an hour');
45573 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ਇੱਕ ਘੰਟਾ', '89 minutes = an hour');
45574 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '੨ ਘੰਟੇ', '90 minutes = 2 hours');
45575 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '੫ ਘੰਟੇ', '5 hours = 5 hours');
45576 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '੨੧ ਘੰਟੇ', '21 hours = 21 hours');
45577 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ਇੱਕ ਦਿਨ', '22 hours = a day');
45578 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ਇੱਕ ਦਿਨ', '35 hours = a day');
45579 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '੨ ਦਿਨ', '36 hours = 2 days');
45580 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ਇੱਕ ਦਿਨ', '1 day = a day');
45581 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '੫ ਦਿਨ', '5 days = 5 days');
45582 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '੨੫ ਦਿਨ', '25 days = 25 days');
45583 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ਇੱਕ ਮਹੀਨਾ', '26 days = a month');
45584 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ਇੱਕ ਮਹੀਨਾ', '30 days = a month');
45585 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ਇੱਕ ਮਹੀਨਾ', '43 days = a month');
45586 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '੨ ਮਹੀਨੇ', '46 days = 2 months');
45587 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '੨ ਮਹੀਨੇ', '75 days = 2 months');
45588 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '੩ ਮਹੀਨੇ', '76 days = 3 months');
45589 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ਇੱਕ ਮਹੀਨਾ', '1 month = a month');
45590 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '੫ ਮਹੀਨੇ', '5 months = 5 months');
45591 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ਇੱਕ ਸਾਲ', '345 days = a year');
45592 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '੨ ਸਾਲ', '548 days = 2 years');
45593 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ਇੱਕ ਸਾਲ', '1 year = a year');
45594 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '੫ ਸਾਲ', '5 years = 5 years');
45595 });
45596
45597 test('suffix', function (assert) {
45598 assert.equal(moment(30000).from(0), 'ਕੁਝ ਸਕਿੰਟ ਵਿੱਚ', 'prefix');
45599 assert.equal(moment(0).from(30000), 'ਕੁਝ ਸਕਿੰਟ ਪਿਛਲੇ', 'suffix');
45600 });
45601
45602 test('now from now', function (assert) {
45603 assert.equal(moment().fromNow(), 'ਕੁਝ ਸਕਿੰਟ ਪਿਛਲੇ', 'now from now should display as in the past');
45604 });
45605
45606 test('fromNow', function (assert) {
45607 assert.equal(moment().add({s: 30}).fromNow(), 'ਕੁਝ ਸਕਿੰਟ ਵਿੱਚ', 'ਕੁਝ ਸਕਿੰਟ ਵਿੱਚ');
45608 assert.equal(moment().add({d: 5}).fromNow(), '੫ ਦਿਨ ਵਿੱਚ', '੫ ਦਿਨ ਵਿੱਚ');
45609 });
45610
45611 test('calendar day', function (assert) {
45612 var a = moment().hours(12).minutes(0).seconds(0);
45613
45614 assert.equal(moment(a).calendar(), 'ਅਜ ਦੁਪਹਿਰ ੧੨:੦੦ ਵਜੇ', 'today at the same time');
45615 assert.equal(moment(a).add({m: 25}).calendar(), 'ਅਜ ਦੁਪਹਿਰ ੧੨:੨੫ ਵਜੇ', 'Now plus 25 min');
45616 assert.equal(moment(a).add({h: 3}).calendar(), 'ਅਜ ਦੁਪਹਿਰ ੩:੦੦ ਵਜੇ', 'Now plus 3 hours');
45617 assert.equal(moment(a).add({d: 1}).calendar(), 'ਕਲ ਦੁਪਹਿਰ ੧੨:੦੦ ਵਜੇ', 'tomorrow at the same time');
45618 assert.equal(moment(a).subtract({h: 1}).calendar(), 'ਅਜ ਦੁਪਹਿਰ ੧੧:੦੦ ਵਜੇ', 'Now minus 1 hour');
45619 assert.equal(moment(a).subtract({d: 1}).calendar(), 'ਕਲ ਦੁਪਹਿਰ ੧੨:੦੦ ਵਜੇ', 'yesterday at the same time');
45620 });
45621
45622 test('calendar next week', function (assert) {
45623 var i, m;
45624 for (i = 2; i < 7; i++) {
45625 m = moment().add({d: i});
2e2a5b35 45626 assert.equal(m.calendar(), m.format('[ਅਗਲਾ] dddd[,] LT'), 'Today + ' + i + ' days current time');
db71a655 45627 m.hours(0).minutes(0).seconds(0).milliseconds(0);
2e2a5b35 45628 assert.equal(m.calendar(), m.format('[ਅਗਲਾ] dddd[,] LT'), 'Today + ' + i + ' days beginning of day');
db71a655 45629 m.hours(23).minutes(59).seconds(59).milliseconds(999);
2e2a5b35 45630 assert.equal(m.calendar(), m.format('[ਅਗਲਾ] dddd[,] LT'), 'Today + ' + i + ' days end of day');
db71a655
KM
45631 }
45632 });
73f3c911 45633
db71a655
KM
45634 test('calendar last week', function (assert) {
45635 var i, m;
516f5f67 45636
db71a655
KM
45637 for (i = 2; i < 7; i++) {
45638 m = moment().subtract({d: i});
45639 assert.equal(m.calendar(), m.format('[ਪਿਛਲੇ] dddd[,] LT'), 'Today - ' + i + ' days current time');
45640 m.hours(0).minutes(0).seconds(0).milliseconds(0);
45641 assert.equal(m.calendar(), m.format('[ਪਿਛਲੇ] dddd[,] LT'), 'Today - ' + i + ' days beginning of day');
45642 m.hours(23).minutes(59).seconds(59).milliseconds(999);
45643 assert.equal(m.calendar(), m.format('[ਪਿਛਲੇ] dddd[,] LT'), 'Today - ' + i + ' days end of day');
45644 }
45645 });
516f5f67 45646
db71a655
KM
45647 test('calendar all else', function (assert) {
45648 var weeksAgo = moment().subtract({w: 1}),
45649 weeksFromNow = moment().add({w: 1});
516f5f67 45650
db71a655
KM
45651 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
45652 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
b135bf1a 45653
db71a655
KM
45654 weeksAgo = moment().subtract({w: 2});
45655 weeksFromNow = moment().add({w: 2});
45656
45657 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
45658 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
45659 });
b135bf1a 45660
db71a655
KM
45661 test('meridiem invariant', function (assert) {
45662 assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), 'ਰਾਤ', 'before dawn');
45663 assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), 'ਸਵੇਰ', 'morning');
45664 assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), 'ਦੁਪਹਿਰ', 'during day');
45665 assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), 'ਸ਼ਾਮ', 'evening');
45666 assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), 'ਸ਼ਾਮ', 'late evening');
45667 assert.equal(moment([2011, 2, 23, 21, 20]).format('a'), 'ਰਾਤ', 'night');
45668
45669 assert.equal(moment([2011, 2, 23, 2, 30]).format('A'), 'ਰਾਤ', 'before dawn');
45670 assert.equal(moment([2011, 2, 23, 9, 30]).format('A'), 'ਸਵੇਰ', 'morning');
45671 assert.equal(moment([2011, 2, 23, 14, 30]).format('A'), 'ਦੁਪਹਿਰ', ' during day');
45672 assert.equal(moment([2011, 2, 23, 17, 30]).format('A'), 'ਸ਼ਾਮ', 'evening');
45673 assert.equal(moment([2011, 2, 23, 19, 30]).format('A'), 'ਸ਼ਾਮ', 'late evening');
45674 assert.equal(moment([2011, 2, 23, 21, 20]).format('A'), 'ਰਾਤ', 'night');
45675 });
45676
45677 test('weeks year starting sunday', function (assert) {
45678 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
45679 assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1');
45680 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
45681 assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2');
45682 assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3');
45683 });
45684
45685 test('weeks year starting monday', function (assert) {
45686 assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1');
45687 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
45688 assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1');
45689 assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2');
45690 assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2');
45691 assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3');
45692 });
45693
45694 test('weeks year starting tuesday', function (assert) {
45695 assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52');
45696 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
45697 assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1');
45698 assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2');
45699 assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2');
45700 assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3');
45701 });
45702
45703 test('weeks year starting wednesday', function (assert) {
45704 assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1');
45705 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
45706 assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1');
45707 assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2');
45708 assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2');
45709 assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3');
45710 });
45711
45712 test('weeks year starting thursday', function (assert) {
45713 assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1');
45714 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
45715 assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1');
45716 assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2');
45717 assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2');
45718 assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3');
45719 });
45720
45721 test('weeks year starting friday', function (assert) {
45722 assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1');
45723 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
45724 assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1');
45725 assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2');
45726 assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2');
45727 assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3');
45728 });
45729
45730 test('weeks year starting saturday', function (assert) {
45731 assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1');
45732 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
45733 assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2');
45734 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
45735 assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3');
45736 });
45737
45738 test('weeks year starting sunday formatted', function (assert) {
45739 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '੧ ੦੧ ੧', 'Jan 1 2012 should be week 1');
45740 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '੧ ੦੧ ੧', 'Jan 7 2012 should be week 1');
45741 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '੨ ੦੨ ੨', 'Jan 8 2012 should be week 2');
45742 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '੨ ੦੨ ੨', 'Jan 14 2012 should be week 2');
45743 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '੩ ੦੩ ੩', 'Jan 15 2012 should be week 3');
45744 });
73f3c911 45745
f2af24d5 45746 test('lenient day of month ordinal parsing', function (assert) {
73f3c911
IC
45747 var i, ordinalStr, testMoment;
45748 for (i = 1; i <= 31; ++i) {
45749 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
45750 testMoment = moment(ordinalStr, 'YYYY MM Do');
45751 assert.equal(testMoment.year(), 2014,
f2af24d5 45752 'lenient day of month ordinal parsing ' + i + ' year check');
73f3c911 45753 assert.equal(testMoment.month(), 0,
f2af24d5 45754 'lenient day of month ordinal parsing ' + i + ' month check');
73f3c911 45755 assert.equal(testMoment.date(), i,
f2af24d5 45756 'lenient day of month ordinal parsing ' + i + ' date check');
b135bf1a 45757 }
73f3c911 45758 });
b135bf1a 45759
f2af24d5 45760 test('lenient day of month ordinal parsing of number', function (assert) {
73f3c911
IC
45761 var i, testMoment;
45762 for (i = 1; i <= 31; ++i) {
45763 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
45764 assert.equal(testMoment.year(), 2014,
f2af24d5 45765 'lenient day of month ordinal parsing of number ' + i + ' year check');
73f3c911 45766 assert.equal(testMoment.month(), 0,
f2af24d5 45767 'lenient day of month ordinal parsing of number ' + i + ' month check');
73f3c911 45768 assert.equal(testMoment.date(), i,
f2af24d5 45769 'lenient day of month ordinal parsing of number ' + i + ' date check');
73f3c911
IC
45770 }
45771 });
b135bf1a 45772
f2af24d5 45773 test('strict day of month ordinal parsing', function (assert) {
73f3c911
IC
45774 var i, ordinalStr, testMoment;
45775 for (i = 1; i <= 31; ++i) {
45776 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
45777 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
f2af24d5 45778 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
73f3c911
IC
45779 }
45780 });
b135bf1a 45781
73f3c911
IC
45782})));
45783
516f5f67 45784
c74a101d
IC
45785;(function (global, factory) {
45786 typeof exports === 'object' && typeof module !== 'undefined'
45787 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
45788 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
45789 factory(global.moment)
73f3c911 45790}(this, (function (moment) { 'use strict';
516f5f67 45791
db71a655
KM
45792 function each(array, callback) {
45793 var i;
45794 for (i = 0; i < array.length; i++) {
45795 callback(array[i], i, array);
45796 }
b135bf1a
IC
45797 }
45798
c58511b9
KM
45799 function setupDeprecationHandler(test, moment$$1, scope) {
45800 test._expectedDeprecations = null;
45801 test._observedDeprecations = null;
45802 test._oldSupress = moment$$1.suppressDeprecationWarnings;
45803 moment$$1.suppressDeprecationWarnings = true;
45804 test.expectedDeprecations = function () {
45805 test._expectedDeprecations = arguments;
45806 test._observedDeprecations = [];
45807 };
45808 moment$$1.deprecationHandler = function (name, msg) {
45809 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
45810 if (deprecationId === -1) {
45811 throw new Error('Unexpected deprecation thrown name=' +
45812 name + ' msg=' + msg);
45813 }
45814 test._observedDeprecations[deprecationId] = 1;
45815 };
45816 }
45817
45818 function teardownDeprecationHandler(test, moment$$1, scope) {
45819 moment$$1.suppressDeprecationWarnings = test._oldSupress;
45820
45821 if (test._expectedDeprecations != null) {
45822 var missedDeprecations = [];
45823 each(test._expectedDeprecations, function (deprecationPattern, id) {
45824 if (test._observedDeprecations[id] !== 1) {
45825 missedDeprecations.push(deprecationPattern);
45826 }
45827 });
45828 if (missedDeprecations.length !== 0) {
45829 throw new Error('Expected deprecation warnings did not happen: ' +
45830 missedDeprecations.join(' '));
45831 }
45832 }
45833 }
45834
45835 function matchedDeprecation(name, msg, deprecations) {
45836 if (deprecations == null) {
45837 return -1;
45838 }
45839 for (var i = 0; i < deprecations.length; ++i) {
45840 if (name != null && name === deprecations[i]) {
45841 return i;
45842 }
45843 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
45844 return i;
45845 }
45846 }
45847 return -1;
45848 }
45849
45850 /*global QUnit:false*/
45851
45852 var test = QUnit.test;
45853
db71a655
KM
45854 function objectKeys(obj) {
45855 if (Object.keys) {
45856 return Object.keys(obj);
45857 } else {
45858 // IE8
45859 var res = [], i;
45860 for (i in obj) {
45861 if (obj.hasOwnProperty(i)) {
45862 res.push(i);
45863 }
b135bf1a 45864 }
db71a655 45865 return res;
b135bf1a
IC
45866 }
45867 }
73f3c911 45868
db71a655 45869 // Pick the first defined of two or three arguments.
b135bf1a 45870
db71a655
KM
45871 function defineCommonLocaleTests(locale, options) {
45872 test('lenient day of month ordinal parsing', function (assert) {
45873 var i, ordinalStr, testMoment;
45874 for (i = 1; i <= 31; ++i) {
45875 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
45876 testMoment = moment(ordinalStr, 'YYYY MM Do');
45877 assert.equal(testMoment.year(), 2014,
45878 'lenient day of month ordinal parsing ' + i + ' year check');
45879 assert.equal(testMoment.month(), 0,
45880 'lenient day of month ordinal parsing ' + i + ' month check');
45881 assert.equal(testMoment.date(), i,
45882 'lenient day of month ordinal parsing ' + i + ' date check');
45883 }
45884 });
b135bf1a 45885
db71a655
KM
45886 test('lenient day of month ordinal parsing of number', function (assert) {
45887 var i, testMoment;
45888 for (i = 1; i <= 31; ++i) {
45889 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
45890 assert.equal(testMoment.year(), 2014,
45891 'lenient day of month ordinal parsing of number ' + i + ' year check');
45892 assert.equal(testMoment.month(), 0,
45893 'lenient day of month ordinal parsing of number ' + i + ' month check');
45894 assert.equal(testMoment.date(), i,
45895 'lenient day of month ordinal parsing of number ' + i + ' date check');
45896 }
b135bf1a
IC
45897 });
45898
db71a655
KM
45899 test('strict day of month ordinal parsing', function (assert) {
45900 var i, ordinalStr, testMoment;
45901 for (i = 1; i <= 31; ++i) {
45902 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
45903 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
45904 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
45905 }
45906 });
b135bf1a 45907
db71a655
KM
45908 test('meridiem invariant', function (assert) {
45909 var h, m, t1, t2;
45910 for (h = 0; h < 24; ++h) {
45911 for (m = 0; m < 60; m += 15) {
45912 t1 = moment.utc([2000, 0, 1, h, m]);
45913 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
45914 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
45915 'meridiem at ' + t1.format('HH:mm'));
45916 }
45917 }
45918 });
b135bf1a 45919
db71a655
KM
45920 test('date format correctness', function (assert) {
45921 var data, tokens;
45922 data = moment.localeData()._longDateFormat;
45923 tokens = objectKeys(data);
45924 each(tokens, function (srchToken) {
45925 // Check each format string to make sure it does not contain any
45926 // tokens that need to be expanded.
45927 each(tokens, function (baseToken) {
45928 // strip escaped sequences
45929 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
45930 assert.equal(false, !!~format.indexOf(srchToken),
45931 'contains ' + srchToken + ' in ' + baseToken);
45932 });
45933 });
45934 });
d6651c21 45935
db71a655
KM
45936 test('month parsing correctness', function (assert) {
45937 var i, m;
45938
45939 if (locale === 'tr') {
45940 // I can't fix it :(
c58511b9 45941 assert.expect(0);
db71a655
KM
45942 return;
45943 }
45944 function tester(format) {
45945 var r;
45946 r = moment(m.format(format), format);
45947 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
45948 if (locale !== 'ka') {
45949 r = moment(m.format(format).toLocaleUpperCase(), format);
45950 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
45951 }
db71a655
KM
45952 r = moment(m.format(format).toLocaleLowerCase(), format);
45953 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
45954
45955 r = moment(m.format(format), format, true);
45956 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
45957 if (locale !== 'ka') {
45958 r = moment(m.format(format).toLocaleUpperCase(), format, true);
45959 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
45960 }
db71a655
KM
45961 r = moment(m.format(format).toLocaleLowerCase(), format, true);
45962 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
45963 }
45964
45965 for (i = 0; i < 12; ++i) {
45966 m = moment([2015, i, 15, 18]);
45967 tester('MMM');
45968 tester('MMM.');
45969 tester('MMMM');
45970 tester('MMMM.');
45971 }
45972 });
d6651c21 45973
db71a655
KM
45974 test('weekday parsing correctness', function (assert) {
45975 var i, m;
45976
96d0d679 45977 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
45978 // tr, az: There is a lower-case letter (ı), that converted to
45979 // upper then lower changes to i
45980 // ro: there is the letter ț which behaves weird under IE8
45981 // mt: letter Ħ
96d0d679 45982 // ga: month with spaces
c58511b9 45983 assert.expect(0);
db71a655
KM
45984 return;
45985 }
45986 function tester(format) {
45987 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
45988 r = moment(m.format(format), format);
45989 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
45990 if (locale !== 'ka') {
45991 r = moment(m.format(format).toLocaleUpperCase(), format);
45992 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
45993 }
db71a655
KM
45994 r = moment(m.format(format).toLocaleLowerCase(), format);
45995 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
45996 r = moment(m.format(format), format, true);
45997 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
45998 if (locale !== 'ka') {
45999 r = moment(m.format(format).toLocaleUpperCase(), format, true);
46000 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
46001 }
db71a655
KM
46002 r = moment(m.format(format).toLocaleLowerCase(), format, true);
46003 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
46004 }
46005
46006 for (i = 0; i < 7; ++i) {
46007 m = moment.utc([2015, 0, i + 1, 18]);
46008 tester('dd');
46009 tester('ddd');
46010 tester('dddd');
46011 }
46012 });
d6651c21 46013
db71a655
KM
46014 test('valid localeData', function (assert) {
46015 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
46016 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
46017 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
46018 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
46019 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
46020 });
96d0d679
KM
46021
46022 test('localeData weekdays can localeSort', function (assert) {
46023 var weekdays = moment().localeData().weekdays();
46024 var weekdaysShort = moment().localeData().weekdaysShort();
46025 var weekdaysMin = moment().localeData().weekdaysMin();
46026 var shift = moment().localeData()._week.dow;
46027 assert.deepEqual(
46028 moment().localeData().weekdays(true),
46029 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
46030 'weekdays should localeSort');
46031 assert.deepEqual(
46032 moment().localeData().weekdaysShort(true),
46033 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
46034 'weekdaysShort should localeSort');
46035 assert.deepEqual(
46036 moment().localeData().weekdaysMin(true),
46037 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
46038 'weekdaysMin should localeSort');
46039 });
db71a655 46040 }
d6651c21 46041
db71a655 46042 /*global QUnit:false*/
516f5f67 46043
db71a655
KM
46044 function localeModule (name, lifecycle) {
46045 QUnit.module('locale:' + name, {
c58511b9 46046 beforeEach : function () {
db71a655
KM
46047 moment.locale(name);
46048 moment.createFromInputFallback = function (config) {
46049 throw new Error('input not handled by moment: ' + config._i);
46050 };
46051 setupDeprecationHandler(test, moment, 'locale');
46052 if (lifecycle && lifecycle.setup) {
46053 lifecycle.setup();
46054 }
46055 },
c58511b9 46056 afterEach : function () {
db71a655
KM
46057 moment.locale('en');
46058 teardownDeprecationHandler(test, moment, 'locale');
46059 if (lifecycle && lifecycle.teardown) {
46060 lifecycle.teardown();
46061 }
73f3c911 46062 }
db71a655
KM
46063 });
46064 defineCommonLocaleTests(name, -1, -1);
46065 }
46066
46067 localeModule('pl');
46068
46069 test('parse', function (assert) {
46070 var tests = 'styczeń stycznia sty_luty lutego lut_marzec marca mar_kwiecień kwietnia kwi_maj maja maj_czerwiec czerwca cze_lipiec lipca lip_sierpień sierpnia sie_wrzesień września wrz_październik października paź_listopad listopada lis_grudzień grudnia gru'.split('_'), i;
46071 function equalTest(input, mmm, i) {
46072 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
46073 }
46074 for (i = 0; i < 12; i++) {
46075 tests[i] = tests[i].split(' ');
46076 equalTest(tests[i][0], 'MMM', i);
46077 equalTest(tests[i][1], 'MMM', i);
46078 equalTest(tests[i][2], 'MMM', i);
46079 equalTest(tests[i][0], 'MMMM', i);
46080 equalTest(tests[i][1], 'MMMM', i);
46081 equalTest(tests[i][2], 'MMMM', i);
46082 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
46083 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
46084 equalTest(tests[i][2].toLocaleLowerCase(), 'MMMM', i);
46085 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
46086 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
46087 equalTest(tests[i][2].toLocaleUpperCase(), 'MMMM', i);
46088 }
46089 });
46090
46091 test('parse strict', function (assert) {
46092 var tests = 'styczeń stycznia sty_luty lutego lut_marzec marca mar_kwiecień kwietnia kwi_maj maja maj_czerwiec czerwca cze_lipiec lipca lip_sierpień sierpnia sie_wrzesień września wrz_październik października paź_listopad listopada lis_grudzień grudnia gru'.split('_'), i;
46093 function equalTest(input, mmm, i) {
46094 assert.equal(moment(input, mmm, true).month(), i, input + ' should be month ' + (i + 1));
46095 }
46096 for (i = 0; i < 12; i++) {
46097 tests[i] = tests[i].split(' ');
46098 equalTest(tests[i][0], 'MMMM', i);
46099 equalTest(tests[i][1], 'MMMM', i);
46100 equalTest(tests[i][2], 'MMM', i);
46101 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
46102 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
46103 equalTest(tests[i][2].toLocaleLowerCase(), 'MMM', i);
46104 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
46105 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
46106 equalTest(tests[i][2].toLocaleUpperCase(), 'MMM', i);
46107 }
46108 });
46109
46110 test('format', function (assert) {
46111 var a = [
46112 ['dddd, MMMM Do YYYY, h:mm:ss a', 'niedziela, luty 14. 2010, 3:25:50 pm'],
46113 ['ddd, hA', 'ndz, 3PM'],
46114 ['M Mo MM MMMM MMM', '2 2. 02 luty lut'],
46115 ['YYYY YY', '2010 10'],
46116 ['D Do DD', '14 14. 14'],
46117 ['d do dddd ddd dd', '0 0. niedziela ndz Nd'],
46118 ['DDD DDDo DDDD', '45 45. 045'],
46119 ['w wo ww', '6 6. 06'],
46120 ['h hh', '3 03'],
46121 ['H HH', '15 15'],
46122 ['m mm', '25 25'],
46123 ['s ss', '50 50'],
46124 ['a A', 'pm PM'],
46125 ['[the] DDDo [day of the year]', 'the 45. day of the year'],
46126 ['LTS', '15:25:50'],
46127 ['L', '14.02.2010'],
46128 ['LL', '14 lutego 2010'],
46129 ['LLL', '14 lutego 2010 15:25'],
46130 ['LLLL', 'niedziela, 14 lutego 2010 15:25'],
46131 ['l', '14.2.2010'],
46132 ['ll', '14 lut 2010'],
46133 ['lll', '14 lut 2010 15:25'],
46134 ['llll', 'ndz, 14 lut 2010 15:25']
46135 ],
46136 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
46137 i;
46138 for (i = 0; i < a.length; i++) {
46139 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
46140 }
46141 });
46142
46143 test('format ordinal', function (assert) {
46144 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
46145 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
46146 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
46147 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
46148 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
46149 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
46150 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
46151 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
46152 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
46153 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
46154
46155 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
46156 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
46157 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
46158 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
46159 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
46160 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
46161 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
46162 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
46163 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
46164 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
46165
46166 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
46167 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
46168 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
46169 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
46170 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
46171 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
46172 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
46173 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
46174 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
46175 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
46176
46177 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
46178 });
46179
46180 test('format month', function (assert) {
46181 var expected = 'styczeń sty_luty lut_marzec mar_kwiecień kwi_maj maj_czerwiec cze_lipiec lip_sierpień sie_wrzesień wrz_październik paź_listopad lis_grudzień gru'.split('_'), i;
46182 for (i = 0; i < expected.length; i++) {
46183 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
46184 }
46185 });
46186
46187 test('format week', function (assert) {
46188 var expected = 'niedziela ndz Nd_poniedziałek pon Pn_wtorek wt Wt_środa śr Śr_czwartek czw Cz_piątek pt Pt_sobota sob So'.split('_'), i;
46189 for (i = 0; i < expected.length; i++) {
46190 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
46191 }
46192 });
46193
46194 test('from', function (assert) {
46195 var start = moment([2007, 1, 28]);
46196 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'kilka sekund', '44 seconds = a few seconds');
46197 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minuta', '45 seconds = a minute');
46198 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minuta', '89 seconds = a minute');
46199 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuty', '90 seconds = 2 minutes');
46200 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuty', '44 minutes = 44 minutes');
46201 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'godzina', '45 minutes = an hour');
46202 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'godzina', '89 minutes = an hour');
46203 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 godziny', '90 minutes = 2 hours');
46204 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 godzin', '5 hours = 5 hours');
46205 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 godzin', '21 hours = 21 hours');
46206 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '1 dzień', '22 hours = a day');
46207 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '1 dzień', '35 hours = a day');
46208 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dni', '36 hours = 2 days');
46209 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '1 dzień', '1 day = a day');
46210 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dni', '5 days = 5 days');
46211 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dni', '25 days = 25 days');
46212 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'miesiąc', '26 days = a month');
46213 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'miesiąc', '30 days = a month');
46214 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'miesiąc', '43 days = a month');
46215 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 miesiące', '46 days = 2 months');
46216 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 miesiące', '75 days = 2 months');
46217 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 miesiące', '76 days = 3 months');
46218 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'miesiąc', '1 month = a month');
46219 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 miesięcy', '5 months = 5 months');
46220 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'rok', '345 days = a year');
46221 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 lata', '548 days = 2 years');
46222 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'rok', '1 year = a year');
46223 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 lat', '5 years = 5 years');
46224 assert.equal(start.from(moment([2007, 1, 28]).add({y: 112}), true), '112 lat', '112 years = 112 years');
46225 assert.equal(start.from(moment([2007, 1, 28]).add({y: 122}), true), '122 lata', '122 years = 122 years');
46226 assert.equal(start.from(moment([2007, 1, 28]).add({y: 213}), true), '213 lat', '213 years = 213 years');
46227 assert.equal(start.from(moment([2007, 1, 28]).add({y: 223}), true), '223 lata', '223 years = 223 years');
46228 });
46229
46230 test('suffix', function (assert) {
46231 assert.equal(moment(30000).from(0), 'za kilka sekund', 'prefix');
46232 assert.equal(moment(0).from(30000), 'kilka sekund temu', 'suffix');
46233 });
46234
46235 test('now from now', function (assert) {
46236 assert.equal(moment().fromNow(), 'kilka sekund temu', 'now from now should display as in the past');
46237 });
46238
46239 test('fromNow', function (assert) {
46240 assert.equal(moment().add({s: 30}).fromNow(), 'za kilka sekund', 'in a few seconds');
46241 assert.equal(moment().add({h: 1}).fromNow(), 'za godzinę', 'in an hour');
46242 assert.equal(moment().add({d: 5}).fromNow(), 'za 5 dni', 'in 5 days');
46243 });
46244
46245 test('calendar day', function (assert) {
46246 var a = moment().hours(12).minutes(0).seconds(0);
46247
46248 assert.equal(moment(a).calendar(), 'Dziś o 12:00', 'today at the same time');
46249 assert.equal(moment(a).add({m: 25}).calendar(), 'Dziś o 12:25', 'Now plus 25 min');
46250 assert.equal(moment(a).add({h: 1}).calendar(), 'Dziś o 13:00', 'Now plus 1 hour');
46251 assert.equal(moment(a).add({d: 1}).calendar(), 'Jutro o 12:00', 'tomorrow at the same time');
46252 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Dziś o 11:00', 'Now minus 1 hour');
46253 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Wczoraj o 12:00', 'yesterday at the same time');
46254 });
46255
46256 test('calendar next week', function (assert) {
46257 var i, m;
46258
46259 function makeFormat(d) {
46260 switch (d.day()) {
46261 case 0:
46262 return '[W niedzielę o] LT';
46263
46264 case 2:
46265 return '[We wtorek o] LT';
46266
46267 case 3:
46268 return '[W środę o] LT';
46269
46270 case 6:
46271 return '[W sobotę o] LT';
46272
46273 default:
46274 return '[W] dddd [o] LT';
c587bf00 46275 }
516f5f67 46276 }
516f5f67 46277
db71a655
KM
46278 for (i = 2; i < 7; i++) {
46279 m = moment().add({d: i});
46280 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time');
c587bf00 46281
db71a655
KM
46282 m.hours(0).minutes(0).seconds(0).milliseconds(0);
46283 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day');
c587bf00 46284
db71a655
KM
46285 m.hours(23).minutes(59).seconds(59).milliseconds(999);
46286 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day');
46287 }
46288 });
c587bf00 46289
db71a655
KM
46290 test('calendar last week', function (assert) {
46291 var i, m;
516f5f67 46292
db71a655
KM
46293 function makeFormat(d) {
46294 switch (d.day()) {
46295 case 0:
46296 return '[W zeszłą niedzielę o] LT';
46297 case 3:
46298 return '[W zeszłą środę o] LT';
46299 case 6:
46300 return '[W zeszłą sobotę o] LT';
46301 default:
46302 return '[W zeszły] dddd [o] LT';
46303 }
46304 }
46305
46306 for (i = 2; i < 7; i++) {
46307 m = moment().subtract({d: i});
46308 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time');
46309
46310 m.hours(0).minutes(0).seconds(0).milliseconds(0);
46311 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day');
516f5f67 46312
db71a655
KM
46313 m.hours(23).minutes(59).seconds(59).milliseconds(999);
46314 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day');
46315 }
46316 });
516f5f67 46317
db71a655
KM
46318 test('calendar all else', function (assert) {
46319 var weeksAgo = moment().subtract({w: 1}),
46320 weeksFromNow = moment().add({w: 1});
516f5f67 46321
db71a655
KM
46322 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
46323 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 46324
db71a655
KM
46325 weeksAgo = moment().subtract({w: 2});
46326 weeksFromNow = moment().add({w: 2});
c587bf00 46327
db71a655
KM
46328 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
46329 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
46330 });
73f3c911 46331
db71a655
KM
46332 test('weeks year starting sunday formatted', function (assert) {
46333 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
46334 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
46335 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
46336 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
46337 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
46338 });
73f3c911
IC
46339
46340})));
c74a101d 46341
516f5f67 46342
c74a101d
IC
46343;(function (global, factory) {
46344 typeof exports === 'object' && typeof module !== 'undefined'
46345 && typeof require === 'function' ? factory(require('../../moment')) :
1d986a17
IC
46346 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
46347 factory(global.moment)
73f3c911 46348}(this, (function (moment) { 'use strict';
1d986a17 46349
db71a655
KM
46350 function each(array, callback) {
46351 var i;
46352 for (i = 0; i < array.length; i++) {
46353 callback(array[i], i, array);
46354 }
b135bf1a
IC
46355 }
46356
db71a655
KM
46357 function setupDeprecationHandler(test, moment$$1, scope) {
46358 test._expectedDeprecations = null;
46359 test._observedDeprecations = null;
46360 test._oldSupress = moment$$1.suppressDeprecationWarnings;
46361 moment$$1.suppressDeprecationWarnings = true;
46362 test.expectedDeprecations = function () {
46363 test._expectedDeprecations = arguments;
46364 test._observedDeprecations = [];
46365 };
46366 moment$$1.deprecationHandler = function (name, msg) {
46367 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
46368 if (deprecationId === -1) {
46369 throw new Error('Unexpected deprecation thrown name=' +
46370 name + ' msg=' + msg);
46371 }
46372 test._observedDeprecations[deprecationId] = 1;
46373 };
46374 }
73f3c911 46375
db71a655
KM
46376 function teardownDeprecationHandler(test, moment$$1, scope) {
46377 moment$$1.suppressDeprecationWarnings = test._oldSupress;
d6651c21 46378
db71a655
KM
46379 if (test._expectedDeprecations != null) {
46380 var missedDeprecations = [];
46381 each(test._expectedDeprecations, function (deprecationPattern, id) {
46382 if (test._observedDeprecations[id] !== 1) {
46383 missedDeprecations.push(deprecationPattern);
46384 }
46385 });
46386 if (missedDeprecations.length !== 0) {
46387 throw new Error('Expected deprecation warnings did not happen: ' +
46388 missedDeprecations.join(' '));
46389 }
d6651c21 46390 }
db71a655 46391 }
b135bf1a 46392
db71a655
KM
46393 function matchedDeprecation(name, msg, deprecations) {
46394 if (deprecations == null) {
46395 return -1;
73f3c911 46396 }
db71a655
KM
46397 for (var i = 0; i < deprecations.length; ++i) {
46398 if (name != null && name === deprecations[i]) {
46399 return i;
46400 }
46401 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
46402 return i;
46403 }
46404 }
46405 return -1;
46406 }
46407
46408 /*global QUnit:false*/
46409
46410 var test = QUnit.test;
1d986a17 46411
c58511b9
KM
46412 function objectKeys(obj) {
46413 if (Object.keys) {
46414 return Object.keys(obj);
46415 } else {
46416 // IE8
46417 var res = [], i;
46418 for (i in obj) {
46419 if (obj.hasOwnProperty(i)) {
46420 res.push(i);
46421 }
46422 }
46423 return res;
46424 }
46425 }
46426
46427 // Pick the first defined of two or three arguments.
46428
46429 function defineCommonLocaleTests(locale, options) {
46430 test('lenient day of month ordinal parsing', function (assert) {
46431 var i, ordinalStr, testMoment;
46432 for (i = 1; i <= 31; ++i) {
46433 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
46434 testMoment = moment(ordinalStr, 'YYYY MM Do');
46435 assert.equal(testMoment.year(), 2014,
46436 'lenient day of month ordinal parsing ' + i + ' year check');
46437 assert.equal(testMoment.month(), 0,
46438 'lenient day of month ordinal parsing ' + i + ' month check');
46439 assert.equal(testMoment.date(), i,
46440 'lenient day of month ordinal parsing ' + i + ' date check');
46441 }
46442 });
46443
46444 test('lenient day of month ordinal parsing of number', function (assert) {
46445 var i, testMoment;
46446 for (i = 1; i <= 31; ++i) {
46447 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
46448 assert.equal(testMoment.year(), 2014,
46449 'lenient day of month ordinal parsing of number ' + i + ' year check');
46450 assert.equal(testMoment.month(), 0,
46451 'lenient day of month ordinal parsing of number ' + i + ' month check');
46452 assert.equal(testMoment.date(), i,
46453 'lenient day of month ordinal parsing of number ' + i + ' date check');
46454 }
46455 });
46456
46457 test('strict day of month ordinal parsing', function (assert) {
46458 var i, ordinalStr, testMoment;
46459 for (i = 1; i <= 31; ++i) {
46460 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
46461 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
46462 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
46463 }
46464 });
46465
46466 test('meridiem invariant', function (assert) {
46467 var h, m, t1, t2;
46468 for (h = 0; h < 24; ++h) {
46469 for (m = 0; m < 60; m += 15) {
46470 t1 = moment.utc([2000, 0, 1, h, m]);
46471 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
46472 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
46473 'meridiem at ' + t1.format('HH:mm'));
46474 }
46475 }
46476 });
46477
46478 test('date format correctness', function (assert) {
46479 var data, tokens;
46480 data = moment.localeData()._longDateFormat;
46481 tokens = objectKeys(data);
46482 each(tokens, function (srchToken) {
46483 // Check each format string to make sure it does not contain any
46484 // tokens that need to be expanded.
46485 each(tokens, function (baseToken) {
46486 // strip escaped sequences
46487 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
46488 assert.equal(false, !!~format.indexOf(srchToken),
46489 'contains ' + srchToken + ' in ' + baseToken);
46490 });
46491 });
46492 });
46493
46494 test('month parsing correctness', function (assert) {
46495 var i, m;
46496
46497 if (locale === 'tr') {
46498 // I can't fix it :(
46499 assert.expect(0);
46500 return;
46501 }
46502 function tester(format) {
46503 var r;
46504 r = moment(m.format(format), format);
46505 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
46506 if (locale !== 'ka') {
46507 r = moment(m.format(format).toLocaleUpperCase(), format);
46508 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
46509 }
c58511b9
KM
46510 r = moment(m.format(format).toLocaleLowerCase(), format);
46511 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
46512
46513 r = moment(m.format(format), format, true);
46514 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
46515 if (locale !== 'ka') {
46516 r = moment(m.format(format).toLocaleUpperCase(), format, true);
46517 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
46518 }
c58511b9
KM
46519 r = moment(m.format(format).toLocaleLowerCase(), format, true);
46520 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
46521 }
46522
46523 for (i = 0; i < 12; ++i) {
46524 m = moment([2015, i, 15, 18]);
46525 tester('MMM');
46526 tester('MMM.');
46527 tester('MMMM');
46528 tester('MMMM.');
46529 }
46530 });
46531
46532 test('weekday parsing correctness', function (assert) {
46533 var i, m;
46534
96d0d679 46535 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
c58511b9
KM
46536 // tr, az: There is a lower-case letter (ı), that converted to
46537 // upper then lower changes to i
46538 // ro: there is the letter ț which behaves weird under IE8
46539 // mt: letter Ħ
96d0d679 46540 // ga: month with spaces
c58511b9
KM
46541 assert.expect(0);
46542 return;
46543 }
46544 function tester(format) {
46545 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
46546 r = moment(m.format(format), format);
46547 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
46548 if (locale !== 'ka') {
46549 r = moment(m.format(format).toLocaleUpperCase(), format);
46550 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
46551 }
c58511b9
KM
46552 r = moment(m.format(format).toLocaleLowerCase(), format);
46553 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
46554 r = moment(m.format(format), format, true);
46555 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
46556 if (locale !== 'ka') {
46557 r = moment(m.format(format).toLocaleUpperCase(), format, true);
46558 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
46559 }
c58511b9
KM
46560 r = moment(m.format(format).toLocaleLowerCase(), format, true);
46561 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
46562 }
46563
46564 for (i = 0; i < 7; ++i) {
46565 m = moment.utc([2015, 0, i + 1, 18]);
46566 tester('dd');
46567 tester('ddd');
46568 tester('dddd');
46569 }
46570 });
46571
46572 test('valid localeData', function (assert) {
46573 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
46574 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
46575 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
46576 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
46577 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
46578 });
96d0d679
KM
46579
46580 test('localeData weekdays can localeSort', function (assert) {
46581 var weekdays = moment().localeData().weekdays();
46582 var weekdaysShort = moment().localeData().weekdaysShort();
46583 var weekdaysMin = moment().localeData().weekdaysMin();
46584 var shift = moment().localeData()._week.dow;
46585 assert.deepEqual(
46586 moment().localeData().weekdays(true),
46587 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
46588 'weekdays should localeSort');
46589 assert.deepEqual(
46590 moment().localeData().weekdaysShort(true),
46591 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
46592 'weekdaysShort should localeSort');
46593 assert.deepEqual(
46594 moment().localeData().weekdaysMin(true),
46595 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
46596 'weekdaysMin should localeSort');
46597 });
c58511b9
KM
46598 }
46599
46600 /*global QUnit:false*/
c74a101d 46601
db71a655
KM
46602 function localeModule (name, lifecycle) {
46603 QUnit.module('locale:' + name, {
c58511b9 46604 beforeEach : function () {
db71a655
KM
46605 moment.locale(name);
46606 moment.createFromInputFallback = function (config) {
46607 throw new Error('input not handled by moment: ' + config._i);
46608 };
46609 setupDeprecationHandler(test, moment, 'locale');
46610 if (lifecycle && lifecycle.setup) {
46611 lifecycle.setup();
46612 }
46613 },
c58511b9 46614 afterEach : function () {
db71a655
KM
46615 moment.locale('en');
46616 teardownDeprecationHandler(test, moment, 'locale');
46617 if (lifecycle && lifecycle.teardown) {
46618 lifecycle.teardown();
46619 }
1d986a17
IC
46620 }
46621 });
db71a655
KM
46622 defineCommonLocaleTests(name, -1, -1);
46623 }
46624
46625 localeModule('pt-br');
46626
46627 test('parse', function (assert) {
96d0d679 46628 var tests = 'Janeiro Jan_Fevereiro Fev_Março Mar_Abril Abr_Maio Mai_Junho Jun_Julho Jul_Agosto Ago_Setembro Set_Outubro Out_Novembro Nov_Dezembro Dez'.split('_'), i;
db71a655
KM
46629
46630 function equalTest(input, mmm, i) {
46631 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
46632 }
46633
46634 for (i = 0; i < 12; i++) {
46635 tests[i] = tests[i].split(' ');
46636 equalTest(tests[i][0], 'MMM', i);
46637 equalTest(tests[i][1], 'MMM', i);
46638 equalTest(tests[i][0], 'MMMM', i);
46639 equalTest(tests[i][1], 'MMMM', i);
46640 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
46641 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
46642 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
46643 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
46644 }
46645 });
46646
46647 test('format', function (assert) {
46648 var a = [
96d0d679 46649 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Domingo, Fevereiro 14º 2010, 3:25:50 pm'],
db71a655 46650 ['ddd, hA', 'Dom, 3PM'],
96d0d679 46651 ['M Mo MM MMMM MMM', '2 2º 02 Fevereiro Fev'],
db71a655
KM
46652 ['YYYY YY', '2010 10'],
46653 ['D Do DD', '14 14º 14'],
46654 ['d do dddd ddd', '0 0º Domingo Dom'],
46655 ['DDD DDDo DDDD', '45 45º 045'],
46656 ['w wo ww', '8 8º 08'],
46657 ['h hh', '3 03'],
46658 ['H HH', '15 15'],
46659 ['m mm', '25 25'],
46660 ['s ss', '50 50'],
46661 ['a A', 'pm PM'],
46662 ['[the] DDDo [day of the year]', 'the 45º day of the year'],
46663 ['LTS', '15:25:50'],
46664 ['L', '14/02/2010'],
96d0d679
KM
46665 ['LL', '14 de Fevereiro de 2010'],
46666 ['LLL', '14 de Fevereiro de 2010 às 15:25'],
46667 ['LLLL', 'Domingo, 14 de Fevereiro de 2010 às 15:25'],
db71a655 46668 ['l', '14/2/2010'],
96d0d679
KM
46669 ['ll', '14 de Fev de 2010'],
46670 ['lll', '14 de Fev de 2010 às 15:25'],
46671 ['llll', 'Dom, 14 de Fev de 2010 às 15:25']
db71a655
KM
46672 ],
46673 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
46674 i;
46675 for (i = 0; i < a.length; i++) {
46676 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
46677 }
46678 });
46679
46680 test('format ordinal', function (assert) {
46681 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1º', '1º');
46682 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2º', '2º');
46683 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3º', '3º');
46684 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4º', '4º');
46685 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5º', '5º');
46686 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6º', '6º');
46687 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7º', '7º');
46688 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8º', '8º');
46689 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9º', '9º');
46690 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10º', '10º');
46691
46692 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11º', '11º');
46693 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12º', '12º');
46694 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13º', '13º');
46695 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14º', '14º');
46696 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15º', '15º');
46697 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16º', '16º');
46698 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17º', '17º');
46699 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18º', '18º');
46700 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19º', '19º');
46701 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20º', '20º');
46702
46703 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21º', '21º');
46704 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22º', '22º');
46705 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23º', '23º');
46706 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24º', '24º');
46707 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25º', '25º');
46708 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26º', '26º');
46709 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27º', '27º');
46710 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28º', '28º');
46711 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29º', '29º');
46712 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30º', '30º');
46713
46714 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31º', '31º');
46715 });
46716
46717 test('format month', function (assert) {
96d0d679 46718 var expected = 'Janeiro Jan_Fevereiro Fev_Março Mar_Abril Abr_Maio Mai_Junho Jun_Julho Jul_Agosto Ago_Setembro Set_Outubro Out_Novembro Nov_Dezembro Dez'.split('_'), i;
db71a655
KM
46719 for (i = 0; i < expected.length; i++) {
46720 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
46721 }
46722 });
46723
46724 test('format week', function (assert) {
46725 var expected = 'Domingo Dom Do_Segunda-feira Seg 2ª_Terça-feira Ter 3ª_Quarta-feira Qua 4ª_Quinta-feira Qui 5ª_Sexta-feira Sex 6ª_Sábado Sáb Sá'.split('_'), i;
46726 for (i = 0; i < expected.length; i++) {
46727 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
46728 }
46729 });
46730
46731 test('from', function (assert) {
46732 var start = moment([2007, 1, 28]);
46733 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'poucos segundos', '44 seconds = seconds');
46734 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'um minuto', '45 seconds = a minute');
46735 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'um minuto', '89 seconds = a minute');
46736 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutos', '90 seconds = 2 minutes');
46737 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutos', '44 minutes = 44 minutes');
46738 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'uma hora', '45 minutes = an hour');
46739 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'uma hora', '89 minutes = an hour');
46740 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 horas', '90 minutes = 2 hours');
46741 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 horas', '5 hours = 5 hours');
46742 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 horas', '21 hours = 21 hours');
46743 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'um dia', '22 hours = a day');
46744 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'um dia', '35 hours = a day');
46745 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dias', '36 hours = 2 days');
46746 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'um dia', '1 day = a day');
46747 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dias', '5 days = 5 days');
46748 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dias', '25 days = 25 days');
46749 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'um mês', '26 days = a month');
46750 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'um mês', '30 days = a month');
46751 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'um mês', '43 days = a month');
46752 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 meses', '46 days = 2 months');
46753 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 meses', '75 days = 2 months');
46754 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 meses', '76 days = 3 months');
46755 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'um mês', '1 month = a month');
46756 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 meses', '5 months = 5 months');
46757 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'um ano', '345 days = a year');
46758 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 anos', '548 days = 2 years');
46759 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'um ano', '1 year = a year');
46760 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 anos', '5 years = 5 years');
46761 });
46762
46763 test('suffix', function (assert) {
46764 assert.equal(moment(30000).from(0), 'em poucos segundos', 'prefix');
46765 assert.equal(moment(0).from(30000), 'há poucos segundos', 'prefix');
46766 });
46767
46768 test('fromNow', function (assert) {
46769 assert.equal(moment().add({s: 30}).fromNow(), 'em poucos segundos', 'in seconds');
46770 assert.equal(moment().add({d: 5}).fromNow(), 'em 5 dias', 'in 5 days');
46771 });
46772
46773 test('calendar day', function (assert) {
46774 var a = moment().hours(12).minutes(0).seconds(0);
46775
46776 assert.equal(moment(a).calendar(), 'Hoje às 12:00', 'today at the same time');
46777 assert.equal(moment(a).add({m: 25}).calendar(), 'Hoje às 12:25', 'Now plus 25 min');
46778 assert.equal(moment(a).add({h: 1}).calendar(), 'Hoje às 13:00', 'Now plus 1 hour');
46779 assert.equal(moment(a).add({d: 1}).calendar(), 'Amanhã às 12:00', 'tomorrow at the same time');
46780 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Hoje às 11:00', 'Now minus 1 hour');
46781 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Ontem às 12:00', 'yesterday at the same time');
46782 });
46783
46784 test('calendar next week', function (assert) {
46785 var i, m;
46786 for (i = 2; i < 7; i++) {
46787 m = moment().add({d: i});
46788 assert.equal(m.calendar(), m.format('dddd [às] LT'), 'Today + ' + i + ' days current time');
46789 m.hours(0).minutes(0).seconds(0).milliseconds(0);
46790 assert.equal(m.calendar(), m.format('dddd [às] LT'), 'Today + ' + i + ' days beginning of day');
46791 m.hours(23).minutes(59).seconds(59).milliseconds(999);
46792 assert.equal(m.calendar(), m.format('dddd [às] LT'), 'Today + ' + i + ' days end of day');
73f3c911 46793 }
db71a655 46794 });
1d986a17 46795
db71a655
KM
46796 test('calendar last week', function (assert) {
46797 var i, m;
46798 for (i = 2; i < 7; i++) {
46799 m = moment().subtract({d: i});
46800 assert.equal(m.calendar(), m.format((m.day() === 0 || m.day() === 6) ? '[Último] dddd [às] LT' : '[Última] dddd [às] LT'), 'Today - ' + i + ' days current time');
46801 m.hours(0).minutes(0).seconds(0).milliseconds(0);
46802 assert.equal(m.calendar(), m.format((m.day() === 0 || m.day() === 6) ? '[Último] dddd [às] LT' : '[Última] dddd [às] LT'), 'Today - ' + i + ' days beginning of day');
46803 m.hours(23).minutes(59).seconds(59).milliseconds(999);
46804 assert.equal(m.calendar(), m.format((m.day() === 0 || m.day() === 6) ? '[Último] dddd [às] LT' : '[Última] dddd [às] LT'), 'Today - ' + i + ' days end of day');
c74a101d 46805 }
db71a655 46806 });
c74a101d 46807
db71a655
KM
46808 test('calendar all else', function (assert) {
46809 var weeksAgo = moment().subtract({w: 1}),
46810 weeksFromNow = moment().add({w: 1});
c74a101d 46811
db71a655
KM
46812 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
46813 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
c74a101d 46814
db71a655
KM
46815 weeksAgo = moment().subtract({w: 2});
46816 weeksFromNow = moment().add({w: 2});
c74a101d 46817
db71a655
KM
46818 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
46819 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
46820 });
46821
46822 test('weeks year starting sunday format', function (assert) {
46823 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1º', 'Jan 1 2012 should be week 1');
46824 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1º', 'Jan 7 2012 should be week 1');
46825 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2º', 'Jan 8 2012 should be week 2');
46826 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2º', 'Jan 14 2012 should be week 2');
46827 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3º', 'Jan 15 2012 should be week 3');
46828 });
46829
46830 test('relative time threshold', function (assert) {
46831 var rts = moment(),
46832 rtsDefault = moment.relativeTimeThreshold('ss');
46833
46834 moment.relativeTimeThreshold('ss', 3);
46835
46836 rts.subtract(3, 'seconds');
46837 assert.equal(rts.fromNow(), 'há poucos segundos', 'Below custom a few seconds to seconds threshold');
46838 rts.subtract(1, 'seconds');
46839 assert.equal(rts.fromNow(), 'há 4 segundos', 'Above custom a few seconds to seconds threshold');
46840
46841 moment.relativeTimeThreshold('ss', rtsDefault);
46842 });
73f3c911
IC
46843
46844})));
46845
c74a101d
IC
46846
46847;(function (global, factory) {
46848 typeof exports === 'object' && typeof module !== 'undefined'
46849 && typeof require === 'function' ? factory(require('../../moment')) :
46850 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
46851 factory(global.moment)
73f3c911 46852}(this, (function (moment) { 'use strict';
c74a101d 46853
db71a655
KM
46854 function each(array, callback) {
46855 var i;
46856 for (i = 0; i < array.length; i++) {
46857 callback(array[i], i, array);
46858 }
b135bf1a
IC
46859 }
46860
c58511b9
KM
46861 function setupDeprecationHandler(test, moment$$1, scope) {
46862 test._expectedDeprecations = null;
46863 test._observedDeprecations = null;
46864 test._oldSupress = moment$$1.suppressDeprecationWarnings;
46865 moment$$1.suppressDeprecationWarnings = true;
46866 test.expectedDeprecations = function () {
46867 test._expectedDeprecations = arguments;
46868 test._observedDeprecations = [];
46869 };
46870 moment$$1.deprecationHandler = function (name, msg) {
46871 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
46872 if (deprecationId === -1) {
46873 throw new Error('Unexpected deprecation thrown name=' +
46874 name + ' msg=' + msg);
46875 }
46876 test._observedDeprecations[deprecationId] = 1;
46877 };
46878 }
46879
46880 function teardownDeprecationHandler(test, moment$$1, scope) {
46881 moment$$1.suppressDeprecationWarnings = test._oldSupress;
46882
46883 if (test._expectedDeprecations != null) {
46884 var missedDeprecations = [];
46885 each(test._expectedDeprecations, function (deprecationPattern, id) {
46886 if (test._observedDeprecations[id] !== 1) {
46887 missedDeprecations.push(deprecationPattern);
46888 }
46889 });
46890 if (missedDeprecations.length !== 0) {
46891 throw new Error('Expected deprecation warnings did not happen: ' +
46892 missedDeprecations.join(' '));
46893 }
46894 }
46895 }
46896
46897 function matchedDeprecation(name, msg, deprecations) {
46898 if (deprecations == null) {
46899 return -1;
46900 }
46901 for (var i = 0; i < deprecations.length; ++i) {
46902 if (name != null && name === deprecations[i]) {
46903 return i;
46904 }
46905 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
46906 return i;
46907 }
46908 }
46909 return -1;
46910 }
46911
46912 /*global QUnit:false*/
46913
46914 var test = QUnit.test;
46915
db71a655
KM
46916 function objectKeys(obj) {
46917 if (Object.keys) {
46918 return Object.keys(obj);
46919 } else {
46920 // IE8
46921 var res = [], i;
46922 for (i in obj) {
46923 if (obj.hasOwnProperty(i)) {
46924 res.push(i);
46925 }
b135bf1a 46926 }
db71a655 46927 return res;
b135bf1a
IC
46928 }
46929 }
46930
db71a655 46931 // Pick the first defined of two or three arguments.
b135bf1a 46932
db71a655
KM
46933 function defineCommonLocaleTests(locale, options) {
46934 test('lenient day of month ordinal parsing', function (assert) {
46935 var i, ordinalStr, testMoment;
46936 for (i = 1; i <= 31; ++i) {
46937 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
46938 testMoment = moment(ordinalStr, 'YYYY MM Do');
46939 assert.equal(testMoment.year(), 2014,
46940 'lenient day of month ordinal parsing ' + i + ' year check');
46941 assert.equal(testMoment.month(), 0,
46942 'lenient day of month ordinal parsing ' + i + ' month check');
46943 assert.equal(testMoment.date(), i,
46944 'lenient day of month ordinal parsing ' + i + ' date check');
46945 }
46946 });
b135bf1a 46947
db71a655
KM
46948 test('lenient day of month ordinal parsing of number', function (assert) {
46949 var i, testMoment;
46950 for (i = 1; i <= 31; ++i) {
46951 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
46952 assert.equal(testMoment.year(), 2014,
46953 'lenient day of month ordinal parsing of number ' + i + ' year check');
46954 assert.equal(testMoment.month(), 0,
46955 'lenient day of month ordinal parsing of number ' + i + ' month check');
46956 assert.equal(testMoment.date(), i,
46957 'lenient day of month ordinal parsing of number ' + i + ' date check');
46958 }
46959 });
b135bf1a 46960
db71a655
KM
46961 test('strict day of month ordinal parsing', function (assert) {
46962 var i, ordinalStr, testMoment;
46963 for (i = 1; i <= 31; ++i) {
46964 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
46965 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
46966 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
46967 }
46968 });
b135bf1a 46969
db71a655
KM
46970 test('meridiem invariant', function (assert) {
46971 var h, m, t1, t2;
46972 for (h = 0; h < 24; ++h) {
46973 for (m = 0; m < 60; m += 15) {
46974 t1 = moment.utc([2000, 0, 1, h, m]);
46975 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
46976 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
46977 'meridiem at ' + t1.format('HH:mm'));
46978 }
46979 }
46980 });
46981
46982 test('date format correctness', function (assert) {
46983 var data, tokens;
46984 data = moment.localeData()._longDateFormat;
46985 tokens = objectKeys(data);
46986 each(tokens, function (srchToken) {
46987 // Check each format string to make sure it does not contain any
46988 // tokens that need to be expanded.
46989 each(tokens, function (baseToken) {
46990 // strip escaped sequences
46991 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
46992 assert.equal(false, !!~format.indexOf(srchToken),
46993 'contains ' + srchToken + ' in ' + baseToken);
46994 });
b135bf1a
IC
46995 });
46996 });
d6651c21 46997
db71a655
KM
46998 test('month parsing correctness', function (assert) {
46999 var i, m;
47000
47001 if (locale === 'tr') {
47002 // I can't fix it :(
c58511b9 47003 assert.expect(0);
db71a655
KM
47004 return;
47005 }
47006 function tester(format) {
47007 var r;
47008 r = moment(m.format(format), format);
47009 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
47010 if (locale !== 'ka') {
47011 r = moment(m.format(format).toLocaleUpperCase(), format);
47012 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
47013 }
db71a655
KM
47014 r = moment(m.format(format).toLocaleLowerCase(), format);
47015 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
47016
47017 r = moment(m.format(format), format, true);
47018 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
47019 if (locale !== 'ka') {
47020 r = moment(m.format(format).toLocaleUpperCase(), format, true);
47021 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
47022 }
db71a655
KM
47023 r = moment(m.format(format).toLocaleLowerCase(), format, true);
47024 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
47025 }
47026
47027 for (i = 0; i < 12; ++i) {
47028 m = moment([2015, i, 15, 18]);
47029 tester('MMM');
47030 tester('MMM.');
47031 tester('MMMM');
47032 tester('MMMM.');
47033 }
47034 });
d6651c21 47035
db71a655
KM
47036 test('weekday parsing correctness', function (assert) {
47037 var i, m;
47038
96d0d679 47039 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
47040 // tr, az: There is a lower-case letter (ı), that converted to
47041 // upper then lower changes to i
47042 // ro: there is the letter ț which behaves weird under IE8
47043 // mt: letter Ħ
96d0d679 47044 // ga: month with spaces
c58511b9 47045 assert.expect(0);
db71a655
KM
47046 return;
47047 }
47048 function tester(format) {
47049 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
47050 r = moment(m.format(format), format);
47051 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
47052 if (locale !== 'ka') {
47053 r = moment(m.format(format).toLocaleUpperCase(), format);
47054 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
47055 }
db71a655
KM
47056 r = moment(m.format(format).toLocaleLowerCase(), format);
47057 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
47058 r = moment(m.format(format), format, true);
47059 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
47060 if (locale !== 'ka') {
47061 r = moment(m.format(format).toLocaleUpperCase(), format, true);
47062 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
47063 }
db71a655
KM
47064 r = moment(m.format(format).toLocaleLowerCase(), format, true);
47065 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
47066 }
47067
47068 for (i = 0; i < 7; ++i) {
47069 m = moment.utc([2015, 0, i + 1, 18]);
47070 tester('dd');
47071 tester('ddd');
47072 tester('dddd');
47073 }
47074 });
d6651c21 47075
db71a655
KM
47076 test('valid localeData', function (assert) {
47077 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
47078 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
47079 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
47080 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
47081 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
47082 });
96d0d679
KM
47083
47084 test('localeData weekdays can localeSort', function (assert) {
47085 var weekdays = moment().localeData().weekdays();
47086 var weekdaysShort = moment().localeData().weekdaysShort();
47087 var weekdaysMin = moment().localeData().weekdaysMin();
47088 var shift = moment().localeData()._week.dow;
47089 assert.deepEqual(
47090 moment().localeData().weekdays(true),
47091 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
47092 'weekdays should localeSort');
47093 assert.deepEqual(
47094 moment().localeData().weekdaysShort(true),
47095 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
47096 'weekdaysShort should localeSort');
47097 assert.deepEqual(
47098 moment().localeData().weekdaysMin(true),
47099 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
47100 'weekdaysMin should localeSort');
47101 });
db71a655
KM
47102 }
47103
db71a655
KM
47104 /*global QUnit:false*/
47105
db71a655
KM
47106 function localeModule (name, lifecycle) {
47107 QUnit.module('locale:' + name, {
c58511b9 47108 beforeEach : function () {
db71a655
KM
47109 moment.locale(name);
47110 moment.createFromInputFallback = function (config) {
47111 throw new Error('input not handled by moment: ' + config._i);
47112 };
47113 setupDeprecationHandler(test, moment, 'locale');
47114 if (lifecycle && lifecycle.setup) {
47115 lifecycle.setup();
47116 }
47117 },
c58511b9 47118 afterEach : function () {
db71a655
KM
47119 moment.locale('en');
47120 teardownDeprecationHandler(test, moment, 'locale');
47121 if (lifecycle && lifecycle.teardown) {
47122 lifecycle.teardown();
47123 }
c74a101d
IC
47124 }
47125 });
db71a655
KM
47126 defineCommonLocaleTests(name, -1, -1);
47127 }
47128
47129 localeModule('pt');
47130
47131 test('parse', function (assert) {
96d0d679 47132 var tests = 'Janeiro Jan_Fevereiro Fev_Março Mar_Abril Abr_Maio Mai_Junho Jun_Julho Jul_Agosto Ago_Setembro Set_Outubro Out_Novembro Nov_Dezembro Dez'.split('_'), i;
db71a655
KM
47133 function equalTest(input, mmm, i) {
47134 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
47135 }
47136 for (i = 0; i < 12; i++) {
47137 tests[i] = tests[i].split(' ');
47138 equalTest(tests[i][0], 'MMM', i);
47139 equalTest(tests[i][1], 'MMM', i);
47140 equalTest(tests[i][0], 'MMMM', i);
47141 equalTest(tests[i][1], 'MMMM', i);
47142 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
47143 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
47144 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
47145 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
47146 }
47147 });
47148
47149 test('format', function (assert) {
47150 var a = [
96d0d679 47151 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Domingo, Fevereiro 14º 2010, 3:25:50 pm'],
db71a655 47152 ['ddd, hA', 'Dom, 3PM'],
96d0d679 47153 ['M Mo MM MMMM MMM', '2 2º 02 Fevereiro Fev'],
db71a655
KM
47154 ['YYYY YY', '2010 10'],
47155 ['D Do DD', '14 14º 14'],
47156 ['d do dddd ddd', '0 0º Domingo Dom'],
47157 ['DDD DDDo DDDD', '45 45º 045'],
47158 ['w wo ww', '6 6º 06'],
47159 ['h hh', '3 03'],
47160 ['H HH', '15 15'],
47161 ['m mm', '25 25'],
47162 ['s ss', '50 50'],
47163 ['a A', 'pm PM'],
47164 ['[the] DDDo [day of the year]', 'the 45º day of the year'],
47165 ['LTS', '15:25:50'],
47166 ['L', '14/02/2010'],
96d0d679
KM
47167 ['LL', '14 de Fevereiro de 2010'],
47168 ['LLL', '14 de Fevereiro de 2010 15:25'],
47169 ['LLLL', 'Domingo, 14 de Fevereiro de 2010 15:25'],
db71a655 47170 ['l', '14/2/2010'],
96d0d679
KM
47171 ['ll', '14 de Fev de 2010'],
47172 ['lll', '14 de Fev de 2010 15:25'],
47173 ['llll', 'Dom, 14 de Fev de 2010 15:25']
db71a655
KM
47174 ],
47175 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
47176 i;
47177 for (i = 0; i < a.length; i++) {
47178 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
47179 }
47180 });
47181
47182 test('format ordinal', function (assert) {
47183 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1º', '1º');
47184 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2º', '2º');
47185 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3º', '3º');
47186 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4º', '4º');
47187 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5º', '5º');
47188 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6º', '6º');
47189 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7º', '7º');
47190 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8º', '8º');
47191 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9º', '9º');
47192 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10º', '10º');
47193
47194 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11º', '11º');
47195 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12º', '12º');
47196 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13º', '13º');
47197 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14º', '14º');
47198 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15º', '15º');
47199 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16º', '16º');
47200 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17º', '17º');
47201 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18º', '18º');
47202 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19º', '19º');
47203 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20º', '20º');
47204
47205 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21º', '21º');
47206 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22º', '22º');
47207 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23º', '23º');
47208 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24º', '24º');
47209 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25º', '25º');
47210 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26º', '26º');
47211 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27º', '27º');
47212 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28º', '28º');
47213 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29º', '29º');
47214 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30º', '30º');
47215
47216 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31º', '31º');
47217 });
47218
47219 test('format month', function (assert) {
96d0d679 47220 var expected = 'Janeiro Jan_Fevereiro Fev_Março Mar_Abril Abr_Maio Mai_Junho Jun_Julho Jul_Agosto Ago_Setembro Set_Outubro Out_Novembro Nov_Dezembro Dez'.split('_'), i;
db71a655
KM
47221 for (i = 0; i < expected.length; i++) {
47222 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
47223 }
47224 });
47225
47226 test('format week', function (assert) {
47227 var expected = 'Domingo Dom Do_Segunda-feira Seg 2ª_Terça-feira Ter 3ª_Quarta-feira Qua 4ª_Quinta-feira Qui 5ª_Sexta-feira Sex 6ª_Sábado Sáb Sá'.split('_'), i;
47228 for (i = 0; i < expected.length; i++) {
47229 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
47230 }
47231 });
47232
47233 test('from', function (assert) {
47234 var start = moment([2007, 1, 28]);
47235 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'segundos', '44 seconds = seconds');
47236 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'um minuto', '45 seconds = a minute');
47237 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'um minuto', '89 seconds = a minute');
47238 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutos', '90 seconds = 2 minutes');
47239 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutos', '44 minutes = 44 minutes');
47240 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'uma hora', '45 minutes = an hour');
47241 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'uma hora', '89 minutes = an hour');
47242 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 horas', '90 minutes = 2 hours');
47243 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 horas', '5 hours = 5 hours');
47244 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 horas', '21 hours = 21 hours');
47245 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'um dia', '22 hours = a day');
47246 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'um dia', '35 hours = a day');
47247 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dias', '36 hours = 2 days');
47248 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'um dia', '1 day = a day');
47249 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dias', '5 days = 5 days');
47250 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dias', '25 days = 25 days');
47251 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'um mês', '26 days = a month');
47252 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'um mês', '30 days = a month');
47253 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'um mês', '43 days = a month');
47254 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 meses', '46 days = 2 months');
47255 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 meses', '75 days = 2 months');
47256 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 meses', '76 days = 3 months');
47257 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'um mês', '1 month = a month');
47258 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 meses', '5 months = 5 months');
47259 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'um ano', '345 days = a year');
47260 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 anos', '548 days = 2 years');
47261 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'um ano', '1 year = a year');
47262 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 anos', '5 years = 5 years');
47263 });
47264
47265 test('suffix', function (assert) {
47266 assert.equal(moment(30000).from(0), 'em segundos', 'prefix');
47267 assert.equal(moment(0).from(30000), 'há segundos', 'suffix');
47268 });
47269
47270 test('fromNow', function (assert) {
47271 assert.equal(moment().add({s: 30}).fromNow(), 'em segundos', 'in seconds');
47272 assert.equal(moment().add({d: 5}).fromNow(), 'em 5 dias', 'in 5 days');
47273 });
47274
47275 test('calendar day', function (assert) {
47276 var a = moment().hours(12).minutes(0).seconds(0);
47277
47278 assert.equal(moment(a).calendar(), 'Hoje às 12:00', 'today at the same time');
47279 assert.equal(moment(a).add({m: 25}).calendar(), 'Hoje às 12:25', 'Now plus 25 min');
47280 assert.equal(moment(a).add({h: 1}).calendar(), 'Hoje às 13:00', 'Now plus 1 hour');
47281 assert.equal(moment(a).add({d: 1}).calendar(), 'Amanhã às 12:00', 'tomorrow at the same time');
47282 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Hoje às 11:00', 'Now minus 1 hour');
47283 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Ontem às 12:00', 'yesterday at the same time');
47284 });
47285
47286 test('calendar next week', function (assert) {
47287 var i, m;
47288 for (i = 2; i < 7; i++) {
47289 m = moment().add({d: i});
47290 assert.equal(m.calendar(), m.format('dddd [às] LT'), 'Today + ' + i + ' days current time');
47291 m.hours(0).minutes(0).seconds(0).milliseconds(0);
47292 assert.equal(m.calendar(), m.format('dddd [às] LT'), 'Today + ' + i + ' days beginning of day');
47293 m.hours(23).minutes(59).seconds(59).milliseconds(999);
47294 assert.equal(m.calendar(), m.format('dddd [às] LT'), 'Today + ' + i + ' days end of day');
73f3c911 47295 }
db71a655 47296 });
c74a101d 47297
db71a655
KM
47298 test('calendar last week', function (assert) {
47299 var i, m;
47300 for (i = 2; i < 7; i++) {
47301 m = moment().subtract({d: i});
47302 assert.equal(m.calendar(), m.format((m.day() === 0 || m.day() === 6) ? '[Último] dddd [às] LT' : '[Última] dddd [às] LT'), 'Today - ' + i + ' days current time');
47303 m.hours(0).minutes(0).seconds(0).milliseconds(0);
47304 assert.equal(m.calendar(), m.format((m.day() === 0 || m.day() === 6) ? '[Último] dddd [às] LT' : '[Última] dddd [às] LT'), 'Today - ' + i + ' days beginning of day');
47305 m.hours(23).minutes(59).seconds(59).milliseconds(999);
47306 assert.equal(m.calendar(), m.format((m.day() === 0 || m.day() === 6) ? '[Último] dddd [às] LT' : '[Última] dddd [às] LT'), 'Today - ' + i + ' days end of day');
c74a101d 47307 }
db71a655 47308 });
c74a101d 47309
db71a655
KM
47310 test('calendar all else', function (assert) {
47311 var weeksAgo = moment().subtract({w: 1}),
47312 weeksFromNow = moment().add({w: 1});
c74a101d 47313
db71a655
KM
47314 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
47315 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
c74a101d 47316
db71a655
KM
47317 weeksAgo = moment().subtract({w: 2});
47318 weeksFromNow = moment().add({w: 2});
c74a101d 47319
db71a655
KM
47320 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
47321 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
47322 });
47323
47324 test('weeks year starting sunday formatted', function (assert) {
47325 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52º', 'Jan 1 2012 should be week 52');
47326 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1º', 'Jan 2 2012 should be week 1');
47327 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1º', 'Jan 8 2012 should be week 1');
47328 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2º', 'Jan 9 2012 should be week 2');
47329 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2º', 'Jan 15 2012 should be week 2');
47330 });
73f3c911
IC
47331
47332})));
c74a101d 47333
c74a101d
IC
47334
47335;(function (global, factory) {
47336 typeof exports === 'object' && typeof module !== 'undefined'
47337 && typeof require === 'function' ? factory(require('../../moment')) :
47338 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
47339 factory(global.moment)
73f3c911 47340}(this, (function (moment) { 'use strict';
c74a101d 47341
db71a655
KM
47342 function each(array, callback) {
47343 var i;
47344 for (i = 0; i < array.length; i++) {
47345 callback(array[i], i, array);
47346 }
b135bf1a
IC
47347 }
47348
c58511b9
KM
47349 function setupDeprecationHandler(test, moment$$1, scope) {
47350 test._expectedDeprecations = null;
47351 test._observedDeprecations = null;
47352 test._oldSupress = moment$$1.suppressDeprecationWarnings;
47353 moment$$1.suppressDeprecationWarnings = true;
47354 test.expectedDeprecations = function () {
47355 test._expectedDeprecations = arguments;
47356 test._observedDeprecations = [];
47357 };
47358 moment$$1.deprecationHandler = function (name, msg) {
47359 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
47360 if (deprecationId === -1) {
47361 throw new Error('Unexpected deprecation thrown name=' +
47362 name + ' msg=' + msg);
47363 }
47364 test._observedDeprecations[deprecationId] = 1;
47365 };
47366 }
47367
47368 function teardownDeprecationHandler(test, moment$$1, scope) {
47369 moment$$1.suppressDeprecationWarnings = test._oldSupress;
47370
47371 if (test._expectedDeprecations != null) {
47372 var missedDeprecations = [];
47373 each(test._expectedDeprecations, function (deprecationPattern, id) {
47374 if (test._observedDeprecations[id] !== 1) {
47375 missedDeprecations.push(deprecationPattern);
47376 }
47377 });
47378 if (missedDeprecations.length !== 0) {
47379 throw new Error('Expected deprecation warnings did not happen: ' +
47380 missedDeprecations.join(' '));
47381 }
47382 }
47383 }
47384
47385 function matchedDeprecation(name, msg, deprecations) {
47386 if (deprecations == null) {
47387 return -1;
47388 }
47389 for (var i = 0; i < deprecations.length; ++i) {
47390 if (name != null && name === deprecations[i]) {
47391 return i;
47392 }
47393 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
47394 return i;
47395 }
47396 }
47397 return -1;
47398 }
47399
47400 /*global QUnit:false*/
47401
47402 var test = QUnit.test;
47403
db71a655
KM
47404 function objectKeys(obj) {
47405 if (Object.keys) {
47406 return Object.keys(obj);
47407 } else {
47408 // IE8
47409 var res = [], i;
47410 for (i in obj) {
47411 if (obj.hasOwnProperty(i)) {
47412 res.push(i);
47413 }
b135bf1a 47414 }
db71a655 47415 return res;
b135bf1a
IC
47416 }
47417 }
47418
db71a655 47419 // Pick the first defined of two or three arguments.
73f3c911 47420
db71a655
KM
47421 function defineCommonLocaleTests(locale, options) {
47422 test('lenient day of month ordinal parsing', function (assert) {
47423 var i, ordinalStr, testMoment;
47424 for (i = 1; i <= 31; ++i) {
47425 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
47426 testMoment = moment(ordinalStr, 'YYYY MM Do');
47427 assert.equal(testMoment.year(), 2014,
47428 'lenient day of month ordinal parsing ' + i + ' year check');
47429 assert.equal(testMoment.month(), 0,
47430 'lenient day of month ordinal parsing ' + i + ' month check');
47431 assert.equal(testMoment.date(), i,
47432 'lenient day of month ordinal parsing ' + i + ' date check');
47433 }
47434 });
73f3c911 47435
db71a655
KM
47436 test('lenient day of month ordinal parsing of number', function (assert) {
47437 var i, testMoment;
47438 for (i = 1; i <= 31; ++i) {
47439 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
47440 assert.equal(testMoment.year(), 2014,
47441 'lenient day of month ordinal parsing of number ' + i + ' year check');
47442 assert.equal(testMoment.month(), 0,
47443 'lenient day of month ordinal parsing of number ' + i + ' month check');
47444 assert.equal(testMoment.date(), i,
47445 'lenient day of month ordinal parsing of number ' + i + ' date check');
47446 }
47447 });
b135bf1a 47448
db71a655
KM
47449 test('strict day of month ordinal parsing', function (assert) {
47450 var i, ordinalStr, testMoment;
47451 for (i = 1; i <= 31; ++i) {
47452 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
47453 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
47454 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
47455 }
47456 });
b135bf1a 47457
db71a655
KM
47458 test('meridiem invariant', function (assert) {
47459 var h, m, t1, t2;
47460 for (h = 0; h < 24; ++h) {
47461 for (m = 0; m < 60; m += 15) {
47462 t1 = moment.utc([2000, 0, 1, h, m]);
47463 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
47464 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
47465 'meridiem at ' + t1.format('HH:mm'));
47466 }
47467 }
47468 });
47469
47470 test('date format correctness', function (assert) {
47471 var data, tokens;
47472 data = moment.localeData()._longDateFormat;
47473 tokens = objectKeys(data);
47474 each(tokens, function (srchToken) {
47475 // Check each format string to make sure it does not contain any
47476 // tokens that need to be expanded.
47477 each(tokens, function (baseToken) {
47478 // strip escaped sequences
47479 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
47480 assert.equal(false, !!~format.indexOf(srchToken),
47481 'contains ' + srchToken + ' in ' + baseToken);
47482 });
73f3c911 47483 });
b135bf1a
IC
47484 });
47485
db71a655
KM
47486 test('month parsing correctness', function (assert) {
47487 var i, m;
47488
47489 if (locale === 'tr') {
47490 // I can't fix it :(
c58511b9 47491 assert.expect(0);
db71a655
KM
47492 return;
47493 }
47494 function tester(format) {
47495 var r;
47496 r = moment(m.format(format), format);
47497 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
47498 if (locale !== 'ka') {
47499 r = moment(m.format(format).toLocaleUpperCase(), format);
47500 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
47501 }
db71a655
KM
47502 r = moment(m.format(format).toLocaleLowerCase(), format);
47503 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
47504
47505 r = moment(m.format(format), format, true);
47506 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
47507 if (locale !== 'ka') {
47508 r = moment(m.format(format).toLocaleUpperCase(), format, true);
47509 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
47510 }
db71a655
KM
47511 r = moment(m.format(format).toLocaleLowerCase(), format, true);
47512 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
47513 }
47514
47515 for (i = 0; i < 12; ++i) {
47516 m = moment([2015, i, 15, 18]);
47517 tester('MMM');
47518 tester('MMM.');
47519 tester('MMMM');
47520 tester('MMMM.');
47521 }
47522 });
d6651c21 47523
db71a655
KM
47524 test('weekday parsing correctness', function (assert) {
47525 var i, m;
47526
96d0d679 47527 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
47528 // tr, az: There is a lower-case letter (ı), that converted to
47529 // upper then lower changes to i
47530 // ro: there is the letter ț which behaves weird under IE8
47531 // mt: letter Ħ
96d0d679 47532 // ga: month with spaces
c58511b9 47533 assert.expect(0);
db71a655
KM
47534 return;
47535 }
47536 function tester(format) {
47537 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
47538 r = moment(m.format(format), format);
47539 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
47540 if (locale !== 'ka') {
47541 r = moment(m.format(format).toLocaleUpperCase(), format);
47542 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
47543 }
db71a655
KM
47544 r = moment(m.format(format).toLocaleLowerCase(), format);
47545 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
47546 r = moment(m.format(format), format, true);
47547 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
47548 if (locale !== 'ka') {
47549 r = moment(m.format(format).toLocaleUpperCase(), format, true);
47550 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
47551 }
db71a655
KM
47552 r = moment(m.format(format).toLocaleLowerCase(), format, true);
47553 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
47554 }
47555
47556 for (i = 0; i < 7; ++i) {
47557 m = moment.utc([2015, 0, i + 1, 18]);
47558 tester('dd');
47559 tester('ddd');
47560 tester('dddd');
47561 }
47562 });
d6651c21 47563
db71a655
KM
47564 test('valid localeData', function (assert) {
47565 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
47566 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
47567 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
47568 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
47569 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
47570 });
96d0d679
KM
47571
47572 test('localeData weekdays can localeSort', function (assert) {
47573 var weekdays = moment().localeData().weekdays();
47574 var weekdaysShort = moment().localeData().weekdaysShort();
47575 var weekdaysMin = moment().localeData().weekdaysMin();
47576 var shift = moment().localeData()._week.dow;
47577 assert.deepEqual(
47578 moment().localeData().weekdays(true),
47579 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
47580 'weekdays should localeSort');
47581 assert.deepEqual(
47582 moment().localeData().weekdaysShort(true),
47583 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
47584 'weekdaysShort should localeSort');
47585 assert.deepEqual(
47586 moment().localeData().weekdaysMin(true),
47587 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
47588 'weekdaysMin should localeSort');
47589 });
db71a655 47590 }
d6651c21 47591
db71a655 47592 /*global QUnit:false*/
c74a101d 47593
db71a655
KM
47594 function localeModule (name, lifecycle) {
47595 QUnit.module('locale:' + name, {
c58511b9 47596 beforeEach : function () {
db71a655
KM
47597 moment.locale(name);
47598 moment.createFromInputFallback = function (config) {
47599 throw new Error('input not handled by moment: ' + config._i);
47600 };
47601 setupDeprecationHandler(test, moment, 'locale');
47602 if (lifecycle && lifecycle.setup) {
47603 lifecycle.setup();
47604 }
47605 },
c58511b9 47606 afterEach : function () {
db71a655
KM
47607 moment.locale('en');
47608 teardownDeprecationHandler(test, moment, 'locale');
47609 if (lifecycle && lifecycle.teardown) {
47610 lifecycle.teardown();
47611 }
c74a101d
IC
47612 }
47613 });
db71a655
KM
47614 defineCommonLocaleTests(name, -1, -1);
47615 }
47616
47617 localeModule('ro');
47618
47619 test('parse', function (assert) {
47620 var tests = 'ianuarie ian._februarie febr._martie mart._aprilie apr._mai mai_iunie iun._iulie iul._august aug._septembrie sept._octombrie oct._noiembrie nov._decembrie dec.'.split('_'), i;
47621 function equalTest(input, mmm, i) {
47622 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
47623 }
47624 for (i = 0; i < 12; i++) {
47625 tests[i] = tests[i].split(' ');
47626 equalTest(tests[i][0], 'MMM', i);
47627 equalTest(tests[i][1], 'MMM', i);
47628 equalTest(tests[i][0], 'MMMM', i);
47629 equalTest(tests[i][1], 'MMMM', i);
47630 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
47631 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
47632 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
47633 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
47634 }
47635 });
47636
47637 test('format', function (assert) {
47638 var a = [
47639 ['dddd, MMMM Do YYYY, h:mm:ss A', 'duminică, februarie 14 2010, 3:25:50 PM'],
47640 ['ddd, hA', 'Dum, 3PM'],
47641 ['M Mo MM MMMM MMM', '2 2 02 februarie febr.'],
47642 ['YYYY YY', '2010 10'],
47643 ['D Do DD', '14 14 14'],
47644 ['d do dddd ddd dd', '0 0 duminică Dum Du'],
47645 ['DDD DDDo DDDD', '45 45 045'],
47646 ['w wo ww', '7 7 07'],
47647 ['h hh', '3 03'],
47648 ['H HH', '15 15'],
47649 ['m mm', '25 25'],
47650 ['s ss', '50 50'],
47651 ['a A', 'pm PM'],
47652 ['[a] DDDo[a zi a anului]', 'a 45a zi a anului'],
47653 ['LTS', '15:25:50'],
47654 ['L', '14.02.2010'],
47655 ['LL', '14 februarie 2010'],
47656 ['LLL', '14 februarie 2010 15:25'],
47657 ['LLLL', 'duminică, 14 februarie 2010 15:25'],
47658 ['l', '14.2.2010'],
47659 ['ll', '14 febr. 2010'],
47660 ['lll', '14 febr. 2010 15:25'],
47661 ['llll', 'Dum, 14 febr. 2010 15:25']
47662 ],
47663 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
47664 i;
47665 for (i = 0; i < a.length; i++) {
47666 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
47667 }
47668 });
47669
47670 test('format ordinal', function (assert) {
47671 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
47672 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
47673 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
47674 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
47675 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
47676 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
47677 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
47678 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
47679 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
47680 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
47681
47682 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
47683 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
47684 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
47685 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
47686 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
47687 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
47688 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
47689 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
47690 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
47691 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
47692
47693 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
47694 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
47695 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
47696 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
47697 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
47698 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
47699 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
47700 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
47701 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
47702 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
47703
47704 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
47705 });
47706
47707 test('format month', function (assert) {
47708 var expected = 'ianuarie ian._februarie febr._martie mart._aprilie apr._mai mai_iunie iun._iulie iul._august aug._septembrie sept._octombrie oct._noiembrie nov._decembrie dec.'.split('_'), i;
47709 for (i = 0; i < expected.length; i++) {
47710 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
47711 }
47712 });
47713
47714 test('format week', function (assert) {
47715 var expected = 'duminică Dum Du_luni Lun Lu_marți Mar Ma_miercuri Mie Mi_joi Joi Jo_vineri Vin Vi_sâmbătă Sâm Sâ'.split('_'), i;
47716 for (i = 0; i < expected.length; i++) {
47717 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
47718 }
47719 });
47720
47721 test('from', function (assert) {
47722 var start = moment([2007, 1, 28]);
47723 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'câteva secunde', '44 seconds = a few seconds');
47724 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'un minut', '45 seconds = a minute');
47725 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'un minut', '89 seconds = a minute');
47726 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minute', '90 seconds = 2 minutes');
47727 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 de minute', '44 minutes = 44 minutes');
47728 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'o oră', '45 minutes = an hour');
47729 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'o oră', '89 minutes = an hour');
47730 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ore', '90 minutes = 2 hours');
47731 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ore', '5 hours = 5 hours');
47732 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 de ore', '21 hours = 21 hours');
47733 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'o zi', '22 hours = a day');
47734 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'o zi', '35 hours = a day');
47735 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 zile', '36 hours = 2 days');
47736 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'o zi', '1 day = a day');
47737 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 zile', '5 days = 5 days');
47738 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 de zile', '25 days = 25 days');
47739 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'o lună', '26 days = a month');
47740 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'o lună', '30 days = a month');
47741 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'o lună', '43 days = a month');
47742 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 luni', '46 days = 2 months');
47743 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 luni', '75 days = 2 months');
47744 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 luni', '76 days = 3 months');
47745 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'o lună', '1 month = a month');
47746 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 luni', '5 months = 5 months');
47747 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un an', '345 days = a year');
47748 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ani', '548 days = 2 years');
47749 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un an', '1 year = a year');
47750 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ani', '5 years = 5 years');
47751 assert.equal(start.from(moment([2007, 1, 28]).add({y: 19}), true), '19 ani', '19 years = 19 years');
47752 assert.equal(start.from(moment([2007, 1, 28]).add({y: 20}), true), '20 de ani', '20 years = 20 years');
47753 assert.equal(start.from(moment([2007, 1, 28]).add({y: 100}), true), '100 de ani', '100 years = 100 years');
47754 assert.equal(start.from(moment([2007, 1, 28]).add({y: 101}), true), '101 ani', '101 years = 101 years');
47755 assert.equal(start.from(moment([2007, 1, 28]).add({y: 119}), true), '119 ani', '119 years = 119 years');
47756 assert.equal(start.from(moment([2007, 1, 28]).add({y: 120}), true), '120 de ani', '120 years = 120 years');
47757 assert.equal(start.from(moment([2007, 1, 28]).add({y: 219}), true), '219 ani', '219 years = 219 years');
47758 assert.equal(start.from(moment([2007, 1, 28]).add({y: 220}), true), '220 de ani', '220 years = 220 years');
47759 });
47760
47761 test('suffix', function (assert) {
47762 assert.equal(moment(30000).from(0), 'peste câteva secunde', 'prefix');
47763 assert.equal(moment(0).from(30000), 'câteva secunde în urmă', 'suffix');
47764 });
47765
47766 test('now from now', function (assert) {
47767 assert.equal(moment().fromNow(), 'câteva secunde în urmă', 'now from now should display as in the past');
47768 });
47769
47770 test('fromNow', function (assert) {
47771 assert.equal(moment().add({s: 30}).fromNow(), 'peste câteva secunde', 'in a few seconds');
47772 assert.equal(moment().add({d: 5}).fromNow(), 'peste 5 zile', 'in 5 days');
47773 });
47774
47775 test('calendar day', function (assert) {
47776 var a = moment().hours(12).minutes(0).seconds(0);
47777
47778 assert.equal(moment(a).calendar(), 'azi la 12:00', 'today at the same time');
47779 assert.equal(moment(a).add({m: 25}).calendar(), 'azi la 12:25', 'Now plus 25 min');
47780 assert.equal(moment(a).add({h: 1}).calendar(), 'azi la 13:00', 'Now plus 1 hour');
47781 assert.equal(moment(a).add({d: 1}).calendar(), 'mâine la 12:00', 'tomorrow at the same time');
47782 assert.equal(moment(a).subtract({h: 1}).calendar(), 'azi la 11:00', 'Now minus 1 hour');
47783 assert.equal(moment(a).subtract({d: 1}).calendar(), 'ieri la 12:00', 'yesterday at the same time');
47784 });
47785
47786 test('calendar next week', function (assert) {
47787 var i, m;
47788 for (i = 2; i < 7; i++) {
47789 m = moment().add({d: i});
47790 assert.equal(m.calendar(), m.format('dddd [la] LT'), 'Today + ' + i + ' days current time');
47791 m.hours(0).minutes(0).seconds(0).milliseconds(0);
47792 assert.equal(m.calendar(), m.format('dddd [la] LT'), 'Today + ' + i + ' days beginning of day');
47793 m.hours(23).minutes(59).seconds(59).milliseconds(999);
47794 assert.equal(m.calendar(), m.format('dddd [la] LT'), 'Today + ' + i + ' days end of day');
73f3c911 47795 }
db71a655 47796 });
c74a101d 47797
db71a655
KM
47798 test('calendar last week', function (assert) {
47799 var i, m;
47800 for (i = 2; i < 7; i++) {
47801 m = moment().subtract({d: i});
47802 assert.equal(m.calendar(), m.format('[fosta] dddd [la] LT'), 'Today - ' + i + ' days current time');
47803 m.hours(0).minutes(0).seconds(0).milliseconds(0);
47804 assert.equal(m.calendar(), m.format('[fosta] dddd [la] LT'), 'Today - ' + i + ' days beginning of day');
47805 m.hours(23).minutes(59).seconds(59).milliseconds(999);
47806 assert.equal(m.calendar(), m.format('[fosta] dddd [la] LT'), 'Today - ' + i + ' days end of day');
c74a101d 47807 }
db71a655 47808 });
c74a101d 47809
db71a655
KM
47810 test('calendar all else', function (assert) {
47811 var weeksAgo = moment().subtract({w: 1}),
47812 weeksFromNow = moment().add({w: 1});
c74a101d 47813
db71a655
KM
47814 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
47815 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
c74a101d 47816
db71a655
KM
47817 weeksAgo = moment().subtract({w: 2});
47818 weeksFromNow = moment().add({w: 2});
c74a101d 47819
db71a655
KM
47820 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
47821 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
47822 });
47823
47824 test('weeks year starting sunday formatted', function (assert) {
47825 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1', 'Dec 26 2011 should be week 1');
47826 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1');
47827 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2', 'Jan 2 2012 should be week 2');
47828 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2');
47829 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3', 'Jan 9 2012 should be week 3');
47830 });
73f3c911
IC
47831
47832})));
c74a101d 47833
c74a101d
IC
47834
47835;(function (global, factory) {
47836 typeof exports === 'object' && typeof module !== 'undefined'
47837 && typeof require === 'function' ? factory(require('../../moment')) :
47838 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
47839 factory(global.moment)
73f3c911 47840}(this, (function (moment) { 'use strict';
c74a101d 47841
db71a655
KM
47842 function each(array, callback) {
47843 var i;
47844 for (i = 0; i < array.length; i++) {
47845 callback(array[i], i, array);
47846 }
b135bf1a
IC
47847 }
47848
c58511b9
KM
47849 function setupDeprecationHandler(test, moment$$1, scope) {
47850 test._expectedDeprecations = null;
47851 test._observedDeprecations = null;
47852 test._oldSupress = moment$$1.suppressDeprecationWarnings;
47853 moment$$1.suppressDeprecationWarnings = true;
47854 test.expectedDeprecations = function () {
47855 test._expectedDeprecations = arguments;
47856 test._observedDeprecations = [];
47857 };
47858 moment$$1.deprecationHandler = function (name, msg) {
47859 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
47860 if (deprecationId === -1) {
47861 throw new Error('Unexpected deprecation thrown name=' +
47862 name + ' msg=' + msg);
47863 }
47864 test._observedDeprecations[deprecationId] = 1;
47865 };
47866 }
47867
47868 function teardownDeprecationHandler(test, moment$$1, scope) {
47869 moment$$1.suppressDeprecationWarnings = test._oldSupress;
47870
47871 if (test._expectedDeprecations != null) {
47872 var missedDeprecations = [];
47873 each(test._expectedDeprecations, function (deprecationPattern, id) {
47874 if (test._observedDeprecations[id] !== 1) {
47875 missedDeprecations.push(deprecationPattern);
47876 }
47877 });
47878 if (missedDeprecations.length !== 0) {
47879 throw new Error('Expected deprecation warnings did not happen: ' +
47880 missedDeprecations.join(' '));
47881 }
47882 }
47883 }
47884
47885 function matchedDeprecation(name, msg, deprecations) {
47886 if (deprecations == null) {
47887 return -1;
47888 }
47889 for (var i = 0; i < deprecations.length; ++i) {
47890 if (name != null && name === deprecations[i]) {
47891 return i;
47892 }
47893 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
47894 return i;
47895 }
47896 }
47897 return -1;
47898 }
47899
47900 /*global QUnit:false*/
47901
47902 var test = QUnit.test;
47903
db71a655
KM
47904 function objectKeys(obj) {
47905 if (Object.keys) {
47906 return Object.keys(obj);
47907 } else {
47908 // IE8
47909 var res = [], i;
47910 for (i in obj) {
47911 if (obj.hasOwnProperty(i)) {
47912 res.push(i);
47913 }
b135bf1a 47914 }
db71a655 47915 return res;
b135bf1a
IC
47916 }
47917 }
47918
db71a655 47919 // Pick the first defined of two or three arguments.
b135bf1a 47920
db71a655
KM
47921 function defineCommonLocaleTests(locale, options) {
47922 test('lenient day of month ordinal parsing', function (assert) {
47923 var i, ordinalStr, testMoment;
47924 for (i = 1; i <= 31; ++i) {
47925 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
47926 testMoment = moment(ordinalStr, 'YYYY MM Do');
47927 assert.equal(testMoment.year(), 2014,
47928 'lenient day of month ordinal parsing ' + i + ' year check');
47929 assert.equal(testMoment.month(), 0,
47930 'lenient day of month ordinal parsing ' + i + ' month check');
47931 assert.equal(testMoment.date(), i,
47932 'lenient day of month ordinal parsing ' + i + ' date check');
47933 }
47934 });
47935
47936 test('lenient day of month ordinal parsing of number', function (assert) {
47937 var i, testMoment;
47938 for (i = 1; i <= 31; ++i) {
47939 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
47940 assert.equal(testMoment.year(), 2014,
47941 'lenient day of month ordinal parsing of number ' + i + ' year check');
47942 assert.equal(testMoment.month(), 0,
47943 'lenient day of month ordinal parsing of number ' + i + ' month check');
47944 assert.equal(testMoment.date(), i,
47945 'lenient day of month ordinal parsing of number ' + i + ' date check');
47946 }
47947 });
47948
47949 test('strict day of month ordinal parsing', function (assert) {
47950 var i, ordinalStr, testMoment;
47951 for (i = 1; i <= 31; ++i) {
47952 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
47953 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
47954 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
47955 }
47956 });
47957
47958 test('meridiem invariant', function (assert) {
47959 var h, m, t1, t2;
47960 for (h = 0; h < 24; ++h) {
47961 for (m = 0; m < 60; m += 15) {
47962 t1 = moment.utc([2000, 0, 1, h, m]);
47963 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
47964 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
47965 'meridiem at ' + t1.format('HH:mm'));
47966 }
47967 }
47968 });
47969
47970 test('date format correctness', function (assert) {
47971 var data, tokens;
47972 data = moment.localeData()._longDateFormat;
47973 tokens = objectKeys(data);
47974 each(tokens, function (srchToken) {
47975 // Check each format string to make sure it does not contain any
47976 // tokens that need to be expanded.
47977 each(tokens, function (baseToken) {
47978 // strip escaped sequences
47979 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
47980 assert.equal(false, !!~format.indexOf(srchToken),
47981 'contains ' + srchToken + ' in ' + baseToken);
47982 });
47983 });
47984 });
47985
47986 test('month parsing correctness', function (assert) {
47987 var i, m;
47988
47989 if (locale === 'tr') {
47990 // I can't fix it :(
c58511b9 47991 assert.expect(0);
db71a655
KM
47992 return;
47993 }
47994 function tester(format) {
47995 var r;
47996 r = moment(m.format(format), format);
47997 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
47998 if (locale !== 'ka') {
47999 r = moment(m.format(format).toLocaleUpperCase(), format);
48000 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
48001 }
db71a655
KM
48002 r = moment(m.format(format).toLocaleLowerCase(), format);
48003 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
48004
48005 r = moment(m.format(format), format, true);
48006 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
48007 if (locale !== 'ka') {
48008 r = moment(m.format(format).toLocaleUpperCase(), format, true);
48009 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
48010 }
db71a655
KM
48011 r = moment(m.format(format).toLocaleLowerCase(), format, true);
48012 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
48013 }
48014
48015 for (i = 0; i < 12; ++i) {
48016 m = moment([2015, i, 15, 18]);
48017 tester('MMM');
48018 tester('MMM.');
48019 tester('MMMM');
48020 tester('MMMM.');
48021 }
48022 });
48023
48024 test('weekday parsing correctness', function (assert) {
48025 var i, m;
48026
96d0d679 48027 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
48028 // tr, az: There is a lower-case letter (ı), that converted to
48029 // upper then lower changes to i
48030 // ro: there is the letter ț which behaves weird under IE8
48031 // mt: letter Ħ
96d0d679 48032 // ga: month with spaces
c58511b9 48033 assert.expect(0);
db71a655
KM
48034 return;
48035 }
48036 function tester(format) {
48037 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
48038 r = moment(m.format(format), format);
48039 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
48040 if (locale !== 'ka') {
48041 r = moment(m.format(format).toLocaleUpperCase(), format);
48042 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
48043 }
db71a655
KM
48044 r = moment(m.format(format).toLocaleLowerCase(), format);
48045 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
48046 r = moment(m.format(format), format, true);
48047 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
48048 if (locale !== 'ka') {
48049 r = moment(m.format(format).toLocaleUpperCase(), format, true);
48050 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
48051 }
db71a655
KM
48052 r = moment(m.format(format).toLocaleLowerCase(), format, true);
48053 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
48054 }
48055
48056 for (i = 0; i < 7; ++i) {
48057 m = moment.utc([2015, 0, i + 1, 18]);
48058 tester('dd');
48059 tester('ddd');
48060 tester('dddd');
48061 }
48062 });
48063
48064 test('valid localeData', function (assert) {
48065 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
48066 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
48067 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
48068 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
48069 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
48070 });
96d0d679
KM
48071
48072 test('localeData weekdays can localeSort', function (assert) {
48073 var weekdays = moment().localeData().weekdays();
48074 var weekdaysShort = moment().localeData().weekdaysShort();
48075 var weekdaysMin = moment().localeData().weekdaysMin();
48076 var shift = moment().localeData()._week.dow;
48077 assert.deepEqual(
48078 moment().localeData().weekdays(true),
48079 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
48080 'weekdays should localeSort');
48081 assert.deepEqual(
48082 moment().localeData().weekdaysShort(true),
48083 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
48084 'weekdaysShort should localeSort');
48085 assert.deepEqual(
48086 moment().localeData().weekdaysMin(true),
48087 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
48088 'weekdaysMin should localeSort');
48089 });
db71a655
KM
48090 }
48091
db71a655
KM
48092 /*global QUnit:false*/
48093
db71a655
KM
48094 function localeModule (name, lifecycle) {
48095 QUnit.module('locale:' + name, {
c58511b9 48096 beforeEach : function () {
db71a655
KM
48097 moment.locale(name);
48098 moment.createFromInputFallback = function (config) {
48099 throw new Error('input not handled by moment: ' + config._i);
48100 };
48101 setupDeprecationHandler(test, moment, 'locale');
48102 if (lifecycle && lifecycle.setup) {
48103 lifecycle.setup();
48104 }
48105 },
c58511b9 48106 afterEach : function () {
db71a655
KM
48107 moment.locale('en');
48108 teardownDeprecationHandler(test, moment, 'locale');
48109 if (lifecycle && lifecycle.teardown) {
48110 lifecycle.teardown();
48111 }
48112 }
48113 });
48114 defineCommonLocaleTests(name, -1, -1);
48115 }
48116
48117 localeModule('ru');
48118
48119 test('parse', function (assert) {
48120 var tests = 'январь янв._февраль февр._март март_апрель апр._май май_июнь июнь_июль июль_август авг._сентябрь сент._октябрь окт._ноябрь нояб._декабрь дек.'.split('_'), i;
48121 function equalTest(input, mmm, i) {
48122 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
48123 }
48124 function equalTestStrict(input, mmm, monthIndex) {
48125 assert.equal(moment(input, mmm, true).month(), monthIndex, input + ' ' + mmm + ' should be strict month ' + (monthIndex + 1));
48126 }
48127 for (i = 0; i < 12; i++) {
48128 tests[i] = tests[i].split(' ');
48129 equalTest(tests[i][0], 'MMM', i);
48130 equalTest(tests[i][1], 'MMM', i);
48131 equalTest(tests[i][0], 'MMMM', i);
48132 equalTest(tests[i][1], 'MMMM', i);
48133 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
48134 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
48135 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
48136 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
48137
48138 equalTestStrict(tests[i][1], 'MMM', i);
48139 equalTestStrict(tests[i][0], 'MMMM', i);
48140 equalTestStrict(tests[i][1].toLocaleLowerCase(), 'MMM', i);
48141 equalTestStrict(tests[i][1].toLocaleUpperCase(), 'MMM', i);
48142 equalTestStrict(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
48143 equalTestStrict(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
48144 }
48145 });
48146
48147 test('parse exceptional case', function (assert) {
48148 assert.equal(moment('11 Мая 1989', ['DD MMMM YYYY']).format('DD-MM-YYYY'), '11-05-1989');
48149 });
48150
48151 test('format', function (assert) {
48152 var a = [
48153 ['dddd, Do MMMM YYYY, HH:mm:ss', 'воскресенье, 14-го февраля 2010, 15:25:50'],
48154 ['ddd, h A', 'вс, 3 дня'],
48155 ['M Mo MM MMMM MMM', '2 2-й 02 февраль февр.'],
48156 ['YYYY YY', '2010 10'],
48157 ['D Do DD', '14 14-го 14'],
48158 ['d do dddd ddd dd', '0 0-й воскресенье вс вс'],
48159 ['DDD DDDo DDDD', '45 45-й 045'],
48160 ['w wo ww', '6 6-я 06'],
48161 ['h hh', '3 03'],
48162 ['H HH', '15 15'],
48163 ['m mm', '25 25'],
48164 ['s ss', '50 50'],
48165 ['a A', 'дня дня'],
48166 ['DDDo [день года]', '45-й день года'],
48167 ['LT', '15:25'],
48168 ['LTS', '15:25:50'],
48169 ['L', '14.02.2010'],
48170 ['LL', '14 февраля 2010 г.'],
48171 ['LLL', '14 февраля 2010 г., 15:25'],
48172 ['LLLL', 'воскресенье, 14 февраля 2010 г., 15:25'],
48173 ['l', '14.2.2010'],
48174 ['ll', '14 февр. 2010 г.'],
48175 ['lll', '14 февр. 2010 г., 15:25'],
48176 ['llll', 'вс, 14 февр. 2010 г., 15:25']
48177 ],
48178 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
48179 i;
48180 for (i = 0; i < a.length; i++) {
48181 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
48182 }
48183 });
48184
48185 test('format meridiem', function (assert) {
48186 assert.equal(moment([2012, 11, 28, 0, 0]).format('A'), 'ночи', 'night');
48187 assert.equal(moment([2012, 11, 28, 3, 59]).format('A'), 'ночи', 'night');
48188 assert.equal(moment([2012, 11, 28, 4, 0]).format('A'), 'утра', 'morning');
48189 assert.equal(moment([2012, 11, 28, 11, 59]).format('A'), 'утра', 'morning');
48190 assert.equal(moment([2012, 11, 28, 12, 0]).format('A'), 'дня', 'afternoon');
48191 assert.equal(moment([2012, 11, 28, 16, 59]).format('A'), 'дня', 'afternoon');
48192 assert.equal(moment([2012, 11, 28, 17, 0]).format('A'), 'вечера', 'evening');
48193 assert.equal(moment([2012, 11, 28, 23, 59]).format('A'), 'вечера', 'evening');
48194 });
48195
48196 test('format ordinal', function (assert) {
48197 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-й', '1-й');
48198 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-й', '2-й');
48199 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-й', '3-й');
48200 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-й', '4-й');
48201 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-й', '5-й');
48202 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-й', '6-й');
48203 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-й', '7-й');
48204 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-й', '8-й');
48205 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-й', '9-й');
48206 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-й', '10-й');
48207
48208 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-й', '11-й');
48209 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-й', '12-й');
48210 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-й', '13-й');
48211 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-й', '14-й');
48212 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-й', '15-й');
48213 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-й', '16-й');
48214 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-й', '17-й');
48215 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-й', '18-й');
48216 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-й', '19-й');
48217 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-й', '20-й');
48218
48219 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-й', '21-й');
48220 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-й', '22-й');
48221 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-й', '23-й');
48222 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-й', '24-й');
48223 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-й', '25-й');
48224 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-й', '26-й');
48225 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-й', '27-й');
48226 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-й', '28-й');
48227 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-й', '29-й');
48228 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-й', '30-й');
48229
48230 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-й', '31-й');
48231 });
48232
48233 test('format month', function (assert) {
48234 var expected = 'январь янв._февраль февр._март март_апрель апр._май май_июнь июнь_июль июль_август авг._сентябрь сент._октябрь окт._ноябрь нояб._декабрь дек.'.split('_'), i;
48235 for (i = 0; i < expected.length; i++) {
48236 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
48237 }
48238 });
48239
48240 test('format month case', function (assert) {
48241 var months = {
48242 'nominative': 'январь_февраль_март_апрель_май_июнь_июль_август_сентябрь_октябрь_ноябрь_декабрь'.split('_'),
48243 'accusative': 'января_февраля_марта_апреля_мая_июня_июля_августа_сентября_октября_ноября_декабря'.split('_')
48244 }, i;
48245 for (i = 0; i < 12; i++) {
48246 assert.equal(moment([2011, i, 1]).format('D MMMM'), '1 ' + months.accusative[i], '1 ' + months.accusative[i]);
48247 assert.equal(moment([2011, i, 1]).format('MMMM'), months.nominative[i], '1 ' + months.nominative[i]);
48248 }
48249 });
48250
48251 test('format month short case', function (assert) {
48252 var monthsShort = {
48253 'nominative': 'янв._февр._март_апр._май_июнь_июль_авг._сент._окт._нояб._дек.'.split('_'),
48254 'accusative': 'янв._февр._мар._апр._мая_июня_июля_авг._сент._окт._нояб._дек.'.split('_')
48255 }, i;
48256 for (i = 0; i < 12; i++) {
48257 assert.equal(moment([2011, i, 1]).format('D MMM'), '1 ' + monthsShort.accusative[i], '1 ' + monthsShort.accusative[i]);
48258 assert.equal(moment([2011, i, 1]).format('MMM'), monthsShort.nominative[i], '1 ' + monthsShort.nominative[i]);
48259 }
48260 });
48261
48262 test('format month case with escaped symbols', function (assert) {
48263 var months = {
48264 'nominative': 'январь_февраль_март_апрель_май_июнь_июль_август_сентябрь_октябрь_ноябрь_декабрь'.split('_'),
48265 'accusative': 'января_февраля_марта_апреля_мая_июня_июля_августа_сентября_октября_ноября_декабря'.split('_')
48266 }, i;
48267 for (i = 0; i < 12; i++) {
48268 assert.equal(moment([2013, i, 1]).format('D[] MMMM'), '1 ' + months.accusative[i], '1 ' + months.accusative[i]);
48269 assert.equal(moment([2013, i, 1]).format('[<i>]D[</i>] [<b>]MMMM[</b>]'), '<i>1</i> <b>' + months.accusative[i] + '</b>', '1 <b>' + months.accusative[i] + '</b>');
48270 assert.equal(moment([2013, i, 1]).format('D[-й день] MMMM'), '1-й день ' + months.accusative[i], '1-й день ' + months.accusative[i]);
48271 assert.equal(moment([2013, i, 1]).format('D, MMMM'), '1, ' + months.nominative[i], '1, ' + months.nominative[i]);
48272 }
48273 });
48274
48275 test('format month short case with escaped symbols', function (assert) {
48276 var monthsShort = {
48277 'nominative': 'янв._февр._март_апр._май_июнь_июль_авг._сент._окт._нояб._дек.'.split('_'),
48278 'accusative': 'янв._февр._мар._апр._мая_июня_июля_авг._сент._окт._нояб._дек.'.split('_')
48279 }, i;
48280 for (i = 0; i < 12; i++) {
48281 assert.equal(moment([2013, i, 1]).format('D[] MMM'), '1 ' + monthsShort.accusative[i], '1 ' + monthsShort.accusative[i]);
48282 assert.equal(moment([2013, i, 1]).format('[<i>]D[</i>] [<b>]MMM[</b>]'), '<i>1</i> <b>' + monthsShort.accusative[i] + '</b>', '1 <b>' + monthsShort.accusative[i] + '</b>');
48283 assert.equal(moment([2013, i, 1]).format('D[-й день] MMM'), '1-й день ' + monthsShort.accusative[i], '1-й день ' + monthsShort.accusative[i]);
48284 assert.equal(moment([2013, i, 1]).format('D, MMM'), '1, ' + monthsShort.nominative[i], '1, ' + monthsShort.nominative[i]);
48285 }
48286 });
48287
48288 test('format week', function (assert) {
48289 var expected = 'воскресенье вс вс_понедельник пн пн_вторник вт вт_среда ср ср_четверг чт чт_пятница пт пт_суббота сб сб'.split('_'), i;
48290 for (i = 0; i < expected.length; i++) {
48291 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
48292 }
48293 });
48294
48295 test('from', function (assert) {
48296 var start = moment([2007, 1, 28]);
48297 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'несколько секунд', '44 seconds = seconds');
48298 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'минута', '45 seconds = a minute');
48299 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'минута', '89 seconds = a minute');
48300 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 минуты', '90 seconds = 2 minutes');
48301 assert.equal(start.from(moment([2007, 1, 28]).add({m: 31}), true), '31 минута', '31 minutes = 31 minutes');
48302 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 минуты', '44 minutes = 44 minutes');
48303 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'час', '45 minutes = an hour');
48304 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'час', '89 minutes = an hour');
48305 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 часа', '90 minutes = 2 hours');
48306 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 часов', '5 hours = 5 hours');
48307 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 час', '21 hours = 21 hours');
48308 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'день', '22 hours = a day');
48309 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'день', '35 hours = a day');
48310 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 дня', '36 hours = 2 days');
48311 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'день', '1 day = a day');
48312 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 дней', '5 days = 5 days');
48313 assert.equal(start.from(moment([2007, 1, 28]).add({d: 11}), true), '11 дней', '11 days = 11 days');
48314 assert.equal(start.from(moment([2007, 1, 28]).add({d: 21}), true), '21 день', '21 days = 21 days');
48315 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 дней', '25 days = 25 days');
48316 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'месяц', '26 days = a month');
48317 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'месяц', '30 days = a month');
48318 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'месяц', '43 days = a month');
48319 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 месяца', '46 days = 2 months');
48320 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 месяца', '75 days = 2 months');
48321 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 месяца', '76 days = 3 months');
48322 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'месяц', '1 month = a month');
48323 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 месяцев', '5 months = 5 months');
48324 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'год', '345 days = a year');
48325 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 года', '548 days = 2 years');
48326 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'год', '1 year = a year');
48327 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 лет', '5 years = 5 years');
73f3c911 48328 });
b135bf1a 48329
db71a655
KM
48330 test('suffix', function (assert) {
48331 assert.equal(moment(30000).from(0), 'через несколько секунд', 'prefix');
48332 assert.equal(moment(0).from(30000), 'несколько секунд назад', 'suffix');
48333 });
48334
48335 test('fromNow', function (assert) {
48336 assert.equal(moment().add({s: 30}).fromNow(), 'через несколько секунд', 'in seconds');
48337 assert.equal(moment().add({d: 5}).fromNow(), 'через 5 дней', 'in 5 days');
48338 assert.equal(moment().add({m: 31}).fromNow(), 'через 31 минуту', 'in 31 minutes = in 31 minutes');
48339 assert.equal(moment().subtract({m: 31}).fromNow(), '31 минуту назад', '31 minutes ago = 31 minutes ago');
48340 });
48341
48342 test('calendar day', function (assert) {
48343 var a = moment().hours(12).minutes(0).seconds(0);
48344
c58511b9
KM
48345 assert.equal(moment(a).calendar(), 'Сегодня, в 12:00', 'today at the same time');
48346 assert.equal(moment(a).add({m: 25}).calendar(), 'Сегодня, в 12:25', 'Now plus 25 min');
48347 assert.equal(moment(a).add({h: 1}).calendar(), 'Сегодня, в 13:00', 'Now plus 1 hour');
48348 assert.equal(moment(a).add({d: 1}).calendar(), 'Завтра, в 12:00', 'tomorrow at the same time');
48349 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Сегодня, в 11:00', 'Now minus 1 hour');
48350 assert.equal(moment(a).subtract({h: 4}).calendar(), 'Сегодня, в 8:00', 'Now minus 4 hours');
48351 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Вчера, в 12:00', 'yesterday at the same time');
db71a655
KM
48352 });
48353
48354 test('calendar next week', function (assert) {
48355 var i, m, now;
48356
48357 function makeFormatNext(d) {
48358 switch (d.day()) {
48359 case 0:
c58511b9 48360 return '[В следующее] dddd, [в] LT';
db71a655
KM
48361 case 1:
48362 case 2:
48363 case 4:
c58511b9 48364 return '[В следующий] dddd, [в] LT';
db71a655
KM
48365 case 3:
48366 case 5:
48367 case 6:
c58511b9 48368 return '[В следующую] dddd, [в] LT';
db71a655
KM
48369 }
48370 }
48371
48372 function makeFormatThis(d) {
48373 if (d.day() === 2) {
c58511b9 48374 return '[Во] dddd, [в] LT';
db71a655
KM
48375 }
48376 else {
c58511b9 48377 return '[В] dddd, [в] LT';
db71a655
KM
48378 }
48379 }
48380
48381 now = moment().startOf('week');
48382 for (i = 2; i < 7; i++) {
48383 m = moment(now).add({d: i});
48384 assert.equal(m.calendar(now), m.format(makeFormatThis(m)), 'Today + ' + i + ' days current time');
48385 m.hours(0).minutes(0).seconds(0).milliseconds(0);
48386 assert.equal(m.calendar(now), m.format(makeFormatThis(m)), 'Today + ' + i + ' days beginning of day');
48387 m.hours(23).minutes(59).seconds(59).milliseconds(999);
48388 assert.equal(m.calendar(now), m.format(makeFormatThis(m)), 'Today + ' + i + ' days end of day');
48389 }
48390
48391 now = moment().endOf('week');
48392 for (i = 2; i < 7; i++) {
48393 m = moment(now).add({d: i});
48394 assert.equal(m.calendar(now), m.format(makeFormatNext(m)), 'Today + ' + i + ' days current time');
48395 m.hours(0).minutes(0).seconds(0).milliseconds(0);
48396 assert.equal(m.calendar(now), m.format(makeFormatNext(m)), 'Today + ' + i + ' days beginning of day');
48397 m.hours(23).minutes(59).seconds(59).milliseconds(999);
48398 assert.equal(m.calendar(now), m.format(makeFormatNext(m)), 'Today + ' + i + ' days end of day');
48399 }
48400 });
48401
48402 test('calendar last week', function (assert) {
48403 var i, m, now;
48404
48405 function makeFormatLast(d) {
48406 switch (d.day()) {
48407 case 0:
c58511b9 48408 return '[В прошлое] dddd, [в] LT';
db71a655
KM
48409 case 1:
48410 case 2:
48411 case 4:
c58511b9 48412 return '[В прошлый] dddd, [в] LT';
db71a655
KM
48413 case 3:
48414 case 5:
48415 case 6:
c58511b9 48416 return '[В прошлую] dddd, [в] LT';
db71a655
KM
48417 }
48418 }
48419
48420 function makeFormatThis(d) {
48421 if (d.day() === 2) {
c58511b9 48422 return '[Во] dddd, [в] LT';
db71a655
KM
48423 }
48424 else {
c58511b9 48425 return '[В] dddd, [в] LT';
db71a655
KM
48426 }
48427 }
48428
48429 now = moment().startOf('week');
48430 for (i = 2; i < 7; i++) {
48431 m = moment(now).subtract({d: i});
48432 assert.equal(m.calendar(now), m.format(makeFormatLast(m)), 'Today - ' + i + ' days current time');
48433 m.hours(0).minutes(0).seconds(0).milliseconds(0);
48434 assert.equal(m.calendar(now), m.format(makeFormatLast(m)), 'Today - ' + i + ' days beginning of day');
48435 m.hours(23).minutes(59).seconds(59).milliseconds(999);
48436 assert.equal(m.calendar(now), m.format(makeFormatLast(m)), 'Today - ' + i + ' days end of day');
48437 }
48438
48439 now = moment().endOf('week');
48440 for (i = 2; i < 7; i++) {
48441 m = moment(now).subtract({d: i});
48442 assert.equal(m.calendar(now), m.format(makeFormatThis(m)), 'Today - ' + i + ' days current time');
48443 m.hours(0).minutes(0).seconds(0).milliseconds(0);
48444 assert.equal(m.calendar(now), m.format(makeFormatThis(m)), 'Today - ' + i + ' days beginning of day');
48445 m.hours(23).minutes(59).seconds(59).milliseconds(999);
48446 assert.equal(m.calendar(now), m.format(makeFormatThis(m)), 'Today - ' + i + ' days end of day');
73f3c911
IC
48447 }
48448 });
b135bf1a 48449
db71a655
KM
48450 test('calendar all else', function (assert) {
48451 var weeksAgo = moment().subtract({w: 1}),
48452 weeksFromNow = moment().add({w: 1});
d6651c21 48453
db71a655
KM
48454 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
48455 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
d6651c21 48456
db71a655
KM
48457 weeksAgo = moment().subtract({w: 2});
48458 weeksFromNow = moment().add({w: 2});
d6651c21 48459
db71a655
KM
48460 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
48461 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
48462 });
d6651c21 48463
db71a655
KM
48464 test('weeks year starting monday formatted', function (assert) {
48465 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '52 52 52-я', 'Dec 26 2011 should be week 52');
48466 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52-я', 'Jan 1 2012 should be week 52');
48467 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1-я', 'Jan 2 2012 should be week 1');
48468 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1-я', 'Jan 8 2012 should be week 1');
48469 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2-я', 'Jan 9 2012 should be week 2');
73f3c911
IC
48470 });
48471
db71a655 48472})));
d6651c21 48473
db71a655
KM
48474
48475;(function (global, factory) {
48476 typeof exports === 'object' && typeof module !== 'undefined'
48477 && typeof require === 'function' ? factory(require('../../moment')) :
48478 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
48479 factory(global.moment)
48480}(this, (function (moment) { 'use strict';
48481
48482 function each(array, callback) {
48483 var i;
48484 for (i = 0; i < array.length; i++) {
48485 callback(array[i], i, array);
d6651c21 48486 }
db71a655 48487 }
b135bf1a 48488
c58511b9
KM
48489 function setupDeprecationHandler(test, moment$$1, scope) {
48490 test._expectedDeprecations = null;
48491 test._observedDeprecations = null;
48492 test._oldSupress = moment$$1.suppressDeprecationWarnings;
48493 moment$$1.suppressDeprecationWarnings = true;
48494 test.expectedDeprecations = function () {
48495 test._expectedDeprecations = arguments;
48496 test._observedDeprecations = [];
48497 };
48498 moment$$1.deprecationHandler = function (name, msg) {
48499 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
48500 if (deprecationId === -1) {
48501 throw new Error('Unexpected deprecation thrown name=' +
48502 name + ' msg=' + msg);
48503 }
48504 test._observedDeprecations[deprecationId] = 1;
48505 };
48506 }
48507
48508 function teardownDeprecationHandler(test, moment$$1, scope) {
48509 moment$$1.suppressDeprecationWarnings = test._oldSupress;
48510
48511 if (test._expectedDeprecations != null) {
48512 var missedDeprecations = [];
48513 each(test._expectedDeprecations, function (deprecationPattern, id) {
48514 if (test._observedDeprecations[id] !== 1) {
48515 missedDeprecations.push(deprecationPattern);
48516 }
48517 });
48518 if (missedDeprecations.length !== 0) {
48519 throw new Error('Expected deprecation warnings did not happen: ' +
48520 missedDeprecations.join(' '));
48521 }
48522 }
48523 }
48524
48525 function matchedDeprecation(name, msg, deprecations) {
48526 if (deprecations == null) {
48527 return -1;
48528 }
48529 for (var i = 0; i < deprecations.length; ++i) {
48530 if (name != null && name === deprecations[i]) {
48531 return i;
48532 }
48533 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
48534 return i;
48535 }
48536 }
48537 return -1;
48538 }
48539
48540 /*global QUnit:false*/
48541
48542 var test = QUnit.test;
48543
db71a655
KM
48544 function objectKeys(obj) {
48545 if (Object.keys) {
48546 return Object.keys(obj);
48547 } else {
48548 // IE8
48549 var res = [], i;
48550 for (i in obj) {
48551 if (obj.hasOwnProperty(i)) {
48552 res.push(i);
48553 }
48554 }
48555 return res;
73f3c911 48556 }
db71a655 48557 }
c74a101d 48558
db71a655 48559 // Pick the first defined of two or three arguments.
c74a101d 48560
db71a655
KM
48561 function defineCommonLocaleTests(locale, options) {
48562 test('lenient day of month ordinal parsing', function (assert) {
48563 var i, ordinalStr, testMoment;
48564 for (i = 1; i <= 31; ++i) {
48565 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
48566 testMoment = moment(ordinalStr, 'YYYY MM Do');
48567 assert.equal(testMoment.year(), 2014,
48568 'lenient day of month ordinal parsing ' + i + ' year check');
48569 assert.equal(testMoment.month(), 0,
48570 'lenient day of month ordinal parsing ' + i + ' month check');
48571 assert.equal(testMoment.date(), i,
48572 'lenient day of month ordinal parsing ' + i + ' date check');
c74a101d
IC
48573 }
48574 });
db71a655
KM
48575
48576 test('lenient day of month ordinal parsing of number', function (assert) {
48577 var i, testMoment;
48578 for (i = 1; i <= 31; ++i) {
48579 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
48580 assert.equal(testMoment.year(), 2014,
48581 'lenient day of month ordinal parsing of number ' + i + ' year check');
48582 assert.equal(testMoment.month(), 0,
48583 'lenient day of month ordinal parsing of number ' + i + ' month check');
48584 assert.equal(testMoment.date(), i,
48585 'lenient day of month ordinal parsing of number ' + i + ' date check');
48586 }
48587 });
48588
48589 test('strict day of month ordinal parsing', function (assert) {
48590 var i, ordinalStr, testMoment;
48591 for (i = 1; i <= 31; ++i) {
48592 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
48593 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
48594 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
48595 }
48596 });
48597
48598 test('meridiem invariant', function (assert) {
48599 var h, m, t1, t2;
48600 for (h = 0; h < 24; ++h) {
48601 for (m = 0; m < 60; m += 15) {
48602 t1 = moment.utc([2000, 0, 1, h, m]);
48603 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
48604 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
48605 'meridiem at ' + t1.format('HH:mm'));
48606 }
48607 }
48608 });
48609
48610 test('date format correctness', function (assert) {
48611 var data, tokens;
48612 data = moment.localeData()._longDateFormat;
48613 tokens = objectKeys(data);
48614 each(tokens, function (srchToken) {
48615 // Check each format string to make sure it does not contain any
48616 // tokens that need to be expanded.
48617 each(tokens, function (baseToken) {
48618 // strip escaped sequences
48619 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
48620 assert.equal(false, !!~format.indexOf(srchToken),
48621 'contains ' + srchToken + ' in ' + baseToken);
48622 });
48623 });
48624 });
48625
48626 test('month parsing correctness', function (assert) {
48627 var i, m;
48628
48629 if (locale === 'tr') {
48630 // I can't fix it :(
c58511b9 48631 assert.expect(0);
db71a655
KM
48632 return;
48633 }
48634 function tester(format) {
48635 var r;
48636 r = moment(m.format(format), format);
48637 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
48638 if (locale !== 'ka') {
48639 r = moment(m.format(format).toLocaleUpperCase(), format);
48640 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
48641 }
db71a655
KM
48642 r = moment(m.format(format).toLocaleLowerCase(), format);
48643 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
48644
48645 r = moment(m.format(format), format, true);
48646 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
48647 if (locale !== 'ka') {
48648 r = moment(m.format(format).toLocaleUpperCase(), format, true);
48649 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
48650 }
db71a655
KM
48651 r = moment(m.format(format).toLocaleLowerCase(), format, true);
48652 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
48653 }
48654
48655 for (i = 0; i < 12; ++i) {
48656 m = moment([2015, i, 15, 18]);
48657 tester('MMM');
48658 tester('MMM.');
48659 tester('MMMM');
48660 tester('MMMM.');
48661 }
48662 });
48663
48664 test('weekday parsing correctness', function (assert) {
48665 var i, m;
48666
96d0d679 48667 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
48668 // tr, az: There is a lower-case letter (ı), that converted to
48669 // upper then lower changes to i
48670 // ro: there is the letter ț which behaves weird under IE8
48671 // mt: letter Ħ
96d0d679 48672 // ga: month with spaces
c58511b9 48673 assert.expect(0);
db71a655
KM
48674 return;
48675 }
48676 function tester(format) {
48677 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
48678 r = moment(m.format(format), format);
48679 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
48680 if (locale !== 'ka') {
48681 r = moment(m.format(format).toLocaleUpperCase(), format);
48682 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
48683 }
db71a655
KM
48684 r = moment(m.format(format).toLocaleLowerCase(), format);
48685 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
48686 r = moment(m.format(format), format, true);
48687 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
48688 if (locale !== 'ka') {
48689 r = moment(m.format(format).toLocaleUpperCase(), format, true);
48690 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
48691 }
db71a655
KM
48692 r = moment(m.format(format).toLocaleLowerCase(), format, true);
48693 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
48694 }
48695
48696 for (i = 0; i < 7; ++i) {
48697 m = moment.utc([2015, 0, i + 1, 18]);
48698 tester('dd');
48699 tester('ddd');
48700 tester('dddd');
48701 }
48702 });
48703
48704 test('valid localeData', function (assert) {
48705 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
48706 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
48707 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
48708 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
48709 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
48710 });
96d0d679
KM
48711
48712 test('localeData weekdays can localeSort', function (assert) {
48713 var weekdays = moment().localeData().weekdays();
48714 var weekdaysShort = moment().localeData().weekdaysShort();
48715 var weekdaysMin = moment().localeData().weekdaysMin();
48716 var shift = moment().localeData()._week.dow;
48717 assert.deepEqual(
48718 moment().localeData().weekdays(true),
48719 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
48720 'weekdays should localeSort');
48721 assert.deepEqual(
48722 moment().localeData().weekdaysShort(true),
48723 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
48724 'weekdaysShort should localeSort');
48725 assert.deepEqual(
48726 moment().localeData().weekdaysMin(true),
48727 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
48728 'weekdaysMin should localeSort');
48729 });
c74a101d
IC
48730 }
48731
db71a655 48732 /*global QUnit:false*/
c74a101d 48733
db71a655
KM
48734 function localeModule (name, lifecycle) {
48735 QUnit.module('locale:' + name, {
c58511b9 48736 beforeEach : function () {
db71a655
KM
48737 moment.locale(name);
48738 moment.createFromInputFallback = function (config) {
48739 throw new Error('input not handled by moment: ' + config._i);
48740 };
48741 setupDeprecationHandler(test, moment, 'locale');
48742 if (lifecycle && lifecycle.setup) {
48743 lifecycle.setup();
48744 }
48745 },
c58511b9 48746 afterEach : function () {
db71a655
KM
48747 moment.locale('en');
48748 teardownDeprecationHandler(test, moment, 'locale');
48749 if (lifecycle && lifecycle.teardown) {
48750 lifecycle.teardown();
48751 }
73f3c911 48752 }
db71a655
KM
48753 });
48754 defineCommonLocaleTests(name, -1, -1);
48755 }
48756
48757 localeModule('sd');
48758
48759 var months = [
48760 'جنوري',
48761 'فيبروري',
48762 'مارچ',
48763 'اپريل',
48764 'مئي',
48765 'جون',
48766 'جولاءِ',
48767 'آگسٽ',
48768 'سيپٽمبر',
48769 'آڪٽوبر',
48770 'نومبر',
48771 'ڊسمبر'
48772 ];
48773 var days = [
48774 'آچر',
48775 'سومر',
48776 'اڱارو',
48777 'اربع',
48778 'خميس',
48779 'جمع',
48780 'ڇنڇر'
48781 ];
48782
48783 test('parse', function (assert) {
48784 function equalTest(input, mmm, i) {
48785 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
48786 }
48787 for (var i = 0; i < 12; i++) {
48788 equalTest(months[i], 'MMM', i);
48789 equalTest(months[i], 'MMMM', i);
48790 }
48791 });
48792
48793 test('format', function (assert) {
48794 var a = [
48795 ['dddd, MMMM Do YYYY, h:mm:ss a', 'آچر، فيبروري 14 2010، 3:25:50 شام'],
48796 ['ddd, hA', 'آچر، 3شام'],
48797 ['M Mo MM MMMM MMM', '2 2 02 فيبروري فيبروري'],
48798 ['YYYY YY', '2010 10'],
48799 ['D Do DD', '14 14 14'],
48800 ['d do dddd ddd dd', '0 0 آچر آچر آچر'],
48801 ['DDD DDDo DDDD', '45 45 045'],
48802 ['w wo ww', '6 6 06'],
48803 ['h hh', '3 03'],
48804 ['H HH', '15 15'],
48805 ['m mm', '25 25'],
48806 ['s ss', '50 50'],
48807 ['a A', 'شام شام'],
48808 ['[سال جو] DDDo[ڏينهن]', 'سال جو 45ڏينهن'],
48809 ['LTS', '15:25:50'],
48810 ['L', '14/02/2010'],
48811 ['LL', '14 فيبروري 2010'],
48812 ['LLL', '14 فيبروري 2010 15:25'],
48813 ['LLLL', 'آچر، 14 فيبروري 2010 15:25'],
48814 ['l', '14/2/2010'],
48815 ['ll', '14 فيبروري 2010'],
48816 ['lll', '14 فيبروري 2010 15:25'],
48817 ['llll', 'آچر، 14 فيبروري 2010 15:25']
48818 ],
48819 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
48820 i;
48821 for (i = 0; i < a.length; i++) {
48822 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
48823 }
48824 });
48825
48826 test('format ordinal', function (assert) {
48827 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
48828 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
48829 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
48830 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
48831 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
48832 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
48833 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
48834 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
48835 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
48836 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
48837
48838 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
48839 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
48840 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
48841 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
48842 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
48843 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
48844 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
48845 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
48846 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
48847 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
48848
48849 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
48850 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
48851 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
48852 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
48853 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
48854 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
48855 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
48856 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
48857 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
48858 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
48859
48860 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
48861 });
48862
48863 test('format month', function (assert) {
48864 for (var i = 0; i < months.length; i++) {
48865 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), months[i] + ' ' + months[i], months[i] + ' ' + months[i]);
48866 }
48867 });
48868
48869 test('format week', function (assert) {
48870 for (var i = 0; i < days.length; i++) {
48871 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), days[i] + ' ' + days[i] + ' ' + days[i], days[i] + ' ' + days[i] + ' ' + days[i]);
48872 }
48873 });
48874
48875 test('from', function (assert) {
48876 var start = moment([2007, 1, 28]);
48877 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'چند سيڪنڊ', '44 seconds = چند سيڪنڊ');
48878 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'هڪ منٽ', '45 seconds = هڪ منٽ');
48879 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'هڪ منٽ', '89 seconds = هڪ منٽ');
48880 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 منٽ', '90 seconds = 2 منٽ');
48881 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 منٽ', '44 minutes = 44 منٽ');
48882 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'هڪ ڪلاڪ', '45 minutes = هڪ ڪلاڪ');
48883 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'هڪ ڪلاڪ', '89 minutes = هڪ ڪلاڪ');
48884 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ڪلاڪ', '90 minutes = 2 ڪلاڪ');
48885 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ڪلاڪ', '5 hours = 5 ڪلاڪ');
48886 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ڪلاڪ', '21 hours = 21 ڪلاڪ');
48887 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'هڪ ڏينهن', '22 hours = هڪ ڏينهن');
48888 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'هڪ ڏينهن', '35 hours = هڪ ڏينهن');
48889 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 ڏينهن', '36 hours = 2 ڏينهن');
48890 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'هڪ ڏينهن', '1 day = هڪ ڏينهن');
48891 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ڏينهن', '5 days = 5 ڏينهن');
48892 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ڏينهن', '25 days = 25 ڏينهن');
48893 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'هڪ مهينو', '26 days = هڪ مهينو');
48894 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'هڪ مهينو', '30 days = هڪ مهينو');
48895 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'هڪ مهينو', '43 days = هڪ مهينو');
48896 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 مهينا', '46 days = 2 مهينا');
48897 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 مهينا', '75 days = 2 مهينا');
48898 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 مهينا', '76 days = 3 مهينا');
48899 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'هڪ مهينو', '1 month = هڪ مهينو');
48900 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 مهينا', '5 months = 5 مهينا');
48901 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'هڪ سال', '345 days = هڪ سال');
48902 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 سال', '548 days = 2 سال');
48903 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'هڪ سال', '1 year = هڪ سال');
48904 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 سال', '5 years = 5 سال');
48905 });
48906
48907 test('suffix', function (assert) {
48908 assert.equal(moment(30000).from(0), 'چند سيڪنڊ پوء', 'prefix');
48909 assert.equal(moment(0).from(30000), 'چند سيڪنڊ اڳ', 'suffix');
48910 });
48911
48912 test('now from now', function (assert) {
48913 assert.equal(moment().fromNow(), 'چند سيڪنڊ اڳ', 'now from now should display as in the past');
48914 });
48915
48916 test('fromNow', function (assert) {
48917 assert.equal(moment().add({s: 30}).fromNow(), 'چند سيڪنڊ پوء', 'in a few seconds');
48918 assert.equal(moment().add({d: 5}).fromNow(), '5 ڏينهن پوء', 'in 5 days');
48919 });
48920
48921 test('calendar day', function (assert) {
48922 var a = moment().hours(12).minutes(0).seconds(0);
48923
48924 assert.equal(moment(a).calendar(), 'اڄ 12:00', 'today at the same time');
48925 assert.equal(moment(a).add({m: 25}).calendar(), 'اڄ 12:25', 'Now plus 25 min');
48926 assert.equal(moment(a).add({h: 1}).calendar(), 'اڄ 13:00', 'Now plus 1 hour');
48927 assert.equal(moment(a).add({d: 1}).calendar(), 'سڀاڻي 12:00', 'tomorrow at the same time');
48928 assert.equal(moment(a).subtract({h: 1}).calendar(), 'اڄ 11:00', 'Now minus 1 hour');
48929 assert.equal(moment(a).subtract({d: 1}).calendar(), 'ڪالهه 12:00', 'yesterday at the same time');
48930 });
48931
48932 test('calendar next week', function (assert) {
48933 var i, m;
48934 for (i = 2; i < 7; i++) {
48935 m = moment().add({d: i});
48936 assert.equal(m.calendar(), m.format('dddd [اڳين هفتي تي] LT'), 'Today + ' + i + ' days current time');
48937 m.hours(0).minutes(0).seconds(0).milliseconds(0);
48938 assert.equal(m.calendar(), m.format('dddd [اڳين هفتي تي] LT'), 'Today + ' + i + ' days beginning of day');
48939 m.hours(23).minutes(59).seconds(59).milliseconds(999);
48940 assert.equal(m.calendar(), m.format('dddd [اڳين هفتي تي] LT'), 'Today + ' + i + ' days end of day');
48941 }
48942 });
48943
48944 test('calendar last week', function (assert) {
48945 var i, m;
48946 for (i = 2; i < 7; i++) {
48947 m = moment().subtract({d: i});
48948 assert.equal(m.calendar(), m.format('[گزريل هفتي] dddd [تي] LT'), 'Today - ' + i + ' days current time');
48949 m.hours(0).minutes(0).seconds(0).milliseconds(0);
48950 assert.equal(m.calendar(), m.format('[گزريل هفتي] dddd [تي] LT'), 'Today - ' + i + ' days beginning of day');
48951 m.hours(23).minutes(59).seconds(59).milliseconds(999);
48952 assert.equal(m.calendar(), m.format('[گزريل هفتي] dddd [تي] LT'), 'Today - ' + i + ' days end of day');
48953 }
48954 });
48955
48956 test('calendar all else', function (assert) {
48957 var weeksAgo = moment().subtract({w: 1}),
48958 weeksFromNow = moment().add({w: 1});
48959
48960 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
48961 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
48962
48963 weeksAgo = moment().subtract({w: 2});
48964 weeksFromNow = moment().add({w: 2});
48965
48966 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
48967 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
48968 });
48969
48970 test('weeks year starting sunday formatted', function (assert) {
48971 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52', 'Jan 1 2012 should be week 52');
48972 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1', 'Jan 2 2012 should be week 1');
48973 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1', 'Jan 8 2012 should be week 1');
48974 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2', 'Jan 9 2012 should be week 2');
48975 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2', 'Jan 15 2012 should be week 2');
48976 });
73f3c911
IC
48977
48978})));
c74a101d 48979
c74a101d 48980
b135bf1a
IC
48981;(function (global, factory) {
48982 typeof exports === 'object' && typeof module !== 'undefined'
48983 && typeof require === 'function' ? factory(require('../../moment')) :
48984 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
48985 factory(global.moment)
73f3c911 48986}(this, (function (moment) { 'use strict';
b135bf1a 48987
db71a655
KM
48988 function each(array, callback) {
48989 var i;
48990 for (i = 0; i < array.length; i++) {
48991 callback(array[i], i, array);
48992 }
b135bf1a 48993 }
c74a101d 48994
c58511b9
KM
48995 function setupDeprecationHandler(test, moment$$1, scope) {
48996 test._expectedDeprecations = null;
48997 test._observedDeprecations = null;
48998 test._oldSupress = moment$$1.suppressDeprecationWarnings;
48999 moment$$1.suppressDeprecationWarnings = true;
49000 test.expectedDeprecations = function () {
49001 test._expectedDeprecations = arguments;
49002 test._observedDeprecations = [];
49003 };
49004 moment$$1.deprecationHandler = function (name, msg) {
49005 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
49006 if (deprecationId === -1) {
49007 throw new Error('Unexpected deprecation thrown name=' +
49008 name + ' msg=' + msg);
49009 }
49010 test._observedDeprecations[deprecationId] = 1;
49011 };
49012 }
49013
49014 function teardownDeprecationHandler(test, moment$$1, scope) {
49015 moment$$1.suppressDeprecationWarnings = test._oldSupress;
49016
49017 if (test._expectedDeprecations != null) {
49018 var missedDeprecations = [];
49019 each(test._expectedDeprecations, function (deprecationPattern, id) {
49020 if (test._observedDeprecations[id] !== 1) {
49021 missedDeprecations.push(deprecationPattern);
49022 }
49023 });
49024 if (missedDeprecations.length !== 0) {
49025 throw new Error('Expected deprecation warnings did not happen: ' +
49026 missedDeprecations.join(' '));
49027 }
49028 }
49029 }
49030
49031 function matchedDeprecation(name, msg, deprecations) {
49032 if (deprecations == null) {
49033 return -1;
49034 }
49035 for (var i = 0; i < deprecations.length; ++i) {
49036 if (name != null && name === deprecations[i]) {
49037 return i;
49038 }
49039 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
49040 return i;
49041 }
49042 }
49043 return -1;
49044 }
49045
49046 /*global QUnit:false*/
49047
49048 var test = QUnit.test;
49049
db71a655
KM
49050 function objectKeys(obj) {
49051 if (Object.keys) {
49052 return Object.keys(obj);
49053 } else {
49054 // IE8
49055 var res = [], i;
49056 for (i in obj) {
49057 if (obj.hasOwnProperty(i)) {
49058 res.push(i);
49059 }
c74a101d 49060 }
db71a655 49061 return res;
c74a101d 49062 }
b135bf1a 49063 }
c74a101d 49064
db71a655 49065 // Pick the first defined of two or three arguments.
73f3c911 49066
db71a655
KM
49067 function defineCommonLocaleTests(locale, options) {
49068 test('lenient day of month ordinal parsing', function (assert) {
49069 var i, ordinalStr, testMoment;
49070 for (i = 1; i <= 31; ++i) {
49071 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
49072 testMoment = moment(ordinalStr, 'YYYY MM Do');
49073 assert.equal(testMoment.year(), 2014,
49074 'lenient day of month ordinal parsing ' + i + ' year check');
49075 assert.equal(testMoment.month(), 0,
49076 'lenient day of month ordinal parsing ' + i + ' month check');
49077 assert.equal(testMoment.date(), i,
49078 'lenient day of month ordinal parsing ' + i + ' date check');
49079 }
49080 });
73f3c911 49081
db71a655
KM
49082 test('lenient day of month ordinal parsing of number', function (assert) {
49083 var i, testMoment;
49084 for (i = 1; i <= 31; ++i) {
49085 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
49086 assert.equal(testMoment.year(), 2014,
49087 'lenient day of month ordinal parsing of number ' + i + ' year check');
49088 assert.equal(testMoment.month(), 0,
49089 'lenient day of month ordinal parsing of number ' + i + ' month check');
49090 assert.equal(testMoment.date(), i,
49091 'lenient day of month ordinal parsing of number ' + i + ' date check');
49092 }
49093 });
c74a101d 49094
db71a655
KM
49095 test('strict day of month ordinal parsing', function (assert) {
49096 var i, ordinalStr, testMoment;
49097 for (i = 1; i <= 31; ++i) {
49098 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
49099 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
49100 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
49101 }
49102 });
c74a101d 49103
db71a655
KM
49104 test('meridiem invariant', function (assert) {
49105 var h, m, t1, t2;
49106 for (h = 0; h < 24; ++h) {
49107 for (m = 0; m < 60; m += 15) {
49108 t1 = moment.utc([2000, 0, 1, h, m]);
49109 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
49110 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
49111 'meridiem at ' + t1.format('HH:mm'));
49112 }
49113 }
49114 });
49115
49116 test('date format correctness', function (assert) {
49117 var data, tokens;
49118 data = moment.localeData()._longDateFormat;
49119 tokens = objectKeys(data);
49120 each(tokens, function (srchToken) {
49121 // Check each format string to make sure it does not contain any
49122 // tokens that need to be expanded.
49123 each(tokens, function (baseToken) {
49124 // strip escaped sequences
49125 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
49126 assert.equal(false, !!~format.indexOf(srchToken),
49127 'contains ' + srchToken + ' in ' + baseToken);
49128 });
73f3c911 49129 });
b135bf1a
IC
49130 });
49131
db71a655
KM
49132 test('month parsing correctness', function (assert) {
49133 var i, m;
49134
49135 if (locale === 'tr') {
49136 // I can't fix it :(
c58511b9 49137 assert.expect(0);
db71a655
KM
49138 return;
49139 }
49140 function tester(format) {
49141 var r;
49142 r = moment(m.format(format), format);
49143 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
49144 if (locale !== 'ka') {
49145 r = moment(m.format(format).toLocaleUpperCase(), format);
49146 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
49147 }
db71a655
KM
49148 r = moment(m.format(format).toLocaleLowerCase(), format);
49149 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
49150
49151 r = moment(m.format(format), format, true);
49152 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
49153 if (locale !== 'ka') {
49154 r = moment(m.format(format).toLocaleUpperCase(), format, true);
49155 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
49156 }
db71a655
KM
49157 r = moment(m.format(format).toLocaleLowerCase(), format, true);
49158 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
49159 }
49160
49161 for (i = 0; i < 12; ++i) {
49162 m = moment([2015, i, 15, 18]);
49163 tester('MMM');
49164 tester('MMM.');
49165 tester('MMMM');
49166 tester('MMMM.');
49167 }
49168 });
b135bf1a 49169
db71a655
KM
49170 test('weekday parsing correctness', function (assert) {
49171 var i, m;
49172
96d0d679 49173 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
49174 // tr, az: There is a lower-case letter (ı), that converted to
49175 // upper then lower changes to i
49176 // ro: there is the letter ț which behaves weird under IE8
49177 // mt: letter Ħ
96d0d679 49178 // ga: month with spaces
c58511b9 49179 assert.expect(0);
db71a655
KM
49180 return;
49181 }
49182 function tester(format) {
49183 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
49184 r = moment(m.format(format), format);
49185 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
49186 if (locale !== 'ka') {
49187 r = moment(m.format(format).toLocaleUpperCase(), format);
49188 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
49189 }
db71a655
KM
49190 r = moment(m.format(format).toLocaleLowerCase(), format);
49191 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
49192 r = moment(m.format(format), format, true);
49193 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
49194 if (locale !== 'ka') {
49195 r = moment(m.format(format).toLocaleUpperCase(), format, true);
49196 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
49197 }
db71a655
KM
49198 r = moment(m.format(format).toLocaleLowerCase(), format, true);
49199 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
49200 }
49201
49202 for (i = 0; i < 7; ++i) {
49203 m = moment.utc([2015, 0, i + 1, 18]);
49204 tester('dd');
49205 tester('ddd');
49206 tester('dddd');
49207 }
49208 });
b135bf1a 49209
db71a655
KM
49210 test('valid localeData', function (assert) {
49211 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
49212 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
49213 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
49214 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
49215 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
49216 });
96d0d679
KM
49217
49218 test('localeData weekdays can localeSort', function (assert) {
49219 var weekdays = moment().localeData().weekdays();
49220 var weekdaysShort = moment().localeData().weekdaysShort();
49221 var weekdaysMin = moment().localeData().weekdaysMin();
49222 var shift = moment().localeData()._week.dow;
49223 assert.deepEqual(
49224 moment().localeData().weekdays(true),
49225 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
49226 'weekdays should localeSort');
49227 assert.deepEqual(
49228 moment().localeData().weekdaysShort(true),
49229 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
49230 'weekdaysShort should localeSort');
49231 assert.deepEqual(
49232 moment().localeData().weekdaysMin(true),
49233 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
49234 'weekdaysMin should localeSort');
49235 });
db71a655 49236 }
d6651c21 49237
db71a655 49238 /*global QUnit:false*/
c74a101d 49239
db71a655
KM
49240 function localeModule (name, lifecycle) {
49241 QUnit.module('locale:' + name, {
c58511b9 49242 beforeEach : function () {
db71a655
KM
49243 moment.locale(name);
49244 moment.createFromInputFallback = function (config) {
49245 throw new Error('input not handled by moment: ' + config._i);
49246 };
49247 setupDeprecationHandler(test, moment, 'locale');
49248 if (lifecycle && lifecycle.setup) {
49249 lifecycle.setup();
49250 }
49251 },
c58511b9 49252 afterEach : function () {
db71a655
KM
49253 moment.locale('en');
49254 teardownDeprecationHandler(test, moment, 'locale');
49255 if (lifecycle && lifecycle.teardown) {
49256 lifecycle.teardown();
49257 }
c74a101d
IC
49258 }
49259 });
db71a655
KM
49260 defineCommonLocaleTests(name, -1, -1);
49261 }
49262
49263 localeModule('se');
49264
49265 test('parse', function (assert) {
49266 var i,
49267 tests = 'ođđajagemánnu ođđj_guovvamánnu guov_njukčamánnu njuk_cuoŋománnu cuo_miessemánnu mies_geassemánnu geas_suoidnemánnu suoi_borgemánnu borg_čakčamánnu čakč_golggotmánnu golg_skábmamánnu skáb_juovlamánnu juov'.split('_');
49268
49269 function equalTest(input, mmm, i) {
49270 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
49271 }
49272
49273 for (i = 0; i < 12; i++) {
49274 tests[i] = tests[i].split(' ');
49275 equalTest(tests[i][0], 'MMM', i);
49276 equalTest(tests[i][1], 'MMM', i);
49277 equalTest(tests[i][0], 'MMMM', i);
49278 equalTest(tests[i][1], 'MMMM', i);
49279 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
49280 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
49281 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
49282 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
49283 }
49284 });
49285
49286 test('format', function (assert) {
49287 var a = [
49288 ['dddd, MMMM Do YYYY, h:mm:ss a', 'sotnabeaivi, guovvamánnu 14. 2010, 3:25:50 pm'],
49289 ['ddd, hA', 'sotn, 3PM'],
49290 ['M Mo MM MMMM MMM', '2 2. 02 guovvamánnu guov'],
49291 ['YYYY YY', '2010 10'],
49292 ['D Do DD', '14 14. 14'],
49293 ['d do dddd ddd dd', '0 0. sotnabeaivi sotn s'],
49294 ['DDD DDDo DDDD', '45 45. 045'],
49295 ['w wo ww', '6 6. 06'],
49296 ['h hh', '3 03'],
49297 ['H HH', '15 15'],
49298 ['m mm', '25 25'],
49299 ['s ss', '50 50'],
49300 ['a A', 'pm PM'],
49301 ['[jagi] DDDo [beaivi]', 'jagi 45. beaivi'],
49302 ['LTS', '15:25:50'],
49303 ['L', '14.02.2010'],
49304 ['LL', 'guovvamánnu 14. b. 2010'],
49305 ['LLL', 'guovvamánnu 14. b. 2010 ti. 15:25'],
49306 ['LLLL', 'sotnabeaivi, guovvamánnu 14. b. 2010 ti. 15:25'],
49307 ['l', '14.2.2010'],
49308 ['ll', 'guov 14. b. 2010'],
49309 ['lll', 'guov 14. b. 2010 ti. 15:25'],
49310 ['llll', 'sotn, guov 14. b. 2010 ti. 15:25']
49311 ],
49312 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
49313 i;
49314
49315 for (i = 0; i < a.length; i++) {
49316 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
49317 }
49318 });
49319
49320 test('format ordinal', function (assert) {
49321 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
49322 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
49323 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
49324 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
49325 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
49326 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
49327 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
49328 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
49329 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
49330 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
49331
49332 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
49333 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
49334 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
49335 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
49336 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
49337 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
49338 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
49339 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
49340 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
49341 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
49342
49343 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
49344 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
49345 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
49346 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
49347 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
49348 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
49349 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
49350 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
49351 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
49352 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
49353
49354 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
49355 });
49356
49357 test('format month', function (assert) {
49358 var i,
49359 expected = 'ođđajagemánnu ođđj_guovvamánnu guov_njukčamánnu njuk_cuoŋománnu cuo_miessemánnu mies_geassemánnu geas_suoidnemánnu suoi_borgemánnu borg_čakčamánnu čakč_golggotmánnu golg_skábmamánnu skáb_juovlamánnu juov'.split('_');
49360
49361 for (i = 0; i < expected.length; i++) {
49362 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
49363 }
49364 });
49365
49366 test('format week', function (assert) {
49367 var i,
49368 expected = 'sotnabeaivi sotn s_vuossárga vuos v_maŋŋebárga maŋ m_gaskavahkku gask g_duorastat duor d_bearjadat bear b_lávvardat láv L'.split('_');
49369
49370 for (i = 0; i < expected.length; i++) {
49371 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
49372 }
49373 });
49374
49375 test('from', function (assert) {
49376 var start = moment([2007, 1, 28]);
49377
49378 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'moadde sekunddat', '44 seconds = a few seconds');
49379 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'okta minuhta', '45 seconds = a minute');
49380 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'okta minuhta', '89 seconds = a minute');
49381 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuhtat', '90 seconds = 2 minutes');
49382 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuhtat', '44 minutes = 44 minutes');
49383 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'okta diimmu', '45 minutes = an hour');
49384 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'okta diimmu', '89 minutes = an hour');
49385 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 diimmut', '90 minutes = 2 hours');
49386 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 diimmut', '5 hours = 5 hours');
49387 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 diimmut', '21 hours = 21 hours');
49388 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'okta beaivi', '22 hours = a day');
49389 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'okta beaivi', '35 hours = a day');
49390 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 beaivvit', '36 hours = 2 days');
49391 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'okta beaivi', '1 day = a day');
49392 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 beaivvit', '5 days = 5 days');
49393 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 beaivvit', '25 days = 25 days');
49394 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'okta mánnu', '26 days = a month');
49395 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'okta mánnu', '30 days = a month');
49396 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'okta mánnu', '43 days = a month');
49397 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mánut', '46 days = 2 months');
49398 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mánut', '75 days = 2 months');
49399 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mánut', '76 days = 3 months');
49400 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'okta mánnu', '1 month = a month');
49401 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mánut', '5 months = 5 months');
49402 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'okta jahki', '345 days = a year');
49403 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 jagit', '548 days = 2 years');
49404 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'okta jahki', '1 year = a year');
49405 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 jagit', '5 years = 5 years');
49406 });
49407
49408 test('suffix', function (assert) {
49409 assert.equal(moment(30000).from(0), 'moadde sekunddat geažes', 'prefix');
49410 assert.equal(moment(0).from(30000), 'maŋit moadde sekunddat', 'suffix');
49411 });
49412
49413 test('now from now', function (assert) {
49414 assert.equal(moment().fromNow(), 'maŋit moadde sekunddat', 'now from now should display as in the past');
49415 });
49416
49417 test('fromNow', function (assert) {
49418 assert.equal(moment().add({s: 30}).fromNow(), 'moadde sekunddat geažes', 'in a few seconds');
49419 assert.equal(moment().add({d: 5}).fromNow(), '5 beaivvit geažes', 'in 5 days');
49420 });
49421
49422 test('calendar day', function (assert) {
49423 var a = moment().hours(12).minutes(0).seconds(0);
49424
49425 assert.equal(moment(a).calendar(), 'otne ti 12:00', 'Today at the same time');
49426 assert.equal(moment(a).add({m: 25}).calendar(), 'otne ti 12:25', 'Now plus 25 min');
49427 assert.equal(moment(a).add({h: 1}).calendar(), 'otne ti 13:00', 'Now plus 1 hour');
49428 assert.equal(moment(a).add({d: 1}).calendar(), 'ihttin ti 12:00', 'Tomorrow at the same time');
49429 assert.equal(moment(a).subtract({h: 1}).calendar(), 'otne ti 11:00', 'Now minus 1 hour');
49430 assert.equal(moment(a).subtract({d: 1}).calendar(), 'ikte ti 12:00', 'yesterday at the same time');
49431 });
49432
49433 test('calendar next week', function (assert) {
49434 var i, m;
c74a101d 49435
db71a655
KM
49436 for (i = 2; i < 7; i++) {
49437 m = moment().add({d: i});
49438 assert.equal(m.calendar(), m.format('dddd [ti] LT'), 'Today + ' + i + ' days current time');
49439 m.hours(0).minutes(0).seconds(0).milliseconds(0);
49440 assert.equal(m.calendar(), m.format('dddd [ti] LT'), 'Today + ' + i + ' days beginning of day');
49441 m.hours(23).minutes(59).seconds(59).milliseconds(999);
49442 assert.equal(m.calendar(), m.format('dddd [ti] LT'), 'Today + ' + i + ' days end of day');
c74a101d 49443 }
db71a655
KM
49444 });
49445
49446 test('calendar last week', function (assert) {
49447 var i, m;
49448
49449 for (i = 2; i < 7; i++) {
49450 m = moment().subtract({d: i});
49451 assert.equal(m.calendar(), m.format('[ovddit] dddd [ti] LT'), 'Today - ' + i + ' days current time');
49452 m.hours(0).minutes(0).seconds(0).milliseconds(0);
49453 assert.equal(m.calendar(), m.format('[ovddit] dddd [ti] LT'), 'Today - ' + i + ' days beginning of day');
49454 m.hours(23).minutes(59).seconds(59).milliseconds(999);
49455 assert.equal(m.calendar(), m.format('[ovddit] dddd [ti] LT'), 'Today - ' + i + ' days end of day');
c74a101d 49456 }
db71a655 49457 });
c74a101d 49458
db71a655
KM
49459 test('calendar all else', function (assert) {
49460 var weeksAgo = moment().subtract({w: 1}),
49461 weeksFromNow = moment().add({w: 1});
c74a101d 49462
db71a655
KM
49463 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
49464 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
c74a101d 49465
db71a655
KM
49466 weeksAgo = moment().subtract({w: 2});
49467 weeksFromNow = moment().add({w: 2});
c74a101d 49468
db71a655
KM
49469 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
49470 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
49471 });
73f3c911 49472
db71a655
KM
49473 test('weeks year starting sunday formatted', function (assert) {
49474 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
49475 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
49476 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
49477 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
49478 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
49479 });
73f3c911
IC
49480
49481})));
49482
b135bf1a
IC
49483
49484;(function (global, factory) {
49485 typeof exports === 'object' && typeof module !== 'undefined'
49486 && typeof require === 'function' ? factory(require('../../moment')) :
49487 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
49488 factory(global.moment)
73f3c911 49489}(this, (function (moment) { 'use strict';
b135bf1a 49490
db71a655
KM
49491 function each(array, callback) {
49492 var i;
49493 for (i = 0; i < array.length; i++) {
49494 callback(array[i], i, array);
c74a101d 49495 }
b135bf1a 49496 }
b135bf1a 49497
c58511b9
KM
49498 function setupDeprecationHandler(test, moment$$1, scope) {
49499 test._expectedDeprecations = null;
49500 test._observedDeprecations = null;
49501 test._oldSupress = moment$$1.suppressDeprecationWarnings;
49502 moment$$1.suppressDeprecationWarnings = true;
49503 test.expectedDeprecations = function () {
49504 test._expectedDeprecations = arguments;
49505 test._observedDeprecations = [];
49506 };
49507 moment$$1.deprecationHandler = function (name, msg) {
49508 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
49509 if (deprecationId === -1) {
49510 throw new Error('Unexpected deprecation thrown name=' +
49511 name + ' msg=' + msg);
49512 }
49513 test._observedDeprecations[deprecationId] = 1;
49514 };
49515 }
49516
49517 function teardownDeprecationHandler(test, moment$$1, scope) {
49518 moment$$1.suppressDeprecationWarnings = test._oldSupress;
49519
49520 if (test._expectedDeprecations != null) {
49521 var missedDeprecations = [];
49522 each(test._expectedDeprecations, function (deprecationPattern, id) {
49523 if (test._observedDeprecations[id] !== 1) {
49524 missedDeprecations.push(deprecationPattern);
49525 }
49526 });
49527 if (missedDeprecations.length !== 0) {
49528 throw new Error('Expected deprecation warnings did not happen: ' +
49529 missedDeprecations.join(' '));
49530 }
49531 }
49532 }
49533
49534 function matchedDeprecation(name, msg, deprecations) {
49535 if (deprecations == null) {
49536 return -1;
49537 }
49538 for (var i = 0; i < deprecations.length; ++i) {
49539 if (name != null && name === deprecations[i]) {
49540 return i;
49541 }
49542 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
49543 return i;
49544 }
49545 }
49546 return -1;
49547 }
49548
49549 /*global QUnit:false*/
49550
49551 var test = QUnit.test;
49552
db71a655
KM
49553 function objectKeys(obj) {
49554 if (Object.keys) {
49555 return Object.keys(obj);
49556 } else {
49557 // IE8
49558 var res = [], i;
49559 for (i in obj) {
49560 if (obj.hasOwnProperty(i)) {
49561 res.push(i);
49562 }
49563 }
49564 return res;
73f3c911 49565 }
db71a655 49566 }
b135bf1a 49567
db71a655
KM
49568 // Pick the first defined of two or three arguments.
49569
49570 function defineCommonLocaleTests(locale, options) {
49571 test('lenient day of month ordinal parsing', function (assert) {
49572 var i, ordinalStr, testMoment;
49573 for (i = 1; i <= 31; ++i) {
49574 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
49575 testMoment = moment(ordinalStr, 'YYYY MM Do');
49576 assert.equal(testMoment.year(), 2014,
49577 'lenient day of month ordinal parsing ' + i + ' year check');
49578 assert.equal(testMoment.month(), 0,
49579 'lenient day of month ordinal parsing ' + i + ' month check');
49580 assert.equal(testMoment.date(), i,
49581 'lenient day of month ordinal parsing ' + i + ' date check');
49582 }
b135bf1a 49583 });
d6651c21 49584
db71a655
KM
49585 test('lenient day of month ordinal parsing of number', function (assert) {
49586 var i, testMoment;
49587 for (i = 1; i <= 31; ++i) {
49588 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
49589 assert.equal(testMoment.year(), 2014,
49590 'lenient day of month ordinal parsing of number ' + i + ' year check');
49591 assert.equal(testMoment.month(), 0,
49592 'lenient day of month ordinal parsing of number ' + i + ' month check');
49593 assert.equal(testMoment.date(), i,
49594 'lenient day of month ordinal parsing of number ' + i + ' date check');
49595 }
49596 });
d6651c21 49597
db71a655
KM
49598 test('strict day of month ordinal parsing', function (assert) {
49599 var i, ordinalStr, testMoment;
49600 for (i = 1; i <= 31; ++i) {
49601 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
49602 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
49603 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
49604 }
49605 });
d6651c21 49606
db71a655
KM
49607 test('meridiem invariant', function (assert) {
49608 var h, m, t1, t2;
49609 for (h = 0; h < 24; ++h) {
49610 for (m = 0; m < 60; m += 15) {
49611 t1 = moment.utc([2000, 0, 1, h, m]);
49612 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
49613 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
49614 'meridiem at ' + t1.format('HH:mm'));
49615 }
49616 }
49617 });
d6651c21 49618
db71a655
KM
49619 test('date format correctness', function (assert) {
49620 var data, tokens;
49621 data = moment.localeData()._longDateFormat;
49622 tokens = objectKeys(data);
49623 each(tokens, function (srchToken) {
49624 // Check each format string to make sure it does not contain any
49625 // tokens that need to be expanded.
49626 each(tokens, function (baseToken) {
49627 // strip escaped sequences
49628 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
49629 assert.equal(false, !!~format.indexOf(srchToken),
49630 'contains ' + srchToken + ' in ' + baseToken);
49631 });
49632 });
49633 });
73f3c911 49634
db71a655
KM
49635 test('month parsing correctness', function (assert) {
49636 var i, m;
49637
49638 if (locale === 'tr') {
49639 // I can't fix it :(
c58511b9 49640 assert.expect(0);
db71a655
KM
49641 return;
49642 }
49643 function tester(format) {
49644 var r;
49645 r = moment(m.format(format), format);
49646 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
49647 if (locale !== 'ka') {
49648 r = moment(m.format(format).toLocaleUpperCase(), format);
49649 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
49650 }
db71a655
KM
49651 r = moment(m.format(format).toLocaleLowerCase(), format);
49652 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
49653
49654 r = moment(m.format(format), format, true);
49655 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
49656 if (locale !== 'ka') {
49657 r = moment(m.format(format).toLocaleUpperCase(), format, true);
49658 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
49659 }
db71a655
KM
49660 r = moment(m.format(format).toLocaleLowerCase(), format, true);
49661 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
49662 }
49663
49664 for (i = 0; i < 12; ++i) {
49665 m = moment([2015, i, 15, 18]);
49666 tester('MMM');
49667 tester('MMM.');
49668 tester('MMMM');
49669 tester('MMMM.');
49670 }
49671 });
d6651c21 49672
db71a655
KM
49673 test('weekday parsing correctness', function (assert) {
49674 var i, m;
49675
96d0d679 49676 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
49677 // tr, az: There is a lower-case letter (ı), that converted to
49678 // upper then lower changes to i
49679 // ro: there is the letter ț which behaves weird under IE8
49680 // mt: letter Ħ
96d0d679 49681 // ga: month with spaces
c58511b9 49682 assert.expect(0);
db71a655
KM
49683 return;
49684 }
49685 function tester(format) {
49686 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
49687 r = moment(m.format(format), format);
49688 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
49689 if (locale !== 'ka') {
49690 r = moment(m.format(format).toLocaleUpperCase(), format);
49691 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
49692 }
db71a655
KM
49693 r = moment(m.format(format).toLocaleLowerCase(), format);
49694 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
49695 r = moment(m.format(format), format, true);
49696 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
49697 if (locale !== 'ka') {
49698 r = moment(m.format(format).toLocaleUpperCase(), format, true);
49699 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
49700 }
db71a655
KM
49701 r = moment(m.format(format).toLocaleLowerCase(), format, true);
49702 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
49703 }
49704
49705 for (i = 0; i < 7; ++i) {
49706 m = moment.utc([2015, 0, i + 1, 18]);
49707 tester('dd');
49708 tester('ddd');
49709 tester('dddd');
49710 }
49711 });
c74a101d 49712
db71a655
KM
49713 test('valid localeData', function (assert) {
49714 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
49715 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
49716 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
49717 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
49718 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
49719 });
96d0d679
KM
49720
49721 test('localeData weekdays can localeSort', function (assert) {
49722 var weekdays = moment().localeData().weekdays();
49723 var weekdaysShort = moment().localeData().weekdaysShort();
49724 var weekdaysMin = moment().localeData().weekdaysMin();
49725 var shift = moment().localeData()._week.dow;
49726 assert.deepEqual(
49727 moment().localeData().weekdays(true),
49728 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
49729 'weekdays should localeSort');
49730 assert.deepEqual(
49731 moment().localeData().weekdaysShort(true),
49732 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
49733 'weekdaysShort should localeSort');
49734 assert.deepEqual(
49735 moment().localeData().weekdaysMin(true),
49736 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
49737 'weekdaysMin should localeSort');
49738 });
db71a655 49739 }
c74a101d 49740
db71a655 49741 /*global QUnit:false*/
c74a101d 49742
db71a655
KM
49743 function localeModule (name, lifecycle) {
49744 QUnit.module('locale:' + name, {
c58511b9 49745 beforeEach : function () {
db71a655
KM
49746 moment.locale(name);
49747 moment.createFromInputFallback = function (config) {
49748 throw new Error('input not handled by moment: ' + config._i);
49749 };
49750 setupDeprecationHandler(test, moment, 'locale');
49751 if (lifecycle && lifecycle.setup) {
49752 lifecycle.setup();
49753 }
49754 },
c58511b9 49755 afterEach : function () {
db71a655
KM
49756 moment.locale('en');
49757 teardownDeprecationHandler(test, moment, 'locale');
49758 if (lifecycle && lifecycle.teardown) {
49759 lifecycle.teardown();
49760 }
73f3c911 49761 }
db71a655
KM
49762 });
49763 defineCommonLocaleTests(name, -1, -1);
49764 }
49765
49766 localeModule('si');
49767
49768 /*jshint -W100*/
49769 test('parse', function (assert) {
49770 var tests = 'ජනවාරි ජන_පෙබරවාරි පෙබ_මාර්තු මාර්_අප්‍රේල් අප්_මැයි මැයි_ජූනි ජූනි_ජූලි ජූලි_අගෝස්තු අගෝ_සැප්තැම්බර් සැප්_ඔක්තෝබර් ඔක්_නොවැම්බර් නොවැ_දෙසැම්බර් දෙසැ'.split('_'), i;
49771 function equalTest(input, mmm, i) {
49772 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
49773 }
49774 for (i = 0; i < 12; i++) {
49775 tests[i] = tests[i].split(' ');
49776 equalTest(tests[i][0], 'MMM', i);
49777 equalTest(tests[i][1], 'MMM', i);
49778 equalTest(tests[i][0], 'MMMM', i);
49779 equalTest(tests[i][1], 'MMMM', i);
49780 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
49781 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
49782 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
49783 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
49784 }
49785 });
49786
49787 test('format', function (assert) {
49788 var a = [
49789 ['YYYY MMMM Do dddd, a h:mm:ss', '2010 පෙබරවාරි 14 වැනි ඉරිදා, ප.ව. 3:25:50'],
49790 ['YYYY MMMM Do dddd, a h:mm:ss', '2010 පෙබරවාරි 14 වැනි ඉරිදා, ප.ව. 3:25:50'],
49791 ['ddd, A h', 'ඉරි, පස් වරු 3'],
49792 ['M Mo MM MMMM MMM', '2 2 වැනි 02 පෙබරවාරි පෙබ'],
49793 ['YYYY YY', '2010 10'],
49794 ['D Do DD', '14 14 වැනි 14'],
49795 ['d do dddd ddd dd', '0 0 වැනි ඉරිදා ඉරි ඉ'],
49796 ['DDD DDDo DDDD', '45 45 වැනි 045'],
49797 ['h hh', '3 03'],
49798 ['H HH', '15 15'],
49799 ['m mm', '25 25'],
49800 ['s ss', '50 50'],
49801 ['a A', 'ප.ව. පස් වරු'],
49802 ['[වසරේ] DDDo [දිනය]', 'වසරේ 45 වැනි දිනය'],
49803 ['LTS', 'ප.ව. 3:25:50'],
49804 ['LT', 'ප.ව. 3:25'],
49805 ['L', '2010/02/14'],
49806 ['LL', '2010 පෙබරවාරි 14'],
49807 ['LLL', '2010 පෙබරවාරි 14, ප.ව. 3:25'],
49808 ['LLLL', '2010 පෙබරවාරි 14 වැනි ඉරිදා, ප.ව. 3:25:50'],
49809 ['l', '2010/2/14'],
49810 ['ll', '2010 පෙබ 14'],
49811 ['lll', '2010 පෙබ 14, ප.ව. 3:25'],
49812 ['llll', '2010 පෙබ 14 වැනි ඉරි, ප.ව. 3:25:50']
49813 ],
49814 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
49815 i;
49816 for (i = 0; i < a.length; i++) {
49817 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
49818 }
49819 });
49820
49821 test('format ordinal', function (assert) {
49822 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1 වැනි', '1 වැනි');
49823 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2 වැනි', '2 වැනි');
49824 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3 වැනි', '3 වැනි');
49825 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4 වැනි', '4 වැනි');
49826 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5 වැනි', '5 වැනි');
49827 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6 වැනි', '6 වැනි');
49828 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7 වැනි', '7 වැනි');
49829 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8 වැනි', '8 වැනි');
49830 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9 වැනි', '9 වැනි');
49831 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10 වැනි', '10 වැනි');
49832
49833 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11 වැනි', '11 වැනි');
49834 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12 වැනි', '12 වැනි');
49835 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13 වැනි', '13 වැනි');
49836 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14 වැනි', '14 වැනි');
49837 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15 වැනි', '15 වැනි');
49838 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16 වැනි', '16 වැනි');
49839 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17 වැනි', '17 වැනි');
49840 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18 වැනි', '18 වැනි');
49841 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19 වැනි', '19 වැනි');
49842 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20 වැනි', '20 වැනි');
49843
49844 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21 වැනි', '21 වැනි');
49845 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22 වැනි', '22 වැනි');
49846 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23 වැනි', '23 වැනි');
49847 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24 වැනි', '24 වැනි');
49848 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25 වැනි', '25 වැනි');
49849 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26 වැනි', '26 වැනි');
49850 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27 වැනි', '27 වැනි');
49851 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28 වැනි', '28 වැනි');
49852 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29 වැනි', '29 වැනි');
49853 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30 වැනි', '30 වැනි');
49854
49855 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31 වැනි', '31 වැනි');
49856 });
49857
49858 test('format month', function (assert) {
49859 var expected = 'ජනවාරි ජන_පෙබරවාරි පෙබ_මාර්තු මාර්_අප්‍රේල් අප්_මැයි මැයි_ජූනි ජූනි_ජූලි ජූලි_අගෝස්තු අගෝ_සැප්තැම්බර් සැප්_ඔක්තෝබර් ඔක්_නොවැම්බර් නොවැ_දෙසැම්බර් දෙසැ'.split('_'), i;
49860 for (i = 0; i < expected.length; i++) {
49861 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
49862 }
49863 });
49864
49865 test('format week', function (assert) {
49866 var expected = 'ඉරිදා ඉරි ඉ_සඳුදා සඳු ස_අඟහරුවාදා අඟ අ_බදාදා බදා බ_බ්‍රහස්පතින්දා බ්‍රහ බ්‍ර_සිකුරාදා සිකු සි_සෙනසුරාදා සෙන සෙ'.split('_'), i;
49867 for (i = 0; i < expected.length; i++) {
49868 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
49869 }
49870 });
49871
49872 test('from', function (assert) {
49873 var start = moment([2007, 1, 28]);
49874 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'තත්පර කිහිපය', '44 seconds = a few seconds');
49875 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'මිනිත්තුව', '45 seconds = a minute');
49876 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'මිනිත්තුව', '89 seconds = a minute');
49877 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), 'මිනිත්තු 2', '90 seconds = 2 minutes');
49878 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), 'මිනිත්තු 44', '44 minutes = 44 minutes');
49879 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'පැය', '45 minutes = an hour');
49880 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'පැය', '89 minutes = an hour');
49881 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), 'පැය 2', '90 minutes = 2 hours');
49882 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), 'පැය 5', '5 hours = 5 hours');
49883 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), 'පැය 21', '21 hours = 21 hours');
49884 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'දිනය', '22 hours = a day');
49885 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'දිනය', '35 hours = a day');
49886 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), 'දින 2', '36 hours = 2 days');
49887 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'දිනය', '1 day = a day');
49888 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), 'දින 5', '5 days = 5 days');
49889 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), 'දින 25', '25 days = 25 days');
49890 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'මාසය', '26 days = a month');
49891 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'මාසය', '30 days = a month');
49892 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'මාසය', '43 days = a month');
49893 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), 'මාස 2', '46 days = 2 months');
49894 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), 'මාස 2', '75 days = 2 months');
49895 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), 'මාස 3', '76 days = 3 months');
49896 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'මාසය', '1 month = a month');
49897 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), 'මාස 5', '5 months = 5 months');
49898 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'වසර', '345 days = a year');
49899 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), 'වසර 2', '548 days = 2 years');
49900 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'වසර', '1 year = a year');
49901 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), 'වසර 5', '5 years = 5 years');
49902 });
49903
49904 test('suffix', function (assert) {
49905 assert.equal(moment(30000).from(0), 'තත්පර කිහිපයකින්', 'prefix');
49906 assert.equal(moment(0).from(30000), 'තත්පර කිහිපයකට පෙර', 'suffix');
49907 });
49908
49909 test('now from now', function (assert) {
49910 assert.equal(moment().fromNow(), 'තත්පර කිහිපයකට පෙර', 'now from now should display as in the past');
49911 });
49912
49913 test('fromNow', function (assert) {
49914 assert.equal(moment().add({s: 30}).fromNow(), 'තත්පර කිහිපයකින්', 'in a few seconds');
49915 assert.equal(moment().add({d: 5}).fromNow(), 'දින 5කින්', 'in 5 days');
49916 });
49917
49918 test('calendar day', function (assert) {
49919 var a = moment().hours(12).minutes(0).seconds(0);
49920
49921 assert.equal(moment(a).calendar(), 'අද ප.ව. 12:00ට', 'today at the same time');
49922 assert.equal(moment(a).add({m: 25}).calendar(), 'අද ප.ව. 12:25ට', 'Now plus 25 min');
49923 assert.equal(moment(a).add({h: 1}).calendar(), 'අද ප.ව. 1:00ට', 'Now plus 1 hour');
49924 assert.equal(moment(a).add({d: 1}).calendar(), 'හෙට ප.ව. 12:00ට', 'tomorrow at the same time');
49925 assert.equal(moment(a).subtract({h: 1}).calendar(), 'අද පෙ.ව. 11:00ට', 'Now minus 1 hour');
49926 assert.equal(moment(a).subtract({d: 1}).calendar(), 'ඊයේ ප.ව. 12:00ට', 'yesterday at the same time');
49927 });
49928
49929 test('calendar next week', function (assert) {
49930 var i, m;
49931 for (i = 2; i < 7; i++) {
49932 m = moment().add({d: i});
49933 assert.equal(m.calendar(), m.format('dddd LT[ට]'), 'Today + ' + i + ' days current time');
49934 m.hours(0).minutes(0).seconds(0).milliseconds(0);
49935 assert.equal(m.calendar(), m.format('dddd LT[ට]'), 'Today + ' + i + ' days beginning of day');
49936 m.hours(23).minutes(59).seconds(59).milliseconds(999);
49937 assert.equal(m.calendar(), m.format('dddd LT[ට]'), 'Today + ' + i + ' days end of day');
49938 }
49939 });
49940
49941 test('calendar last week', function (assert) {
49942 var i, m;
49943
49944 for (i = 2; i < 7; i++) {
49945 m = moment().subtract({d: i});
49946 assert.equal(m.calendar(), m.format('[පසුගිය] dddd LT[ට]'), 'Today - ' + i + ' days current time');
49947 m.hours(0).minutes(0).seconds(0).milliseconds(0);
49948 assert.equal(m.calendar(), m.format('[පසුගිය] dddd LT[ට]'), 'Today - ' + i + ' days beginning of day');
49949 m.hours(23).minutes(59).seconds(59).milliseconds(999);
49950 assert.equal(m.calendar(), m.format('[පසුගිය] dddd LT[ට]'), 'Today - ' + i + ' days end of day');
49951 }
49952 });
49953
49954 test('calendar all else', function (assert) {
49955 var weeksAgo = moment().subtract({w: 1}),
49956 weeksFromNow = moment().add({w: 1});
49957
49958 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
49959 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
73f3c911 49960
db71a655
KM
49961 weeksAgo = moment().subtract({w: 2});
49962 weeksFromNow = moment().add({w: 2});
49963
49964 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
49965 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
49966 });
73f3c911
IC
49967
49968})));
49969
b135bf1a
IC
49970
49971;(function (global, factory) {
49972 typeof exports === 'object' && typeof module !== 'undefined'
49973 && typeof require === 'function' ? factory(require('../../moment')) :
49974 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
49975 factory(global.moment)
73f3c911 49976}(this, (function (moment) { 'use strict';
b135bf1a 49977
db71a655
KM
49978 function each(array, callback) {
49979 var i;
49980 for (i = 0; i < array.length; i++) {
49981 callback(array[i], i, array);
49982 }
b135bf1a 49983 }
c74a101d 49984
c58511b9
KM
49985 function setupDeprecationHandler(test, moment$$1, scope) {
49986 test._expectedDeprecations = null;
49987 test._observedDeprecations = null;
49988 test._oldSupress = moment$$1.suppressDeprecationWarnings;
49989 moment$$1.suppressDeprecationWarnings = true;
49990 test.expectedDeprecations = function () {
49991 test._expectedDeprecations = arguments;
49992 test._observedDeprecations = [];
49993 };
49994 moment$$1.deprecationHandler = function (name, msg) {
49995 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
49996 if (deprecationId === -1) {
49997 throw new Error('Unexpected deprecation thrown name=' +
49998 name + ' msg=' + msg);
49999 }
50000 test._observedDeprecations[deprecationId] = 1;
50001 };
50002 }
50003
50004 function teardownDeprecationHandler(test, moment$$1, scope) {
50005 moment$$1.suppressDeprecationWarnings = test._oldSupress;
50006
50007 if (test._expectedDeprecations != null) {
50008 var missedDeprecations = [];
50009 each(test._expectedDeprecations, function (deprecationPattern, id) {
50010 if (test._observedDeprecations[id] !== 1) {
50011 missedDeprecations.push(deprecationPattern);
50012 }
50013 });
50014 if (missedDeprecations.length !== 0) {
50015 throw new Error('Expected deprecation warnings did not happen: ' +
50016 missedDeprecations.join(' '));
50017 }
50018 }
50019 }
50020
50021 function matchedDeprecation(name, msg, deprecations) {
50022 if (deprecations == null) {
50023 return -1;
50024 }
50025 for (var i = 0; i < deprecations.length; ++i) {
50026 if (name != null && name === deprecations[i]) {
50027 return i;
50028 }
50029 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
50030 return i;
50031 }
50032 }
50033 return -1;
50034 }
50035
50036 /*global QUnit:false*/
50037
50038 var test = QUnit.test;
50039
db71a655
KM
50040 function objectKeys(obj) {
50041 if (Object.keys) {
50042 return Object.keys(obj);
50043 } else {
50044 // IE8
50045 var res = [], i;
50046 for (i in obj) {
50047 if (obj.hasOwnProperty(i)) {
50048 res.push(i);
50049 }
c74a101d 50050 }
db71a655 50051 return res;
c74a101d 50052 }
b135bf1a 50053 }
73f3c911 50054
db71a655 50055 // Pick the first defined of two or three arguments.
c74a101d 50056
db71a655
KM
50057 function defineCommonLocaleTests(locale, options) {
50058 test('lenient day of month ordinal parsing', function (assert) {
50059 var i, ordinalStr, testMoment;
50060 for (i = 1; i <= 31; ++i) {
50061 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
50062 testMoment = moment(ordinalStr, 'YYYY MM Do');
50063 assert.equal(testMoment.year(), 2014,
50064 'lenient day of month ordinal parsing ' + i + ' year check');
50065 assert.equal(testMoment.month(), 0,
50066 'lenient day of month ordinal parsing ' + i + ' month check');
50067 assert.equal(testMoment.date(), i,
50068 'lenient day of month ordinal parsing ' + i + ' date check');
50069 }
50070 });
c74a101d 50071
db71a655
KM
50072 test('lenient day of month ordinal parsing of number', function (assert) {
50073 var i, testMoment;
50074 for (i = 1; i <= 31; ++i) {
50075 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
50076 assert.equal(testMoment.year(), 2014,
50077 'lenient day of month ordinal parsing of number ' + i + ' year check');
50078 assert.equal(testMoment.month(), 0,
50079 'lenient day of month ordinal parsing of number ' + i + ' month check');
50080 assert.equal(testMoment.date(), i,
50081 'lenient day of month ordinal parsing of number ' + i + ' date check');
50082 }
b135bf1a
IC
50083 });
50084
db71a655
KM
50085 test('strict day of month ordinal parsing', function (assert) {
50086 var i, ordinalStr, testMoment;
50087 for (i = 1; i <= 31; ++i) {
50088 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
50089 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
50090 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
50091 }
50092 });
b135bf1a 50093
db71a655
KM
50094 test('meridiem invariant', function (assert) {
50095 var h, m, t1, t2;
50096 for (h = 0; h < 24; ++h) {
50097 for (m = 0; m < 60; m += 15) {
50098 t1 = moment.utc([2000, 0, 1, h, m]);
50099 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
50100 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
50101 'meridiem at ' + t1.format('HH:mm'));
50102 }
50103 }
50104 });
b135bf1a 50105
db71a655
KM
50106 test('date format correctness', function (assert) {
50107 var data, tokens;
50108 data = moment.localeData()._longDateFormat;
50109 tokens = objectKeys(data);
50110 each(tokens, function (srchToken) {
50111 // Check each format string to make sure it does not contain any
50112 // tokens that need to be expanded.
50113 each(tokens, function (baseToken) {
50114 // strip escaped sequences
50115 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
50116 assert.equal(false, !!~format.indexOf(srchToken),
50117 'contains ' + srchToken + ' in ' + baseToken);
50118 });
50119 });
50120 });
d6651c21 50121
db71a655
KM
50122 test('month parsing correctness', function (assert) {
50123 var i, m;
50124
50125 if (locale === 'tr') {
50126 // I can't fix it :(
c58511b9 50127 assert.expect(0);
db71a655
KM
50128 return;
50129 }
50130 function tester(format) {
50131 var r;
50132 r = moment(m.format(format), format);
50133 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
50134 if (locale !== 'ka') {
50135 r = moment(m.format(format).toLocaleUpperCase(), format);
50136 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
50137 }
db71a655
KM
50138 r = moment(m.format(format).toLocaleLowerCase(), format);
50139 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
50140
50141 r = moment(m.format(format), format, true);
50142 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
50143 if (locale !== 'ka') {
50144 r = moment(m.format(format).toLocaleUpperCase(), format, true);
50145 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
50146 }
db71a655
KM
50147 r = moment(m.format(format).toLocaleLowerCase(), format, true);
50148 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
50149 }
50150
50151 for (i = 0; i < 12; ++i) {
50152 m = moment([2015, i, 15, 18]);
50153 tester('MMM');
50154 tester('MMM.');
50155 tester('MMMM');
50156 tester('MMMM.');
50157 }
50158 });
d6651c21 50159
db71a655
KM
50160 test('weekday parsing correctness', function (assert) {
50161 var i, m;
50162
96d0d679 50163 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
50164 // tr, az: There is a lower-case letter (ı), that converted to
50165 // upper then lower changes to i
50166 // ro: there is the letter ț which behaves weird under IE8
50167 // mt: letter Ħ
96d0d679 50168 // ga: month with spaces
c58511b9 50169 assert.expect(0);
db71a655
KM
50170 return;
50171 }
50172 function tester(format) {
50173 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
50174 r = moment(m.format(format), format);
50175 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
50176 if (locale !== 'ka') {
50177 r = moment(m.format(format).toLocaleUpperCase(), format);
50178 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
50179 }
db71a655
KM
50180 r = moment(m.format(format).toLocaleLowerCase(), format);
50181 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
50182 r = moment(m.format(format), format, true);
50183 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
50184 if (locale !== 'ka') {
50185 r = moment(m.format(format).toLocaleUpperCase(), format, true);
50186 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
50187 }
db71a655
KM
50188 r = moment(m.format(format).toLocaleLowerCase(), format, true);
50189 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
50190 }
50191
50192 for (i = 0; i < 7; ++i) {
50193 m = moment.utc([2015, 0, i + 1, 18]);
50194 tester('dd');
50195 tester('ddd');
50196 tester('dddd');
50197 }
50198 });
d6651c21 50199
db71a655
KM
50200 test('valid localeData', function (assert) {
50201 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
50202 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
50203 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
50204 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
50205 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
50206 });
96d0d679
KM
50207
50208 test('localeData weekdays can localeSort', function (assert) {
50209 var weekdays = moment().localeData().weekdays();
50210 var weekdaysShort = moment().localeData().weekdaysShort();
50211 var weekdaysMin = moment().localeData().weekdaysMin();
50212 var shift = moment().localeData()._week.dow;
50213 assert.deepEqual(
50214 moment().localeData().weekdays(true),
50215 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
50216 'weekdays should localeSort');
50217 assert.deepEqual(
50218 moment().localeData().weekdaysShort(true),
50219 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
50220 'weekdaysShort should localeSort');
50221 assert.deepEqual(
50222 moment().localeData().weekdaysMin(true),
50223 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
50224 'weekdaysMin should localeSort');
50225 });
db71a655 50226 }
0e67426b 50227
db71a655 50228 /*global QUnit:false*/
0e67426b 50229
db71a655
KM
50230 function localeModule (name, lifecycle) {
50231 QUnit.module('locale:' + name, {
c58511b9 50232 beforeEach : function () {
db71a655
KM
50233 moment.locale(name);
50234 moment.createFromInputFallback = function (config) {
50235 throw new Error('input not handled by moment: ' + config._i);
50236 };
50237 setupDeprecationHandler(test, moment, 'locale');
50238 if (lifecycle && lifecycle.setup) {
50239 lifecycle.setup();
50240 }
50241 },
c58511b9 50242 afterEach : function () {
db71a655
KM
50243 moment.locale('en');
50244 teardownDeprecationHandler(test, moment, 'locale');
50245 if (lifecycle && lifecycle.teardown) {
50246 lifecycle.teardown();
50247 }
0e67426b 50248 }
db71a655
KM
50249 });
50250 defineCommonLocaleTests(name, -1, -1);
50251 }
50252
50253 localeModule('sk');
50254
50255 test('parse', function (assert) {
50256 var tests = 'január jan._február feb._marec mar._apríl apr._máj máj_jún jún._júl júl._august aug._september sep._október okt._november nov._december dec.'.split('_'), i;
50257 function equalTest(input, mmm, monthIndex) {
50258 assert.equal(moment(input, mmm).month(), monthIndex, input + ' should be month ' + (monthIndex + 1));
50259 }
50260 for (i = 0; i < 12; i++) {
50261 tests[i] = tests[i].split(' ');
50262 equalTest(tests[i][0], 'MMM', i);
50263 equalTest(tests[i][1], 'MMM', i);
50264 equalTest(tests[i][0], 'MMMM', i);
50265 equalTest(tests[i][1], 'MMMM', i);
50266 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
50267 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
50268 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
50269 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
50270 }
50271 });
50272
50273 test('format', function (assert) {
50274 var a = [
50275 ['dddd, MMMM Do YYYY, h:mm:ss', 'nedeľa, február 14. 2010, 3:25:50'],
50276 ['ddd, h', 'ne, 3'],
50277 ['M Mo MM MMMM MMM', '2 2. 02 február feb'],
50278 ['YYYY YY', '2010 10'],
50279 ['D Do DD', '14 14. 14'],
50280 ['d do dddd ddd dd', '0 0. nedeľa ne ne'],
50281 ['DDD DDDo DDDD', '45 45. 045'],
50282 ['w wo ww', '6 6. 06'],
50283 ['h hh', '3 03'],
50284 ['H HH', '15 15'],
50285 ['m mm', '25 25'],
50286 ['s ss', '50 50'],
50287 ['a A', 'pm PM'],
50288 ['DDDo [deň v roku]', '45. deň v roku'],
50289 ['LTS', '15:25:50'],
50290 ['L', '14.02.2010'],
50291 ['LL', '14. február 2010'],
50292 ['LLL', '14. február 2010 15:25'],
50293 ['LLLL', 'nedeľa 14. február 2010 15:25'],
50294 ['l', '14.2.2010'],
50295 ['ll', '14. feb 2010'],
50296 ['lll', '14. feb 2010 15:25'],
50297 ['llll', 'ne 14. feb 2010 15:25']
50298 ],
50299 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
50300 i;
50301 for (i = 0; i < a.length; i++) {
50302 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
50303 }
50304 });
50305
50306 test('format ordinal', function (assert) {
50307 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
50308 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
50309 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
50310 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
50311 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
50312 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
50313 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
50314 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
50315 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
50316 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
50317
50318 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
50319 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
50320 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
50321 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
50322 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
50323 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
50324 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
50325 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
50326 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
50327 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
50328
50329 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
50330 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
50331 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
50332 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
50333 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
50334 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
50335 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
50336 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
50337 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
50338 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
50339
50340 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
50341 });
50342
50343 test('format month', function (assert) {
50344 var expected = 'január jan_február feb_marec mar_apríl apr_máj máj_jún jún_júl júl_august aug_september sep_október okt_november nov_december dec'.split('_'), i;
50345 for (i = 0; i < expected.length; i++) {
50346 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
50347 }
50348 });
50349
50350 test('format week', function (assert) {
50351 var expected = 'nedeľa ne ne_pondelok po po_utorok ut ut_streda st st_štvrtok št št_piatok pi pi_sobota so so'.split('_'), i;
50352 for (i = 0; i < expected.length; i++) {
50353 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
50354 }
50355 });
50356
50357 test('from', function (assert) {
50358 var start = moment([2007, 1, 28]);
50359 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'pár sekúnd', '44 seconds = a few seconds');
50360 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minúta', '45 seconds = a minute');
50361 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minúta', '89 seconds = a minute');
50362 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minúty', '90 seconds = 2 minutes');
50363 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minút', '44 minutes = 44 minutes');
50364 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'hodina', '45 minutes = an hour');
50365 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'hodina', '89 minutes = an hour');
50366 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hodiny', '90 minutes = 2 hours');
50367 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hodín', '5 hours = 5 hours');
50368 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hodín', '21 hours = 21 hours');
50369 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'deň', '22 hours = a day');
50370 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'deň', '35 hours = a day');
50371 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dni', '36 hours = 2 days');
50372 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'deň', '1 day = a day');
50373 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dní', '5 days = 5 days');
50374 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dní', '25 days = 25 days');
50375 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mesiac', '26 days = a month');
50376 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mesiac', '30 days = a month');
50377 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mesiac', '43 days = a month');
50378 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mesiace', '46 days = 2 months');
50379 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mesiace', '75 days = 2 months');
50380 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mesiace', '76 days = 3 months');
50381 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mesiac', '1 month = a month');
50382 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mesiacov', '5 months = 5 months');
50383 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'rok', '345 days = a year');
50384 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 roky', '548 days = 2 years');
50385 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'rok', '1 year = a year');
50386 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 rokov', '5 years = 5 years');
50387 });
50388
50389 test('suffix', function (assert) {
50390 assert.equal(moment(30000).from(0), 'za pár sekúnd', 'prefix');
50391 assert.equal(moment(0).from(30000), 'pred pár sekundami', 'suffix');
50392 });
50393
50394 test('now from now', function (assert) {
50395 assert.equal(moment().fromNow(), 'pred pár sekundami', 'now from now should display as in the past');
50396 });
50397
50398 test('fromNow (future)', function (assert) {
50399 assert.equal(moment().add({s: 30}).fromNow(), 'za pár sekúnd', 'in a few seconds');
50400 assert.equal(moment().add({m: 1}).fromNow(), 'za minútu', 'in a minute');
50401 assert.equal(moment().add({m: 3}).fromNow(), 'za 3 minúty', 'in 3 minutes');
50402 assert.equal(moment().add({m: 10}).fromNow(), 'za 10 minút', 'in 10 minutes');
50403 assert.equal(moment().add({h: 1}).fromNow(), 'za hodinu', 'in an hour');
50404 assert.equal(moment().add({h: 3}).fromNow(), 'za 3 hodiny', 'in 3 hours');
50405 assert.equal(moment().add({h: 10}).fromNow(), 'za 10 hodín', 'in 10 hours');
50406 assert.equal(moment().add({d: 1}).fromNow(), 'za deň', 'in a day');
50407 assert.equal(moment().add({d: 3}).fromNow(), 'za 3 dni', 'in 3 days');
50408 assert.equal(moment().add({d: 10}).fromNow(), 'za 10 dní', 'in 10 days');
50409 assert.equal(moment().add({M: 1}).fromNow(), 'za mesiac', 'in a month');
50410 assert.equal(moment().add({M: 3}).fromNow(), 'za 3 mesiace', 'in 3 months');
50411 assert.equal(moment().add({M: 10}).fromNow(), 'za 10 mesiacov', 'in 10 months');
50412 assert.equal(moment().add({y: 1}).fromNow(), 'za rok', 'in a year');
50413 assert.equal(moment().add({y: 3}).fromNow(), 'za 3 roky', 'in 3 years');
50414 assert.equal(moment().add({y: 10}).fromNow(), 'za 10 rokov', 'in 10 years');
50415 });
50416
50417 test('fromNow (past)', function (assert) {
50418 assert.equal(moment().subtract({s: 30}).fromNow(), 'pred pár sekundami', 'a few seconds ago');
50419 assert.equal(moment().subtract({m: 1}).fromNow(), 'pred minútou', 'a minute ago');
50420 assert.equal(moment().subtract({m: 3}).fromNow(), 'pred 3 minútami', '3 minutes ago');
50421 assert.equal(moment().subtract({m: 10}).fromNow(), 'pred 10 minútami', '10 minutes ago');
50422 assert.equal(moment().subtract({h: 1}).fromNow(), 'pred hodinou', 'an hour ago');
50423 assert.equal(moment().subtract({h: 3}).fromNow(), 'pred 3 hodinami', '3 hours ago');
50424 assert.equal(moment().subtract({h: 10}).fromNow(), 'pred 10 hodinami', '10 hours ago');
50425 assert.equal(moment().subtract({d: 1}).fromNow(), 'pred dňom', 'a day ago');
50426 assert.equal(moment().subtract({d: 3}).fromNow(), 'pred 3 dňami', '3 days ago');
50427 assert.equal(moment().subtract({d: 10}).fromNow(), 'pred 10 dňami', '10 days ago');
50428 assert.equal(moment().subtract({M: 1}).fromNow(), 'pred mesiacom', 'a month ago');
50429 assert.equal(moment().subtract({M: 3}).fromNow(), 'pred 3 mesiacmi', '3 months ago');
50430 assert.equal(moment().subtract({M: 10}).fromNow(), 'pred 10 mesiacmi', '10 months ago');
50431 assert.equal(moment().subtract({y: 1}).fromNow(), 'pred rokom', 'a year ago');
50432 assert.equal(moment().subtract({y: 3}).fromNow(), 'pred 3 rokmi', '3 years ago');
50433 assert.equal(moment().subtract({y: 10}).fromNow(), 'pred 10 rokmi', '10 years ago');
50434 });
50435
50436 test('calendar day', function (assert) {
50437 var a = moment().hours(12).minutes(0).seconds(0);
50438
50439 assert.equal(moment(a).calendar(), 'dnes o 12:00', 'today at the same time');
50440 assert.equal(moment(a).add({m: 25}).calendar(), 'dnes o 12:25', 'Now plus 25 min');
50441 assert.equal(moment(a).add({h: 1}).calendar(), 'dnes o 13:00', 'Now plus 1 hour');
50442 assert.equal(moment(a).add({d: 1}).calendar(), 'zajtra o 12:00', 'tomorrow at the same time');
50443 assert.equal(moment(a).subtract({h: 1}).calendar(), 'dnes o 11:00', 'Now minus 1 hour');
50444 assert.equal(moment(a).subtract({d: 1}).calendar(), 'včera o 12:00', 'yesterday at the same time');
50445 });
50446
50447 test('calendar next week', function (assert) {
50448 var i, m, nextDay;
50449 for (i = 2; i < 7; i++) {
50450 m = moment().add({d: i});
50451 nextDay = '';
50452 switch (m.day()) {
50453 case 0:
50454 nextDay = 'v nedeľu';
50455 break;
50456 case 1:
50457 nextDay = 'v pondelok';
50458 break;
50459 case 2:
50460 nextDay = 'v utorok';
50461 break;
50462 case 3:
50463 nextDay = 'v stredu';
50464 break;
50465 case 4:
50466 nextDay = 'vo štvrtok';
50467 break;
50468 case 5:
50469 nextDay = 'v piatok';
50470 break;
50471 case 6:
50472 nextDay = 'v sobotu';
50473 break;
50474 }
50475 assert.equal(m.calendar(), m.format('[' + nextDay + '] [o] LT'), 'Today + ' + i + ' days current time');
50476 m.hours(0).minutes(0).seconds(0).milliseconds(0);
50477 assert.equal(m.calendar(), m.format('[' + nextDay + '] [o] LT'), 'Today + ' + i + ' days beginning of day');
50478 m.hours(23).minutes(59).seconds(59).milliseconds(999);
50479 assert.equal(m.calendar(), m.format('[' + nextDay + '] [o] LT'), 'Today + ' + i + ' days end of day');
50480 }
50481 });
50482
50483 test('calendar last week', function (assert) {
50484 var i, m, lastDay;
50485 for (i = 2; i < 7; i++) {
50486 m = moment().subtract({d: i});
50487 lastDay = '';
50488 switch (m.day()) {
50489 case 0:
50490 lastDay = 'minulú nedeľu';
50491 break;
50492 case 1:
50493 lastDay = 'minulý pondelok';
50494 break;
50495 case 2:
50496 lastDay = 'minulý utorok';
50497 break;
50498 case 3:
50499 lastDay = 'minulú stredu';
50500 break;
50501 case 4:
50502 lastDay = 'minulý štvrtok';
50503 break;
50504 case 5:
50505 lastDay = 'minulý piatok';
50506 break;
50507 case 6:
50508 lastDay = 'minulú sobotu';
50509 break;
50510 }
50511 assert.equal(m.calendar(), m.format('[' + lastDay + '] [o] LT'), 'Today - ' + i + ' days current time');
50512 m.hours(0).minutes(0).seconds(0).milliseconds(0);
50513 assert.equal(m.calendar(), m.format('[' + lastDay + '] [o] LT'), 'Today - ' + i + ' days beginning of day');
50514 m.hours(23).minutes(59).seconds(59).milliseconds(999);
50515 assert.equal(m.calendar(), m.format('[' + lastDay + '] [o] LT'), 'Today - ' + i + ' days end of day');
50516 }
50517 });
50518
50519 test('calendar all else', function (assert) {
50520 var weeksAgo = moment().subtract({w: 1}),
50521 weeksFromNow = moment().add({w: 1});
50522
50523 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
50524 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
50525
50526 weeksAgo = moment().subtract({w: 2});
50527 weeksFromNow = moment().add({w: 2});
50528
50529 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
50530 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
50531 });
50532
50533 test('humanize duration', function (assert) {
50534 assert.equal(moment.duration(1, 'minutes').humanize(), 'minúta', 'a minute (future)');
50535 assert.equal(moment.duration(1, 'minutes').humanize(true), 'za minútu', 'in a minute');
50536 assert.equal(moment.duration(-1, 'minutes').humanize(), 'minúta', 'a minute (past)');
50537 assert.equal(moment.duration(-1, 'minutes').humanize(true), 'pred minútou', 'a minute ago');
50538 });
50539
50540 test('weeks year starting sunday formatted', function (assert) {
50541 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
50542 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
50543 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
50544 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
50545 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
50546 });
0e67426b
KM
50547
50548})));
50549
50550
50551;(function (global, factory) {
50552 typeof exports === 'object' && typeof module !== 'undefined'
50553 && typeof require === 'function' ? factory(require('../../moment')) :
50554 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
50555 factory(global.moment)
50556}(this, (function (moment) { 'use strict';
50557
db71a655
KM
50558 function each(array, callback) {
50559 var i;
50560 for (i = 0; i < array.length; i++) {
50561 callback(array[i], i, array);
50562 }
0e67426b 50563 }
0e67426b 50564
db71a655
KM
50565 function setupDeprecationHandler(test, moment$$1, scope) {
50566 test._expectedDeprecations = null;
50567 test._observedDeprecations = null;
50568 test._oldSupress = moment$$1.suppressDeprecationWarnings;
50569 moment$$1.suppressDeprecationWarnings = true;
50570 test.expectedDeprecations = function () {
50571 test._expectedDeprecations = arguments;
50572 test._observedDeprecations = [];
50573 };
50574 moment$$1.deprecationHandler = function (name, msg) {
50575 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
50576 if (deprecationId === -1) {
50577 throw new Error('Unexpected deprecation thrown name=' +
50578 name + ' msg=' + msg);
50579 }
50580 test._observedDeprecations[deprecationId] = 1;
50581 };
50582 }
73f3c911 50583
db71a655
KM
50584 function teardownDeprecationHandler(test, moment$$1, scope) {
50585 moment$$1.suppressDeprecationWarnings = test._oldSupress;
73f3c911 50586
db71a655
KM
50587 if (test._expectedDeprecations != null) {
50588 var missedDeprecations = [];
50589 each(test._expectedDeprecations, function (deprecationPattern, id) {
50590 if (test._observedDeprecations[id] !== 1) {
50591 missedDeprecations.push(deprecationPattern);
50592 }
50593 });
50594 if (missedDeprecations.length !== 0) {
50595 throw new Error('Expected deprecation warnings did not happen: ' +
50596 missedDeprecations.join(' '));
d6651c21
IC
50597 }
50598 }
73f3c911 50599 }
73f3c911 50600
db71a655
KM
50601 function matchedDeprecation(name, msg, deprecations) {
50602 if (deprecations == null) {
50603 return -1;
73f3c911 50604 }
db71a655
KM
50605 for (var i = 0; i < deprecations.length; ++i) {
50606 if (name != null && name === deprecations[i]) {
50607 return i;
50608 }
50609 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
50610 return i;
50611 }
73f3c911 50612 }
db71a655 50613 return -1;
73f3c911 50614 }
c74a101d 50615
db71a655 50616 /*global QUnit:false*/
c74a101d 50617
db71a655 50618 var test = QUnit.test;
c74a101d 50619
c58511b9
KM
50620 function objectKeys(obj) {
50621 if (Object.keys) {
50622 return Object.keys(obj);
50623 } else {
50624 // IE8
50625 var res = [], i;
50626 for (i in obj) {
50627 if (obj.hasOwnProperty(i)) {
50628 res.push(i);
50629 }
50630 }
50631 return res;
50632 }
50633 }
50634
50635 // Pick the first defined of two or three arguments.
50636
50637 function defineCommonLocaleTests(locale, options) {
50638 test('lenient day of month ordinal parsing', function (assert) {
50639 var i, ordinalStr, testMoment;
50640 for (i = 1; i <= 31; ++i) {
50641 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
50642 testMoment = moment(ordinalStr, 'YYYY MM Do');
50643 assert.equal(testMoment.year(), 2014,
50644 'lenient day of month ordinal parsing ' + i + ' year check');
50645 assert.equal(testMoment.month(), 0,
50646 'lenient day of month ordinal parsing ' + i + ' month check');
50647 assert.equal(testMoment.date(), i,
50648 'lenient day of month ordinal parsing ' + i + ' date check');
50649 }
50650 });
50651
50652 test('lenient day of month ordinal parsing of number', function (assert) {
50653 var i, testMoment;
50654 for (i = 1; i <= 31; ++i) {
50655 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
50656 assert.equal(testMoment.year(), 2014,
50657 'lenient day of month ordinal parsing of number ' + i + ' year check');
50658 assert.equal(testMoment.month(), 0,
50659 'lenient day of month ordinal parsing of number ' + i + ' month check');
50660 assert.equal(testMoment.date(), i,
50661 'lenient day of month ordinal parsing of number ' + i + ' date check');
50662 }
50663 });
50664
50665 test('strict day of month ordinal parsing', function (assert) {
50666 var i, ordinalStr, testMoment;
50667 for (i = 1; i <= 31; ++i) {
50668 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
50669 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
50670 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
50671 }
50672 });
50673
50674 test('meridiem invariant', function (assert) {
50675 var h, m, t1, t2;
50676 for (h = 0; h < 24; ++h) {
50677 for (m = 0; m < 60; m += 15) {
50678 t1 = moment.utc([2000, 0, 1, h, m]);
50679 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
50680 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
50681 'meridiem at ' + t1.format('HH:mm'));
50682 }
50683 }
50684 });
50685
50686 test('date format correctness', function (assert) {
50687 var data, tokens;
50688 data = moment.localeData()._longDateFormat;
50689 tokens = objectKeys(data);
50690 each(tokens, function (srchToken) {
50691 // Check each format string to make sure it does not contain any
50692 // tokens that need to be expanded.
50693 each(tokens, function (baseToken) {
50694 // strip escaped sequences
50695 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
50696 assert.equal(false, !!~format.indexOf(srchToken),
50697 'contains ' + srchToken + ' in ' + baseToken);
50698 });
50699 });
50700 });
50701
50702 test('month parsing correctness', function (assert) {
50703 var i, m;
50704
50705 if (locale === 'tr') {
50706 // I can't fix it :(
50707 assert.expect(0);
50708 return;
50709 }
50710 function tester(format) {
50711 var r;
50712 r = moment(m.format(format), format);
50713 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
50714 if (locale !== 'ka') {
50715 r = moment(m.format(format).toLocaleUpperCase(), format);
50716 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
50717 }
c58511b9
KM
50718 r = moment(m.format(format).toLocaleLowerCase(), format);
50719 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
50720
50721 r = moment(m.format(format), format, true);
50722 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
50723 if (locale !== 'ka') {
50724 r = moment(m.format(format).toLocaleUpperCase(), format, true);
50725 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
50726 }
c58511b9
KM
50727 r = moment(m.format(format).toLocaleLowerCase(), format, true);
50728 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
50729 }
50730
50731 for (i = 0; i < 12; ++i) {
50732 m = moment([2015, i, 15, 18]);
50733 tester('MMM');
50734 tester('MMM.');
50735 tester('MMMM');
50736 tester('MMMM.');
50737 }
50738 });
50739
50740 test('weekday parsing correctness', function (assert) {
50741 var i, m;
50742
96d0d679 50743 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
c58511b9
KM
50744 // tr, az: There is a lower-case letter (ı), that converted to
50745 // upper then lower changes to i
50746 // ro: there is the letter ț which behaves weird under IE8
50747 // mt: letter Ħ
96d0d679 50748 // ga: month with spaces
c58511b9
KM
50749 assert.expect(0);
50750 return;
50751 }
50752 function tester(format) {
50753 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
50754 r = moment(m.format(format), format);
50755 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
50756 if (locale !== 'ka') {
50757 r = moment(m.format(format).toLocaleUpperCase(), format);
50758 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
50759 }
c58511b9
KM
50760 r = moment(m.format(format).toLocaleLowerCase(), format);
50761 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
50762 r = moment(m.format(format), format, true);
50763 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
50764 if (locale !== 'ka') {
50765 r = moment(m.format(format).toLocaleUpperCase(), format, true);
50766 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
50767 }
c58511b9
KM
50768 r = moment(m.format(format).toLocaleLowerCase(), format, true);
50769 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
50770 }
50771
50772 for (i = 0; i < 7; ++i) {
50773 m = moment.utc([2015, 0, i + 1, 18]);
50774 tester('dd');
50775 tester('ddd');
50776 tester('dddd');
50777 }
50778 });
50779
50780 test('valid localeData', function (assert) {
50781 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
50782 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
50783 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
50784 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
50785 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
50786 });
96d0d679
KM
50787
50788 test('localeData weekdays can localeSort', function (assert) {
50789 var weekdays = moment().localeData().weekdays();
50790 var weekdaysShort = moment().localeData().weekdaysShort();
50791 var weekdaysMin = moment().localeData().weekdaysMin();
50792 var shift = moment().localeData()._week.dow;
50793 assert.deepEqual(
50794 moment().localeData().weekdays(true),
50795 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
50796 'weekdays should localeSort');
50797 assert.deepEqual(
50798 moment().localeData().weekdaysShort(true),
50799 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
50800 'weekdaysShort should localeSort');
50801 assert.deepEqual(
50802 moment().localeData().weekdaysMin(true),
50803 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
50804 'weekdaysMin should localeSort');
50805 });
c58511b9
KM
50806 }
50807
50808 /*global QUnit:false*/
c74a101d 50809
db71a655
KM
50810 function localeModule (name, lifecycle) {
50811 QUnit.module('locale:' + name, {
c58511b9 50812 beforeEach : function () {
db71a655
KM
50813 moment.locale(name);
50814 moment.createFromInputFallback = function (config) {
50815 throw new Error('input not handled by moment: ' + config._i);
50816 };
50817 setupDeprecationHandler(test, moment, 'locale');
50818 if (lifecycle && lifecycle.setup) {
50819 lifecycle.setup();
50820 }
50821 },
c58511b9 50822 afterEach : function () {
db71a655
KM
50823 moment.locale('en');
50824 teardownDeprecationHandler(test, moment, 'locale');
50825 if (lifecycle && lifecycle.teardown) {
50826 lifecycle.teardown();
50827 }
73f3c911 50828 }
db71a655
KM
50829 });
50830 defineCommonLocaleTests(name, -1, -1);
50831 }
50832
50833 localeModule('sl');
50834
50835 test('parse', function (assert) {
50836 var tests = 'januar jan._februar feb._marec mar._april apr._maj maj_junij jun._julij jul._avgust avg._september sep._oktober okt._november nov._december dec.'.split('_'), i;
50837 function equalTest(input, mmm, i) {
50838 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
50839 }
50840 for (i = 0; i < 12; i++) {
50841 tests[i] = tests[i].split(' ');
50842 equalTest(tests[i][0], 'MMM', i);
50843 equalTest(tests[i][1], 'MMM', i);
50844 equalTest(tests[i][0], 'MMMM', i);
50845 equalTest(tests[i][1], 'MMMM', i);
50846 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
50847 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
50848 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
50849 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
50850 }
50851 });
50852
50853 test('format', function (assert) {
50854 var a = [
50855 ['dddd, Do MMMM YYYY, h:mm:ss a', 'nedelja, 14. februar 2010, 3:25:50 pm'],
50856 ['ddd, hA', 'ned., 3PM'],
50857 ['M Mo MM MMMM MMM', '2 2. 02 februar feb.'],
50858 ['YYYY YY', '2010 10'],
50859 ['D Do DD', '14 14. 14'],
50860 ['d do dddd ddd dd', '0 0. nedelja ned. ne'],
50861 ['DDD DDDo DDDD', '45 45. 045'],
50862 ['w wo ww', '7 7. 07'],
50863 ['h hh', '3 03'],
50864 ['H HH', '15 15'],
50865 ['m mm', '25 25'],
50866 ['s ss', '50 50'],
50867 ['a A', 'pm PM'],
50868 ['[the] DDDo [day of the year]', 'the 45. day of the year'],
50869 ['LTS', '15:25:50'],
50870 ['L', '14.02.2010'],
50871 ['LL', '14. februar 2010'],
50872 ['LLL', '14. februar 2010 15:25'],
50873 ['LLLL', 'nedelja, 14. februar 2010 15:25'],
50874 ['l', '14.2.2010'],
50875 ['ll', '14. feb. 2010'],
50876 ['lll', '14. feb. 2010 15:25'],
50877 ['llll', 'ned., 14. feb. 2010 15:25']
50878 ],
50879 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
50880 i;
50881 for (i = 0; i < a.length; i++) {
50882 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
50883 }
50884 });
50885
50886 test('format ordinal', function (assert) {
50887 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
50888 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
50889 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
50890 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
50891 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
50892 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
50893 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
50894 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
50895 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
50896 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
50897
50898 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
50899 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
50900 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
50901 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
50902 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
50903 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
50904 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
50905 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
50906 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
50907 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
50908
50909 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
50910 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
50911 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
50912 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
50913 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
50914 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
50915 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
50916 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
50917 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
50918 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
50919
50920 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
50921 });
50922
50923 test('format month', function (assert) {
50924 var expected = 'januar jan._februar feb._marec mar._april apr._maj maj._junij jun._julij jul._avgust avg._september sep._oktober okt._november nov._december dec.'.split('_'), i;
50925 for (i = 0; i < expected.length; i++) {
50926 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
50927 }
50928 });
50929
50930 test('format week', function (assert) {
50931 var expected = 'nedelja ned. ne_ponedeljek pon. po_torek tor. to_sreda sre. sr_četrtek čet. če_petek pet. pe_sobota sob. so'.split('_'), i;
50932 for (i = 0; i < expected.length; i++) {
50933 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
50934 }
50935 });
50936
50937 test('from', function (assert) {
50938 var start = moment([2007, 1, 28]);
50939 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'nekaj sekund', '44 seconds = a few seconds');
50940 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ena minuta', '45 seconds = a minute');
50941 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ena minuta', '89 seconds = a minute');
50942 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuti', '90 seconds = 2 minutes');
50943 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minut', '44 minutes = 44 minutes');
50944 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ena ura', '45 minutes = an hour');
50945 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ena ura', '89 minutes = an hour');
50946 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 uri', '90 minutes = 2 hours');
50947 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ur', '5 hours = 5 hours');
50948 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ur', '21 hours = 21 hours');
50949 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'en dan', '22 hours = a day');
50950 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'en dan', '35 hours = a day');
50951 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dni', '36 hours = 2 days');
50952 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'en dan', '1 day = a day');
50953 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dni', '5 days = 5 days');
50954 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dni', '25 days = 25 days');
50955 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'en mesec', '26 days = a month');
50956 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'en mesec', '30 days = a month');
50957 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'en mesec', '43 days = a month');
50958 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 meseca', '46 days = 2 months');
50959 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 meseca', '75 days = 2 months');
50960 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mesece', '76 days = 3 months');
50961 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'en mesec', '1 month = a month');
50962 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mesecev', '5 months = 5 months');
50963 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'eno leto', '345 days = a year');
50964 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 leti', '548 days = 2 years');
50965 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'eno leto', '1 year = a year');
50966 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 let', '5 years = 5 years');
50967
50968 assert.equal(start.from(moment([2007, 1, 28]).add({m: 1}), true), 'ena minuta', 'a minute');
50969 assert.equal(start.from(moment([2007, 1, 28]).add({m: 2}), true), '2 minuti', '2 minutes');
50970 assert.equal(start.from(moment([2007, 1, 28]).add({m: 3}), true), '3 minute', '3 minutes');
50971 assert.equal(start.from(moment([2007, 1, 28]).add({m: 4}), true), '4 minute', '4 minutes');
50972 assert.equal(start.from(moment([2007, 1, 28]).add({m: 5}), true), '5 minut', '5 minutes');
50973
50974 assert.equal(start.from(moment([2007, 1, 28]).add({h: 1}), true), 'ena ura', 'an hour');
50975 assert.equal(start.from(moment([2007, 1, 28]).add({h: 2}), true), '2 uri', '2 hours');
50976 assert.equal(start.from(moment([2007, 1, 28]).add({h: 3}), true), '3 ure', '3 hours');
50977 assert.equal(start.from(moment([2007, 1, 28]).add({h: 4}), true), '4 ure', '4 hours');
50978 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ur', '5 hours');
50979
50980 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'en dan', 'a day');
50981 assert.equal(start.from(moment([2007, 1, 28]).add({d: 2}), true), '2 dni', '2 days');
50982 assert.equal(start.from(moment([2007, 1, 28]).add({d: 3}), true), '3 dni', '3 days');
50983 assert.equal(start.from(moment([2007, 1, 28]).add({d: 4}), true), '4 dni', '4 days');
50984 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dni', '5 days');
50985
50986 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'en mesec', 'a month');
50987 assert.equal(start.from(moment([2007, 1, 28]).add({M: 2}), true), '2 meseca', '2 months');
50988 assert.equal(start.from(moment([2007, 1, 28]).add({M: 3}), true), '3 mesece', '3 months');
50989 assert.equal(start.from(moment([2007, 1, 28]).add({M: 4}), true), '4 mesece', '4 months');
50990 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mesecev', '5 months');
50991
50992 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'eno leto', 'a year');
50993 assert.equal(start.from(moment([2007, 1, 28]).add({y: 2}), true), '2 leti', '2 years');
50994 assert.equal(start.from(moment([2007, 1, 28]).add({y: 3}), true), '3 leta', '3 years');
50995 assert.equal(start.from(moment([2007, 1, 28]).add({y: 4}), true), '4 leta', '4 years');
50996 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 let', '5 years');
50997 });
50998
50999 test('suffix', function (assert) {
51000 assert.equal(moment(30000).from(0), 'čez nekaj sekund', 'prefix');
51001 assert.equal(moment(0).from(30000), 'pred nekaj sekundami', 'suffix');
51002 });
51003
51004 test('now from now', function (assert) {
51005 assert.equal(moment().fromNow(), 'pred nekaj sekundami', 'now from now should display as in the past');
51006 });
51007
51008 test('fromNow (future)', function (assert) {
51009 assert.equal(moment().add({s: 30}).fromNow(), 'čez nekaj sekund', 'in a few seconds');
51010 assert.equal(moment().add({m: 1}).fromNow(), 'čez eno minuto', 'in a minute');
51011 assert.equal(moment().add({m: 2}).fromNow(), 'čez 2 minuti', 'in 2 minutes');
51012 assert.equal(moment().add({m: 3}).fromNow(), 'čez 3 minute', 'in 3 minutes');
51013 assert.equal(moment().add({m: 4}).fromNow(), 'čez 4 minute', 'in 4 minutes');
51014 assert.equal(moment().add({m: 5}).fromNow(), 'čez 5 minut', 'in 5 minutes');
51015
51016 assert.equal(moment().add({h: 1}).fromNow(), 'čez eno uro', 'in an hour');
51017 assert.equal(moment().add({h: 2}).fromNow(), 'čez 2 uri', 'in 2 hours');
51018 assert.equal(moment().add({h: 3}).fromNow(), 'čez 3 ure', 'in 3 hours');
51019 assert.equal(moment().add({h: 4}).fromNow(), 'čez 4 ure', 'in 4 hours');
51020 assert.equal(moment().add({h: 5}).fromNow(), 'čez 5 ur', 'in 5 hours');
51021
51022 assert.equal(moment().add({d: 1}).fromNow(), 'čez en dan', 'in a day');
51023 assert.equal(moment().add({d: 2}).fromNow(), 'čez 2 dni', 'in 2 days');
51024 assert.equal(moment().add({d: 3}).fromNow(), 'čez 3 dni', 'in 3 days');
51025 assert.equal(moment().add({d: 4}).fromNow(), 'čez 4 dni', 'in 4 days');
51026 assert.equal(moment().add({d: 5}).fromNow(), 'čez 5 dni', 'in 5 days');
51027
51028 assert.equal(moment().add({M: 1}).fromNow(), 'čez en mesec', 'in a month');
51029 assert.equal(moment().add({M: 2}).fromNow(), 'čez 2 meseca', 'in 2 months');
51030 assert.equal(moment().add({M: 3}).fromNow(), 'čez 3 mesece', 'in 3 months');
51031 assert.equal(moment().add({M: 4}).fromNow(), 'čez 4 mesece', 'in 4 months');
51032 assert.equal(moment().add({M: 5}).fromNow(), 'čez 5 mesecev', 'in 5 months');
51033
51034 assert.equal(moment().add({y: 1}).fromNow(), 'čez eno leto', 'in a year');
51035 assert.equal(moment().add({y: 2}).fromNow(), 'čez 2 leti', 'in 2 years');
51036 assert.equal(moment().add({y: 3}).fromNow(), 'čez 3 leta', 'in 3 years');
51037 assert.equal(moment().add({y: 4}).fromNow(), 'čez 4 leta', 'in 4 years');
51038 assert.equal(moment().add({y: 5}).fromNow(), 'čez 5 let', 'in 5 years');
51039
51040 assert.equal(moment().subtract({s: 30}).fromNow(), 'pred nekaj sekundami', 'a few seconds ago');
51041
51042 assert.equal(moment().subtract({m: 1}).fromNow(), 'pred eno minuto', 'a minute ago');
51043 assert.equal(moment().subtract({m: 2}).fromNow(), 'pred 2 minutama', '2 minutes ago');
51044 assert.equal(moment().subtract({m: 3}).fromNow(), 'pred 3 minutami', '3 minutes ago');
51045 assert.equal(moment().subtract({m: 4}).fromNow(), 'pred 4 minutami', '4 minutes ago');
51046 assert.equal(moment().subtract({m: 5}).fromNow(), 'pred 5 minutami', '5 minutes ago');
51047
51048 assert.equal(moment().subtract({h: 1}).fromNow(), 'pred eno uro', 'an hour ago');
51049 assert.equal(moment().subtract({h: 2}).fromNow(), 'pred 2 urama', '2 hours ago');
51050 assert.equal(moment().subtract({h: 3}).fromNow(), 'pred 3 urami', '3 hours ago');
51051 assert.equal(moment().subtract({h: 4}).fromNow(), 'pred 4 urami', '4 hours ago');
51052 assert.equal(moment().subtract({h: 5}).fromNow(), 'pred 5 urami', '5 hours ago');
51053
51054 assert.equal(moment().subtract({d: 1}).fromNow(), 'pred enim dnem', 'a day ago');
51055 assert.equal(moment().subtract({d: 2}).fromNow(), 'pred 2 dnevoma', '2 days ago');
51056 assert.equal(moment().subtract({d: 3}).fromNow(), 'pred 3 dnevi', '3 days ago');
51057 assert.equal(moment().subtract({d: 4}).fromNow(), 'pred 4 dnevi', '4 days ago');
51058 assert.equal(moment().subtract({d: 5}).fromNow(), 'pred 5 dnevi', '5 days ago');
51059
51060 assert.equal(moment().subtract({M: 1}).fromNow(), 'pred enim mesecem', 'a month ago');
51061 assert.equal(moment().subtract({M: 2}).fromNow(), 'pred 2 mesecema', '2 months ago');
51062 assert.equal(moment().subtract({M: 3}).fromNow(), 'pred 3 meseci', '3 months ago');
51063 assert.equal(moment().subtract({M: 4}).fromNow(), 'pred 4 meseci', '4 months ago');
51064 assert.equal(moment().subtract({M: 5}).fromNow(), 'pred 5 meseci', '5 months ago');
51065
51066 assert.equal(moment().subtract({y: 1}).fromNow(), 'pred enim letom', 'a year ago');
51067 assert.equal(moment().subtract({y: 2}).fromNow(), 'pred 2 letoma', '2 years ago');
51068 assert.equal(moment().subtract({y: 3}).fromNow(), 'pred 3 leti', '3 years ago');
51069 assert.equal(moment().subtract({y: 4}).fromNow(), 'pred 4 leti', '4 years ago');
51070 assert.equal(moment().subtract({y: 5}).fromNow(), 'pred 5 leti', '5 years ago');
51071 });
51072
51073 test('calendar day', function (assert) {
51074 var a = moment().hours(12).minutes(0).seconds(0);
51075
51076 assert.equal(moment(a).calendar(), 'danes ob 12:00', 'today at the same time');
51077 assert.equal(moment(a).add({m: 25}).calendar(), 'danes ob 12:25', 'Now plus 25 min');
51078 assert.equal(moment(a).add({h: 1}).calendar(), 'danes ob 13:00', 'Now plus 1 hour');
51079 assert.equal(moment(a).add({d: 1}).calendar(), 'jutri ob 12:00', 'tomorrow at the same time');
51080 assert.equal(moment(a).subtract({h: 1}).calendar(), 'danes ob 11:00', 'Now minus 1 hour');
51081 assert.equal(moment(a).subtract({d: 1}).calendar(), 'včeraj ob 12:00', 'yesterday at the same time');
51082 });
51083
51084 test('calendar next week', function (assert) {
51085 var i, m;
51086
51087 function makeFormat(d) {
51088 switch (d.day()) {
51089 case 0:
51090 return '[v] [nedeljo] [ob] LT';
51091 case 3:
51092 return '[v] [sredo] [ob] LT';
51093 case 6:
51094 return '[v] [soboto] [ob] LT';
51095 case 1:
51096 case 2:
51097 case 4:
51098 case 5:
51099 return '[v] dddd [ob] LT';
c74a101d 51100 }
c74a101d 51101 }
db71a655
KM
51102
51103 for (i = 2; i < 7; i++) {
51104 m = moment().add({d: i});
51105 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time');
51106 m.hours(0).minutes(0).seconds(0).milliseconds(0);
51107 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day');
51108 m.hours(23).minutes(59).seconds(59).milliseconds(999);
51109 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day');
51110 }
c74a101d
IC
51111 });
51112
db71a655
KM
51113 test('calendar last week', function (assert) {
51114 var i, m;
c74a101d 51115
db71a655
KM
51116 function makeFormat(d) {
51117 switch (d.day()) {
51118 case 0:
51119 return '[prejšnjo] [nedeljo] [ob] LT';
51120 case 3:
51121 return '[prejšnjo] [sredo] [ob] LT';
51122 case 6:
51123 return '[prejšnjo] [soboto] [ob] LT';
51124 case 1:
51125 case 2:
51126 case 4:
51127 case 5:
51128 return '[prejšnji] dddd [ob] LT';
51129 }
51130 }
c74a101d 51131
db71a655
KM
51132 for (i = 2; i < 7; i++) {
51133 m = moment().subtract({d: i});
51134 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time');
51135 m.hours(0).minutes(0).seconds(0).milliseconds(0);
51136 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day');
51137 m.hours(23).minutes(59).seconds(59).milliseconds(999);
51138 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day');
51139 }
51140 });
c74a101d 51141
db71a655
KM
51142 test('calendar all else', function (assert) {
51143 var weeksAgo = moment().subtract({w: 1}),
51144 weeksFromNow = moment().add({w: 1});
c74a101d 51145
db71a655
KM
51146 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
51147 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
c74a101d 51148
db71a655
KM
51149 weeksAgo = moment().subtract({w: 2});
51150 weeksFromNow = moment().add({w: 2});
c74a101d 51151
db71a655
KM
51152 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
51153 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
73f3c911
IC
51154 });
51155
db71a655
KM
51156 test('weeks year starting sunday formatted', function (assert) {
51157 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', 'Dec 26 2011 should be week 1');
51158 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1.', 'Jan 1 2012 should be week 1');
51159 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2.', 'Jan 2 2012 should be week 2');
51160 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2.', 'Jan 8 2012 should be week 2');
51161 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3.', 'Jan 9 2012 should be week 3');
51162 });
73f3c911
IC
51163
51164})));
c74a101d 51165
c74a101d
IC
51166
51167;(function (global, factory) {
51168 typeof exports === 'object' && typeof module !== 'undefined'
51169 && typeof require === 'function' ? factory(require('../../moment')) :
51170 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
51171 factory(global.moment)
73f3c911 51172}(this, (function (moment) { 'use strict';
c74a101d 51173
db71a655
KM
51174 function each(array, callback) {
51175 var i;
51176 for (i = 0; i < array.length; i++) {
51177 callback(array[i], i, array);
51178 }
b135bf1a
IC
51179 }
51180
c58511b9
KM
51181 function setupDeprecationHandler(test, moment$$1, scope) {
51182 test._expectedDeprecations = null;
51183 test._observedDeprecations = null;
51184 test._oldSupress = moment$$1.suppressDeprecationWarnings;
51185 moment$$1.suppressDeprecationWarnings = true;
51186 test.expectedDeprecations = function () {
51187 test._expectedDeprecations = arguments;
51188 test._observedDeprecations = [];
51189 };
51190 moment$$1.deprecationHandler = function (name, msg) {
51191 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
51192 if (deprecationId === -1) {
51193 throw new Error('Unexpected deprecation thrown name=' +
51194 name + ' msg=' + msg);
51195 }
51196 test._observedDeprecations[deprecationId] = 1;
51197 };
51198 }
51199
51200 function teardownDeprecationHandler(test, moment$$1, scope) {
51201 moment$$1.suppressDeprecationWarnings = test._oldSupress;
51202
51203 if (test._expectedDeprecations != null) {
51204 var missedDeprecations = [];
51205 each(test._expectedDeprecations, function (deprecationPattern, id) {
51206 if (test._observedDeprecations[id] !== 1) {
51207 missedDeprecations.push(deprecationPattern);
51208 }
51209 });
51210 if (missedDeprecations.length !== 0) {
51211 throw new Error('Expected deprecation warnings did not happen: ' +
51212 missedDeprecations.join(' '));
51213 }
51214 }
51215 }
51216
51217 function matchedDeprecation(name, msg, deprecations) {
51218 if (deprecations == null) {
51219 return -1;
51220 }
51221 for (var i = 0; i < deprecations.length; ++i) {
51222 if (name != null && name === deprecations[i]) {
51223 return i;
51224 }
51225 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
51226 return i;
51227 }
51228 }
51229 return -1;
51230 }
51231
51232 /*global QUnit:false*/
51233
51234 var test = QUnit.test;
51235
db71a655
KM
51236 function objectKeys(obj) {
51237 if (Object.keys) {
51238 return Object.keys(obj);
51239 } else {
51240 // IE8
51241 var res = [], i;
51242 for (i in obj) {
51243 if (obj.hasOwnProperty(i)) {
51244 res.push(i);
51245 }
b135bf1a 51246 }
db71a655 51247 return res;
b135bf1a 51248 }
b135bf1a 51249 }
b135bf1a 51250
db71a655 51251 // Pick the first defined of two or three arguments.
b135bf1a 51252
db71a655
KM
51253 function defineCommonLocaleTests(locale, options) {
51254 test('lenient day of month ordinal parsing', function (assert) {
51255 var i, ordinalStr, testMoment;
51256 for (i = 1; i <= 31; ++i) {
51257 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
51258 testMoment = moment(ordinalStr, 'YYYY MM Do');
51259 assert.equal(testMoment.year(), 2014,
51260 'lenient day of month ordinal parsing ' + i + ' year check');
51261 assert.equal(testMoment.month(), 0,
51262 'lenient day of month ordinal parsing ' + i + ' month check');
51263 assert.equal(testMoment.date(), i,
51264 'lenient day of month ordinal parsing ' + i + ' date check');
51265 }
51266 });
b135bf1a 51267
db71a655
KM
51268 test('lenient day of month ordinal parsing of number', function (assert) {
51269 var i, testMoment;
51270 for (i = 1; i <= 31; ++i) {
51271 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
51272 assert.equal(testMoment.year(), 2014,
51273 'lenient day of month ordinal parsing of number ' + i + ' year check');
51274 assert.equal(testMoment.month(), 0,
51275 'lenient day of month ordinal parsing of number ' + i + ' month check');
51276 assert.equal(testMoment.date(), i,
51277 'lenient day of month ordinal parsing of number ' + i + ' date check');
51278 }
b135bf1a 51279 });
d6651c21 51280
db71a655
KM
51281 test('strict day of month ordinal parsing', function (assert) {
51282 var i, ordinalStr, testMoment;
51283 for (i = 1; i <= 31; ++i) {
51284 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
51285 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
51286 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
51287 }
51288 });
d6651c21 51289
db71a655
KM
51290 test('meridiem invariant', function (assert) {
51291 var h, m, t1, t2;
51292 for (h = 0; h < 24; ++h) {
51293 for (m = 0; m < 60; m += 15) {
51294 t1 = moment.utc([2000, 0, 1, h, m]);
51295 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
51296 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
51297 'meridiem at ' + t1.format('HH:mm'));
51298 }
51299 }
51300 });
d6651c21 51301
db71a655
KM
51302 test('date format correctness', function (assert) {
51303 var data, tokens;
51304 data = moment.localeData()._longDateFormat;
51305 tokens = objectKeys(data);
51306 each(tokens, function (srchToken) {
51307 // Check each format string to make sure it does not contain any
51308 // tokens that need to be expanded.
51309 each(tokens, function (baseToken) {
51310 // strip escaped sequences
51311 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
51312 assert.equal(false, !!~format.indexOf(srchToken),
51313 'contains ' + srchToken + ' in ' + baseToken);
51314 });
51315 });
51316 });
d6651c21 51317
db71a655
KM
51318 test('month parsing correctness', function (assert) {
51319 var i, m;
51320
51321 if (locale === 'tr') {
51322 // I can't fix it :(
c58511b9 51323 assert.expect(0);
db71a655
KM
51324 return;
51325 }
51326 function tester(format) {
51327 var r;
51328 r = moment(m.format(format), format);
51329 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
51330 if (locale !== 'ka') {
51331 r = moment(m.format(format).toLocaleUpperCase(), format);
51332 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
51333 }
db71a655
KM
51334 r = moment(m.format(format).toLocaleLowerCase(), format);
51335 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
51336
51337 r = moment(m.format(format), format, true);
51338 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
51339 if (locale !== 'ka') {
51340 r = moment(m.format(format).toLocaleUpperCase(), format, true);
51341 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
51342 }
db71a655
KM
51343 r = moment(m.format(format).toLocaleLowerCase(), format, true);
51344 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
51345 }
51346
51347 for (i = 0; i < 12; ++i) {
51348 m = moment([2015, i, 15, 18]);
51349 tester('MMM');
51350 tester('MMM.');
51351 tester('MMMM');
51352 tester('MMMM.');
51353 }
51354 });
73f3c911 51355
db71a655
KM
51356 test('weekday parsing correctness', function (assert) {
51357 var i, m;
51358
96d0d679 51359 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
51360 // tr, az: There is a lower-case letter (ı), that converted to
51361 // upper then lower changes to i
51362 // ro: there is the letter ț which behaves weird under IE8
51363 // mt: letter Ħ
96d0d679 51364 // ga: month with spaces
c58511b9 51365 assert.expect(0);
db71a655
KM
51366 return;
51367 }
51368 function tester(format) {
51369 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
51370 r = moment(m.format(format), format);
51371 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
51372 if (locale !== 'ka') {
51373 r = moment(m.format(format).toLocaleUpperCase(), format);
51374 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
51375 }
db71a655
KM
51376 r = moment(m.format(format).toLocaleLowerCase(), format);
51377 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
51378 r = moment(m.format(format), format, true);
51379 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
51380 if (locale !== 'ka') {
51381 r = moment(m.format(format).toLocaleUpperCase(), format, true);
51382 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
51383 }
db71a655
KM
51384 r = moment(m.format(format).toLocaleLowerCase(), format, true);
51385 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
51386 }
51387
51388 for (i = 0; i < 7; ++i) {
51389 m = moment.utc([2015, 0, i + 1, 18]);
51390 tester('dd');
51391 tester('ddd');
51392 tester('dddd');
51393 }
51394 });
d6651c21 51395
db71a655
KM
51396 test('valid localeData', function (assert) {
51397 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
51398 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
51399 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
51400 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
51401 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
51402 });
96d0d679
KM
51403
51404 test('localeData weekdays can localeSort', function (assert) {
51405 var weekdays = moment().localeData().weekdays();
51406 var weekdaysShort = moment().localeData().weekdaysShort();
51407 var weekdaysMin = moment().localeData().weekdaysMin();
51408 var shift = moment().localeData()._week.dow;
51409 assert.deepEqual(
51410 moment().localeData().weekdays(true),
51411 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
51412 'weekdays should localeSort');
51413 assert.deepEqual(
51414 moment().localeData().weekdaysShort(true),
51415 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
51416 'weekdaysShort should localeSort');
51417 assert.deepEqual(
51418 moment().localeData().weekdaysMin(true),
51419 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
51420 'weekdaysMin should localeSort');
51421 });
db71a655 51422 }
b135bf1a 51423
db71a655 51424 /*global QUnit:false*/
1d986a17 51425
db71a655
KM
51426 function localeModule (name, lifecycle) {
51427 QUnit.module('locale:' + name, {
c58511b9 51428 beforeEach : function () {
db71a655
KM
51429 moment.locale(name);
51430 moment.createFromInputFallback = function (config) {
51431 throw new Error('input not handled by moment: ' + config._i);
51432 };
51433 setupDeprecationHandler(test, moment, 'locale');
51434 if (lifecycle && lifecycle.setup) {
51435 lifecycle.setup();
51436 }
51437 },
c58511b9 51438 afterEach : function () {
db71a655
KM
51439 moment.locale('en');
51440 teardownDeprecationHandler(test, moment, 'locale');
51441 if (lifecycle && lifecycle.teardown) {
51442 lifecycle.teardown();
51443 }
b135bf1a 51444 }
db71a655
KM
51445 });
51446 defineCommonLocaleTests(name, -1, -1);
51447 }
51448
51449 localeModule('sq');
51450
51451 test('parse', function (assert) {
51452 var i,
51453 tests = 'Janar Jan_Shkurt Shk_Mars Mar_Prill Pri_Maj Maj_Qershor Qer_Korrik Kor_Gusht Gus_Shtator Sht_Tetor Tet_Nëntor Nën_Dhjetor Dhj'.split('_');
51454
51455 function equalTest(input, mmm, i) {
51456 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
51457 }
51458
51459 for (i = 0; i < 12; i++) {
51460 tests[i] = tests[i].split(' ');
51461 equalTest(tests[i][0], 'MMM', i);
51462 equalTest(tests[i][1], 'MMM', i);
51463 equalTest(tests[i][0], 'MMMM', i);
51464 equalTest(tests[i][1], 'MMMM', i);
51465 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
51466 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
51467 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
51468 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
51469 }
51470 });
51471
51472 test('format', function (assert) {
51473 var a = [
51474 ['dddd, MMMM Do YYYY, HH:mm:ss', 'E Diel, Shkurt 14. 2010, 15:25:50'],
51475 ['ddd, HH', 'Die, 15'],
51476 ['M Mo MM MMMM MMM', '2 2. 02 Shkurt Shk'],
51477 ['YYYY YY', '2010 10'],
51478 ['D Do DD', '14 14. 14'],
51479 ['d do dddd ddd dd', '0 0. E Diel Die D'],
51480 ['DDD DDDo DDDD', '45 45. 045'],
51481 ['w wo ww', '6 6. 06'],
51482 ['h hh', '3 03'],
51483 ['H HH', '15 15'],
51484 ['m mm', '25 25'],
51485 ['s ss', '50 50'],
51486 ['a A', 'MD MD'],
51487 ['[the] DDDo [day of the year]', 'the 45. day of the year'],
51488 ['LTS', '15:25:50'],
51489 ['L', '14/02/2010'],
51490 ['LL', '14 Shkurt 2010'],
51491 ['LLL', '14 Shkurt 2010 15:25'],
51492 ['LLLL', 'E Diel, 14 Shkurt 2010 15:25'],
51493 ['l', '14/2/2010'],
51494 ['ll', '14 Shk 2010'],
51495 ['lll', '14 Shk 2010 15:25'],
51496 ['llll', 'Die, 14 Shk 2010 15:25']
51497 ],
51498 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
51499 i;
51500
51501 for (i = 0; i < a.length; i++) {
51502 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
51503 }
51504 });
51505
51506 test('meridiem', function (assert) {
51507 assert.equal(moment([2011, 2, 23, 0, 0]).format('A'), 'PD', 'before dawn');
51508 assert.equal(moment([2011, 2, 23, 12, 0]).format('A'), 'MD', 'noon');
51509 });
51510
51511 test('format ordinal', function (assert) {
51512 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
51513 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
51514 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
51515 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
51516 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
51517 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
51518 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
51519 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
51520 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
51521 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
51522
51523 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
51524 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
51525 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
51526 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
51527 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
51528 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
51529 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
51530 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
51531 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
51532 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
51533
51534 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
51535 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
51536 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
51537 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
51538 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
51539 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
51540 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
51541 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
51542 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
51543 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
51544
51545 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
51546 });
51547
51548 test('format month', function (assert) {
51549 var i,
51550 expected = 'Janar Jan_Shkurt Shk_Mars Mar_Prill Pri_Maj Maj_Qershor Qer_Korrik Kor_Gusht Gus_Shtator Sht_Tetor Tet_Nëntor Nën_Dhjetor Dhj'.split('_');
51551
51552 for (i = 0; i < expected.length; i++) {
51553 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
51554 }
51555 });
51556
51557 test('format week', function (assert) {
51558 var i,
51559 expected = 'E Diel Die D_E Hënë Hën H_E Martë Mar Ma_E Mërkurë Mër Më_E Enjte Enj E_E Premte Pre P_E Shtunë Sht Sh'.split('_');
51560
51561 for (i = 0; i < expected.length; i++) {
51562 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
51563 }
51564 });
51565
51566 test('from', function (assert) {
51567 var start = moment([2007, 1, 28]);
51568
51569 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'disa sekonda', '44 seconds = a few seconds');
51570 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'një minutë', '45 seconds = a minute');
51571 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'një minutë', '89 seconds = a minute');
51572 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuta', '90 seconds = 2 minutes');
51573 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuta', '44 minutes = 44 minutes');
51574 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'një orë', '45 minutes = an hour');
51575 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'një orë', '89 minutes = an hour');
51576 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 orë', '90 minutes = 2 hours');
51577 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 orë', '5 hours = 5 hours');
51578 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 orë', '21 hours = 21 hours');
51579 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'një ditë', '22 hours = a day');
51580 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'një ditë', '35 hours = a day');
51581 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 ditë', '36 hours = 2 days');
51582 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'një ditë', '1 day = a day');
51583 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ditë', '5 days = 5 days');
51584 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ditë', '25 days = 25 days');
51585 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'një muaj', '26 days = a month');
51586 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'një muaj', '30 days = a month');
51587 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'një muaj', '43 days = a month');
51588 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 muaj', '46 days = 2 months');
51589 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 muaj', '75 days = 2 months');
51590 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 muaj', '76 days = 3 months');
51591 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'një muaj', '1 month = a month');
51592 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 muaj', '5 months = 5 months');
51593 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'një vit', '345 days = a year');
51594 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 vite', '548 days = 2 years');
51595 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'një vit', '1 year = a year');
51596 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 vite', '5 years = 5 years');
51597 });
73f3c911 51598
db71a655
KM
51599 test('suffix', function (assert) {
51600 assert.equal(moment(30000).from(0), 'në disa sekonda', 'prefix');
51601 assert.equal(moment(0).from(30000), 'disa sekonda më parë', 'suffix');
73f3c911
IC
51602 });
51603
db71a655
KM
51604 test('now from now', function (assert) {
51605 assert.equal(moment().fromNow(), 'disa sekonda më parë', 'now from now should display as in the past');
51606 });
51607
51608 test('fromNow', function (assert) {
51609 assert.equal(moment().add({s: 30}).fromNow(), 'në disa sekonda', 'in a few seconds');
51610 assert.equal(moment().add({d: 5}).fromNow(), 'në 5 ditë', 'in 5 days');
51611 });
51612
51613 test('calendar day', function (assert) {
51614 var a = moment().hours(12).minutes(0).seconds(0);
51615
51616 assert.equal(moment(a).calendar(), 'Sot në 12:00', 'today at the same time');
51617 assert.equal(moment(a).add({m: 25}).calendar(), 'Sot në 12:25', 'Now plus 25 min');
51618 assert.equal(moment(a).add({h: 1}).calendar(), 'Sot në 13:00', 'Now plus 1 hour');
51619 assert.equal(moment(a).add({d: 1}).calendar(), 'Nesër në 12:00', 'tomorrow at the same time');
51620 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Sot në 11:00', 'Now minus 1 hour');
51621 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Dje në 12:00', 'yesterday at the same time');
73f3c911 51622 });
b135bf1a 51623
db71a655
KM
51624 test('calendar next week', function (assert) {
51625 var i, m;
51626
51627 for (i = 2; i < 7; i++) {
51628 m = moment().add({d: i});
51629 assert.equal(m.calendar(), m.format('dddd [në] LT'), 'Today + ' + i + ' days current time');
51630 m.hours(0).minutes(0).seconds(0).milliseconds(0);
51631 assert.equal(m.calendar(), m.format('dddd [në] LT'), 'Today + ' + i + ' days beginning of day');
51632 m.hours(23).minutes(59).seconds(59).milliseconds(999);
51633 assert.equal(m.calendar(), m.format('dddd [në] LT'), 'Today + ' + i + ' days end of day');
73f3c911
IC
51634 }
51635 });
b135bf1a 51636
db71a655 51637 test('calendar last week', function (assert) {
73f3c911 51638 var i, m;
b135bf1a 51639
db71a655
KM
51640 for (i = 2; i < 7; i++) {
51641 m = moment().subtract({d: i});
51642 assert.equal(m.calendar(), m.format('dddd [e kaluar në] LT'), 'Today - ' + i + ' days current time');
51643 m.hours(0).minutes(0).seconds(0).milliseconds(0);
51644 assert.equal(m.calendar(), m.format('dddd [e kaluar në] LT'), 'Today - ' + i + ' days beginning of day');
51645 m.hours(23).minutes(59).seconds(59).milliseconds(999);
51646 assert.equal(m.calendar(), m.format('dddd [e kaluar në] LT'), 'Today - ' + i + ' days end of day');
73f3c911 51647 }
db71a655 51648 });
b135bf1a 51649
db71a655
KM
51650 test('calendar all else', function (assert) {
51651 var weeksAgo = moment().subtract({w: 1}),
51652 weeksFromNow = moment().add({w: 1});
d6651c21 51653
db71a655
KM
51654 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
51655 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
51656
51657 weeksAgo = moment().subtract({w: 2});
51658 weeksFromNow = moment().add({w: 2});
51659
51660 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
51661 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
73f3c911 51662 });
d6651c21 51663
db71a655
KM
51664 test('weeks year starting sunday formatted', function (assert) {
51665 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
51666 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
51667 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
51668 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
51669 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
51670 });
d6651c21 51671
db71a655 51672})));
d6651c21 51673
516f5f67 51674
db71a655
KM
51675;(function (global, factory) {
51676 typeof exports === 'object' && typeof module !== 'undefined'
51677 && typeof require === 'function' ? factory(require('../../moment')) :
51678 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
51679 factory(global.moment)
51680}(this, (function (moment) { 'use strict';
c74a101d 51681
db71a655
KM
51682 function each(array, callback) {
51683 var i;
51684 for (i = 0; i < array.length; i++) {
51685 callback(array[i], i, array);
73f3c911 51686 }
516f5f67
IC
51687 }
51688
c58511b9
KM
51689 function setupDeprecationHandler(test, moment$$1, scope) {
51690 test._expectedDeprecations = null;
51691 test._observedDeprecations = null;
51692 test._oldSupress = moment$$1.suppressDeprecationWarnings;
51693 moment$$1.suppressDeprecationWarnings = true;
51694 test.expectedDeprecations = function () {
51695 test._expectedDeprecations = arguments;
51696 test._observedDeprecations = [];
51697 };
51698 moment$$1.deprecationHandler = function (name, msg) {
51699 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
51700 if (deprecationId === -1) {
51701 throw new Error('Unexpected deprecation thrown name=' +
51702 name + ' msg=' + msg);
51703 }
51704 test._observedDeprecations[deprecationId] = 1;
51705 };
51706 }
51707
51708 function teardownDeprecationHandler(test, moment$$1, scope) {
51709 moment$$1.suppressDeprecationWarnings = test._oldSupress;
51710
51711 if (test._expectedDeprecations != null) {
51712 var missedDeprecations = [];
51713 each(test._expectedDeprecations, function (deprecationPattern, id) {
51714 if (test._observedDeprecations[id] !== 1) {
51715 missedDeprecations.push(deprecationPattern);
51716 }
51717 });
51718 if (missedDeprecations.length !== 0) {
51719 throw new Error('Expected deprecation warnings did not happen: ' +
51720 missedDeprecations.join(' '));
51721 }
51722 }
51723 }
51724
51725 function matchedDeprecation(name, msg, deprecations) {
51726 if (deprecations == null) {
51727 return -1;
51728 }
51729 for (var i = 0; i < deprecations.length; ++i) {
51730 if (name != null && name === deprecations[i]) {
51731 return i;
51732 }
51733 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
51734 return i;
51735 }
51736 }
51737 return -1;
51738 }
51739
51740 /*global QUnit:false*/
51741
51742 var test = QUnit.test;
51743
db71a655
KM
51744 function objectKeys(obj) {
51745 if (Object.keys) {
51746 return Object.keys(obj);
51747 } else {
51748 // IE8
51749 var res = [], i;
51750 for (i in obj) {
51751 if (obj.hasOwnProperty(i)) {
51752 res.push(i);
51753 }
51754 }
51755 return res;
516f5f67 51756 }
73f3c911 51757 }
516f5f67 51758
db71a655 51759 // Pick the first defined of two or three arguments.
516f5f67 51760
db71a655
KM
51761 function defineCommonLocaleTests(locale, options) {
51762 test('lenient day of month ordinal parsing', function (assert) {
51763 var i, ordinalStr, testMoment;
51764 for (i = 1; i <= 31; ++i) {
51765 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
51766 testMoment = moment(ordinalStr, 'YYYY MM Do');
51767 assert.equal(testMoment.year(), 2014,
51768 'lenient day of month ordinal parsing ' + i + ' year check');
51769 assert.equal(testMoment.month(), 0,
51770 'lenient day of month ordinal parsing ' + i + ' month check');
51771 assert.equal(testMoment.date(), i,
51772 'lenient day of month ordinal parsing ' + i + ' date check');
51773 }
51774 });
516f5f67 51775
db71a655
KM
51776 test('lenient day of month ordinal parsing of number', function (assert) {
51777 var i, testMoment;
51778 for (i = 1; i <= 31; ++i) {
51779 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
51780 assert.equal(testMoment.year(), 2014,
51781 'lenient day of month ordinal parsing of number ' + i + ' year check');
51782 assert.equal(testMoment.month(), 0,
51783 'lenient day of month ordinal parsing of number ' + i + ' month check');
51784 assert.equal(testMoment.date(), i,
51785 'lenient day of month ordinal parsing of number ' + i + ' date check');
51786 }
51787 });
c74a101d 51788
db71a655
KM
51789 test('strict day of month ordinal parsing', function (assert) {
51790 var i, ordinalStr, testMoment;
51791 for (i = 1; i <= 31; ++i) {
51792 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
51793 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
51794 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
73f3c911 51795 }
db71a655 51796 });
73f3c911 51797
db71a655
KM
51798 test('meridiem invariant', function (assert) {
51799 var h, m, t1, t2;
51800 for (h = 0; h < 24; ++h) {
51801 for (m = 0; m < 60; m += 15) {
51802 t1 = moment.utc([2000, 0, 1, h, m]);
51803 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
51804 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
51805 'meridiem at ' + t1.format('HH:mm'));
51806 }
51807 }
51808 });
51809
51810 test('date format correctness', function (assert) {
51811 var data, tokens;
51812 data = moment.localeData()._longDateFormat;
51813 tokens = objectKeys(data);
51814 each(tokens, function (srchToken) {
51815 // Check each format string to make sure it does not contain any
51816 // tokens that need to be expanded.
51817 each(tokens, function (baseToken) {
51818 // strip escaped sequences
51819 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
51820 assert.equal(false, !!~format.indexOf(srchToken),
51821 'contains ' + srchToken + ' in ' + baseToken);
51822 });
51823 });
51824 });
516f5f67 51825
db71a655
KM
51826 test('month parsing correctness', function (assert) {
51827 var i, m;
51828
51829 if (locale === 'tr') {
51830 // I can't fix it :(
c58511b9 51831 assert.expect(0);
db71a655
KM
51832 return;
51833 }
51834 function tester(format) {
51835 var r;
51836 r = moment(m.format(format), format);
51837 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
51838 if (locale !== 'ka') {
51839 r = moment(m.format(format).toLocaleUpperCase(), format);
51840 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
51841 }
db71a655
KM
51842 r = moment(m.format(format).toLocaleLowerCase(), format);
51843 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
51844
51845 r = moment(m.format(format), format, true);
51846 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
51847 if (locale !== 'ka') {
51848 r = moment(m.format(format).toLocaleUpperCase(), format, true);
51849 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
51850 }
db71a655
KM
51851 r = moment(m.format(format).toLocaleLowerCase(), format, true);
51852 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
51853 }
51854
51855 for (i = 0; i < 12; ++i) {
51856 m = moment([2015, i, 15, 18]);
51857 tester('MMM');
51858 tester('MMM.');
51859 tester('MMMM');
51860 tester('MMMM.');
51861 }
51862 });
516f5f67 51863
db71a655
KM
51864 test('weekday parsing correctness', function (assert) {
51865 var i, m;
51866
96d0d679 51867 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
51868 // tr, az: There is a lower-case letter (ı), that converted to
51869 // upper then lower changes to i
51870 // ro: there is the letter ț which behaves weird under IE8
51871 // mt: letter Ħ
96d0d679 51872 // ga: month with spaces
c58511b9 51873 assert.expect(0);
db71a655
KM
51874 return;
51875 }
51876 function tester(format) {
51877 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
51878 r = moment(m.format(format), format);
51879 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
51880 if (locale !== 'ka') {
51881 r = moment(m.format(format).toLocaleUpperCase(), format);
51882 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
51883 }
db71a655
KM
51884 r = moment(m.format(format).toLocaleLowerCase(), format);
51885 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
51886 r = moment(m.format(format), format, true);
51887 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
51888 if (locale !== 'ka') {
51889 r = moment(m.format(format).toLocaleUpperCase(), format, true);
51890 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
51891 }
db71a655
KM
51892 r = moment(m.format(format).toLocaleLowerCase(), format, true);
51893 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
51894 }
51895
51896 for (i = 0; i < 7; ++i) {
51897 m = moment.utc([2015, 0, i + 1, 18]);
51898 tester('dd');
51899 tester('ddd');
51900 tester('dddd');
51901 }
51902 });
b135bf1a 51903
db71a655
KM
51904 test('valid localeData', function (assert) {
51905 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
51906 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
51907 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
51908 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
51909 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
51910 });
96d0d679
KM
51911
51912 test('localeData weekdays can localeSort', function (assert) {
51913 var weekdays = moment().localeData().weekdays();
51914 var weekdaysShort = moment().localeData().weekdaysShort();
51915 var weekdaysMin = moment().localeData().weekdaysMin();
51916 var shift = moment().localeData()._week.dow;
51917 assert.deepEqual(
51918 moment().localeData().weekdays(true),
51919 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
51920 'weekdays should localeSort');
51921 assert.deepEqual(
51922 moment().localeData().weekdaysShort(true),
51923 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
51924 'weekdaysShort should localeSort');
51925 assert.deepEqual(
51926 moment().localeData().weekdaysMin(true),
51927 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
51928 'weekdaysMin should localeSort');
51929 });
b135bf1a 51930 }
516f5f67 51931
db71a655 51932 /*global QUnit:false*/
d6651c21 51933
db71a655
KM
51934 function localeModule (name, lifecycle) {
51935 QUnit.module('locale:' + name, {
c58511b9 51936 beforeEach : function () {
db71a655
KM
51937 moment.locale(name);
51938 moment.createFromInputFallback = function (config) {
51939 throw new Error('input not handled by moment: ' + config._i);
51940 };
51941 setupDeprecationHandler(test, moment, 'locale');
51942 if (lifecycle && lifecycle.setup) {
51943 lifecycle.setup();
51944 }
51945 },
c58511b9 51946 afterEach : function () {
db71a655
KM
51947 moment.locale('en');
51948 teardownDeprecationHandler(test, moment, 'locale');
51949 if (lifecycle && lifecycle.teardown) {
51950 lifecycle.teardown();
51951 }
51952 }
51953 });
51954 defineCommonLocaleTests(name, -1, -1);
51955 }
51956
51957 localeModule('sr-cyrl');
51958
51959 test('parse', function (assert) {
51960 var tests = 'јануар јан._фебруар феб._март мар._април апр._мај мај_јун јун_јул јул_август авг._септембар сеп._октобар окт._новембар нов._децембар дец.'.split('_'),
51961 i;
51962 function equalTest(input, mmm, i) {
51963 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
51964 }
51965 for (i = 0; i < 12; i++) {
51966 tests[i] = tests[i].split(' ');
51967 equalTest(tests[i][0], 'MMM', i);
51968 equalTest(tests[i][1], 'MMM', i);
51969 equalTest(tests[i][0], 'MMMM', i);
51970 equalTest(tests[i][1], 'MMMM', i);
51971 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
51972 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
51973 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
51974 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
51975 }
51976 });
51977
51978 test('format', function (assert) {
51979 var a = [
51980 ['dddd, Do MMMM YYYY, h:mm:ss a', 'недеља, 14. фебруар 2010, 3:25:50 pm'],
51981 ['ddd, hA', 'нед., 3PM'],
51982 ['M Mo MM MMMM MMM', '2 2. 02 фебруар феб.'],
51983 ['YYYY YY', '2010 10'],
51984 ['D Do DD', '14 14. 14'],
51985 ['d do dddd ddd dd', '0 0. недеља нед. не'],
51986 ['DDD DDDo DDDD', '45 45. 045'],
51987 ['w wo ww', '7 7. 07'],
51988 ['h hh', '3 03'],
51989 ['H HH', '15 15'],
51990 ['m mm', '25 25'],
51991 ['s ss', '50 50'],
51992 ['a A', 'pm PM'],
51993 ['[the] DDDo [day of the year]', 'the 45. day of the year'],
51994 ['LTS', '15:25:50'],
51995 ['L', '14.02.2010'],
51996 ['LL', '14. фебруар 2010'],
51997 ['LLL', '14. фебруар 2010 15:25'],
51998 ['LLLL', 'недеља, 14. фебруар 2010 15:25'],
51999 ['l', '14.2.2010'],
52000 ['ll', '14. феб. 2010'],
52001 ['lll', '14. феб. 2010 15:25'],
52002 ['llll', 'нед., 14. феб. 2010 15:25']
52003 ],
52004 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
52005 i;
52006 for (i = 0; i < a.length; i++) {
52007 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
52008 }
52009 });
52010
52011 test('format ordinal', function (assert) {
52012 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
52013 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
52014 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
52015 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
52016 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
52017 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
52018 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
52019 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
52020 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
52021 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
52022
52023 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
52024 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
52025 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
52026 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
52027 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
52028 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
52029 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
52030 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
52031 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
52032 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
52033
52034 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
52035 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
52036 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
52037 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
52038 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
52039 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
52040 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
52041 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
52042 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
52043 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
52044
52045 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
52046 });
52047
52048 test('format month', function (assert) {
52049 var expected = 'јануар јан._фебруар феб._март мар._април апр._мај мај_јун јун_јул јул_август авг._септембар сеп._октобар окт._новембар нов._децембар дец.'.split('_'),
52050 i;
52051 for (i = 0; i < expected.length; i++) {
52052 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
52053 }
52054 });
52055
52056 test('format week', function (assert) {
52057 var expected = 'недеља нед. не_понедељак пон. по_уторак уто. ут_среда сре. ср_четвртак чет. че_петак пет. пе_субота суб. су'.split('_'),
52058 i;
52059 for (i = 0; i < expected.length; i++) {
52060 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
52061 }
52062 });
52063
52064 test('from', function (assert) {
52065 var start = moment([2007, 1, 28]);
52066 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'неколико секунди', '44 seconds = a few seconds');
52067 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'један минут', '45 seconds = a minute');
52068 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'један минут', '89 seconds = a minute');
52069 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 минуте', '90 seconds = 2 minutes');
52070 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 минута', '44 minutes = 44 minutes');
52071 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'један сат', '45 minutes = an hour');
52072 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'један сат', '89 minutes = an hour');
52073 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 сата', '90 minutes = 2 hours');
52074 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 сати', '5 hours = 5 hours');
52075 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 сати', '21 hours = 21 hours');
52076 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'дан', '22 hours = a day');
52077 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'дан', '35 hours = a day');
52078 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 дана', '36 hours = 2 days');
52079 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'дан', '1 day = a day');
52080 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 дана', '5 days = 5 days');
52081 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 дана', '25 days = 25 days');
52082 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'месец', '26 days = a month');
52083 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'месец', '30 days = a month');
52084 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'месец', '43 days = a month');
52085 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 месеца', '46 days = 2 months');
52086 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 месеца', '75 days = 2 months');
52087 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 месеца', '76 days = 3 months');
52088 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'месец', '1 month = a month');
52089 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 месеци', '5 months = 5 months');
52090 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'годину', '345 days = a year');
52091 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 године', '548 days = 2 years');
52092 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'годину', '1 year = a year');
52093 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 година', '5 years = 5 years');
52094 });
52095
52096 test('suffix', function (assert) {
52097 assert.equal(moment(30000).from(0), 'за неколико секунди', 'prefix');
52098 assert.equal(moment(0).from(30000), 'пре неколико секунди', 'prefix');
52099 });
52100
52101 test('now from now', function (assert) {
52102 assert.equal(moment().fromNow(), 'пре неколико секунди', 'now from now should display as in the past');
52103 });
52104
52105 test('fromNow', function (assert) {
52106 assert.equal(moment().add({s: 30}).fromNow(), 'за неколико секунди', 'in a few seconds');
52107 assert.equal(moment().add({d: 5}).fromNow(), 'за 5 дана', 'in 5 days');
52108 });
52109
52110 test('calendar day', function (assert) {
52111 var a = moment().hours(12).minutes(0).seconds(0);
52112
52113 assert.equal(moment(a).calendar(), 'данас у 12:00', 'today at the same time');
52114 assert.equal(moment(a).add({m: 25}).calendar(), 'данас у 12:25', 'Now plus 25 min');
52115 assert.equal(moment(a).add({h: 1}).calendar(), 'данас у 13:00', 'Now plus 1 hour');
52116 assert.equal(moment(a).add({d: 1}).calendar(), 'сутра у 12:00', 'tomorrow at the same time');
52117 assert.equal(moment(a).subtract({h: 1}).calendar(), 'данас у 11:00', 'Now minus 1 hour');
52118 assert.equal(moment(a).subtract({d: 1}).calendar(), 'јуче у 12:00', 'yesterday at the same time');
52119 });
52120
52121 test('calendar next week', function (assert) {
52122 var i, m;
d6651c21 52123
db71a655
KM
52124 function makeFormat(d) {
52125 switch (d.day()) {
52126 case 0:
52127 return '[у] [недељу] [у] LT';
52128 case 3:
52129 return '[у] [среду] [у] LT';
52130 case 6:
52131 return '[у] [суботу] [у] LT';
52132 case 1:
52133 case 2:
52134 case 4:
52135 case 5:
52136 return '[у] dddd [у] LT';
52137 }
73f3c911 52138 }
d6651c21 52139
db71a655
KM
52140 for (i = 2; i < 7; i++) {
52141 m = moment().add({d: i});
52142 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time');
52143 m.hours(0).minutes(0).seconds(0).milliseconds(0);
52144 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day');
52145 m.hours(23).minutes(59).seconds(59).milliseconds(999);
52146 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day');
d6651c21 52147 }
73f3c911 52148 });
d6651c21 52149
db71a655 52150 test('calendar last week', function (assert) {
73f3c911
IC
52151 var i, m;
52152
db71a655
KM
52153 function makeFormat(d) {
52154 var lastWeekDay = [
52155 '[прошле] [недеље] [у] LT',
52156 '[прошлог] [понедељка] [у] LT',
52157 '[прошлог] [уторка] [у] LT',
52158 '[прошле] [среде] [у] LT',
52159 '[прошлог] [четвртка] [у] LT',
52160 '[прошлог] [петка] [у] LT',
52161 '[прошле] [суботе] [у] LT'
52162 ];
516f5f67 52163
db71a655 52164 return lastWeekDay[d.day()];
73f3c911 52165 }
516f5f67 52166
db71a655
KM
52167 for (i = 2; i < 7; i++) {
52168 m = moment().subtract({d: i});
52169 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time');
52170 m.hours(0).minutes(0).seconds(0).milliseconds(0);
52171 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day');
52172 m.hours(23).minutes(59).seconds(59).milliseconds(999);
52173 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day');
73f3c911 52174 }
db71a655 52175 });
516f5f67 52176
db71a655
KM
52177 test('calendar all else', function (assert) {
52178 var weeksAgo = moment().subtract({w: 1}),
52179 weeksFromNow = moment().add({w: 1});
516f5f67 52180
db71a655
KM
52181 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
52182 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 52183
db71a655
KM
52184 weeksAgo = moment().subtract({w: 2});
52185 weeksFromNow = moment().add({w: 2});
516f5f67 52186
db71a655
KM
52187 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
52188 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
52189 });
516f5f67 52190
db71a655
KM
52191 test('weeks year starting sunday formatted', function (assert) {
52192 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', 'Dec 26 2011 should be week 1');
52193 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1.', 'Jan 1 2012 should be week 1');
52194 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2.', 'Jan 2 2012 should be week 2');
52195 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2.', 'Jan 8 2012 should be week 2');
52196 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3.', 'Jan 9 2012 should be week 3');
52197 });
73f3c911
IC
52198
52199})));
516f5f67 52200
516f5f67 52201
c74a101d
IC
52202;(function (global, factory) {
52203 typeof exports === 'object' && typeof module !== 'undefined'
52204 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
52205 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
52206 factory(global.moment)
73f3c911 52207}(this, (function (moment) { 'use strict';
516f5f67 52208
db71a655
KM
52209 function each(array, callback) {
52210 var i;
52211 for (i = 0; i < array.length; i++) {
52212 callback(array[i], i, array);
52213 }
b135bf1a
IC
52214 }
52215
db71a655
KM
52216 function setupDeprecationHandler(test, moment$$1, scope) {
52217 test._expectedDeprecations = null;
52218 test._observedDeprecations = null;
52219 test._oldSupress = moment$$1.suppressDeprecationWarnings;
52220 moment$$1.suppressDeprecationWarnings = true;
52221 test.expectedDeprecations = function () {
52222 test._expectedDeprecations = arguments;
52223 test._observedDeprecations = [];
52224 };
52225 moment$$1.deprecationHandler = function (name, msg) {
52226 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
52227 if (deprecationId === -1) {
52228 throw new Error('Unexpected deprecation thrown name=' +
52229 name + ' msg=' + msg);
52230 }
52231 test._observedDeprecations[deprecationId] = 1;
52232 };
52233 }
d6651c21 52234
db71a655
KM
52235 function teardownDeprecationHandler(test, moment$$1, scope) {
52236 moment$$1.suppressDeprecationWarnings = test._oldSupress;
d6651c21 52237
db71a655
KM
52238 if (test._expectedDeprecations != null) {
52239 var missedDeprecations = [];
52240 each(test._expectedDeprecations, function (deprecationPattern, id) {
52241 if (test._observedDeprecations[id] !== 1) {
52242 missedDeprecations.push(deprecationPattern);
52243 }
52244 });
52245 if (missedDeprecations.length !== 0) {
52246 throw new Error('Expected deprecation warnings did not happen: ' +
52247 missedDeprecations.join(' '));
52248 }
73f3c911 52249 }
db71a655 52250 }
d6651c21 52251
db71a655
KM
52252 function matchedDeprecation(name, msg, deprecations) {
52253 if (deprecations == null) {
52254 return -1;
d6651c21 52255 }
db71a655
KM
52256 for (var i = 0; i < deprecations.length; ++i) {
52257 if (name != null && name === deprecations[i]) {
52258 return i;
52259 }
52260 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
52261 return i;
52262 }
52263 }
52264 return -1;
52265 }
73f3c911 52266
db71a655 52267 /*global QUnit:false*/
73f3c911 52268
db71a655
KM
52269 var test = QUnit.test;
52270
c58511b9
KM
52271 function objectKeys(obj) {
52272 if (Object.keys) {
52273 return Object.keys(obj);
52274 } else {
52275 // IE8
52276 var res = [], i;
52277 for (i in obj) {
52278 if (obj.hasOwnProperty(i)) {
52279 res.push(i);
52280 }
52281 }
52282 return res;
52283 }
52284 }
52285
52286 // Pick the first defined of two or three arguments.
52287
52288 function defineCommonLocaleTests(locale, options) {
52289 test('lenient day of month ordinal parsing', function (assert) {
52290 var i, ordinalStr, testMoment;
52291 for (i = 1; i <= 31; ++i) {
52292 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
52293 testMoment = moment(ordinalStr, 'YYYY MM Do');
52294 assert.equal(testMoment.year(), 2014,
52295 'lenient day of month ordinal parsing ' + i + ' year check');
52296 assert.equal(testMoment.month(), 0,
52297 'lenient day of month ordinal parsing ' + i + ' month check');
52298 assert.equal(testMoment.date(), i,
52299 'lenient day of month ordinal parsing ' + i + ' date check');
52300 }
52301 });
52302
52303 test('lenient day of month ordinal parsing of number', function (assert) {
52304 var i, testMoment;
52305 for (i = 1; i <= 31; ++i) {
52306 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
52307 assert.equal(testMoment.year(), 2014,
52308 'lenient day of month ordinal parsing of number ' + i + ' year check');
52309 assert.equal(testMoment.month(), 0,
52310 'lenient day of month ordinal parsing of number ' + i + ' month check');
52311 assert.equal(testMoment.date(), i,
52312 'lenient day of month ordinal parsing of number ' + i + ' date check');
52313 }
52314 });
52315
52316 test('strict day of month ordinal parsing', function (assert) {
52317 var i, ordinalStr, testMoment;
52318 for (i = 1; i <= 31; ++i) {
52319 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
52320 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
52321 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
52322 }
52323 });
52324
52325 test('meridiem invariant', function (assert) {
52326 var h, m, t1, t2;
52327 for (h = 0; h < 24; ++h) {
52328 for (m = 0; m < 60; m += 15) {
52329 t1 = moment.utc([2000, 0, 1, h, m]);
52330 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
52331 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
52332 'meridiem at ' + t1.format('HH:mm'));
52333 }
52334 }
52335 });
52336
52337 test('date format correctness', function (assert) {
52338 var data, tokens;
52339 data = moment.localeData()._longDateFormat;
52340 tokens = objectKeys(data);
52341 each(tokens, function (srchToken) {
52342 // Check each format string to make sure it does not contain any
52343 // tokens that need to be expanded.
52344 each(tokens, function (baseToken) {
52345 // strip escaped sequences
52346 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
52347 assert.equal(false, !!~format.indexOf(srchToken),
52348 'contains ' + srchToken + ' in ' + baseToken);
52349 });
52350 });
52351 });
52352
52353 test('month parsing correctness', function (assert) {
52354 var i, m;
52355
52356 if (locale === 'tr') {
52357 // I can't fix it :(
52358 assert.expect(0);
52359 return;
52360 }
52361 function tester(format) {
52362 var r;
52363 r = moment(m.format(format), format);
52364 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
52365 if (locale !== 'ka') {
52366 r = moment(m.format(format).toLocaleUpperCase(), format);
52367 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
52368 }
c58511b9
KM
52369 r = moment(m.format(format).toLocaleLowerCase(), format);
52370 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
52371
52372 r = moment(m.format(format), format, true);
52373 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
52374 if (locale !== 'ka') {
52375 r = moment(m.format(format).toLocaleUpperCase(), format, true);
52376 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
52377 }
c58511b9
KM
52378 r = moment(m.format(format).toLocaleLowerCase(), format, true);
52379 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
52380 }
52381
52382 for (i = 0; i < 12; ++i) {
52383 m = moment([2015, i, 15, 18]);
52384 tester('MMM');
52385 tester('MMM.');
52386 tester('MMMM');
52387 tester('MMMM.');
52388 }
52389 });
52390
52391 test('weekday parsing correctness', function (assert) {
52392 var i, m;
52393
96d0d679 52394 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
c58511b9
KM
52395 // tr, az: There is a lower-case letter (ı), that converted to
52396 // upper then lower changes to i
52397 // ro: there is the letter ț which behaves weird under IE8
52398 // mt: letter Ħ
96d0d679 52399 // ga: month with spaces
c58511b9
KM
52400 assert.expect(0);
52401 return;
52402 }
52403 function tester(format) {
52404 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
52405 r = moment(m.format(format), format);
52406 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
52407 if (locale !== 'ka') {
52408 r = moment(m.format(format).toLocaleUpperCase(), format);
52409 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
52410 }
c58511b9
KM
52411 r = moment(m.format(format).toLocaleLowerCase(), format);
52412 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
52413 r = moment(m.format(format), format, true);
52414 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
52415 if (locale !== 'ka') {
52416 r = moment(m.format(format).toLocaleUpperCase(), format, true);
52417 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
52418 }
c58511b9
KM
52419 r = moment(m.format(format).toLocaleLowerCase(), format, true);
52420 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
52421 }
52422
52423 for (i = 0; i < 7; ++i) {
52424 m = moment.utc([2015, 0, i + 1, 18]);
52425 tester('dd');
52426 tester('ddd');
52427 tester('dddd');
52428 }
52429 });
52430
52431 test('valid localeData', function (assert) {
52432 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
52433 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
52434 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
52435 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
52436 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
52437 });
96d0d679
KM
52438
52439 test('localeData weekdays can localeSort', function (assert) {
52440 var weekdays = moment().localeData().weekdays();
52441 var weekdaysShort = moment().localeData().weekdaysShort();
52442 var weekdaysMin = moment().localeData().weekdaysMin();
52443 var shift = moment().localeData()._week.dow;
52444 assert.deepEqual(
52445 moment().localeData().weekdays(true),
52446 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
52447 'weekdays should localeSort');
52448 assert.deepEqual(
52449 moment().localeData().weekdaysShort(true),
52450 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
52451 'weekdaysShort should localeSort');
52452 assert.deepEqual(
52453 moment().localeData().weekdaysMin(true),
52454 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
52455 'weekdaysMin should localeSort');
52456 });
c58511b9
KM
52457 }
52458
52459 /*global QUnit:false*/
db71a655
KM
52460
52461 function localeModule (name, lifecycle) {
52462 QUnit.module('locale:' + name, {
c58511b9 52463 beforeEach : function () {
db71a655
KM
52464 moment.locale(name);
52465 moment.createFromInputFallback = function (config) {
52466 throw new Error('input not handled by moment: ' + config._i);
52467 };
52468 setupDeprecationHandler(test, moment, 'locale');
52469 if (lifecycle && lifecycle.setup) {
52470 lifecycle.setup();
52471 }
52472 },
c58511b9 52473 afterEach : function () {
db71a655
KM
52474 moment.locale('en');
52475 teardownDeprecationHandler(test, moment, 'locale');
52476 if (lifecycle && lifecycle.teardown) {
52477 lifecycle.teardown();
52478 }
d6651c21 52479 }
73f3c911 52480 });
db71a655
KM
52481 defineCommonLocaleTests(name, -1, -1);
52482 }
52483
52484 localeModule('sr');
52485
52486 test('parse', function (assert) {
52487 var tests = 'januar jan._februar feb._mart mar._april apr._maj maj_jun jun_jul jul_avgust avg._septembar sep._oktobar okt._novembar nov._decembar dec.'.split('_'),
52488 i;
52489 function equalTest(input, mmm, i) {
52490 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
52491 }
52492 for (i = 0; i < 12; i++) {
52493 tests[i] = tests[i].split(' ');
52494 equalTest(tests[i][0], 'MMM', i);
52495 equalTest(tests[i][1], 'MMM', i);
52496 equalTest(tests[i][0], 'MMMM', i);
52497 equalTest(tests[i][1], 'MMMM', i);
52498 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
52499 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
52500 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
52501 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
52502 }
52503 });
52504
52505 test('format', function (assert) {
52506 var a = [
52507 ['dddd, Do MMMM YYYY, h:mm:ss a', 'nedelja, 14. februar 2010, 3:25:50 pm'],
52508 ['ddd, hA', 'ned., 3PM'],
52509 ['M Mo MM MMMM MMM', '2 2. 02 februar feb.'],
52510 ['YYYY YY', '2010 10'],
52511 ['D Do DD', '14 14. 14'],
52512 ['d do dddd ddd dd', '0 0. nedelja ned. ne'],
52513 ['DDD DDDo DDDD', '45 45. 045'],
52514 ['w wo ww', '7 7. 07'],
52515 ['h hh', '3 03'],
52516 ['H HH', '15 15'],
52517 ['m mm', '25 25'],
52518 ['s ss', '50 50'],
52519 ['a A', 'pm PM'],
52520 ['[the] DDDo [day of the year]', 'the 45. day of the year'],
52521 ['LTS', '15:25:50'],
52522 ['L', '14.02.2010'],
52523 ['LL', '14. februar 2010'],
52524 ['LLL', '14. februar 2010 15:25'],
52525 ['LLLL', 'nedelja, 14. februar 2010 15:25'],
52526 ['l', '14.2.2010'],
52527 ['ll', '14. feb. 2010'],
52528 ['lll', '14. feb. 2010 15:25'],
52529 ['llll', 'ned., 14. feb. 2010 15:25']
52530 ],
52531 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
52532 i;
52533 for (i = 0; i < a.length; i++) {
52534 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
52535 }
52536 });
52537
52538 test('format ordinal', function (assert) {
52539 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
52540 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
52541 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
52542 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
52543 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
52544 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
52545 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
52546 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
52547 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
52548 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
52549
52550 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
52551 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
52552 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
52553 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
52554 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
52555 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
52556 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
52557 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
52558 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
52559 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
52560
52561 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
52562 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
52563 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
52564 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
52565 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
52566 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
52567 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
52568 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
52569 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
52570 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
52571
52572 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
52573 });
52574
52575 test('format month', function (assert) {
52576 var expected = 'januar jan._februar feb._mart mar._april apr._maj maj_jun jun_jul jul_avgust avg._septembar sep._oktobar okt._novembar nov._decembar dec.'.split('_'),
52577 i;
52578 for (i = 0; i < expected.length; i++) {
52579 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
52580 }
52581 });
52582
52583 test('format week', function (assert) {
52584 var expected = 'nedelja ned. ne_ponedeljak pon. po_utorak uto. ut_sreda sre. sr_četvrtak čet. če_petak pet. pe_subota sub. su'.split('_'),
52585 i;
52586 for (i = 0; i < expected.length; i++) {
52587 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
52588 }
52589 });
52590
52591 test('from', function (assert) {
52592 var start = moment([2007, 1, 28]);
52593 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'nekoliko sekundi', '44 seconds = a few seconds');
52594 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'jedan minut', '45 seconds = a minute');
52595 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'jedan minut', '89 seconds = a minute');
52596 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minute', '90 seconds = 2 minutes');
52597 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuta', '44 minutes = 44 minutes');
52598 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'jedan sat', '45 minutes = an hour');
52599 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'jedan sat', '89 minutes = an hour');
52600 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 sata', '90 minutes = 2 hours');
52601 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 sati', '5 hours = 5 hours');
52602 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 sati', '21 hours = 21 hours');
52603 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'dan', '22 hours = a day');
52604 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'dan', '35 hours = a day');
52605 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dana', '36 hours = 2 days');
52606 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'dan', '1 day = a day');
52607 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dana', '5 days = 5 days');
52608 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dana', '25 days = 25 days');
52609 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mesec', '26 days = a month');
52610 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mesec', '30 days = a month');
52611 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mesec', '43 days = a month');
52612 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 meseca', '46 days = 2 months');
52613 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 meseca', '75 days = 2 months');
52614 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 meseca', '76 days = 3 months');
52615 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mesec', '1 month = a month');
52616 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 meseci', '5 months = 5 months');
52617 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'godinu', '345 days = a year');
52618 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 godine', '548 days = 2 years');
52619 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'godinu', '1 year = a year');
52620 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 godina', '5 years = 5 years');
52621 });
52622
52623 test('suffix', function (assert) {
52624 assert.equal(moment(30000).from(0), 'za nekoliko sekundi', 'prefix');
52625 assert.equal(moment(0).from(30000), 'pre nekoliko sekundi', 'prefix');
52626 });
52627
52628 test('now from now', function (assert) {
52629 assert.equal(moment().fromNow(), 'pre nekoliko sekundi', 'now from now should display as in the past');
52630 });
52631
52632 test('fromNow', function (assert) {
52633 assert.equal(moment().add({s: 30}).fromNow(), 'za nekoliko sekundi', 'in a few seconds');
52634 assert.equal(moment().add({d: 5}).fromNow(), 'za 5 dana', 'in 5 days');
52635 });
52636
52637 test('calendar day', function (assert) {
52638 var a = moment().hours(12).minutes(0).seconds(0);
52639
52640 assert.equal(moment(a).calendar(), 'danas u 12:00', 'today at the same time');
52641 assert.equal(moment(a).add({m: 25}).calendar(), 'danas u 12:25', 'Now plus 25 min');
52642 assert.equal(moment(a).add({h: 1}).calendar(), 'danas u 13:00', 'Now plus 1 hour');
52643 assert.equal(moment(a).add({d: 1}).calendar(), 'sutra u 12:00', 'tomorrow at the same time');
52644 assert.equal(moment(a).subtract({h: 1}).calendar(), 'danas u 11:00', 'Now minus 1 hour');
52645 assert.equal(moment(a).subtract({d: 1}).calendar(), 'juče u 12:00', 'yesterday at the same time');
52646 });
52647
52648 test('calendar next week', function (assert) {
52649 var i, m;
52650
52651 function makeFormat(d) {
52652 switch (d.day()) {
52653 case 0:
52654 return '[u] [nedelju] [u] LT';
52655 case 3:
52656 return '[u] [sredu] [u] LT';
52657 case 6:
52658 return '[u] [subotu] [u] LT';
52659 case 1:
52660 case 2:
52661 case 4:
52662 case 5:
52663 return '[u] dddd [u] LT';
52664 }
d6651c21 52665 }
73f3c911 52666
db71a655
KM
52667 for (i = 2; i < 7; i++) {
52668 m = moment().add({d: i});
52669 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time');
52670 m.hours(0).minutes(0).seconds(0).milliseconds(0);
52671 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day');
52672 m.hours(23).minutes(59).seconds(59).milliseconds(999);
52673 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day');
73f3c911 52674 }
db71a655
KM
52675 });
52676
52677 test('calendar last week', function (assert) {
52678 var i, m;
52679
52680 function makeFormat(d) {
52681 var lastWeekDay = [
52682 '[prošle] [nedelje] [u] LT',
52683 '[prošlog] [ponedeljka] [u] LT',
52684 '[prošlog] [utorka] [u] LT',
52685 '[prošle] [srede] [u] LT',
52686 '[prošlog] [četvrtka] [u] LT',
52687 '[prošlog] [petka] [u] LT',
52688 '[prošle] [subote] [u] LT'
52689 ];
52690
52691 return lastWeekDay[d.day()];
73f3c911 52692 }
b135bf1a 52693
db71a655
KM
52694 for (i = 2; i < 7; i++) {
52695 m = moment().subtract({d: i});
52696 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time');
52697 m.hours(0).minutes(0).seconds(0).milliseconds(0);
52698 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day');
52699 m.hours(23).minutes(59).seconds(59).milliseconds(999);
52700 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day');
52701 }
52702 });
516f5f67 52703
db71a655
KM
52704 test('calendar all else', function (assert) {
52705 var weeksAgo = moment().subtract({w: 1}),
52706 weeksFromNow = moment().add({w: 1});
516f5f67 52707
db71a655
KM
52708 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
52709 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
c74a101d 52710
db71a655
KM
52711 weeksAgo = moment().subtract({w: 2});
52712 weeksFromNow = moment().add({w: 2});
52713
52714 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
52715 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
52716 });
52717
52718 test('weeks year starting sunday formatted', function (assert) {
52719 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', 'Dec 26 2011 should be week 1');
52720 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1.', 'Jan 1 2012 should be week 1');
52721 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2.', 'Jan 2 2012 should be week 2');
52722 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2.', 'Jan 8 2012 should be week 2');
52723 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3.', 'Jan 9 2012 should be week 3');
52724 });
73f3c911
IC
52725
52726})));
b135bf1a 52727
b135bf1a
IC
52728
52729;(function (global, factory) {
52730 typeof exports === 'object' && typeof module !== 'undefined'
52731 && typeof require === 'function' ? factory(require('../../moment')) :
52732 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
52733 factory(global.moment)
73f3c911 52734}(this, (function (moment) { 'use strict';
b135bf1a 52735
db71a655
KM
52736 function each(array, callback) {
52737 var i;
52738 for (i = 0; i < array.length; i++) {
52739 callback(array[i], i, array);
52740 }
b135bf1a
IC
52741 }
52742
c58511b9
KM
52743 function setupDeprecationHandler(test, moment$$1, scope) {
52744 test._expectedDeprecations = null;
52745 test._observedDeprecations = null;
52746 test._oldSupress = moment$$1.suppressDeprecationWarnings;
52747 moment$$1.suppressDeprecationWarnings = true;
52748 test.expectedDeprecations = function () {
52749 test._expectedDeprecations = arguments;
52750 test._observedDeprecations = [];
52751 };
52752 moment$$1.deprecationHandler = function (name, msg) {
52753 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
52754 if (deprecationId === -1) {
52755 throw new Error('Unexpected deprecation thrown name=' +
52756 name + ' msg=' + msg);
52757 }
52758 test._observedDeprecations[deprecationId] = 1;
52759 };
52760 }
52761
52762 function teardownDeprecationHandler(test, moment$$1, scope) {
52763 moment$$1.suppressDeprecationWarnings = test._oldSupress;
52764
52765 if (test._expectedDeprecations != null) {
52766 var missedDeprecations = [];
52767 each(test._expectedDeprecations, function (deprecationPattern, id) {
52768 if (test._observedDeprecations[id] !== 1) {
52769 missedDeprecations.push(deprecationPattern);
52770 }
52771 });
52772 if (missedDeprecations.length !== 0) {
52773 throw new Error('Expected deprecation warnings did not happen: ' +
52774 missedDeprecations.join(' '));
52775 }
52776 }
52777 }
52778
52779 function matchedDeprecation(name, msg, deprecations) {
52780 if (deprecations == null) {
52781 return -1;
52782 }
52783 for (var i = 0; i < deprecations.length; ++i) {
52784 if (name != null && name === deprecations[i]) {
52785 return i;
52786 }
52787 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
52788 return i;
52789 }
52790 }
52791 return -1;
52792 }
52793
52794 /*global QUnit:false*/
52795
52796 var test = QUnit.test;
52797
db71a655
KM
52798 function objectKeys(obj) {
52799 if (Object.keys) {
52800 return Object.keys(obj);
52801 } else {
52802 // IE8
52803 var res = [], i;
52804 for (i in obj) {
52805 if (obj.hasOwnProperty(i)) {
52806 res.push(i);
52807 }
b135bf1a 52808 }
db71a655 52809 return res;
b135bf1a
IC
52810 }
52811 }
52812
db71a655 52813 // Pick the first defined of two or three arguments.
73f3c911 52814
db71a655
KM
52815 function defineCommonLocaleTests(locale, options) {
52816 test('lenient day of month ordinal parsing', function (assert) {
52817 var i, ordinalStr, testMoment;
52818 for (i = 1; i <= 31; ++i) {
52819 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
52820 testMoment = moment(ordinalStr, 'YYYY MM Do');
52821 assert.equal(testMoment.year(), 2014,
52822 'lenient day of month ordinal parsing ' + i + ' year check');
52823 assert.equal(testMoment.month(), 0,
52824 'lenient day of month ordinal parsing ' + i + ' month check');
52825 assert.equal(testMoment.date(), i,
52826 'lenient day of month ordinal parsing ' + i + ' date check');
52827 }
52828 });
b135bf1a 52829
db71a655
KM
52830 test('lenient day of month ordinal parsing of number', function (assert) {
52831 var i, testMoment;
52832 for (i = 1; i <= 31; ++i) {
52833 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
52834 assert.equal(testMoment.year(), 2014,
52835 'lenient day of month ordinal parsing of number ' + i + ' year check');
52836 assert.equal(testMoment.month(), 0,
52837 'lenient day of month ordinal parsing of number ' + i + ' month check');
52838 assert.equal(testMoment.date(), i,
52839 'lenient day of month ordinal parsing of number ' + i + ' date check');
52840 }
52841 });
b135bf1a 52842
db71a655
KM
52843 test('strict day of month ordinal parsing', function (assert) {
52844 var i, ordinalStr, testMoment;
52845 for (i = 1; i <= 31; ++i) {
52846 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
52847 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
52848 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
52849 }
52850 });
52851
52852 test('meridiem invariant', function (assert) {
52853 var h, m, t1, t2;
52854 for (h = 0; h < 24; ++h) {
52855 for (m = 0; m < 60; m += 15) {
52856 t1 = moment.utc([2000, 0, 1, h, m]);
52857 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
52858 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
52859 'meridiem at ' + t1.format('HH:mm'));
52860 }
52861 }
52862 });
52863
52864 test('date format correctness', function (assert) {
52865 var data, tokens;
52866 data = moment.localeData()._longDateFormat;
52867 tokens = objectKeys(data);
52868 each(tokens, function (srchToken) {
52869 // Check each format string to make sure it does not contain any
52870 // tokens that need to be expanded.
52871 each(tokens, function (baseToken) {
52872 // strip escaped sequences
52873 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
52874 assert.equal(false, !!~format.indexOf(srchToken),
52875 'contains ' + srchToken + ' in ' + baseToken);
52876 });
73f3c911 52877 });
b135bf1a
IC
52878 });
52879
db71a655
KM
52880 test('month parsing correctness', function (assert) {
52881 var i, m;
52882
52883 if (locale === 'tr') {
52884 // I can't fix it :(
c58511b9 52885 assert.expect(0);
db71a655
KM
52886 return;
52887 }
52888 function tester(format) {
52889 var r;
52890 r = moment(m.format(format), format);
52891 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
52892 if (locale !== 'ka') {
52893 r = moment(m.format(format).toLocaleUpperCase(), format);
52894 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
52895 }
db71a655
KM
52896 r = moment(m.format(format).toLocaleLowerCase(), format);
52897 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
52898
52899 r = moment(m.format(format), format, true);
52900 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
52901 if (locale !== 'ka') {
52902 r = moment(m.format(format).toLocaleUpperCase(), format, true);
52903 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
52904 }
db71a655
KM
52905 r = moment(m.format(format).toLocaleLowerCase(), format, true);
52906 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
52907 }
52908
52909 for (i = 0; i < 12; ++i) {
52910 m = moment([2015, i, 15, 18]);
52911 tester('MMM');
52912 tester('MMM.');
52913 tester('MMMM');
52914 tester('MMMM.');
52915 }
52916 });
b135bf1a 52917
db71a655
KM
52918 test('weekday parsing correctness', function (assert) {
52919 var i, m;
52920
96d0d679 52921 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
52922 // tr, az: There is a lower-case letter (ı), that converted to
52923 // upper then lower changes to i
52924 // ro: there is the letter ț which behaves weird under IE8
52925 // mt: letter Ħ
96d0d679 52926 // ga: month with spaces
c58511b9 52927 assert.expect(0);
db71a655
KM
52928 return;
52929 }
52930 function tester(format) {
52931 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
52932 r = moment(m.format(format), format);
52933 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
52934 if (locale !== 'ka') {
52935 r = moment(m.format(format).toLocaleUpperCase(), format);
52936 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
52937 }
db71a655
KM
52938 r = moment(m.format(format).toLocaleLowerCase(), format);
52939 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
52940 r = moment(m.format(format), format, true);
52941 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
52942 if (locale !== 'ka') {
52943 r = moment(m.format(format).toLocaleUpperCase(), format, true);
52944 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
52945 }
db71a655
KM
52946 r = moment(m.format(format).toLocaleLowerCase(), format, true);
52947 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
52948 }
52949
52950 for (i = 0; i < 7; ++i) {
52951 m = moment.utc([2015, 0, i + 1, 18]);
52952 tester('dd');
52953 tester('ddd');
52954 tester('dddd');
52955 }
52956 });
b135bf1a 52957
db71a655
KM
52958 test('valid localeData', function (assert) {
52959 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
52960 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
52961 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
52962 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
52963 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
52964 });
96d0d679
KM
52965
52966 test('localeData weekdays can localeSort', function (assert) {
52967 var weekdays = moment().localeData().weekdays();
52968 var weekdaysShort = moment().localeData().weekdaysShort();
52969 var weekdaysMin = moment().localeData().weekdaysMin();
52970 var shift = moment().localeData()._week.dow;
52971 assert.deepEqual(
52972 moment().localeData().weekdays(true),
52973 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
52974 'weekdays should localeSort');
52975 assert.deepEqual(
52976 moment().localeData().weekdaysShort(true),
52977 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
52978 'weekdaysShort should localeSort');
52979 assert.deepEqual(
52980 moment().localeData().weekdaysMin(true),
52981 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
52982 'weekdaysMin should localeSort');
52983 });
db71a655 52984 }
d6651c21 52985
db71a655 52986 /*global QUnit:false*/
73f3c911 52987
db71a655
KM
52988 function localeModule (name, lifecycle) {
52989 QUnit.module('locale:' + name, {
c58511b9 52990 beforeEach : function () {
db71a655
KM
52991 moment.locale(name);
52992 moment.createFromInputFallback = function (config) {
52993 throw new Error('input not handled by moment: ' + config._i);
52994 };
52995 setupDeprecationHandler(test, moment, 'locale');
52996 if (lifecycle && lifecycle.setup) {
52997 lifecycle.setup();
52998 }
52999 },
c58511b9 53000 afterEach : function () {
db71a655
KM
53001 moment.locale('en');
53002 teardownDeprecationHandler(test, moment, 'locale');
53003 if (lifecycle && lifecycle.teardown) {
53004 lifecycle.teardown();
53005 }
d6651c21 53006 }
73f3c911 53007 });
db71a655
KM
53008 defineCommonLocaleTests(name, -1, -1);
53009 }
53010
53011 localeModule('ss');
53012
53013 test('parse', function (assert) {
53014 var tests = "Bhimbidvwane Bhi_Indlovana Ina_Indlov'lenkhulu Inu_Mabasa Mab_Inkhwekhweti Ink_Inhlaba Inh_Kholwane Kho_Ingci Igc_Inyoni Iny_Imphala Imp_Lweti lwe_Ingongoni Igo".split('_'), i;
53015 function equalTest(input, mmm, i) {
53016 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
53017 }
53018 for (i = 0; i < 12; i++) {
53019 tests[i] = tests[i].split(' ');
53020 equalTest(tests[i][0], 'MMM', i);
53021 equalTest(tests[i][1], 'MMM', i);
53022 equalTest(tests[i][0], 'MMMM', i);
53023 equalTest(tests[i][1], 'MMMM', i);
53024 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
53025 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
53026 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
53027 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
53028 }
53029 });
53030
53031 test('parse meridiem', function (assert) {
53032 var i,
53033 b = moment(),
53034 meridiemTests = [
53035 // h a patterns, expected hours, isValid
53036 ['10 ekuseni', 10, true],
53037 ['11 emini', 11, true],
53038 ['3 entsambama', 15, true],
53039 ['4 entsambama', 16, true],
53040 ['6 entsambama', 18, true],
53041 ['7 ebusuku', 19, true],
53042 ['12 ebusuku', 0, true],
53043 ['10 am', 10, false],
53044 ['10 pm', 10, false]
53045 ],
53046 parsed;
53047
53048 // test that a formatted moment including meridiem string can be parsed back to the same moment
53049 assert.ok(b.isSame(moment(b.format('h:mm:ss a'), 'h:mm:ss a', 'ss', true), 'seconds'), b.format('h:mm:ss a') + ' should be equal to ' + moment(b.format('h:mm:ss a'), 'h:mm:ss a', 'ss', true).format('h:mm:ss a'));
53050
53051 // test that a formatted moment having a meridiem string can be parsed with strict flag
53052 assert.ok(moment(b.format('h:mm:ss a'), 'h:mm:ss a', 'ss', true).isValid(), b.format('h:mm:ss a') + ' should be parsed as valid');
53053
53054 for (i = 0; i < meridiemTests.length; i++) {
53055 parsed = moment(meridiemTests[i][0], 'h a', 'ss', true);
53056 assert.equal(parsed.isValid(), meridiemTests[i][2], 'validity for ' + meridiemTests[i][0]);
53057 if (parsed.isValid()) {
53058 assert.equal(parsed.hours(), meridiemTests[i][1], 'hours for ' + meridiemTests[i][0]);
53059 }
53060 }
53061 });
53062
53063 test('format', function (assert) {
53064 var a = [
53065 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Lisontfo, Indlovana 14 2010, 3:25:50 entsambama'],
53066 ['ddd, h A', 'Lis, 3 entsambama'],
53067 ['M Mo MM MMMM MMM', '2 2 02 Indlovana Ina'],
53068 ['YYYY YY', '2010 10'],
53069 ['D Do DD', '14 14 14'],
53070 ['d do dddd ddd dd', '0 0 Lisontfo Lis Li'],
53071 ['DDD DDDo DDDD', '45 45 045'],
53072 ['w wo ww', '6 6 06'],
53073 ['h hh', '3 03'],
53074 ['H HH', '15 15'],
53075 ['m mm', '25 25'],
53076 ['s ss', '50 50'],
53077 ['a A', 'entsambama entsambama'],
53078 ['[Lilanga] DDDo [lilanga lelinyaka]', 'Lilanga 45 lilanga lelinyaka'],
53079 ['LTS', '3:25:50 entsambama'],
53080 ['L', '14/02/2010'],
53081 ['LL', '14 Indlovana 2010'],
53082 ['LLL', '14 Indlovana 2010 3:25 entsambama'],
53083 ['LLLL', 'Lisontfo, 14 Indlovana 2010 3:25 entsambama'],
53084 ['l', '14/2/2010'],
53085 ['ll', '14 Ina 2010'],
53086 ['lll', '14 Ina 2010 3:25 entsambama'],
53087 ['llll', 'Lis, 14 Ina 2010 3:25 entsambama']
53088 ],
53089 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
53090 i;
53091 for (i = 0; i < a.length; i++) {
53092 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
53093 }
53094 });
53095
53096 test('format ordinal', function (assert) {
53097 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
53098 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
53099 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
53100 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
53101 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
53102 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
53103 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
53104 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
53105 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
53106 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
53107
53108 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
53109 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
53110 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
53111 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
53112 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
53113 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
53114 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
53115 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
53116 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
53117 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
53118
53119 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
53120 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
53121 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
53122 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
53123 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
53124 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
53125 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
53126 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
53127 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
53128 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
53129
53130 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
53131 });
53132
53133 test('format month', function (assert) {
53134 var expected = "Bhimbidvwane Bhi_Indlovana Ina_Indlov'lenkhulu Inu_Mabasa Mab_Inkhwekhweti Ink_Inhlaba Inh_Kholwane Kho_Ingci Igc_Inyoni Iny_Imphala Imp_Lweti Lwe_Ingongoni Igo".split('_'), i;
53135 for (i = 0; i < expected.length; i++) {
53136 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
53137 }
53138 });
53139
53140 test('format week', function (assert) {
53141 var expected = 'Lisontfo Lis Li_Umsombuluko Umb Us_Lesibili Lsb Lb_Lesitsatfu Les Lt_Lesine Lsi Ls_Lesihlanu Lsh Lh_Umgcibelo Umg Ug'.split('_'), i;
53142 for (i = 0; i < expected.length; i++) {
53143 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
53144 }
53145 });
53146
53147 test('from', function (assert) {
53148 var start = moment([2007, 1, 28]);
53149 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'emizuzwana lomcane', '44 seconds = a few seconds');
53150 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'umzuzu', '45 seconds = a minute');
53151 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'umzuzu', '89 seconds = a minute');
53152 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 emizuzu', '90 seconds = 2 minutes');
53153 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 emizuzu', '44 minutes = 44 minutes');
53154 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'lihora', '45 minutes = an hour');
53155 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'lihora', '89 minutes = an hour');
53156 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 emahora', '90 minutes = 2 hours');
53157 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 emahora', '5 hours = 5 hours');
53158 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 emahora', '21 hours = 21 hours');
53159 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'lilanga', '22 hours = a day');
53160 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'lilanga', '35 hours = a day');
53161 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 emalanga', '36 hours = 2 days');
53162 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'lilanga', '1 day = a day');
53163 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 emalanga', '5 days = 5 days');
53164 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 emalanga', '25 days = 25 days');
53165 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'inyanga', '26 days = a month');
53166 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'inyanga', '30 days = a month');
53167 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'inyanga', '43 days = a month');
53168 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 tinyanga', '46 days = 2 months');
53169 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 tinyanga', '75 days = 2 months');
53170 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 tinyanga', '76 days = 3 months');
53171 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'inyanga', '1 month = a month');
53172 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 tinyanga', '5 months = 5 months');
53173 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'umnyaka', '345 days = a year');
53174 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 iminyaka', '548 days = 2 years');
53175 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'umnyaka', '1 year = a year');
53176 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 iminyaka', '5 years = 5 years');
53177 });
53178
53179 test('suffix', function (assert) {
53180 assert.equal(moment(30000).from(0), 'nga emizuzwana lomcane', 'prefix');
53181 assert.equal(moment(0).from(30000), 'wenteka nga emizuzwana lomcane', 'suffix');
53182 });
53183
53184 test('now from now', function (assert) {
53185 assert.equal(moment().fromNow(), 'wenteka nga emizuzwana lomcane', 'now from now should display as in the past');
53186 });
53187
53188 test('fromNow', function (assert) {
53189 assert.equal(moment().add({s: 30}).fromNow(), 'nga emizuzwana lomcane', 'in a few seconds');
53190 assert.equal(moment().add({d: 5}).fromNow(), 'nga 5 emalanga', 'in 5 days');
53191 });
53192
53193 test('calendar day', function (assert) {
53194 var a = moment().hours(12).minutes(0).seconds(0);
53195
53196 assert.equal(moment(a).calendar(), 'Namuhla nga 12:00 emini', 'Today at the same time');
53197 assert.equal(moment(a).add({m: 25}).calendar(), 'Namuhla nga 12:25 emini', 'Now plus 25 min');
53198 assert.equal(moment(a).add({h: 1}).calendar(), 'Namuhla nga 1:00 emini', 'Now plus 1 hour');
53199 assert.equal(moment(a).add({d: 1}).calendar(), 'Kusasa nga 12:00 emini', 'tomorrow at the same time');
53200 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Namuhla nga 11:00 emini', 'Now minus 1 hour');
53201 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Itolo nga 12:00 emini', 'yesterday at the same time');
53202 });
53203
53204 test('calendar next week', function (assert) {
53205 var i, m;
53206 for (i = 2; i < 7; i++) {
53207 m = moment().add({d: i});
53208 assert.equal(m.calendar(), m.format('dddd [nga] LT'), 'Today + ' + i + ' days current time');
53209 m.hours(0).minutes(0).seconds(0).milliseconds(0);
53210 assert.equal(m.calendar(), m.format('dddd [nga] LT'), 'Today + ' + i + ' days beginning of day');
53211 m.hours(23).minutes(59).seconds(59).milliseconds(999);
53212 assert.equal(m.calendar(), m.format('dddd [nga] LT'), 'Today + ' + i + ' days end of day');
d6651c21 53213 }
db71a655 53214 });
b135bf1a 53215
db71a655
KM
53216 test('calendar last week', function (assert) {
53217 var i, m;
53218
53219 for (i = 2; i < 7; i++) {
53220 m = moment().subtract({d: i});
53221 assert.equal(m.calendar(), m.format('dddd [leliphelile] [nga] LT'), 'Today - ' + i + ' days current time');
53222 m.hours(0).minutes(0).seconds(0).milliseconds(0);
53223 assert.equal(m.calendar(), m.format('dddd [leliphelile] [nga] LT'), 'Today - ' + i + ' days beginning of day');
53224 m.hours(23).minutes(59).seconds(59).milliseconds(999);
53225 assert.equal(m.calendar(), m.format('dddd [leliphelile] [nga] LT'), 'Today - ' + i + ' days end of day');
73f3c911 53226 }
db71a655 53227 });
b135bf1a 53228
db71a655
KM
53229 test('calendar all else', function (assert) {
53230 var weeksAgo = moment().subtract({w: 1}),
53231 weeksFromNow = moment().add({w: 1});
b135bf1a 53232
db71a655
KM
53233 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
53234 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
b135bf1a 53235
db71a655
KM
53236 weeksAgo = moment().subtract({w: 2});
53237 weeksFromNow = moment().add({w: 2});
b135bf1a 53238
db71a655
KM
53239 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
53240 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
53241 });
53242
53243 test('weeks year starting sunday formatted', function (assert) {
53244 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52', 'Jan 1 2012 should be week 52');
53245 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1', 'Jan 4 2012 should be week 1');
53246 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1', 'Jan 8 2012 should be week 1');
53247 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2', 'Jan 9 2012 should be week 2');
53248 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2', 'Jan 15 2012 should be week 2');
53249 });
73f3c911
IC
53250
53251})));
b135bf1a 53252
b135bf1a 53253
73f3c911
IC
53254;(function (global, factory) {
53255 typeof exports === 'object' && typeof module !== 'undefined'
53256 && typeof require === 'function' ? factory(require('../../moment')) :
53257 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
53258 factory(global.moment)
53259}(this, (function (moment) { 'use strict';
b135bf1a 53260
db71a655
KM
53261 function each(array, callback) {
53262 var i;
53263 for (i = 0; i < array.length; i++) {
53264 callback(array[i], i, array);
53265 }
73f3c911 53266 }
b135bf1a 53267
c58511b9
KM
53268 function setupDeprecationHandler(test, moment$$1, scope) {
53269 test._expectedDeprecations = null;
53270 test._observedDeprecations = null;
53271 test._oldSupress = moment$$1.suppressDeprecationWarnings;
53272 moment$$1.suppressDeprecationWarnings = true;
53273 test.expectedDeprecations = function () {
53274 test._expectedDeprecations = arguments;
53275 test._observedDeprecations = [];
53276 };
53277 moment$$1.deprecationHandler = function (name, msg) {
53278 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
53279 if (deprecationId === -1) {
53280 throw new Error('Unexpected deprecation thrown name=' +
53281 name + ' msg=' + msg);
53282 }
53283 test._observedDeprecations[deprecationId] = 1;
53284 };
53285 }
53286
53287 function teardownDeprecationHandler(test, moment$$1, scope) {
53288 moment$$1.suppressDeprecationWarnings = test._oldSupress;
53289
53290 if (test._expectedDeprecations != null) {
53291 var missedDeprecations = [];
53292 each(test._expectedDeprecations, function (deprecationPattern, id) {
53293 if (test._observedDeprecations[id] !== 1) {
53294 missedDeprecations.push(deprecationPattern);
53295 }
53296 });
53297 if (missedDeprecations.length !== 0) {
53298 throw new Error('Expected deprecation warnings did not happen: ' +
53299 missedDeprecations.join(' '));
53300 }
53301 }
53302 }
53303
53304 function matchedDeprecation(name, msg, deprecations) {
53305 if (deprecations == null) {
53306 return -1;
53307 }
53308 for (var i = 0; i < deprecations.length; ++i) {
53309 if (name != null && name === deprecations[i]) {
53310 return i;
53311 }
53312 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
53313 return i;
53314 }
53315 }
53316 return -1;
53317 }
53318
53319 /*global QUnit:false*/
53320
53321 var test = QUnit.test;
53322
db71a655
KM
53323 function objectKeys(obj) {
53324 if (Object.keys) {
53325 return Object.keys(obj);
53326 } else {
53327 // IE8
53328 var res = [], i;
53329 for (i in obj) {
53330 if (obj.hasOwnProperty(i)) {
53331 res.push(i);
53332 }
73f3c911 53333 }
db71a655 53334 return res;
73f3c911 53335 }
73f3c911 53336 }
b135bf1a 53337
db71a655 53338 // Pick the first defined of two or three arguments.
516f5f67 53339
db71a655
KM
53340 function defineCommonLocaleTests(locale, options) {
53341 test('lenient day of month ordinal parsing', function (assert) {
53342 var i, ordinalStr, testMoment;
53343 for (i = 1; i <= 31; ++i) {
53344 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
53345 testMoment = moment(ordinalStr, 'YYYY MM Do');
53346 assert.equal(testMoment.year(), 2014,
53347 'lenient day of month ordinal parsing ' + i + ' year check');
53348 assert.equal(testMoment.month(), 0,
53349 'lenient day of month ordinal parsing ' + i + ' month check');
53350 assert.equal(testMoment.date(), i,
53351 'lenient day of month ordinal parsing ' + i + ' date check');
53352 }
53353 });
516f5f67 53354
db71a655
KM
53355 test('lenient day of month ordinal parsing of number', function (assert) {
53356 var i, testMoment;
53357 for (i = 1; i <= 31; ++i) {
53358 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
53359 assert.equal(testMoment.year(), 2014,
53360 'lenient day of month ordinal parsing of number ' + i + ' year check');
53361 assert.equal(testMoment.month(), 0,
53362 'lenient day of month ordinal parsing of number ' + i + ' month check');
53363 assert.equal(testMoment.date(), i,
53364 'lenient day of month ordinal parsing of number ' + i + ' date check');
53365 }
53366 });
516f5f67 53367
db71a655
KM
53368 test('strict day of month ordinal parsing', function (assert) {
53369 var i, ordinalStr, testMoment;
53370 for (i = 1; i <= 31; ++i) {
53371 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
53372 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
53373 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
53374 }
53375 });
516f5f67 53376
db71a655
KM
53377 test('meridiem invariant', function (assert) {
53378 var h, m, t1, t2;
53379 for (h = 0; h < 24; ++h) {
53380 for (m = 0; m < 60; m += 15) {
53381 t1 = moment.utc([2000, 0, 1, h, m]);
53382 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
53383 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
53384 'meridiem at ' + t1.format('HH:mm'));
53385 }
53386 }
53387 });
53388
53389 test('date format correctness', function (assert) {
53390 var data, tokens;
53391 data = moment.localeData()._longDateFormat;
53392 tokens = objectKeys(data);
53393 each(tokens, function (srchToken) {
53394 // Check each format string to make sure it does not contain any
53395 // tokens that need to be expanded.
53396 each(tokens, function (baseToken) {
53397 // strip escaped sequences
53398 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
53399 assert.equal(false, !!~format.indexOf(srchToken),
53400 'contains ' + srchToken + ' in ' + baseToken);
53401 });
73f3c911
IC
53402 });
53403 });
516f5f67 53404
db71a655
KM
53405 test('month parsing correctness', function (assert) {
53406 var i, m;
53407
53408 if (locale === 'tr') {
53409 // I can't fix it :(
c58511b9 53410 assert.expect(0);
db71a655
KM
53411 return;
53412 }
53413 function tester(format) {
53414 var r;
53415 r = moment(m.format(format), format);
53416 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
53417 if (locale !== 'ka') {
53418 r = moment(m.format(format).toLocaleUpperCase(), format);
53419 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
53420 }
db71a655
KM
53421 r = moment(m.format(format).toLocaleLowerCase(), format);
53422 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
53423
53424 r = moment(m.format(format), format, true);
53425 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
53426 if (locale !== 'ka') {
53427 r = moment(m.format(format).toLocaleUpperCase(), format, true);
53428 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
53429 }
db71a655
KM
53430 r = moment(m.format(format).toLocaleLowerCase(), format, true);
53431 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
53432 }
53433
53434 for (i = 0; i < 12; ++i) {
53435 m = moment([2015, i, 15, 18]);
53436 tester('MMM');
53437 tester('MMM.');
53438 tester('MMMM');
53439 tester('MMMM.');
53440 }
53441 });
516f5f67 53442
db71a655
KM
53443 test('weekday parsing correctness', function (assert) {
53444 var i, m;
53445
96d0d679 53446 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
53447 // tr, az: There is a lower-case letter (ı), that converted to
53448 // upper then lower changes to i
53449 // ro: there is the letter ț which behaves weird under IE8
53450 // mt: letter Ħ
96d0d679 53451 // ga: month with spaces
c58511b9 53452 assert.expect(0);
db71a655
KM
53453 return;
53454 }
53455 function tester(format) {
53456 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
53457 r = moment(m.format(format), format);
53458 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
53459 if (locale !== 'ka') {
53460 r = moment(m.format(format).toLocaleUpperCase(), format);
53461 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
53462 }
db71a655
KM
53463 r = moment(m.format(format).toLocaleLowerCase(), format);
53464 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
53465 r = moment(m.format(format), format, true);
53466 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
53467 if (locale !== 'ka') {
53468 r = moment(m.format(format).toLocaleUpperCase(), format, true);
53469 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
53470 }
db71a655
KM
53471 r = moment(m.format(format).toLocaleLowerCase(), format, true);
53472 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
53473 }
53474
53475 for (i = 0; i < 7; ++i) {
53476 m = moment.utc([2015, 0, i + 1, 18]);
53477 tester('dd');
53478 tester('ddd');
53479 tester('dddd');
53480 }
53481 });
b135bf1a 53482
db71a655
KM
53483 test('valid localeData', function (assert) {
53484 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
53485 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
53486 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
53487 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
53488 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
53489 });
96d0d679
KM
53490
53491 test('localeData weekdays can localeSort', function (assert) {
53492 var weekdays = moment().localeData().weekdays();
53493 var weekdaysShort = moment().localeData().weekdaysShort();
53494 var weekdaysMin = moment().localeData().weekdaysMin();
53495 var shift = moment().localeData()._week.dow;
53496 assert.deepEqual(
53497 moment().localeData().weekdays(true),
53498 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
53499 'weekdays should localeSort');
53500 assert.deepEqual(
53501 moment().localeData().weekdaysShort(true),
53502 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
53503 'weekdaysShort should localeSort');
53504 assert.deepEqual(
53505 moment().localeData().weekdaysMin(true),
53506 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
53507 'weekdaysMin should localeSort');
53508 });
db71a655 53509 }
b135bf1a 53510
db71a655 53511 /*global QUnit:false*/
d6651c21 53512
db71a655
KM
53513 function localeModule (name, lifecycle) {
53514 QUnit.module('locale:' + name, {
c58511b9 53515 beforeEach : function () {
db71a655
KM
53516 moment.locale(name);
53517 moment.createFromInputFallback = function (config) {
53518 throw new Error('input not handled by moment: ' + config._i);
53519 };
53520 setupDeprecationHandler(test, moment, 'locale');
53521 if (lifecycle && lifecycle.setup) {
53522 lifecycle.setup();
53523 }
53524 },
c58511b9 53525 afterEach : function () {
db71a655
KM
53526 moment.locale('en');
53527 teardownDeprecationHandler(test, moment, 'locale');
53528 if (lifecycle && lifecycle.teardown) {
53529 lifecycle.teardown();
53530 }
d6651c21
IC
53531 }
53532 });
db71a655
KM
53533 defineCommonLocaleTests(name, -1, -1);
53534 }
53535
53536 localeModule('sv');
53537
53538 test('parse', function (assert) {
53539 var tests = 'januari jan_februari feb_mars mar_april apr_maj maj_juni jun_juli jul_augusti aug_september sep_oktober okt_november nov_december dec'.split('_'), i;
53540 function equalTest(input, mmm, i) {
53541 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
53542 }
53543 for (i = 0; i < 12; i++) {
53544 tests[i] = tests[i].split(' ');
53545 equalTest(tests[i][0], 'MMM', i);
53546 equalTest(tests[i][1], 'MMM', i);
53547 equalTest(tests[i][0], 'MMMM', i);
53548 equalTest(tests[i][1], 'MMMM', i);
53549 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
53550 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
53551 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
53552 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
53553 }
53554 });
53555
53556 test('format', function (assert) {
53557 var a = [
53558 ['dddd, MMMM Do YYYY, h:mm:ss a', 'söndag, februari 14e 2010, 3:25:50 pm'],
53559 ['ddd, hA', 'sön, 3PM'],
53560 ['M Mo MM MMMM MMM', '2 2a 02 februari feb'],
53561 ['YYYY YY', '2010 10'],
53562 ['D Do DD', '14 14e 14'],
53563 ['d do dddd ddd dd', '0 0e söndag sön sö'],
53564 ['DDD DDDo DDDD', '45 45e 045'],
53565 ['w wo ww', '6 6e 06'],
53566 ['h hh', '3 03'],
53567 ['H HH', '15 15'],
53568 ['m mm', '25 25'],
53569 ['s ss', '50 50'],
53570 ['a A', 'pm PM'],
53571 ['[the] DDDo [day of the year]', 'the 45e day of the year'],
53572 ['LTS', '15:25:50'],
53573 ['L', '2010-02-14'],
53574 ['LL', '14 februari 2010'],
53575 ['LLL', '14 februari 2010 kl. 15:25'],
53576 ['LLLL', 'söndag 14 februari 2010 kl. 15:25'],
53577 ['l', '2010-2-14'],
53578 ['ll', '14 feb 2010'],
53579 ['lll', '14 feb 2010 15:25'],
53580 ['llll', 'sön 14 feb 2010 15:25']
53581 ],
53582 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
53583 i;
53584 for (i = 0; i < a.length; i++) {
53585 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
53586 }
53587 });
53588
53589 test('format ordinal', function (assert) {
53590 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1a', '1a');
53591 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2a', '2a');
53592 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3e', '3e');
53593 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4e', '4e');
53594 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5e', '5e');
53595 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6e', '6e');
53596 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7e', '7e');
53597 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8e', '8e');
53598 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9e', '9e');
53599 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10e', '10e');
53600
53601 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11e', '11e');
53602 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12e', '12e');
53603 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13e', '13e');
53604 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14e', '14e');
53605 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15e', '15e');
53606 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16e', '16e');
53607 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17e', '17e');
53608 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18e', '18e');
53609 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19e', '19e');
53610 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20e', '20e');
53611
53612 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21a', '21a');
53613 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22a', '22a');
53614 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23e', '23e');
53615 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24e', '24e');
53616 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25e', '25e');
53617 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26e', '26e');
53618 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27e', '27e');
53619 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28e', '28e');
53620 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29e', '29e');
53621 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30e', '30e');
53622
53623 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31a', '31a');
53624 });
53625
53626 test('format month', function (assert) {
53627 var expected = 'januari jan_februari feb_mars mar_april apr_maj maj_juni jun_juli jul_augusti aug_september sep_oktober okt_november nov_december dec'.split('_'), i;
53628 for (i = 0; i < expected.length; i++) {
53629 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
53630 }
53631 });
53632
53633 test('format week', function (assert) {
53634 var expected = 'söndag sön sö_måndag mån må_tisdag tis ti_onsdag ons on_torsdag tor to_fredag fre fr_lördag lör lö'.split('_'), i;
53635 for (i = 0; i < expected.length; i++) {
53636 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
53637 }
53638 });
53639
53640 test('from', function (assert) {
53641 var start = moment([2007, 1, 28]);
53642 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'några sekunder', '44 seconds = a few seconds');
53643 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'en minut', '45 seconds = a minute');
53644 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'en minut', '89 seconds = a minute');
53645 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuter', '90 seconds = 2 minutes');
53646 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuter', '44 minutes = 44 minutes');
53647 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'en timme', '45 minutes = an hour');
53648 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'en timme', '89 minutes = an hour');
53649 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 timmar', '90 minutes = 2 hours');
53650 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 timmar', '5 hours = 5 hours');
53651 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 timmar', '21 hours = 21 hours');
53652 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'en dag', '22 hours = a day');
53653 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'en dag', '35 hours = a day');
53654 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dagar', '36 hours = 2 days');
53655 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'en dag', '1 day = a day');
53656 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dagar', '5 days = 5 days');
53657 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dagar', '25 days = 25 days');
53658 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'en månad', '26 days = a month');
53659 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'en månad', '30 days = a month');
53660 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'en månad', '43 days = a month');
53661 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 månader', '46 days = 2 months');
53662 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 månader', '75 days = 2 months');
53663 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 månader', '76 days = 3 months');
53664 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'en månad', '1 month = a month');
53665 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 månader', '5 months = 5 months');
53666 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ett år', '345 days = a year');
53667 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 år', '548 days = 2 years');
53668 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ett år', '1 year = a year');
53669 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 år', '5 years = 5 years');
53670 });
53671
53672 test('suffix', function (assert) {
53673 assert.equal(moment(30000).from(0), 'om några sekunder', 'prefix');
53674 assert.equal(moment(0).from(30000), 'för några sekunder sedan', 'suffix');
53675 });
53676
53677 test('now from now', function (assert) {
53678 assert.equal(moment().fromNow(), 'för några sekunder sedan', 'now from now should display as in the past');
53679 });
53680
53681 test('fromNow', function (assert) {
53682 assert.equal(moment().add({s: 30}).fromNow(), 'om några sekunder', 'in a few seconds');
53683 assert.equal(moment().add({d: 5}).fromNow(), 'om 5 dagar', 'in 5 days');
53684 });
53685
53686 test('calendar day', function (assert) {
53687 var a = moment().hours(12).minutes(0).seconds(0);
53688
53689 assert.equal(moment(a).calendar(), 'Idag 12:00', 'today at the same time');
53690 assert.equal(moment(a).add({m: 25}).calendar(), 'Idag 12:25', 'Now plus 25 min');
53691 assert.equal(moment(a).add({h: 1}).calendar(), 'Idag 13:00', 'Now plus 1 hour');
53692 assert.equal(moment(a).add({d: 1}).calendar(), 'Imorgon 12:00', 'tomorrow at the same time');
53693 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Idag 11:00', 'Now minus 1 hour');
53694 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Igår 12:00', 'yesterday at the same time');
53695 });
53696
53697 test('calendar next week', function (assert) {
53698 var i, m;
53699 for (i = 2; i < 7; i++) {
53700 m = moment().add({d: i});
53701 assert.equal(m.calendar(), m.format('[På] dddd LT'), 'Today + ' + i + ' days current time');
53702 m.hours(0).minutes(0).seconds(0).milliseconds(0);
53703 assert.equal(m.calendar(), m.format('[På] dddd LT'), 'Today + ' + i + ' days beginning of day');
53704 m.hours(23).minutes(59).seconds(59).milliseconds(999);
53705 assert.equal(m.calendar(), m.format('[På] dddd LT'), 'Today + ' + i + ' days end of day');
d6651c21 53706 }
db71a655 53707 });
d6651c21 53708
db71a655
KM
53709 test('calendar last week', function (assert) {
53710 var i, m;
53711 for (i = 2; i < 7; i++) {
53712 m = moment().subtract({d: i});
53713 assert.equal(m.calendar(), m.format('[I] dddd[s] LT'), 'Today - ' + i + ' days current time');
53714 m.hours(0).minutes(0).seconds(0).milliseconds(0);
53715 assert.equal(m.calendar(), m.format('[I] dddd[s] LT'), 'Today - ' + i + ' days beginning of day');
53716 m.hours(23).minutes(59).seconds(59).milliseconds(999);
53717 assert.equal(m.calendar(), m.format('[I] dddd[s] LT'), 'Today - ' + i + ' days end of day');
c74a101d 53718 }
db71a655 53719 });
c74a101d 53720
db71a655
KM
53721 test('calendar all else', function (assert) {
53722 var weeksAgo = moment().subtract({w: 1}),
53723 weeksFromNow = moment().add({w: 1});
516f5f67 53724
db71a655
KM
53725 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
53726 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 53727
db71a655
KM
53728 weeksAgo = moment().subtract({w: 2});
53729 weeksFromNow = moment().add({w: 2});
516f5f67 53730
db71a655
KM
53731 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
53732 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
53733 });
53734
53735 test('weeks year starting sunday formatted', function (assert) {
53736 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52a', 'Jan 1 2012 should be week 52');
53737 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1a', 'Jan 2 2012 should be week 1');
53738 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1a', 'Jan 8 2012 should be week 1');
53739 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2a', 'Jan 9 2012 should be week 2');
53740 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2a', 'Jan 15 2012 should be week 2');
53741 });
73f3c911
IC
53742
53743})));
516f5f67 53744
516f5f67 53745
c74a101d
IC
53746;(function (global, factory) {
53747 typeof exports === 'object' && typeof module !== 'undefined'
53748 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
53749 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
53750 factory(global.moment)
73f3c911 53751}(this, (function (moment) { 'use strict';
516f5f67 53752
db71a655
KM
53753 function each(array, callback) {
53754 var i;
53755 for (i = 0; i < array.length; i++) {
53756 callback(array[i], i, array);
53757 }
b135bf1a
IC
53758 }
53759
c58511b9
KM
53760 function setupDeprecationHandler(test, moment$$1, scope) {
53761 test._expectedDeprecations = null;
53762 test._observedDeprecations = null;
53763 test._oldSupress = moment$$1.suppressDeprecationWarnings;
53764 moment$$1.suppressDeprecationWarnings = true;
53765 test.expectedDeprecations = function () {
53766 test._expectedDeprecations = arguments;
53767 test._observedDeprecations = [];
53768 };
53769 moment$$1.deprecationHandler = function (name, msg) {
53770 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
53771 if (deprecationId === -1) {
53772 throw new Error('Unexpected deprecation thrown name=' +
53773 name + ' msg=' + msg);
53774 }
53775 test._observedDeprecations[deprecationId] = 1;
53776 };
53777 }
53778
53779 function teardownDeprecationHandler(test, moment$$1, scope) {
53780 moment$$1.suppressDeprecationWarnings = test._oldSupress;
53781
53782 if (test._expectedDeprecations != null) {
53783 var missedDeprecations = [];
53784 each(test._expectedDeprecations, function (deprecationPattern, id) {
53785 if (test._observedDeprecations[id] !== 1) {
53786 missedDeprecations.push(deprecationPattern);
53787 }
53788 });
53789 if (missedDeprecations.length !== 0) {
53790 throw new Error('Expected deprecation warnings did not happen: ' +
53791 missedDeprecations.join(' '));
53792 }
53793 }
53794 }
53795
53796 function matchedDeprecation(name, msg, deprecations) {
53797 if (deprecations == null) {
53798 return -1;
53799 }
53800 for (var i = 0; i < deprecations.length; ++i) {
53801 if (name != null && name === deprecations[i]) {
53802 return i;
53803 }
53804 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
53805 return i;
53806 }
53807 }
53808 return -1;
53809 }
53810
53811 /*global QUnit:false*/
53812
53813 var test = QUnit.test;
53814
db71a655
KM
53815 function objectKeys(obj) {
53816 if (Object.keys) {
53817 return Object.keys(obj);
53818 } else {
53819 // IE8
53820 var res = [], i;
53821 for (i in obj) {
53822 if (obj.hasOwnProperty(i)) {
53823 res.push(i);
53824 }
b135bf1a 53825 }
db71a655 53826 return res;
b135bf1a 53827 }
b135bf1a 53828 }
b135bf1a 53829
db71a655 53830 // Pick the first defined of two or three arguments.
b135bf1a 53831
db71a655
KM
53832 function defineCommonLocaleTests(locale, options) {
53833 test('lenient day of month ordinal parsing', function (assert) {
53834 var i, ordinalStr, testMoment;
53835 for (i = 1; i <= 31; ++i) {
53836 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
53837 testMoment = moment(ordinalStr, 'YYYY MM Do');
53838 assert.equal(testMoment.year(), 2014,
53839 'lenient day of month ordinal parsing ' + i + ' year check');
53840 assert.equal(testMoment.month(), 0,
53841 'lenient day of month ordinal parsing ' + i + ' month check');
53842 assert.equal(testMoment.date(), i,
53843 'lenient day of month ordinal parsing ' + i + ' date check');
53844 }
53845 });
b135bf1a 53846
db71a655
KM
53847 test('lenient day of month ordinal parsing of number', function (assert) {
53848 var i, testMoment;
53849 for (i = 1; i <= 31; ++i) {
53850 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
53851 assert.equal(testMoment.year(), 2014,
53852 'lenient day of month ordinal parsing of number ' + i + ' year check');
53853 assert.equal(testMoment.month(), 0,
53854 'lenient day of month ordinal parsing of number ' + i + ' month check');
53855 assert.equal(testMoment.date(), i,
53856 'lenient day of month ordinal parsing of number ' + i + ' date check');
53857 }
b135bf1a 53858 });
d6651c21 53859
db71a655
KM
53860 test('strict day of month ordinal parsing', function (assert) {
53861 var i, ordinalStr, testMoment;
53862 for (i = 1; i <= 31; ++i) {
53863 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
53864 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
53865 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
53866 }
53867 });
d6651c21 53868
db71a655
KM
53869 test('meridiem invariant', function (assert) {
53870 var h, m, t1, t2;
53871 for (h = 0; h < 24; ++h) {
53872 for (m = 0; m < 60; m += 15) {
53873 t1 = moment.utc([2000, 0, 1, h, m]);
53874 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
53875 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
53876 'meridiem at ' + t1.format('HH:mm'));
53877 }
53878 }
53879 });
d6651c21 53880
db71a655
KM
53881 test('date format correctness', function (assert) {
53882 var data, tokens;
53883 data = moment.localeData()._longDateFormat;
53884 tokens = objectKeys(data);
53885 each(tokens, function (srchToken) {
53886 // Check each format string to make sure it does not contain any
53887 // tokens that need to be expanded.
53888 each(tokens, function (baseToken) {
53889 // strip escaped sequences
53890 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
53891 assert.equal(false, !!~format.indexOf(srchToken),
53892 'contains ' + srchToken + ' in ' + baseToken);
53893 });
53894 });
53895 });
d6651c21 53896
db71a655
KM
53897 test('month parsing correctness', function (assert) {
53898 var i, m;
53899
53900 if (locale === 'tr') {
53901 // I can't fix it :(
c58511b9 53902 assert.expect(0);
db71a655
KM
53903 return;
53904 }
53905 function tester(format) {
53906 var r;
53907 r = moment(m.format(format), format);
53908 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
53909 if (locale !== 'ka') {
53910 r = moment(m.format(format).toLocaleUpperCase(), format);
53911 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
53912 }
db71a655
KM
53913 r = moment(m.format(format).toLocaleLowerCase(), format);
53914 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
53915
53916 r = moment(m.format(format), format, true);
53917 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
53918 if (locale !== 'ka') {
53919 r = moment(m.format(format).toLocaleUpperCase(), format, true);
53920 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
53921 }
db71a655
KM
53922 r = moment(m.format(format).toLocaleLowerCase(), format, true);
53923 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
53924 }
53925
53926 for (i = 0; i < 12; ++i) {
53927 m = moment([2015, i, 15, 18]);
53928 tester('MMM');
53929 tester('MMM.');
53930 tester('MMMM');
53931 tester('MMMM.');
53932 }
53933 });
d6651c21 53934
db71a655
KM
53935 test('weekday parsing correctness', function (assert) {
53936 var i, m;
53937
96d0d679 53938 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
53939 // tr, az: There is a lower-case letter (ı), that converted to
53940 // upper then lower changes to i
53941 // ro: there is the letter ț which behaves weird under IE8
53942 // mt: letter Ħ
96d0d679 53943 // ga: month with spaces
c58511b9 53944 assert.expect(0);
db71a655
KM
53945 return;
53946 }
53947 function tester(format) {
53948 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
53949 r = moment(m.format(format), format);
53950 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
53951 if (locale !== 'ka') {
53952 r = moment(m.format(format).toLocaleUpperCase(), format);
53953 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
53954 }
db71a655
KM
53955 r = moment(m.format(format).toLocaleLowerCase(), format);
53956 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
53957 r = moment(m.format(format), format, true);
53958 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
53959 if (locale !== 'ka') {
53960 r = moment(m.format(format).toLocaleUpperCase(), format, true);
53961 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
53962 }
db71a655
KM
53963 r = moment(m.format(format).toLocaleLowerCase(), format, true);
53964 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
53965 }
53966
53967 for (i = 0; i < 7; ++i) {
53968 m = moment.utc([2015, 0, i + 1, 18]);
53969 tester('dd');
53970 tester('ddd');
53971 tester('dddd');
53972 }
53973 });
73f3c911 53974
db71a655
KM
53975 test('valid localeData', function (assert) {
53976 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
53977 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
53978 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
53979 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
53980 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
53981 });
96d0d679
KM
53982
53983 test('localeData weekdays can localeSort', function (assert) {
53984 var weekdays = moment().localeData().weekdays();
53985 var weekdaysShort = moment().localeData().weekdaysShort();
53986 var weekdaysMin = moment().localeData().weekdaysMin();
53987 var shift = moment().localeData()._week.dow;
53988 assert.deepEqual(
53989 moment().localeData().weekdays(true),
53990 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
53991 'weekdays should localeSort');
53992 assert.deepEqual(
53993 moment().localeData().weekdaysShort(true),
53994 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
53995 'weekdaysShort should localeSort');
53996 assert.deepEqual(
53997 moment().localeData().weekdaysMin(true),
53998 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
53999 'weekdaysMin should localeSort');
54000 });
db71a655 54001 }
b135bf1a 54002
db71a655 54003 /*global QUnit:false*/
25cc720f 54004
db71a655
KM
54005 function localeModule (name, lifecycle) {
54006 QUnit.module('locale:' + name, {
c58511b9 54007 beforeEach : function () {
db71a655
KM
54008 moment.locale(name);
54009 moment.createFromInputFallback = function (config) {
54010 throw new Error('input not handled by moment: ' + config._i);
54011 };
54012 setupDeprecationHandler(test, moment, 'locale');
54013 if (lifecycle && lifecycle.setup) {
54014 lifecycle.setup();
54015 }
54016 },
c58511b9 54017 afterEach : function () {
db71a655
KM
54018 moment.locale('en');
54019 teardownDeprecationHandler(test, moment, 'locale');
54020 if (lifecycle && lifecycle.teardown) {
54021 lifecycle.teardown();
54022 }
73f3c911 54023 }
db71a655
KM
54024 });
54025 defineCommonLocaleTests(name, -1, -1);
54026 }
54027
54028 localeModule('sw');
54029
54030 test('parse', function (assert) {
54031 var tests = 'Januari Jan_Februari Feb_Machi Mac_Aprili Apr_Mei Mei_Juni Jun_Julai Jul_Agosti Ago_Septemba Sep_Oktoba Okt_Novemba Nov_Desemba Des'.split('_'), i;
54032 function equalTest(input, mmm, i) {
54033 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
54034 }
54035 for (i = 0; i < 12; i++) {
54036 tests[i] = tests[i].split(' ');
54037 equalTest(tests[i][0], 'MMM', i);
54038 equalTest(tests[i][1], 'MMM', i);
54039 equalTest(tests[i][0], 'MMMM', i);
54040 equalTest(tests[i][1], 'MMMM', i);
54041 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
54042 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
54043 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
54044 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
54045 }
54046 });
54047
54048 test('format', function (assert) {
54049 var a = [
54050 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Jumapili, Februari 14 2010, 3:25:50 pm'],
54051 ['ddd, hA', 'Jpl, 3PM'],
54052 ['M Mo MM MMMM MMM', '2 2 02 Februari Feb'],
54053 ['YYYY YY', '2010 10'],
54054 ['D Do DD', '14 14 14'],
54055 ['d do dddd ddd dd', '0 0 Jumapili Jpl J2'],
54056 ['DDD DDDo DDDD', '45 45 045'],
54057 ['w wo ww', '7 7 07'],
54058 ['h hh', '3 03'],
54059 ['H HH', '15 15'],
54060 ['m mm', '25 25'],
54061 ['s ss', '50 50'],
54062 ['a A', 'pm PM'],
54063 ['[siku] DDDo [ya mwaka]', 'siku 45 ya mwaka'],
54064 ['LTS', '15:25:50'],
54065 ['L', '14.02.2010'],
54066 ['LL', '14 Februari 2010'],
54067 ['LLL', '14 Februari 2010 15:25'],
54068 ['LLLL', 'Jumapili, 14 Februari 2010 15:25'],
54069 ['l', '14.2.2010'],
54070 ['ll', '14 Feb 2010'],
54071 ['lll', '14 Feb 2010 15:25'],
54072 ['llll', 'Jpl, 14 Feb 2010 15:25']
54073 ],
54074 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
54075 i;
54076 for (i = 0; i < a.length; i++) {
54077 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
54078 }
54079 });
54080
54081 test('format ordinal', function (assert) {
54082 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
54083 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
54084 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
54085 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
54086 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
54087 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
54088 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
54089 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
54090 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
54091 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
54092
54093 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
54094 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
54095 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
54096 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
54097 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
54098 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
54099 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
54100 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
54101 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
54102 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
54103
54104 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
54105 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
54106 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
54107 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
54108 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
54109 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
54110 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
54111 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
54112 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
54113 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
54114
54115 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
54116 });
54117
54118 test('format month', function (assert) {
54119 var expected = 'Januari Jan_Februari Feb_Machi Mac_Aprili Apr_Mei Mei_Juni Jun_Julai Jul_Agosti Ago_Septemba Sep_Oktoba Okt_Novemba Nov_Desemba Des'.split('_'), i;
54120 for (i = 0; i < expected.length; i++) {
54121 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
54122 }
54123 });
54124
54125 test('format week', function (assert) {
54126 var expected = 'Jumapili Jpl J2_Jumatatu Jtat J3_Jumanne Jnne J4_Jumatano Jtan J5_Alhamisi Alh Al_Ijumaa Ijm Ij_Jumamosi Jmos J1'.split('_'), i;
54127 for (i = 0; i < expected.length; i++) {
54128 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
54129 }
54130 });
54131
54132 test('from', function (assert) {
54133 var start = moment([2007, 1, 28]);
54134 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'hivi punde', '44 seconds = a few seconds');
54135 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'dakika moja', '45 seconds = a minute');
54136 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'dakika moja', '89 seconds = a minute');
54137 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), 'dakika 2', '90 seconds = 2 minutes');
54138 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), 'dakika 44', '44 minutes = 44 minutes');
54139 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'saa limoja', '45 minutes = an hour');
54140 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'saa limoja', '89 minutes = an hour');
54141 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), 'masaa 2', '90 minutes = 2 hours');
54142 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), 'masaa 5', '5 hours = 5 hours');
54143 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), 'masaa 21', '21 hours = 21 hours');
54144 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'siku moja', '22 hours = a day');
54145 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'siku moja', '35 hours = a day');
54146 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), 'masiku 2', '36 hours = 2 days');
54147 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'siku moja', '1 day = a day');
54148 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), 'masiku 5', '5 days = 5 days');
54149 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), 'masiku 25', '25 days = 25 days');
54150 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mwezi mmoja', '26 days = a month');
54151 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mwezi mmoja', '30 days = a month');
54152 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mwezi mmoja', '43 days = a month');
54153 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), 'miezi 2', '46 days = 2 months');
54154 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), 'miezi 2', '75 days = 2 months');
54155 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), 'miezi 3', '76 days = 3 months');
54156 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mwezi mmoja', '1 month = a month');
54157 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), 'miezi 5', '5 months = 5 months');
54158 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'mwaka mmoja', '345 days = a year');
54159 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), 'miaka 2', '548 days = 2 years');
54160 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'mwaka mmoja', '1 year = a year');
54161 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), 'miaka 5', '5 years = 5 years');
54162 });
54163
54164 test('suffix', function (assert) {
54165 assert.equal(moment(30000).from(0), 'hivi punde baadaye', 'prefix');
54166 assert.equal(moment(0).from(30000), 'tokea hivi punde', 'suffix');
54167 });
54168
54169 test('now from now', function (assert) {
54170 assert.equal(moment().fromNow(), 'tokea hivi punde', 'now from now should display as in the past');
54171 });
54172
54173 test('fromNow', function (assert) {
54174 assert.equal(moment().add({s: 30}).fromNow(), 'hivi punde baadaye', 'in a few seconds');
54175 assert.equal(moment().add({d: 5}).fromNow(), 'masiku 5 baadaye', 'in 5 days');
54176 });
54177
54178 test('calendar day', function (assert) {
54179 var a = moment().hours(12).minutes(0).seconds(0);
54180 assert.equal(moment(a).calendar(), 'leo saa 12:00', 'today at the same time');
54181 assert.equal(moment(a).add({m: 25}).calendar(), 'leo saa 12:25', 'Now plus 25 min');
54182 assert.equal(moment(a).add({h: 1}).calendar(), 'leo saa 13:00', 'Now plus 1 hour');
54183 assert.equal(moment(a).add({d: 1}).calendar(), 'kesho saa 12:00', 'tomorrow at the same time');
54184 assert.equal(moment(a).subtract({h: 1}).calendar(), 'leo saa 11:00', 'Now minus 1 hour');
54185 assert.equal(moment(a).subtract({d: 1}).calendar(), 'jana 12:00', 'yesterday at the same time');
54186 });
54187
54188 test('calendar next week', function (assert) {
54189 var i, m;
54190 for (i = 2; i < 7; i++) {
54191 m = moment().add({d: i});
54192 assert.equal(m.calendar(), m.format('[wiki ijayo] dddd [saat] LT'), 'Today + ' + i + ' days current time');
54193 m.hours(0).minutes(0).seconds(0).milliseconds(0);
54194 assert.equal(m.calendar(), m.format('[wiki ijayo] dddd [saat] LT'), 'Today + ' + i + ' days beginning of day');
54195 m.hours(23).minutes(59).seconds(59).milliseconds(999);
54196 assert.equal(m.calendar(), m.format('[wiki ijayo] dddd [saat] LT'), 'Today + ' + i + ' days end of day');
54197 }
54198 });
54199
54200 test('calendar last week', function (assert) {
54201 var i, m;
54202
54203 for (i = 2; i < 7; i++) {
54204 m = moment().subtract({d: i});
54205 assert.equal(m.calendar(), m.format('[wiki iliyopita] dddd [saat] LT'), 'Today - ' + i + ' days current time');
54206 m.hours(0).minutes(0).seconds(0).milliseconds(0);
54207 assert.equal(m.calendar(), m.format('[wiki iliyopita] dddd [saat] LT'), 'Today - ' + i + ' days beginning of day');
54208 m.hours(23).minutes(59).seconds(59).milliseconds(999);
54209 assert.equal(m.calendar(), m.format('[wiki iliyopita] dddd [saat] LT'), 'Today - ' + i + ' days end of day');
54210 }
54211 });
73f3c911 54212
db71a655
KM
54213 test('calendar all else', function (assert) {
54214 var weeksAgo = moment().subtract({w: 1}),
54215 weeksFromNow = moment().add({w: 1});
73f3c911 54216
db71a655
KM
54217 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
54218 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
73f3c911 54219
db71a655
KM
54220 weeksAgo = moment().subtract({w: 2});
54221 weeksFromNow = moment().add({w: 2});
73f3c911 54222
db71a655
KM
54223 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
54224 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
54225 });
73f3c911 54226
db71a655
KM
54227 test('weeks year starting sunday format', function (assert) {
54228 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1', 'Dec 26 2011 should be week 1');
54229 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1');
54230 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2', 'Jan 2 2012 should be week 2');
54231 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2');
54232 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3', 'Jan 9 2012 should be week 3');
54233 });
73f3c911
IC
54234
54235})));
54236
25cc720f 54237
c74a101d
IC
54238;(function (global, factory) {
54239 typeof exports === 'object' && typeof module !== 'undefined'
54240 && typeof require === 'function' ? factory(require('../../moment')) :
25cc720f
IC
54241 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
54242 factory(global.moment)
73f3c911 54243}(this, (function (moment) { 'use strict';
25cc720f 54244
db71a655
KM
54245 function each(array, callback) {
54246 var i;
54247 for (i = 0; i < array.length; i++) {
54248 callback(array[i], i, array);
54249 }
b135bf1a
IC
54250 }
54251
c58511b9
KM
54252 function setupDeprecationHandler(test, moment$$1, scope) {
54253 test._expectedDeprecations = null;
54254 test._observedDeprecations = null;
54255 test._oldSupress = moment$$1.suppressDeprecationWarnings;
54256 moment$$1.suppressDeprecationWarnings = true;
54257 test.expectedDeprecations = function () {
54258 test._expectedDeprecations = arguments;
54259 test._observedDeprecations = [];
54260 };
54261 moment$$1.deprecationHandler = function (name, msg) {
54262 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
54263 if (deprecationId === -1) {
54264 throw new Error('Unexpected deprecation thrown name=' +
54265 name + ' msg=' + msg);
54266 }
54267 test._observedDeprecations[deprecationId] = 1;
54268 };
54269 }
54270
54271 function teardownDeprecationHandler(test, moment$$1, scope) {
54272 moment$$1.suppressDeprecationWarnings = test._oldSupress;
54273
54274 if (test._expectedDeprecations != null) {
54275 var missedDeprecations = [];
54276 each(test._expectedDeprecations, function (deprecationPattern, id) {
54277 if (test._observedDeprecations[id] !== 1) {
54278 missedDeprecations.push(deprecationPattern);
54279 }
54280 });
54281 if (missedDeprecations.length !== 0) {
54282 throw new Error('Expected deprecation warnings did not happen: ' +
54283 missedDeprecations.join(' '));
54284 }
54285 }
54286 }
54287
54288 function matchedDeprecation(name, msg, deprecations) {
54289 if (deprecations == null) {
54290 return -1;
54291 }
54292 for (var i = 0; i < deprecations.length; ++i) {
54293 if (name != null && name === deprecations[i]) {
54294 return i;
54295 }
54296 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
54297 return i;
54298 }
54299 }
54300 return -1;
54301 }
54302
54303 /*global QUnit:false*/
54304
54305 var test = QUnit.test;
54306
db71a655
KM
54307 function objectKeys(obj) {
54308 if (Object.keys) {
54309 return Object.keys(obj);
54310 } else {
54311 // IE8
54312 var res = [], i;
54313 for (i in obj) {
54314 if (obj.hasOwnProperty(i)) {
54315 res.push(i);
54316 }
b135bf1a 54317 }
db71a655 54318 return res;
b135bf1a
IC
54319 }
54320 }
54321
db71a655 54322 // Pick the first defined of two or three arguments.
b135bf1a 54323
db71a655
KM
54324 function defineCommonLocaleTests(locale, options) {
54325 test('lenient day of month ordinal parsing', function (assert) {
54326 var i, ordinalStr, testMoment;
54327 for (i = 1; i <= 31; ++i) {
54328 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
54329 testMoment = moment(ordinalStr, 'YYYY MM Do');
54330 assert.equal(testMoment.year(), 2014,
54331 'lenient day of month ordinal parsing ' + i + ' year check');
54332 assert.equal(testMoment.month(), 0,
54333 'lenient day of month ordinal parsing ' + i + ' month check');
54334 assert.equal(testMoment.date(), i,
54335 'lenient day of month ordinal parsing ' + i + ' date check');
54336 }
54337 });
b135bf1a 54338
db71a655
KM
54339 test('lenient day of month ordinal parsing of number', function (assert) {
54340 var i, testMoment;
54341 for (i = 1; i <= 31; ++i) {
54342 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
54343 assert.equal(testMoment.year(), 2014,
54344 'lenient day of month ordinal parsing of number ' + i + ' year check');
54345 assert.equal(testMoment.month(), 0,
54346 'lenient day of month ordinal parsing of number ' + i + ' month check');
54347 assert.equal(testMoment.date(), i,
54348 'lenient day of month ordinal parsing of number ' + i + ' date check');
54349 }
54350 });
b135bf1a 54351
db71a655
KM
54352 test('strict day of month ordinal parsing', function (assert) {
54353 var i, ordinalStr, testMoment;
54354 for (i = 1; i <= 31; ++i) {
54355 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
54356 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
54357 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
54358 }
54359 });
b135bf1a 54360
db71a655
KM
54361 test('meridiem invariant', function (assert) {
54362 var h, m, t1, t2;
54363 for (h = 0; h < 24; ++h) {
54364 for (m = 0; m < 60; m += 15) {
54365 t1 = moment.utc([2000, 0, 1, h, m]);
54366 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
54367 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
54368 'meridiem at ' + t1.format('HH:mm'));
54369 }
54370 }
54371 });
54372
54373 test('date format correctness', function (assert) {
54374 var data, tokens;
54375 data = moment.localeData()._longDateFormat;
54376 tokens = objectKeys(data);
54377 each(tokens, function (srchToken) {
54378 // Check each format string to make sure it does not contain any
54379 // tokens that need to be expanded.
54380 each(tokens, function (baseToken) {
54381 // strip escaped sequences
54382 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
54383 assert.equal(false, !!~format.indexOf(srchToken),
54384 'contains ' + srchToken + ' in ' + baseToken);
54385 });
b135bf1a
IC
54386 });
54387 });
d6651c21 54388
db71a655
KM
54389 test('month parsing correctness', function (assert) {
54390 var i, m;
54391
54392 if (locale === 'tr') {
54393 // I can't fix it :(
c58511b9 54394 assert.expect(0);
db71a655
KM
54395 return;
54396 }
54397 function tester(format) {
54398 var r;
54399 r = moment(m.format(format), format);
54400 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
54401 if (locale !== 'ka') {
54402 r = moment(m.format(format).toLocaleUpperCase(), format);
54403 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
54404 }
db71a655
KM
54405 r = moment(m.format(format).toLocaleLowerCase(), format);
54406 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
54407
54408 r = moment(m.format(format), format, true);
54409 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
54410 if (locale !== 'ka') {
54411 r = moment(m.format(format).toLocaleUpperCase(), format, true);
54412 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
54413 }
db71a655
KM
54414 r = moment(m.format(format).toLocaleLowerCase(), format, true);
54415 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
54416 }
54417
54418 for (i = 0; i < 12; ++i) {
54419 m = moment([2015, i, 15, 18]);
54420 tester('MMM');
54421 tester('MMM.');
54422 tester('MMMM');
54423 tester('MMMM.');
54424 }
54425 });
d6651c21 54426
db71a655
KM
54427 test('weekday parsing correctness', function (assert) {
54428 var i, m;
54429
96d0d679 54430 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
54431 // tr, az: There is a lower-case letter (ı), that converted to
54432 // upper then lower changes to i
54433 // ro: there is the letter ț which behaves weird under IE8
54434 // mt: letter Ħ
96d0d679 54435 // ga: month with spaces
c58511b9 54436 assert.expect(0);
db71a655
KM
54437 return;
54438 }
54439 function tester(format) {
54440 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
54441 r = moment(m.format(format), format);
54442 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
54443 if (locale !== 'ka') {
54444 r = moment(m.format(format).toLocaleUpperCase(), format);
54445 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
54446 }
db71a655
KM
54447 r = moment(m.format(format).toLocaleLowerCase(), format);
54448 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
54449 r = moment(m.format(format), format, true);
54450 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
54451 if (locale !== 'ka') {
54452 r = moment(m.format(format).toLocaleUpperCase(), format, true);
54453 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
54454 }
db71a655
KM
54455 r = moment(m.format(format).toLocaleLowerCase(), format, true);
54456 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
54457 }
54458
54459 for (i = 0; i < 7; ++i) {
54460 m = moment.utc([2015, 0, i + 1, 18]);
54461 tester('dd');
54462 tester('ddd');
54463 tester('dddd');
54464 }
54465 });
d6651c21 54466
db71a655
KM
54467 test('valid localeData', function (assert) {
54468 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
54469 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
54470 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
54471 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
54472 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
54473 });
96d0d679
KM
54474
54475 test('localeData weekdays can localeSort', function (assert) {
54476 var weekdays = moment().localeData().weekdays();
54477 var weekdaysShort = moment().localeData().weekdaysShort();
54478 var weekdaysMin = moment().localeData().weekdaysMin();
54479 var shift = moment().localeData()._week.dow;
54480 assert.deepEqual(
54481 moment().localeData().weekdays(true),
54482 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
54483 'weekdays should localeSort');
54484 assert.deepEqual(
54485 moment().localeData().weekdaysShort(true),
54486 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
54487 'weekdaysShort should localeSort');
54488 assert.deepEqual(
54489 moment().localeData().weekdaysMin(true),
54490 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
54491 'weekdaysMin should localeSort');
54492 });
db71a655 54493 }
d6651c21 54494
db71a655
KM
54495 /*global QUnit:false*/
54496
db71a655
KM
54497 function localeModule (name, lifecycle) {
54498 QUnit.module('locale:' + name, {
c58511b9 54499 beforeEach : function () {
db71a655
KM
54500 moment.locale(name);
54501 moment.createFromInputFallback = function (config) {
54502 throw new Error('input not handled by moment: ' + config._i);
54503 };
54504 setupDeprecationHandler(test, moment, 'locale');
54505 if (lifecycle && lifecycle.setup) {
54506 lifecycle.setup();
54507 }
54508 },
c58511b9 54509 afterEach : function () {
db71a655
KM
54510 moment.locale('en');
54511 teardownDeprecationHandler(test, moment, 'locale');
54512 if (lifecycle && lifecycle.teardown) {
54513 lifecycle.teardown();
54514 }
25cc720f
IC
54515 }
54516 });
db71a655
KM
54517 defineCommonLocaleTests(name, -1, -1);
54518 }
54519
54520 localeModule('ta');
54521
54522 test('parse', function (assert) {
54523 var tests = 'ஜனவரி ஜனவரி_பிப்ரவரி பிப்ரவரி_மார்ச் மார்ச்_ஏப்ரல் ஏப்ரல்_மே மே_ஜூன் ஜூன்_ஜூலை ஜூலை_ஆகஸ்ட் ஆகஸ்ட்_செப்டெம்பர் செப்டெம்பர்_அக்டோபர் அக்டோபர்_நவம்பர் நவம்பர்_டிசம்பர் டிசம்பர்'.split('_'), i;
54524 function equalTest(input, mmm, i) {
54525 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
54526 }
54527 for (i = 0; i < 12; i++) {
54528 tests[i] = tests[i].split(' ');
54529 equalTest(tests[i][0], 'MMM', i);
54530 equalTest(tests[i][1], 'MMM', i);
54531 equalTest(tests[i][0], 'MMMM', i);
54532 equalTest(tests[i][1], 'MMMM', i);
54533 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
54534 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
54535 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
54536 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
54537 }
54538 });
54539
54540 test('format', function (assert) {
54541 var a = [
54542 ['dddd, MMMM Do YYYY, h:mm:ss a', 'ஞாயிற்றுக்கிழமை, பிப்ரவரி ௧௪வது ௨௦௧௦, ௩:௨௫:௫௦ எற்பாடு'],
54543 ['ddd, hA', 'ஞாயிறு, ௩ எற்பாடு'],
54544 ['M Mo MM MMMM MMM', '௨ ௨வது ௦௨ பிப்ரவரி பிப்ரவரி'],
54545 ['YYYY YY', '௨௦௧௦ ௧௦'],
54546 ['D Do DD', '௧௪ ௧௪வது ௧௪'],
54547 ['d do dddd ddd dd', '௦ ௦வது ஞாயிற்றுக்கிழமை ஞாயிறு ஞா'],
54548 ['DDD DDDo DDDD', '௪௫ ௪௫வது ௦௪௫'],
54549 ['w wo ww', '௮ ௮வது ௦௮'],
54550 ['h hh', '௩ ௦௩'],
54551 ['H HH', '௧௫ ௧௫'],
54552 ['m mm', '௨௫ ௨௫'],
54553 ['s ss', '௫௦ ௫௦'],
54554 ['a A', ' எற்பாடு எற்பாடு'],
54555 ['[ஆண்டின்] DDDo [நாள்]', 'ஆண்டின் ௪௫வது நாள்'],
54556 ['LTS', '௧௫:௨௫:௫௦'],
54557 ['L', '௧௪/௦௨/௨௦௧௦'],
54558 ['LL', '௧௪ பிப்ரவரி ௨௦௧௦'],
54559 ['LLL', '௧௪ பிப்ரவரி ௨௦௧௦, ௧௫:௨௫'],
54560 ['LLLL', 'ஞாயிற்றுக்கிழமை, ௧௪ பிப்ரவரி ௨௦௧௦, ௧௫:௨௫'],
54561 ['l', '௧௪/௨/௨௦௧௦'],
54562 ['ll', '௧௪ பிப்ரவரி ௨௦௧௦'],
54563 ['lll', '௧௪ பிப்ரவரி ௨௦௧௦, ௧௫:௨௫'],
54564 ['llll', 'ஞாயிறு, ௧௪ பிப்ரவரி ௨௦௧௦, ௧௫:௨௫']
54565 ],
54566 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
54567 i;
54568 for (i = 0; i < a.length; i++) {
54569 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
54570 }
54571 });
54572
54573 test('format ordinal', function (assert) {
54574 assert.equal(moment([2011, 0, 1]).format('DDDo'), '௧வது', '௧வது');
54575 assert.equal(moment([2011, 0, 2]).format('DDDo'), '௨வது', '௨வது');
54576 assert.equal(moment([2011, 0, 3]).format('DDDo'), '௩வது', '௩வது');
54577 assert.equal(moment([2011, 0, 4]).format('DDDo'), '௪வது', '௪வது');
54578 assert.equal(moment([2011, 0, 5]).format('DDDo'), '௫வது', '௫வது');
54579 assert.equal(moment([2011, 0, 6]).format('DDDo'), '௬வது', '௬வது');
54580 assert.equal(moment([2011, 0, 7]).format('DDDo'), '௭வது', '௭வது');
54581 assert.equal(moment([2011, 0, 8]).format('DDDo'), '௮வது', '௮வது');
54582 assert.equal(moment([2011, 0, 9]).format('DDDo'), '௯வது', '௯வது');
54583 assert.equal(moment([2011, 0, 10]).format('DDDo'), '௧௦வது', '௧௦வது');
54584
54585 assert.equal(moment([2011, 0, 11]).format('DDDo'), '௧௧வது', '௧௧வது');
54586 assert.equal(moment([2011, 0, 12]).format('DDDo'), '௧௨வது', '௧௨வது');
54587 assert.equal(moment([2011, 0, 13]).format('DDDo'), '௧௩வது', '௧௩வது');
54588 assert.equal(moment([2011, 0, 14]).format('DDDo'), '௧௪வது', '௧௪வது');
54589 assert.equal(moment([2011, 0, 15]).format('DDDo'), '௧௫வது', '௧௫வது');
54590 assert.equal(moment([2011, 0, 16]).format('DDDo'), '௧௬வது', '௧௬வது');
54591 assert.equal(moment([2011, 0, 17]).format('DDDo'), '௧௭வது', '௧௭வது');
54592 assert.equal(moment([2011, 0, 18]).format('DDDo'), '௧௮வது', '௧௮வது');
54593 assert.equal(moment([2011, 0, 19]).format('DDDo'), '௧௯வது', '௧௯வது');
54594 assert.equal(moment([2011, 0, 20]).format('DDDo'), '௨௦வது', '௨௦வது');
54595
54596 assert.equal(moment([2011, 0, 21]).format('DDDo'), '௨௧வது', '௨௧வது');
54597 assert.equal(moment([2011, 0, 22]).format('DDDo'), '௨௨வது', '௨௨வது');
54598 assert.equal(moment([2011, 0, 23]).format('DDDo'), '௨௩வது', '௨௩வது');
54599 assert.equal(moment([2011, 0, 24]).format('DDDo'), '௨௪வது', '௨௪வது');
54600 assert.equal(moment([2011, 0, 25]).format('DDDo'), '௨௫வது', '௨௫வது');
54601 assert.equal(moment([2011, 0, 26]).format('DDDo'), '௨௬வது', '௨௬வது');
54602 assert.equal(moment([2011, 0, 27]).format('DDDo'), '௨௭வது', '௨௭வது');
54603 assert.equal(moment([2011, 0, 28]).format('DDDo'), '௨௮வது', '௨௮வது');
54604 assert.equal(moment([2011, 0, 29]).format('DDDo'), '௨௯வது', '௨௯வது');
54605 assert.equal(moment([2011, 0, 30]).format('DDDo'), '௩௦வது', '௩௦வது');
54606
54607 assert.equal(moment([2011, 0, 31]).format('DDDo'), '௩௧வது', '௩௧வது');
54608 });
54609
54610 test('format month', function (assert) {
54611 var expected = 'ஜனவரி ஜனவரி_பிப்ரவரி பிப்ரவரி_மார்ச் மார்ச்_ஏப்ரல் ஏப்ரல்_மே மே_ஜூன் ஜூன்_ஜூலை ஜூலை_ஆகஸ்ட் ஆகஸ்ட்_செப்டெம்பர் செப்டெம்பர்_அக்டோபர் அக்டோபர்_நவம்பர் நவம்பர்_டிசம்பர் டிசம்பர்'.split('_'), i;
54612 for (i = 0; i < expected.length; i++) {
54613 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
54614 }
54615 });
54616
54617 test('format week', function (assert) {
54618 var expected = 'ஞாயிற்றுக்கிழமை ஞாயிறு ஞா_திங்கட்கிழமை திங்கள் தி_செவ்வாய்கிழமை செவ்வாய் செ_புதன்கிழமை புதன் பு_வியாழக்கிழமை வியாழன் வி_வெள்ளிக்கிழமை வெள்ளி வெ_சனிக்கிழமை சனி ச'.split('_'), i;
54619 for (i = 0; i < expected.length; i++) {
54620 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
54621 }
54622 });
54623
54624 test('from', function (assert) {
54625 var start = moment([2007, 1, 28]);
54626 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ஒரு சில விநாடிகள்', '44 விநாடிகள் = ஒரு சில விநாடிகள்');
54627 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ஒரு நிமிடம்', '45 விநாடிகள் = ஒரு நிமிடம்');
54628 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ஒரு நிமிடம்', '89 விநாடிகள் = ஒரு நிமிடம்');
54629 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '௨ நிமிடங்கள்', '90 விநாடிகள் = ௨ நிமிடங்கள்');
54630 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '௪௪ நிமிடங்கள்', '44 நிமிடங்கள் = 44 நிமிடங்கள்');
54631 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ஒரு மணி நேரம்', '45 நிமிடங்கள் = ஒரு மணி நேரம்');
54632 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ஒரு மணி நேரம்', '89 நிமிடங்கள் = ஒரு மணி நேரம்');
54633 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '௨ மணி நேரம்', '90 நிமிடங்கள் = ௨ மணி நேரம்');
54634 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '௫ மணி நேரம்', '5 மணி நேரம் = 5 மணி நேரம்');
54635 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '௨௧ மணி நேரம்', '௨௧ மணி நேரம் = ௨௧ மணி நேரம்');
54636 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ஒரு நாள்', '௨௨ மணி நேரம் = ஒரு நாள்');
54637 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ஒரு நாள்', '௩5 மணி நேரம் = ஒரு நாள்');
54638 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '௨ நாட்கள்', '௩6 மணி நேரம் = ௨ days');
54639 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ஒரு நாள்', '௧ நாள் = ஒரு நாள்');
54640 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '௫ நாட்கள்', '5 நாட்கள் = 5 நாட்கள்');
54641 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '௨௫ நாட்கள்', '௨5 நாட்கள் = ௨5 நாட்கள்');
54642 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ஒரு மாதம்', '௨6 நாட்கள் = ஒரு மாதம்');
54643 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ஒரு மாதம்', '௩0 நாட்கள் = ஒரு மாதம்');
54644 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ஒரு மாதம்', '45 நாட்கள் = ஒரு மாதம்');
54645 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '௨ மாதங்கள்', '46 நாட்கள் = ௨ மாதங்கள்');
54646 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '௨ மாதங்கள்', '75 நாட்கள் = ௨ மாதங்கள்');
54647 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '௩ மாதங்கள்', '76 நாட்கள் = ௩ மாதங்கள்');
54648 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ஒரு மாதம்', '௧ மாதம் = ஒரு மாதம்');
54649 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '௫ மாதங்கள்', '5 மாதங்கள் = 5 மாதங்கள்');
54650 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ஒரு வருடம்', '௩45 நாட்கள் = ஒரு வருடம்');
54651 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '௨ ஆண்டுகள்', '548 நாட்கள் = ௨ ஆண்டுகள்');
54652 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ஒரு வருடம்', '௧ வருடம் = ஒரு வருடம்');
54653 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '௫ ஆண்டுகள்', '5 ஆண்டுகள் = 5 ஆண்டுகள்');
54654 });
54655
54656 test('suffix', function (assert) {
54657 assert.equal(moment(30000).from(0), 'ஒரு சில விநாடிகள் இல்', 'prefix');
54658 assert.equal(moment(0).from(30000), 'ஒரு சில விநாடிகள் முன்', 'suffix');
54659 });
54660
54661 test('now from now', function (assert) {
54662 assert.equal(moment().fromNow(), 'ஒரு சில விநாடிகள் முன்', 'இப்போது இருந்து கடந்த காலத்தில் காட்ட வேண்டும்');
54663 });
54664
54665 test('fromNow', function (assert) {
54666 assert.equal(moment().add({s: 30}).fromNow(), 'ஒரு சில விநாடிகள் இல்', 'ஒரு சில விநாடிகள் இல்');
54667 assert.equal(moment().add({d: 5}).fromNow(), '௫ நாட்கள் இல்', '5 நாட்கள் இல்');
54668 });
54669
54670 test('calendar day', function (assert) {
54671 var a = moment().hours(12).minutes(0).seconds(0);
54672
54673 assert.equal(moment(a).calendar(), 'இன்று ௧௨:௦௦', 'இன்று 12:00');
54674 assert.equal(moment(a).add({m: 25}).calendar(), 'இன்று ௧௨:௨௫', 'இன்று 12:25');
54675 assert.equal(moment(a).add({h: 1}).calendar(), 'இன்று ௧௩:௦௦', 'இன்று 13:00');
54676 assert.equal(moment(a).add({d: 1}).calendar(), 'நாளை ௧௨:௦௦', 'நாளை 12:00');
54677 assert.equal(moment(a).subtract({h: 1}).calendar(), 'இன்று ௧௧:௦௦', 'இன்று 11:00');
54678 assert.equal(moment(a).subtract({d: 1}).calendar(), 'நேற்று ௧௨:௦௦', 'நேற்று 12:00');
54679 });
54680
54681 test('calendar next week', function (assert) {
54682 var i, m;
54683 for (i = 2; i < 7; i++) {
54684 m = moment().add({d: i});
54685 assert.equal(m.calendar(), m.format('dddd, LT'), 'Today + ' + i + ' days current time');
54686 m.hours(0).minutes(0).seconds(0).milliseconds(0);
54687 assert.equal(m.calendar(), m.format('dddd, LT'), 'Today + ' + i + ' days beginning of day');
54688 m.hours(23).minutes(59).seconds(59).milliseconds(999);
54689 assert.equal(m.calendar(), m.format('dddd, LT'), 'Today + ' + i + ' days end of day');
73f3c911 54690 }
db71a655 54691 });
25cc720f 54692
db71a655
KM
54693 test('calendar last week', function (assert) {
54694 var i, m;
54695
54696 for (i = 2; i < 7; i++) {
54697 m = moment().subtract({d: i});
54698 assert.equal(m.calendar(), m.format('[கடந்த வாரம்] dddd, LT'), 'Today - ' + i + ' days current time');
54699 m.hours(0).minutes(0).seconds(0).milliseconds(0);
54700 assert.equal(m.calendar(), m.format('[கடந்த வாரம்] dddd, LT'), 'Today - ' + i + ' days beginning of day');
54701 m.hours(23).minutes(59).seconds(59).milliseconds(999);
54702 assert.equal(m.calendar(), m.format('[கடந்த வாரம்] dddd, LT'), 'Today - ' + i + ' days end of day');
516f5f67 54703 }
db71a655 54704 });
516f5f67 54705
db71a655
KM
54706 test('calendar all else', function (assert) {
54707 var weeksAgo = moment().subtract({w: 1}),
54708 weeksFromNow = moment().add({w: 1});
516f5f67 54709
db71a655
KM
54710 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
54711 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 54712
db71a655
KM
54713 weeksAgo = moment().subtract({w: 2});
54714 weeksFromNow = moment().add({w: 2});
516f5f67 54715
db71a655
KM
54716 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
54717 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
54718 });
54719
54720 test('meridiem', function (assert) {
54721 assert.equal(moment([2011, 2, 23, 0, 30]).format('a'), ' யாமம்', '(after) midnight');
54722 assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), ' வைகறை', 'before dawn');
54723 assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), ' காலை', 'morning');
54724 assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), ' எற்பாடு', 'during day');
54725 assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), ' எற்பாடு', 'evening');
54726 assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), ' மாலை', 'late evening');
54727 assert.equal(moment([2011, 2, 23, 23, 30]).format('a'), ' யாமம்', '(before) midnight');
54728 });
9483e2a4 54729
73f3c911
IC
54730})));
54731
516f5f67 54732
c74a101d
IC
54733;(function (global, factory) {
54734 typeof exports === 'object' && typeof module !== 'undefined'
54735 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
54736 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
54737 factory(global.moment)
73f3c911 54738}(this, (function (moment) { 'use strict';
516f5f67 54739
db71a655
KM
54740 function each(array, callback) {
54741 var i;
54742 for (i = 0; i < array.length; i++) {
54743 callback(array[i], i, array);
54744 }
b135bf1a
IC
54745 }
54746
c58511b9
KM
54747 function setupDeprecationHandler(test, moment$$1, scope) {
54748 test._expectedDeprecations = null;
54749 test._observedDeprecations = null;
54750 test._oldSupress = moment$$1.suppressDeprecationWarnings;
54751 moment$$1.suppressDeprecationWarnings = true;
54752 test.expectedDeprecations = function () {
54753 test._expectedDeprecations = arguments;
54754 test._observedDeprecations = [];
54755 };
54756 moment$$1.deprecationHandler = function (name, msg) {
54757 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
54758 if (deprecationId === -1) {
54759 throw new Error('Unexpected deprecation thrown name=' +
54760 name + ' msg=' + msg);
54761 }
54762 test._observedDeprecations[deprecationId] = 1;
54763 };
54764 }
54765
54766 function teardownDeprecationHandler(test, moment$$1, scope) {
54767 moment$$1.suppressDeprecationWarnings = test._oldSupress;
54768
54769 if (test._expectedDeprecations != null) {
54770 var missedDeprecations = [];
54771 each(test._expectedDeprecations, function (deprecationPattern, id) {
54772 if (test._observedDeprecations[id] !== 1) {
54773 missedDeprecations.push(deprecationPattern);
54774 }
54775 });
54776 if (missedDeprecations.length !== 0) {
54777 throw new Error('Expected deprecation warnings did not happen: ' +
54778 missedDeprecations.join(' '));
54779 }
54780 }
54781 }
54782
54783 function matchedDeprecation(name, msg, deprecations) {
54784 if (deprecations == null) {
54785 return -1;
54786 }
54787 for (var i = 0; i < deprecations.length; ++i) {
54788 if (name != null && name === deprecations[i]) {
54789 return i;
54790 }
54791 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
54792 return i;
54793 }
54794 }
54795 return -1;
54796 }
54797
54798 /*global QUnit:false*/
54799
54800 var test = QUnit.test;
54801
db71a655
KM
54802 function objectKeys(obj) {
54803 if (Object.keys) {
54804 return Object.keys(obj);
54805 } else {
54806 // IE8
54807 var res = [], i;
54808 for (i in obj) {
54809 if (obj.hasOwnProperty(i)) {
54810 res.push(i);
54811 }
b135bf1a 54812 }
db71a655 54813 return res;
b135bf1a
IC
54814 }
54815 }
b135bf1a 54816
db71a655 54817 // Pick the first defined of two or three arguments.
b135bf1a 54818
db71a655
KM
54819 function defineCommonLocaleTests(locale, options) {
54820 test('lenient day of month ordinal parsing', function (assert) {
54821 var i, ordinalStr, testMoment;
54822 for (i = 1; i <= 31; ++i) {
54823 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
54824 testMoment = moment(ordinalStr, 'YYYY MM Do');
54825 assert.equal(testMoment.year(), 2014,
54826 'lenient day of month ordinal parsing ' + i + ' year check');
54827 assert.equal(testMoment.month(), 0,
54828 'lenient day of month ordinal parsing ' + i + ' month check');
54829 assert.equal(testMoment.date(), i,
54830 'lenient day of month ordinal parsing ' + i + ' date check');
54831 }
b135bf1a 54832 });
d6651c21 54833
db71a655
KM
54834 test('lenient day of month ordinal parsing of number', function (assert) {
54835 var i, testMoment;
54836 for (i = 1; i <= 31; ++i) {
54837 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
54838 assert.equal(testMoment.year(), 2014,
54839 'lenient day of month ordinal parsing of number ' + i + ' year check');
54840 assert.equal(testMoment.month(), 0,
54841 'lenient day of month ordinal parsing of number ' + i + ' month check');
54842 assert.equal(testMoment.date(), i,
54843 'lenient day of month ordinal parsing of number ' + i + ' date check');
516f5f67
IC
54844 }
54845 });
516f5f67 54846
db71a655
KM
54847 test('strict day of month ordinal parsing', function (assert) {
54848 var i, ordinalStr, testMoment;
54849 for (i = 1; i <= 31; ++i) {
54850 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
54851 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
54852 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
54853 }
54854 });
516f5f67 54855
db71a655
KM
54856 test('meridiem invariant', function (assert) {
54857 var h, m, t1, t2;
54858 for (h = 0; h < 24; ++h) {
54859 for (m = 0; m < 60; m += 15) {
54860 t1 = moment.utc([2000, 0, 1, h, m]);
54861 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
54862 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
54863 'meridiem at ' + t1.format('HH:mm'));
54864 }
73f3c911 54865 }
db71a655 54866 });
73f3c911 54867
db71a655
KM
54868 test('date format correctness', function (assert) {
54869 var data, tokens;
54870 data = moment.localeData()._longDateFormat;
54871 tokens = objectKeys(data);
54872 each(tokens, function (srchToken) {
54873 // Check each format string to make sure it does not contain any
54874 // tokens that need to be expanded.
54875 each(tokens, function (baseToken) {
54876 // strip escaped sequences
54877 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
54878 assert.equal(false, !!~format.indexOf(srchToken),
54879 'contains ' + srchToken + ' in ' + baseToken);
54880 });
54881 });
54882 });
73f3c911 54883
db71a655
KM
54884 test('month parsing correctness', function (assert) {
54885 var i, m;
54886
54887 if (locale === 'tr') {
54888 // I can't fix it :(
c58511b9 54889 assert.expect(0);
db71a655
KM
54890 return;
54891 }
54892 function tester(format) {
54893 var r;
54894 r = moment(m.format(format), format);
54895 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
54896 if (locale !== 'ka') {
54897 r = moment(m.format(format).toLocaleUpperCase(), format);
54898 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
54899 }
db71a655
KM
54900 r = moment(m.format(format).toLocaleLowerCase(), format);
54901 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
54902
54903 r = moment(m.format(format), format, true);
54904 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
54905 if (locale !== 'ka') {
54906 r = moment(m.format(format).toLocaleUpperCase(), format, true);
54907 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
54908 }
db71a655
KM
54909 r = moment(m.format(format).toLocaleLowerCase(), format, true);
54910 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
54911 }
54912
54913 for (i = 0; i < 12; ++i) {
54914 m = moment([2015, i, 15, 18]);
54915 tester('MMM');
54916 tester('MMM.');
54917 tester('MMMM');
54918 tester('MMMM.');
54919 }
54920 });
516f5f67 54921
db71a655
KM
54922 test('weekday parsing correctness', function (assert) {
54923 var i, m;
54924
96d0d679 54925 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
54926 // tr, az: There is a lower-case letter (ı), that converted to
54927 // upper then lower changes to i
54928 // ro: there is the letter ț which behaves weird under IE8
54929 // mt: letter Ħ
96d0d679 54930 // ga: month with spaces
c58511b9 54931 assert.expect(0);
db71a655
KM
54932 return;
54933 }
54934 function tester(format) {
54935 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
54936 r = moment(m.format(format), format);
54937 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
54938 if (locale !== 'ka') {
54939 r = moment(m.format(format).toLocaleUpperCase(), format);
54940 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
54941 }
db71a655
KM
54942 r = moment(m.format(format).toLocaleLowerCase(), format);
54943 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
54944 r = moment(m.format(format), format, true);
54945 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
54946 if (locale !== 'ka') {
54947 r = moment(m.format(format).toLocaleUpperCase(), format, true);
54948 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
54949 }
db71a655
KM
54950 r = moment(m.format(format).toLocaleLowerCase(), format, true);
54951 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
54952 }
54953
54954 for (i = 0; i < 7; ++i) {
54955 m = moment.utc([2015, 0, i + 1, 18]);
54956 tester('dd');
54957 tester('ddd');
54958 tester('dddd');
54959 }
54960 });
516f5f67 54961
db71a655
KM
54962 test('valid localeData', function (assert) {
54963 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
54964 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
54965 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
54966 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
54967 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
54968 });
96d0d679
KM
54969
54970 test('localeData weekdays can localeSort', function (assert) {
54971 var weekdays = moment().localeData().weekdays();
54972 var weekdaysShort = moment().localeData().weekdaysShort();
54973 var weekdaysMin = moment().localeData().weekdaysMin();
54974 var shift = moment().localeData()._week.dow;
54975 assert.deepEqual(
54976 moment().localeData().weekdays(true),
54977 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
54978 'weekdays should localeSort');
54979 assert.deepEqual(
54980 moment().localeData().weekdaysShort(true),
54981 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
54982 'weekdaysShort should localeSort');
54983 assert.deepEqual(
54984 moment().localeData().weekdaysMin(true),
54985 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
54986 'weekdaysMin should localeSort');
54987 });
b135bf1a
IC
54988 }
54989
db71a655 54990 /*global QUnit:false*/
d6651c21 54991
db71a655
KM
54992 function localeModule (name, lifecycle) {
54993 QUnit.module('locale:' + name, {
c58511b9 54994 beforeEach : function () {
db71a655
KM
54995 moment.locale(name);
54996 moment.createFromInputFallback = function (config) {
54997 throw new Error('input not handled by moment: ' + config._i);
54998 };
54999 setupDeprecationHandler(test, moment, 'locale');
55000 if (lifecycle && lifecycle.setup) {
55001 lifecycle.setup();
55002 }
55003 },
c58511b9 55004 afterEach : function () {
db71a655
KM
55005 moment.locale('en');
55006 teardownDeprecationHandler(test, moment, 'locale');
55007 if (lifecycle && lifecycle.teardown) {
55008 lifecycle.teardown();
55009 }
55010 }
55011 });
55012 defineCommonLocaleTests(name, -1, -1);
55013 }
55014
55015 localeModule('te');
55016
55017 test('parse', function (assert) {
96d0d679 55018 var tests = 'జనవరి జన._ఫిబ్రవరి ఫిబ్ర._మార్చి మార్చి_ఏప్రిల్ ఏప్రి._మే మే_జూన్ జూన్_జులై జులై_ఆగస్టు ఆగ._సెప్టెంబర్ సెప్._అక్టోబర్ అక్టో._నవంబర్ నవ._డిసెంబర్ డిసె.'.split('_'), i;
db71a655
KM
55019 function equalTest(input, mmm, i) {
55020 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
55021 }
55022 for (i = 0; i < 12; i++) {
55023 tests[i] = tests[i].split(' ');
55024 equalTest(tests[i][0], 'MMM', i);
55025 equalTest(tests[i][1], 'MMM', i);
55026 equalTest(tests[i][0], 'MMMM', i);
55027 equalTest(tests[i][1], 'MMMM', i);
55028 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
55029 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
55030 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
55031 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
55032 }
55033 });
55034
55035 test('format', function (assert) {
55036 var a = [
55037 ['dddd, Do తేదీ MMMM YYYY, a h:mm:ss', 'ఆదివారం, 14వ తేదీ ఫిబ్రవరి 2010, మధ్యాహ్నం 3:25:50'],
55038 ['ddd, a h గంటలు', 'ఆది, మధ్యాహ్నం 3 గంటలు'],
55039 ['M Mo నెల MM MMMM MMM', '2 2వ నెల 02 ఫిబ్రవరి ఫిబ్ర.'],
55040 ['YYYY YY', '2010 10'],
55041 ['D Do DD', '14 14వ 14'],
55042 ['d do dddd ddd dd', '0 0వ ఆదివారం ఆది ఆ'],
55043 ['DDD DDDo DDDD', '45 45వ 045'],
55044 ['w wo ww', '8 8వ 08'],
55045 ['h hh', '3 03'],
55046 ['H HH', '15 15'],
55047 ['m mm', '25 25'],
55048 ['s ss', '50 50'],
55049 ['a A', 'మధ్యాహ్నం మధ్యాహ్నం'],
55050 ['LTS', 'మధ్యాహ్నం 3:25:50'],
55051 ['L', '14/02/2010'],
55052 ['LL', '14 ఫిబ్రవరి 2010'],
55053 ['LLL', '14 ఫిబ్రవరి 2010, మధ్యాహ్నం 3:25'],
55054 ['LLLL', 'ఆదివారం, 14 ఫిబ్రవరి 2010, మధ్యాహ్నం 3:25'],
55055 ['l', '14/2/2010'],
55056 ['ll', '14 ఫిబ్ర. 2010'],
55057 ['lll', '14 ఫిబ్ర. 2010, మధ్యాహ్నం 3:25'],
55058 ['llll', 'ఆది, 14 ఫిబ్ర. 2010, మధ్యాహ్నం 3:25']
55059 ],
55060 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
55061 i;
55062 for (i = 0; i < a.length; i++) {
55063 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
55064 }
55065 });
55066
55067 test('format ordinal', function (assert) {
55068 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1వ', '1వ');
55069 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2వ', '2వ');
55070 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3వ', '3వ');
55071 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4వ', '4వ');
55072 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5వ', '5వ');
55073 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6వ', '6వ');
55074 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7వ', '7వ');
55075 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8వ', '8వ');
55076 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9వ', '9వ');
55077 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10వ', '10వ');
55078
55079 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11వ', '11వ');
55080 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12వ', '12వ');
55081 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13వ', '13వ');
55082 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14వ', '14వ');
55083 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15వ', '15వ');
55084 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16వ', '16వ');
55085 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17వ', '17వ');
55086 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18వ', '18వ');
55087 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19వ', '19వ');
55088 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20వ', '20వ');
55089
55090 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21వ', '21వ');
55091 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22వ', '22వ');
55092 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23వ', '23వ');
55093 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24వ', '24వ');
55094 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25వ', '25వ');
55095 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26వ', '26వ');
55096 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27వ', '27వ');
55097 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28వ', '28వ');
55098 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29వ', '29వ');
55099 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30వ', '30వ');
55100
55101 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31వ', '31వ');
55102 });
55103
55104 test('format month', function (assert) {
96d0d679 55105 var expected = 'జనవరి జన._ఫిబ్రవరి ఫిబ్ర._మార్చి మార్చి_ఏప్రిల్ ఏప్రి._మే మే_జూన్ జూన్_జులై జులై_ఆగస్టు ఆగ._సెప్టెంబర్ సెప్._అక్టోబర్ అక్టో._నవంబర్ నవ._డిసెంబర్ డిసె.'.split('_'), i;
db71a655
KM
55106 for (i = 0; i < expected.length; i++) {
55107 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
55108 }
55109 });
55110
55111 test('format week', function (assert) {
55112 var expected = 'ఆదివారం ఆది ఆ_సోమవారం సోమ సో_మంగళవారం మంగళ మం_బుధవారం బుధ బు_గురువారం గురు గు_శుక్రవారం శుక్ర శు_శనివారం శని శ'.split('_'), i;
55113 for (i = 0; i < expected.length; i++) {
55114 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
55115 }
55116 });
55117
55118 test('from', function (assert) {
55119 var start = moment([2007, 1, 28]);
55120 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'కొన్ని క్షణాలు', '44 seconds = a few seconds');
55121 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ఒక నిమిషం', '45 seconds = a minute');
55122 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ఒక నిమిషం', '89 seconds = a minute');
55123 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 నిమిషాలు', '90 seconds = 2 minutes');
55124 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 నిమిషాలు', '44 minutes = 44 minutes');
55125 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ఒక గంట', '45 minutes = an hour');
55126 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ఒక గంట', '89 minutes = an hour');
55127 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 గంటలు', '90 minutes = 2 hours');
55128 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 గంటలు', '5 hours = 5 hours');
55129 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 గంటలు', '21 hours = 21 hours');
55130 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ఒక రోజు', '22 hours = a day');
55131 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ఒక రోజు', '35 hours = a day');
55132 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 రోజులు', '36 hours = 2 days');
55133 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ఒక రోజు', '1 day = a day');
55134 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 రోజులు', '5 days = 5 days');
55135 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 రోజులు', '25 days = 25 days');
55136 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ఒక నెల', '26 days = a month');
55137 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ఒక నెల', '30 days = a month');
55138 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ఒక నెల', '43 days = a month');
55139 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 నెలలు', '46 days = 2 months');
55140 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 నెలలు', '75 days = 2 months');
55141 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 నెలలు', '76 days = 3 months');
55142 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ఒక నెల', '1 month = a month');
55143 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 నెలలు', '5 months = 5 months');
55144 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ఒక సంవత్సరం', '345 days = a year');
55145 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 సంవత్సరాలు', '548 days = 2 years');
55146 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ఒక సంవత్సరం', '1 year = a year');
55147 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 సంవత్సరాలు', '5 years = 5 years');
55148 });
55149
55150 test('suffix', function (assert) {
55151 assert.equal(moment(30000).from(0), 'కొన్ని క్షణాలు లో', 'prefix');
55152 assert.equal(moment(0).from(30000), 'కొన్ని క్షణాలు క్రితం', 'suffix');
55153 });
55154
55155 test('now from now', function (assert) {
55156 assert.equal(moment().fromNow(), 'కొన్ని క్షణాలు క్రితం', 'now from now should display as in the past');
55157 });
55158
55159 test('fromNow', function (assert) {
55160 assert.equal(moment().add({s: 30}).fromNow(), 'కొన్ని క్షణాలు లో', 'కొన్ని క్షణాలు లో');
55161 assert.equal(moment().add({d: 5}).fromNow(), '5 రోజులు లో', '5 రోజులు లో');
55162 });
55163
55164 test('calendar day', function (assert) {
55165 var a = moment().hours(12).minutes(0).seconds(0);
55166
55167 assert.equal(moment(a).calendar(), 'నేడు మధ్యాహ్నం 12:00', 'today at the same time');
55168 assert.equal(moment(a).add({m: 25}).calendar(), 'నేడు మధ్యాహ్నం 12:25', 'Now plus 25 min');
55169 assert.equal(moment(a).add({h: 3}).calendar(), 'నేడు మధ్యాహ్నం 3:00', 'Now plus 3 hours');
55170 assert.equal(moment(a).add({d: 1}).calendar(), 'రేపు మధ్యాహ్నం 12:00', 'tomorrow at the same time');
55171 assert.equal(moment(a).subtract({h: 1}).calendar(), 'నేడు మధ్యాహ్నం 11:00', 'Now minus 1 hour');
55172 assert.equal(moment(a).subtract({d: 1}).calendar(), 'నిన్న మధ్యాహ్నం 12:00', 'yesterday at the same time');
55173 });
55174
55175 test('calendar next week', function (assert) {
55176 var i, m;
55177 for (i = 2; i < 7; i++) {
55178 m = moment().add({d: i});
55179 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days current time');
55180 m.hours(0).minutes(0).seconds(0).milliseconds(0);
55181 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days beginning of day');
55182 m.hours(23).minutes(59).seconds(59).milliseconds(999);
55183 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days end of day');
73f3c911 55184 }
516f5f67
IC
55185 });
55186
db71a655 55187 test('calendar last week', function (assert) {
73f3c911 55188 var i, m;
c74a101d 55189
db71a655
KM
55190 for (i = 2; i < 7; i++) {
55191 m = moment().subtract({d: i});
55192 assert.equal(m.calendar(), m.format('[గత] dddd[,] LT'), 'Today - ' + i + ' days current time');
55193 m.hours(0).minutes(0).seconds(0).milliseconds(0);
55194 assert.equal(m.calendar(), m.format('[గత] dddd[,] LT'), 'Today - ' + i + ' days beginning of day');
55195 m.hours(23).minutes(59).seconds(59).milliseconds(999);
55196 assert.equal(m.calendar(), m.format('[గత] dddd[,] LT'), 'Today - ' + i + ' days end of day');
c74a101d 55197 }
db71a655 55198 });
c74a101d 55199
db71a655
KM
55200 test('calendar all else', function (assert) {
55201 var weeksAgo = moment().subtract({w: 1}),
55202 weeksFromNow = moment().add({w: 1});
73f3c911 55203
db71a655
KM
55204 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
55205 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
c74a101d 55206
db71a655
KM
55207 weeksAgo = moment().subtract({w: 2});
55208 weeksFromNow = moment().add({w: 2});
516f5f67 55209
db71a655
KM
55210 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
55211 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
55212 });
516f5f67 55213
db71a655
KM
55214 test('meridiem', function (assert) {
55215 assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), 'రాత్రి', 'before dawn');
55216 assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), 'ఉదయం', 'morning');
55217 assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), 'మధ్యాహ్నం', 'during day');
55218 assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), 'సాయంత్రం', 'evening');
55219 assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), 'సాయంత్రం', 'late evening');
55220 assert.equal(moment([2011, 2, 23, 21, 20]).format('a'), 'రాత్రి', 'night');
516f5f67 55221
db71a655
KM
55222 assert.equal(moment([2011, 2, 23, 2, 30]).format('A'), 'రాత్రి', 'before dawn');
55223 assert.equal(moment([2011, 2, 23, 9, 30]).format('A'), 'ఉదయం', 'morning');
55224 assert.equal(moment([2011, 2, 23, 14, 30]).format('A'), 'మధ్యాహ్నం', ' during day');
55225 assert.equal(moment([2011, 2, 23, 17, 30]).format('A'), 'సాయంత్రం', 'evening');
55226 assert.equal(moment([2011, 2, 23, 19, 30]).format('A'), 'సాయంత్రం', 'late evening');
55227 assert.equal(moment([2011, 2, 23, 21, 20]).format('A'), 'రాత్రి', 'night');
55228 });
516f5f67 55229
db71a655
KM
55230 test('weeks year starting sunday formatted', function (assert) {
55231 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1వ', 'Jan 1 2012 should be week 1');
55232 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1వ', 'Jan 7 2012 should be week 1');
55233 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2వ', 'Jan 8 2012 should be week 2');
55234 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2వ', 'Jan 14 2012 should be week 2');
55235 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3వ', 'Jan 15 2012 should be week 3');
55236 });
73f3c911
IC
55237
55238})));
55239
516f5f67 55240
c74a101d
IC
55241;(function (global, factory) {
55242 typeof exports === 'object' && typeof module !== 'undefined'
55243 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
55244 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
55245 factory(global.moment)
73f3c911 55246}(this, (function (moment) { 'use strict';
516f5f67 55247
db71a655
KM
55248 function each(array, callback) {
55249 var i;
55250 for (i = 0; i < array.length; i++) {
55251 callback(array[i], i, array);
55252 }
b135bf1a
IC
55253 }
55254
c58511b9
KM
55255 function setupDeprecationHandler(test, moment$$1, scope) {
55256 test._expectedDeprecations = null;
55257 test._observedDeprecations = null;
55258 test._oldSupress = moment$$1.suppressDeprecationWarnings;
55259 moment$$1.suppressDeprecationWarnings = true;
55260 test.expectedDeprecations = function () {
55261 test._expectedDeprecations = arguments;
55262 test._observedDeprecations = [];
55263 };
55264 moment$$1.deprecationHandler = function (name, msg) {
55265 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
55266 if (deprecationId === -1) {
55267 throw new Error('Unexpected deprecation thrown name=' +
55268 name + ' msg=' + msg);
55269 }
55270 test._observedDeprecations[deprecationId] = 1;
55271 };
55272 }
55273
55274 function teardownDeprecationHandler(test, moment$$1, scope) {
55275 moment$$1.suppressDeprecationWarnings = test._oldSupress;
55276
55277 if (test._expectedDeprecations != null) {
55278 var missedDeprecations = [];
55279 each(test._expectedDeprecations, function (deprecationPattern, id) {
55280 if (test._observedDeprecations[id] !== 1) {
55281 missedDeprecations.push(deprecationPattern);
55282 }
55283 });
55284 if (missedDeprecations.length !== 0) {
55285 throw new Error('Expected deprecation warnings did not happen: ' +
55286 missedDeprecations.join(' '));
55287 }
55288 }
55289 }
55290
55291 function matchedDeprecation(name, msg, deprecations) {
55292 if (deprecations == null) {
55293 return -1;
55294 }
55295 for (var i = 0; i < deprecations.length; ++i) {
55296 if (name != null && name === deprecations[i]) {
55297 return i;
55298 }
55299 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
55300 return i;
55301 }
55302 }
55303 return -1;
55304 }
55305
55306 /*global QUnit:false*/
55307
55308 var test = QUnit.test;
55309
db71a655
KM
55310 function objectKeys(obj) {
55311 if (Object.keys) {
55312 return Object.keys(obj);
55313 } else {
55314 // IE8
55315 var res = [], i;
55316 for (i in obj) {
55317 if (obj.hasOwnProperty(i)) {
55318 res.push(i);
55319 }
b135bf1a 55320 }
db71a655 55321 return res;
b135bf1a
IC
55322 }
55323 }
55324
db71a655 55325 // Pick the first defined of two or three arguments.
73f3c911 55326
db71a655
KM
55327 function defineCommonLocaleTests(locale, options) {
55328 test('lenient day of month ordinal parsing', function (assert) {
55329 var i, ordinalStr, testMoment;
55330 for (i = 1; i <= 31; ++i) {
55331 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
55332 testMoment = moment(ordinalStr, 'YYYY MM Do');
55333 assert.equal(testMoment.year(), 2014,
55334 'lenient day of month ordinal parsing ' + i + ' year check');
55335 assert.equal(testMoment.month(), 0,
55336 'lenient day of month ordinal parsing ' + i + ' month check');
55337 assert.equal(testMoment.date(), i,
55338 'lenient day of month ordinal parsing ' + i + ' date check');
55339 }
55340 });
b135bf1a 55341
db71a655
KM
55342 test('lenient day of month ordinal parsing of number', function (assert) {
55343 var i, testMoment;
55344 for (i = 1; i <= 31; ++i) {
55345 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
55346 assert.equal(testMoment.year(), 2014,
55347 'lenient day of month ordinal parsing of number ' + i + ' year check');
55348 assert.equal(testMoment.month(), 0,
55349 'lenient day of month ordinal parsing of number ' + i + ' month check');
55350 assert.equal(testMoment.date(), i,
55351 'lenient day of month ordinal parsing of number ' + i + ' date check');
55352 }
b135bf1a
IC
55353 });
55354
db71a655
KM
55355 test('strict day of month ordinal parsing', function (assert) {
55356 var i, ordinalStr, testMoment;
55357 for (i = 1; i <= 31; ++i) {
55358 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
55359 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
55360 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
55361 }
55362 });
b135bf1a 55363
db71a655
KM
55364 test('meridiem invariant', function (assert) {
55365 var h, m, t1, t2;
55366 for (h = 0; h < 24; ++h) {
55367 for (m = 0; m < 60; m += 15) {
55368 t1 = moment.utc([2000, 0, 1, h, m]);
55369 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
55370 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
55371 'meridiem at ' + t1.format('HH:mm'));
55372 }
55373 }
55374 });
d6651c21 55375
db71a655
KM
55376 test('date format correctness', function (assert) {
55377 var data, tokens;
55378 data = moment.localeData()._longDateFormat;
55379 tokens = objectKeys(data);
55380 each(tokens, function (srchToken) {
55381 // Check each format string to make sure it does not contain any
55382 // tokens that need to be expanded.
55383 each(tokens, function (baseToken) {
55384 // strip escaped sequences
55385 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
55386 assert.equal(false, !!~format.indexOf(srchToken),
55387 'contains ' + srchToken + ' in ' + baseToken);
55388 });
55389 });
55390 });
d6651c21 55391
db71a655
KM
55392 test('month parsing correctness', function (assert) {
55393 var i, m;
55394
55395 if (locale === 'tr') {
55396 // I can't fix it :(
c58511b9 55397 assert.expect(0);
db71a655
KM
55398 return;
55399 }
55400 function tester(format) {
55401 var r;
55402 r = moment(m.format(format), format);
55403 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
55404 if (locale !== 'ka') {
55405 r = moment(m.format(format).toLocaleUpperCase(), format);
55406 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
55407 }
db71a655
KM
55408 r = moment(m.format(format).toLocaleLowerCase(), format);
55409 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
55410
55411 r = moment(m.format(format), format, true);
55412 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
55413 if (locale !== 'ka') {
55414 r = moment(m.format(format).toLocaleUpperCase(), format, true);
55415 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
55416 }
db71a655
KM
55417 r = moment(m.format(format).toLocaleLowerCase(), format, true);
55418 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
55419 }
55420
55421 for (i = 0; i < 12; ++i) {
55422 m = moment([2015, i, 15, 18]);
55423 tester('MMM');
55424 tester('MMM.');
55425 tester('MMMM');
55426 tester('MMMM.');
55427 }
55428 });
d6651c21 55429
db71a655
KM
55430 test('weekday parsing correctness', function (assert) {
55431 var i, m;
55432
96d0d679 55433 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
55434 // tr, az: There is a lower-case letter (ı), that converted to
55435 // upper then lower changes to i
55436 // ro: there is the letter ț which behaves weird under IE8
55437 // mt: letter Ħ
96d0d679 55438 // ga: month with spaces
c58511b9 55439 assert.expect(0);
db71a655
KM
55440 return;
55441 }
55442 function tester(format) {
55443 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
55444 r = moment(m.format(format), format);
55445 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
55446 if (locale !== 'ka') {
55447 r = moment(m.format(format).toLocaleUpperCase(), format);
55448 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
55449 }
db71a655
KM
55450 r = moment(m.format(format).toLocaleLowerCase(), format);
55451 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
55452 r = moment(m.format(format), format, true);
55453 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
55454 if (locale !== 'ka') {
55455 r = moment(m.format(format).toLocaleUpperCase(), format, true);
55456 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
55457 }
db71a655
KM
55458 r = moment(m.format(format).toLocaleLowerCase(), format, true);
55459 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
55460 }
55461
55462 for (i = 0; i < 7; ++i) {
55463 m = moment.utc([2015, 0, i + 1, 18]);
55464 tester('dd');
55465 tester('ddd');
55466 tester('dddd');
55467 }
55468 });
d6651c21 55469
db71a655
KM
55470 test('valid localeData', function (assert) {
55471 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
55472 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
55473 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
55474 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
55475 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
55476 });
96d0d679
KM
55477
55478 test('localeData weekdays can localeSort', function (assert) {
55479 var weekdays = moment().localeData().weekdays();
55480 var weekdaysShort = moment().localeData().weekdaysShort();
55481 var weekdaysMin = moment().localeData().weekdaysMin();
55482 var shift = moment().localeData()._week.dow;
55483 assert.deepEqual(
55484 moment().localeData().weekdays(true),
55485 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
55486 'weekdays should localeSort');
55487 assert.deepEqual(
55488 moment().localeData().weekdaysShort(true),
55489 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
55490 'weekdaysShort should localeSort');
55491 assert.deepEqual(
55492 moment().localeData().weekdaysMin(true),
55493 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
55494 'weekdaysMin should localeSort');
55495 });
db71a655 55496 }
d6651c21 55497
db71a655 55498 /*global QUnit:false*/
516f5f67 55499
db71a655
KM
55500 function localeModule (name, lifecycle) {
55501 QUnit.module('locale:' + name, {
c58511b9 55502 beforeEach : function () {
db71a655
KM
55503 moment.locale(name);
55504 moment.createFromInputFallback = function (config) {
55505 throw new Error('input not handled by moment: ' + config._i);
55506 };
55507 setupDeprecationHandler(test, moment, 'locale');
55508 if (lifecycle && lifecycle.setup) {
55509 lifecycle.setup();
55510 }
55511 },
c58511b9 55512 afterEach : function () {
db71a655
KM
55513 moment.locale('en');
55514 teardownDeprecationHandler(test, moment, 'locale');
55515 if (lifecycle && lifecycle.teardown) {
55516 lifecycle.teardown();
55517 }
516f5f67 55518 }
db71a655
KM
55519 });
55520 defineCommonLocaleTests(name, -1, -1);
55521 }
55522
55523 localeModule('tet');
55524
55525 test('parse', function (assert) {
55526 var tests = 'Janeiru Jan_Fevereiru Fev_Marsu Mar_Abril Abr_Maiu Mai_Juñu Jun_Jullu Jul_Agustu Ago_Setembru Set_Outubru Out_Novembru Nov_Dezembru Dez'.split('_'), i;
55527 function equalTest(input, mmm, i) {
55528 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
55529 }
55530 for (i = 0; i < 12; i++) {
55531 tests[i] = tests[i].split(' ');
55532 equalTest(tests[i][0], 'MMM', i);
55533 equalTest(tests[i][1], 'MMM', i);
55534 equalTest(tests[i][0], 'MMMM', i);
55535 equalTest(tests[i][1], 'MMMM', i);
55536 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
55537 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
55538 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
55539 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
55540 }
55541 });
55542
55543 test('format', function (assert) {
55544 var a = [
55545 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Domingu, Fevereiru 14th 2010, 3:25:50 pm'],
55546 ['ddd, hA', 'Dom, 3PM'],
55547 ['M Mo MM MMMM MMM', '2 2nd 02 Fevereiru Fev'],
55548 ['YYYY YY', '2010 10'],
55549 ['D Do DD', '14 14th 14'],
55550 ['d do dddd ddd dd', '0 0th Domingu Dom Do'],
55551 ['DDD DDDo DDDD', '45 45th 045'],
55552 ['w wo ww', '6 6th 06'],
55553 ['h hh', '3 03'],
55554 ['H HH', '15 15'],
55555 ['m mm', '25 25'],
55556 ['s ss', '50 50'],
55557 ['a A', 'pm PM'],
55558 ['[the] DDDo [day of the year]', 'the 45th day of the year'],
55559 ['LTS', '15:25:50'],
55560 ['L', '14/02/2010'],
55561 ['LL', '14 Fevereiru 2010'],
55562 ['LLL', '14 Fevereiru 2010 15:25'],
55563 ['LLLL', 'Domingu, 14 Fevereiru 2010 15:25'],
55564 ['l', '14/2/2010'],
55565 ['ll', '14 Fev 2010'],
55566 ['lll', '14 Fev 2010 15:25'],
55567 ['llll', 'Dom, 14 Fev 2010 15:25']
55568 ],
55569 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
55570 i;
55571 for (i = 0; i < a.length; i++) {
55572 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
55573 }
55574 });
55575
55576 test('format ordinal', function (assert) {
55577 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1st', '1st');
55578 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2nd', '2nd');
55579 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3rd', '3rd');
55580 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4th', '4th');
55581 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5th', '5th');
55582 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6th', '6th');
55583 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7th', '7th');
55584 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8th', '8th');
55585 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9th', '9th');
55586 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10th', '10th');
55587
55588 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11th', '11th');
55589 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12th', '12th');
55590 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13th', '13th');
55591 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14th', '14th');
55592 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15th', '15th');
55593 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16th', '16th');
55594 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17th', '17th');
55595 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18th', '18th');
55596 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19th', '19th');
55597 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20th', '20th');
55598
55599 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21st', '21st');
55600 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22nd', '22nd');
55601 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23rd', '23rd');
55602 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24th', '24th');
55603 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25th', '25th');
55604 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26th', '26th');
55605 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27th', '27th');
55606 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28th', '28th');
55607 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29th', '29th');
55608 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30th', '30th');
55609
55610 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31st', '31st');
55611 });
55612
55613 test('format month', function (assert) {
55614 var expected = 'Janeiru Jan_Fevereiru Fev_Marsu Mar_Abril Abr_Maiu Mai_Juñu Jun_Jullu Jul_Agustu Ago_Setembru Set_Outubru Out_Novembru Nov_Dezembru Dez'.split('_'), i;
55615 for (i = 0; i < expected.length; i++) {
55616 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
55617 }
55618 });
55619
55620 test('format week', function (assert) {
55621 var expected = 'Domingu Dom Do_Segunda Seg Seg_Tersa Ters Te_Kuarta Kua Ku_Kinta Kint Ki_Sesta Sest Ses_Sabadu Sab Sa'.split('_'), i;
55622 for (i = 0; i < expected.length; i++) {
55623 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
55624 }
55625 });
55626
55627 test('from', function (assert) {
55628 var start = moment([2007, 1, 28]);
55629 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'minutu balun', '44 seconds = a few seconds');
55630 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minutu ida', '45 seconds = a minute');
55631 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minutu ida', '89 seconds = a minute');
55632 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), 'minutu 2', '90 seconds = 2 minutes');
55633 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), 'minutu 44', '44 minutes = 44 minutes');
55634 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'oras ida', '45 minutes = an hour');
55635 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'oras ida', '89 minutes = an hour');
55636 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), 'oras 2', '90 minutes = 2 hours');
55637 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), 'oras 5', '5 hours = 5 hours');
55638 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), 'oras 21', '21 hours = 21 hours');
55639 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'loron ida', '22 hours = a day');
55640 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'loron ida', '35 hours = a day');
55641 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), 'loron 2', '36 hours = 2 days');
55642 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'loron ida', '1 day = a day');
55643 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), 'loron 5', '5 days = 5 days');
55644 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), 'loron 25', '25 days = 25 days');
55645 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'fulan ida', '26 days = a month');
55646 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'fulan ida', '30 days = a month');
55647 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'fulan ida', '43 days = a month');
55648 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), 'fulan 2', '46 days = 2 months');
55649 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), 'fulan 2', '75 days = 2 months');
55650 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), 'fulan 3', '76 days = 3 months');
55651 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'fulan ida', '1 month = a month');
55652 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), 'fulan 5', '5 months = 5 months');
55653 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'tinan ida', '345 days = a year');
55654 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), 'tinan 2', '548 days = 2 years');
55655 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'tinan ida', '1 year = a year');
55656 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), 'tinan 5', '5 years = 5 years');
55657 });
55658
55659 test('suffix', function (assert) {
55660 assert.equal(moment(30000).from(0), 'iha minutu balun', 'prefix');
55661 assert.equal(moment(0).from(30000), 'minutu balun liuba', 'suffix');
55662 });
55663
55664 test('now from now', function (assert) {
55665 assert.equal(moment().fromNow(), 'minutu balun liuba', 'now from now should display as in the past');
55666 });
55667
55668 test('fromNow', function (assert) {
55669 assert.equal(moment().add({s: 30}).fromNow(), 'iha minutu balun', 'in a few seconds');
55670 assert.equal(moment().add({d: 5}).fromNow(), 'iha loron 5', 'in 5 days');
55671 });
55672
55673 test('calendar day', function (assert) {
55674 var a = moment().hours(12).minutes(0).seconds(0);
55675
55676 assert.equal(moment(a).calendar(), 'Ohin iha 12:00', 'today at the same time');
55677 assert.equal(moment(a).add({m: 25}).calendar(), 'Ohin iha 12:25', 'Now plus 25 min');
55678 assert.equal(moment(a).add({h: 1}).calendar(), 'Ohin iha 13:00', 'Now plus 1 hour');
55679 assert.equal(moment(a).add({d: 1}).calendar(), 'Aban iha 12:00', 'tomorrow at the same time');
55680 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Ohin iha 11:00', 'Now minus 1 hour');
55681 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Horiseik iha 12:00', 'yesterday at the same time');
55682 });
55683
55684 test('calendar next week', function (assert) {
55685 var i, m;
55686 for (i = 2; i < 7; i++) {
55687 m = moment().add({d: i});
55688 assert.equal(m.calendar(), m.format('dddd [iha] LT'), 'Today + ' + i + ' days current time');
55689 m.hours(0).minutes(0).seconds(0).milliseconds(0);
55690 assert.equal(m.calendar(), m.format('dddd [iha] LT'), 'Today + ' + i + ' days beginning of day');
55691 m.hours(23).minutes(59).seconds(59).milliseconds(999);
55692 assert.equal(m.calendar(), m.format('dddd [iha] LT'), 'Today + ' + i + ' days end of day');
55693 }
55694 });
55695
55696 test('calendar last week', function (assert) {
55697 var i, m;
55698
55699 for (i = 2; i < 7; i++) {
55700 m = moment().subtract({d: i});
55701 assert.equal(m.calendar(), m.format('dddd [semana kotuk] [iha] LT'), 'Today - ' + i + ' days current time');
55702 m.hours(0).minutes(0).seconds(0).milliseconds(0);
55703 assert.equal(m.calendar(), m.format('dddd [semana kotuk] [iha] LT'), 'Today - ' + i + ' days beginning of day');
55704 m.hours(23).minutes(59).seconds(59).milliseconds(999);
55705 assert.equal(m.calendar(), m.format('dddd [semana kotuk] [iha] LT'), 'Today - ' + i + ' days end of day');
55706 }
55707 });
c74a101d 55708
db71a655
KM
55709 test('calendar all else', function (assert) {
55710 var weeksAgo = moment().subtract({w: 1}),
55711 weeksFromNow = moment().add({w: 1});
516f5f67 55712
db71a655
KM
55713 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
55714 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 55715
db71a655
KM
55716 weeksAgo = moment().subtract({w: 2});
55717 weeksFromNow = moment().add({w: 2});
516f5f67 55718
db71a655
KM
55719 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
55720 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
55721 });
516f5f67 55722
db71a655
KM
55723 test('weeks year starting sunday formatted', function (assert) {
55724 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52nd', 'Jan 1 2012 should be week 52');
55725 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1st', 'Jan 2 2012 should be week 1');
55726 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1st', 'Jan 8 2012 should be week 1');
55727 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2nd', 'Jan 9 2012 should be week 2');
55728 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2nd', 'Jan 15 2012 should be week 2');
55729 });
516f5f67 55730
73f3c911 55731})));
516f5f67 55732
516f5f67 55733
c74a101d
IC
55734;(function (global, factory) {
55735 typeof exports === 'object' && typeof module !== 'undefined'
55736 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
55737 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
55738 factory(global.moment)
73f3c911 55739}(this, (function (moment) { 'use strict';
516f5f67 55740
db71a655
KM
55741 function each(array, callback) {
55742 var i;
55743 for (i = 0; i < array.length; i++) {
55744 callback(array[i], i, array);
55745 }
b135bf1a
IC
55746 }
55747
c58511b9
KM
55748 function setupDeprecationHandler(test, moment$$1, scope) {
55749 test._expectedDeprecations = null;
55750 test._observedDeprecations = null;
55751 test._oldSupress = moment$$1.suppressDeprecationWarnings;
55752 moment$$1.suppressDeprecationWarnings = true;
55753 test.expectedDeprecations = function () {
55754 test._expectedDeprecations = arguments;
55755 test._observedDeprecations = [];
55756 };
55757 moment$$1.deprecationHandler = function (name, msg) {
55758 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
55759 if (deprecationId === -1) {
55760 throw new Error('Unexpected deprecation thrown name=' +
55761 name + ' msg=' + msg);
55762 }
55763 test._observedDeprecations[deprecationId] = 1;
55764 };
55765 }
55766
55767 function teardownDeprecationHandler(test, moment$$1, scope) {
55768 moment$$1.suppressDeprecationWarnings = test._oldSupress;
55769
55770 if (test._expectedDeprecations != null) {
55771 var missedDeprecations = [];
55772 each(test._expectedDeprecations, function (deprecationPattern, id) {
55773 if (test._observedDeprecations[id] !== 1) {
55774 missedDeprecations.push(deprecationPattern);
55775 }
55776 });
55777 if (missedDeprecations.length !== 0) {
55778 throw new Error('Expected deprecation warnings did not happen: ' +
55779 missedDeprecations.join(' '));
55780 }
55781 }
55782 }
55783
55784 function matchedDeprecation(name, msg, deprecations) {
55785 if (deprecations == null) {
55786 return -1;
55787 }
55788 for (var i = 0; i < deprecations.length; ++i) {
55789 if (name != null && name === deprecations[i]) {
55790 return i;
55791 }
55792 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
55793 return i;
55794 }
55795 }
55796 return -1;
55797 }
55798
55799 /*global QUnit:false*/
55800
55801 var test = QUnit.test;
55802
db71a655
KM
55803 function objectKeys(obj) {
55804 if (Object.keys) {
55805 return Object.keys(obj);
55806 } else {
55807 // IE8
55808 var res = [], i;
55809 for (i in obj) {
55810 if (obj.hasOwnProperty(i)) {
55811 res.push(i);
55812 }
b135bf1a 55813 }
db71a655 55814 return res;
b135bf1a 55815 }
b135bf1a
IC
55816 }
55817
db71a655 55818 // Pick the first defined of two or three arguments.
b135bf1a 55819
db71a655
KM
55820 function defineCommonLocaleTests(locale, options) {
55821 test('lenient day of month ordinal parsing', function (assert) {
55822 var i, ordinalStr, testMoment;
55823 for (i = 1; i <= 31; ++i) {
55824 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
55825 testMoment = moment(ordinalStr, 'YYYY MM Do');
55826 assert.equal(testMoment.year(), 2014,
55827 'lenient day of month ordinal parsing ' + i + ' year check');
55828 assert.equal(testMoment.month(), 0,
55829 'lenient day of month ordinal parsing ' + i + ' month check');
55830 assert.equal(testMoment.date(), i,
55831 'lenient day of month ordinal parsing ' + i + ' date check');
55832 }
55833 });
f2af24d5 55834
db71a655
KM
55835 test('lenient day of month ordinal parsing of number', function (assert) {
55836 var i, testMoment;
55837 for (i = 1; i <= 31; ++i) {
55838 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
55839 assert.equal(testMoment.year(), 2014,
55840 'lenient day of month ordinal parsing of number ' + i + ' year check');
55841 assert.equal(testMoment.month(), 0,
55842 'lenient day of month ordinal parsing of number ' + i + ' month check');
55843 assert.equal(testMoment.date(), i,
55844 'lenient day of month ordinal parsing of number ' + i + ' date check');
55845 }
55846 });
f2af24d5 55847
db71a655
KM
55848 test('strict day of month ordinal parsing', function (assert) {
55849 var i, ordinalStr, testMoment;
55850 for (i = 1; i <= 31; ++i) {
55851 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
55852 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
55853 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
55854 }
55855 });
f2af24d5 55856
db71a655
KM
55857 test('meridiem invariant', function (assert) {
55858 var h, m, t1, t2;
55859 for (h = 0; h < 24; ++h) {
55860 for (m = 0; m < 60; m += 15) {
55861 t1 = moment.utc([2000, 0, 1, h, m]);
55862 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
55863 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
55864 'meridiem at ' + t1.format('HH:mm'));
55865 }
55866 }
55867 });
55868
55869 test('date format correctness', function (assert) {
55870 var data, tokens;
55871 data = moment.localeData()._longDateFormat;
55872 tokens = objectKeys(data);
55873 each(tokens, function (srchToken) {
55874 // Check each format string to make sure it does not contain any
55875 // tokens that need to be expanded.
55876 each(tokens, function (baseToken) {
55877 // strip escaped sequences
55878 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
55879 assert.equal(false, !!~format.indexOf(srchToken),
55880 'contains ' + srchToken + ' in ' + baseToken);
55881 });
f2af24d5
IC
55882 });
55883 });
f2af24d5 55884
db71a655
KM
55885 test('month parsing correctness', function (assert) {
55886 var i, m;
55887
55888 if (locale === 'tr') {
55889 // I can't fix it :(
c58511b9 55890 assert.expect(0);
db71a655
KM
55891 return;
55892 }
55893 function tester(format) {
55894 var r;
55895 r = moment(m.format(format), format);
55896 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
55897 if (locale !== 'ka') {
55898 r = moment(m.format(format).toLocaleUpperCase(), format);
55899 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
55900 }
db71a655
KM
55901 r = moment(m.format(format).toLocaleLowerCase(), format);
55902 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
55903
55904 r = moment(m.format(format), format, true);
55905 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
55906 if (locale !== 'ka') {
55907 r = moment(m.format(format).toLocaleUpperCase(), format, true);
55908 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
55909 }
db71a655
KM
55910 r = moment(m.format(format).toLocaleLowerCase(), format, true);
55911 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
55912 }
55913
55914 for (i = 0; i < 12; ++i) {
55915 m = moment([2015, i, 15, 18]);
55916 tester('MMM');
55917 tester('MMM.');
55918 tester('MMMM');
55919 tester('MMMM.');
55920 }
55921 });
55922
55923 test('weekday parsing correctness', function (assert) {
55924 var i, m;
55925
96d0d679 55926 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
55927 // tr, az: There is a lower-case letter (ı), that converted to
55928 // upper then lower changes to i
55929 // ro: there is the letter ț which behaves weird under IE8
55930 // mt: letter Ħ
96d0d679 55931 // ga: month with spaces
c58511b9 55932 assert.expect(0);
db71a655
KM
55933 return;
55934 }
55935 function tester(format) {
55936 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
55937 r = moment(m.format(format), format);
55938 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
55939 if (locale !== 'ka') {
55940 r = moment(m.format(format).toLocaleUpperCase(), format);
55941 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
55942 }
db71a655
KM
55943 r = moment(m.format(format).toLocaleLowerCase(), format);
55944 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
55945 r = moment(m.format(format), format, true);
55946 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
55947 if (locale !== 'ka') {
55948 r = moment(m.format(format).toLocaleUpperCase(), format, true);
55949 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
55950 }
db71a655
KM
55951 r = moment(m.format(format).toLocaleLowerCase(), format, true);
55952 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
55953 }
55954
55955 for (i = 0; i < 7; ++i) {
55956 m = moment.utc([2015, 0, i + 1, 18]);
55957 tester('dd');
55958 tester('ddd');
55959 tester('dddd');
55960 }
55961 });
55962
55963 test('valid localeData', function (assert) {
55964 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
55965 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
55966 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
55967 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
55968 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
55969 });
96d0d679
KM
55970
55971 test('localeData weekdays can localeSort', function (assert) {
55972 var weekdays = moment().localeData().weekdays();
55973 var weekdaysShort = moment().localeData().weekdaysShort();
55974 var weekdaysMin = moment().localeData().weekdaysMin();
55975 var shift = moment().localeData()._week.dow;
55976 assert.deepEqual(
55977 moment().localeData().weekdays(true),
55978 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
55979 'weekdays should localeSort');
55980 assert.deepEqual(
55981 moment().localeData().weekdaysShort(true),
55982 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
55983 'weekdaysShort should localeSort');
55984 assert.deepEqual(
55985 moment().localeData().weekdaysMin(true),
55986 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
55987 'weekdaysMin should localeSort');
55988 });
db71a655 55989 }
f2af24d5 55990
db71a655
KM
55991 /*global QUnit:false*/
55992
db71a655
KM
55993 function localeModule (name, lifecycle) {
55994 QUnit.module('locale:' + name, {
c58511b9 55995 beforeEach : function () {
db71a655
KM
55996 moment.locale(name);
55997 moment.createFromInputFallback = function (config) {
55998 throw new Error('input not handled by moment: ' + config._i);
55999 };
56000 setupDeprecationHandler(test, moment, 'locale');
56001 if (lifecycle && lifecycle.setup) {
56002 lifecycle.setup();
56003 }
56004 },
c58511b9 56005 afterEach : function () {
db71a655
KM
56006 moment.locale('en');
56007 teardownDeprecationHandler(test, moment, 'locale');
56008 if (lifecycle && lifecycle.teardown) {
56009 lifecycle.teardown();
56010 }
f2af24d5
IC
56011 }
56012 });
db71a655
KM
56013 defineCommonLocaleTests(name, -1, -1);
56014 }
56015
56016 localeModule('tg');
56017
56018 test('parse', function (assert) {
56019 var tests = 'январ янв_феврал фев_март мар_апрел апр_май май_июн июн_июл июл_август авг_сентябр сен_октябр окт_ноябр ноя_декабр дек'.split('_'), i;
56020 function equalTest(input, mmm, i) {
56021 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
56022 }
56023 for (i = 0; i < 12; i++) {
56024 tests[i] = tests[i].split(' ');
56025 equalTest(tests[i][0], 'MMM', i);
56026 equalTest(tests[i][1], 'MMM', i);
56027 equalTest(tests[i][0], 'MMMM', i);
56028 equalTest(tests[i][1], 'MMMM', i);
56029 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
56030 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
56031 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
56032 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
56033 }
56034 });
56035
56036 test('format', function (assert) {
56037 var a = [
56038 ['dddd, Do MMMM YYYY, h:mm:ss', 'якшанбе, 14-ум феврал 2010, 3:25:50'],
56039 ['ddd, h A', 'яшб, 3 рӯз'],
56040 ['M Mo MM MMMM MMM', '2 2-юм 02 феврал фев'],
56041 ['YYYY YY', '2010 10'],
56042 ['D Do DD', '14 14-ум 14'],
56043 ['d do dddd ddd dd', '0 0-ум якшанбе яшб яш'],
56044 ['DDD DDDo DDDD', '45 45-ум 045'],
56045 ['w wo ww', '7 7-ум 07'],
56046 ['h hh', '3 03'],
56047 ['H HH', '15 15'],
56048 ['m mm', '25 25'],
56049 ['s ss', '50 50'],
56050 ['a A', 'рӯз рӯз'],
56051 ['DDDo [рӯзи сол]', '45-ум рӯзи сол'],
56052 ['LTS', '15:25:50'],
56053 ['L', '14/02/2010'],
56054 ['LL', '14 феврал 2010'],
56055 ['LLL', '14 феврал 2010 15:25'],
56056 ['LLLL', 'якшанбе, 14 феврал 2010 15:25'],
56057 ['l', '14/2/2010'],
56058 ['ll', '14 фев 2010'],
56059 ['lll', '14 фев 2010 15:25'],
56060 ['llll', 'яшб, 14 фев 2010 15:25']
56061 ],
56062 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
56063 i;
56064 for (i = 0; i < a.length; i++) {
56065 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
56066 }
56067 });
56068
56069 test('format meridiem', function (assert) {
56070 assert.equal(moment([2012, 11, 28, 0, 0]).format('A'), 'шаб', 'night');
56071 assert.equal(moment([2012, 11, 28, 3, 59]).format('A'), 'шаб', 'night');
56072 assert.equal(moment([2012, 11, 28, 4, 0]).format('A'), 'субҳ', 'morning');
56073 assert.equal(moment([2012, 11, 28, 10, 59]).format('A'), 'субҳ', 'morning');
56074 assert.equal(moment([2012, 11, 28, 12, 0]).format('A'), 'рӯз', 'afternoon');
56075 assert.equal(moment([2012, 11, 28, 15, 59]).format('A'), 'рӯз', 'afternoon');
56076 assert.equal(moment([2012, 11, 28, 17, 0]).format('A'), 'бегоҳ', 'evening');
56077 assert.equal(moment([2012, 11, 28, 23, 59]).format('A'), 'шаб', 'evening');
56078 });
56079
56080 test('format ordinal', function (assert) {
56081 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-ум', '1st');
56082 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-юм', '2nd');
56083 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-юм', '3rd');
56084 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-ум', '4th');
56085 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-ум', '5th');
56086 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-ум', '6th');
56087 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-ум', '7th');
56088 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-ум', '8th');
56089 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-ум', '9th');
56090 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-ум', '10th');
56091
56092 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-ум', '11th');
56093 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-ум', '12th');
56094 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-ум', '13th');
56095 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-ум', '14th');
56096 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-ум', '15th');
56097 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-ум', '16th');
56098 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-ум', '17th');
56099 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-ум', '18th');
56100 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-ум', '19th');
56101 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-ум', '20th');
56102
56103 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-ум', '21st');
56104 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-юм', '22nd');
56105 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-юм', '23rd');
56106 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-ум', '24th');
56107 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-ум', '25th');
56108 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-ум', '26th');
56109 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-ум', '27th');
56110 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-ум', '28th');
56111 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-ум', '29th');
56112 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-юм', '30th');
56113
56114 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-ум', '31st');
56115 });
56116
56117 test('format month', function (assert) {
56118 var expected = 'январ янв_феврал фев_март мар_апрел апр_май май_июн июн_июл июл_август авг_сентябр сен_октябр окт_ноябр ноя_декабр дек'.split('_'), i;
56119 for (i = 0; i < expected.length; i++) {
56120 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
56121 }
56122 });
56123
56124 test('format week', function (assert) {
56125 var expected = 'якшанбе яшб яш_душанбе дшб дш_сешанбе сшб сш_чоршанбе чшб чш_панҷшанбе пшб пш_ҷумъа ҷум ҷм_шанбе шнб шб'.split('_'), i;
56126 for (i = 0; i < expected.length; i++) {
56127 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
56128 }
56129 });
56130
56131 test('from', function (assert) {
56132 var start = moment([2007, 1, 28]);
56133 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'якчанд сония', '44 сония = a few seconds');
56134 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'як дақиқа', '45 сония = як дақиқа');
56135 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'як дақиқа', '89 сония = як дақиқа');
56136 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 дақиқа', '90 сония = 2 дақиқа');
56137 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 дақиқа', '44 дақиқа = 44 дақиқа');
56138 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'як соат', '45 дақиқа = як соат');
56139 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'як соат', '89 дақиқа = як соат');
56140 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 соат', '90 дақиқа = 2 соат');
56141 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 соат', '5 соат = 5 соат');
56142 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 соат', '21 соат = 21 соат');
56143 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'як рӯз', '22 соат = як рӯз');
56144 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'як рӯз', '35 соат = як рӯз');
56145 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 рӯз', '36 соат = 2 рӯз');
56146 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'як рӯз', '1 рӯз = як рӯз');
56147 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 рӯз', '5 рӯз = 5 рӯз');
56148 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 рӯз', '25 рӯз = 25 рӯз');
56149 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'як моҳ', '26 рӯз = як моҳ');
56150 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'як моҳ', '30 рӯз = як моҳ');
56151 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'як моҳ', '43 рӯз = як моҳ');
56152 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 моҳ', '46 рӯз = 2 моҳ');
56153 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 моҳ', '74 рӯз = 2 моҳ');
56154 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 моҳ', '76 рӯз = 3 моҳ');
56155 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'як моҳ', 'як моҳ = як моҳ');
56156 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 моҳ', '5 моҳ = 5 моҳ');
56157 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'як сол', '345 рӯз = як сол');
56158 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 сол', '548 рӯз = 2 сол');
56159 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'як сол', '1 сол = як сол');
56160 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 сол', '5 сол = 5 сол');
56161 });
56162
56163 test('suffix', function (assert) {
56164 assert.equal(moment(30000).from(0), 'баъди якчанд сония', 'prefix');
56165 assert.equal(moment(0).from(30000), 'якчанд сония пеш', 'suffix');
56166 });
56167
56168 test('now from now', function (assert) {
56169 assert.equal(moment().fromNow(), 'якчанд сония пеш', 'now from now should display as in the past');
56170 });
56171
56172 test('fromNow', function (assert) {
56173 assert.equal(moment().add({s: 30}).fromNow(), 'баъди якчанд сония', 'in a few seconds');
56174 assert.equal(moment().add({d: 5}).fromNow(), 'баъди 5 рӯз', 'in 5 days');
56175 });
56176
56177 test('calendar day', function (assert) {
56178 var a = moment().hours(12).minutes(0).seconds(0);
56179
56180 assert.equal(moment(a).calendar(), 'Имрӯз соати 12:00', 'today at the same time');
56181 assert.equal(moment(a).add({m: 25}).calendar(), 'Имрӯз соати 12:25', 'Now plus 25 min');
56182 assert.equal(moment(a).add({h: 1}).calendar(), 'Имрӯз соати 13:00', 'Now plus 1 hour');
56183 assert.equal(moment(a).add({d: 1}).calendar(), 'Пагоҳ соати 12:00', 'tomorrow at the same time');
56184 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Имрӯз соати 11:00', 'Now minus 1 hour');
56185 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Дирӯз соати 12:00', 'yesterday at the same time');
56186 });
56187
56188 test('calendar next week', function (assert) {
56189 var i, m;
56190 for (i = 2; i < 7; i++) {
56191 m = moment().add({d: i});
56192 assert.equal(m.calendar(), m.format('dddd[и] [ҳафтаи оянда соати] LT'), 'Today + ' + i + ' days current time');
56193 m.hours(0).minutes(0).seconds(0).milliseconds(0);
56194 assert.equal(m.calendar(), m.format('dddd[и] [ҳафтаи оянда соати] LT'), 'Today + ' + i + ' days beginning of day');
56195 m.hours(23).minutes(59).seconds(59).milliseconds(999);
56196 assert.equal(m.calendar(), m.format('dddd[и] [ҳафтаи оянда соати] LT'), 'Today + ' + i + ' days end of day');
f2af24d5 56197 }
db71a655 56198 });
f2af24d5 56199
db71a655
KM
56200 test('calendar last week', function (assert) {
56201 var i, m;
56202
56203 for (i = 2; i < 7; i++) {
56204 m = moment().subtract({d: i});
56205 assert.equal(m.calendar(), m.format('dddd[и] [ҳафтаи гузашта соати] LT'), 'Today - ' + i + ' days current time');
56206 m.hours(0).minutes(0).seconds(0).milliseconds(0);
56207 assert.equal(m.calendar(), m.format('dddd[и] [ҳафтаи гузашта соати] LT'), 'Today - ' + i + ' days beginning of day');
56208 m.hours(23).minutes(59).seconds(59).milliseconds(999);
56209 assert.equal(m.calendar(), m.format('dddd[и] [ҳафтаи гузашта соати] LT'), 'Today - ' + i + ' days end of day');
f2af24d5 56210 }
db71a655 56211 });
f2af24d5 56212
db71a655
KM
56213 test('calendar all else', function (assert) {
56214 var weeksAgo = moment().subtract({w: 1}),
56215 weeksFromNow = moment().add({w: 1});
f2af24d5 56216
db71a655
KM
56217 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
56218 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
f2af24d5 56219
db71a655
KM
56220 weeksAgo = moment().subtract({w: 2});
56221 weeksFromNow = moment().add({w: 2});
f2af24d5 56222
db71a655
KM
56223 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
56224 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
56225 });
56226
56227 test('weeks year starting sunday formatted', function (assert) {
56228 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-ум', 'Jan 1 2012 should be week 1');
56229 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-юм', 'Jan 2 2012 should be week 2');
56230 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-юм', 'Jan 8 2012 should be week 2');
56231 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-юм', 'Jan 9 2012 should be week 3');
56232 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3-юм', 'Jan 15 2012 should be week 3');
56233 });
f2af24d5
IC
56234
56235})));
56236
56237
56238;(function (global, factory) {
56239 typeof exports === 'object' && typeof module !== 'undefined'
56240 && typeof require === 'function' ? factory(require('../../moment')) :
56241 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
56242 factory(global.moment)
56243}(this, (function (moment) { 'use strict';
56244
db71a655
KM
56245 function each(array, callback) {
56246 var i;
56247 for (i = 0; i < array.length; i++) {
56248 callback(array[i], i, array);
56249 }
f2af24d5 56250 }
f2af24d5 56251
c58511b9
KM
56252 function setupDeprecationHandler(test, moment$$1, scope) {
56253 test._expectedDeprecations = null;
56254 test._observedDeprecations = null;
56255 test._oldSupress = moment$$1.suppressDeprecationWarnings;
56256 moment$$1.suppressDeprecationWarnings = true;
56257 test.expectedDeprecations = function () {
56258 test._expectedDeprecations = arguments;
56259 test._observedDeprecations = [];
56260 };
56261 moment$$1.deprecationHandler = function (name, msg) {
56262 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
56263 if (deprecationId === -1) {
56264 throw new Error('Unexpected deprecation thrown name=' +
56265 name + ' msg=' + msg);
56266 }
56267 test._observedDeprecations[deprecationId] = 1;
56268 };
56269 }
56270
56271 function teardownDeprecationHandler(test, moment$$1, scope) {
56272 moment$$1.suppressDeprecationWarnings = test._oldSupress;
56273
56274 if (test._expectedDeprecations != null) {
56275 var missedDeprecations = [];
56276 each(test._expectedDeprecations, function (deprecationPattern, id) {
56277 if (test._observedDeprecations[id] !== 1) {
56278 missedDeprecations.push(deprecationPattern);
56279 }
56280 });
56281 if (missedDeprecations.length !== 0) {
56282 throw new Error('Expected deprecation warnings did not happen: ' +
56283 missedDeprecations.join(' '));
56284 }
56285 }
56286 }
56287
56288 function matchedDeprecation(name, msg, deprecations) {
56289 if (deprecations == null) {
56290 return -1;
56291 }
56292 for (var i = 0; i < deprecations.length; ++i) {
56293 if (name != null && name === deprecations[i]) {
56294 return i;
56295 }
56296 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
56297 return i;
56298 }
56299 }
56300 return -1;
56301 }
56302
56303 /*global QUnit:false*/
56304
56305 var test = QUnit.test;
56306
db71a655
KM
56307 function objectKeys(obj) {
56308 if (Object.keys) {
56309 return Object.keys(obj);
56310 } else {
56311 // IE8
56312 var res = [], i;
56313 for (i in obj) {
56314 if (obj.hasOwnProperty(i)) {
56315 res.push(i);
56316 }
f2af24d5 56317 }
db71a655 56318 return res;
f2af24d5 56319 }
f2af24d5 56320 }
f2af24d5 56321
db71a655 56322 // Pick the first defined of two or three arguments.
f2af24d5 56323
db71a655
KM
56324 function defineCommonLocaleTests(locale, options) {
56325 test('lenient day of month ordinal parsing', function (assert) {
56326 var i, ordinalStr, testMoment;
56327 for (i = 1; i <= 31; ++i) {
56328 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
56329 testMoment = moment(ordinalStr, 'YYYY MM Do');
56330 assert.equal(testMoment.year(), 2014,
56331 'lenient day of month ordinal parsing ' + i + ' year check');
56332 assert.equal(testMoment.month(), 0,
56333 'lenient day of month ordinal parsing ' + i + ' month check');
56334 assert.equal(testMoment.date(), i,
56335 'lenient day of month ordinal parsing ' + i + ' date check');
56336 }
56337 });
b135bf1a 56338
db71a655
KM
56339 test('lenient day of month ordinal parsing of number', function (assert) {
56340 var i, testMoment;
56341 for (i = 1; i <= 31; ++i) {
56342 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
56343 assert.equal(testMoment.year(), 2014,
56344 'lenient day of month ordinal parsing of number ' + i + ' year check');
56345 assert.equal(testMoment.month(), 0,
56346 'lenient day of month ordinal parsing of number ' + i + ' month check');
56347 assert.equal(testMoment.date(), i,
56348 'lenient day of month ordinal parsing of number ' + i + ' date check');
56349 }
56350 });
b135bf1a 56351
db71a655
KM
56352 test('strict day of month ordinal parsing', function (assert) {
56353 var i, ordinalStr, testMoment;
56354 for (i = 1; i <= 31; ++i) {
56355 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
56356 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
56357 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
56358 }
56359 });
b135bf1a 56360
db71a655
KM
56361 test('meridiem invariant', function (assert) {
56362 var h, m, t1, t2;
56363 for (h = 0; h < 24; ++h) {
56364 for (m = 0; m < 60; m += 15) {
56365 t1 = moment.utc([2000, 0, 1, h, m]);
56366 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
56367 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
56368 'meridiem at ' + t1.format('HH:mm'));
56369 }
56370 }
56371 });
56372
56373 test('date format correctness', function (assert) {
56374 var data, tokens;
56375 data = moment.localeData()._longDateFormat;
56376 tokens = objectKeys(data);
56377 each(tokens, function (srchToken) {
56378 // Check each format string to make sure it does not contain any
56379 // tokens that need to be expanded.
56380 each(tokens, function (baseToken) {
56381 // strip escaped sequences
56382 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
56383 assert.equal(false, !!~format.indexOf(srchToken),
56384 'contains ' + srchToken + ' in ' + baseToken);
56385 });
b135bf1a
IC
56386 });
56387 });
d6651c21 56388
db71a655
KM
56389 test('month parsing correctness', function (assert) {
56390 var i, m;
56391
56392 if (locale === 'tr') {
56393 // I can't fix it :(
c58511b9 56394 assert.expect(0);
db71a655
KM
56395 return;
56396 }
56397 function tester(format) {
56398 var r;
56399 r = moment(m.format(format), format);
56400 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
56401 if (locale !== 'ka') {
56402 r = moment(m.format(format).toLocaleUpperCase(), format);
56403 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
56404 }
db71a655
KM
56405 r = moment(m.format(format).toLocaleLowerCase(), format);
56406 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
56407
56408 r = moment(m.format(format), format, true);
56409 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
56410 if (locale !== 'ka') {
56411 r = moment(m.format(format).toLocaleUpperCase(), format, true);
56412 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
56413 }
db71a655
KM
56414 r = moment(m.format(format).toLocaleLowerCase(), format, true);
56415 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
56416 }
56417
56418 for (i = 0; i < 12; ++i) {
56419 m = moment([2015, i, 15, 18]);
56420 tester('MMM');
56421 tester('MMM.');
56422 tester('MMMM');
56423 tester('MMMM.');
56424 }
56425 });
d6651c21 56426
db71a655
KM
56427 test('weekday parsing correctness', function (assert) {
56428 var i, m;
56429
96d0d679 56430 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
56431 // tr, az: There is a lower-case letter (ı), that converted to
56432 // upper then lower changes to i
56433 // ro: there is the letter ț which behaves weird under IE8
56434 // mt: letter Ħ
96d0d679 56435 // ga: month with spaces
c58511b9 56436 assert.expect(0);
db71a655
KM
56437 return;
56438 }
56439 function tester(format) {
56440 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
56441 r = moment(m.format(format), format);
56442 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
56443 if (locale !== 'ka') {
56444 r = moment(m.format(format).toLocaleUpperCase(), format);
56445 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
56446 }
db71a655
KM
56447 r = moment(m.format(format).toLocaleLowerCase(), format);
56448 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
56449 r = moment(m.format(format), format, true);
56450 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
56451 if (locale !== 'ka') {
56452 r = moment(m.format(format).toLocaleUpperCase(), format, true);
56453 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
56454 }
db71a655
KM
56455 r = moment(m.format(format).toLocaleLowerCase(), format, true);
56456 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
56457 }
56458
56459 for (i = 0; i < 7; ++i) {
56460 m = moment.utc([2015, 0, i + 1, 18]);
56461 tester('dd');
56462 tester('ddd');
56463 tester('dddd');
56464 }
56465 });
d6651c21 56466
db71a655
KM
56467 test('valid localeData', function (assert) {
56468 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
56469 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
56470 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
56471 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
56472 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
56473 });
96d0d679
KM
56474
56475 test('localeData weekdays can localeSort', function (assert) {
56476 var weekdays = moment().localeData().weekdays();
56477 var weekdaysShort = moment().localeData().weekdaysShort();
56478 var weekdaysMin = moment().localeData().weekdaysMin();
56479 var shift = moment().localeData()._week.dow;
56480 assert.deepEqual(
56481 moment().localeData().weekdays(true),
56482 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
56483 'weekdays should localeSort');
56484 assert.deepEqual(
56485 moment().localeData().weekdaysShort(true),
56486 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
56487 'weekdaysShort should localeSort');
56488 assert.deepEqual(
56489 moment().localeData().weekdaysMin(true),
56490 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
56491 'weekdaysMin should localeSort');
56492 });
db71a655 56493 }
d6651c21 56494
db71a655 56495 /*global QUnit:false*/
c74a101d 56496
db71a655
KM
56497 function localeModule (name, lifecycle) {
56498 QUnit.module('locale:' + name, {
c58511b9 56499 beforeEach : function () {
db71a655
KM
56500 moment.locale(name);
56501 moment.createFromInputFallback = function (config) {
56502 throw new Error('input not handled by moment: ' + config._i);
56503 };
56504 setupDeprecationHandler(test, moment, 'locale');
56505 if (lifecycle && lifecycle.setup) {
56506 lifecycle.setup();
56507 }
56508 },
c58511b9 56509 afterEach : function () {
db71a655
KM
56510 moment.locale('en');
56511 teardownDeprecationHandler(test, moment, 'locale');
56512 if (lifecycle && lifecycle.teardown) {
56513 lifecycle.teardown();
56514 }
516f5f67
IC
56515 }
56516 });
db71a655
KM
56517 defineCommonLocaleTests(name, -1, -1);
56518 }
56519
56520 localeModule('th');
56521
56522 test('parse', function (assert) {
56523 var tests = 'มกราคม ม.ค._กุมภาพันธ์ ก.พ._มีนาคม มี.ค._เมษายน เม.ย._พฤษภาคม พ.ค._มิถุนายน มิ.ย._กรกฎาคม ก.ค._สิงหาคม ส.ค._กันยายน ก.ย._ตุลาคม ต.ค._พฤศจิกายน พ.ย._ธันวาคม ธ.ค.'.split('_'), i;
56524 function equalTest(input, mmm, i) {
56525 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
56526 }
56527 for (i = 0; i < 12; i++) {
56528 tests[i] = tests[i].split(' ');
56529 equalTest(tests[i][0], 'MMM', i);
56530 equalTest(tests[i][1], 'MMM', i);
56531 equalTest(tests[i][0], 'MMMM', i);
56532 equalTest(tests[i][1], 'MMMM', i);
56533 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
56534 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
56535 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
56536 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
56537 }
56538 });
56539
56540 test('format', function (assert) {
56541 var a = [
56542 ['dddd, Do MMMM YYYY, h:mm:ss a', 'อาทิตย์, 14 กุมภาพันธ์ 2010, 3:25:50 หลังเที่ยง'],
56543 ['ddd, h A', 'อาทิตย์, 3 หลังเที่ยง'],
56544 ['M Mo MM MMMM MMM', '2 2 02 กุมภาพันธ์ ก.พ.'],
56545 ['YYYY YY', '2010 10'],
56546 ['D Do DD', '14 14 14'],
56547 ['d do dddd ddd dd', '0 0 อาทิตย์ อาทิตย์ อา.'],
56548 ['DDD DDDo DDDD', '45 45 045'],
56549 ['w wo ww', '8 8 08'],
56550 ['h hh', '3 03'],
56551 ['H HH', '15 15'],
56552 ['m mm', '25 25'],
56553 ['s ss', '50 50'],
56554 ['a A', 'หลังเที่ยง หลังเที่ยง'],
56555 ['[the] DDDo [day of the year]', 'the 45 day of the year'],
56556 ['LTS', '15:25:50'],
56557 ['L', '14/02/2010'],
56558 ['LL', '14 กุมภาพันธ์ 2010'],
56559 ['LLL', '14 กุมภาพันธ์ 2010 เวลา 15:25'],
56560 ['LLLL', 'วันอาทิตย์ที่ 14 กุมภาพันธ์ 2010 เวลา 15:25'],
56561 ['l', '14/2/2010'],
56562 ['ll', '14 ก.พ. 2010'],
56563 ['lll', '14 ก.พ. 2010 เวลา 15:25'],
56564 ['llll', 'วันอาทิตย์ที่ 14 ก.พ. 2010 เวลา 15:25']
56565 ],
56566 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
56567 i;
56568 for (i = 0; i < a.length; i++) {
56569 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
56570 }
56571 });
56572
56573 test('format month', function (assert) {
56574 var expected = 'มกราคม ม.ค._กุมภาพันธ์ ก.พ._มีนาคม มี.ค._เมษายน เม.ย._พฤษภาคม พ.ค._มิถุนายน มิ.ย._กรกฎาคม ก.ค._สิงหาคม ส.ค._กันยายน ก.ย._ตุลาคม ต.ค._พฤศจิกายน พ.ย._ธันวาคม ธ.ค.'.split('_'), i;
56575 for (i = 0; i < expected.length; i++) {
56576 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
56577 }
56578 });
56579
56580 test('format week', function (assert) {
56581 var expected = 'อาทิตย์ อาทิตย์ อา._จันทร์ จันทร์ จ._อังคาร อังคาร อ._พุธ พุธ พ._พฤหัสบดี พฤหัส พฤ._ศุกร์ ศุกร์ ศ._เสาร์ เสาร์ ส.'.split('_'), i;
56582 for (i = 0; i < expected.length; i++) {
56583 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
56584 }
56585 });
56586
56587 test('from', function (assert) {
56588 var start = moment([2007, 1, 28]);
56589 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ไม่กี่วินาที', '44 seconds = a few seconds');
56590 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '1 นาที', '45 seconds = a minute');
56591 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '1 นาที', '89 seconds = a minute');
56592 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 นาที', '90 seconds = 2 minutes');
56593 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 นาที', '44 minutes = 44 minutes');
56594 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '1 ชั่วโมง', '45 minutes = an hour');
56595 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '1 ชั่วโมง', '89 minutes = an hour');
56596 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ชั่วโมง', '90 minutes = 2 hours');
56597 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ชั่วโมง', '5 hours = 5 hours');
56598 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ชั่วโมง', '21 hours = 21 hours');
56599 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '1 วัน', '22 hours = a day');
56600 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '1 วัน', '35 hours = a day');
56601 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 วัน', '36 hours = 2 days');
56602 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '1 วัน', '1 day = a day');
56603 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 วัน', '5 days = 5 days');
56604 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 วัน', '25 days = 25 days');
56605 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '1 เดือน', '26 days = a month');
56606 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '1 เดือน', '30 days = a month');
56607 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '1 เดือน', '43 days = a month');
56608 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 เดือน', '46 days = 2 months');
56609 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 เดือน', '75 days = 2 months');
56610 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 เดือน', '76 days = 3 months');
56611 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '1 เดือน', '1 month = a month');
56612 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 เดือน', '5 months = 5 months');
56613 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '1 ปี', '345 days = a year');
56614 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ปี', '548 days = 2 years');
56615 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '1 ปี', '1 year = a year');
56616 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ปี', '5 years = 5 years');
56617 });
56618
56619 test('suffix', function (assert) {
56620 assert.equal(moment(30000).from(0), 'อีก ไม่กี่วินาที', 'prefix');
56621 assert.equal(moment(0).from(30000), 'ไม่กี่วินาทีที่แล้ว', 'suffix');
56622 });
56623
56624 test('now from now', function (assert) {
56625 assert.equal(moment().fromNow(), 'ไม่กี่วินาทีที่แล้ว', 'now from now should display as in the past');
56626 });
56627
56628 test('fromNow', function (assert) {
56629 assert.equal(moment().add({s: 30}).fromNow(), 'อีก ไม่กี่วินาที', 'in a few seconds');
56630 assert.equal(moment().add({d: 5}).fromNow(), 'อีก 5 วัน', 'in 5 days');
56631 });
56632
56633 test('calendar day', function (assert) {
56634 var a = moment().hours(12).minutes(0).seconds(0);
56635
56636 assert.equal(moment(a).calendar(), 'วันนี้ เวลา 12:00', 'today at the same time');
56637 assert.equal(moment(a).add({m: 25}).calendar(), 'วันนี้ เวลา 12:25', 'Now plus 25 min');
56638 assert.equal(moment(a).add({h: 1}).calendar(), 'วันนี้ เวลา 13:00', 'Now plus 1 hour');
56639 assert.equal(moment(a).add({d: 1}).calendar(), 'พรุ่งนี้ เวลา 12:00', 'tomorrow at the same time');
56640 assert.equal(moment(a).subtract({h: 1}).calendar(), 'วันนี้ เวลา 11:00', 'Now minus 1 hour');
56641 assert.equal(moment(a).subtract({d: 1}).calendar(), 'เมื่อวานนี้ เวลา 12:00', 'yesterday at the same time');
56642 });
56643
56644 test('calendar next week', function (assert) {
56645 var i, m;
56646 for (i = 2; i < 7; i++) {
56647 m = moment().add({d: i});
56648 assert.equal(m.calendar(), m.format('dddd[หน้า เวลา] LT'), 'Today + ' + i + ' days current time');
56649 m.hours(0).minutes(0).seconds(0).milliseconds(0);
56650 assert.equal(m.calendar(), m.format('dddd[หน้า เวลา] LT'), 'Today + ' + i + ' days beginning of day');
56651 m.hours(23).minutes(59).seconds(59).milliseconds(999);
56652 assert.equal(m.calendar(), m.format('dddd[หน้า เวลา] LT'), 'Today + ' + i + ' days end of day');
73f3c911 56653 }
db71a655 56654 });
516f5f67 56655
db71a655
KM
56656 test('calendar last week', function (assert) {
56657 var i, m;
56658 for (i = 2; i < 7; i++) {
56659 m = moment().subtract({d: i});
56660 assert.equal(m.calendar(), m.format('[วัน]dddd[ที่แล้ว เวลา] LT'), 'Today - ' + i + ' days current time');
56661 m.hours(0).minutes(0).seconds(0).milliseconds(0);
56662 assert.equal(m.calendar(), m.format('[วัน]dddd[ที่แล้ว เวลา] LT'), 'Today - ' + i + ' days beginning of day');
56663 m.hours(23).minutes(59).seconds(59).milliseconds(999);
56664 assert.equal(m.calendar(), m.format('[วัน]dddd[ที่แล้ว เวลา] LT'), 'Today - ' + i + ' days end of day');
73f3c911 56665 }
db71a655 56666 });
516f5f67 56667
db71a655
KM
56668 test('calendar all else', function (assert) {
56669 var weeksAgo = moment().subtract({w: 1}),
56670 weeksFromNow = moment().add({w: 1});
516f5f67 56671
db71a655
KM
56672 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
56673 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 56674
db71a655
KM
56675 weeksAgo = moment().subtract({w: 2});
56676 weeksFromNow = moment().add({w: 2});
516f5f67 56677
db71a655
KM
56678 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
56679 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
56680 });
73f3c911 56681
db71a655
KM
56682 test('weeks year starting sunday format', function (assert) {
56683 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1');
56684 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1', 'Jan 7 2012 should be week 1');
56685 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2');
56686 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2', 'Jan 14 2012 should be week 2');
56687 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', 'Jan 15 2012 should be week 3');
56688 });
73f3c911
IC
56689
56690})));
516f5f67 56691
516f5f67 56692
c74a101d
IC
56693;(function (global, factory) {
56694 typeof exports === 'object' && typeof module !== 'undefined'
56695 && typeof require === 'function' ? factory(require('../../moment')) :
25cc720f
IC
56696 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
56697 factory(global.moment)
73f3c911 56698}(this, (function (moment) { 'use strict';
25cc720f 56699
db71a655
KM
56700 function each(array, callback) {
56701 var i;
56702 for (i = 0; i < array.length; i++) {
56703 callback(array[i], i, array);
56704 }
b135bf1a
IC
56705 }
56706
c58511b9
KM
56707 function setupDeprecationHandler(test, moment$$1, scope) {
56708 test._expectedDeprecations = null;
56709 test._observedDeprecations = null;
56710 test._oldSupress = moment$$1.suppressDeprecationWarnings;
56711 moment$$1.suppressDeprecationWarnings = true;
56712 test.expectedDeprecations = function () {
56713 test._expectedDeprecations = arguments;
56714 test._observedDeprecations = [];
56715 };
56716 moment$$1.deprecationHandler = function (name, msg) {
56717 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
56718 if (deprecationId === -1) {
56719 throw new Error('Unexpected deprecation thrown name=' +
56720 name + ' msg=' + msg);
56721 }
56722 test._observedDeprecations[deprecationId] = 1;
56723 };
56724 }
56725
56726 function teardownDeprecationHandler(test, moment$$1, scope) {
56727 moment$$1.suppressDeprecationWarnings = test._oldSupress;
56728
56729 if (test._expectedDeprecations != null) {
56730 var missedDeprecations = [];
56731 each(test._expectedDeprecations, function (deprecationPattern, id) {
56732 if (test._observedDeprecations[id] !== 1) {
56733 missedDeprecations.push(deprecationPattern);
56734 }
56735 });
56736 if (missedDeprecations.length !== 0) {
56737 throw new Error('Expected deprecation warnings did not happen: ' +
56738 missedDeprecations.join(' '));
56739 }
56740 }
56741 }
56742
56743 function matchedDeprecation(name, msg, deprecations) {
56744 if (deprecations == null) {
56745 return -1;
56746 }
56747 for (var i = 0; i < deprecations.length; ++i) {
56748 if (name != null && name === deprecations[i]) {
56749 return i;
56750 }
56751 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
56752 return i;
56753 }
56754 }
56755 return -1;
56756 }
56757
56758 /*global QUnit:false*/
56759
56760 var test = QUnit.test;
56761
db71a655
KM
56762 function objectKeys(obj) {
56763 if (Object.keys) {
56764 return Object.keys(obj);
56765 } else {
56766 // IE8
56767 var res = [], i;
56768 for (i in obj) {
56769 if (obj.hasOwnProperty(i)) {
56770 res.push(i);
56771 }
b135bf1a 56772 }
db71a655 56773 return res;
b135bf1a
IC
56774 }
56775 }
56776
db71a655 56777 // Pick the first defined of two or three arguments.
73f3c911 56778
db71a655
KM
56779 function defineCommonLocaleTests(locale, options) {
56780 test('lenient day of month ordinal parsing', function (assert) {
56781 var i, ordinalStr, testMoment;
56782 for (i = 1; i <= 31; ++i) {
56783 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
56784 testMoment = moment(ordinalStr, 'YYYY MM Do');
56785 assert.equal(testMoment.year(), 2014,
56786 'lenient day of month ordinal parsing ' + i + ' year check');
56787 assert.equal(testMoment.month(), 0,
56788 'lenient day of month ordinal parsing ' + i + ' month check');
56789 assert.equal(testMoment.date(), i,
56790 'lenient day of month ordinal parsing ' + i + ' date check');
56791 }
56792 });
73f3c911 56793
db71a655
KM
56794 test('lenient day of month ordinal parsing of number', function (assert) {
56795 var i, testMoment;
56796 for (i = 1; i <= 31; ++i) {
56797 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
56798 assert.equal(testMoment.year(), 2014,
56799 'lenient day of month ordinal parsing of number ' + i + ' year check');
56800 assert.equal(testMoment.month(), 0,
56801 'lenient day of month ordinal parsing of number ' + i + ' month check');
56802 assert.equal(testMoment.date(), i,
56803 'lenient day of month ordinal parsing of number ' + i + ' date check');
56804 }
56805 });
56806
56807 test('strict day of month ordinal parsing', function (assert) {
56808 var i, ordinalStr, testMoment;
56809 for (i = 1; i <= 31; ++i) {
56810 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
56811 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
56812 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
56813 }
56814 });
56815
56816 test('meridiem invariant', function (assert) {
56817 var h, m, t1, t2;
56818 for (h = 0; h < 24; ++h) {
56819 for (m = 0; m < 60; m += 15) {
56820 t1 = moment.utc([2000, 0, 1, h, m]);
56821 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
56822 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
56823 'meridiem at ' + t1.format('HH:mm'));
56824 }
56825 }
56826 });
56827
56828 test('date format correctness', function (assert) {
56829 var data, tokens;
56830 data = moment.localeData()._longDateFormat;
56831 tokens = objectKeys(data);
56832 each(tokens, function (srchToken) {
56833 // Check each format string to make sure it does not contain any
56834 // tokens that need to be expanded.
56835 each(tokens, function (baseToken) {
56836 // strip escaped sequences
56837 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
56838 assert.equal(false, !!~format.indexOf(srchToken),
56839 'contains ' + srchToken + ' in ' + baseToken);
56840 });
56841 });
56842 });
56843
56844 test('month parsing correctness', function (assert) {
56845 var i, m;
56846
56847 if (locale === 'tr') {
56848 // I can't fix it :(
c58511b9 56849 assert.expect(0);
db71a655
KM
56850 return;
56851 }
56852 function tester(format) {
56853 var r;
56854 r = moment(m.format(format), format);
56855 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
56856 if (locale !== 'ka') {
56857 r = moment(m.format(format).toLocaleUpperCase(), format);
56858 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
56859 }
db71a655
KM
56860 r = moment(m.format(format).toLocaleLowerCase(), format);
56861 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
56862
56863 r = moment(m.format(format), format, true);
56864 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
56865 if (locale !== 'ka') {
56866 r = moment(m.format(format).toLocaleUpperCase(), format, true);
56867 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
56868 }
db71a655
KM
56869 r = moment(m.format(format).toLocaleLowerCase(), format, true);
56870 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
56871 }
56872
56873 for (i = 0; i < 12; ++i) {
56874 m = moment([2015, i, 15, 18]);
56875 tester('MMM');
56876 tester('MMM.');
56877 tester('MMMM');
56878 tester('MMMM.');
56879 }
56880 });
56881
56882 test('weekday parsing correctness', function (assert) {
56883 var i, m;
56884
96d0d679 56885 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
56886 // tr, az: There is a lower-case letter (ı), that converted to
56887 // upper then lower changes to i
56888 // ro: there is the letter ț which behaves weird under IE8
56889 // mt: letter Ħ
96d0d679 56890 // ga: month with spaces
c58511b9 56891 assert.expect(0);
db71a655
KM
56892 return;
56893 }
56894 function tester(format) {
56895 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
56896 r = moment(m.format(format), format);
56897 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
56898 if (locale !== 'ka') {
56899 r = moment(m.format(format).toLocaleUpperCase(), format);
56900 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
56901 }
db71a655
KM
56902 r = moment(m.format(format).toLocaleLowerCase(), format);
56903 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
56904 r = moment(m.format(format), format, true);
56905 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
56906 if (locale !== 'ka') {
56907 r = moment(m.format(format).toLocaleUpperCase(), format, true);
56908 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
56909 }
db71a655
KM
56910 r = moment(m.format(format).toLocaleLowerCase(), format, true);
56911 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
56912 }
56913
56914 for (i = 0; i < 7; ++i) {
56915 m = moment.utc([2015, 0, i + 1, 18]);
56916 tester('dd');
56917 tester('ddd');
56918 tester('dddd');
56919 }
56920 });
56921
56922 test('valid localeData', function (assert) {
56923 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
56924 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
56925 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
56926 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
56927 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
56928 });
96d0d679
KM
56929
56930 test('localeData weekdays can localeSort', function (assert) {
56931 var weekdays = moment().localeData().weekdays();
56932 var weekdaysShort = moment().localeData().weekdaysShort();
56933 var weekdaysMin = moment().localeData().weekdaysMin();
56934 var shift = moment().localeData()._week.dow;
56935 assert.deepEqual(
56936 moment().localeData().weekdays(true),
56937 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
56938 'weekdays should localeSort');
56939 assert.deepEqual(
56940 moment().localeData().weekdaysShort(true),
56941 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
56942 'weekdaysShort should localeSort');
56943 assert.deepEqual(
56944 moment().localeData().weekdaysMin(true),
56945 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
56946 'weekdaysMin should localeSort');
56947 });
db71a655
KM
56948 }
56949
db71a655
KM
56950 /*global QUnit:false*/
56951
db71a655
KM
56952 function localeModule (name, lifecycle) {
56953 QUnit.module('locale:' + name, {
c58511b9 56954 beforeEach : function () {
db71a655
KM
56955 moment.locale(name);
56956 moment.createFromInputFallback = function (config) {
56957 throw new Error('input not handled by moment: ' + config._i);
56958 };
56959 setupDeprecationHandler(test, moment, 'locale');
56960 if (lifecycle && lifecycle.setup) {
56961 lifecycle.setup();
56962 }
56963 },
c58511b9 56964 afterEach : function () {
db71a655
KM
56965 moment.locale('en');
56966 teardownDeprecationHandler(test, moment, 'locale');
56967 if (lifecycle && lifecycle.teardown) {
56968 lifecycle.teardown();
56969 }
56970 }
b135bf1a 56971 });
db71a655
KM
56972 defineCommonLocaleTests(name, -1, -1);
56973 }
56974
56975 localeModule('tl-ph');
56976
56977 test('parse', function (assert) {
56978 var tests = 'Enero Ene_Pebrero Peb_Marso Mar_Abril Abr_Mayo May_Hunyo Hun_Hulyo Hul_Agosto Ago_Setyembre Set_Oktubre Okt_Nobyembre Nob_Disyembre Dis'.split('_'),
56979 i;
56980 function equalTest(input, mmm, i) {
56981 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
56982 }
56983 for (i = 0; i < 12; i++) {
56984 tests[i] = tests[i].split(' ');
56985 equalTest(tests[i][0], 'MMM', i);
56986 equalTest(tests[i][1], 'MMM', i);
56987 equalTest(tests[i][0], 'MMMM', i);
56988 equalTest(tests[i][1], 'MMMM', i);
56989 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
56990 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
56991 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
56992 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
56993 }
56994 });
56995
56996 test('format', function (assert) {
56997 var a = [
56998 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Linggo, Pebrero 14 2010, 3:25:50 pm'],
56999 ['ddd, hA', 'Lin, 3PM'],
57000 ['M Mo MM MMMM MMM', '2 2 02 Pebrero Peb'],
57001 ['YYYY YY', '2010 10'],
57002 ['D Do DD', '14 14 14'],
57003 ['d do dddd ddd dd', '0 0 Linggo Lin Li'],
57004 ['DDD DDDo DDDD', '45 45 045'],
57005 ['w wo ww', '6 6 06'],
57006 ['h hh', '3 03'],
57007 ['H HH', '15 15'],
57008 ['m mm', '25 25'],
57009 ['s ss', '50 50'],
57010 ['a A', 'pm PM'],
57011 ['[the] DDDo [day of the year]', 'the 45 day of the year'],
57012 ['LTS', '15:25:50'],
57013 ['L', '02/14/2010'],
57014 ['LL', 'Pebrero 14, 2010'],
57015 ['LLL', 'Pebrero 14, 2010 15:25'],
57016 ['LLLL', 'Linggo, Pebrero 14, 2010 15:25'],
57017 ['l', '2/14/2010'],
57018 ['ll', 'Peb 14, 2010'],
57019 ['lll', 'Peb 14, 2010 15:25'],
57020 ['llll', 'Lin, Peb 14, 2010 15:25']
57021 ],
57022 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
57023 i;
57024 for (i = 0; i < a.length; i++) {
57025 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
57026 }
57027 });
57028
57029 test('format ordinal', function (assert) {
57030 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
57031 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
57032 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
57033 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
57034 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
57035 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
57036 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
57037 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
57038 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
57039 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
57040
57041 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
57042 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
57043 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
57044 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
57045 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
57046 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
57047 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
57048 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
57049 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
57050 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
57051
57052 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
57053 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
57054 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
57055 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
57056 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
57057 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
57058 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
57059 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
57060 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
57061 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
57062
57063 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
57064 });
57065
57066 test('format month', function (assert) {
57067 var expected = 'Enero Ene_Pebrero Peb_Marso Mar_Abril Abr_Mayo May_Hunyo Hun_Hulyo Hul_Agosto Ago_Setyembre Set_Oktubre Okt_Nobyembre Nob_Disyembre Dis'.split('_'), i;
57068 for (i = 0; i < expected.length; i++) {
57069 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
57070 }
57071 });
57072
57073 test('format week', function (assert) {
57074 var expected = 'Linggo Lin Li_Lunes Lun Lu_Martes Mar Ma_Miyerkules Miy Mi_Huwebes Huw Hu_Biyernes Biy Bi_Sabado Sab Sab'.split('_'), i;
57075 for (i = 0; i < expected.length; i++) {
57076 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
57077 }
57078 });
57079
57080 test('from', function (assert) {
57081 var start = moment([2007, 1, 28]);
57082 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ilang segundo', '44 seconds = a few seconds');
57083 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'isang minuto', '45 seconds = a minute');
57084 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'isang minuto', '89 seconds = a minute');
57085 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuto', '90 seconds = 2 minutes');
57086 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuto', '44 minutes = 44 minutes');
57087 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'isang oras', '45 minutes = an hour');
57088 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'isang oras', '89 minutes = an hour');
57089 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 oras', '90 minutes = 2 hours');
57090 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 oras', '5 hours = 5 hours');
57091 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 oras', '21 hours = 21 hours');
57092 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'isang araw', '22 hours = a day');
57093 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'isang araw', '35 hours = a day');
57094 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 araw', '36 hours = 2 days');
57095 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'isang araw', '1 day = a day');
57096 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 araw', '5 days = 5 days');
57097 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 araw', '25 days = 25 days');
57098 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'isang buwan', '26 days = a month');
57099 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'isang buwan', '30 days = a month');
57100 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'isang buwan', '43 days = a month');
57101 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 buwan', '46 days = 2 months');
57102 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 buwan', '75 days = 2 months');
57103 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 buwan', '76 days = 3 months');
57104 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'isang buwan', '1 month = a month');
57105 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 buwan', '5 months = 5 months');
57106 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'isang taon', '345 days = a year');
57107 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 taon', '548 days = 2 years');
57108 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'isang taon', '1 year = a year');
57109 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 taon', '5 years = 5 years');
57110 });
57111
57112 test('suffix', function (assert) {
57113 assert.equal(moment(30000).from(0), 'sa loob ng ilang segundo', 'prefix');
57114 assert.equal(moment(0).from(30000), 'ilang segundo ang nakalipas', 'suffix');
57115 });
57116
57117 test('fromNow', function (assert) {
57118 assert.equal(moment().add({s: 30}).fromNow(), 'sa loob ng ilang segundo', 'in a few seconds');
57119 assert.equal(moment().add({d: 5}).fromNow(), 'sa loob ng 5 araw', 'in 5 days');
57120 });
57121
57122 test('same day', function (assert) {
57123 var a = moment().hours(12).minutes(0).seconds(0);
57124
57125 assert.equal(moment(a).calendar(), '12:00 ngayong araw', 'today at the same time');
57126 assert.equal(moment(a).add({m: 25}).calendar(), '12:25 ngayong araw', 'Now plus 25 min');
57127 assert.equal(moment(a).add({h: 1}).calendar(), '13:00 ngayong araw', 'Now plus 1 hour');
57128 assert.equal(moment(a).add({d: 1}).calendar(), 'Bukas ng 12:00', 'tomorrow at the same time');
57129 assert.equal(moment(a).subtract({h: 1}).calendar(), '11:00 ngayong araw', 'Now minus 1 hour');
57130 assert.equal(moment(a).subtract({d: 1}).calendar(), '12:00 kahapon', 'yesterday at the same time');
57131 });
57132
57133 test('same next week', function (assert) {
57134 var i, m;
57135
57136 for (i = 2; i < 7; i++) {
57137 m = moment().add({d: i});
57138 assert.equal(m.calendar(), m.format('LT [sa susunod na] dddd'), 'Today + ' + i + ' days current time');
57139 m.hours(0).minutes(0).seconds(0).milliseconds(0);
57140 assert.equal(m.calendar(), m.format('LT [sa susunod na] dddd'), 'Today + ' + i + ' days beginning of day');
57141 m.hours(23).minutes(59).seconds(59).milliseconds(999);
57142 assert.equal(m.calendar(), m.format('LT [sa susunod na] dddd'), 'Today + ' + i + ' days end of day');
57143 }
73f3c911 57144 });
b135bf1a 57145
db71a655 57146 test('same last week', function (assert) {
73f3c911 57147 var i, m;
b135bf1a 57148
db71a655
KM
57149 for (i = 2; i < 7; i++) {
57150 m = moment().subtract({d: i});
57151 assert.equal(m.calendar(), m.format('LT [noong nakaraang] dddd'), 'Today - ' + i + ' days current time');
57152 m.hours(0).minutes(0).seconds(0).milliseconds(0);
57153 assert.equal(m.calendar(), m.format('LT [noong nakaraang] dddd'), 'Today - ' + i + ' days beginning of day');
57154 m.hours(23).minutes(59).seconds(59).milliseconds(999);
57155 assert.equal(m.calendar(), m.format('LT [noong nakaraang] dddd'), 'Today - ' + i + ' days end of day');
73f3c911 57156 }
db71a655 57157 });
b135bf1a 57158
db71a655
KM
57159 test('same all else', function (assert) {
57160 var weeksAgo = moment().subtract({w: 1}),
57161 weeksFromNow = moment().add({w: 1});
d6651c21 57162
db71a655
KM
57163 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
57164 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
57165
57166 weeksAgo = moment().subtract({w: 2});
57167 weeksFromNow = moment().add({w: 2});
57168
57169 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
57170 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
73f3c911 57171 });
d6651c21 57172
db71a655
KM
57173 test('weeks year starting sunday formatted', function (assert) {
57174 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52', 'Jan 1 2012 should be week 52');
57175 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1', 'Jan 2 2012 should be week 1');
57176 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1', 'Jan 8 2012 should be week 1');
57177 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2', 'Jan 9 2012 should be week 2');
57178 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2', 'Jan 15 2012 should be week 2');
57179 });
d6651c21 57180
db71a655
KM
57181})));
57182
57183
57184;(function (global, factory) {
57185 typeof exports === 'object' && typeof module !== 'undefined'
57186 && typeof require === 'function' ? factory(require('../../moment')) :
57187 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
57188 factory(global.moment)
57189}(this, (function (moment) { 'use strict';
57190
57191 function each(array, callback) {
57192 var i;
57193 for (i = 0; i < array.length; i++) {
57194 callback(array[i], i, array);
73f3c911 57195 }
db71a655 57196 }
d6651c21 57197
c58511b9
KM
57198 function setupDeprecationHandler(test, moment$$1, scope) {
57199 test._expectedDeprecations = null;
57200 test._observedDeprecations = null;
57201 test._oldSupress = moment$$1.suppressDeprecationWarnings;
57202 moment$$1.suppressDeprecationWarnings = true;
57203 test.expectedDeprecations = function () {
57204 test._expectedDeprecations = arguments;
57205 test._observedDeprecations = [];
57206 };
57207 moment$$1.deprecationHandler = function (name, msg) {
57208 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
57209 if (deprecationId === -1) {
57210 throw new Error('Unexpected deprecation thrown name=' +
57211 name + ' msg=' + msg);
57212 }
57213 test._observedDeprecations[deprecationId] = 1;
57214 };
57215 }
57216
57217 function teardownDeprecationHandler(test, moment$$1, scope) {
57218 moment$$1.suppressDeprecationWarnings = test._oldSupress;
57219
57220 if (test._expectedDeprecations != null) {
57221 var missedDeprecations = [];
57222 each(test._expectedDeprecations, function (deprecationPattern, id) {
57223 if (test._observedDeprecations[id] !== 1) {
57224 missedDeprecations.push(deprecationPattern);
57225 }
57226 });
57227 if (missedDeprecations.length !== 0) {
57228 throw new Error('Expected deprecation warnings did not happen: ' +
57229 missedDeprecations.join(' '));
57230 }
57231 }
57232 }
57233
57234 function matchedDeprecation(name, msg, deprecations) {
57235 if (deprecations == null) {
57236 return -1;
57237 }
57238 for (var i = 0; i < deprecations.length; ++i) {
57239 if (name != null && name === deprecations[i]) {
57240 return i;
57241 }
57242 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
57243 return i;
57244 }
57245 }
57246 return -1;
57247 }
57248
57249 /*global QUnit:false*/
57250
57251 var test = QUnit.test;
57252
db71a655
KM
57253 function objectKeys(obj) {
57254 if (Object.keys) {
57255 return Object.keys(obj);
57256 } else {
57257 // IE8
57258 var res = [], i;
57259 for (i in obj) {
57260 if (obj.hasOwnProperty(i)) {
57261 res.push(i);
57262 }
57263 }
57264 return res;
d6651c21 57265 }
db71a655 57266 }
73f3c911 57267
db71a655 57268 // Pick the first defined of two or three arguments.
73f3c911 57269
db71a655
KM
57270 function defineCommonLocaleTests(locale, options) {
57271 test('lenient day of month ordinal parsing', function (assert) {
57272 var i, ordinalStr, testMoment;
57273 for (i = 1; i <= 31; ++i) {
57274 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
57275 testMoment = moment(ordinalStr, 'YYYY MM Do');
57276 assert.equal(testMoment.year(), 2014,
57277 'lenient day of month ordinal parsing ' + i + ' year check');
57278 assert.equal(testMoment.month(), 0,
57279 'lenient day of month ordinal parsing ' + i + ' month check');
57280 assert.equal(testMoment.date(), i,
57281 'lenient day of month ordinal parsing ' + i + ' date check');
d6651c21 57282 }
73f3c911 57283 });
db71a655
KM
57284
57285 test('lenient day of month ordinal parsing of number', function (assert) {
57286 var i, testMoment;
57287 for (i = 1; i <= 31; ++i) {
57288 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
57289 assert.equal(testMoment.year(), 2014,
57290 'lenient day of month ordinal parsing of number ' + i + ' year check');
57291 assert.equal(testMoment.month(), 0,
57292 'lenient day of month ordinal parsing of number ' + i + ' month check');
57293 assert.equal(testMoment.date(), i,
57294 'lenient day of month ordinal parsing of number ' + i + ' date check');
57295 }
57296 });
57297
57298 test('strict day of month ordinal parsing', function (assert) {
57299 var i, ordinalStr, testMoment;
57300 for (i = 1; i <= 31; ++i) {
57301 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
57302 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
57303 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
57304 }
57305 });
57306
57307 test('meridiem invariant', function (assert) {
57308 var h, m, t1, t2;
57309 for (h = 0; h < 24; ++h) {
57310 for (m = 0; m < 60; m += 15) {
57311 t1 = moment.utc([2000, 0, 1, h, m]);
57312 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
57313 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
57314 'meridiem at ' + t1.format('HH:mm'));
57315 }
57316 }
57317 });
57318
57319 test('date format correctness', function (assert) {
57320 var data, tokens;
57321 data = moment.localeData()._longDateFormat;
57322 tokens = objectKeys(data);
57323 each(tokens, function (srchToken) {
57324 // Check each format string to make sure it does not contain any
57325 // tokens that need to be expanded.
57326 each(tokens, function (baseToken) {
57327 // strip escaped sequences
57328 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
57329 assert.equal(false, !!~format.indexOf(srchToken),
57330 'contains ' + srchToken + ' in ' + baseToken);
57331 });
57332 });
57333 });
57334
57335 test('month parsing correctness', function (assert) {
57336 var i, m;
57337
57338 if (locale === 'tr') {
57339 // I can't fix it :(
c58511b9 57340 assert.expect(0);
db71a655
KM
57341 return;
57342 }
57343 function tester(format) {
57344 var r;
57345 r = moment(m.format(format), format);
57346 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
57347 if (locale !== 'ka') {
57348 r = moment(m.format(format).toLocaleUpperCase(), format);
57349 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
57350 }
db71a655
KM
57351 r = moment(m.format(format).toLocaleLowerCase(), format);
57352 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
57353
57354 r = moment(m.format(format), format, true);
57355 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
57356 if (locale !== 'ka') {
57357 r = moment(m.format(format).toLocaleUpperCase(), format, true);
57358 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
57359 }
db71a655
KM
57360 r = moment(m.format(format).toLocaleLowerCase(), format, true);
57361 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
57362 }
57363
57364 for (i = 0; i < 12; ++i) {
57365 m = moment([2015, i, 15, 18]);
57366 tester('MMM');
57367 tester('MMM.');
57368 tester('MMMM');
57369 tester('MMMM.');
57370 }
57371 });
57372
57373 test('weekday parsing correctness', function (assert) {
57374 var i, m;
57375
96d0d679 57376 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
57377 // tr, az: There is a lower-case letter (ı), that converted to
57378 // upper then lower changes to i
57379 // ro: there is the letter ț which behaves weird under IE8
57380 // mt: letter Ħ
96d0d679 57381 // ga: month with spaces
c58511b9 57382 assert.expect(0);
db71a655
KM
57383 return;
57384 }
57385 function tester(format) {
57386 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
57387 r = moment(m.format(format), format);
57388 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
57389 if (locale !== 'ka') {
57390 r = moment(m.format(format).toLocaleUpperCase(), format);
57391 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
57392 }
db71a655
KM
57393 r = moment(m.format(format).toLocaleLowerCase(), format);
57394 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
57395 r = moment(m.format(format), format, true);
57396 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
57397 if (locale !== 'ka') {
57398 r = moment(m.format(format).toLocaleUpperCase(), format, true);
57399 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
57400 }
db71a655
KM
57401 r = moment(m.format(format).toLocaleLowerCase(), format, true);
57402 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
57403 }
57404
57405 for (i = 0; i < 7; ++i) {
57406 m = moment.utc([2015, 0, i + 1, 18]);
57407 tester('dd');
57408 tester('ddd');
57409 tester('dddd');
57410 }
57411 });
57412
57413 test('valid localeData', function (assert) {
57414 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
57415 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
57416 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
57417 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
57418 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
57419 });
96d0d679
KM
57420
57421 test('localeData weekdays can localeSort', function (assert) {
57422 var weekdays = moment().localeData().weekdays();
57423 var weekdaysShort = moment().localeData().weekdaysShort();
57424 var weekdaysMin = moment().localeData().weekdaysMin();
57425 var shift = moment().localeData()._week.dow;
57426 assert.deepEqual(
57427 moment().localeData().weekdays(true),
57428 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
57429 'weekdays should localeSort');
57430 assert.deepEqual(
57431 moment().localeData().weekdaysShort(true),
57432 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
57433 'weekdaysShort should localeSort');
57434 assert.deepEqual(
57435 moment().localeData().weekdaysMin(true),
57436 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
57437 'weekdaysMin should localeSort');
57438 });
73f3c911 57439 }
73f3c911 57440
db71a655 57441 /*global QUnit:false*/
25cc720f 57442
db71a655
KM
57443 function localeModule (name, lifecycle) {
57444 QUnit.module('locale:' + name, {
c58511b9 57445 beforeEach : function () {
db71a655
KM
57446 moment.locale(name);
57447 moment.createFromInputFallback = function (config) {
57448 throw new Error('input not handled by moment: ' + config._i);
57449 };
57450 setupDeprecationHandler(test, moment, 'locale');
57451 if (lifecycle && lifecycle.setup) {
57452 lifecycle.setup();
57453 }
57454 },
c58511b9 57455 afterEach : function () {
db71a655
KM
57456 moment.locale('en');
57457 teardownDeprecationHandler(test, moment, 'locale');
57458 if (lifecycle && lifecycle.teardown) {
57459 lifecycle.teardown();
57460 }
516f5f67 57461 }
db71a655
KM
57462 });
57463 defineCommonLocaleTests(name, -1, -1);
57464 }
57465
57466 localeModule('tlh');
57467
57468 //Current parsing method doesn't allow parsing correctly months 10, 11 and 12.
57469 /*
57470 * test('parse', function (assert) {
57471 var tests = 'tera’ jar wa’.jar wa’_tera’ jar cha’.jar cha’_tera’ jar wej.jar wej_tera’ jar loS.jar loS_tera’ jar vagh.jar vagh_tera’ jar jav.jar jav_tera’ jar Soch.jar Soch_tera’ jar chorgh.jar chorgh_tera’ jar Hut.jar Hut_tera’ jar wa’maH.jar wa’maH_tera’ jar wa’maH wa’.jar wa’maH wa’_tera’ jar wa’maH cha’.jar wa’maH cha’'.split('_'), i;
57472 function equalTest(input, mmm, i) {
57473 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
57474 }
57475 for (i = 0; i < 12; i++) {
57476 tests[i] = tests[i].split('.');
57477 equalTest(tests[i][0], 'MMM', i);
57478 equalTest(tests[i][1], 'MMM', i);
57479 equalTest(tests[i][0], 'MMMM', i);
57480 equalTest(tests[i][1], 'MMMM', i);
57481 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
57482 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
57483 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
57484 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
57485 }
57486 });
57487 */
57488 test('format', function (assert) {
57489 var a = [
57490 ['dddd, MMMM Do YYYY, h:mm:ss a', 'lojmItjaj, tera’ jar cha’ 14. 2010, 3:25:50 pm'],
57491 ['ddd, hA', 'lojmItjaj, 3PM'],
57492 ['M Mo MM MMMM MMM', '2 2. 02 tera’ jar cha’ jar cha’'],
57493 ['YYYY YY', '2010 10'],
57494 ['D Do DD', '14 14. 14'],
57495 ['d do dddd ddd dd', '0 0. lojmItjaj lojmItjaj lojmItjaj'],
57496 ['DDD DDDo DDDD', '45 45. 045'],
57497 ['w wo ww', '6 6. 06'],
57498 ['h hh', '3 03'],
57499 ['H HH', '15 15'],
57500 ['m mm', '25 25'],
57501 ['s ss', '50 50'],
57502 ['a A', 'pm PM'],
57503 ['[DIS jaj] DDDo', 'DIS jaj 45.'],
57504 ['LTS', '15:25:50'],
57505 ['L', '14.02.2010'],
57506 ['LL', '14 tera’ jar cha’ 2010'],
57507 ['LLL', '14 tera’ jar cha’ 2010 15:25'],
57508 ['LLLL', 'lojmItjaj, 14 tera’ jar cha’ 2010 15:25'],
57509 ['l', '14.2.2010'],
57510 ['ll', '14 jar cha’ 2010'],
57511 ['lll', '14 jar cha’ 2010 15:25'],
57512 ['llll', 'lojmItjaj, 14 jar cha’ 2010 15:25']
57513 ],
57514 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
57515 i;
57516 for (i = 0; i < a.length; i++) {
57517 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
57518 }
57519 });
57520
57521 test('format ordinal', function (assert) {
57522 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
57523 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
57524 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
57525 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
57526 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
57527 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
57528 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
57529 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
57530 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
57531 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
57532
57533 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
57534 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
57535 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
57536 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
57537 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
57538 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
57539 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
57540 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
57541 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
57542 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
57543
57544 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
57545 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
57546 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
57547 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
57548 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
57549 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
57550 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
57551 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
57552 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
57553 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
57554
57555 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
57556 });
57557
57558 test('format month', function (assert) {
57559 var expected = 'tera’ jar wa’ jar wa’_tera’ jar cha’ jar cha’_tera’ jar wej jar wej_tera’ jar loS jar loS_tera’ jar vagh jar vagh_tera’ jar jav jar jav_tera’ jar Soch jar Soch_tera’ jar chorgh jar chorgh_tera’ jar Hut jar Hut_tera’ jar wa’maH jar wa’maH_tera’ jar wa’maH wa’ jar wa’maH wa’_tera’ jar wa’maH cha’ jar wa’maH cha’'.split('_'), i;
57560 for (i = 0; i < expected.length; i++) {
57561 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
57562 }
57563 });
57564
57565 test('format week', function (assert) {
57566 var expected = 'lojmItjaj lojmItjaj lojmItjaj_DaSjaj DaSjaj DaSjaj_povjaj povjaj povjaj_ghItlhjaj ghItlhjaj ghItlhjaj_loghjaj loghjaj loghjaj_buqjaj buqjaj buqjaj_ghInjaj ghInjaj ghInjaj'.split('_'), i;
57567 for (i = 0; i < expected.length; i++) {
57568 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
57569 }
57570 });
57571
57572 test('from', function (assert) {
57573 var start = moment([2007, 1, 28]);
57574 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'puS lup', '44 seconds = a few seconds');
57575 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'wa’ tup', '45 seconds = a minute');
57576 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'wa’ tup', '89 seconds = a minute');
57577 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), 'cha’ tup', '90 seconds = 2 minutes');
57578 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), 'loSmaH loS tup', '44 minutes = 44 minutes');
57579 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'wa’ rep', '45 minutes = an hour');
57580 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'wa’ rep', '89 minutes = an hour');
57581 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), 'cha’ rep', '90 minutes = 2 hours');
57582 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), 'vagh rep', '5 hours = 5 hours');
57583 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), 'cha’maH wa’ rep', '21 hours = 21 hours');
57584 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'wa’ jaj', '22 hours = a day');
57585 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'wa’ jaj', '35 hours = a day');
57586 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), 'cha’ jaj', '36 hours = 2 days');
57587 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'wa’ jaj', '1 day = a day');
57588 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), 'vagh jaj', '5 days = 5 days');
57589 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), 'cha’maH vagh jaj', '25 days = 25 days');
57590 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'wa’ jar', '26 days = a month');
57591 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'wa’ jar', '30 days = a month');
57592 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'wa’ jar', '43 days = a month');
57593 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), 'cha’ jar', '46 days = 2 months');
57594 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), 'cha’ jar', '75 days = 2 months');
57595 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), 'wej jar', '76 days = 3 months');
57596 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'wa’ jar', '1 month = a month');
57597 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), 'vagh jar', '5 months = 5 months');
57598 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'wa’ DIS', '345 days = a year');
57599 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), 'cha’ DIS', '548 days = 2 years');
57600 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'wa’ DIS', '1 year = a year');
57601 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), 'vagh DIS', '5 years = 5 years');
57602 assert.equal(start.from(moment([2007, 1, 28]).add({y: 112}), true), 'wa’vatlh wa’maH cha’ DIS', '112 years = 112 years');
57603 assert.equal(start.from(moment([2007, 1, 28]).add({y: 122}), true), 'wa’vatlh cha’maH cha’ DIS', '122 years = 122 years');
57604 assert.equal(start.from(moment([2007, 1, 28]).add({y: 213}), true), 'cha’vatlh wa’maH wej DIS', '213 years = 213 years');
57605 assert.equal(start.from(moment([2007, 1, 28]).add({y: 223}), true), 'cha’vatlh cha’maH wej DIS', '223 years = 223 years');
57606 });
57607
57608 test('suffix', function (assert) {
57609 assert.equal(moment(30000).from(0), 'puS lup pIq', 'suffix');
57610 assert.equal(moment(0).from(30000), 'puS lup ret', 'suffix');
57611 });
57612
57613 test('now from now', function (assert) {
57614 assert.equal(moment().fromNow(), 'puS lup ret', 'now from now should display as in the past');
57615 });
57616
57617 test('fromNow', function (assert) {
57618 assert.equal(moment().add({s: 30}).fromNow(), 'puS lup pIq', 'in a few seconds');
57619 assert.equal(moment().add({h: 1}).fromNow(), 'wa’ rep pIq', 'in an hour');
57620 assert.equal(moment().add({d: 5}).fromNow(), 'vagh leS', 'in 5 days');
57621 assert.equal(moment().add({M: 2}).fromNow(), 'cha’ waQ', 'in 2 months');
57622 assert.equal(moment().add({y: 1}).fromNow(), 'wa’ nem', 'in a year');
57623 assert.equal(moment().add({s: -30}).fromNow(), 'puS lup ret', 'a few seconds ago');
57624 assert.equal(moment().add({h: -1}).fromNow(), 'wa’ rep ret', 'an hour ago');
57625 assert.equal(moment().add({d: -5}).fromNow(), 'vagh Hu’', '5 days ago');
57626 assert.equal(moment().add({M: -2}).fromNow(), 'cha’ wen', '2 months ago');
57627 assert.equal(moment().add({y: -1}).fromNow(), 'wa’ ben', 'a year ago');
57628 });
57629
57630 test('calendar day', function (assert) {
57631 var a = moment().hours(12).minutes(0).seconds(0);
57632
57633 assert.equal(moment(a).calendar(), 'DaHjaj 12:00', 'today at the same time');
57634 assert.equal(moment(a).add({m: 25}).calendar(), 'DaHjaj 12:25', 'Now plus 25 min');
57635 assert.equal(moment(a).add({h: 1}).calendar(), 'DaHjaj 13:00', 'Now plus 1 hour');
57636 assert.equal(moment(a).add({d: 1}).calendar(), 'wa’leS 12:00', 'tomorrow at the same time');
57637 assert.equal(moment(a).subtract({h: 1}).calendar(), 'DaHjaj 11:00', 'Now minus 1 hour');
57638 assert.equal(moment(a).subtract({d: 1}).calendar(), 'wa’Hu’ 12:00', 'yesterday at the same time');
57639 });
57640
57641 test('calendar next week', function (assert) {
57642 var i, m;
57643 for (i = 2; i < 7; i++) {
57644 m = moment().add({d: i});
57645 assert.equal(m.calendar(), m.format('LLL'), 'Today + ' + i + ' days current time');
57646 m.hours(0).minutes(0).seconds(0).milliseconds(0);
57647 assert.equal(m.calendar(), m.format('LLL'), 'Today + ' + i + ' days beginning of day');
57648 m.hours(23).minutes(59).seconds(59).milliseconds(999);
57649 assert.equal(m.calendar(), m.format('LLL'), 'Today + ' + i + ' days end of day');
57650 }
57651 });
57652
57653 test('calendar last week', function (assert) {
57654 var i, m;
57655 for (i = 2; i < 7; i++) {
57656 m = moment().subtract({d: i});
57657 assert.equal(m.calendar(), m.format('LLL'), 'Today - ' + i + ' days current time');
57658
57659 m.hours(0).minutes(0).seconds(0).milliseconds(0);
57660 assert.equal(m.calendar(), m.format('LLL'), 'Today - ' + i + ' days beginning of day');
57661
57662 m.hours(23).minutes(59).seconds(59).milliseconds(999);
57663 assert.equal(m.calendar(), m.format('LLL'), 'Today - ' + i + ' days end of day');
57664 }
57665 });
57666
57667 test('calendar all else', function (assert) {
57668 var weeksAgo = moment().subtract({w: 1}),
57669 weeksFromNow = moment().add({w: 1});
57670
57671 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
57672 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
57673
57674 weeksAgo = moment().subtract({w: 2});
57675 weeksFromNow = moment().add({w: 2});
57676
57677 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
57678 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
57679 });
57680
57681 test('weeks year starting sunday formatted', function (assert) {
57682 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
57683 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
57684 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
57685 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
57686 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
57687 });
73f3c911
IC
57688
57689})));
57690
516f5f67 57691
c74a101d
IC
57692;(function (global, factory) {
57693 typeof exports === 'object' && typeof module !== 'undefined'
57694 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
57695 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
57696 factory(global.moment)
73f3c911 57697}(this, (function (moment) { 'use strict';
516f5f67 57698
db71a655
KM
57699 function each(array, callback) {
57700 var i;
57701 for (i = 0; i < array.length; i++) {
57702 callback(array[i], i, array);
57703 }
b135bf1a
IC
57704 }
57705
c58511b9
KM
57706 function setupDeprecationHandler(test, moment$$1, scope) {
57707 test._expectedDeprecations = null;
57708 test._observedDeprecations = null;
57709 test._oldSupress = moment$$1.suppressDeprecationWarnings;
57710 moment$$1.suppressDeprecationWarnings = true;
57711 test.expectedDeprecations = function () {
57712 test._expectedDeprecations = arguments;
57713 test._observedDeprecations = [];
57714 };
57715 moment$$1.deprecationHandler = function (name, msg) {
57716 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
57717 if (deprecationId === -1) {
57718 throw new Error('Unexpected deprecation thrown name=' +
57719 name + ' msg=' + msg);
57720 }
57721 test._observedDeprecations[deprecationId] = 1;
57722 };
57723 }
57724
57725 function teardownDeprecationHandler(test, moment$$1, scope) {
57726 moment$$1.suppressDeprecationWarnings = test._oldSupress;
57727
57728 if (test._expectedDeprecations != null) {
57729 var missedDeprecations = [];
57730 each(test._expectedDeprecations, function (deprecationPattern, id) {
57731 if (test._observedDeprecations[id] !== 1) {
57732 missedDeprecations.push(deprecationPattern);
57733 }
57734 });
57735 if (missedDeprecations.length !== 0) {
57736 throw new Error('Expected deprecation warnings did not happen: ' +
57737 missedDeprecations.join(' '));
57738 }
57739 }
57740 }
57741
57742 function matchedDeprecation(name, msg, deprecations) {
57743 if (deprecations == null) {
57744 return -1;
57745 }
57746 for (var i = 0; i < deprecations.length; ++i) {
57747 if (name != null && name === deprecations[i]) {
57748 return i;
57749 }
57750 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
57751 return i;
57752 }
57753 }
57754 return -1;
57755 }
57756
57757 /*global QUnit:false*/
57758
57759 var test = QUnit.test;
57760
db71a655
KM
57761 function objectKeys(obj) {
57762 if (Object.keys) {
57763 return Object.keys(obj);
57764 } else {
57765 // IE8
57766 var res = [], i;
57767 for (i in obj) {
57768 if (obj.hasOwnProperty(i)) {
57769 res.push(i);
57770 }
b135bf1a 57771 }
db71a655 57772 return res;
b135bf1a
IC
57773 }
57774 }
73f3c911 57775
db71a655 57776 // Pick the first defined of two or three arguments.
b135bf1a 57777
db71a655
KM
57778 function defineCommonLocaleTests(locale, options) {
57779 test('lenient day of month ordinal parsing', function (assert) {
57780 var i, ordinalStr, testMoment;
57781 for (i = 1; i <= 31; ++i) {
57782 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
57783 testMoment = moment(ordinalStr, 'YYYY MM Do');
57784 assert.equal(testMoment.year(), 2014,
57785 'lenient day of month ordinal parsing ' + i + ' year check');
57786 assert.equal(testMoment.month(), 0,
57787 'lenient day of month ordinal parsing ' + i + ' month check');
57788 assert.equal(testMoment.date(), i,
57789 'lenient day of month ordinal parsing ' + i + ' date check');
57790 }
57791 });
b135bf1a 57792
db71a655
KM
57793 test('lenient day of month ordinal parsing of number', function (assert) {
57794 var i, testMoment;
57795 for (i = 1; i <= 31; ++i) {
57796 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
57797 assert.equal(testMoment.year(), 2014,
57798 'lenient day of month ordinal parsing of number ' + i + ' year check');
57799 assert.equal(testMoment.month(), 0,
57800 'lenient day of month ordinal parsing of number ' + i + ' month check');
57801 assert.equal(testMoment.date(), i,
57802 'lenient day of month ordinal parsing of number ' + i + ' date check');
57803 }
b135bf1a
IC
57804 });
57805
db71a655
KM
57806 test('strict day of month ordinal parsing', function (assert) {
57807 var i, ordinalStr, testMoment;
57808 for (i = 1; i <= 31; ++i) {
57809 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
57810 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
57811 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
57812 }
57813 });
b135bf1a 57814
db71a655
KM
57815 test('meridiem invariant', function (assert) {
57816 var h, m, t1, t2;
57817 for (h = 0; h < 24; ++h) {
57818 for (m = 0; m < 60; m += 15) {
57819 t1 = moment.utc([2000, 0, 1, h, m]);
57820 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
57821 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
57822 'meridiem at ' + t1.format('HH:mm'));
57823 }
57824 }
57825 });
b135bf1a 57826
db71a655
KM
57827 test('date format correctness', function (assert) {
57828 var data, tokens;
57829 data = moment.localeData()._longDateFormat;
57830 tokens = objectKeys(data);
57831 each(tokens, function (srchToken) {
57832 // Check each format string to make sure it does not contain any
57833 // tokens that need to be expanded.
57834 each(tokens, function (baseToken) {
57835 // strip escaped sequences
57836 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
57837 assert.equal(false, !!~format.indexOf(srchToken),
57838 'contains ' + srchToken + ' in ' + baseToken);
57839 });
57840 });
57841 });
d6651c21 57842
db71a655
KM
57843 test('month parsing correctness', function (assert) {
57844 var i, m;
57845
57846 if (locale === 'tr') {
57847 // I can't fix it :(
c58511b9 57848 assert.expect(0);
db71a655
KM
57849 return;
57850 }
57851 function tester(format) {
57852 var r;
57853 r = moment(m.format(format), format);
57854 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
57855 if (locale !== 'ka') {
57856 r = moment(m.format(format).toLocaleUpperCase(), format);
57857 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
57858 }
db71a655
KM
57859 r = moment(m.format(format).toLocaleLowerCase(), format);
57860 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
57861
57862 r = moment(m.format(format), format, true);
57863 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
57864 if (locale !== 'ka') {
57865 r = moment(m.format(format).toLocaleUpperCase(), format, true);
57866 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
57867 }
db71a655
KM
57868 r = moment(m.format(format).toLocaleLowerCase(), format, true);
57869 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
57870 }
57871
57872 for (i = 0; i < 12; ++i) {
57873 m = moment([2015, i, 15, 18]);
57874 tester('MMM');
57875 tester('MMM.');
57876 tester('MMMM');
57877 tester('MMMM.');
57878 }
57879 });
d6651c21 57880
db71a655
KM
57881 test('weekday parsing correctness', function (assert) {
57882 var i, m;
57883
96d0d679 57884 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
57885 // tr, az: There is a lower-case letter (ı), that converted to
57886 // upper then lower changes to i
57887 // ro: there is the letter ț which behaves weird under IE8
57888 // mt: letter Ħ
96d0d679 57889 // ga: month with spaces
c58511b9 57890 assert.expect(0);
db71a655
KM
57891 return;
57892 }
57893 function tester(format) {
57894 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
57895 r = moment(m.format(format), format);
57896 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
57897 if (locale !== 'ka') {
57898 r = moment(m.format(format).toLocaleUpperCase(), format);
57899 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
57900 }
db71a655
KM
57901 r = moment(m.format(format).toLocaleLowerCase(), format);
57902 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
57903 r = moment(m.format(format), format, true);
57904 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
57905 if (locale !== 'ka') {
57906 r = moment(m.format(format).toLocaleUpperCase(), format, true);
57907 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
57908 }
db71a655
KM
57909 r = moment(m.format(format).toLocaleLowerCase(), format, true);
57910 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
57911 }
57912
57913 for (i = 0; i < 7; ++i) {
57914 m = moment.utc([2015, 0, i + 1, 18]);
57915 tester('dd');
57916 tester('ddd');
57917 tester('dddd');
57918 }
57919 });
d6651c21 57920
db71a655
KM
57921 test('valid localeData', function (assert) {
57922 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
57923 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
57924 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
57925 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
57926 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
57927 });
96d0d679
KM
57928
57929 test('localeData weekdays can localeSort', function (assert) {
57930 var weekdays = moment().localeData().weekdays();
57931 var weekdaysShort = moment().localeData().weekdaysShort();
57932 var weekdaysMin = moment().localeData().weekdaysMin();
57933 var shift = moment().localeData()._week.dow;
57934 assert.deepEqual(
57935 moment().localeData().weekdays(true),
57936 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
57937 'weekdays should localeSort');
57938 assert.deepEqual(
57939 moment().localeData().weekdaysShort(true),
57940 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
57941 'weekdaysShort should localeSort');
57942 assert.deepEqual(
57943 moment().localeData().weekdaysMin(true),
57944 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
57945 'weekdaysMin should localeSort');
57946 });
db71a655 57947 }
d6651c21 57948
db71a655 57949 /*global QUnit:false*/
516f5f67 57950
db71a655
KM
57951 function localeModule (name, lifecycle) {
57952 QUnit.module('locale:' + name, {
c58511b9 57953 beforeEach : function () {
db71a655
KM
57954 moment.locale(name);
57955 moment.createFromInputFallback = function (config) {
57956 throw new Error('input not handled by moment: ' + config._i);
57957 };
57958 setupDeprecationHandler(test, moment, 'locale');
57959 if (lifecycle && lifecycle.setup) {
57960 lifecycle.setup();
57961 }
57962 },
c58511b9 57963 afterEach : function () {
db71a655
KM
57964 moment.locale('en');
57965 teardownDeprecationHandler(test, moment, 'locale');
57966 if (lifecycle && lifecycle.teardown) {
57967 lifecycle.teardown();
57968 }
516f5f67 57969 }
db71a655
KM
57970 });
57971 defineCommonLocaleTests(name, -1, -1);
57972 }
57973
57974 localeModule('tr');
57975
57976 test('parse', function (assert) {
57977 var tests = 'Ocak Oca_Şubat Şub_Mart Mar_Nisan Nis_Mayıs May_Haziran Haz_Temmuz Tem_Ağustos Ağu_Eylül Eyl_Ekim Eki_Kasım Kas_Aralık Ara'.split('_'), i;
57978 function equalTest(input, mmm, i) {
57979 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
57980 }
57981 for (i = 0; i < 12; i++) {
57982 tests[i] = tests[i].split(' ');
57983 equalTest(tests[i][0], 'MMM', i);
57984 equalTest(tests[i][1], 'MMM', i);
57985 equalTest(tests[i][0], 'MMMM', i);
57986 equalTest(tests[i][1], 'MMMM', i);
57987 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
57988 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
57989 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
57990 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
57991 }
57992 });
57993
57994 test('format', function (assert) {
57995 var a = [
57996 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Pazar, Şubat 14 2010, 3:25:50 pm'],
57997 ['ddd, hA', 'Paz, 3PM'],
57998 ['M Mo MM MMMM MMM', '2 2\'nci 02 Şubat Şub'],
57999 ['YYYY YY', '2010 10'],
58000 ['D Do DD', '14 14 14'],
58001 ['d do dddd ddd dd', '0 0 Pazar Paz Pz'],
58002 ['DDD DDDo DDDD', '45 45\'inci 045'],
58003 ['w wo ww', '7 7\'nci 07'],
58004 ['h hh', '3 03'],
58005 ['H HH', '15 15'],
58006 ['m mm', '25 25'],
58007 ['s ss', '50 50'],
58008 ['a A', 'pm PM'],
58009 ['[yılın] DDDo [günü]', 'yılın 45\'inci günü'],
58010 ['LTS', '15:25:50'],
58011 ['L', '14.02.2010'],
58012 ['LL', '14 Şubat 2010'],
58013 ['LLL', '14 Şubat 2010 15:25'],
58014 ['LLLL', 'Pazar, 14 Şubat 2010 15:25'],
58015 ['l', '14.2.2010'],
58016 ['ll', '14 Şub 2010'],
58017 ['lll', '14 Şub 2010 15:25'],
58018 ['llll', 'Paz, 14 Şub 2010 15:25']
58019 ],
58020 DDDo = [
58021 [359, '360\'ıncı'],
58022 [199, '200\'üncü'],
58023 [149, '150\'nci']
58024 ],
58025 dt = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
58026 DDDoDt,
58027 i;
58028
58029 for (i = 0; i < a.length; i++) {
58030 assert.equal(dt.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
58031 }
58032 for (i = 0; i < DDDo.length; i++) {
58033 DDDoDt = moment([2010]);
58034 assert.equal(DDDoDt.add(DDDo[i][0], 'days').format('DDDo'), DDDo[i][1], DDDo[i][0] + ' ---> ' + DDDo[i][1]);
58035 }
58036 });
58037
58038 test('format ordinal', function (assert) {
58039 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1\'inci', '1st');
58040 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2\'nci', '2nd');
58041 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3\'üncü', '3rd');
58042 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4\'üncü', '4th');
58043 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5\'inci', '5th');
58044 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6\'ncı', '6th');
58045 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7\'nci', '7th');
58046 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8\'inci', '8th');
58047 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9\'uncu', '9th');
58048 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10\'uncu', '10th');
58049
58050 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11\'inci', '11th');
58051 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12\'nci', '12th');
58052 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13\'üncü', '13th');
58053 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14\'üncü', '14th');
58054 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15\'inci', '15th');
58055 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16\'ncı', '16th');
58056 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17\'nci', '17th');
58057 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18\'inci', '18th');
58058 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19\'uncu', '19th');
58059 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20\'nci', '20th');
58060
58061 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21\'inci', '21th');
58062 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22\'nci', '22th');
58063 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23\'üncü', '23th');
58064 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24\'üncü', '24th');
58065 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25\'inci', '25th');
58066 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26\'ncı', '26th');
58067 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27\'nci', '27th');
58068 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28\'inci', '28th');
58069 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29\'uncu', '29th');
58070 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30\'uncu', '30th');
58071
58072 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31\'inci', '31st');
58073 });
58074
58075 test('format month', function (assert) {
58076 var expected = 'Ocak Oca_Şubat Şub_Mart Mar_Nisan Nis_Mayıs May_Haziran Haz_Temmuz Tem_Ağustos Ağu_Eylül Eyl_Ekim Eki_Kasım Kas_Aralık Ara'.split('_'), i;
58077 for (i = 0; i < expected.length; i++) {
58078 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
58079 }
58080 });
58081
58082 test('format week', function (assert) {
58083 var expected = 'Pazar Paz Pz_Pazartesi Pts Pt_Salı Sal Sa_Çarşamba Çar Ça_Perşembe Per Pe_Cuma Cum Cu_Cumartesi Cts Ct'.split('_'), i;
58084 for (i = 0; i < expected.length; i++) {
58085 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
58086 }
58087 });
58088
58089 test('from', function (assert) {
58090 var start = moment([2007, 1, 28]);
58091 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'birkaç saniye', '44 seconds = a few seconds');
58092 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'bir dakika', '45 seconds = a minute');
58093 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'bir dakika', '89 seconds = a minute');
58094 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 dakika', '90 seconds = 2 minutes');
58095 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 dakika', '44 minutes = 44 minutes');
58096 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'bir saat', '45 minutes = an hour');
58097 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'bir saat', '89 minutes = an hour');
58098 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 saat', '90 minutes = 2 hours');
58099 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 saat', '5 hours = 5 hours');
58100 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 saat', '21 hours = 21 hours');
58101 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'bir gün', '22 hours = a day');
58102 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'bir gün', '35 hours = a day');
58103 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 gün', '36 hours = 2 days');
58104 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'bir gün', '1 day = a day');
58105 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 gün', '5 days = 5 days');
58106 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 gün', '25 days = 25 days');
58107 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'bir ay', '26 days = a month');
58108 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'bir ay', '30 days = a month');
58109 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'bir ay', '43 days = a month');
58110 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 ay', '46 days = 2 months');
58111 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 ay', '75 days = 2 months');
58112 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 ay', '76 days = 3 months');
58113 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'bir ay', '1 month = a month');
58114 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 ay', '5 months = 5 months');
58115 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'bir yıl', '345 days = a year');
58116 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 yıl', '548 days = 2 years');
58117 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'bir yıl', '1 year = a year');
58118 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 yıl', '5 years = 5 years');
58119 });
58120
58121 test('suffix', function (assert) {
58122 assert.equal(moment(30000).from(0), 'birkaç saniye sonra', 'prefix');
58123 assert.equal(moment(0).from(30000), 'birkaç saniye önce', 'suffix');
58124 });
58125
58126 test('now from now', function (assert) {
58127 assert.equal(moment().fromNow(), 'birkaç saniye önce', 'now from now should display as in the past');
58128 });
58129
58130 test('fromNow', function (assert) {
58131 assert.equal(moment().add({s: 30}).fromNow(), 'birkaç saniye sonra', 'in a few seconds');
58132 assert.equal(moment().add({d: 5}).fromNow(), '5 gün sonra', 'in 5 days');
58133 });
58134
58135 test('calendar day', function (assert) {
58136 var a = moment().hours(12).minutes(0).seconds(0);
58137
58138 assert.equal(moment(a).calendar(), 'bugün saat 12:00', 'today at the same time');
58139 assert.equal(moment(a).add({m: 25}).calendar(), 'bugün saat 12:25', 'Now plus 25 min');
58140 assert.equal(moment(a).add({h: 1}).calendar(), 'bugün saat 13:00', 'Now plus 1 hour');
58141 assert.equal(moment(a).add({d: 1}).calendar(), 'yarın saat 12:00', 'tomorrow at the same time');
58142 assert.equal(moment(a).subtract({h: 1}).calendar(), 'bugün saat 11:00', 'Now minus 1 hour');
58143 assert.equal(moment(a).subtract({d: 1}).calendar(), 'dün 12:00', 'yesterday at the same time');
58144 });
58145
58146 test('calendar next week', function (assert) {
58147 var i, m;
58148 for (i = 2; i < 7; i++) {
58149 m = moment().add({d: i});
58150 assert.equal(m.calendar(), m.format('[gelecek] dddd [saat] LT'), 'Today + ' + i + ' days current time');
58151 m.hours(0).minutes(0).seconds(0).milliseconds(0);
58152 assert.equal(m.calendar(), m.format('[gelecek] dddd [saat] LT'), 'Today + ' + i + ' days beginning of day');
58153 m.hours(23).minutes(59).seconds(59).milliseconds(999);
58154 assert.equal(m.calendar(), m.format('[gelecek] dddd [saat] LT'), 'Today + ' + i + ' days end of day');
516f5f67 58155 }
db71a655 58156 });
516f5f67 58157
db71a655
KM
58158 test('calendar last week', function (assert) {
58159 var i, m;
58160 for (i = 2; i < 7; i++) {
58161 m = moment().subtract({d: i});
58162 assert.equal(m.calendar(), m.format('[geçen] dddd [saat] LT'), 'Today - ' + i + ' days current time');
58163 m.hours(0).minutes(0).seconds(0).milliseconds(0);
58164 assert.equal(m.calendar(), m.format('[geçen] dddd [saat] LT'), 'Today - ' + i + ' days beginning of day');
58165 m.hours(23).minutes(59).seconds(59).milliseconds(999);
58166 assert.equal(m.calendar(), m.format('[geçen] dddd [saat] LT'), 'Today - ' + i + ' days end of day');
58167 }
58168 });
516f5f67 58169
db71a655
KM
58170 test('calendar all else', function (assert) {
58171 var weeksAgo = moment().subtract({w: 1}),
58172 weeksFromNow = moment().add({w: 1});
516f5f67 58173
db71a655
KM
58174 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
58175 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 58176
db71a655
KM
58177 weeksAgo = moment().subtract({w: 2});
58178 weeksFromNow = moment().add({w: 2});
516f5f67 58179
db71a655
KM
58180 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
58181 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
58182 });
516f5f67 58183
db71a655
KM
58184 test('weeks year starting sunday formatted', function (assert) {
58185 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1\'inci', 'Dec 26 2011 should be week 1');
58186 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1\'inci', 'Jan 1 2012 should be week 1');
58187 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2\'nci', 'Jan 2 2012 should be week 2');
58188 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2\'nci', 'Jan 8 2012 should be week 2');
58189 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3\'üncü', 'Jan 9 2012 should be week 3');
58190 });
516f5f67 58191
73f3c911 58192})));
516f5f67 58193
516f5f67 58194
c74a101d
IC
58195;(function (global, factory) {
58196 typeof exports === 'object' && typeof module !== 'undefined'
58197 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
58198 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
58199 factory(global.moment)
73f3c911 58200}(this, (function (moment) { 'use strict';
516f5f67 58201
db71a655
KM
58202 function each(array, callback) {
58203 var i;
58204 for (i = 0; i < array.length; i++) {
58205 callback(array[i], i, array);
58206 }
58207 }
58208
c58511b9
KM
58209 function setupDeprecationHandler(test, moment$$1, scope) {
58210 test._expectedDeprecations = null;
58211 test._observedDeprecations = null;
58212 test._oldSupress = moment$$1.suppressDeprecationWarnings;
58213 moment$$1.suppressDeprecationWarnings = true;
58214 test.expectedDeprecations = function () {
58215 test._expectedDeprecations = arguments;
58216 test._observedDeprecations = [];
58217 };
58218 moment$$1.deprecationHandler = function (name, msg) {
58219 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
58220 if (deprecationId === -1) {
58221 throw new Error('Unexpected deprecation thrown name=' +
58222 name + ' msg=' + msg);
58223 }
58224 test._observedDeprecations[deprecationId] = 1;
58225 };
58226 }
58227
58228 function teardownDeprecationHandler(test, moment$$1, scope) {
58229 moment$$1.suppressDeprecationWarnings = test._oldSupress;
58230
58231 if (test._expectedDeprecations != null) {
58232 var missedDeprecations = [];
58233 each(test._expectedDeprecations, function (deprecationPattern, id) {
58234 if (test._observedDeprecations[id] !== 1) {
58235 missedDeprecations.push(deprecationPattern);
58236 }
58237 });
58238 if (missedDeprecations.length !== 0) {
58239 throw new Error('Expected deprecation warnings did not happen: ' +
58240 missedDeprecations.join(' '));
58241 }
58242 }
58243 }
58244
58245 function matchedDeprecation(name, msg, deprecations) {
58246 if (deprecations == null) {
58247 return -1;
58248 }
58249 for (var i = 0; i < deprecations.length; ++i) {
58250 if (name != null && name === deprecations[i]) {
58251 return i;
58252 }
58253 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
58254 return i;
58255 }
58256 }
58257 return -1;
58258 }
58259
58260 /*global QUnit:false*/
58261
58262 var test = QUnit.test;
58263
db71a655
KM
58264 function objectKeys(obj) {
58265 if (Object.keys) {
58266 return Object.keys(obj);
58267 } else {
58268 // IE8
58269 var res = [], i;
58270 for (i in obj) {
58271 if (obj.hasOwnProperty(i)) {
58272 res.push(i);
58273 }
58274 }
58275 return res;
58276 }
58277 }
58278
58279 // Pick the first defined of two or three arguments.
58280
58281 function defineCommonLocaleTests(locale, options) {
58282 test('lenient day of month ordinal parsing', function (assert) {
58283 var i, ordinalStr, testMoment;
58284 for (i = 1; i <= 31; ++i) {
58285 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
58286 testMoment = moment(ordinalStr, 'YYYY MM Do');
58287 assert.equal(testMoment.year(), 2014,
58288 'lenient day of month ordinal parsing ' + i + ' year check');
58289 assert.equal(testMoment.month(), 0,
58290 'lenient day of month ordinal parsing ' + i + ' month check');
58291 assert.equal(testMoment.date(), i,
58292 'lenient day of month ordinal parsing ' + i + ' date check');
58293 }
58294 });
58295
58296 test('lenient day of month ordinal parsing of number', function (assert) {
58297 var i, testMoment;
58298 for (i = 1; i <= 31; ++i) {
58299 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
58300 assert.equal(testMoment.year(), 2014,
58301 'lenient day of month ordinal parsing of number ' + i + ' year check');
58302 assert.equal(testMoment.month(), 0,
58303 'lenient day of month ordinal parsing of number ' + i + ' month check');
58304 assert.equal(testMoment.date(), i,
58305 'lenient day of month ordinal parsing of number ' + i + ' date check');
58306 }
58307 });
58308
58309 test('strict day of month ordinal parsing', function (assert) {
58310 var i, ordinalStr, testMoment;
58311 for (i = 1; i <= 31; ++i) {
58312 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
58313 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
58314 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
58315 }
58316 });
58317
58318 test('meridiem invariant', function (assert) {
58319 var h, m, t1, t2;
58320 for (h = 0; h < 24; ++h) {
58321 for (m = 0; m < 60; m += 15) {
58322 t1 = moment.utc([2000, 0, 1, h, m]);
58323 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
58324 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
58325 'meridiem at ' + t1.format('HH:mm'));
58326 }
58327 }
58328 });
58329
58330 test('date format correctness', function (assert) {
58331 var data, tokens;
58332 data = moment.localeData()._longDateFormat;
58333 tokens = objectKeys(data);
58334 each(tokens, function (srchToken) {
58335 // Check each format string to make sure it does not contain any
58336 // tokens that need to be expanded.
58337 each(tokens, function (baseToken) {
58338 // strip escaped sequences
58339 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
58340 assert.equal(false, !!~format.indexOf(srchToken),
58341 'contains ' + srchToken + ' in ' + baseToken);
58342 });
58343 });
58344 });
58345
58346 test('month parsing correctness', function (assert) {
58347 var i, m;
58348
58349 if (locale === 'tr') {
58350 // I can't fix it :(
c58511b9 58351 assert.expect(0);
db71a655
KM
58352 return;
58353 }
58354 function tester(format) {
58355 var r;
58356 r = moment(m.format(format), format);
58357 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
58358 if (locale !== 'ka') {
58359 r = moment(m.format(format).toLocaleUpperCase(), format);
58360 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
58361 }
db71a655
KM
58362 r = moment(m.format(format).toLocaleLowerCase(), format);
58363 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
58364
58365 r = moment(m.format(format), format, true);
58366 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
58367 if (locale !== 'ka') {
58368 r = moment(m.format(format).toLocaleUpperCase(), format, true);
58369 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
58370 }
db71a655
KM
58371 r = moment(m.format(format).toLocaleLowerCase(), format, true);
58372 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
58373 }
58374
58375 for (i = 0; i < 12; ++i) {
58376 m = moment([2015, i, 15, 18]);
58377 tester('MMM');
58378 tester('MMM.');
58379 tester('MMMM');
58380 tester('MMMM.');
58381 }
58382 });
58383
58384 test('weekday parsing correctness', function (assert) {
58385 var i, m;
58386
96d0d679 58387 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
58388 // tr, az: There is a lower-case letter (ı), that converted to
58389 // upper then lower changes to i
58390 // ro: there is the letter ț which behaves weird under IE8
58391 // mt: letter Ħ
96d0d679 58392 // ga: month with spaces
c58511b9 58393 assert.expect(0);
db71a655
KM
58394 return;
58395 }
58396 function tester(format) {
58397 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
58398 r = moment(m.format(format), format);
58399 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
58400 if (locale !== 'ka') {
58401 r = moment(m.format(format).toLocaleUpperCase(), format);
58402 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
58403 }
db71a655
KM
58404 r = moment(m.format(format).toLocaleLowerCase(), format);
58405 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
58406 r = moment(m.format(format), format, true);
58407 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
58408 if (locale !== 'ka') {
58409 r = moment(m.format(format).toLocaleUpperCase(), format, true);
58410 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
58411 }
db71a655
KM
58412 r = moment(m.format(format).toLocaleLowerCase(), format, true);
58413 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
58414 }
58415
58416 for (i = 0; i < 7; ++i) {
58417 m = moment.utc([2015, 0, i + 1, 18]);
58418 tester('dd');
58419 tester('ddd');
58420 tester('dddd');
58421 }
58422 });
58423
58424 test('valid localeData', function (assert) {
58425 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
58426 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
58427 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
58428 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
58429 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
58430 });
96d0d679
KM
58431
58432 test('localeData weekdays can localeSort', function (assert) {
58433 var weekdays = moment().localeData().weekdays();
58434 var weekdaysShort = moment().localeData().weekdaysShort();
58435 var weekdaysMin = moment().localeData().weekdaysMin();
58436 var shift = moment().localeData()._week.dow;
58437 assert.deepEqual(
58438 moment().localeData().weekdays(true),
58439 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
58440 'weekdays should localeSort');
58441 assert.deepEqual(
58442 moment().localeData().weekdaysShort(true),
58443 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
58444 'weekdaysShort should localeSort');
58445 assert.deepEqual(
58446 moment().localeData().weekdaysMin(true),
58447 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
58448 'weekdaysMin should localeSort');
58449 });
b135bf1a
IC
58450 }
58451
db71a655 58452 /*global QUnit:false*/
b135bf1a 58453
db71a655
KM
58454 function localeModule (name, lifecycle) {
58455 QUnit.module('locale:' + name, {
c58511b9 58456 beforeEach : function () {
db71a655
KM
58457 moment.locale(name);
58458 moment.createFromInputFallback = function (config) {
58459 throw new Error('input not handled by moment: ' + config._i);
58460 };
58461 setupDeprecationHandler(test, moment, 'locale');
58462 if (lifecycle && lifecycle.setup) {
58463 lifecycle.setup();
58464 }
58465 },
c58511b9 58466 afterEach : function () {
db71a655
KM
58467 moment.locale('en');
58468 teardownDeprecationHandler(test, moment, 'locale');
58469 if (lifecycle && lifecycle.teardown) {
58470 lifecycle.teardown();
58471 }
58472 }
58473 });
58474 defineCommonLocaleTests(name, -1, -1);
58475 }
58476
58477 localeModule('tzl');
58478
58479 test('parse', function (assert) {
58480 var tests = 'Januar Jan_Fevraglh Fev_Març Mar_Avrïu Avr_Mai Mai_Gün Gün_Julia Jul_Guscht Gus_Setemvar Set_Listopäts Lis_Noemvar Noe_Zecemvar Zec'.split('_'), i;
58481 function equalTest(input, mmm, i) {
58482 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
58483 }
58484 for (i = 0; i < 12; i++) {
58485 tests[i] = tests[i].split(' ');
58486 equalTest(tests[i][0], 'MMM', i);
58487 equalTest(tests[i][1], 'MMM', i);
58488 equalTest(tests[i][0], 'MMMM', i);
58489 equalTest(tests[i][1], 'MMMM', i);
58490 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
58491 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
58492 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
58493 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
58494 }
58495 });
58496
58497 test('format', function (assert) {
58498 var a = [
58499 ['dddd, MMMM Do YYYY, h.mm.ss a', 'Súladi, Fevraglh 14. 2010, 3.25.50 d\'o'],
58500 ['ddd, hA', 'Súl, 3D\'O'],
58501 ['M Mo MM MMMM MMM', '2 2. 02 Fevraglh Fev'],
58502 ['YYYY YY', '2010 10'],
58503 ['D Do DD', '14 14. 14'],
58504 ['d do dddd ddd dd', '0 0. Súladi Súl Sú'],
58505 ['DDD DDDo DDDD', '45 45. 045'],
58506 ['w wo ww', '6 6. 06'],
58507 ['h hh', '3 03'],
58508 ['H HH', '15 15'],
58509 ['m mm', '25 25'],
58510 ['s ss', '50 50'],
58511 ['a A', 'd\'o D\'O'],
58512 ['[the] DDDo [day of the year]', 'the 45. day of the year'],
58513 ['LTS', '15.25.50'],
58514 ['L', '14.02.2010'],
58515 ['LL', '14. Fevraglh dallas 2010'],
58516 ['LLL', '14. Fevraglh dallas 2010 15.25'],
58517 ['LLLL', 'Súladi, li 14. Fevraglh dallas 2010 15.25'],
58518 ['l', '14.2.2010'],
58519 ['ll', '14. Fev dallas 2010'],
58520 ['lll', '14. Fev dallas 2010 15.25'],
58521 ['llll', 'Súl, li 14. Fev dallas 2010 15.25']
58522 ],
58523 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
58524 i;
58525 for (i = 0; i < a.length; i++) {
58526 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
58527 }
58528 });
58529
58530 test('format ordinal', function (assert) {
58531 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.');
58532 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.');
58533 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.');
58534 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.');
58535 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.');
58536 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.');
58537 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.');
58538 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.');
58539 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.');
58540 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.');
58541
58542 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.');
58543 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.');
58544 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.');
58545 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.');
58546 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.');
58547 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.');
58548 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.');
58549 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.');
58550 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.');
58551 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.');
58552
58553 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.');
58554 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.');
58555 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.');
58556 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.');
58557 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.');
58558 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.');
58559 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.');
58560 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.');
58561 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.');
58562 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.');
58563
58564 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.');
58565 });
58566
58567 test('format month', function (assert) {
58568 var expected = 'Januar Jan_Fevraglh Fev_Març Mar_Avrïu Avr_Mai Mai_Gün Gün_Julia Jul_Guscht Gus_Setemvar Set_Listopäts Lis_Noemvar Noe_Zecemvar Zec'.split('_'), i;
58569 for (i = 0; i < expected.length; i++) {
58570 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
58571 }
58572 });
58573
58574 test('format week', function (assert) {
58575 var expected = 'Súladi Súl Sú_Lúneçi Lún Lú_Maitzi Mai Ma_Márcuri Már Má_Xhúadi Xhú Xh_Viénerçi Vié Vi_Sáturi Sát Sá'.split('_'), i;
58576 for (i = 0; i < expected.length; i++) {
58577 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
58578 }
58579 });
58580
58581 test('from', function (assert) {
58582 var start = moment([2007, 1, 28]);
58583 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'viensas secunds', '44 seconds = a few seconds');
58584 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '\'n míut', '45 seconds = a minute');
58585 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '\'n míut', '89 seconds = a minute');
58586 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 míuts', '90 seconds = 2 minutes');
58587 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 míuts', '44 minutes = 44 minutes');
58588 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '\'n þora', '45 minutes = an hour');
58589 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '\'n þora', '89 minutes = an hour');
58590 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 þoras', '90 minutes = 2 hours');
58591 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 þoras', '5 hours = 5 hours');
58592 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 þoras', '21 hours = 21 hours');
58593 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '\'n ziua', '22 hours = a day');
58594 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '\'n ziua', '35 hours = a day');
58595 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 ziuas', '36 hours = 2 days');
58596 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '\'n ziua', '1 day = a day');
58597 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ziuas', '5 days = 5 days');
58598 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ziuas', '25 days = 25 days');
58599 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '\'n mes', '26 days = a month');
58600 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '\'n mes', '30 days = a month');
58601 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '\'n mes', '43 days = a month');
58602 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mesen', '46 days = 2 months');
58603 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mesen', '75 days = 2 months');
58604 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mesen', '76 days = 3 months');
58605 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '\'n mes', '1 month = a month');
58606 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mesen', '5 months = 5 months');
58607 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '\'n ar', '345 days = a year');
58608 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ars', '548 days = 2 years');
58609 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '\'n ar', '1 year = a year');
58610 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ars', '5 years = 5 years');
58611 });
58612
58613 test('suffix', function (assert) {
58614 assert.equal(moment(30000).from(0), 'osprei viensas secunds', 'prefix');
58615 assert.equal(moment(0).from(30000), 'ja\'iensas secunds', 'suffix');
58616 });
58617
58618 test('now from now', function (assert) {
58619 assert.equal(moment().fromNow(), 'ja\'iensas secunds', 'now from now should display as in the past');
58620 });
58621
58622 test('fromNow', function (assert) {
58623 assert.equal(moment().add({s: 30}).fromNow(), 'osprei viensas secunds', 'in a few seconds');
58624 assert.equal(moment().add({d: 5}).fromNow(), 'osprei 5 ziuas', 'in 5 days');
58625 });
58626
58627 test('calendar day', function (assert) {
58628 var a = moment().hours(12).minutes(0).seconds(0);
58629
58630 assert.equal(moment(a).calendar(), 'oxhi à 12.00', 'today at the same time');
58631 assert.equal(moment(a).add({m: 25}).calendar(), 'oxhi à 12.25', 'Now plus 25 min');
58632 assert.equal(moment(a).add({h: 1}).calendar(), 'oxhi à 13.00', 'Now plus 1 hour');
58633 assert.equal(moment(a).add({d: 1}).calendar(), 'demà à 12.00', 'tomorrow at the same time');
58634 assert.equal(moment(a).subtract({h: 1}).calendar(), 'oxhi à 11.00', 'Now minus 1 hour');
58635 assert.equal(moment(a).subtract({d: 1}).calendar(), 'ieiri à 12.00', 'yesterday at the same time');
58636 });
58637
58638 test('calendar next week', function (assert) {
58639 var i, m;
58640 for (i = 2; i < 7; i++) {
58641 m = moment().add({d: i});
58642 assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days current time');
58643 m.hours(0).minutes(0).seconds(0).milliseconds(0);
58644 assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days beginning of day');
58645 m.hours(23).minutes(59).seconds(59).milliseconds(999);
58646 assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days end of day');
73f3c911
IC
58647 }
58648 });
d6651c21 58649
db71a655 58650 test('calendar last week', function (assert) {
73f3c911 58651 var i, m;
d6651c21 58652
db71a655
KM
58653 for (i = 2; i < 7; i++) {
58654 m = moment().subtract({d: i});
58655 assert.equal(m.calendar(), m.format('[sür el] dddd [lasteu à] LT'), 'Today - ' + i + ' days current time');
58656 m.hours(0).minutes(0).seconds(0).milliseconds(0);
58657 assert.equal(m.calendar(), m.format('[sür el] dddd [lasteu à] LT'), 'Today - ' + i + ' days beginning of day');
58658 m.hours(23).minutes(59).seconds(59).milliseconds(999);
58659 assert.equal(m.calendar(), m.format('[sür el] dddd [lasteu à] LT'), 'Today - ' + i + ' days end of day');
d6651c21 58660 }
db71a655 58661 });
73f3c911 58662
db71a655
KM
58663 test('calendar all else', function (assert) {
58664 var weeksAgo = moment().subtract({w: 1}),
58665 weeksFromNow = moment().add({w: 1});
73f3c911 58666
db71a655
KM
58667 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
58668 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
b135bf1a 58669
db71a655
KM
58670 weeksAgo = moment().subtract({w: 2});
58671 weeksFromNow = moment().add({w: 2});
516f5f67 58672
db71a655
KM
58673 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
58674 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
58675 });
516f5f67 58676
db71a655
KM
58677 // Monday is the first day of the week.
58678 // The week that contains Jan 4th is the first week of the year.
c74a101d 58679
db71a655
KM
58680 test('weeks year starting sunday formatted', function (assert) {
58681 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52');
58682 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1');
58683 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1');
58684 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2');
58685 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2');
58686 });
73f3c911
IC
58687
58688})));
58689
58690
58691;(function (global, factory) {
58692 typeof exports === 'object' && typeof module !== 'undefined'
58693 && typeof require === 'function' ? factory(require('../../moment')) :
58694 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
58695 factory(global.moment)
58696}(this, (function (moment) { 'use strict';
58697
db71a655
KM
58698 function each(array, callback) {
58699 var i;
58700 for (i = 0; i < array.length; i++) {
58701 callback(array[i], i, array);
58702 }
516f5f67
IC
58703 }
58704
c58511b9
KM
58705 function setupDeprecationHandler(test, moment$$1, scope) {
58706 test._expectedDeprecations = null;
58707 test._observedDeprecations = null;
58708 test._oldSupress = moment$$1.suppressDeprecationWarnings;
58709 moment$$1.suppressDeprecationWarnings = true;
58710 test.expectedDeprecations = function () {
58711 test._expectedDeprecations = arguments;
58712 test._observedDeprecations = [];
58713 };
58714 moment$$1.deprecationHandler = function (name, msg) {
58715 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
58716 if (deprecationId === -1) {
58717 throw new Error('Unexpected deprecation thrown name=' +
58718 name + ' msg=' + msg);
58719 }
58720 test._observedDeprecations[deprecationId] = 1;
58721 };
58722 }
58723
58724 function teardownDeprecationHandler(test, moment$$1, scope) {
58725 moment$$1.suppressDeprecationWarnings = test._oldSupress;
58726
58727 if (test._expectedDeprecations != null) {
58728 var missedDeprecations = [];
58729 each(test._expectedDeprecations, function (deprecationPattern, id) {
58730 if (test._observedDeprecations[id] !== 1) {
58731 missedDeprecations.push(deprecationPattern);
58732 }
58733 });
58734 if (missedDeprecations.length !== 0) {
58735 throw new Error('Expected deprecation warnings did not happen: ' +
58736 missedDeprecations.join(' '));
58737 }
58738 }
58739 }
58740
58741 function matchedDeprecation(name, msg, deprecations) {
58742 if (deprecations == null) {
58743 return -1;
58744 }
58745 for (var i = 0; i < deprecations.length; ++i) {
58746 if (name != null && name === deprecations[i]) {
58747 return i;
58748 }
58749 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
58750 return i;
58751 }
58752 }
58753 return -1;
58754 }
58755
58756 /*global QUnit:false*/
58757
58758 var test = QUnit.test;
58759
db71a655
KM
58760 function objectKeys(obj) {
58761 if (Object.keys) {
58762 return Object.keys(obj);
58763 } else {
58764 // IE8
58765 var res = [], i;
58766 for (i in obj) {
58767 if (obj.hasOwnProperty(i)) {
58768 res.push(i);
58769 }
516f5f67 58770 }
db71a655 58771 return res;
73f3c911 58772 }
73f3c911 58773 }
516f5f67 58774
db71a655 58775 // Pick the first defined of two or three arguments.
516f5f67 58776
db71a655
KM
58777 function defineCommonLocaleTests(locale, options) {
58778 test('lenient day of month ordinal parsing', function (assert) {
58779 var i, ordinalStr, testMoment;
58780 for (i = 1; i <= 31; ++i) {
58781 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
58782 testMoment = moment(ordinalStr, 'YYYY MM Do');
58783 assert.equal(testMoment.year(), 2014,
58784 'lenient day of month ordinal parsing ' + i + ' year check');
58785 assert.equal(testMoment.month(), 0,
58786 'lenient day of month ordinal parsing ' + i + ' month check');
58787 assert.equal(testMoment.date(), i,
58788 'lenient day of month ordinal parsing ' + i + ' date check');
58789 }
58790 });
f2af24d5 58791
db71a655
KM
58792 test('lenient day of month ordinal parsing of number', function (assert) {
58793 var i, testMoment;
58794 for (i = 1; i <= 31; ++i) {
58795 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
58796 assert.equal(testMoment.year(), 2014,
58797 'lenient day of month ordinal parsing of number ' + i + ' year check');
58798 assert.equal(testMoment.month(), 0,
58799 'lenient day of month ordinal parsing of number ' + i + ' month check');
58800 assert.equal(testMoment.date(), i,
58801 'lenient day of month ordinal parsing of number ' + i + ' date check');
58802 }
58803 });
f2af24d5 58804
db71a655
KM
58805 test('strict day of month ordinal parsing', function (assert) {
58806 var i, ordinalStr, testMoment;
58807 for (i = 1; i <= 31; ++i) {
58808 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
58809 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
58810 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
58811 }
58812 });
f2af24d5 58813
db71a655
KM
58814 test('meridiem invariant', function (assert) {
58815 var h, m, t1, t2;
58816 for (h = 0; h < 24; ++h) {
58817 for (m = 0; m < 60; m += 15) {
58818 t1 = moment.utc([2000, 0, 1, h, m]);
58819 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
58820 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
58821 'meridiem at ' + t1.format('HH:mm'));
58822 }
58823 }
58824 });
58825
58826 test('date format correctness', function (assert) {
58827 var data, tokens;
58828 data = moment.localeData()._longDateFormat;
58829 tokens = objectKeys(data);
58830 each(tokens, function (srchToken) {
58831 // Check each format string to make sure it does not contain any
58832 // tokens that need to be expanded.
58833 each(tokens, function (baseToken) {
58834 // strip escaped sequences
58835 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
58836 assert.equal(false, !!~format.indexOf(srchToken),
58837 'contains ' + srchToken + ' in ' + baseToken);
58838 });
f2af24d5
IC
58839 });
58840 });
f2af24d5 58841
db71a655
KM
58842 test('month parsing correctness', function (assert) {
58843 var i, m;
58844
58845 if (locale === 'tr') {
58846 // I can't fix it :(
c58511b9 58847 assert.expect(0);
db71a655
KM
58848 return;
58849 }
58850 function tester(format) {
58851 var r;
58852 r = moment(m.format(format), format);
58853 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
58854 if (locale !== 'ka') {
58855 r = moment(m.format(format).toLocaleUpperCase(), format);
58856 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
58857 }
db71a655
KM
58858 r = moment(m.format(format).toLocaleLowerCase(), format);
58859 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
58860
58861 r = moment(m.format(format), format, true);
58862 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
58863 if (locale !== 'ka') {
58864 r = moment(m.format(format).toLocaleUpperCase(), format, true);
58865 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
58866 }
db71a655
KM
58867 r = moment(m.format(format).toLocaleLowerCase(), format, true);
58868 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
58869 }
58870
58871 for (i = 0; i < 12; ++i) {
58872 m = moment([2015, i, 15, 18]);
58873 tester('MMM');
58874 tester('MMM.');
58875 tester('MMMM');
58876 tester('MMMM.');
58877 }
58878 });
f2af24d5 58879
db71a655
KM
58880 test('weekday parsing correctness', function (assert) {
58881 var i, m;
58882
96d0d679 58883 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
58884 // tr, az: There is a lower-case letter (ı), that converted to
58885 // upper then lower changes to i
58886 // ro: there is the letter ț which behaves weird under IE8
58887 // mt: letter Ħ
96d0d679 58888 // ga: month with spaces
c58511b9 58889 assert.expect(0);
db71a655
KM
58890 return;
58891 }
58892 function tester(format) {
58893 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
58894 r = moment(m.format(format), format);
58895 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
58896 if (locale !== 'ka') {
58897 r = moment(m.format(format).toLocaleUpperCase(), format);
58898 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
58899 }
db71a655
KM
58900 r = moment(m.format(format).toLocaleLowerCase(), format);
58901 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
58902 r = moment(m.format(format), format, true);
58903 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
58904 if (locale !== 'ka') {
58905 r = moment(m.format(format).toLocaleUpperCase(), format, true);
58906 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
58907 }
db71a655
KM
58908 r = moment(m.format(format).toLocaleLowerCase(), format, true);
58909 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
58910 }
58911
58912 for (i = 0; i < 7; ++i) {
58913 m = moment.utc([2015, 0, i + 1, 18]);
58914 tester('dd');
58915 tester('ddd');
58916 tester('dddd');
58917 }
58918 });
f2af24d5 58919
db71a655
KM
58920 test('valid localeData', function (assert) {
58921 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
58922 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
58923 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
58924 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
58925 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
58926 });
96d0d679
KM
58927
58928 test('localeData weekdays can localeSort', function (assert) {
58929 var weekdays = moment().localeData().weekdays();
58930 var weekdaysShort = moment().localeData().weekdaysShort();
58931 var weekdaysMin = moment().localeData().weekdaysMin();
58932 var shift = moment().localeData()._week.dow;
58933 assert.deepEqual(
58934 moment().localeData().weekdays(true),
58935 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
58936 'weekdays should localeSort');
58937 assert.deepEqual(
58938 moment().localeData().weekdaysShort(true),
58939 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
58940 'weekdaysShort should localeSort');
58941 assert.deepEqual(
58942 moment().localeData().weekdaysMin(true),
58943 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
58944 'weekdaysMin should localeSort');
58945 });
db71a655 58946 }
f2af24d5 58947
db71a655 58948 /*global QUnit:false*/
f2af24d5 58949
db71a655
KM
58950 function localeModule (name, lifecycle) {
58951 QUnit.module('locale:' + name, {
c58511b9 58952 beforeEach : function () {
db71a655
KM
58953 moment.locale(name);
58954 moment.createFromInputFallback = function (config) {
58955 throw new Error('input not handled by moment: ' + config._i);
58956 };
58957 setupDeprecationHandler(test, moment, 'locale');
58958 if (lifecycle && lifecycle.setup) {
58959 lifecycle.setup();
58960 }
58961 },
c58511b9 58962 afterEach : function () {
db71a655
KM
58963 moment.locale('en');
58964 teardownDeprecationHandler(test, moment, 'locale');
58965 if (lifecycle && lifecycle.teardown) {
58966 lifecycle.teardown();
58967 }
f2af24d5
IC
58968 }
58969 });
db71a655
KM
58970 defineCommonLocaleTests(name, -1, -1);
58971 }
58972
58973 localeModule('tzm-latn');
58974
58975 test('parse', function (assert) {
58976 var tests = 'innayr innayr_brˤayrˤ brˤayrˤ_marˤsˤ marˤsˤ_ibrir ibrir_mayyw mayyw_ywnyw ywnyw_ywlywz ywlywz_ɣwšt ɣwšt_šwtanbir šwtanbir_ktˤwbrˤ ktˤwbrˤ_nwwanbir nwwanbir_dwjnbir dwjnbir'.split('_'), i;
58977 function equalTest(input, mmm, i) {
58978 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
58979 }
58980 for (i = 0; i < 12; i++) {
58981 tests[i] = tests[i].split(' ');
58982 equalTest(tests[i][0], 'MMM', i);
58983 equalTest(tests[i][1], 'MMM', i);
58984 equalTest(tests[i][0], 'MMMM', i);
58985 equalTest(tests[i][1], 'MMMM', i);
58986 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
58987 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
58988 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
58989 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
58990 }
58991 });
58992
58993 test('format', function (assert) {
58994 var a = [
58995 ['dddd, MMMM Do YYYY, h:mm:ss a', 'asamas, brˤayrˤ 14 2010, 3:25:50 pm'],
58996 ['ddd, hA', 'asamas, 3PM'],
58997 ['M Mo MM MMMM MMM', '2 2 02 brˤayrˤ brˤayrˤ'],
58998 ['YYYY YY', '2010 10'],
58999 ['D Do DD', '14 14 14'],
59000 ['d do dddd ddd dd', '0 0 asamas asamas asamas'],
59001 ['DDD DDDo DDDD', '45 45 045'],
59002 ['w wo ww', '8 8 08'],
59003 ['h hh', '3 03'],
59004 ['H HH', '15 15'],
59005 ['m mm', '25 25'],
59006 ['s ss', '50 50'],
59007 ['a A', 'pm PM'],
59008 ['[the] DDDo [day of the year]', 'the 45 day of the year'],
59009 ['LTS', '15:25:50'],
59010 ['L', '14/02/2010'],
59011 ['LL', '14 brˤayrˤ 2010'],
59012 ['LLL', '14 brˤayrˤ 2010 15:25'],
59013 ['LLLL', 'asamas 14 brˤayrˤ 2010 15:25'],
59014 ['l', '14/2/2010'],
59015 ['ll', '14 brˤayrˤ 2010'],
59016 ['lll', '14 brˤayrˤ 2010 15:25'],
59017 ['llll', 'asamas 14 brˤayrˤ 2010 15:25']
59018 ],
59019 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
59020 i;
59021 for (i = 0; i < a.length; i++) {
59022 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
59023 }
59024 });
59025
59026 test('format ordinal', function (assert) {
59027 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
59028 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
59029 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
59030 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
59031 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
59032 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
59033 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
59034 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
59035 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
59036 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
59037
59038 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
59039 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
59040 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
59041 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
59042 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
59043 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
59044 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
59045 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
59046 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
59047 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
59048
59049 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
59050 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
59051 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
59052 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
59053 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
59054 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
59055 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
59056 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
59057 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
59058 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
59059
59060 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
59061 });
59062
59063 test('format month', function (assert) {
59064 var expected = 'innayr innayr_brˤayrˤ brˤayrˤ_marˤsˤ marˤsˤ_ibrir ibrir_mayyw mayyw_ywnyw ywnyw_ywlywz ywlywz_ɣwšt ɣwšt_šwtanbir šwtanbir_ktˤwbrˤ ktˤwbrˤ_nwwanbir nwwanbir_dwjnbir dwjnbir'.split('_'), i;
59065 for (i = 0; i < expected.length; i++) {
59066 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
59067 }
59068 });
59069
59070 test('format week', function (assert) {
59071 var expected = 'asamas asamas asamas_aynas aynas aynas_asinas asinas asinas_akras akras akras_akwas akwas akwas_asimwas asimwas asimwas_asiḍyas asiḍyas asiḍyas'.split('_'), i;
59072 for (i = 0; i < expected.length; i++) {
59073 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
59074 }
59075 });
59076
59077 test('from', function (assert) {
59078 var start = moment([2007, 1, 28]);
59079 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'imik', '44 seconds = a few seconds');
59080 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minuḍ', '45 seconds = a minute');
59081 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minuḍ', '89 seconds = a minute');
59082 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuḍ', '90 seconds = 2 minutes');
59083 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuḍ', '44 minutes = 44 minutes');
59084 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'saɛa', '45 minutes = an hour');
59085 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'saɛa', '89 minutes = an hour');
59086 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 tassaɛin', '90 minutes = 2 hours');
59087 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 tassaɛin', '5 hours = 5 hours');
59088 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 tassaɛin', '21 hours = 21 hours');
59089 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ass', '22 hours = a day');
59090 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ass', '35 hours = a day');
59091 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 ossan', '36 hours = 2 days');
59092 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ass', '1 day = a day');
59093 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ossan', '5 days = 5 days');
59094 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ossan', '25 days = 25 days');
59095 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ayowr', '26 days = a month');
59096 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ayowr', '30 days = a month');
59097 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ayowr', '43 days = a month');
59098 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 iyyirn', '46 days = 2 months');
59099 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 iyyirn', '75 days = 2 months');
59100 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 iyyirn', '76 days = 3 months');
59101 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ayowr', '1 month = a month');
59102 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 iyyirn', '5 months = 5 months');
59103 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'asgas', '345 days = a year');
59104 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 isgasn', '548 days = 2 years');
59105 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'asgas', '1 year = a year');
59106 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 isgasn', '5 years = 5 years');
59107 });
59108
59109 test('suffix', function (assert) {
59110 assert.equal(moment(30000).from(0), 'dadkh s yan imik', 'prefix');
59111 assert.equal(moment(0).from(30000), 'yan imik', 'suffix');
59112 });
59113
59114 test('now from now', function (assert) {
59115 assert.equal(moment().fromNow(), 'yan imik', 'now from now should display as in the past');
59116 });
59117
59118 test('fromNow', function (assert) {
59119 assert.equal(moment().add({s: 30}).fromNow(), 'dadkh s yan imik', 'in a few seconds');
59120 assert.equal(moment().add({d: 5}).fromNow(), 'dadkh s yan 5 ossan', 'in 5 days');
59121 });
59122
59123 test('calendar day', function (assert) {
59124 var a = moment().hours(12).minutes(0).seconds(0);
59125
59126 assert.equal(moment(a).calendar(), 'asdkh g 12:00', 'today at the same time');
59127 assert.equal(moment(a).add({m: 25}).calendar(), 'asdkh g 12:25', 'Now plus 25 min');
59128 assert.equal(moment(a).add({h: 1}).calendar(), 'asdkh g 13:00', 'Now plus 1 hour');
59129 assert.equal(moment(a).add({d: 1}).calendar(), 'aska g 12:00', 'tomorrow at the same time');
59130 assert.equal(moment(a).subtract({h: 1}).calendar(), 'asdkh g 11:00', 'Now minus 1 hour');
59131 assert.equal(moment(a).subtract({d: 1}).calendar(), 'assant g 12:00', 'yesterday at the same time');
59132 });
59133
59134 test('calendar next week', function (assert) {
59135 var i, m;
59136 for (i = 2; i < 7; i++) {
59137 m = moment().add({d: i});
59138 assert.equal(m.calendar(), m.format('dddd [g] LT'), 'Today + ' + i + ' days current time');
59139 m.hours(0).minutes(0).seconds(0).milliseconds(0);
59140 assert.equal(m.calendar(), m.format('dddd [g] LT'), 'Today + ' + i + ' days beginning of day');
59141 m.hours(23).minutes(59).seconds(59).milliseconds(999);
59142 assert.equal(m.calendar(), m.format('dddd [g] LT'), 'Today + ' + i + ' days end of day');
f2af24d5 59143 }
db71a655 59144 });
f2af24d5 59145
db71a655
KM
59146 test('calendar last week', function (assert) {
59147 var i, m;
59148 for (i = 2; i < 7; i++) {
59149 m = moment().subtract({d: i});
59150 assert.equal(m.calendar(), m.format('dddd [g] LT'), 'Today - ' + i + ' days current time');
59151 m.hours(0).minutes(0).seconds(0).milliseconds(0);
59152 assert.equal(m.calendar(), m.format('dddd [g] LT'), 'Today - ' + i + ' days beginning of day');
59153 m.hours(23).minutes(59).seconds(59).milliseconds(999);
59154 assert.equal(m.calendar(), m.format('dddd [g] LT'), 'Today - ' + i + ' days end of day');
f2af24d5 59155 }
db71a655 59156 });
f2af24d5 59157
db71a655
KM
59158 test('calendar all else', function (assert) {
59159 var weeksAgo = moment().subtract({w: 1}),
59160 weeksFromNow = moment().add({w: 1});
f2af24d5 59161
db71a655
KM
59162 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
59163 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
f2af24d5 59164
db71a655
KM
59165 weeksAgo = moment().subtract({w: 2});
59166 weeksFromNow = moment().add({w: 2});
f2af24d5 59167
db71a655
KM
59168 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
59169 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
59170 });
f2af24d5 59171
db71a655
KM
59172 test('weeks year starting sunday formatted', function (assert) {
59173 assert.equal(moment([2011, 11, 31]).format('w ww wo'), '1 01 1', 'Dec 31 2011 should be week 1');
59174 assert.equal(moment([2012, 0, 6]).format('w ww wo'), '1 01 1', 'Jan 6 2012 should be week 1');
59175 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '2 02 2', 'Jan 7 2012 should be week 2');
59176 assert.equal(moment([2012, 0, 13]).format('w ww wo'), '2 02 2', 'Jan 13 2012 should be week 2');
59177 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '3 03 3', 'Jan 14 2012 should be week 3');
59178 });
f2af24d5
IC
59179
59180})));
59181
59182
59183;(function (global, factory) {
59184 typeof exports === 'object' && typeof module !== 'undefined'
59185 && typeof require === 'function' ? factory(require('../../moment')) :
59186 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
59187 factory(global.moment)
59188}(this, (function (moment) { 'use strict';
59189
db71a655
KM
59190 function each(array, callback) {
59191 var i;
59192 for (i = 0; i < array.length; i++) {
59193 callback(array[i], i, array);
59194 }
f2af24d5 59195 }
f2af24d5 59196
c58511b9
KM
59197 function setupDeprecationHandler(test, moment$$1, scope) {
59198 test._expectedDeprecations = null;
59199 test._observedDeprecations = null;
59200 test._oldSupress = moment$$1.suppressDeprecationWarnings;
59201 moment$$1.suppressDeprecationWarnings = true;
59202 test.expectedDeprecations = function () {
59203 test._expectedDeprecations = arguments;
59204 test._observedDeprecations = [];
59205 };
59206 moment$$1.deprecationHandler = function (name, msg) {
59207 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
59208 if (deprecationId === -1) {
59209 throw new Error('Unexpected deprecation thrown name=' +
59210 name + ' msg=' + msg);
59211 }
59212 test._observedDeprecations[deprecationId] = 1;
59213 };
59214 }
59215
59216 function teardownDeprecationHandler(test, moment$$1, scope) {
59217 moment$$1.suppressDeprecationWarnings = test._oldSupress;
59218
59219 if (test._expectedDeprecations != null) {
59220 var missedDeprecations = [];
59221 each(test._expectedDeprecations, function (deprecationPattern, id) {
59222 if (test._observedDeprecations[id] !== 1) {
59223 missedDeprecations.push(deprecationPattern);
59224 }
59225 });
59226 if (missedDeprecations.length !== 0) {
59227 throw new Error('Expected deprecation warnings did not happen: ' +
59228 missedDeprecations.join(' '));
59229 }
59230 }
59231 }
59232
59233 function matchedDeprecation(name, msg, deprecations) {
59234 if (deprecations == null) {
59235 return -1;
59236 }
59237 for (var i = 0; i < deprecations.length; ++i) {
59238 if (name != null && name === deprecations[i]) {
59239 return i;
59240 }
59241 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
59242 return i;
59243 }
59244 }
59245 return -1;
59246 }
59247
59248 /*global QUnit:false*/
59249
59250 var test = QUnit.test;
59251
db71a655
KM
59252 function objectKeys(obj) {
59253 if (Object.keys) {
59254 return Object.keys(obj);
59255 } else {
59256 // IE8
59257 var res = [], i;
59258 for (i in obj) {
59259 if (obj.hasOwnProperty(i)) {
59260 res.push(i);
59261 }
f2af24d5 59262 }
db71a655 59263 return res;
f2af24d5 59264 }
f2af24d5 59265 }
f2af24d5 59266
db71a655 59267 // Pick the first defined of two or three arguments.
f2af24d5 59268
db71a655
KM
59269 function defineCommonLocaleTests(locale, options) {
59270 test('lenient day of month ordinal parsing', function (assert) {
59271 var i, ordinalStr, testMoment;
59272 for (i = 1; i <= 31; ++i) {
59273 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
59274 testMoment = moment(ordinalStr, 'YYYY MM Do');
59275 assert.equal(testMoment.year(), 2014,
59276 'lenient day of month ordinal parsing ' + i + ' year check');
59277 assert.equal(testMoment.month(), 0,
59278 'lenient day of month ordinal parsing ' + i + ' month check');
59279 assert.equal(testMoment.date(), i,
59280 'lenient day of month ordinal parsing ' + i + ' date check');
59281 }
f2af24d5 59282 });
f2af24d5 59283
db71a655
KM
59284 test('lenient day of month ordinal parsing of number', function (assert) {
59285 var i, testMoment;
59286 for (i = 1; i <= 31; ++i) {
59287 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
59288 assert.equal(testMoment.year(), 2014,
59289 'lenient day of month ordinal parsing of number ' + i + ' year check');
59290 assert.equal(testMoment.month(), 0,
59291 'lenient day of month ordinal parsing of number ' + i + ' month check');
59292 assert.equal(testMoment.date(), i,
59293 'lenient day of month ordinal parsing of number ' + i + ' date check');
59294 }
59295 });
f2af24d5 59296
db71a655
KM
59297 test('strict day of month ordinal parsing', function (assert) {
59298 var i, ordinalStr, testMoment;
59299 for (i = 1; i <= 31; ++i) {
59300 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
59301 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
59302 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
59303 }
59304 });
f2af24d5 59305
db71a655
KM
59306 test('meridiem invariant', function (assert) {
59307 var h, m, t1, t2;
59308 for (h = 0; h < 24; ++h) {
59309 for (m = 0; m < 60; m += 15) {
59310 t1 = moment.utc([2000, 0, 1, h, m]);
59311 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
59312 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
59313 'meridiem at ' + t1.format('HH:mm'));
59314 }
59315 }
59316 });
f2af24d5 59317
db71a655
KM
59318 test('date format correctness', function (assert) {
59319 var data, tokens;
59320 data = moment.localeData()._longDateFormat;
59321 tokens = objectKeys(data);
59322 each(tokens, function (srchToken) {
59323 // Check each format string to make sure it does not contain any
59324 // tokens that need to be expanded.
59325 each(tokens, function (baseToken) {
59326 // strip escaped sequences
59327 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
59328 assert.equal(false, !!~format.indexOf(srchToken),
59329 'contains ' + srchToken + ' in ' + baseToken);
59330 });
59331 });
59332 });
f2af24d5 59333
db71a655
KM
59334 test('month parsing correctness', function (assert) {
59335 var i, m;
59336
59337 if (locale === 'tr') {
59338 // I can't fix it :(
c58511b9 59339 assert.expect(0);
db71a655
KM
59340 return;
59341 }
59342 function tester(format) {
59343 var r;
59344 r = moment(m.format(format), format);
59345 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
59346 if (locale !== 'ka') {
59347 r = moment(m.format(format).toLocaleUpperCase(), format);
59348 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
59349 }
db71a655
KM
59350 r = moment(m.format(format).toLocaleLowerCase(), format);
59351 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
59352
59353 r = moment(m.format(format), format, true);
59354 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
59355 if (locale !== 'ka') {
59356 r = moment(m.format(format).toLocaleUpperCase(), format, true);
59357 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
59358 }
db71a655
KM
59359 r = moment(m.format(format).toLocaleLowerCase(), format, true);
59360 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
59361 }
59362
59363 for (i = 0; i < 12; ++i) {
59364 m = moment([2015, i, 15, 18]);
59365 tester('MMM');
59366 tester('MMM.');
59367 tester('MMMM');
59368 tester('MMMM.');
59369 }
59370 });
f2af24d5 59371
db71a655
KM
59372 test('weekday parsing correctness', function (assert) {
59373 var i, m;
59374
96d0d679 59375 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
59376 // tr, az: There is a lower-case letter (ı), that converted to
59377 // upper then lower changes to i
59378 // ro: there is the letter ț which behaves weird under IE8
59379 // mt: letter Ħ
96d0d679 59380 // ga: month with spaces
c58511b9 59381 assert.expect(0);
db71a655
KM
59382 return;
59383 }
59384 function tester(format) {
59385 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
59386 r = moment(m.format(format), format);
59387 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
59388 if (locale !== 'ka') {
59389 r = moment(m.format(format).toLocaleUpperCase(), format);
59390 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
59391 }
db71a655
KM
59392 r = moment(m.format(format).toLocaleLowerCase(), format);
59393 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
59394 r = moment(m.format(format), format, true);
59395 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
59396 if (locale !== 'ka') {
59397 r = moment(m.format(format).toLocaleUpperCase(), format, true);
59398 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
59399 }
db71a655
KM
59400 r = moment(m.format(format).toLocaleLowerCase(), format, true);
59401 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
59402 }
59403
59404 for (i = 0; i < 7; ++i) {
59405 m = moment.utc([2015, 0, i + 1, 18]);
59406 tester('dd');
59407 tester('ddd');
59408 tester('dddd');
59409 }
59410 });
f2af24d5 59411
db71a655
KM
59412 test('valid localeData', function (assert) {
59413 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
59414 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
59415 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
59416 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
59417 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
59418 });
96d0d679
KM
59419
59420 test('localeData weekdays can localeSort', function (assert) {
59421 var weekdays = moment().localeData().weekdays();
59422 var weekdaysShort = moment().localeData().weekdaysShort();
59423 var weekdaysMin = moment().localeData().weekdaysMin();
59424 var shift = moment().localeData()._week.dow;
59425 assert.deepEqual(
59426 moment().localeData().weekdays(true),
59427 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
59428 'weekdays should localeSort');
59429 assert.deepEqual(
59430 moment().localeData().weekdaysShort(true),
59431 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
59432 'weekdaysShort should localeSort');
59433 assert.deepEqual(
59434 moment().localeData().weekdaysMin(true),
59435 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
59436 'weekdaysMin should localeSort');
59437 });
db71a655 59438 }
f2af24d5 59439
db71a655 59440 /*global QUnit:false*/
f2af24d5 59441
db71a655
KM
59442 function localeModule (name, lifecycle) {
59443 QUnit.module('locale:' + name, {
c58511b9 59444 beforeEach : function () {
db71a655
KM
59445 moment.locale(name);
59446 moment.createFromInputFallback = function (config) {
59447 throw new Error('input not handled by moment: ' + config._i);
59448 };
59449 setupDeprecationHandler(test, moment, 'locale');
59450 if (lifecycle && lifecycle.setup) {
59451 lifecycle.setup();
59452 }
59453 },
c58511b9 59454 afterEach : function () {
db71a655
KM
59455 moment.locale('en');
59456 teardownDeprecationHandler(test, moment, 'locale');
59457 if (lifecycle && lifecycle.teardown) {
59458 lifecycle.teardown();
59459 }
f2af24d5 59460 }
db71a655
KM
59461 });
59462 defineCommonLocaleTests(name, -1, -1);
59463 }
59464
59465 localeModule('tzm');
59466
59467 test('parse', function (assert) {
59468 var tests = 'ⵉⵏⵏⴰⵢⵔ ⵉⵏⵏⴰⵢⵔ_ⴱⵕⴰⵢⵕ ⴱⵕⴰⵢⵕ_ⵎⴰⵕⵚ ⵎⴰⵕⵚ_ⵉⴱⵔⵉⵔ ⵉⴱⵔⵉⵔ_ⵎⴰⵢⵢⵓ ⵎⴰⵢⵢⵓ_ⵢⵓⵏⵢⵓ ⵢⵓⵏⵢⵓ_ⵢⵓⵍⵢⵓⵣ ⵢⵓⵍⵢⵓⵣ_ⵖⵓⵛⵜ ⵖⵓⵛⵜ_ⵛⵓⵜⴰⵏⴱⵉⵔ ⵛⵓⵜⴰⵏⴱⵉⵔ_ⴽⵟⵓⴱⵕ ⴽⵟⵓⴱⵕ_ⵏⵓⵡⴰⵏⴱⵉⵔ ⵏⵓⵡⴰⵏⴱⵉⵔ_ⴷⵓⵊⵏⴱⵉⵔ ⴷⵓⵊⵏⴱⵉⵔ'.split('_'), i;
59469 function equalTest(input, mmm, i) {
59470 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
59471 }
59472 for (i = 0; i < 12; i++) {
59473 tests[i] = tests[i].split(' ');
59474 equalTest(tests[i][0], 'MMM', i);
59475 equalTest(tests[i][1], 'MMM', i);
59476 equalTest(tests[i][0], 'MMMM', i);
59477 equalTest(tests[i][1], 'MMMM', i);
59478 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
59479 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
59480 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
59481 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
59482 }
59483 });
59484
59485 test('format', function (assert) {
59486 var a = [
59487 ['dddd, MMMM Do YYYY, h:mm:ss a', 'ⴰⵙⴰⵎⴰⵙ, ⴱⵕⴰⵢⵕ 14 2010, 3:25:50 pm'],
59488 ['ddd, hA', 'ⴰⵙⴰⵎⴰⵙ, 3PM'],
59489 ['M Mo MM MMMM MMM', '2 2 02 ⴱⵕⴰⵢⵕ ⴱⵕⴰⵢⵕ'],
59490 ['YYYY YY', '2010 10'],
59491 ['D Do DD', '14 14 14'],
59492 ['d do dddd ddd dd', '0 0 ⴰⵙⴰⵎⴰⵙ ⴰⵙⴰⵎⴰⵙ ⴰⵙⴰⵎⴰⵙ'],
59493 ['DDD DDDo DDDD', '45 45 045'],
59494 ['w wo ww', '8 8 08'],
59495 ['h hh', '3 03'],
59496 ['H HH', '15 15'],
59497 ['m mm', '25 25'],
59498 ['s ss', '50 50'],
59499 ['a A', 'pm PM'],
59500 ['[the] DDDo [day of the year]', 'the 45 day of the year'],
59501 ['LTS', '15:25:50'],
59502 ['L', '14/02/2010'],
59503 ['LL', '14 ⴱⵕⴰⵢⵕ 2010'],
59504 ['LLL', '14 ⴱⵕⴰⵢⵕ 2010 15:25'],
59505 ['LLLL', 'ⴰⵙⴰⵎⴰⵙ 14 ⴱⵕⴰⵢⵕ 2010 15:25'],
59506 ['l', '14/2/2010'],
59507 ['ll', '14 ⴱⵕⴰⵢⵕ 2010'],
59508 ['lll', '14 ⴱⵕⴰⵢⵕ 2010 15:25'],
59509 ['llll', 'ⴰⵙⴰⵎⴰⵙ 14 ⴱⵕⴰⵢⵕ 2010 15:25']
59510 ],
59511 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
59512 i;
59513 for (i = 0; i < a.length; i++) {
59514 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
59515 }
59516 });
59517
59518 test('format ordinal', function (assert) {
59519 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
59520 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
59521 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
59522 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
59523 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
59524 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
59525 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
59526 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
59527 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
59528 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
59529
59530 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
59531 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
59532 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
59533 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
59534 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
59535 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
59536 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
59537 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
59538 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
59539 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
59540
59541 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
59542 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
59543 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
59544 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
59545 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
59546 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
59547 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
59548 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
59549 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
59550 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
59551
59552 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
59553 });
59554
59555 test('format month', function (assert) {
59556 var expected = 'ⵉⵏⵏⴰⵢⵔ ⵉⵏⵏⴰⵢⵔ_ⴱⵕⴰⵢⵕ ⴱⵕⴰⵢⵕ_ⵎⴰⵕⵚ ⵎⴰⵕⵚ_ⵉⴱⵔⵉⵔ ⵉⴱⵔⵉⵔ_ⵎⴰⵢⵢⵓ ⵎⴰⵢⵢⵓ_ⵢⵓⵏⵢⵓ ⵢⵓⵏⵢⵓ_ⵢⵓⵍⵢⵓⵣ ⵢⵓⵍⵢⵓⵣ_ⵖⵓⵛⵜ ⵖⵓⵛⵜ_ⵛⵓⵜⴰⵏⴱⵉⵔ ⵛⵓⵜⴰⵏⴱⵉⵔ_ⴽⵟⵓⴱⵕ ⴽⵟⵓⴱⵕ_ⵏⵓⵡⴰⵏⴱⵉⵔ ⵏⵓⵡⴰⵏⴱⵉⵔ_ⴷⵓⵊⵏⴱⵉⵔ ⴷⵓⵊⵏⴱⵉⵔ'.split('_'), i;
59557 for (i = 0; i < expected.length; i++) {
59558 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
59559 }
59560 });
59561
59562 test('format week', function (assert) {
59563 var expected = 'ⴰⵙⴰⵎⴰⵙ ⴰⵙⴰⵎⴰⵙ ⴰⵙⴰⵎⴰⵙ_ⴰⵢⵏⴰⵙ ⴰⵢⵏⴰⵙ ⴰⵢⵏⴰⵙ_ⴰⵙⵉⵏⴰⵙ ⴰⵙⵉⵏⴰⵙ ⴰⵙⵉⵏⴰⵙ_ⴰⴽⵔⴰⵙ ⴰⴽⵔⴰⵙ ⴰⴽⵔⴰⵙ_ⴰⴽⵡⴰⵙ ⴰⴽⵡⴰⵙ ⴰⴽⵡⴰⵙ_ⴰⵙⵉⵎⵡⴰⵙ ⴰⵙⵉⵎⵡⴰⵙ ⴰⵙⵉⵎⵡⴰⵙ_ⴰⵙⵉⴹⵢⴰⵙ ⴰⵙⵉⴹⵢⴰⵙ ⴰⵙⵉⴹⵢⴰⵙ'.split('_'), i;
59564 for (i = 0; i < expected.length; i++) {
59565 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
59566 }
59567 });
59568
59569 test('from', function (assert) {
59570 var start = moment([2007, 1, 28]);
59571 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ⵉⵎⵉⴽ', '44 seconds = a few seconds');
59572 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ⵎⵉⵏⵓⴺ', '45 seconds = a minute');
59573 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ⵎⵉⵏⵓⴺ', '89 seconds = a minute');
59574 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 ⵎⵉⵏⵓⴺ', '90 seconds = 2 minutes');
59575 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 ⵎⵉⵏⵓⴺ', '44 minutes = 44 minutes');
59576 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ⵙⴰⵄⴰ', '45 minutes = an hour');
59577 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ⵙⴰⵄⴰ', '89 minutes = an hour');
59578 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ⵜⴰⵙⵙⴰⵄⵉⵏ', '90 minutes = 2 hours');
59579 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ⵜⴰⵙⵙⴰⵄⵉⵏ', '5 hours = 5 hours');
59580 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ⵜⴰⵙⵙⴰⵄⵉⵏ', '21 hours = 21 hours');
59581 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ⴰⵙⵙ', '22 hours = a day');
59582 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ⴰⵙⵙ', '35 hours = a day');
59583 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 oⵙⵙⴰⵏ', '36 hours = 2 days');
59584 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ⴰⵙⵙ', '1 day = a day');
59585 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 oⵙⵙⴰⵏ', '5 days = 5 days');
59586 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 oⵙⵙⴰⵏ', '25 days = 25 days');
59587 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ⴰⵢoⵓⵔ', '26 days = a month');
59588 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ⴰⵢoⵓⵔ', '30 days = a month');
59589 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ⴰⵢoⵓⵔ', '43 days = a month');
59590 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 ⵉⵢⵢⵉⵔⵏ', '46 days = 2 months');
59591 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 ⵉⵢⵢⵉⵔⵏ', '75 days = 2 months');
59592 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 ⵉⵢⵢⵉⵔⵏ', '76 days = 3 months');
59593 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ⴰⵢoⵓⵔ', '1 month = a month');
59594 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 ⵉⵢⵢⵉⵔⵏ', '5 months = 5 months');
59595 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ⴰⵙⴳⴰⵙ', '345 days = a year');
59596 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ⵉⵙⴳⴰⵙⵏ', '548 days = 2 years');
59597 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ⴰⵙⴳⴰⵙ', '1 year = a year');
59598 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ⵉⵙⴳⴰⵙⵏ', '5 years = 5 years');
59599 });
59600
59601 test('suffix', function (assert) {
59602 assert.equal(moment(30000).from(0), 'ⴷⴰⴷⵅ ⵙ ⵢⴰⵏ ⵉⵎⵉⴽ', 'prefix');
59603 assert.equal(moment(0).from(30000), 'ⵢⴰⵏ ⵉⵎⵉⴽ', 'suffix');
59604 });
59605
59606 test('now from now', function (assert) {
59607 assert.equal(moment().fromNow(), 'ⵢⴰⵏ ⵉⵎⵉⴽ', 'now from now should display as in the past');
59608 });
59609
59610 test('fromNow', function (assert) {
59611 assert.equal(moment().add({s: 30}).fromNow(), 'ⴷⴰⴷⵅ ⵙ ⵢⴰⵏ ⵉⵎⵉⴽ', 'in a few seconds');
59612 assert.equal(moment().add({d: 5}).fromNow(), 'ⴷⴰⴷⵅ ⵙ ⵢⴰⵏ 5 oⵙⵙⴰⵏ', 'in 5 days');
59613 });
59614
59615 test('calendar day', function (assert) {
59616 var a = moment().hours(12).minutes(0).seconds(0);
59617
59618 assert.equal(moment(a).calendar(), 'ⴰⵙⴷⵅ ⴴ 12:00', 'today at the same time');
59619 assert.equal(moment(a).add({m: 25}).calendar(), 'ⴰⵙⴷⵅ ⴴ 12:25', 'Now plus 25 min');
59620 assert.equal(moment(a).add({h: 1}).calendar(), 'ⴰⵙⴷⵅ ⴴ 13:00', 'Now plus 1 hour');
59621 assert.equal(moment(a).add({d: 1}).calendar(), 'ⴰⵙⴽⴰ ⴴ 12:00', 'tomorrow at the same time');
59622 assert.equal(moment(a).subtract({h: 1}).calendar(), 'ⴰⵙⴷⵅ ⴴ 11:00', 'Now minus 1 hour');
59623 assert.equal(moment(a).subtract({d: 1}).calendar(), 'ⴰⵚⴰⵏⵜ ⴴ 12:00', 'yesterday at the same time');
59624 });
59625
59626 test('calendar next week', function (assert) {
59627 var i, m;
59628 for (i = 2; i < 7; i++) {
59629 m = moment().add({d: i});
59630 assert.equal(m.calendar(), m.format('dddd [ⴴ] LT'), 'Today + ' + i + ' days current time');
59631 m.hours(0).minutes(0).seconds(0).milliseconds(0);
59632 assert.equal(m.calendar(), m.format('dddd [ⴴ] LT'), 'Today + ' + i + ' days beginning of day');
59633 m.hours(23).minutes(59).seconds(59).milliseconds(999);
59634 assert.equal(m.calendar(), m.format('dddd [ⴴ] LT'), 'Today + ' + i + ' days end of day');
f2af24d5
IC
59635 }
59636 });
f2af24d5 59637
db71a655
KM
59638 test('calendar last week', function (assert) {
59639 var i, m;
59640 for (i = 2; i < 7; i++) {
59641 m = moment().subtract({d: i});
59642 assert.equal(m.calendar(), m.format('dddd [ⴴ] LT'), 'Today - ' + i + ' days current time');
59643 m.hours(0).minutes(0).seconds(0).milliseconds(0);
59644 assert.equal(m.calendar(), m.format('dddd [ⴴ] LT'), 'Today - ' + i + ' days beginning of day');
59645 m.hours(23).minutes(59).seconds(59).milliseconds(999);
59646 assert.equal(m.calendar(), m.format('dddd [ⴴ] LT'), 'Today - ' + i + ' days end of day');
59647 }
59648 });
f2af24d5 59649
db71a655
KM
59650 test('calendar all else', function (assert) {
59651 var weeksAgo = moment().subtract({w: 1}),
59652 weeksFromNow = moment().add({w: 1});
f2af24d5 59653
db71a655
KM
59654 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
59655 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
f2af24d5 59656
db71a655
KM
59657 weeksAgo = moment().subtract({w: 2});
59658 weeksFromNow = moment().add({w: 2});
f2af24d5 59659
db71a655
KM
59660 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
59661 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
59662 });
f2af24d5 59663
db71a655
KM
59664 test('weeks year starting sunday formatted', function (assert) {
59665 assert.equal(moment([2011, 11, 31]).format('w ww wo'), '1 01 1', 'Dec 31 2011 should be week 1');
59666 assert.equal(moment([2012, 0, 6]).format('w ww wo'), '1 01 1', 'Jan 6 2012 should be week 1');
59667 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '2 02 2', 'Jan 7 2012 should be week 2');
59668 assert.equal(moment([2012, 0, 13]).format('w ww wo'), '2 02 2', 'Jan 13 2012 should be week 2');
59669 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '3 03 3', 'Jan 14 2012 should be week 3');
59670 });
f2af24d5
IC
59671
59672})));
59673
59674
59675;(function (global, factory) {
59676 typeof exports === 'object' && typeof module !== 'undefined'
59677 && typeof require === 'function' ? factory(require('../../moment')) :
59678 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
59679 factory(global.moment)
59680}(this, (function (moment) { 'use strict';
59681
db71a655
KM
59682 function each(array, callback) {
59683 var i;
59684 for (i = 0; i < array.length; i++) {
59685 callback(array[i], i, array);
59686 }
f2af24d5 59687 }
f2af24d5 59688
c58511b9
KM
59689 function setupDeprecationHandler(test, moment$$1, scope) {
59690 test._expectedDeprecations = null;
59691 test._observedDeprecations = null;
59692 test._oldSupress = moment$$1.suppressDeprecationWarnings;
59693 moment$$1.suppressDeprecationWarnings = true;
59694 test.expectedDeprecations = function () {
59695 test._expectedDeprecations = arguments;
59696 test._observedDeprecations = [];
59697 };
59698 moment$$1.deprecationHandler = function (name, msg) {
59699 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
59700 if (deprecationId === -1) {
59701 throw new Error('Unexpected deprecation thrown name=' +
59702 name + ' msg=' + msg);
59703 }
59704 test._observedDeprecations[deprecationId] = 1;
59705 };
59706 }
59707
59708 function teardownDeprecationHandler(test, moment$$1, scope) {
59709 moment$$1.suppressDeprecationWarnings = test._oldSupress;
59710
59711 if (test._expectedDeprecations != null) {
59712 var missedDeprecations = [];
59713 each(test._expectedDeprecations, function (deprecationPattern, id) {
59714 if (test._observedDeprecations[id] !== 1) {
59715 missedDeprecations.push(deprecationPattern);
59716 }
59717 });
59718 if (missedDeprecations.length !== 0) {
59719 throw new Error('Expected deprecation warnings did not happen: ' +
59720 missedDeprecations.join(' '));
59721 }
59722 }
59723 }
59724
59725 function matchedDeprecation(name, msg, deprecations) {
59726 if (deprecations == null) {
59727 return -1;
59728 }
59729 for (var i = 0; i < deprecations.length; ++i) {
59730 if (name != null && name === deprecations[i]) {
59731 return i;
59732 }
59733 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
59734 return i;
59735 }
59736 }
59737 return -1;
59738 }
59739
59740 /*global QUnit:false*/
59741
59742 var test = QUnit.test;
59743
db71a655
KM
59744 function objectKeys(obj) {
59745 if (Object.keys) {
59746 return Object.keys(obj);
59747 } else {
59748 // IE8
59749 var res = [], i;
59750 for (i in obj) {
59751 if (obj.hasOwnProperty(i)) {
59752 res.push(i);
59753 }
f2af24d5 59754 }
db71a655 59755 return res;
f2af24d5 59756 }
f2af24d5 59757 }
f2af24d5 59758
db71a655 59759 // Pick the first defined of two or three arguments.
f2af24d5 59760
db71a655
KM
59761 function defineCommonLocaleTests(locale, options) {
59762 test('lenient day of month ordinal parsing', function (assert) {
59763 var i, ordinalStr, testMoment;
59764 for (i = 1; i <= 31; ++i) {
59765 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
59766 testMoment = moment(ordinalStr, 'YYYY MM Do');
59767 assert.equal(testMoment.year(), 2014,
59768 'lenient day of month ordinal parsing ' + i + ' year check');
59769 assert.equal(testMoment.month(), 0,
59770 'lenient day of month ordinal parsing ' + i + ' month check');
59771 assert.equal(testMoment.date(), i,
59772 'lenient day of month ordinal parsing ' + i + ' date check');
59773 }
59774 });
516f5f67 59775
db71a655
KM
59776 test('lenient day of month ordinal parsing of number', function (assert) {
59777 var i, testMoment;
59778 for (i = 1; i <= 31; ++i) {
59779 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
59780 assert.equal(testMoment.year(), 2014,
59781 'lenient day of month ordinal parsing of number ' + i + ' year check');
59782 assert.equal(testMoment.month(), 0,
59783 'lenient day of month ordinal parsing of number ' + i + ' month check');
59784 assert.equal(testMoment.date(), i,
59785 'lenient day of month ordinal parsing of number ' + i + ' date check');
59786 }
59787 });
516f5f67 59788
db71a655
KM
59789 test('strict day of month ordinal parsing', function (assert) {
59790 var i, ordinalStr, testMoment;
59791 for (i = 1; i <= 31; ++i) {
59792 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
59793 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
59794 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
59795 }
59796 });
516f5f67 59797
db71a655
KM
59798 test('meridiem invariant', function (assert) {
59799 var h, m, t1, t2;
59800 for (h = 0; h < 24; ++h) {
59801 for (m = 0; m < 60; m += 15) {
59802 t1 = moment.utc([2000, 0, 1, h, m]);
59803 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
59804 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
59805 'meridiem at ' + t1.format('HH:mm'));
59806 }
59807 }
59808 });
59809
59810 test('date format correctness', function (assert) {
59811 var data, tokens;
59812 data = moment.localeData()._longDateFormat;
59813 tokens = objectKeys(data);
59814 each(tokens, function (srchToken) {
59815 // Check each format string to make sure it does not contain any
59816 // tokens that need to be expanded.
59817 each(tokens, function (baseToken) {
59818 // strip escaped sequences
59819 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
59820 assert.equal(false, !!~format.indexOf(srchToken),
59821 'contains ' + srchToken + ' in ' + baseToken);
59822 });
73f3c911
IC
59823 });
59824 });
73f3c911 59825
db71a655
KM
59826 test('month parsing correctness', function (assert) {
59827 var i, m;
59828
59829 if (locale === 'tr') {
59830 // I can't fix it :(
c58511b9 59831 assert.expect(0);
db71a655
KM
59832 return;
59833 }
59834 function tester(format) {
59835 var r;
59836 r = moment(m.format(format), format);
59837 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
59838 if (locale !== 'ka') {
59839 r = moment(m.format(format).toLocaleUpperCase(), format);
59840 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
59841 }
db71a655
KM
59842 r = moment(m.format(format).toLocaleLowerCase(), format);
59843 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
59844
59845 r = moment(m.format(format), format, true);
59846 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
59847 if (locale !== 'ka') {
59848 r = moment(m.format(format).toLocaleUpperCase(), format, true);
59849 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
59850 }
db71a655
KM
59851 r = moment(m.format(format).toLocaleLowerCase(), format, true);
59852 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
59853 }
59854
59855 for (i = 0; i < 12; ++i) {
59856 m = moment([2015, i, 15, 18]);
59857 tester('MMM');
59858 tester('MMM.');
59859 tester('MMMM');
59860 tester('MMMM.');
59861 }
59862 });
516f5f67 59863
db71a655
KM
59864 test('weekday parsing correctness', function (assert) {
59865 var i, m;
59866
96d0d679 59867 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
59868 // tr, az: There is a lower-case letter (ı), that converted to
59869 // upper then lower changes to i
59870 // ro: there is the letter ț which behaves weird under IE8
59871 // mt: letter Ħ
96d0d679 59872 // ga: month with spaces
c58511b9 59873 assert.expect(0);
db71a655
KM
59874 return;
59875 }
59876 function tester(format) {
59877 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
59878 r = moment(m.format(format), format);
59879 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
59880 if (locale !== 'ka') {
59881 r = moment(m.format(format).toLocaleUpperCase(), format);
59882 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
59883 }
db71a655
KM
59884 r = moment(m.format(format).toLocaleLowerCase(), format);
59885 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
59886 r = moment(m.format(format), format, true);
59887 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
59888 if (locale !== 'ka') {
59889 r = moment(m.format(format).toLocaleUpperCase(), format, true);
59890 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
59891 }
db71a655
KM
59892 r = moment(m.format(format).toLocaleLowerCase(), format, true);
59893 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
59894 }
59895
59896 for (i = 0; i < 7; ++i) {
59897 m = moment.utc([2015, 0, i + 1, 18]);
59898 tester('dd');
59899 tester('ddd');
59900 tester('dddd');
59901 }
59902 });
516f5f67 59903
db71a655
KM
59904 test('valid localeData', function (assert) {
59905 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
59906 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
59907 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
59908 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
59909 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
59910 });
96d0d679
KM
59911
59912 test('localeData weekdays can localeSort', function (assert) {
59913 var weekdays = moment().localeData().weekdays();
59914 var weekdaysShort = moment().localeData().weekdaysShort();
59915 var weekdaysMin = moment().localeData().weekdaysMin();
59916 var shift = moment().localeData()._week.dow;
59917 assert.deepEqual(
59918 moment().localeData().weekdays(true),
59919 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
59920 'weekdays should localeSort');
59921 assert.deepEqual(
59922 moment().localeData().weekdaysShort(true),
59923 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
59924 'weekdaysShort should localeSort');
59925 assert.deepEqual(
59926 moment().localeData().weekdaysMin(true),
59927 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
59928 'weekdaysMin should localeSort');
59929 });
db71a655 59930 }
516f5f67 59931
db71a655
KM
59932 /*global QUnit:false*/
59933
db71a655
KM
59934 function localeModule (name, lifecycle) {
59935 QUnit.module('locale:' + name, {
c58511b9 59936 beforeEach : function () {
db71a655
KM
59937 moment.locale(name);
59938 moment.createFromInputFallback = function (config) {
59939 throw new Error('input not handled by moment: ' + config._i);
59940 };
59941 setupDeprecationHandler(test, moment, 'locale');
59942 if (lifecycle && lifecycle.setup) {
59943 lifecycle.setup();
59944 }
59945 },
c58511b9 59946 afterEach : function () {
db71a655
KM
59947 moment.locale('en');
59948 teardownDeprecationHandler(test, moment, 'locale');
59949 if (lifecycle && lifecycle.teardown) {
59950 lifecycle.teardown();
59951 }
b135bf1a 59952 }
73f3c911 59953 });
db71a655
KM
59954 defineCommonLocaleTests(name, -1, -1);
59955 }
59956
59957 localeModule('ug-cn');
59958
59959 test('parse', function (assert) {
59960 var tests = 'يانۋار يانۋار_فېۋرال فېۋرال_مارت مارت_ئاپرېل ئاپرېل_ماي ماي_ئىيۇن ئىيۇن_ئىيۇل ئىيۇل_ئاۋغۇست ئاۋغۇست_سېنتەبىر سېنتەبىر_ئۆكتەبىر ئۆكتەبىر_نويابىر نويابىر_دېكابىر دېكابىر'.split('_'), i;
59961 function equalTest (input, mmm, i) {
59962 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
59963 }
59964 for (i = 0; i < 12; i++) {
59965 tests[i] = tests[i].split(' ');
59966 equalTest(tests[i][0], 'MMM', i);
59967 equalTest(tests[i][1], 'MMM', i);
59968 equalTest(tests[i][0], 'MMMM', i);
59969 equalTest(tests[i][1], 'MMMM', i);
59970 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
59971 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
59972 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
59973 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
59974 }
59975 });
59976
59977 test('format', function (assert) {
59978 var a = [
59979 ['dddd, YYYY MMMM Do, a h:mm:ss', 'يەكشەنبە، 2010 فېۋرال 14-كۈنى، چۈشتىن كېيىن 3:25:50'],
59980 ['dddd, A h', 'يەكشەنبە، چۈشتىن كېيىن 3'],
59981 ['M Mo MM MMMM MMM', '2 2 02 فېۋرال فېۋرال'],
59982 ['YYYY YY', '2010 10'],
59983 ['D Do DD', '14 14-كۈنى 14'],
59984 ['d do dddd ddd dd', '0 0-كۈنى يەكشەنبە يە يە'],
59985 ['DDD DDDo DDDD', '45 45-كۈنى 045'],
59986 ['w wo ww', '7 7-ھەپتە 07'],
59987 ['h hh', '3 03'],
59988 ['H HH', '15 15'],
59989 ['m mm', '25 25'],
59990 ['s ss', '50 50'],
59991 ['a A', 'چۈشتىن كېيىن چۈشتىن كېيىن'],
59992 ['[يىلنىڭ] DDDo', 'يىلنىڭ 45-كۈنى'],
59993 ['LTS', '15:25:50'],
59994 ['L', '2010-02-14'],
59995 ['LL', '2010-يىلى2-ئاينىڭ14-كۈنى'],
59996 ['LLL', '2010-يىلى2-ئاينىڭ14-كۈنى، 15:25'],
59997 ['LLLL', 'يەكشەنبە، 2010-يىلى2-ئاينىڭ14-كۈنى، 15:25']
59998 ],
59999 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
60000 i;
b135bf1a 60001
db71a655
KM
60002 for (i = 0; i < a.length; i++) {
60003 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
b135bf1a 60004 }
db71a655
KM
60005 });
60006
60007 test('format month', function (assert) {
60008 var expected = 'يانۋار يانۋار_فېۋرال فېۋرال_مارت مارت_ئاپرېل ئاپرېل_ماي ماي_ئىيۇن ئىيۇن_ئىيۇل ئىيۇل_ئاۋغۇست ئاۋغۇست_سېنتەبىر سېنتەبىر_ئۆكتەبىر ئۆكتەبىر_نويابىر نويابىر_دېكابىر دېكابىر'.split('_'), i;
60009 for (i = 0; i < expected.length; i++) {
60010 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
b135bf1a 60011 }
db71a655 60012 });
b135bf1a 60013
b135bf1a 60014
b135bf1a 60015
db71a655
KM
60016 test('format week', function (assert) {
60017 var expected = 'يەكشەنبە يە يە_دۈشەنبە دۈ دۈ_سەيشەنبە سە سە_چارشەنبە چا چا_پەيشەنبە پە پە_جۈمە جۈ جۈ_شەنبە شە شە'.split('_'), i;
b135bf1a 60018
db71a655
KM
60019 for (i = 0; i < expected.length; i++) {
60020 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
73f3c911
IC
60021 }
60022 });
73f3c911 60023
db71a655
KM
60024 test('from', function (assert) {
60025 var start = moment([2007, 1, 28]);
60026 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'نەچچە سېكونت', '44 seconds = a few seconds');
60027 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'بىر مىنۇت', '45 seconds = a minute');
60028 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'بىر مىنۇت', '89 seconds = a minute');
60029 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 مىنۇت', '90 seconds = 2 minutes');
60030 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 مىنۇت', '44 minutes = 44 minutes');
60031 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'بىر سائەت', '45 minutes = an hour');
60032 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'بىر سائەت', '89 minutes = an hour');
60033 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 سائەت', '90 minutes = 2 hours');
60034 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 سائەت', '5 hours = 5 hours');
60035 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 سائەت', '21 hours = 21 hours');
60036 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'بىر كۈن', '22 hours = a day');
60037 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'بىر كۈن', '35 hours = a day');
60038 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 كۈن', '36 hours = 2 days');
60039 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'بىر كۈن', '1 day = a day');
60040 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 كۈن', '5 days = 5 days');
60041 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 كۈن', '25 days = 25 days');
60042 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'بىر ئاي', '26 days = a month');
60043 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'بىر ئاي', '30 days = a month');
60044 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'بىر ئاي', '43 days = a month');
60045 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 ئاي', '46 days = 2 months');
60046 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 ئاي', '75 days = 2 months');
60047 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 ئاي', '76 days = 3 months');
60048 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'بىر ئاي', '1 month = a month');
60049 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 ئاي', '5 months = 5 months');
60050 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'بىر يىل', '345 days = a year');
60051 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 يىل', '548 days = 2 years');
60052 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'بىر يىل', '1 year = a year');
60053 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 يىل', '5 years = 5 years');
60054 });
73f3c911 60055
db71a655
KM
60056 test('suffix', function (assert) {
60057 assert.equal(moment(30000).from(0), 'نەچچە سېكونت كېيىن', 'prefix');
60058 assert.equal(moment(0).from(30000), 'نەچچە سېكونت بۇرۇن', 'suffix');
60059 });
60060
60061 test('now from now', function (assert) {
60062 assert.equal(moment().fromNow(), 'نەچچە سېكونت بۇرۇن', 'now from now should display as in the past');
60063 });
60064
60065 test('fromNow', function (assert) {
60066 assert.equal(moment().add({s: 30}).fromNow(), 'نەچچە سېكونت كېيىن', 'in a few seconds');
60067 assert.equal(moment().add({d: 5}).fromNow(), '5 كۈن كېيىن', 'in 5 days');
60068 });
73f3c911 60069
db71a655
KM
60070 test('calendar day', function (assert) {
60071 var a = moment().hours(12).minutes(0).seconds(0);
f2af24d5 60072
db71a655
KM
60073 assert.equal(moment(a).calendar(), 'بۈگۈن سائەت 12:00', 'today at the same time');
60074 assert.equal(moment(a).add({m: 25}).calendar(), 'بۈگۈن سائەت 12:25', 'Now plus 25 min');
60075 assert.equal(moment(a).add({h: 1}).calendar(), 'بۈگۈن سائەت 13:00', 'Now plus 1 hour');
60076 assert.equal(moment(a).add({d: 1}).calendar(), 'ئەتە سائەت 12:00', 'tomorrow at the same time');
60077 assert.equal(moment(a).subtract({h: 1}).calendar(), 'بۈگۈن سائەت 11:00', 'Now minus 1 hour');
60078 assert.equal(moment(a).subtract({d: 1}).calendar(), 'تۆنۈگۈن 12:00', 'yesterday at the same time');
60079 });
f2af24d5 60080
73f3c911 60081
db71a655
KM
60082 test('calendar next week', function (assert) {
60083 var i, m;
60084 for (i = 2; i < 7; i++) {
60085 m = moment().add({d: i});
60086 assert.equal(m.calendar(), m.format('[كېلەركى] dddd [سائەت] LT'), 'Today + ' + i + ' days current time');
60087 m.hours(0).minutes(0).seconds(0).milliseconds(0);
60088 assert.equal(m.calendar(), m.format('[كېلەركى] dddd [سائەت] LT'), 'Today + ' + i + ' days beginning of day');
60089 m.hours(23).minutes(59).seconds(59).milliseconds(999);
60090 assert.equal(m.calendar(), m.format('[كېلەركى] dddd [سائەت] LT'), 'Today + ' + i + ' days end of day');
60091 }
60092 });
60093
60094 test('calendar last week', function (assert) {
60095 var i, m;
60096 for (i = 2; i < 7; i++) {
60097 m = moment().subtract({d: i});
60098 assert.equal(m.calendar(), m.format('[ئالدىنقى] dddd [سائەت] LT'), 'Today - ' + i + ' days current time');
60099 m.hours(0).minutes(0).seconds(0).milliseconds(0);
60100 assert.equal(m.calendar(), m.format('[ئالدىنقى] dddd [سائەت] LT'), 'Today - ' + i + ' days beginning of day');
60101 m.hours(23).minutes(59).seconds(59).milliseconds(999);
60102 assert.equal(m.calendar(), m.format('[ئالدىنقى] dddd [سائەت] LT'), 'Today - ' + i + ' days end of day');
60103 }
60104 });
60105
60106 test('calendar all else', function (assert) {
60107 var weeksAgo = moment().subtract({w: 1}),
60108 weeksFromNow = moment().add({w: 1});
60109
60110 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
60111 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
73f3c911 60112
db71a655
KM
60113 weeksAgo = moment().subtract({w: 2});
60114 weeksFromNow = moment().add({w: 2});
73f3c911 60115
db71a655
KM
60116 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
60117 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
60118 });
73f3c911 60119
db71a655
KM
60120 test('meridiem', function (assert) {
60121 assert.equal(moment([2011, 2, 23, 0, 0]).format('A'), 'يېرىم كېچە', 'before dawn');
60122 assert.equal(moment([2011, 2, 23, 6, 0]).format('A'), 'سەھەر', 'morning');
60123 assert.equal(moment([2011, 2, 23, 9, 0]).format('A'), 'چۈشتىن بۇرۇن', 'before noon');
60124 assert.equal(moment([2011, 2, 23, 12, 0]).format('A'), 'چۈش', 'noon');
60125 assert.equal(moment([2011, 2, 23, 13, 0]).format('A'), 'چۈشتىن كېيىن', 'afternoon');
60126 assert.equal(moment([2011, 2, 23, 18, 0]).format('A'), 'كەچ', 'night');
60127 });
73f3c911 60128
db71a655
KM
60129 test('weeks year starting sunday format', function (assert) {
60130 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-ھەپتە', 'Dec 26 2011 should be week 1');
60131 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-ھەپتە', 'Jan 1 2012 should be week 1');
60132 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-ھەپتە', 'Jan 2 2012 should be week 2');
60133 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-ھەپتە', 'Jan 8 2012 should be week 2');
60134 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-ھەپتە', 'Jan 9 2012 should be week 3');
60135 });
73f3c911
IC
60136
60137})));
d6651c21 60138
d6651c21 60139
73f3c911
IC
60140;(function (global, factory) {
60141 typeof exports === 'object' && typeof module !== 'undefined'
60142 && typeof require === 'function' ? factory(require('../../moment')) :
60143 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
60144 factory(global.moment)
60145}(this, (function (moment) { 'use strict';
d6651c21 60146
db71a655
KM
60147 function each(array, callback) {
60148 var i;
60149 for (i = 0; i < array.length; i++) {
60150 callback(array[i], i, array);
60151 }
d6651c21
IC
60152 }
60153
c58511b9
KM
60154 function setupDeprecationHandler(test, moment$$1, scope) {
60155 test._expectedDeprecations = null;
60156 test._observedDeprecations = null;
60157 test._oldSupress = moment$$1.suppressDeprecationWarnings;
60158 moment$$1.suppressDeprecationWarnings = true;
60159 test.expectedDeprecations = function () {
60160 test._expectedDeprecations = arguments;
60161 test._observedDeprecations = [];
60162 };
60163 moment$$1.deprecationHandler = function (name, msg) {
60164 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
60165 if (deprecationId === -1) {
60166 throw new Error('Unexpected deprecation thrown name=' +
60167 name + ' msg=' + msg);
60168 }
60169 test._observedDeprecations[deprecationId] = 1;
60170 };
60171 }
60172
60173 function teardownDeprecationHandler(test, moment$$1, scope) {
60174 moment$$1.suppressDeprecationWarnings = test._oldSupress;
60175
60176 if (test._expectedDeprecations != null) {
60177 var missedDeprecations = [];
60178 each(test._expectedDeprecations, function (deprecationPattern, id) {
60179 if (test._observedDeprecations[id] !== 1) {
60180 missedDeprecations.push(deprecationPattern);
60181 }
60182 });
60183 if (missedDeprecations.length !== 0) {
60184 throw new Error('Expected deprecation warnings did not happen: ' +
60185 missedDeprecations.join(' '));
60186 }
60187 }
60188 }
60189
60190 function matchedDeprecation(name, msg, deprecations) {
60191 if (deprecations == null) {
60192 return -1;
60193 }
60194 for (var i = 0; i < deprecations.length; ++i) {
60195 if (name != null && name === deprecations[i]) {
60196 return i;
60197 }
60198 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
60199 return i;
60200 }
60201 }
60202 return -1;
60203 }
60204
60205 /*global QUnit:false*/
60206
60207 var test = QUnit.test;
60208
db71a655
KM
60209 function objectKeys(obj) {
60210 if (Object.keys) {
60211 return Object.keys(obj);
60212 } else {
60213 // IE8
60214 var res = [], i;
60215 for (i in obj) {
60216 if (obj.hasOwnProperty(i)) {
60217 res.push(i);
60218 }
d6651c21 60219 }
db71a655 60220 return res;
d6651c21 60221 }
b135bf1a
IC
60222 }
60223
db71a655 60224 // Pick the first defined of two or three arguments.
516f5f67 60225
db71a655
KM
60226 function defineCommonLocaleTests(locale, options) {
60227 test('lenient day of month ordinal parsing', function (assert) {
60228 var i, ordinalStr, testMoment;
60229 for (i = 1; i <= 31; ++i) {
60230 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
60231 testMoment = moment(ordinalStr, 'YYYY MM Do');
60232 assert.equal(testMoment.year(), 2014,
60233 'lenient day of month ordinal parsing ' + i + ' year check');
60234 assert.equal(testMoment.month(), 0,
60235 'lenient day of month ordinal parsing ' + i + ' month check');
60236 assert.equal(testMoment.date(), i,
60237 'lenient day of month ordinal parsing ' + i + ' date check');
60238 }
60239 });
516f5f67 60240
db71a655
KM
60241 test('lenient day of month ordinal parsing of number', function (assert) {
60242 var i, testMoment;
60243 for (i = 1; i <= 31; ++i) {
60244 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
60245 assert.equal(testMoment.year(), 2014,
60246 'lenient day of month ordinal parsing of number ' + i + ' year check');
60247 assert.equal(testMoment.month(), 0,
60248 'lenient day of month ordinal parsing of number ' + i + ' month check');
60249 assert.equal(testMoment.date(), i,
60250 'lenient day of month ordinal parsing of number ' + i + ' date check');
60251 }
60252 });
516f5f67 60253
db71a655
KM
60254 test('strict day of month ordinal parsing', function (assert) {
60255 var i, ordinalStr, testMoment;
60256 for (i = 1; i <= 31; ++i) {
60257 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
60258 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
60259 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
60260 }
60261 });
516f5f67 60262
db71a655
KM
60263 test('meridiem invariant', function (assert) {
60264 var h, m, t1, t2;
60265 for (h = 0; h < 24; ++h) {
60266 for (m = 0; m < 60; m += 15) {
60267 t1 = moment.utc([2000, 0, 1, h, m]);
60268 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
60269 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
60270 'meridiem at ' + t1.format('HH:mm'));
60271 }
60272 }
60273 });
60274
60275 test('date format correctness', function (assert) {
60276 var data, tokens;
60277 data = moment.localeData()._longDateFormat;
60278 tokens = objectKeys(data);
60279 each(tokens, function (srchToken) {
60280 // Check each format string to make sure it does not contain any
60281 // tokens that need to be expanded.
60282 each(tokens, function (baseToken) {
60283 // strip escaped sequences
60284 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
60285 assert.equal(false, !!~format.indexOf(srchToken),
60286 'contains ' + srchToken + ' in ' + baseToken);
60287 });
73f3c911
IC
60288 });
60289 });
73f3c911 60290
db71a655
KM
60291 test('month parsing correctness', function (assert) {
60292 var i, m;
60293
60294 if (locale === 'tr') {
60295 // I can't fix it :(
c58511b9 60296 assert.expect(0);
db71a655
KM
60297 return;
60298 }
60299 function tester(format) {
60300 var r;
60301 r = moment(m.format(format), format);
60302 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
60303 if (locale !== 'ka') {
60304 r = moment(m.format(format).toLocaleUpperCase(), format);
60305 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
60306 }
db71a655
KM
60307 r = moment(m.format(format).toLocaleLowerCase(), format);
60308 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
60309
60310 r = moment(m.format(format), format, true);
60311 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
60312 if (locale !== 'ka') {
60313 r = moment(m.format(format).toLocaleUpperCase(), format, true);
60314 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
60315 }
db71a655
KM
60316 r = moment(m.format(format).toLocaleLowerCase(), format, true);
60317 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
60318 }
60319
60320 for (i = 0; i < 12; ++i) {
60321 m = moment([2015, i, 15, 18]);
60322 tester('MMM');
60323 tester('MMM.');
60324 tester('MMMM');
60325 tester('MMMM.');
60326 }
60327 });
60328
60329 test('weekday parsing correctness', function (assert) {
60330 var i, m;
60331
96d0d679 60332 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
60333 // tr, az: There is a lower-case letter (ı), that converted to
60334 // upper then lower changes to i
60335 // ro: there is the letter ț which behaves weird under IE8
60336 // mt: letter Ħ
96d0d679 60337 // ga: month with spaces
c58511b9 60338 assert.expect(0);
db71a655
KM
60339 return;
60340 }
60341 function tester(format) {
60342 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
60343 r = moment(m.format(format), format);
60344 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
60345 if (locale !== 'ka') {
60346 r = moment(m.format(format).toLocaleUpperCase(), format);
60347 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
60348 }
db71a655
KM
60349 r = moment(m.format(format).toLocaleLowerCase(), format);
60350 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
60351 r = moment(m.format(format), format, true);
60352 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
60353 if (locale !== 'ka') {
60354 r = moment(m.format(format).toLocaleUpperCase(), format, true);
60355 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
60356 }
db71a655
KM
60357 r = moment(m.format(format).toLocaleLowerCase(), format, true);
60358 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
60359 }
60360
60361 for (i = 0; i < 7; ++i) {
60362 m = moment.utc([2015, 0, i + 1, 18]);
60363 tester('dd');
60364 tester('ddd');
60365 tester('dddd');
60366 }
60367 });
60368
60369 test('valid localeData', function (assert) {
60370 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
60371 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
60372 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
60373 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
60374 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
60375 });
96d0d679
KM
60376
60377 test('localeData weekdays can localeSort', function (assert) {
60378 var weekdays = moment().localeData().weekdays();
60379 var weekdaysShort = moment().localeData().weekdaysShort();
60380 var weekdaysMin = moment().localeData().weekdaysMin();
60381 var shift = moment().localeData()._week.dow;
60382 assert.deepEqual(
60383 moment().localeData().weekdays(true),
60384 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
60385 'weekdays should localeSort');
60386 assert.deepEqual(
60387 moment().localeData().weekdaysShort(true),
60388 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
60389 'weekdaysShort should localeSort');
60390 assert.deepEqual(
60391 moment().localeData().weekdaysMin(true),
60392 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
60393 'weekdaysMin should localeSort');
60394 });
db71a655 60395 }
516f5f67 60396
db71a655 60397 /*global QUnit:false*/
b135bf1a 60398
db71a655
KM
60399 function localeModule (name, lifecycle) {
60400 QUnit.module('locale:' + name, {
c58511b9 60401 beforeEach : function () {
db71a655
KM
60402 moment.locale(name);
60403 moment.createFromInputFallback = function (config) {
60404 throw new Error('input not handled by moment: ' + config._i);
60405 };
60406 setupDeprecationHandler(test, moment, 'locale');
60407 if (lifecycle && lifecycle.setup) {
60408 lifecycle.setup();
60409 }
60410 },
c58511b9 60411 afterEach : function () {
db71a655
KM
60412 moment.locale('en');
60413 teardownDeprecationHandler(test, moment, 'locale');
60414 if (lifecycle && lifecycle.teardown) {
60415 lifecycle.teardown();
60416 }
b135bf1a 60417 }
73f3c911 60418 });
db71a655
KM
60419 defineCommonLocaleTests(name, -1, -1);
60420 }
60421
60422 localeModule('uk');
60423
60424 test('parse', function (assert) {
60425 var tests = 'січень січ_лютий лют_березень бер_квітень квіт_травень трав_червень черв_липень лип_серпень серп_вересень вер_жовтень жовт_листопад лист_грудень груд'.split('_'), i;
60426 function equalTest(input, mmm, i) {
60427 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
60428 }
60429 for (i = 0; i < 12; i++) {
60430 tests[i] = tests[i].split(' ');
60431 equalTest(tests[i][0], 'MMM', i);
60432 equalTest(tests[i][1], 'MMM', i);
60433 equalTest(tests[i][0], 'MMMM', i);
60434 equalTest(tests[i][1], 'MMMM', i);
60435 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
60436 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
60437 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
60438 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
60439 }
60440 });
60441
60442 test('format', function (assert) {
60443 var a = [
60444 ['dddd, Do MMMM YYYY, HH:mm:ss', 'неділя, 14-го лютого 2010, 15:25:50'],
60445 ['ddd, h A', 'нд, 3 дня'],
60446 ['M Mo MM MMMM MMM', '2 2-й 02 лютий лют'],
60447 ['YYYY YY', '2010 10'],
60448 ['D Do DD', '14 14-го 14'],
60449 ['d do dddd ddd dd', '0 0-й неділя нд нд'],
60450 ['DDD DDDo DDDD', '45 45-й 045'],
60451 ['w wo ww', '7 7-й 07'],
60452 ['h hh', '3 03'],
60453 ['H HH', '15 15'],
60454 ['m mm', '25 25'],
60455 ['s ss', '50 50'],
60456 ['a A', 'дня дня'],
60457 ['DDDo [день року]', '45-й день року'],
60458 ['LTS', '15:25:50'],
60459 ['L', '14.02.2010'],
60460 ['LL', '14 лютого 2010 р.'],
60461 ['LLL', '14 лютого 2010 р., 15:25'],
60462 ['LLLL', 'неділя, 14 лютого 2010 р., 15:25']
60463 ],
60464 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
60465 i;
60466 for (i = 0; i < a.length; i++) {
60467 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
60468 }
60469 });
60470
60471 test('format meridiem', function (assert) {
60472 assert.equal(moment([2012, 11, 28, 0, 0]).format('A'), 'ночі', 'night');
60473 assert.equal(moment([2012, 11, 28, 3, 59]).format('A'), 'ночі', 'night');
60474 assert.equal(moment([2012, 11, 28, 4, 0]).format('A'), 'ранку', 'morning');
60475 assert.equal(moment([2012, 11, 28, 11, 59]).format('A'), 'ранку', 'morning');
60476 assert.equal(moment([2012, 11, 28, 12, 0]).format('A'), 'дня', 'afternoon');
60477 assert.equal(moment([2012, 11, 28, 16, 59]).format('A'), 'дня', 'afternoon');
60478 assert.equal(moment([2012, 11, 28, 17, 0]).format('A'), 'вечора', 'evening');
60479 assert.equal(moment([2012, 11, 28, 23, 59]).format('A'), 'вечора', 'evening');
60480 });
60481
60482 test('format ordinal', function (assert) {
60483 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-й', '1-й');
60484 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-й', '2-й');
60485 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-й', '3-й');
60486 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-й', '4-й');
60487 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-й', '5-й');
60488 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-й', '6-й');
60489 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-й', '7-й');
60490 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-й', '8-й');
60491 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-й', '9-й');
60492 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-й', '10-й');
60493
60494 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-й', '11-й');
60495 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-й', '12-й');
60496 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-й', '13-й');
60497 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-й', '14-й');
60498 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-й', '15-й');
60499 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-й', '16-й');
60500 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-й', '17-й');
60501 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-й', '18-й');
60502 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-й', '19-й');
60503 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-й', '20-й');
60504
60505 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-й', '21-й');
60506 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-й', '22-й');
60507 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-й', '23-й');
60508 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-й', '24-й');
60509 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-й', '25-й');
60510 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-й', '26-й');
60511 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-й', '27-й');
60512 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-й', '28-й');
60513 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-й', '29-й');
60514 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-й', '30-й');
60515
60516 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-й', '31-й');
60517 });
60518
60519 test('format month', function (assert) {
60520 var expected = 'січень січ_лютий лют_березень бер_квітень квіт_травень трав_червень черв_липень лип_серпень серп_вересень вер_жовтень жовт_листопад лист_грудень груд'.split('_'), i;
60521 for (i = 0; i < expected.length; i++) {
60522 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
60523 }
60524 });
60525
60526 test('format month case', function (assert) {
60527 var months = {
60528 'nominative': 'січень_лютий_березень_квітень_травень_червень_липень_серпень_вересень_жовтень_листопад_грудень'.split('_'),
60529 'accusative': 'січня_лютого_березня_квітня_травня_червня_липня_серпня_вересня_жовтня_листопада_грудня'.split('_')
60530 }, i;
60531 for (i = 0; i < 12; i++) {
60532 assert.equal(moment([2011, i, 1]).format('D MMMM'), '1 ' + months.accusative[i], '1 ' + months.accusative[i]);
60533 assert.equal(moment([2011, i, 1]).format('MMMM'), months.nominative[i], '1 ' + months.nominative[i]);
60534 }
60535 });
60536
60537 test('format week', function (assert) {
60538 var expected = 'неділя нд нд_понеділок пн пн_вівторок вт вт_середа ср ср_четвер чт чт_п’ятниця пт пт_субота сб сб'.split('_'), i;
60539 for (i = 0; i < expected.length; i++) {
60540 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
60541 }
60542 });
60543
60544 test('from', function (assert) {
60545 var start = moment([2007, 1, 28]);
60546 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'декілька секунд', '44 seconds = seconds');
60547 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'хвилина', '45 seconds = a minute');
60548 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'хвилина', '89 seconds = a minute');
60549 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 хвилини', '90 seconds = 2 minutes');
60550 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 хвилини', '44 minutes = 44 minutes');
60551 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'годину', '45 minutes = an hour');
60552 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'годину', '89 minutes = an hour');
60553 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 години', '90 minutes = 2 hours');
60554 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 годин', '5 hours = 5 hours');
60555 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 година', '21 hours = 21 hours');
60556 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'день', '22 hours = a day');
60557 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'день', '35 hours = a day');
60558 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 дні', '36 hours = 2 days');
60559 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'день', '1 day = a day');
60560 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 днів', '5 days = 5 days');
60561 assert.equal(start.from(moment([2007, 1, 28]).add({d: 11}), true), '11 днів', '11 days = 11 days');
60562 assert.equal(start.from(moment([2007, 1, 28]).add({d: 21}), true), '21 день', '21 days = 21 days');
60563 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 днів', '25 days = 25 days');
60564 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'місяць', '26 days = a month');
60565 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'місяць', '30 days = a month');
60566 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'місяць', '43 days = a month');
60567 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 місяці', '46 days = 2 months');
60568 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 місяці', '75 days = 2 months');
60569 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 місяці', '76 days = 3 months');
60570 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'місяць', '1 month = a month');
60571 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 місяців', '5 months = 5 months');
60572 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'рік', '345 days = a year');
60573 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 роки', '548 days = 2 years');
60574 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'рік', '1 year = a year');
60575 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 років', '5 years = 5 years');
60576 });
60577
60578 test('suffix', function (assert) {
60579 assert.equal(moment(30000).from(0), 'за декілька секунд', 'prefix');
60580 assert.equal(moment(0).from(30000), 'декілька секунд тому', 'suffix');
60581 });
60582
60583 test('fromNow', function (assert) {
60584 assert.equal(moment().add({s: 30}).fromNow(), 'за декілька секунд', 'in seconds');
60585 assert.equal(moment().add({d: 5}).fromNow(), 'за 5 днів', 'in 5 days');
60586 });
60587
60588 test('calendar day', function (assert) {
60589 var a = moment().hours(12).minutes(0).seconds(0);
60590
60591 assert.equal(moment(a).calendar(), 'Сьогодні о 12:00', 'today at the same time');
60592 assert.equal(moment(a).add({m: 25}).calendar(), 'Сьогодні о 12:25', 'Now plus 25 min');
60593 assert.equal(moment(a).add({h: 1}).calendar(), 'Сьогодні о 13:00', 'Now plus 1 hour');
60594 assert.equal(moment(a).add({d: 1}).calendar(), 'Завтра о 12:00', 'tomorrow at the same time');
60595 assert.equal(moment(a).subtract({h: 2}).calendar(), 'Сьогодні о 10:00', 'Now minus 2 hours');
60596 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Вчора о 12:00', 'yesterday at the same time');
60597 // A special case for Ukrainian since 11 hours have different preposition
60598 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Сьогодні об 11:00', 'same day at 11 o\'clock');
60599 });
60600
60601 test('calendar next week', function (assert) {
60602 var i, m;
60603 for (i = 2; i < 7; i++) {
60604 m = moment().add({d: i});
60605 assert.equal(m.calendar(), m.format('[У] dddd [о' + (m.hours() === 11 ? 'б' : '') + '] LT'), 'Today + ' + i + ' days current time');
60606 m.hours(0).minutes(0).seconds(0).milliseconds(0);
60607 assert.equal(m.calendar(), m.format('[У] dddd [о] LT'), 'Today + ' + i + ' days beginning of day');
60608 m.hours(23).minutes(59).seconds(59).milliseconds(999);
60609 assert.equal(m.calendar(), m.format('[У] dddd [о] LT'), 'Today + ' + i + ' days end of day');
b135bf1a 60610 }
db71a655 60611 });
b135bf1a 60612
db71a655
KM
60613 test('calendar last week', function (assert) {
60614 var i, m;
60615
60616 function makeFormat(d) {
60617 switch (d.day()) {
60618 case 0:
60619 case 3:
60620 case 5:
60621 case 6:
60622 return '[Минулої] dddd [о' + (d.hours() === 11 ? 'б' : '') + '] LT';
60623 case 1:
60624 case 2:
60625 case 4:
60626 return '[Минулого] dddd [о' + (d.hours() === 11 ? 'б' : '') + '] LT';
60627 }
b135bf1a 60628 }
db71a655
KM
60629
60630 for (i = 2; i < 7; i++) {
60631 m = moment().subtract({d: i});
60632 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time');
60633 m.hours(0).minutes(0).seconds(0).milliseconds(0);
60634 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day');
60635 m.hours(23).minutes(59).seconds(59).milliseconds(999);
60636 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day');
b135bf1a 60637 }
db71a655 60638 });
b135bf1a 60639
db71a655
KM
60640 test('calendar all else', function (assert) {
60641 var weeksAgo = moment().subtract({w: 1}),
60642 weeksFromNow = moment().add({w: 1});
b135bf1a 60643
db71a655
KM
60644 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
60645 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
b135bf1a 60646
db71a655
KM
60647 weeksAgo = moment().subtract({w: 2});
60648 weeksFromNow = moment().add({w: 2});
b135bf1a 60649
db71a655
KM
60650 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
60651 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
60652 });
60653
60654 test('weeks year starting sunday formatted', function (assert) {
60655 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-й', 'Dec 26 2011 should be week 1');
60656 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-й', 'Jan 1 2012 should be week 1');
60657 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-й', 'Jan 2 2012 should be week 2');
60658 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-й', 'Jan 8 2012 should be week 2');
60659 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-й', 'Jan 9 2012 should be week 3');
60660 });
516f5f67 60661
73f3c911 60662})));
516f5f67 60663
516f5f67 60664
73f3c911
IC
60665;(function (global, factory) {
60666 typeof exports === 'object' && typeof module !== 'undefined'
60667 && typeof require === 'function' ? factory(require('../../moment')) :
60668 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
60669 factory(global.moment)
60670}(this, (function (moment) { 'use strict';
516f5f67 60671
db71a655
KM
60672 function each(array, callback) {
60673 var i;
60674 for (i = 0; i < array.length; i++) {
60675 callback(array[i], i, array);
60676 }
73f3c911 60677 }
516f5f67 60678
c58511b9
KM
60679 function setupDeprecationHandler(test, moment$$1, scope) {
60680 test._expectedDeprecations = null;
60681 test._observedDeprecations = null;
60682 test._oldSupress = moment$$1.suppressDeprecationWarnings;
60683 moment$$1.suppressDeprecationWarnings = true;
60684 test.expectedDeprecations = function () {
60685 test._expectedDeprecations = arguments;
60686 test._observedDeprecations = [];
60687 };
60688 moment$$1.deprecationHandler = function (name, msg) {
60689 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
60690 if (deprecationId === -1) {
60691 throw new Error('Unexpected deprecation thrown name=' +
60692 name + ' msg=' + msg);
60693 }
60694 test._observedDeprecations[deprecationId] = 1;
60695 };
60696 }
60697
60698 function teardownDeprecationHandler(test, moment$$1, scope) {
60699 moment$$1.suppressDeprecationWarnings = test._oldSupress;
60700
60701 if (test._expectedDeprecations != null) {
60702 var missedDeprecations = [];
60703 each(test._expectedDeprecations, function (deprecationPattern, id) {
60704 if (test._observedDeprecations[id] !== 1) {
60705 missedDeprecations.push(deprecationPattern);
60706 }
60707 });
60708 if (missedDeprecations.length !== 0) {
60709 throw new Error('Expected deprecation warnings did not happen: ' +
60710 missedDeprecations.join(' '));
60711 }
60712 }
60713 }
60714
60715 function matchedDeprecation(name, msg, deprecations) {
60716 if (deprecations == null) {
60717 return -1;
60718 }
60719 for (var i = 0; i < deprecations.length; ++i) {
60720 if (name != null && name === deprecations[i]) {
60721 return i;
60722 }
60723 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
60724 return i;
60725 }
60726 }
60727 return -1;
60728 }
60729
60730 /*global QUnit:false*/
60731
60732 var test = QUnit.test;
60733
db71a655
KM
60734 function objectKeys(obj) {
60735 if (Object.keys) {
60736 return Object.keys(obj);
60737 } else {
60738 // IE8
60739 var res = [], i;
60740 for (i in obj) {
60741 if (obj.hasOwnProperty(i)) {
60742 res.push(i);
60743 }
73f3c911 60744 }
db71a655 60745 return res;
516f5f67 60746 }
73f3c911 60747 }
73f3c911 60748
db71a655 60749 // Pick the first defined of two or three arguments.
516f5f67 60750
db71a655
KM
60751 function defineCommonLocaleTests(locale, options) {
60752 test('lenient day of month ordinal parsing', function (assert) {
60753 var i, ordinalStr, testMoment;
60754 for (i = 1; i <= 31; ++i) {
60755 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
60756 testMoment = moment(ordinalStr, 'YYYY MM Do');
60757 assert.equal(testMoment.year(), 2014,
60758 'lenient day of month ordinal parsing ' + i + ' year check');
60759 assert.equal(testMoment.month(), 0,
60760 'lenient day of month ordinal parsing ' + i + ' month check');
60761 assert.equal(testMoment.date(), i,
60762 'lenient day of month ordinal parsing ' + i + ' date check');
60763 }
60764 });
516f5f67 60765
db71a655
KM
60766 test('lenient day of month ordinal parsing of number', function (assert) {
60767 var i, testMoment;
60768 for (i = 1; i <= 31; ++i) {
60769 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
60770 assert.equal(testMoment.year(), 2014,
60771 'lenient day of month ordinal parsing of number ' + i + ' year check');
60772 assert.equal(testMoment.month(), 0,
60773 'lenient day of month ordinal parsing of number ' + i + ' month check');
60774 assert.equal(testMoment.date(), i,
60775 'lenient day of month ordinal parsing of number ' + i + ' date check');
60776 }
60777 });
516f5f67 60778
db71a655
KM
60779 test('strict day of month ordinal parsing', function (assert) {
60780 var i, ordinalStr, testMoment;
60781 for (i = 1; i <= 31; ++i) {
60782 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
60783 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
60784 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
60785 }
60786 });
516f5f67 60787
db71a655
KM
60788 test('meridiem invariant', function (assert) {
60789 var h, m, t1, t2;
60790 for (h = 0; h < 24; ++h) {
60791 for (m = 0; m < 60; m += 15) {
60792 t1 = moment.utc([2000, 0, 1, h, m]);
60793 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
60794 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
60795 'meridiem at ' + t1.format('HH:mm'));
60796 }
60797 }
60798 });
60799
60800 test('date format correctness', function (assert) {
60801 var data, tokens;
60802 data = moment.localeData()._longDateFormat;
60803 tokens = objectKeys(data);
60804 each(tokens, function (srchToken) {
60805 // Check each format string to make sure it does not contain any
60806 // tokens that need to be expanded.
60807 each(tokens, function (baseToken) {
60808 // strip escaped sequences
60809 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
60810 assert.equal(false, !!~format.indexOf(srchToken),
60811 'contains ' + srchToken + ' in ' + baseToken);
60812 });
73f3c911
IC
60813 });
60814 });
516f5f67 60815
db71a655
KM
60816 test('month parsing correctness', function (assert) {
60817 var i, m;
60818
60819 if (locale === 'tr') {
60820 // I can't fix it :(
c58511b9 60821 assert.expect(0);
db71a655
KM
60822 return;
60823 }
60824 function tester(format) {
60825 var r;
60826 r = moment(m.format(format), format);
60827 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
60828 if (locale !== 'ka') {
60829 r = moment(m.format(format).toLocaleUpperCase(), format);
60830 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
60831 }
db71a655
KM
60832 r = moment(m.format(format).toLocaleLowerCase(), format);
60833 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
60834
60835 r = moment(m.format(format), format, true);
60836 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
60837 if (locale !== 'ka') {
60838 r = moment(m.format(format).toLocaleUpperCase(), format, true);
60839 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
60840 }
db71a655
KM
60841 r = moment(m.format(format).toLocaleLowerCase(), format, true);
60842 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
60843 }
60844
60845 for (i = 0; i < 12; ++i) {
60846 m = moment([2015, i, 15, 18]);
60847 tester('MMM');
60848 tester('MMM.');
60849 tester('MMMM');
60850 tester('MMMM.');
60851 }
60852 });
516f5f67 60853
db71a655
KM
60854 test('weekday parsing correctness', function (assert) {
60855 var i, m;
60856
96d0d679 60857 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
60858 // tr, az: There is a lower-case letter (ı), that converted to
60859 // upper then lower changes to i
60860 // ro: there is the letter ț which behaves weird under IE8
60861 // mt: letter Ħ
96d0d679 60862 // ga: month with spaces
c58511b9 60863 assert.expect(0);
db71a655
KM
60864 return;
60865 }
60866 function tester(format) {
60867 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
60868 r = moment(m.format(format), format);
60869 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
60870 if (locale !== 'ka') {
60871 r = moment(m.format(format).toLocaleUpperCase(), format);
60872 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
60873 }
db71a655
KM
60874 r = moment(m.format(format).toLocaleLowerCase(), format);
60875 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
60876 r = moment(m.format(format), format, true);
60877 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
60878 if (locale !== 'ka') {
60879 r = moment(m.format(format).toLocaleUpperCase(), format, true);
60880 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
60881 }
db71a655
KM
60882 r = moment(m.format(format).toLocaleLowerCase(), format, true);
60883 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
60884 }
60885
60886 for (i = 0; i < 7; ++i) {
60887 m = moment.utc([2015, 0, i + 1, 18]);
60888 tester('dd');
60889 tester('ddd');
60890 tester('dddd');
60891 }
60892 });
b135bf1a 60893
db71a655
KM
60894 test('valid localeData', function (assert) {
60895 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
60896 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
60897 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
60898 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
60899 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
60900 });
96d0d679
KM
60901
60902 test('localeData weekdays can localeSort', function (assert) {
60903 var weekdays = moment().localeData().weekdays();
60904 var weekdaysShort = moment().localeData().weekdaysShort();
60905 var weekdaysMin = moment().localeData().weekdaysMin();
60906 var shift = moment().localeData()._week.dow;
60907 assert.deepEqual(
60908 moment().localeData().weekdays(true),
60909 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
60910 'weekdays should localeSort');
60911 assert.deepEqual(
60912 moment().localeData().weekdaysShort(true),
60913 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
60914 'weekdaysShort should localeSort');
60915 assert.deepEqual(
60916 moment().localeData().weekdaysMin(true),
60917 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
60918 'weekdaysMin should localeSort');
60919 });
db71a655 60920 }
b135bf1a 60921
db71a655 60922 /*global QUnit:false*/
d6651c21 60923
db71a655
KM
60924 function localeModule (name, lifecycle) {
60925 QUnit.module('locale:' + name, {
c58511b9 60926 beforeEach : function () {
db71a655
KM
60927 moment.locale(name);
60928 moment.createFromInputFallback = function (config) {
60929 throw new Error('input not handled by moment: ' + config._i);
60930 };
60931 setupDeprecationHandler(test, moment, 'locale');
60932 if (lifecycle && lifecycle.setup) {
60933 lifecycle.setup();
60934 }
60935 },
c58511b9 60936 afterEach : function () {
db71a655
KM
60937 moment.locale('en');
60938 teardownDeprecationHandler(test, moment, 'locale');
60939 if (lifecycle && lifecycle.teardown) {
60940 lifecycle.teardown();
60941 }
d6651c21
IC
60942 }
60943 });
db71a655
KM
60944 defineCommonLocaleTests(name, -1, -1);
60945 }
60946
60947 localeModule('ur');
60948
60949 var months = [
60950 'جنوری',
60951 'فروری',
60952 'مارچ',
60953 'اپریل',
60954 'مئی',
60955 'جون',
60956 'جولائی',
60957 'اگست',
60958 'ستمبر',
60959 'اکتوبر',
60960 'نومبر',
60961 'دسمبر'
60962 ];
60963 var days = [
60964 'اتوار',
60965 'پیر',
60966 'منگل',
60967 'بدھ',
60968 'جمعرات',
60969 'جمعہ',
60970 'ہفتہ'
60971 ];
d6651c21 60972
db71a655
KM
60973 test('parse', function (assert) {
60974 function equalTest(input, mmm, i) {
60975 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
60976 }
60977 for (var i = 0; i < 12; i++) {
60978 equalTest(months[i], 'MMM', i);
60979 equalTest(months[i], 'MMMM', i);
60980 }
60981 });
60982
60983 test('format', function (assert) {
60984 var a = [
60985 ['dddd, MMMM Do YYYY, h:mm:ss a', 'اتوار، فروری 14 2010، 3:25:50 شام'],
60986 ['ddd, hA', 'اتوار، 3شام'],
60987 ['M Mo MM MMMM MMM', '2 2 02 فروری فروری'],
60988 ['YYYY YY', '2010 10'],
60989 ['D Do DD', '14 14 14'],
60990 ['d do dddd ddd dd', '0 0 اتوار اتوار اتوار'],
60991 ['DDD DDDo DDDD', '45 45 045'],
60992 ['w wo ww', '6 6 06'],
60993 ['h hh', '3 03'],
60994 ['H HH', '15 15'],
60995 ['m mm', '25 25'],
60996 ['s ss', '50 50'],
60997 ['a A', 'شام شام'],
60998 ['[سال کا] DDDo[واں دن]', 'سال کا 45واں دن'],
60999 ['LTS', '15:25:50'],
61000 ['L', '14/02/2010'],
61001 ['LL', '14 فروری 2010'],
61002 ['LLL', '14 فروری 2010 15:25'],
61003 ['LLLL', 'اتوار، 14 فروری 2010 15:25'],
61004 ['l', '14/2/2010'],
61005 ['ll', '14 فروری 2010'],
61006 ['lll', '14 فروری 2010 15:25'],
61007 ['llll', 'اتوار، 14 فروری 2010 15:25']
61008 ],
61009 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
61010 i;
61011 for (i = 0; i < a.length; i++) {
61012 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
61013 }
61014 });
61015
61016 test('format ordinal', function (assert) {
61017 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
61018 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
61019 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
61020 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
61021 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
61022 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
61023 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
61024 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
61025 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
61026 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
61027
61028 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
61029 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
61030 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
61031 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
61032 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
61033 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
61034 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
61035 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
61036 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
61037 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
61038
61039 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
61040 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
61041 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
61042 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
61043 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
61044 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
61045 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
61046 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
61047 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
61048 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
61049
61050 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
61051 });
61052
61053 test('format month', function (assert) {
61054 for (var i = 0; i < months.length; i++) {
61055 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), months[i] + ' ' + months[i], months[i] + ' ' + months[i]);
61056 }
61057 });
61058
61059 test('format week', function (assert) {
61060 for (var i = 0; i < days.length; i++) {
61061 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), days[i] + ' ' + days[i] + ' ' + days[i], days[i] + ' ' + days[i] + ' ' + days[i]);
61062 }
61063 });
61064
61065 test('from', function (assert) {
61066 var start = moment([2007, 1, 28]);
61067 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'چند سیکنڈ', '44 seconds = چند سیکنڈ');
61068 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ایک منٹ', '45 seconds = ایک منٹ');
61069 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ایک منٹ', '89 seconds = ایک منٹ');
61070 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 منٹ', '90 seconds = 2 منٹ');
61071 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 منٹ', '44 minutes = 44 منٹ');
61072 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ایک گھنٹہ', '45 minutes = ایک گھنٹہ');
61073 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ایک گھنٹہ', '89 minutes = ایک گھنٹہ');
61074 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 گھنٹے', '90 minutes = 2 گھنٹے');
61075 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 گھنٹے', '5 hours = 5 گھنٹے');
61076 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 گھنٹے', '21 hours = 21 گھنٹے');
61077 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ایک دن', '22 hours = ایک دن');
61078 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ایک دن', '35 hours = ایک دن');
61079 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 دن', '36 hours = 2 دن');
61080 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ایک دن', '1 day = ایک دن');
61081 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 دن', '5 days = 5 دن');
61082 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 دن', '25 days = 25 دن');
61083 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ایک ماہ', '26 days = ایک ماہ');
61084 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ایک ماہ', '30 days = ایک ماہ');
61085 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ایک ماہ', '43 days = ایک ماہ');
61086 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 ماہ', '46 days = 2 ماہ');
61087 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 ماہ', '75 days = 2 ماہ');
61088 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 ماہ', '76 days = 3 ماہ');
61089 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ایک ماہ', '1 month = ایک ماہ');
61090 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 ماہ', '5 months = 5 ماہ');
61091 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ایک سال', '345 days = ایک سال');
61092 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 سال', '548 days = 2 سال');
61093 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ایک سال', '1 year = ایک سال');
61094 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 سال', '5 years = 5 سال');
61095 });
61096
61097 test('suffix', function (assert) {
61098 assert.equal(moment(30000).from(0), 'چند سیکنڈ بعد', 'prefix');
61099 assert.equal(moment(0).from(30000), 'چند سیکنڈ قبل', 'suffix');
61100 });
61101
61102 test('now from now', function (assert) {
61103 assert.equal(moment().fromNow(), 'چند سیکنڈ قبل', 'now from now should display as in the past');
61104 });
61105
61106 test('fromNow', function (assert) {
61107 assert.equal(moment().add({s: 30}).fromNow(), 'چند سیکنڈ بعد', 'in a few seconds');
61108 assert.equal(moment().add({d: 5}).fromNow(), '5 دن بعد', 'in 5 days');
61109 });
61110
61111 test('calendar day', function (assert) {
61112 var a = moment().hours(12).minutes(0).seconds(0);
61113
61114 assert.equal(moment(a).calendar(), 'آج بوقت 12:00', 'today at the same time');
61115 assert.equal(moment(a).add({m: 25}).calendar(), 'آج بوقت 12:25', 'Now plus 25 min');
61116 assert.equal(moment(a).add({h: 1}).calendar(), 'آج بوقت 13:00', 'Now plus 1 hour');
61117 assert.equal(moment(a).add({d: 1}).calendar(), 'کل بوقت 12:00', 'tomorrow at the same time');
61118 assert.equal(moment(a).subtract({h: 1}).calendar(), 'آج بوقت 11:00', 'Now minus 1 hour');
61119 assert.equal(moment(a).subtract({d: 1}).calendar(), 'گذشتہ روز بوقت 12:00', 'yesterday at the same time');
61120 });
61121
61122 test('calendar next week', function (assert) {
61123 var i, m;
61124 for (i = 2; i < 7; i++) {
61125 m = moment().add({d: i});
61126 assert.equal(m.calendar(), m.format('dddd [بوقت] LT'), 'Today + ' + i + ' days current time');
61127 m.hours(0).minutes(0).seconds(0).milliseconds(0);
61128 assert.equal(m.calendar(), m.format('dddd [بوقت] LT'), 'Today + ' + i + ' days beginning of day');
61129 m.hours(23).minutes(59).seconds(59).milliseconds(999);
61130 assert.equal(m.calendar(), m.format('dddd [بوقت] LT'), 'Today + ' + i + ' days end of day');
d6651c21 61131 }
db71a655
KM
61132 });
61133
61134 test('calendar last week', function (assert) {
61135 var i, m;
61136
61137 for (i = 2; i < 7; i++) {
61138 m = moment().subtract({d: i});
61139 assert.equal(m.calendar(), m.format('[گذشتہ] dddd [بوقت] LT'), 'Today - ' + i + ' days current time');
61140 m.hours(0).minutes(0).seconds(0).milliseconds(0);
61141 assert.equal(m.calendar(), m.format('[گذشتہ] dddd [بوقت] LT'), 'Today - ' + i + ' days beginning of day');
61142 m.hours(23).minutes(59).seconds(59).milliseconds(999);
61143 assert.equal(m.calendar(), m.format('[گذشتہ] dddd [بوقت] LT'), 'Today - ' + i + ' days end of day');
d6651c21 61144 }
db71a655 61145 });
b135bf1a 61146
db71a655
KM
61147 test('calendar all else', function (assert) {
61148 var weeksAgo = moment().subtract({w: 1}),
61149 weeksFromNow = moment().add({w: 1});
516f5f67 61150
db71a655
KM
61151 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
61152 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 61153
db71a655
KM
61154 weeksAgo = moment().subtract({w: 2});
61155 weeksFromNow = moment().add({w: 2});
c74a101d 61156
db71a655
KM
61157 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
61158 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
61159 });
61160
61161 test('weeks year starting sunday formatted', function (assert) {
61162 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52', 'Jan 1 2012 should be week 52');
61163 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1', 'Jan 2 2012 should be week 1');
61164 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1', 'Jan 8 2012 should be week 1');
61165 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2', 'Jan 9 2012 should be week 2');
61166 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2', 'Jan 15 2012 should be week 2');
61167 });
73f3c911
IC
61168
61169})));
516f5f67 61170
516f5f67 61171
c74a101d
IC
61172;(function (global, factory) {
61173 typeof exports === 'object' && typeof module !== 'undefined'
61174 && typeof require === 'function' ? factory(require('../../moment')) :
61175 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
61176 factory(global.moment)
73f3c911 61177}(this, (function (moment) { 'use strict';
c74a101d 61178
db71a655
KM
61179 function each(array, callback) {
61180 var i;
61181 for (i = 0; i < array.length; i++) {
61182 callback(array[i], i, array);
61183 }
b135bf1a
IC
61184 }
61185
c58511b9
KM
61186 function setupDeprecationHandler(test, moment$$1, scope) {
61187 test._expectedDeprecations = null;
61188 test._observedDeprecations = null;
61189 test._oldSupress = moment$$1.suppressDeprecationWarnings;
61190 moment$$1.suppressDeprecationWarnings = true;
61191 test.expectedDeprecations = function () {
61192 test._expectedDeprecations = arguments;
61193 test._observedDeprecations = [];
61194 };
61195 moment$$1.deprecationHandler = function (name, msg) {
61196 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
61197 if (deprecationId === -1) {
61198 throw new Error('Unexpected deprecation thrown name=' +
61199 name + ' msg=' + msg);
61200 }
61201 test._observedDeprecations[deprecationId] = 1;
61202 };
61203 }
61204
61205 function teardownDeprecationHandler(test, moment$$1, scope) {
61206 moment$$1.suppressDeprecationWarnings = test._oldSupress;
61207
61208 if (test._expectedDeprecations != null) {
61209 var missedDeprecations = [];
61210 each(test._expectedDeprecations, function (deprecationPattern, id) {
61211 if (test._observedDeprecations[id] !== 1) {
61212 missedDeprecations.push(deprecationPattern);
61213 }
61214 });
61215 if (missedDeprecations.length !== 0) {
61216 throw new Error('Expected deprecation warnings did not happen: ' +
61217 missedDeprecations.join(' '));
61218 }
61219 }
61220 }
61221
61222 function matchedDeprecation(name, msg, deprecations) {
61223 if (deprecations == null) {
61224 return -1;
61225 }
61226 for (var i = 0; i < deprecations.length; ++i) {
61227 if (name != null && name === deprecations[i]) {
61228 return i;
61229 }
61230 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
61231 return i;
61232 }
61233 }
61234 return -1;
61235 }
61236
61237 /*global QUnit:false*/
61238
61239 var test = QUnit.test;
61240
db71a655
KM
61241 function objectKeys(obj) {
61242 if (Object.keys) {
61243 return Object.keys(obj);
61244 } else {
61245 // IE8
61246 var res = [], i;
61247 for (i in obj) {
61248 if (obj.hasOwnProperty(i)) {
61249 res.push(i);
61250 }
b135bf1a 61251 }
db71a655 61252 return res;
b135bf1a
IC
61253 }
61254 }
61255
db71a655 61256 // Pick the first defined of two or three arguments.
73f3c911 61257
db71a655
KM
61258 function defineCommonLocaleTests(locale, options) {
61259 test('lenient day of month ordinal parsing', function (assert) {
61260 var i, ordinalStr, testMoment;
61261 for (i = 1; i <= 31; ++i) {
61262 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
61263 testMoment = moment(ordinalStr, 'YYYY MM Do');
61264 assert.equal(testMoment.year(), 2014,
61265 'lenient day of month ordinal parsing ' + i + ' year check');
61266 assert.equal(testMoment.month(), 0,
61267 'lenient day of month ordinal parsing ' + i + ' month check');
61268 assert.equal(testMoment.date(), i,
61269 'lenient day of month ordinal parsing ' + i + ' date check');
61270 }
61271 });
73f3c911 61272
db71a655
KM
61273 test('lenient day of month ordinal parsing of number', function (assert) {
61274 var i, testMoment;
61275 for (i = 1; i <= 31; ++i) {
61276 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
61277 assert.equal(testMoment.year(), 2014,
61278 'lenient day of month ordinal parsing of number ' + i + ' year check');
61279 assert.equal(testMoment.month(), 0,
61280 'lenient day of month ordinal parsing of number ' + i + ' month check');
61281 assert.equal(testMoment.date(), i,
61282 'lenient day of month ordinal parsing of number ' + i + ' date check');
61283 }
61284 });
61285
61286 test('strict day of month ordinal parsing', function (assert) {
61287 var i, ordinalStr, testMoment;
61288 for (i = 1; i <= 31; ++i) {
61289 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
61290 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
61291 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
61292 }
61293 });
61294
61295 test('meridiem invariant', function (assert) {
61296 var h, m, t1, t2;
61297 for (h = 0; h < 24; ++h) {
61298 for (m = 0; m < 60; m += 15) {
61299 t1 = moment.utc([2000, 0, 1, h, m]);
61300 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
61301 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
61302 'meridiem at ' + t1.format('HH:mm'));
61303 }
61304 }
61305 });
61306
61307 test('date format correctness', function (assert) {
61308 var data, tokens;
61309 data = moment.localeData()._longDateFormat;
61310 tokens = objectKeys(data);
61311 each(tokens, function (srchToken) {
61312 // Check each format string to make sure it does not contain any
61313 // tokens that need to be expanded.
61314 each(tokens, function (baseToken) {
61315 // strip escaped sequences
61316 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
61317 assert.equal(false, !!~format.indexOf(srchToken),
61318 'contains ' + srchToken + ' in ' + baseToken);
61319 });
61320 });
61321 });
61322
61323 test('month parsing correctness', function (assert) {
61324 var i, m;
61325
61326 if (locale === 'tr') {
61327 // I can't fix it :(
c58511b9 61328 assert.expect(0);
db71a655
KM
61329 return;
61330 }
61331 function tester(format) {
61332 var r;
61333 r = moment(m.format(format), format);
61334 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
61335 if (locale !== 'ka') {
61336 r = moment(m.format(format).toLocaleUpperCase(), format);
61337 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
61338 }
db71a655
KM
61339 r = moment(m.format(format).toLocaleLowerCase(), format);
61340 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
61341
61342 r = moment(m.format(format), format, true);
61343 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
61344 if (locale !== 'ka') {
61345 r = moment(m.format(format).toLocaleUpperCase(), format, true);
61346 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
61347 }
db71a655
KM
61348 r = moment(m.format(format).toLocaleLowerCase(), format, true);
61349 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
61350 }
61351
61352 for (i = 0; i < 12; ++i) {
61353 m = moment([2015, i, 15, 18]);
61354 tester('MMM');
61355 tester('MMM.');
61356 tester('MMMM');
61357 tester('MMMM.');
61358 }
61359 });
61360
61361 test('weekday parsing correctness', function (assert) {
61362 var i, m;
61363
96d0d679 61364 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
61365 // tr, az: There is a lower-case letter (ı), that converted to
61366 // upper then lower changes to i
61367 // ro: there is the letter ț which behaves weird under IE8
61368 // mt: letter Ħ
96d0d679 61369 // ga: month with spaces
c58511b9 61370 assert.expect(0);
db71a655
KM
61371 return;
61372 }
61373 function tester(format) {
61374 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
61375 r = moment(m.format(format), format);
61376 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
61377 if (locale !== 'ka') {
61378 r = moment(m.format(format).toLocaleUpperCase(), format);
61379 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
61380 }
db71a655
KM
61381 r = moment(m.format(format).toLocaleLowerCase(), format);
61382 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
61383 r = moment(m.format(format), format, true);
61384 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
61385 if (locale !== 'ka') {
61386 r = moment(m.format(format).toLocaleUpperCase(), format, true);
61387 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
61388 }
db71a655
KM
61389 r = moment(m.format(format).toLocaleLowerCase(), format, true);
61390 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
61391 }
61392
61393 for (i = 0; i < 7; ++i) {
61394 m = moment.utc([2015, 0, i + 1, 18]);
61395 tester('dd');
61396 tester('ddd');
61397 tester('dddd');
61398 }
61399 });
61400
61401 test('valid localeData', function (assert) {
61402 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
61403 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
61404 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
61405 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
61406 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
61407 });
96d0d679
KM
61408
61409 test('localeData weekdays can localeSort', function (assert) {
61410 var weekdays = moment().localeData().weekdays();
61411 var weekdaysShort = moment().localeData().weekdaysShort();
61412 var weekdaysMin = moment().localeData().weekdaysMin();
61413 var shift = moment().localeData()._week.dow;
61414 assert.deepEqual(
61415 moment().localeData().weekdays(true),
61416 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
61417 'weekdays should localeSort');
61418 assert.deepEqual(
61419 moment().localeData().weekdaysShort(true),
61420 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
61421 'weekdaysShort should localeSort');
61422 assert.deepEqual(
61423 moment().localeData().weekdaysMin(true),
61424 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
61425 'weekdaysMin should localeSort');
61426 });
db71a655
KM
61427 }
61428
db71a655
KM
61429 /*global QUnit:false*/
61430
db71a655
KM
61431 function localeModule (name, lifecycle) {
61432 QUnit.module('locale:' + name, {
c58511b9 61433 beforeEach : function () {
db71a655
KM
61434 moment.locale(name);
61435 moment.createFromInputFallback = function (config) {
61436 throw new Error('input not handled by moment: ' + config._i);
61437 };
61438 setupDeprecationHandler(test, moment, 'locale');
61439 if (lifecycle && lifecycle.setup) {
61440 lifecycle.setup();
61441 }
61442 },
c58511b9 61443 afterEach : function () {
db71a655
KM
61444 moment.locale('en');
61445 teardownDeprecationHandler(test, moment, 'locale');
61446 if (lifecycle && lifecycle.teardown) {
61447 lifecycle.teardown();
61448 }
61449 }
b135bf1a 61450 });
db71a655
KM
61451 defineCommonLocaleTests(name, -1, -1);
61452 }
61453
61454 localeModule('uz-latn');
61455
61456 test('parse', function (assert) {
61457 var tests = 'Yanvar Yan_Fevral Fev_Mart Mar_Aprel Apr_May May_Iyun Iyun_Iyul Iyul_Avgust Avg_Sentabr Sen_Oktabr Okt_Noyabr Noy_Dekabr Dek'.split('_'), i;
61458 function equalTest(input, mmm, i) {
61459 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
61460 }
61461 for (i = 0; i < 12; i++) {
61462 tests[i] = tests[i].split(' ');
61463 equalTest(tests[i][0], 'MMM', i);
61464 equalTest(tests[i][1], 'MMM', i);
61465 equalTest(tests[i][0], 'MMMM', i);
61466 equalTest(tests[i][1], 'MMMM', i);
61467 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
61468 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
61469 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
61470 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
61471 }
61472 });
61473
61474 test('format', function (assert) {
61475 var a = [
61476 ['dddd, Do-MMMM YYYY, h:mm:ss', 'Yakshanba, 14-Fevral 2010, 3:25:50'],
61477 ['ddd, h:mm', 'Yak, 3:25'],
61478 ['M Mo MM MMMM MMM', '2 2 02 Fevral Fev'],
61479 ['YYYY YY', '2010 10'],
61480 ['D Do DD', '14 14 14'],
61481 ['d do dddd ddd dd', '0 0 Yakshanba Yak Ya'],
61482 ['DDD DDDo DDDD', '45 45 045'],
61483 ['w wo ww', '7 7 07'],
61484 ['h hh', '3 03'],
61485 ['H HH', '15 15'],
61486 ['m mm', '25 25'],
61487 ['s ss', '50 50'],
61488 ['a A', 'pm PM'],
61489 ['[yilning] DDDo-[kuni]', 'yilning 45-kuni'],
61490 ['LTS', '15:25:50'],
61491 ['L', '14/02/2010'],
61492 ['LL', '14 Fevral 2010'],
61493 ['LLL', '14 Fevral 2010 15:25'],
61494 ['LLLL', '14 Fevral 2010, Yakshanba 15:25'],
61495 ['l', '14/2/2010'],
61496 ['ll', '14 Fev 2010'],
61497 ['lll', '14 Fev 2010 15:25'],
61498 ['llll', '14 Fev 2010, Yak 15:25']
61499 ],
61500 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
61501 i;
61502 for (i = 0; i < a.length; i++) {
61503 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
61504 }
61505 });
61506
61507 test('format ordinal', function (assert) {
61508 assert.equal(moment([2016, 0, 1]).format('DDDo'), '1', '1');
61509 assert.equal(moment([2016, 0, 2]).format('DDDo'), '2', '2');
61510 assert.equal(moment([2016, 0, 3]).format('DDDo'), '3', '3');
61511 assert.equal(moment([2016, 0, 4]).format('DDDo'), '4', '4');
61512 assert.equal(moment([2016, 0, 5]).format('DDDo'), '5', '5');
61513 assert.equal(moment([2016, 0, 6]).format('DDDo'), '6', '6');
61514 assert.equal(moment([2016, 0, 7]).format('DDDo'), '7', '7');
61515 assert.equal(moment([2016, 0, 8]).format('DDDo'), '8', '8');
61516 assert.equal(moment([2016, 0, 9]).format('DDDo'), '9', '9');
61517 assert.equal(moment([2016, 0, 10]).format('DDDo'), '10', '10');
61518
61519 assert.equal(moment([2016, 0, 11]).format('DDDo'), '11', '11');
61520 assert.equal(moment([2016, 0, 12]).format('DDDo'), '12', '12');
61521 assert.equal(moment([2016, 0, 13]).format('DDDo'), '13', '13');
61522 assert.equal(moment([2016, 0, 14]).format('DDDo'), '14', '14');
61523 assert.equal(moment([2016, 0, 15]).format('DDDo'), '15', '15');
61524 assert.equal(moment([2016, 0, 16]).format('DDDo'), '16', '16');
61525 assert.equal(moment([2016, 0, 17]).format('DDDo'), '17', '17');
61526 assert.equal(moment([2016, 0, 18]).format('DDDo'), '18', '18');
61527 assert.equal(moment([2016, 0, 19]).format('DDDo'), '19', '19');
61528 assert.equal(moment([2016, 0, 20]).format('DDDo'), '20', '20');
61529
61530 assert.equal(moment([2016, 0, 21]).format('DDDo'), '21', '21');
61531 assert.equal(moment([2016, 0, 22]).format('DDDo'), '22', '22');
61532 assert.equal(moment([2016, 0, 23]).format('DDDo'), '23', '23');
61533 assert.equal(moment([2016, 0, 24]).format('DDDo'), '24', '24');
61534 assert.equal(moment([2016, 0, 25]).format('DDDo'), '25', '25');
61535 assert.equal(moment([2016, 0, 26]).format('DDDo'), '26', '26');
61536 assert.equal(moment([2016, 0, 27]).format('DDDo'), '27', '27');
61537 assert.equal(moment([2016, 0, 28]).format('DDDo'), '28', '28');
61538 assert.equal(moment([2016, 0, 29]).format('DDDo'), '29', '29');
61539 assert.equal(moment([2016, 0, 30]).format('DDDo'), '30', '30');
61540
61541 assert.equal(moment([2016, 0, 31]).format('DDDo'), '31', '31');
61542 });
61543
61544 test('format month', function (assert) {
61545 var expected = 'Yanvar Yan_Fevral Fev_Mart Mar_Aprel Apr_May May_Iyun Iyun_Iyul Iyul_Avgust Avg_Sentabr Sen_Oktabr Okt_Noyabr Noy_Dekabr Dek'.split('_'), i;
61546 for (i = 0; i < expected.length; i++) {
61547 assert.equal(moment([2016, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
61548 }
61549 });
61550
61551 test('format week', function (assert) {
61552 var expected = 'Yakshanba Yak Ya_Dushanba Dush Du_Seshanba Sesh Se_Chorshanba Chor Cho_Payshanba Pay Pa_Juma Jum Ju_Shanba Shan Sha'.split('_'), i;
61553 for (i = 0; i < expected.length; i++) {
61554 assert.equal(moment([2016, 0, 3 + i]).format('dddd ddd dd'), expected[i], expected[i]);
61555 }
61556 });
61557
61558 test('from', function (assert) {
61559 var start = moment([2017, 1, 28]);
61560 assert.equal(start.from(moment([2017, 1, 28]).add({s: 44}), true), 'soniya', '44 soniya = soniya');
61561 assert.equal(start.from(moment([2017, 1, 28]).add({s: 45}), true), 'bir daqiqa', '45 soniya = bir daqiqa');
61562 assert.equal(start.from(moment([2017, 1, 28]).add({s: 89}), true), 'bir daqiqa', '89 soniya = bir daqiqa');
61563 assert.equal(start.from(moment([2017, 1, 28]).add({s: 90}), true), '2 daqiqa', '90 soniya = 2 daqiqa');
61564 assert.equal(start.from(moment([2017, 1, 28]).add({m: 44}), true), '44 daqiqa', '44 daqiqa = 44 daqiqa');
61565 assert.equal(start.from(moment([2017, 1, 28]).add({m: 45}), true), 'bir soat', '45 minut = bir soat');
61566 assert.equal(start.from(moment([2017, 1, 28]).add({m: 89}), true), 'bir soat', '89 minut = bir soat');
61567 assert.equal(start.from(moment([2017, 1, 28]).add({m: 90}), true), '2 soat', '90 minut = 2 soat');
61568 assert.equal(start.from(moment([2017, 1, 28]).add({h: 5}), true), '5 soat', '5 soat = 5 soat');
61569 assert.equal(start.from(moment([2017, 1, 28]).add({h: 21}), true), '21 soat', '21 soat = 21 soat');
61570 assert.equal(start.from(moment([2017, 1, 28]).add({h: 22}), true), 'bir kun', '22 soat = bir kun');
61571 assert.equal(start.from(moment([2017, 1, 28]).add({h: 35}), true), 'bir kun', '35 soat = bir kun');
61572 assert.equal(start.from(moment([2017, 1, 28]).add({h: 36}), true), '2 kun', '36 soat = 2 kun');
61573 assert.equal(start.from(moment([2017, 1, 28]).add({d: 1}), true), 'bir kun', '1 kun = 1 kun');
61574 assert.equal(start.from(moment([2017, 1, 28]).add({d: 5}), true), '5 kun', '5 kun = 5 kun');
61575 assert.equal(start.from(moment([2017, 1, 28]).add({d: 25}), true), '25 kun', '25 kun = 25 kun');
61576 assert.equal(start.from(moment([2017, 1, 28]).add({d: 26}), true), 'bir oy', '26 kun = bir oy');
61577 assert.equal(start.from(moment([2017, 1, 28]).add({d: 30}), true), 'bir oy', '30 kun = bir oy');
61578 assert.equal(start.from(moment([2017, 1, 28]).add({d: 43}), true), 'bir oy', '45 kun = bir oy');
61579 assert.equal(start.from(moment([2017, 1, 28]).add({d: 46}), true), '2 oy', '46 kun = 2 oy');
61580 assert.equal(start.from(moment([2017, 1, 28]).add({d: 74}), true), '2 oy', '75 kun = 2 oy');
61581 assert.equal(start.from(moment([2017, 1, 28]).add({d: 76}), true), '3 oy', '76 kun = 3 oy');
61582 assert.equal(start.from(moment([2017, 1, 28]).add({M: 1}), true), 'bir oy', 'bir oy = bir oy');
61583 assert.equal(start.from(moment([2017, 1, 28]).add({M: 5}), true), '5 oy', '5 oy = 5 oy');
61584 assert.equal(start.from(moment([2017, 1, 28]).add({d: 345}), true), 'bir yil', '345 kun = bir yil');
61585 assert.equal(start.from(moment([2017, 1, 28]).add({d: 548}), true), '2 yil', '548 kun = 2 yil');
61586 assert.equal(start.from(moment([2017, 1, 28]).add({y: 1}), true), 'bir yil', '1 yil = bir yil');
61587 assert.equal(start.from(moment([2017, 1, 28]).add({y: 5}), true), '5 yil', '5 yil = 5 yil');
61588 });
61589
61590 test('suffix', function (assert) {
61591 assert.equal(moment(30000).from(0), 'Yaqin soniya ichida', 'prefix');
61592 assert.equal(moment(0).from(30000), 'Bir necha soniya oldin', 'suffix');
61593 });
61594
61595 test('now from now', function (assert) {
61596 assert.equal(moment().fromNow(), 'Bir necha soniya oldin', 'now from now should display as in the past');
61597 });
61598
61599 test('fromNow', function (assert) {
61600 assert.equal(moment().add({s: 30}).fromNow(), 'Yaqin soniya ichida', 'in a few seconds');
61601 assert.equal(moment().add({d: 5}).fromNow(), 'Yaqin 5 kun ichida', 'in 5 days');
61602 });
61603
61604 test('calendar day', function (assert) {
61605 var a = moment().hours(12).minutes(0).seconds(0);
61606
61607 assert.equal(moment(a).calendar(), 'Bugun soat 12:00 da', 'today at the same time');
61608 assert.equal(moment(a).add({m: 25}).calendar(), 'Bugun soat 12:25 da', 'Now plus 25 min');
61609 assert.equal(moment(a).add({h: 1}).calendar(), 'Bugun soat 13:00 da', 'Now plus 1 hour');
61610 assert.equal(moment(a).add({d: 1}).calendar(), 'Ertaga 12:00 da', 'tomorrow at the same time');
61611 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Bugun soat 11:00 da', 'Now minus 1 hour');
61612 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Kecha soat 12:00 da', 'yesterday at the same time');
61613 });
61614
61615 test('calendar next week', function (assert) {
61616 var i, m;
61617 for (i = 2; i < 7; i++) {
61618 m = moment().add({d: i});
61619 assert.equal(m.calendar(), m.format('dddd [kuni soat] LT [da]'), 'Today + ' + i + ' days current time');
61620 m.hours(0).minutes(0).seconds(0).milliseconds(0);
61621 assert.equal(m.calendar(), m.format('dddd [kuni soat] LT [da]'), 'Today + ' + i + ' days beginning of day');
61622 m.hours(23).minutes(59).seconds(59).milliseconds(999);
61623 assert.equal(m.calendar(), m.format('dddd [kuni soat] LT [da]'), 'Today + ' + i + ' days end of day');
61624 }
73f3c911 61625 });
b135bf1a 61626
db71a655 61627 test('calendar last week', function (assert) {
73f3c911 61628 var i, m;
b135bf1a 61629
db71a655
KM
61630 for (i = 2; i < 7; i++) {
61631 m = moment().subtract({d: i});
61632 assert.equal(m.calendar(), m.format('[O\'tgan] dddd [kuni soat] LT [da]'), 'Today - ' + i + ' days current time');
61633 m.hours(0).minutes(0).seconds(0).milliseconds(0);
61634 assert.equal(m.calendar(), m.format('[O\'tgan] dddd [kuni soat] LT [da]'), 'Today - ' + i + ' days beginning of day');
61635 m.hours(23).minutes(59).seconds(59).milliseconds(999);
61636 assert.equal(m.calendar(), m.format('[O\'tgan] dddd [kuni soat] LT [da]'), 'Today - ' + i + ' days end of day');
73f3c911 61637 }
db71a655 61638 });
b135bf1a 61639
db71a655
KM
61640 test('calendar all else', function (assert) {
61641 var weeksAgo = moment().subtract({w: 1}),
61642 weeksFromNow = moment().add({w: 1});
d6651c21 61643
db71a655
KM
61644 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
61645 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
61646
61647 weeksAgo = moment().subtract({w: 2});
61648 weeksFromNow = moment().add({w: 2});
61649
61650 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
61651 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
73f3c911 61652 });
d6651c21 61653
db71a655
KM
61654 test('weeks year starting sunday formatted', function (assert) {
61655 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 52');
61656 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2', 'Jan 2 2012 should be week 1');
61657 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 1');
61658 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3', 'Jan 9 2012 should be week 2');
61659 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', 'Jan 15 2012 should be week 2');
61660 });
d6651c21 61661
db71a655
KM
61662})));
61663
61664
61665;(function (global, factory) {
61666 typeof exports === 'object' && typeof module !== 'undefined'
61667 && typeof require === 'function' ? factory(require('../../moment')) :
61668 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
61669 factory(global.moment)
61670}(this, (function (moment) { 'use strict';
61671
61672 function each(array, callback) {
61673 var i;
61674 for (i = 0; i < array.length; i++) {
61675 callback(array[i], i, array);
d6651c21 61676 }
db71a655 61677 }
b135bf1a 61678
c58511b9
KM
61679 function setupDeprecationHandler(test, moment$$1, scope) {
61680 test._expectedDeprecations = null;
61681 test._observedDeprecations = null;
61682 test._oldSupress = moment$$1.suppressDeprecationWarnings;
61683 moment$$1.suppressDeprecationWarnings = true;
61684 test.expectedDeprecations = function () {
61685 test._expectedDeprecations = arguments;
61686 test._observedDeprecations = [];
61687 };
61688 moment$$1.deprecationHandler = function (name, msg) {
61689 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
61690 if (deprecationId === -1) {
61691 throw new Error('Unexpected deprecation thrown name=' +
61692 name + ' msg=' + msg);
61693 }
61694 test._observedDeprecations[deprecationId] = 1;
61695 };
61696 }
61697
61698 function teardownDeprecationHandler(test, moment$$1, scope) {
61699 moment$$1.suppressDeprecationWarnings = test._oldSupress;
61700
61701 if (test._expectedDeprecations != null) {
61702 var missedDeprecations = [];
61703 each(test._expectedDeprecations, function (deprecationPattern, id) {
61704 if (test._observedDeprecations[id] !== 1) {
61705 missedDeprecations.push(deprecationPattern);
61706 }
61707 });
61708 if (missedDeprecations.length !== 0) {
61709 throw new Error('Expected deprecation warnings did not happen: ' +
61710 missedDeprecations.join(' '));
61711 }
61712 }
61713 }
61714
61715 function matchedDeprecation(name, msg, deprecations) {
61716 if (deprecations == null) {
61717 return -1;
61718 }
61719 for (var i = 0; i < deprecations.length; ++i) {
61720 if (name != null && name === deprecations[i]) {
61721 return i;
61722 }
61723 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
61724 return i;
61725 }
61726 }
61727 return -1;
61728 }
61729
61730 /*global QUnit:false*/
61731
61732 var test = QUnit.test;
61733
db71a655
KM
61734 function objectKeys(obj) {
61735 if (Object.keys) {
61736 return Object.keys(obj);
61737 } else {
61738 // IE8
61739 var res = [], i;
61740 for (i in obj) {
61741 if (obj.hasOwnProperty(i)) {
61742 res.push(i);
61743 }
61744 }
61745 return res;
73f3c911 61746 }
db71a655 61747 }
c74a101d 61748
db71a655 61749 // Pick the first defined of two or three arguments.
c74a101d 61750
db71a655
KM
61751 function defineCommonLocaleTests(locale, options) {
61752 test('lenient day of month ordinal parsing', function (assert) {
61753 var i, ordinalStr, testMoment;
61754 for (i = 1; i <= 31; ++i) {
61755 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
61756 testMoment = moment(ordinalStr, 'YYYY MM Do');
61757 assert.equal(testMoment.year(), 2014,
61758 'lenient day of month ordinal parsing ' + i + ' year check');
61759 assert.equal(testMoment.month(), 0,
61760 'lenient day of month ordinal parsing ' + i + ' month check');
61761 assert.equal(testMoment.date(), i,
61762 'lenient day of month ordinal parsing ' + i + ' date check');
c74a101d
IC
61763 }
61764 });
db71a655
KM
61765
61766 test('lenient day of month ordinal parsing of number', function (assert) {
61767 var i, testMoment;
61768 for (i = 1; i <= 31; ++i) {
61769 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
61770 assert.equal(testMoment.year(), 2014,
61771 'lenient day of month ordinal parsing of number ' + i + ' year check');
61772 assert.equal(testMoment.month(), 0,
61773 'lenient day of month ordinal parsing of number ' + i + ' month check');
61774 assert.equal(testMoment.date(), i,
61775 'lenient day of month ordinal parsing of number ' + i + ' date check');
61776 }
61777 });
61778
61779 test('strict day of month ordinal parsing', function (assert) {
61780 var i, ordinalStr, testMoment;
61781 for (i = 1; i <= 31; ++i) {
61782 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
61783 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
61784 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
61785 }
61786 });
61787
61788 test('meridiem invariant', function (assert) {
61789 var h, m, t1, t2;
61790 for (h = 0; h < 24; ++h) {
61791 for (m = 0; m < 60; m += 15) {
61792 t1 = moment.utc([2000, 0, 1, h, m]);
61793 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
61794 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
61795 'meridiem at ' + t1.format('HH:mm'));
61796 }
61797 }
61798 });
61799
61800 test('date format correctness', function (assert) {
61801 var data, tokens;
61802 data = moment.localeData()._longDateFormat;
61803 tokens = objectKeys(data);
61804 each(tokens, function (srchToken) {
61805 // Check each format string to make sure it does not contain any
61806 // tokens that need to be expanded.
61807 each(tokens, function (baseToken) {
61808 // strip escaped sequences
61809 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
61810 assert.equal(false, !!~format.indexOf(srchToken),
61811 'contains ' + srchToken + ' in ' + baseToken);
61812 });
61813 });
61814 });
61815
61816 test('month parsing correctness', function (assert) {
61817 var i, m;
61818
61819 if (locale === 'tr') {
61820 // I can't fix it :(
c58511b9 61821 assert.expect(0);
db71a655
KM
61822 return;
61823 }
61824 function tester(format) {
61825 var r;
61826 r = moment(m.format(format), format);
61827 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
61828 if (locale !== 'ka') {
61829 r = moment(m.format(format).toLocaleUpperCase(), format);
61830 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
61831 }
db71a655
KM
61832 r = moment(m.format(format).toLocaleLowerCase(), format);
61833 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
61834
61835 r = moment(m.format(format), format, true);
61836 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
61837 if (locale !== 'ka') {
61838 r = moment(m.format(format).toLocaleUpperCase(), format, true);
61839 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
61840 }
db71a655
KM
61841 r = moment(m.format(format).toLocaleLowerCase(), format, true);
61842 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
61843 }
61844
61845 for (i = 0; i < 12; ++i) {
61846 m = moment([2015, i, 15, 18]);
61847 tester('MMM');
61848 tester('MMM.');
61849 tester('MMMM');
61850 tester('MMMM.');
61851 }
61852 });
61853
61854 test('weekday parsing correctness', function (assert) {
61855 var i, m;
61856
96d0d679 61857 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
61858 // tr, az: There is a lower-case letter (ı), that converted to
61859 // upper then lower changes to i
61860 // ro: there is the letter ț which behaves weird under IE8
61861 // mt: letter Ħ
96d0d679 61862 // ga: month with spaces
c58511b9 61863 assert.expect(0);
db71a655
KM
61864 return;
61865 }
61866 function tester(format) {
61867 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
61868 r = moment(m.format(format), format);
61869 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
61870 if (locale !== 'ka') {
61871 r = moment(m.format(format).toLocaleUpperCase(), format);
61872 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
61873 }
db71a655
KM
61874 r = moment(m.format(format).toLocaleLowerCase(), format);
61875 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
61876 r = moment(m.format(format), format, true);
61877 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
61878 if (locale !== 'ka') {
61879 r = moment(m.format(format).toLocaleUpperCase(), format, true);
61880 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
61881 }
db71a655
KM
61882 r = moment(m.format(format).toLocaleLowerCase(), format, true);
61883 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
61884 }
61885
61886 for (i = 0; i < 7; ++i) {
61887 m = moment.utc([2015, 0, i + 1, 18]);
61888 tester('dd');
61889 tester('ddd');
61890 tester('dddd');
61891 }
61892 });
61893
61894 test('valid localeData', function (assert) {
61895 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
61896 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
61897 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
61898 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
61899 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
61900 });
96d0d679
KM
61901
61902 test('localeData weekdays can localeSort', function (assert) {
61903 var weekdays = moment().localeData().weekdays();
61904 var weekdaysShort = moment().localeData().weekdaysShort();
61905 var weekdaysMin = moment().localeData().weekdaysMin();
61906 var shift = moment().localeData()._week.dow;
61907 assert.deepEqual(
61908 moment().localeData().weekdays(true),
61909 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
61910 'weekdays should localeSort');
61911 assert.deepEqual(
61912 moment().localeData().weekdaysShort(true),
61913 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
61914 'weekdaysShort should localeSort');
61915 assert.deepEqual(
61916 moment().localeData().weekdaysMin(true),
61917 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
61918 'weekdaysMin should localeSort');
61919 });
c74a101d
IC
61920 }
61921
db71a655 61922 /*global QUnit:false*/
c74a101d 61923
db71a655
KM
61924 function localeModule (name, lifecycle) {
61925 QUnit.module('locale:' + name, {
c58511b9 61926 beforeEach : function () {
db71a655
KM
61927 moment.locale(name);
61928 moment.createFromInputFallback = function (config) {
61929 throw new Error('input not handled by moment: ' + config._i);
61930 };
61931 setupDeprecationHandler(test, moment, 'locale');
61932 if (lifecycle && lifecycle.setup) {
61933 lifecycle.setup();
61934 }
61935 },
c58511b9 61936 afterEach : function () {
db71a655
KM
61937 moment.locale('en');
61938 teardownDeprecationHandler(test, moment, 'locale');
61939 if (lifecycle && lifecycle.teardown) {
61940 lifecycle.teardown();
61941 }
73f3c911 61942 }
db71a655
KM
61943 });
61944 defineCommonLocaleTests(name, -1, -1);
61945 }
61946
61947 localeModule('uz');
61948
61949 test('parse', function (assert) {
61950 var tests = 'январ янв_феврал фев_март мар_апрел апр_май май_июн июн_июл июл_август авг_сентябр сен_октябр окт_ноябр ноя_декабр дек'.split('_'), i;
61951 function equalTest(input, mmm, i) {
61952 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
61953 }
61954 for (i = 0; i < 12; i++) {
61955 tests[i] = tests[i].split(' ');
61956 equalTest(tests[i][0], 'MMM', i);
61957 equalTest(tests[i][1], 'MMM', i);
61958 equalTest(tests[i][0], 'MMMM', i);
61959 equalTest(tests[i][1], 'MMMM', i);
61960 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
61961 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
61962 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
61963 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
61964 }
61965 });
61966
61967 test('format', function (assert) {
61968 var a = [
61969 ['dddd, Do-MMMM YYYY, h:mm:ss', 'Якшанба, 14-феврал 2010, 3:25:50'],
61970 ['ddd, h:mm', 'Якш, 3:25'],
61971 ['M Mo MM MMMM MMM', '2 2 02 феврал фев'],
61972 ['YYYY YY', '2010 10'],
61973 ['D Do DD', '14 14 14'],
61974 ['d do dddd ddd dd', '0 0 Якшанба Якш Як'],
61975 ['DDD DDDo DDDD', '45 45 045'],
61976 ['w wo ww', '7 7 07'],
61977 ['h hh', '3 03'],
61978 ['H HH', '15 15'],
61979 ['m mm', '25 25'],
61980 ['s ss', '50 50'],
61981 ['a A', 'pm PM'],
61982 ['[йилнинг] DDDo-[куни]', 'йилнинг 45-куни'],
61983 ['LTS', '15:25:50'],
61984 ['L', '14/02/2010'],
61985 ['LL', '14 феврал 2010'],
61986 ['LLL', '14 феврал 2010 15:25'],
61987 ['LLLL', '14 феврал 2010, Якшанба 15:25'],
61988 ['l', '14/2/2010'],
61989 ['ll', '14 фев 2010'],
61990 ['lll', '14 фев 2010 15:25'],
61991 ['llll', '14 фев 2010, Якш 15:25']
61992 ],
61993 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
61994 i;
61995 for (i = 0; i < a.length; i++) {
61996 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
61997 }
61998 });
61999
62000 test('format ordinal', function (assert) {
62001 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
62002 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
62003 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
62004 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
62005 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
62006 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
62007 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
62008 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
62009 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
62010 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
62011
62012 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
62013 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
62014 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
62015 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
62016 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
62017 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
62018 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
62019 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
62020 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
62021 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
62022
62023 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
62024 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
62025 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
62026 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
62027 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
62028 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
62029 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
62030 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
62031 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
62032 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
62033
62034 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
62035 });
62036
62037 test('format month', function (assert) {
62038 var expected = 'январ янв_феврал фев_март мар_апрел апр_май май_июн июн_июл июл_август авг_сентябр сен_октябр окт_ноябр ноя_декабр дек'.split('_'), i;
62039 for (i = 0; i < expected.length; i++) {
62040 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
62041 }
62042 });
62043
62044 test('format week', function (assert) {
62045 var expected = 'Якшанба Якш Як_Душанба Душ Ду_Сешанба Сеш Се_Чоршанба Чор Чо_Пайшанба Пай Па_Жума Жум Жу_Шанба Шан Ша'.split('_'), i;
62046 for (i = 0; i < expected.length; i++) {
62047 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
62048 }
62049 });
62050
62051 test('from', function (assert) {
62052 var start = moment([2007, 1, 28]);
62053 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'фурсат', '44 секунд = фурсат');
62054 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'бир дакика', '45 секунд = бир дакика');
62055 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'бир дакика', '89 секунд = бир дакика');
62056 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 дакика', '90 секунд = 2 дакика');
62057 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 дакика', '44 дакика = 44 дакика');
62058 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'бир соат', '45 минут = бир соат');
62059 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'бир соат', '89 minutes = an hour');
62060 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 соат', '90 минут = 2 соат');
62061 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 соат', '5 соат = 5 соат');
62062 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 соат', '21 соат = 21 соат');
62063 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'бир кун', '22 соат = бир кун');
62064 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'бир кун', '35 соат = бир кун');
62065 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 кун', '36 соат = 2 кун');
62066 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'бир кун', '1 кун = 1 кун');
62067 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 кун', '5 кун = 5 кун');
62068 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 кун', '25 кун = 25 кун');
62069 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'бир ой', '26 кун = бир ой');
62070 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'бир ой', '30 кун = бир ой');
62071 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'бир ой', '45 кун = бир ой');
62072 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 ой', '46 кун = 2 ой');
62073 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 ой', '75 кун = 2 ой');
62074 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 ой', '76 кун = 3 ой');
62075 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'бир ой', 'бир ой = бир ой');
62076 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 ой', '5 ой = 5 ой');
62077 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'бир йил', '345 кун = бир йил');
62078 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 йил', '548 кун = 2 йил');
62079 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'бир йил', '1 йил = бир йил');
62080 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 йил', '5 йил = 5 йил');
62081 });
62082
62083 test('suffix', function (assert) {
62084 assert.equal(moment(30000).from(0), 'Якин фурсат ичида', 'prefix');
62085 assert.equal(moment(0).from(30000), 'Бир неча фурсат олдин', 'suffix');
62086 });
62087
62088 test('now from now', function (assert) {
62089 assert.equal(moment().fromNow(), 'Бир неча фурсат олдин', 'now from now should display as in the past');
62090 });
62091
62092 test('fromNow', function (assert) {
62093 assert.equal(moment().add({s: 30}).fromNow(), 'Якин фурсат ичида', 'in a few seconds');
62094 assert.equal(moment().add({d: 5}).fromNow(), 'Якин 5 кун ичида', 'in 5 days');
62095 });
62096
62097 test('calendar day', function (assert) {
62098 var a = moment().hours(12).minutes(0).seconds(0);
62099
62100 assert.equal(moment(a).calendar(), 'Бугун соат 12:00 да', 'today at the same time');
62101 assert.equal(moment(a).add({m: 25}).calendar(), 'Бугун соат 12:25 да', 'Now plus 25 min');
62102 assert.equal(moment(a).add({h: 1}).calendar(), 'Бугун соат 13:00 да', 'Now plus 1 hour');
62103 assert.equal(moment(a).add({d: 1}).calendar(), 'Эртага 12:00 да', 'tomorrow at the same time');
62104 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Бугун соат 11:00 да', 'Now minus 1 hour');
62105 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Кеча соат 12:00 да', 'yesterday at the same time');
62106 });
62107
62108 test('calendar next week', function (assert) {
62109 var i, m;
62110 for (i = 2; i < 7; i++) {
62111 m = moment().add({d: i});
62112 assert.equal(m.calendar(), m.format('dddd [куни соат] LT [да]'), 'Today + ' + i + ' days current time');
62113 m.hours(0).minutes(0).seconds(0).milliseconds(0);
62114 assert.equal(m.calendar(), m.format('dddd [куни соат] LT [да]'), 'Today + ' + i + ' days beginning of day');
62115 m.hours(23).minutes(59).seconds(59).milliseconds(999);
62116 assert.equal(m.calendar(), m.format('dddd [куни соат] LT [да]'), 'Today + ' + i + ' days end of day');
62117 }
62118 });
62119
62120 test('calendar last week', function (assert) {
62121 var i, m;
62122
62123 for (i = 2; i < 7; i++) {
62124 m = moment().subtract({d: i});
62125 assert.equal(m.calendar(), m.format('[Утган] dddd [куни соат] LT [да]'), 'Today - ' + i + ' days current time');
62126 m.hours(0).minutes(0).seconds(0).milliseconds(0);
62127 assert.equal(m.calendar(), m.format('[Утган] dddd [куни соат] LT [да]'), 'Today - ' + i + ' days beginning of day');
62128 m.hours(23).minutes(59).seconds(59).milliseconds(999);
62129 assert.equal(m.calendar(), m.format('[Утган] dddd [куни соат] LT [да]'), 'Today - ' + i + ' days end of day');
62130 }
62131 });
62132
62133 test('calendar all else', function (assert) {
62134 var weeksAgo = moment().subtract({w: 1}),
62135 weeksFromNow = moment().add({w: 1});
62136
62137 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
62138 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
62139
62140 weeksAgo = moment().subtract({w: 2});
62141 weeksFromNow = moment().add({w: 2});
62142
62143 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
62144 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
62145 });
62146
62147 test('weeks year starting sunday formatted', function (assert) {
62148 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 52');
62149 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2', 'Jan 2 2012 should be week 1');
62150 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 1');
62151 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3', 'Jan 9 2012 should be week 2');
62152 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', 'Jan 15 2012 should be week 2');
62153 });
73f3c911
IC
62154
62155})));
62156
c74a101d
IC
62157
62158;(function (global, factory) {
62159 typeof exports === 'object' && typeof module !== 'undefined'
62160 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
62161 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
62162 factory(global.moment)
73f3c911 62163}(this, (function (moment) { 'use strict';
516f5f67 62164
db71a655
KM
62165 function each(array, callback) {
62166 var i;
62167 for (i = 0; i < array.length; i++) {
62168 callback(array[i], i, array);
62169 }
b135bf1a
IC
62170 }
62171
c58511b9
KM
62172 function setupDeprecationHandler(test, moment$$1, scope) {
62173 test._expectedDeprecations = null;
62174 test._observedDeprecations = null;
62175 test._oldSupress = moment$$1.suppressDeprecationWarnings;
62176 moment$$1.suppressDeprecationWarnings = true;
62177 test.expectedDeprecations = function () {
62178 test._expectedDeprecations = arguments;
62179 test._observedDeprecations = [];
62180 };
62181 moment$$1.deprecationHandler = function (name, msg) {
62182 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
62183 if (deprecationId === -1) {
62184 throw new Error('Unexpected deprecation thrown name=' +
62185 name + ' msg=' + msg);
62186 }
62187 test._observedDeprecations[deprecationId] = 1;
62188 };
62189 }
62190
62191 function teardownDeprecationHandler(test, moment$$1, scope) {
62192 moment$$1.suppressDeprecationWarnings = test._oldSupress;
62193
62194 if (test._expectedDeprecations != null) {
62195 var missedDeprecations = [];
62196 each(test._expectedDeprecations, function (deprecationPattern, id) {
62197 if (test._observedDeprecations[id] !== 1) {
62198 missedDeprecations.push(deprecationPattern);
62199 }
62200 });
62201 if (missedDeprecations.length !== 0) {
62202 throw new Error('Expected deprecation warnings did not happen: ' +
62203 missedDeprecations.join(' '));
62204 }
62205 }
62206 }
62207
62208 function matchedDeprecation(name, msg, deprecations) {
62209 if (deprecations == null) {
62210 return -1;
62211 }
62212 for (var i = 0; i < deprecations.length; ++i) {
62213 if (name != null && name === deprecations[i]) {
62214 return i;
62215 }
62216 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
62217 return i;
62218 }
62219 }
62220 return -1;
62221 }
62222
62223 /*global QUnit:false*/
62224
62225 var test = QUnit.test;
62226
db71a655
KM
62227 function objectKeys(obj) {
62228 if (Object.keys) {
62229 return Object.keys(obj);
62230 } else {
62231 // IE8
62232 var res = [], i;
62233 for (i in obj) {
62234 if (obj.hasOwnProperty(i)) {
62235 res.push(i);
62236 }
b135bf1a 62237 }
db71a655 62238 return res;
b135bf1a 62239 }
b135bf1a
IC
62240 }
62241
db71a655 62242 // Pick the first defined of two or three arguments.
b135bf1a 62243
db71a655
KM
62244 function defineCommonLocaleTests(locale, options) {
62245 test('lenient day of month ordinal parsing', function (assert) {
62246 var i, ordinalStr, testMoment;
62247 for (i = 1; i <= 31; ++i) {
62248 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
62249 testMoment = moment(ordinalStr, 'YYYY MM Do');
62250 assert.equal(testMoment.year(), 2014,
62251 'lenient day of month ordinal parsing ' + i + ' year check');
62252 assert.equal(testMoment.month(), 0,
62253 'lenient day of month ordinal parsing ' + i + ' month check');
62254 assert.equal(testMoment.date(), i,
62255 'lenient day of month ordinal parsing ' + i + ' date check');
62256 }
62257 });
b135bf1a 62258
db71a655
KM
62259 test('lenient day of month ordinal parsing of number', function (assert) {
62260 var i, testMoment;
62261 for (i = 1; i <= 31; ++i) {
62262 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
62263 assert.equal(testMoment.year(), 2014,
62264 'lenient day of month ordinal parsing of number ' + i + ' year check');
62265 assert.equal(testMoment.month(), 0,
62266 'lenient day of month ordinal parsing of number ' + i + ' month check');
62267 assert.equal(testMoment.date(), i,
62268 'lenient day of month ordinal parsing of number ' + i + ' date check');
62269 }
62270 });
b135bf1a 62271
db71a655
KM
62272 test('strict day of month ordinal parsing', function (assert) {
62273 var i, ordinalStr, testMoment;
62274 for (i = 1; i <= 31; ++i) {
62275 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
62276 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
62277 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
62278 }
62279 });
b135bf1a 62280
db71a655
KM
62281 test('meridiem invariant', function (assert) {
62282 var h, m, t1, t2;
62283 for (h = 0; h < 24; ++h) {
62284 for (m = 0; m < 60; m += 15) {
62285 t1 = moment.utc([2000, 0, 1, h, m]);
62286 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
62287 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
62288 'meridiem at ' + t1.format('HH:mm'));
62289 }
62290 }
62291 });
62292
62293 test('date format correctness', function (assert) {
62294 var data, tokens;
62295 data = moment.localeData()._longDateFormat;
62296 tokens = objectKeys(data);
62297 each(tokens, function (srchToken) {
62298 // Check each format string to make sure it does not contain any
62299 // tokens that need to be expanded.
62300 each(tokens, function (baseToken) {
62301 // strip escaped sequences
62302 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
62303 assert.equal(false, !!~format.indexOf(srchToken),
62304 'contains ' + srchToken + ' in ' + baseToken);
62305 });
b135bf1a
IC
62306 });
62307 });
d6651c21 62308
db71a655
KM
62309 test('month parsing correctness', function (assert) {
62310 var i, m;
62311
62312 if (locale === 'tr') {
62313 // I can't fix it :(
c58511b9 62314 assert.expect(0);
db71a655
KM
62315 return;
62316 }
62317 function tester(format) {
62318 var r;
62319 r = moment(m.format(format), format);
62320 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
62321 if (locale !== 'ka') {
62322 r = moment(m.format(format).toLocaleUpperCase(), format);
62323 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
62324 }
db71a655
KM
62325 r = moment(m.format(format).toLocaleLowerCase(), format);
62326 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
62327
62328 r = moment(m.format(format), format, true);
62329 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
62330 if (locale !== 'ka') {
62331 r = moment(m.format(format).toLocaleUpperCase(), format, true);
62332 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
62333 }
db71a655
KM
62334 r = moment(m.format(format).toLocaleLowerCase(), format, true);
62335 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
62336 }
62337
62338 for (i = 0; i < 12; ++i) {
62339 m = moment([2015, i, 15, 18]);
62340 tester('MMM');
62341 tester('MMM.');
62342 tester('MMMM');
62343 tester('MMMM.');
62344 }
62345 });
d6651c21 62346
db71a655
KM
62347 test('weekday parsing correctness', function (assert) {
62348 var i, m;
62349
96d0d679 62350 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
62351 // tr, az: There is a lower-case letter (ı), that converted to
62352 // upper then lower changes to i
62353 // ro: there is the letter ț which behaves weird under IE8
62354 // mt: letter Ħ
96d0d679 62355 // ga: month with spaces
c58511b9 62356 assert.expect(0);
db71a655
KM
62357 return;
62358 }
62359 function tester(format) {
62360 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
62361 r = moment(m.format(format), format);
62362 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
62363 if (locale !== 'ka') {
62364 r = moment(m.format(format).toLocaleUpperCase(), format);
62365 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
62366 }
db71a655
KM
62367 r = moment(m.format(format).toLocaleLowerCase(), format);
62368 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
62369 r = moment(m.format(format), format, true);
62370 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
62371 if (locale !== 'ka') {
62372 r = moment(m.format(format).toLocaleUpperCase(), format, true);
62373 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
62374 }
db71a655
KM
62375 r = moment(m.format(format).toLocaleLowerCase(), format, true);
62376 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
62377 }
62378
62379 for (i = 0; i < 7; ++i) {
62380 m = moment.utc([2015, 0, i + 1, 18]);
62381 tester('dd');
62382 tester('ddd');
62383 tester('dddd');
62384 }
62385 });
d6651c21 62386
db71a655
KM
62387 test('valid localeData', function (assert) {
62388 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
62389 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
62390 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
62391 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
62392 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
62393 });
96d0d679
KM
62394
62395 test('localeData weekdays can localeSort', function (assert) {
62396 var weekdays = moment().localeData().weekdays();
62397 var weekdaysShort = moment().localeData().weekdaysShort();
62398 var weekdaysMin = moment().localeData().weekdaysMin();
62399 var shift = moment().localeData()._week.dow;
62400 assert.deepEqual(
62401 moment().localeData().weekdays(true),
62402 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
62403 'weekdays should localeSort');
62404 assert.deepEqual(
62405 moment().localeData().weekdaysShort(true),
62406 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
62407 'weekdaysShort should localeSort');
62408 assert.deepEqual(
62409 moment().localeData().weekdaysMin(true),
62410 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
62411 'weekdaysMin should localeSort');
62412 });
db71a655 62413 }
d6651c21 62414
db71a655
KM
62415 /*global QUnit:false*/
62416
db71a655
KM
62417 function localeModule (name, lifecycle) {
62418 QUnit.module('locale:' + name, {
c58511b9 62419 beforeEach : function () {
db71a655
KM
62420 moment.locale(name);
62421 moment.createFromInputFallback = function (config) {
62422 throw new Error('input not handled by moment: ' + config._i);
62423 };
62424 setupDeprecationHandler(test, moment, 'locale');
62425 if (lifecycle && lifecycle.setup) {
62426 lifecycle.setup();
62427 }
62428 },
c58511b9 62429 afterEach : function () {
db71a655
KM
62430 moment.locale('en');
62431 teardownDeprecationHandler(test, moment, 'locale');
62432 if (lifecycle && lifecycle.teardown) {
62433 lifecycle.teardown();
62434 }
d6651c21
IC
62435 }
62436 });
db71a655
KM
62437 defineCommonLocaleTests(name, -1, -1);
62438 }
62439
62440 localeModule('vi');
62441
62442 test('parse', function (assert) {
62443 var i,
62444 tests = 'tháng 1,Th01_tháng 2,Th02_tháng 3,Th03_tháng 4,Th04_tháng 5,Th05_tháng 6,Th06_tháng 7,Th07_tháng 8,Th08_tháng 9,Th09_tháng 10,Th10_tháng 11,Th11_tháng 12,Th12'.split('_');
62445
62446 function equalTest(input, mmm, i) {
62447 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + i);
62448 }
62449
62450 for (i = 0; i < 12; i++) {
62451 tests[i] = tests[i].split(',');
62452 equalTest(tests[i][0], '[tháng] M', i);
62453 equalTest(tests[i][1], '[Th]M', i);
62454 equalTest(tests[i][0], '[tháng] MM', i);
62455 equalTest(tests[i][1], '[Th]MM', i);
62456 equalTest(tests[i][0].toLocaleLowerCase(), '[THÁNG] M', i);
62457 equalTest(tests[i][1].toLocaleLowerCase(), '[TH]M', i);
62458 equalTest(tests[i][0].toLocaleUpperCase(), '[THÁNG] MM', i);
62459 equalTest(tests[i][1].toLocaleUpperCase(), '[TH]MM', i);
62460 }
62461 });
62462
62463 test('format', function (assert) {
62464 var a = [
62465 ['dddd, MMMM Do YYYY, h:mm:ss a', 'chủ nhật, tháng 2 14 2010, 3:25:50 ch'],
62466 ['ddd, hA', 'CN, 3CH'],
62467 ['M Mo MM MMMM MMM', '2 2 02 tháng 2 Th02'],
62468 ['YYYY YY', '2010 10'],
62469 ['D Do DD', '14 14 14'],
62470 ['d do dddd ddd dd', '0 0 chủ nhật CN CN'],
62471 ['DDD DDDo DDDD', '45 45 045'],
62472 ['w wo ww', '6 6 06'],
62473 ['h hh', '3 03'],
62474 ['H HH', '15 15'],
62475 ['m mm', '25 25'],
62476 ['s ss', '50 50'],
62477 ['a A', 'ch CH'],
62478 ['[ngày thứ] DDDo [của năm]', 'ngày thứ 45 của năm'],
62479 ['LTS', '15:25:50'],
62480 ['L', '14/02/2010'],
62481 ['LL', '14 tháng 2 năm 2010'],
62482 ['LLL', '14 tháng 2 năm 2010 15:25'],
62483 ['LLLL', 'chủ nhật, 14 tháng 2 năm 2010 15:25'],
62484 ['l', '14/2/2010'],
62485 ['ll', '14 Th02 2010'],
62486 ['lll', '14 Th02 2010 15:25'],
62487 ['llll', 'CN, 14 Th02 2010 15:25']
62488 ],
62489 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
62490 i;
62491
62492 for (i = 0; i < a.length; i++) {
62493 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
62494 }
62495 });
62496
62497 test('format ordinal', function (assert) {
62498 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1');
62499 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2');
62500 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3');
62501 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4');
62502 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5');
62503 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6');
62504 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7');
62505 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8');
62506 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9');
62507 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10');
62508
62509 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11');
62510 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12');
62511 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13');
62512 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14');
62513 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15');
62514 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16');
62515 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17');
62516 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18');
62517 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19');
62518 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20');
62519
62520 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21');
62521 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22');
62522 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23');
62523 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24');
62524 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25');
62525 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26');
62526 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27');
62527 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28');
62528 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29');
62529 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30');
62530
62531 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31');
62532 });
62533
62534 test('format month', function (assert) {
62535 var i,
62536 expected = 'tháng 1,Th01_tháng 2,Th02_tháng 3,Th03_tháng 4,Th04_tháng 5,Th05_tháng 6,Th06_tháng 7,Th07_tháng 8,Th08_tháng 9,Th09_tháng 10,Th10_tháng 11,Th11_tháng 12,Th12'.split('_');
62537
62538 for (i = 0; i < expected.length; i++) {
62539 assert.equal(moment([2011, i, 1]).format('MMMM,MMM'), expected[i], expected[i]);
62540 }
62541 });
62542
62543 test('format week', function (assert) {
62544 var i,
62545 expected = 'chủ nhật CN CN_thứ hai T2 T2_thứ ba T3 T3_thứ tư T4 T4_thứ năm T5 T5_thứ sáu T6 T6_thứ bảy T7 T7'.split('_');
62546
62547 for (i = 0; i < expected.length; i++) {
62548 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
62549 }
62550 });
62551
62552 test('from', function (assert) {
62553 var start = moment([2007, 1, 28]);
62554
62555 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'vài giây', '44 seconds = a few seconds');
62556 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'một phút', '45 seconds = a minute');
62557 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'một phút', '89 seconds = a minute');
62558 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 phút', '90 seconds = 2 minutes');
62559 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 phút', '44 minutes = 44 minutes');
62560 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'một giờ', '45 minutes = an hour');
62561 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'một giờ', '89 minutes = an hour');
62562 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 giờ', '90 minutes = 2 hours');
62563 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 giờ', '5 hours = 5 hours');
62564 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 giờ', '21 hours = 21 hours');
62565 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'một ngày', '22 hours = a day');
62566 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'một ngày', '35 hours = a day');
62567 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 ngày', '36 hours = 2 days');
62568 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'một ngày', '1 day = a day');
62569 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ngày', '5 days = 5 days');
62570 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ngày', '25 days = 25 days');
62571 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'một tháng', '26 days = a month');
62572 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'một tháng', '30 days = a month');
62573 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'một tháng', '43 days = a month');
62574 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 tháng', '46 days = 2 months');
62575 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 tháng', '75 days = 2 months');
62576 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 tháng', '76 days = 3 months');
62577 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'một tháng', '1 month = a month');
62578 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 tháng', '5 months = 5 months');
62579 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'một năm', '345 days = a year');
62580 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 năm', '548 days = 2 years');
62581 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'một năm', '1 year = a year');
62582 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 năm', '5 years = 5 years');
62583 });
62584
62585 test('suffix', function (assert) {
62586 assert.equal(moment(30000).from(0), 'vài giây tới', 'prefix');
62587 assert.equal(moment(0).from(30000), 'vài giây trước', 'suffix');
62588 });
62589
62590 test('now from now', function (assert) {
62591 assert.equal(moment().fromNow(), 'vài giây trước', 'now from now should display as in the past');
62592 });
62593
62594 test('fromNow', function (assert) {
62595 assert.equal(moment().add({s: 30}).fromNow(), 'vài giây tới', 'in a few seconds');
62596 assert.equal(moment().add({d: 5}).fromNow(), '5 ngày tới', 'in 5 days');
62597 });
62598
62599 test('calendar day', function (assert) {
62600 var a = moment().hours(12).minutes(0).seconds(0);
62601
62602 assert.equal(moment(a).calendar(), 'Hôm nay lúc 12:00', 'today at the same time');
62603 assert.equal(moment(a).add({m: 25}).calendar(), 'Hôm nay lúc 12:25', 'Now plus 25 min');
62604 assert.equal(moment(a).add({h: 1}).calendar(), 'Hôm nay lúc 13:00', 'Now plus 1 hour');
62605 assert.equal(moment(a).add({d: 1}).calendar(), 'Ngày mai lúc 12:00', 'tomorrow at the same time');
62606 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Hôm nay lúc 11:00', 'Now minus 1 hour');
62607 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Hôm qua lúc 12:00', 'yesterday at the same time');
62608 });
62609
62610 test('calendar next week', function (assert) {
62611 var i, m;
d6651c21 62612
db71a655
KM
62613 for (i = 2; i < 7; i++) {
62614 m = moment().add({d: i});
62615 assert.equal(m.calendar(), m.format('dddd [tuần tới lúc] LT'), 'Today + ' + i + ' days current time');
62616 m.hours(0).minutes(0).seconds(0).milliseconds(0);
62617 assert.equal(m.calendar(), m.format('dddd [tuần tới lúc] LT'), 'Today + ' + i + ' days beginning of day');
62618 m.hours(23).minutes(59).seconds(59).milliseconds(999);
62619 assert.equal(m.calendar(), m.format('dddd [tuần tới lúc] LT'), 'Today + ' + i + ' days end of day');
d6651c21 62620 }
db71a655
KM
62621 });
62622
62623 test('calendar last week', function (assert) {
62624 var i, m;
62625
62626 for (i = 2; i < 7; i++) {
62627 m = moment().subtract({d: i});
62628 assert.equal(m.calendar(), m.format('dddd [tuần rồi lúc] LT'), 'Today - ' + i + ' days current time');
62629 m.hours(0).minutes(0).seconds(0).milliseconds(0);
62630 assert.equal(m.calendar(), m.format('dddd [tuần rồi lúc] LT'), 'Today - ' + i + ' days beginning of day');
62631 m.hours(23).minutes(59).seconds(59).milliseconds(999);
62632 assert.equal(m.calendar(), m.format('dddd [tuần rồi lúc] LT'), 'Today - ' + i + ' days end of day');
d6651c21 62633 }
db71a655 62634 });
d6651c21 62635
db71a655
KM
62636 test('calendar all else', function (assert) {
62637 var weeksAgo = moment().subtract({w: 1}),
62638 weeksFromNow = moment().add({w: 1});
d6651c21 62639
db71a655
KM
62640 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
62641 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
d6651c21 62642
db71a655
KM
62643 weeksAgo = moment().subtract({w: 2});
62644 weeksFromNow = moment().add({w: 2});
d6651c21 62645
db71a655
KM
62646 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
62647 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
62648 });
62649
62650 test('weeks year starting sunday formatted', function (assert) {
62651 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52', 'Jan 1 2012 should be week 52');
62652 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1', 'Jan 2 2012 should be week 1');
62653 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1', 'Jan 8 2012 should be week 1');
62654 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2', 'Jan 9 2012 should be week 2');
62655 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2', 'Jan 15 2012 should be week 2');
62656 });
73f3c911
IC
62657
62658})));
62659
d6651c21
IC
62660
62661;(function (global, factory) {
62662 typeof exports === 'object' && typeof module !== 'undefined'
62663 && typeof require === 'function' ? factory(require('../../moment')) :
62664 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
62665 factory(global.moment)
73f3c911 62666}(this, (function (moment) { 'use strict';
d6651c21 62667
db71a655
KM
62668 function each(array, callback) {
62669 var i;
62670 for (i = 0; i < array.length; i++) {
62671 callback(array[i], i, array);
62672 }
d6651c21
IC
62673 }
62674
c58511b9
KM
62675 function setupDeprecationHandler(test, moment$$1, scope) {
62676 test._expectedDeprecations = null;
62677 test._observedDeprecations = null;
62678 test._oldSupress = moment$$1.suppressDeprecationWarnings;
62679 moment$$1.suppressDeprecationWarnings = true;
62680 test.expectedDeprecations = function () {
62681 test._expectedDeprecations = arguments;
62682 test._observedDeprecations = [];
62683 };
62684 moment$$1.deprecationHandler = function (name, msg) {
62685 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
62686 if (deprecationId === -1) {
62687 throw new Error('Unexpected deprecation thrown name=' +
62688 name + ' msg=' + msg);
62689 }
62690 test._observedDeprecations[deprecationId] = 1;
62691 };
62692 }
62693
62694 function teardownDeprecationHandler(test, moment$$1, scope) {
62695 moment$$1.suppressDeprecationWarnings = test._oldSupress;
62696
62697 if (test._expectedDeprecations != null) {
62698 var missedDeprecations = [];
62699 each(test._expectedDeprecations, function (deprecationPattern, id) {
62700 if (test._observedDeprecations[id] !== 1) {
62701 missedDeprecations.push(deprecationPattern);
62702 }
62703 });
62704 if (missedDeprecations.length !== 0) {
62705 throw new Error('Expected deprecation warnings did not happen: ' +
62706 missedDeprecations.join(' '));
62707 }
62708 }
62709 }
62710
62711 function matchedDeprecation(name, msg, deprecations) {
62712 if (deprecations == null) {
62713 return -1;
62714 }
62715 for (var i = 0; i < deprecations.length; ++i) {
62716 if (name != null && name === deprecations[i]) {
62717 return i;
62718 }
62719 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
62720 return i;
62721 }
62722 }
62723 return -1;
62724 }
62725
62726 /*global QUnit:false*/
62727
62728 var test = QUnit.test;
62729
db71a655
KM
62730 function objectKeys(obj) {
62731 if (Object.keys) {
62732 return Object.keys(obj);
62733 } else {
62734 // IE8
62735 var res = [], i;
62736 for (i in obj) {
62737 if (obj.hasOwnProperty(i)) {
62738 res.push(i);
62739 }
d6651c21 62740 }
db71a655 62741 return res;
d6651c21 62742 }
d6651c21 62743 }
d6651c21 62744
db71a655 62745 // Pick the first defined of two or three arguments.
d6651c21 62746
db71a655
KM
62747 function defineCommonLocaleTests(locale, options) {
62748 test('lenient day of month ordinal parsing', function (assert) {
62749 var i, ordinalStr, testMoment;
62750 for (i = 1; i <= 31; ++i) {
62751 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
62752 testMoment = moment(ordinalStr, 'YYYY MM Do');
62753 assert.equal(testMoment.year(), 2014,
62754 'lenient day of month ordinal parsing ' + i + ' year check');
62755 assert.equal(testMoment.month(), 0,
62756 'lenient day of month ordinal parsing ' + i + ' month check');
62757 assert.equal(testMoment.date(), i,
62758 'lenient day of month ordinal parsing ' + i + ' date check');
62759 }
62760 });
d6651c21 62761
db71a655
KM
62762 test('lenient day of month ordinal parsing of number', function (assert) {
62763 var i, testMoment;
62764 for (i = 1; i <= 31; ++i) {
62765 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
62766 assert.equal(testMoment.year(), 2014,
62767 'lenient day of month ordinal parsing of number ' + i + ' year check');
62768 assert.equal(testMoment.month(), 0,
62769 'lenient day of month ordinal parsing of number ' + i + ' month check');
62770 assert.equal(testMoment.date(), i,
62771 'lenient day of month ordinal parsing of number ' + i + ' date check');
62772 }
62773 });
d6651c21 62774
db71a655
KM
62775 test('strict day of month ordinal parsing', function (assert) {
62776 var i, ordinalStr, testMoment;
62777 for (i = 1; i <= 31; ++i) {
62778 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
62779 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
62780 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
62781 }
62782 });
62783
62784 test('meridiem invariant', function (assert) {
62785 var h, m, t1, t2;
62786 for (h = 0; h < 24; ++h) {
62787 for (m = 0; m < 60; m += 15) {
62788 t1 = moment.utc([2000, 0, 1, h, m]);
62789 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
62790 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
62791 'meridiem at ' + t1.format('HH:mm'));
62792 }
62793 }
62794 });
62795
62796 test('date format correctness', function (assert) {
62797 var data, tokens;
62798 data = moment.localeData()._longDateFormat;
62799 tokens = objectKeys(data);
62800 each(tokens, function (srchToken) {
62801 // Check each format string to make sure it does not contain any
62802 // tokens that need to be expanded.
62803 each(tokens, function (baseToken) {
62804 // strip escaped sequences
62805 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
62806 assert.equal(false, !!~format.indexOf(srchToken),
62807 'contains ' + srchToken + ' in ' + baseToken);
62808 });
d6651c21
IC
62809 });
62810 });
62811
db71a655
KM
62812 test('month parsing correctness', function (assert) {
62813 var i, m;
62814
62815 if (locale === 'tr') {
62816 // I can't fix it :(
c58511b9 62817 assert.expect(0);
db71a655
KM
62818 return;
62819 }
62820 function tester(format) {
62821 var r;
62822 r = moment(m.format(format), format);
62823 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
62824 if (locale !== 'ka') {
62825 r = moment(m.format(format).toLocaleUpperCase(), format);
62826 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
62827 }
db71a655
KM
62828 r = moment(m.format(format).toLocaleLowerCase(), format);
62829 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
62830
62831 r = moment(m.format(format), format, true);
62832 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
62833 if (locale !== 'ka') {
62834 r = moment(m.format(format).toLocaleUpperCase(), format, true);
62835 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
62836 }
db71a655
KM
62837 r = moment(m.format(format).toLocaleLowerCase(), format, true);
62838 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
62839 }
62840
62841 for (i = 0; i < 12; ++i) {
62842 m = moment([2015, i, 15, 18]);
62843 tester('MMM');
62844 tester('MMM.');
62845 tester('MMMM');
62846 tester('MMMM.');
62847 }
62848 });
d6651c21 62849
db71a655
KM
62850 test('weekday parsing correctness', function (assert) {
62851 var i, m;
62852
96d0d679 62853 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
62854 // tr, az: There is a lower-case letter (ı), that converted to
62855 // upper then lower changes to i
62856 // ro: there is the letter ț which behaves weird under IE8
62857 // mt: letter Ħ
96d0d679 62858 // ga: month with spaces
c58511b9 62859 assert.expect(0);
db71a655
KM
62860 return;
62861 }
62862 function tester(format) {
62863 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
62864 r = moment(m.format(format), format);
62865 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
62866 if (locale !== 'ka') {
62867 r = moment(m.format(format).toLocaleUpperCase(), format);
62868 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
62869 }
db71a655
KM
62870 r = moment(m.format(format).toLocaleLowerCase(), format);
62871 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
62872 r = moment(m.format(format), format, true);
62873 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
62874 if (locale !== 'ka') {
62875 r = moment(m.format(format).toLocaleUpperCase(), format, true);
62876 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
62877 }
db71a655
KM
62878 r = moment(m.format(format).toLocaleLowerCase(), format, true);
62879 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
62880 }
62881
62882 for (i = 0; i < 7; ++i) {
62883 m = moment.utc([2015, 0, i + 1, 18]);
62884 tester('dd');
62885 tester('ddd');
62886 tester('dddd');
62887 }
62888 });
d6651c21 62889
db71a655
KM
62890 test('valid localeData', function (assert) {
62891 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
62892 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
62893 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
62894 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
62895 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
62896 });
96d0d679
KM
62897
62898 test('localeData weekdays can localeSort', function (assert) {
62899 var weekdays = moment().localeData().weekdays();
62900 var weekdaysShort = moment().localeData().weekdaysShort();
62901 var weekdaysMin = moment().localeData().weekdaysMin();
62902 var shift = moment().localeData()._week.dow;
62903 assert.deepEqual(
62904 moment().localeData().weekdays(true),
62905 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
62906 'weekdays should localeSort');
62907 assert.deepEqual(
62908 moment().localeData().weekdaysShort(true),
62909 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
62910 'weekdaysShort should localeSort');
62911 assert.deepEqual(
62912 moment().localeData().weekdaysMin(true),
62913 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
62914 'weekdaysMin should localeSort');
62915 });
db71a655 62916 }
73f3c911 62917
db71a655
KM
62918 /*global QUnit:false*/
62919
db71a655
KM
62920 function localeModule (name, lifecycle) {
62921 QUnit.module('locale:' + name, {
c58511b9 62922 beforeEach : function () {
db71a655
KM
62923 moment.locale(name);
62924 moment.createFromInputFallback = function (config) {
62925 throw new Error('input not handled by moment: ' + config._i);
62926 };
62927 setupDeprecationHandler(test, moment, 'locale');
62928 if (lifecycle && lifecycle.setup) {
62929 lifecycle.setup();
62930 }
62931 },
c58511b9 62932 afterEach : function () {
db71a655
KM
62933 moment.locale('en');
62934 teardownDeprecationHandler(test, moment, 'locale');
62935 if (lifecycle && lifecycle.teardown) {
62936 lifecycle.teardown();
62937 }
516f5f67
IC
62938 }
62939 });
db71a655
KM
62940 defineCommonLocaleTests(name, -1, -1);
62941 }
62942
62943 localeModule('x-pseudo');
62944
62945 test('parse', function (assert) {
62946 var tests = 'J~áñúá~rý J~áñ_F~ébrú~árý ~Féb_~Márc~h ~Már_Áp~ríl ~Ápr_~Máý ~Máý_~Júñé~ ~Júñ_Júl~ý ~Júl_Áú~gúst~ ~Áúg_Sép~témb~ér ~Sép_Ó~ctób~ér ~Óct_Ñ~óvém~bér ~Ñóv_~Décé~mbér ~Déc'.split('_'), i;
62947 function equalTest(input, mmm, i) {
62948 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
62949 }
62950 for (i = 0; i < 12; i++) {
62951 tests[i] = tests[i].split(' ');
62952 equalTest(tests[i][0], 'MMM', i);
62953 equalTest(tests[i][1], 'MMM', i);
62954 equalTest(tests[i][0], 'MMMM', i);
62955 equalTest(tests[i][1], 'MMMM', i);
62956 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
62957 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
62958 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
62959 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
62960 }
62961 });
62962
62963 test('format', function (assert) {
62964 var a = [
62965 ['dddd, MMMM Do YYYY, h:mm:ss a', 'S~úñdá~ý, F~ébrú~árý 14th 2010, 3:25:50 pm'],
62966 ['ddd, hA', 'S~úñ, 3PM'],
62967 ['M Mo MM MMMM MMM', '2 2nd 02 F~ébrú~árý ~Féb'],
62968 ['YYYY YY', '2010 10'],
62969 ['D Do DD', '14 14th 14'],
62970 ['d do dddd ddd dd', '0 0th S~úñdá~ý S~úñ S~ú'],
62971 ['DDD DDDo DDDD', '45 45th 045'],
62972 ['w wo ww', '6 6th 06'],
62973 ['h hh', '3 03'],
62974 ['H HH', '15 15'],
62975 ['m mm', '25 25'],
62976 ['s ss', '50 50'],
62977 ['a A', 'pm PM'],
62978 ['[the] DDDo [day of the year]', 'the 45th day of the year'],
62979 ['LT', '15:25'],
62980 ['L', '14/02/2010'],
62981 ['LL', '14 F~ébrú~árý 2010'],
62982 ['LLL', '14 F~ébrú~árý 2010 15:25'],
62983 ['LLLL', 'S~úñdá~ý, 14 F~ébrú~árý 2010 15:25'],
62984 ['l', '14/2/2010'],
62985 ['ll', '14 ~Féb 2010'],
62986 ['lll', '14 ~Féb 2010 15:25'],
62987 ['llll', 'S~úñ, 14 ~Féb 2010 15:25']
62988 ],
62989 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
62990 i;
62991 for (i = 0; i < a.length; i++) {
62992 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
62993 }
62994 });
62995
62996 test('format ordinal', function (assert) {
62997 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1st', '1st');
62998 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2nd', '2nd');
62999 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3rd', '3rd');
63000 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4th', '4th');
63001 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5th', '5th');
63002 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6th', '6th');
63003 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7th', '7th');
63004 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8th', '8th');
63005 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9th', '9th');
63006 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10th', '10th');
63007
63008 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11th', '11th');
63009 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12th', '12th');
63010 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13th', '13th');
63011 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14th', '14th');
63012 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15th', '15th');
63013 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16th', '16th');
63014 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17th', '17th');
63015 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18th', '18th');
63016 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19th', '19th');
63017 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20th', '20th');
63018
63019 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21st', '21st');
63020 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22nd', '22nd');
63021 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23rd', '23rd');
63022 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24th', '24th');
63023 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25th', '25th');
63024 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26th', '26th');
63025 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27th', '27th');
63026 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28th', '28th');
63027 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29th', '29th');
63028 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30th', '30th');
63029
63030 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31st', '31st');
63031 });
63032
63033 test('format month', function (assert) {
63034 var expected = 'J~áñúá~rý J~áñ_F~ébrú~árý ~Féb_~Márc~h ~Már_Áp~ríl ~Ápr_~Máý ~Máý_~Júñé~ ~Júñ_Júl~ý ~Júl_Áú~gúst~ ~Áúg_Sép~témb~ér ~Sép_Ó~ctób~ér ~Óct_Ñ~óvém~bér ~Ñóv_~Décé~mbér ~Déc'.split('_'), i;
63035 for (i = 0; i < expected.length; i++) {
63036 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
63037 }
63038 });
63039
63040 test('format week', function (assert) {
63041 var expected = 'S~úñdá~ý S~úñ S~ú_Mó~ñdáý~ ~Móñ Mó~_Túé~sdáý~ ~Túé Tú_Wéd~ñésd~áý ~Wéd ~Wé_T~húrs~dáý ~Thú T~h_~Fríd~áý ~Frí Fr~_S~átúr~dáý ~Sát Sá'.split('_'), i;
63042 for (i = 0; i < expected.length; i++) {
63043 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
63044 }
63045 });
63046
63047 test('from', function (assert) {
63048 var start = moment([2007, 1, 28]);
63049 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'á ~féw ~sécó~ñds', '44 seconds = a few seconds');
63050 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'á ~míñ~úté', '45 seconds = a minute');
63051 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'á ~míñ~úté', '89 seconds = a minute');
63052 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 m~íñú~tés', '90 seconds = 2 minutes');
63053 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 m~íñú~tés', '44 minutes = 44 minutes');
63054 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'á~ñ hó~úr', '45 minutes = an hour');
63055 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'á~ñ hó~úr', '89 minutes = an hour');
63056 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 h~óúrs', '90 minutes = 2 hours');
63057 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 h~óúrs', '5 hours = 5 hours');
63058 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 h~óúrs', '21 hours = 21 hours');
63059 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'á ~dáý', '22 hours = a day');
63060 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'á ~dáý', '35 hours = a day');
63061 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 d~áýs', '36 hours = 2 days');
63062 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'á ~dáý', '1 day = a day');
63063 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 d~áýs', '5 days = 5 days');
63064 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 d~áýs', '25 days = 25 days');
63065 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'á ~móñ~th', '26 days = a month');
63066 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'á ~móñ~th', '30 days = a month');
63067 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'á ~móñ~th', '43 days = a month');
63068 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 m~óñt~hs', '46 days = 2 months');
63069 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 m~óñt~hs', '75 days = 2 months');
63070 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 m~óñt~hs', '76 days = 3 months');
63071 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'á ~móñ~th', '1 month = a month');
63072 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 m~óñt~hs', '5 months = 5 months');
63073 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'á ~ýéár', '345 days = a year');
63074 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ý~éárs', '548 days = 2 years');
63075 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'á ~ýéár', '1 year = a year');
63076 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ý~éárs', '5 years = 5 years');
63077 });
63078
63079 test('suffix', function (assert) {
63080 assert.equal(moment(30000).from(0), 'í~ñ á ~féw ~sécó~ñds', 'prefix');
63081 assert.equal(moment(0).from(30000), 'á ~féw ~sécó~ñds á~gó', 'suffix');
63082 });
63083
63084 test('now from now', function (assert) {
63085 assert.equal(moment().fromNow(), 'á ~féw ~sécó~ñds á~gó', 'now from now should display as in the past');
63086 });
63087
63088 test('fromNow', function (assert) {
63089 assert.equal(moment().add({s: 30}).fromNow(), 'í~ñ á ~féw ~sécó~ñds', 'in a few seconds');
63090 assert.equal(moment().add({d: 5}).fromNow(), 'í~ñ 5 d~áýs', 'in 5 days');
63091 });
63092
63093 test('calendar day', function (assert) {
63094 var a = moment().hours(2).minutes(0).seconds(0);
63095
63096 assert.equal(moment(a).calendar(), 'T~ódá~ý át 02:00', 'today at the same time');
63097 assert.equal(moment(a).add({m: 25}).calendar(), 'T~ódá~ý át 02:25', 'Now plus 25 min');
63098 assert.equal(moment(a).add({h: 1}).calendar(), 'T~ódá~ý át 03:00', 'Now plus 1 hour');
63099 assert.equal(moment(a).add({d: 1}).calendar(), 'T~ómó~rró~w át 02:00', 'tomorrow at the same time');
63100 assert.equal(moment(a).subtract({h: 1}).calendar(), 'T~ódá~ý át 01:00', 'Now minus 1 hour');
63101 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Ý~ést~érdá~ý át 02:00', 'yesterday at the same time');
63102 });
63103
63104 test('calendar next week', function (assert) {
63105 var i, m;
63106 for (i = 2; i < 7; i++) {
63107 m = moment().add({d: i});
63108 assert.equal(m.calendar(), m.format('dddd [át] LT'), 'Today + ' + i + ' days current time');
63109 m.hours(0).minutes(0).seconds(0).milliseconds(0);
63110 assert.equal(m.calendar(), m.format('dddd [át] LT'), 'Today + ' + i + ' days beginning of day');
63111 m.hours(23).minutes(59).seconds(59).milliseconds(999);
63112 assert.equal(m.calendar(), m.format('dddd [át] LT'), 'Today + ' + i + ' days end of day');
73f3c911 63113 }
db71a655 63114 });
516f5f67 63115
db71a655
KM
63116 test('calendar last week', function (assert) {
63117 var i, m;
63118
63119 for (i = 2; i < 7; i++) {
63120 m = moment().subtract({d: i});
63121 assert.equal(m.calendar(), m.format('[L~ást] dddd [át] LT'), 'Today - ' + i + ' days current time');
63122 m.hours(0).minutes(0).seconds(0).milliseconds(0);
63123 assert.equal(m.calendar(), m.format('[L~ást] dddd [át] LT'), 'Today - ' + i + ' days beginning of day');
63124 m.hours(23).minutes(59).seconds(59).milliseconds(999);
63125 assert.equal(m.calendar(), m.format('[L~ást] dddd [át] LT'), 'Today - ' + i + ' days end of day');
516f5f67 63126 }
db71a655 63127 });
516f5f67 63128
db71a655
KM
63129 test('calendar all else', function (assert) {
63130 var weeksAgo = moment().subtract({w: 1}),
63131 weeksFromNow = moment().add({w: 1});
516f5f67 63132
db71a655
KM
63133 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
63134 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 63135
db71a655
KM
63136 weeksAgo = moment().subtract({w: 2});
63137 weeksFromNow = moment().add({w: 2});
516f5f67 63138
db71a655
KM
63139 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
63140 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
63141 });
63142
63143 test('weeks year starting sunday formatted', function (assert) {
63144 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52nd', 'Jan 1 2012 should be week 52');
63145 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1st', 'Jan 2 2012 should be week 1');
63146 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1st', 'Jan 8 2012 should be week 1');
63147 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2nd', 'Jan 9 2012 should be week 2');
63148 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2nd', 'Jan 15 2012 should be week 2');
63149 });
73f3c911
IC
63150
63151})));
63152
516f5f67 63153
b135bf1a
IC
63154;(function (global, factory) {
63155 typeof exports === 'object' && typeof module !== 'undefined'
63156 && typeof require === 'function' ? factory(require('../../moment')) :
63157 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
63158 factory(global.moment)
73f3c911 63159}(this, (function (moment) { 'use strict';
b135bf1a 63160
db71a655
KM
63161 function each(array, callback) {
63162 var i;
63163 for (i = 0; i < array.length; i++) {
63164 callback(array[i], i, array);
63165 }
b135bf1a 63166 }
516f5f67 63167
c58511b9
KM
63168 function setupDeprecationHandler(test, moment$$1, scope) {
63169 test._expectedDeprecations = null;
63170 test._observedDeprecations = null;
63171 test._oldSupress = moment$$1.suppressDeprecationWarnings;
63172 moment$$1.suppressDeprecationWarnings = true;
63173 test.expectedDeprecations = function () {
63174 test._expectedDeprecations = arguments;
63175 test._observedDeprecations = [];
63176 };
63177 moment$$1.deprecationHandler = function (name, msg) {
63178 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
63179 if (deprecationId === -1) {
63180 throw new Error('Unexpected deprecation thrown name=' +
63181 name + ' msg=' + msg);
63182 }
63183 test._observedDeprecations[deprecationId] = 1;
63184 };
63185 }
63186
63187 function teardownDeprecationHandler(test, moment$$1, scope) {
63188 moment$$1.suppressDeprecationWarnings = test._oldSupress;
63189
63190 if (test._expectedDeprecations != null) {
63191 var missedDeprecations = [];
63192 each(test._expectedDeprecations, function (deprecationPattern, id) {
63193 if (test._observedDeprecations[id] !== 1) {
63194 missedDeprecations.push(deprecationPattern);
63195 }
63196 });
63197 if (missedDeprecations.length !== 0) {
63198 throw new Error('Expected deprecation warnings did not happen: ' +
63199 missedDeprecations.join(' '));
63200 }
63201 }
63202 }
63203
63204 function matchedDeprecation(name, msg, deprecations) {
63205 if (deprecations == null) {
63206 return -1;
63207 }
63208 for (var i = 0; i < deprecations.length; ++i) {
63209 if (name != null && name === deprecations[i]) {
63210 return i;
63211 }
63212 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
63213 return i;
63214 }
63215 }
63216 return -1;
63217 }
63218
63219 /*global QUnit:false*/
63220
63221 var test = QUnit.test;
63222
db71a655
KM
63223 function objectKeys(obj) {
63224 if (Object.keys) {
63225 return Object.keys(obj);
63226 } else {
63227 // IE8
63228 var res = [], i;
63229 for (i in obj) {
63230 if (obj.hasOwnProperty(i)) {
63231 res.push(i);
63232 }
516f5f67 63233 }
db71a655 63234 return res;
b135bf1a 63235 }
b135bf1a 63236 }
516f5f67 63237
db71a655 63238 // Pick the first defined of two or three arguments.
516f5f67 63239
db71a655
KM
63240 function defineCommonLocaleTests(locale, options) {
63241 test('lenient day of month ordinal parsing', function (assert) {
63242 var i, ordinalStr, testMoment;
63243 for (i = 1; i <= 31; ++i) {
63244 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
63245 testMoment = moment(ordinalStr, 'YYYY MM Do');
63246 assert.equal(testMoment.year(), 2014,
63247 'lenient day of month ordinal parsing ' + i + ' year check');
63248 assert.equal(testMoment.month(), 0,
63249 'lenient day of month ordinal parsing ' + i + ' month check');
63250 assert.equal(testMoment.date(), i,
63251 'lenient day of month ordinal parsing ' + i + ' date check');
63252 }
63253 });
b135bf1a 63254
db71a655
KM
63255 test('lenient day of month ordinal parsing of number', function (assert) {
63256 var i, testMoment;
63257 for (i = 1; i <= 31; ++i) {
63258 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
63259 assert.equal(testMoment.year(), 2014,
63260 'lenient day of month ordinal parsing of number ' + i + ' year check');
63261 assert.equal(testMoment.month(), 0,
63262 'lenient day of month ordinal parsing of number ' + i + ' month check');
63263 assert.equal(testMoment.date(), i,
63264 'lenient day of month ordinal parsing of number ' + i + ' date check');
63265 }
63266 });
b135bf1a 63267
db71a655
KM
63268 test('strict day of month ordinal parsing', function (assert) {
63269 var i, ordinalStr, testMoment;
63270 for (i = 1; i <= 31; ++i) {
63271 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
63272 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
63273 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
63274 }
63275 });
b135bf1a 63276
db71a655
KM
63277 test('meridiem invariant', function (assert) {
63278 var h, m, t1, t2;
63279 for (h = 0; h < 24; ++h) {
63280 for (m = 0; m < 60; m += 15) {
63281 t1 = moment.utc([2000, 0, 1, h, m]);
63282 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
63283 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
63284 'meridiem at ' + t1.format('HH:mm'));
63285 }
63286 }
63287 });
63288
63289 test('date format correctness', function (assert) {
63290 var data, tokens;
63291 data = moment.localeData()._longDateFormat;
63292 tokens = objectKeys(data);
63293 each(tokens, function (srchToken) {
63294 // Check each format string to make sure it does not contain any
63295 // tokens that need to be expanded.
63296 each(tokens, function (baseToken) {
63297 // strip escaped sequences
63298 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
63299 assert.equal(false, !!~format.indexOf(srchToken),
63300 'contains ' + srchToken + ' in ' + baseToken);
63301 });
b135bf1a
IC
63302 });
63303 });
d6651c21 63304
db71a655
KM
63305 test('month parsing correctness', function (assert) {
63306 var i, m;
63307
63308 if (locale === 'tr') {
63309 // I can't fix it :(
c58511b9 63310 assert.expect(0);
db71a655
KM
63311 return;
63312 }
63313 function tester(format) {
63314 var r;
63315 r = moment(m.format(format), format);
63316 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
63317 if (locale !== 'ka') {
63318 r = moment(m.format(format).toLocaleUpperCase(), format);
63319 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
63320 }
db71a655
KM
63321 r = moment(m.format(format).toLocaleLowerCase(), format);
63322 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
63323
63324 r = moment(m.format(format), format, true);
63325 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
63326 if (locale !== 'ka') {
63327 r = moment(m.format(format).toLocaleUpperCase(), format, true);
63328 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
63329 }
db71a655
KM
63330 r = moment(m.format(format).toLocaleLowerCase(), format, true);
63331 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
63332 }
63333
63334 for (i = 0; i < 12; ++i) {
63335 m = moment([2015, i, 15, 18]);
63336 tester('MMM');
63337 tester('MMM.');
63338 tester('MMMM');
63339 tester('MMMM.');
63340 }
63341 });
d6651c21 63342
db71a655
KM
63343 test('weekday parsing correctness', function (assert) {
63344 var i, m;
63345
96d0d679 63346 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
63347 // tr, az: There is a lower-case letter (ı), that converted to
63348 // upper then lower changes to i
63349 // ro: there is the letter ț which behaves weird under IE8
63350 // mt: letter Ħ
96d0d679 63351 // ga: month with spaces
c58511b9 63352 assert.expect(0);
db71a655
KM
63353 return;
63354 }
63355 function tester(format) {
63356 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
63357 r = moment(m.format(format), format);
63358 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
63359 if (locale !== 'ka') {
63360 r = moment(m.format(format).toLocaleUpperCase(), format);
63361 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
63362 }
db71a655
KM
63363 r = moment(m.format(format).toLocaleLowerCase(), format);
63364 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
63365 r = moment(m.format(format), format, true);
63366 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
63367 if (locale !== 'ka') {
63368 r = moment(m.format(format).toLocaleUpperCase(), format, true);
63369 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
63370 }
db71a655
KM
63371 r = moment(m.format(format).toLocaleLowerCase(), format, true);
63372 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
63373 }
63374
63375 for (i = 0; i < 7; ++i) {
63376 m = moment.utc([2015, 0, i + 1, 18]);
63377 tester('dd');
63378 tester('ddd');
63379 tester('dddd');
63380 }
63381 });
d6651c21 63382
db71a655
KM
63383 test('valid localeData', function (assert) {
63384 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
63385 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
63386 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
63387 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
63388 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
63389 });
96d0d679
KM
63390
63391 test('localeData weekdays can localeSort', function (assert) {
63392 var weekdays = moment().localeData().weekdays();
63393 var weekdaysShort = moment().localeData().weekdaysShort();
63394 var weekdaysMin = moment().localeData().weekdaysMin();
63395 var shift = moment().localeData()._week.dow;
63396 assert.deepEqual(
63397 moment().localeData().weekdays(true),
63398 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
63399 'weekdays should localeSort');
63400 assert.deepEqual(
63401 moment().localeData().weekdaysShort(true),
63402 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
63403 'weekdaysShort should localeSort');
63404 assert.deepEqual(
63405 moment().localeData().weekdaysMin(true),
63406 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
63407 'weekdaysMin should localeSort');
63408 });
db71a655 63409 }
d6651c21 63410
db71a655
KM
63411 /*global QUnit:false*/
63412
db71a655
KM
63413 function localeModule (name, lifecycle) {
63414 QUnit.module('locale:' + name, {
c58511b9 63415 beforeEach : function () {
db71a655
KM
63416 moment.locale(name);
63417 moment.createFromInputFallback = function (config) {
63418 throw new Error('input not handled by moment: ' + config._i);
63419 };
63420 setupDeprecationHandler(test, moment, 'locale');
63421 if (lifecycle && lifecycle.setup) {
63422 lifecycle.setup();
63423 }
63424 },
c58511b9 63425 afterEach : function () {
db71a655
KM
63426 moment.locale('en');
63427 teardownDeprecationHandler(test, moment, 'locale');
63428 if (lifecycle && lifecycle.teardown) {
63429 lifecycle.teardown();
63430 }
516f5f67
IC
63431 }
63432 });
db71a655
KM
63433 defineCommonLocaleTests(name, -1, -1);
63434 }
63435
63436 localeModule('yo');
63437
63438 test('parse', function (assert) {
63439 var tests = 'Sẹ́rẹ́ Sẹ́r_Èrèlè Èrl_Ẹrẹ̀nà Ẹrn_Ìgbé Ìgb_Èbibi Èbi_Òkùdu Òkù_Agẹmo Agẹ_Ògún Ògú_Owewe Owe_Ọ̀wàrà Ọ̀wà_Bélú Bél_Ọ̀pẹ̀̀ Ọ̀pẹ̀̀'.split('_'), i;
63440 function equalTest(input, mmm, i) {
63441 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
63442 }
63443 for (i = 0; i < 12; i++) {
63444 tests[i] = tests[i].split(' ');
63445 equalTest(tests[i][0], 'MMM', i);
63446 equalTest(tests[i][1], 'MMM', i);
63447 equalTest(tests[i][0], 'MMMM', i);
63448 equalTest(tests[i][1], 'MMMM', i);
63449 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
63450 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
63451 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
63452 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
63453 }
63454 });
63455
63456 test('format', function (assert) {
63457 var a = [
63458 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Àìkú, Èrèlè ọjọ́ 14 2010, 3:25:50 pm'],
63459 ['ddd, hA', 'Àìk, 3PM'],
63460 ['M Mo MM MMMM MMM', '2 ọjọ́ 2 02 Èrèlè Èrl'],
63461 ['YYYY YY', '2010 10'],
63462 ['D Do DD', '14 ọjọ́ 14 14'],
63463 ['d do dddd ddd dd', '0 ọjọ́ 0 Àìkú Àìk Àì'],
63464 ['DDD DDDo DDDD', '45 ọjọ́ 45 045'],
63465 ['w wo ww', '6 ọjọ́ 6 06'],
63466 ['h hh', '3 03'],
63467 ['H HH', '15 15'],
63468 ['m mm', '25 25'],
63469 ['s ss', '50 50'],
63470 ['a A', 'pm PM'],
63471 ['[the] DDDo [day of the year]', 'the ọjọ́ 45 day of the year'],
63472 ['LTS', '3:25:50 PM'],
63473 ['L', '14/02/2010'],
63474 ['LL', '14 Èrèlè 2010'],
63475 ['LLL', '14 Èrèlè 2010 3:25 PM'],
63476 ['LLLL', 'Àìkú, 14 Èrèlè 2010 3:25 PM'],
63477 ['l', '14/2/2010'],
63478 ['ll', '14 Èrl 2010'],
63479 ['lll', '14 Èrl 2010 3:25 PM'],
63480 ['llll', 'Àìk, 14 Èrl 2010 3:25 PM']
63481 ],
63482 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
63483 i;
63484 for (i = 0; i < a.length; i++) {
63485 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
63486 }
63487 });
63488
63489 test('format ordinal', function (assert) {
63490 assert.equal(moment([2011, 0, 1]).format('DDDo'), 'ọjọ́ 1', 'ọjọ́ 1');
63491 assert.equal(moment([2011, 0, 2]).format('DDDo'), 'ọjọ́ 2', 'ọjọ́ 2');
63492 assert.equal(moment([2011, 0, 3]).format('DDDo'), 'ọjọ́ 3', 'ọjọ́ 3');
63493 assert.equal(moment([2011, 0, 4]).format('DDDo'), 'ọjọ́ 4', 'ọjọ́ 4');
63494 assert.equal(moment([2011, 0, 5]).format('DDDo'), 'ọjọ́ 5', 'ọjọ́ 5');
63495 assert.equal(moment([2011, 0, 6]).format('DDDo'), 'ọjọ́ 6', 'ọjọ́ 6');
63496 assert.equal(moment([2011, 0, 7]).format('DDDo'), 'ọjọ́ 7', 'ọjọ́ 7');
63497 assert.equal(moment([2011, 0, 8]).format('DDDo'), 'ọjọ́ 8', 'ọjọ́ 8');
63498 assert.equal(moment([2011, 0, 9]).format('DDDo'), 'ọjọ́ 9', 'ọjọ́ 9');
63499 assert.equal(moment([2011, 0, 10]).format('DDDo'), 'ọjọ́ 10', 'ọjọ́ 10');
63500
63501 assert.equal(moment([2011, 0, 11]).format('DDDo'), 'ọjọ́ 11', 'ọjọ́ 11');
63502 assert.equal(moment([2011, 0, 12]).format('DDDo'), 'ọjọ́ 12', 'ọjọ́ 12');
63503 assert.equal(moment([2011, 0, 13]).format('DDDo'), 'ọjọ́ 13', 'ọjọ́ 13');
63504 assert.equal(moment([2011, 0, 14]).format('DDDo'), 'ọjọ́ 14', 'ọjọ́ 14');
63505 assert.equal(moment([2011, 0, 15]).format('DDDo'), 'ọjọ́ 15', 'ọjọ́ 15');
63506 assert.equal(moment([2011, 0, 16]).format('DDDo'), 'ọjọ́ 16', 'ọjọ́ 16');
63507 assert.equal(moment([2011, 0, 17]).format('DDDo'), 'ọjọ́ 17', 'ọjọ́ 17');
63508 assert.equal(moment([2011, 0, 18]).format('DDDo'), 'ọjọ́ 18', 'ọjọ́ 18');
63509 assert.equal(moment([2011, 0, 19]).format('DDDo'), 'ọjọ́ 19', 'ọjọ́ 19');
63510 assert.equal(moment([2011, 0, 20]).format('DDDo'), 'ọjọ́ 20', 'ọjọ́ 20');
63511
63512 assert.equal(moment([2011, 0, 21]).format('DDDo'), 'ọjọ́ 21', 'ọjọ́ 21');
63513 assert.equal(moment([2011, 0, 22]).format('DDDo'), 'ọjọ́ 22', 'ọjọ́ 22');
63514 assert.equal(moment([2011, 0, 23]).format('DDDo'), 'ọjọ́ 23', 'ọjọ́ 23');
63515 assert.equal(moment([2011, 0, 24]).format('DDDo'), 'ọjọ́ 24', 'ọjọ́ 24');
63516 assert.equal(moment([2011, 0, 25]).format('DDDo'), 'ọjọ́ 25', 'ọjọ́ 25');
63517 assert.equal(moment([2011, 0, 26]).format('DDDo'), 'ọjọ́ 26', 'ọjọ́ 26');
63518 assert.equal(moment([2011, 0, 27]).format('DDDo'), 'ọjọ́ 27', 'ọjọ́ 27');
63519 assert.equal(moment([2011, 0, 28]).format('DDDo'), 'ọjọ́ 28', 'ọjọ́ 28');
63520 assert.equal(moment([2011, 0, 29]).format('DDDo'), 'ọjọ́ 29', 'ọjọ́ 29');
63521 assert.equal(moment([2011, 0, 30]).format('DDDo'), 'ọjọ́ 30', 'ọjọ́ 30');
63522
63523 assert.equal(moment([2011, 0, 31]).format('DDDo'), 'ọjọ́ 31', 'ọjọ́ 31');
63524 });
63525
63526 test('format month', function (assert) {
63527 var expected = 'Sẹ́rẹ́ Sẹ́r_Èrèlè Èrl_Ẹrẹ̀nà Ẹrn_Ìgbé Ìgb_Èbibi Èbi_Òkùdu Òkù_Agẹmo Agẹ_Ògún Ògú_Owewe Owe_Ọ̀wàrà Ọ̀wà_Bélú Bél_Ọ̀pẹ̀̀ Ọ̀pẹ̀̀'.split('_'),
63528 i;
63529 for (i = 0; i < expected.length; i++) {
63530 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
63531 }
63532 });
63533
63534 test('format week', function (assert) {
63535 var expected = 'Àìkú Àìk Àì_Ajé Ajé Aj_Ìsẹ́gun Ìsẹ́ Ìs_Ọjọ́rú Ọjr Ọr_Ọjọ́bọ Ọjb Ọb_Ẹtì Ẹtì Ẹt_Àbámẹ́ta Àbá Àb'.split('_'),
63536 i;
63537 for (i = 0; i < expected.length; i++) {
63538 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
63539 }
63540 });
63541
63542 test('from', function (assert) {
63543 var start = moment([2007, 1, 28]);
63544 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ìsẹjú aayá die', '44 seconds = ìsẹjú aayá die');
63545 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ìsẹjú kan', '45 seconds = ìsẹjú kan');
63546 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ìsẹjú kan', '89 seconds = a minute');
63547 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), 'ìsẹjú 2', '90 seconds = ìsẹjú 2');
63548 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), 'ìsẹjú 44', 'ìsẹjú 44 = ìsẹjú 44');
63549 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'wákati kan', 'ìsẹjú 45 = wákati kan');
63550 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'wákati kan', 'ìsẹjú 89 = wákati kan');
63551 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), 'wákati 2', 'ìsẹjú 90 = wákati 2');
63552 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), 'wákati 5', 'wákati 5 = wákati 5');
63553 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), 'wákati 21', 'wákati 21 = wákati 21');
63554 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ọjọ́ kan', '22 wákati = ọjọ́ kan');
63555 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ọjọ́ kan', '35 wákati = ọjọ́ kan');
63556 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), 'ọjọ́ 2', 'wákati 36 = ọjọ́ 2');
63557 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ọjọ́ kan', '1 = ọjọ́ kan');
63558 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), 'ọjọ́ 5', 'ọjọ́ 5 = ọjọ́ 5');
63559 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), 'ọjọ́ 25', 'ọjọ́ 25 = ọjọ́ 25');
63560 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'osù kan', 'ọjọ́ 26 = osù kan');
63561 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'osù kan', 'ọjọ́ 30 = osù kan');
63562 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'osù kan', 'ọjọ́ 43 = osù kan');
63563 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), 'osù 2', 'ọjọ́ 46 = osù 2');
63564 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), 'osù 2', 'ọjọ́ 75 = osù 2');
63565 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), 'osù 3', 'ọjọ́ 76 = osù 3');
63566 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'osù kan', 'osù 1 = osù kan');
63567 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), 'osù 5', 'osù 5 = osù 5');
63568 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ọdún kan', 'ọjọ 345 = ọdún kan');
63569 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), 'ọdún 2', 'ọjọ 548 = ọdún 2');
63570 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ọdún kan', 'ọdún 1 = ọdún kan');
63571 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), 'ọdún 5', 'ọdún 5 = ọdún 5');
63572 });
63573
63574 test('suffix', function (assert) {
63575 assert.equal(moment(30000).from(0), 'ní ìsẹjú aayá die', 'prefix');
63576 assert.equal(moment(0).from(30000), 'ìsẹjú aayá die kọjá', 'suffix');
63577 });
63578
63579 test('now from now', function (assert) {
63580 assert.equal(moment().fromNow(), 'ìsẹjú aayá die kọjá', 'now from now should display as in the past');
63581 });
63582
63583 test('fromNow', function (assert) {
63584 assert.equal(moment().add({s: 30}).fromNow(), 'ní ìsẹjú aayá die', 'ní ìsẹjú aayá die');
63585 assert.equal(moment().add({d: 5}).fromNow(), 'ní ọjọ́ 5', 'ní ọjọ́ 5');
63586 });
63587
63588 test('calendar day', function (assert) {
63589 var a = moment().hours(12).minutes(0).seconds(0);
63590
63591 assert.equal(moment(a).calendar(), 'Ònì ni 12:00 PM', 'today at the same time');
63592 assert.equal(moment(a).add({m: 25}).calendar(), 'Ònì ni 12:25 PM', 'Now plus 25 min');
63593 assert.equal(moment(a).add({h: 1}).calendar(), 'Ònì ni 1:00 PM', 'Now plus 1 hour');
63594 assert.equal(moment(a).add({d: 1}).calendar(), 'Ọ̀la ni 12:00 PM', 'tomorrow at the same time');
63595 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Ònì ni 11:00 AM', 'Now minus 1 hour');
63596 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Àna ni 12:00 PM', 'yesterday at the same time');
63597 });
63598
63599 test('calendar next week', function (assert) {
63600 var i, m;
516f5f67 63601
db71a655
KM
63602 for (i = 2; i < 7; i++) {
63603 m = moment().add({d: i});
63604 assert.equal(m.calendar(), m.format('dddd [Ọsẹ̀ tón\'bọ] [ni] LT'), 'Today + ' + i + ' days current time');
63605 m.hours(0).minutes(0).seconds(0).milliseconds(0);
63606 assert.equal(m.calendar(), m.format('dddd [Ọsẹ̀ tón\'bọ] [ni] LT'), 'Today + ' + i + ' days beginning of day');
63607 m.hours(23).minutes(59).seconds(59).milliseconds(999);
63608 assert.equal(m.calendar(), m.format('dddd [Ọsẹ̀ tón\'bọ] [ni] LT'), 'Today + ' + i + ' days end of day');
c74a101d 63609 }
db71a655
KM
63610 });
63611
63612 test('calendar last week', function (assert) {
63613 var i, m;
63614
63615 for (i = 2; i < 7; i++) {
63616 m = moment().subtract({d: i});
63617 assert.equal(m.calendar(), m.format('dddd [Ọsẹ̀ tólọ́] [ni] LT'), 'Today - ' + i + ' days current time');
63618 m.hours(0).minutes(0).seconds(0).milliseconds(0);
63619 assert.equal(m.calendar(), m.format('dddd [Ọsẹ̀ tólọ́] [ni] LT'), 'Today - ' + i + ' days beginning of day');
63620 m.hours(23).minutes(59).seconds(59).milliseconds(999);
63621 assert.equal(m.calendar(), m.format('dddd [Ọsẹ̀ tólọ́] [ni] LT'), 'Today - ' + i + ' days end of day');
c74a101d 63622 }
db71a655 63623 });
c74a101d 63624
db71a655
KM
63625 test('calendar all else', function (assert) {
63626 var weeksAgo = moment().subtract({w: 1}),
63627 weeksFromNow = moment().add({w: 1});
c74a101d 63628
db71a655
KM
63629 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
63630 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
c74a101d 63631
db71a655
KM
63632 weeksAgo = moment().subtract({w: 2});
63633 weeksFromNow = moment().add({w: 2});
c74a101d 63634
db71a655
KM
63635 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
63636 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
63637 });
63638
63639 test('weeks year starting sunday format', function (assert) {
63640 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 ọjọ́ 52', 'Jan 1 2012 should be week 52');
63641 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 ọjọ́ 1', 'Jan 2 2012 should be week 1');
63642 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 ọjọ́ 1', 'Jan 8 2012 should be week 1');
63643 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 ọjọ́ 2', 'Jan 9 2012 should be week 2');
63644 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 ọjọ́ 2', 'Jan 15 2012 should be week 2');
63645 });
73f3c911
IC
63646
63647})));
c74a101d 63648
c74a101d 63649
b135bf1a
IC
63650;(function (global, factory) {
63651 typeof exports === 'object' && typeof module !== 'undefined'
63652 && typeof require === 'function' ? factory(require('../../moment')) :
63653 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
63654 factory(global.moment)
73f3c911 63655}(this, (function (moment) { 'use strict';
b135bf1a 63656
db71a655
KM
63657 function each(array, callback) {
63658 var i;
63659 for (i = 0; i < array.length; i++) {
63660 callback(array[i], i, array);
63661 }
b135bf1a 63662 }
c74a101d 63663
c58511b9
KM
63664 function setupDeprecationHandler(test, moment$$1, scope) {
63665 test._expectedDeprecations = null;
63666 test._observedDeprecations = null;
63667 test._oldSupress = moment$$1.suppressDeprecationWarnings;
63668 moment$$1.suppressDeprecationWarnings = true;
63669 test.expectedDeprecations = function () {
63670 test._expectedDeprecations = arguments;
63671 test._observedDeprecations = [];
63672 };
63673 moment$$1.deprecationHandler = function (name, msg) {
63674 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
63675 if (deprecationId === -1) {
63676 throw new Error('Unexpected deprecation thrown name=' +
63677 name + ' msg=' + msg);
63678 }
63679 test._observedDeprecations[deprecationId] = 1;
63680 };
63681 }
63682
63683 function teardownDeprecationHandler(test, moment$$1, scope) {
63684 moment$$1.suppressDeprecationWarnings = test._oldSupress;
63685
63686 if (test._expectedDeprecations != null) {
63687 var missedDeprecations = [];
63688 each(test._expectedDeprecations, function (deprecationPattern, id) {
63689 if (test._observedDeprecations[id] !== 1) {
63690 missedDeprecations.push(deprecationPattern);
63691 }
63692 });
63693 if (missedDeprecations.length !== 0) {
63694 throw new Error('Expected deprecation warnings did not happen: ' +
63695 missedDeprecations.join(' '));
63696 }
63697 }
63698 }
63699
63700 function matchedDeprecation(name, msg, deprecations) {
63701 if (deprecations == null) {
63702 return -1;
63703 }
63704 for (var i = 0; i < deprecations.length; ++i) {
63705 if (name != null && name === deprecations[i]) {
63706 return i;
63707 }
63708 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
63709 return i;
63710 }
63711 }
63712 return -1;
63713 }
63714
63715 /*global QUnit:false*/
63716
63717 var test = QUnit.test;
63718
db71a655
KM
63719 function objectKeys(obj) {
63720 if (Object.keys) {
63721 return Object.keys(obj);
63722 } else {
63723 // IE8
63724 var res = [], i;
63725 for (i in obj) {
63726 if (obj.hasOwnProperty(i)) {
63727 res.push(i);
63728 }
c74a101d 63729 }
db71a655 63730 return res;
c74a101d 63731 }
b135bf1a 63732 }
c74a101d 63733
db71a655 63734 // Pick the first defined of two or three arguments.
73f3c911 63735
db71a655
KM
63736 function defineCommonLocaleTests(locale, options) {
63737 test('lenient day of month ordinal parsing', function (assert) {
63738 var i, ordinalStr, testMoment;
63739 for (i = 1; i <= 31; ++i) {
63740 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
63741 testMoment = moment(ordinalStr, 'YYYY MM Do');
63742 assert.equal(testMoment.year(), 2014,
63743 'lenient day of month ordinal parsing ' + i + ' year check');
63744 assert.equal(testMoment.month(), 0,
63745 'lenient day of month ordinal parsing ' + i + ' month check');
63746 assert.equal(testMoment.date(), i,
63747 'lenient day of month ordinal parsing ' + i + ' date check');
63748 }
63749 });
73f3c911 63750
db71a655
KM
63751 test('lenient day of month ordinal parsing of number', function (assert) {
63752 var i, testMoment;
63753 for (i = 1; i <= 31; ++i) {
63754 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
63755 assert.equal(testMoment.year(), 2014,
63756 'lenient day of month ordinal parsing of number ' + i + ' year check');
63757 assert.equal(testMoment.month(), 0,
63758 'lenient day of month ordinal parsing of number ' + i + ' month check');
63759 assert.equal(testMoment.date(), i,
63760 'lenient day of month ordinal parsing of number ' + i + ' date check');
63761 }
63762 });
c74a101d 63763
db71a655
KM
63764 test('strict day of month ordinal parsing', function (assert) {
63765 var i, ordinalStr, testMoment;
63766 for (i = 1; i <= 31; ++i) {
63767 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
63768 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
63769 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
63770 }
63771 });
c74a101d 63772
db71a655
KM
63773 test('meridiem invariant', function (assert) {
63774 var h, m, t1, t2;
63775 for (h = 0; h < 24; ++h) {
63776 for (m = 0; m < 60; m += 15) {
63777 t1 = moment.utc([2000, 0, 1, h, m]);
63778 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
63779 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
63780 'meridiem at ' + t1.format('HH:mm'));
63781 }
63782 }
63783 });
63784
63785 test('date format correctness', function (assert) {
63786 var data, tokens;
63787 data = moment.localeData()._longDateFormat;
63788 tokens = objectKeys(data);
63789 each(tokens, function (srchToken) {
63790 // Check each format string to make sure it does not contain any
63791 // tokens that need to be expanded.
63792 each(tokens, function (baseToken) {
63793 // strip escaped sequences
63794 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
63795 assert.equal(false, !!~format.indexOf(srchToken),
63796 'contains ' + srchToken + ' in ' + baseToken);
63797 });
73f3c911 63798 });
b135bf1a
IC
63799 });
63800
db71a655
KM
63801 test('month parsing correctness', function (assert) {
63802 var i, m;
63803
63804 if (locale === 'tr') {
63805 // I can't fix it :(
c58511b9 63806 assert.expect(0);
db71a655
KM
63807 return;
63808 }
63809 function tester(format) {
63810 var r;
63811 r = moment(m.format(format), format);
63812 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
63813 if (locale !== 'ka') {
63814 r = moment(m.format(format).toLocaleUpperCase(), format);
63815 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
63816 }
db71a655
KM
63817 r = moment(m.format(format).toLocaleLowerCase(), format);
63818 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
63819
63820 r = moment(m.format(format), format, true);
63821 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
63822 if (locale !== 'ka') {
63823 r = moment(m.format(format).toLocaleUpperCase(), format, true);
63824 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
63825 }
db71a655
KM
63826 r = moment(m.format(format).toLocaleLowerCase(), format, true);
63827 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
63828 }
63829
63830 for (i = 0; i < 12; ++i) {
63831 m = moment([2015, i, 15, 18]);
63832 tester('MMM');
63833 tester('MMM.');
63834 tester('MMMM');
63835 tester('MMMM.');
63836 }
63837 });
b135bf1a 63838
db71a655
KM
63839 test('weekday parsing correctness', function (assert) {
63840 var i, m;
63841
96d0d679 63842 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
63843 // tr, az: There is a lower-case letter (ı), that converted to
63844 // upper then lower changes to i
63845 // ro: there is the letter ț which behaves weird under IE8
63846 // mt: letter Ħ
96d0d679 63847 // ga: month with spaces
c58511b9 63848 assert.expect(0);
db71a655
KM
63849 return;
63850 }
63851 function tester(format) {
63852 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
63853 r = moment(m.format(format), format);
63854 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
63855 if (locale !== 'ka') {
63856 r = moment(m.format(format).toLocaleUpperCase(), format);
63857 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
63858 }
db71a655
KM
63859 r = moment(m.format(format).toLocaleLowerCase(), format);
63860 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
63861 r = moment(m.format(format), format, true);
63862 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
63863 if (locale !== 'ka') {
63864 r = moment(m.format(format).toLocaleUpperCase(), format, true);
63865 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
63866 }
db71a655
KM
63867 r = moment(m.format(format).toLocaleLowerCase(), format, true);
63868 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
63869 }
63870
63871 for (i = 0; i < 7; ++i) {
63872 m = moment.utc([2015, 0, i + 1, 18]);
63873 tester('dd');
63874 tester('ddd');
63875 tester('dddd');
63876 }
63877 });
b135bf1a 63878
db71a655
KM
63879 test('valid localeData', function (assert) {
63880 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
63881 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
63882 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
63883 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
63884 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
63885 });
96d0d679
KM
63886
63887 test('localeData weekdays can localeSort', function (assert) {
63888 var weekdays = moment().localeData().weekdays();
63889 var weekdaysShort = moment().localeData().weekdaysShort();
63890 var weekdaysMin = moment().localeData().weekdaysMin();
63891 var shift = moment().localeData()._week.dow;
63892 assert.deepEqual(
63893 moment().localeData().weekdays(true),
63894 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
63895 'weekdays should localeSort');
63896 assert.deepEqual(
63897 moment().localeData().weekdaysShort(true),
63898 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
63899 'weekdaysShort should localeSort');
63900 assert.deepEqual(
63901 moment().localeData().weekdaysMin(true),
63902 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
63903 'weekdaysMin should localeSort');
63904 });
db71a655
KM
63905 }
63906
db71a655 63907 /*global QUnit:false*/
73f3c911 63908
db71a655
KM
63909 function localeModule (name, lifecycle) {
63910 QUnit.module('locale:' + name, {
c58511b9 63911 beforeEach : function () {
db71a655
KM
63912 moment.locale(name);
63913 moment.createFromInputFallback = function (config) {
63914 throw new Error('input not handled by moment: ' + config._i);
63915 };
63916 setupDeprecationHandler(test, moment, 'locale');
63917 if (lifecycle && lifecycle.setup) {
63918 lifecycle.setup();
63919 }
63920 },
c58511b9 63921 afterEach : function () {
db71a655
KM
63922 moment.locale('en');
63923 teardownDeprecationHandler(test, moment, 'locale');
63924 if (lifecycle && lifecycle.teardown) {
63925 lifecycle.teardown();
63926 }
d6651c21 63927 }
73f3c911 63928 });
db71a655
KM
63929 defineCommonLocaleTests(name, -1, -1);
63930 }
63931
63932 localeModule('zh-cn');
63933
63934 test('parse', function (assert) {
63935 var tests = '一月 1月_二月 2月_三月 3月_四月 4月_五月 5月_六月 6月_七月 7月_八月 8月_九月 9月_十月 10月_十一月 11月_十二月 12月'.split('_'), i;
63936
63937 function equalTest(input, mmm, i) {
63938 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
63939 }
63940
63941 for (i = 0; i < 12; i++) {
63942 tests[i] = tests[i].split(' ');
63943 equalTest(tests[i][0], 'MMM', i);
63944 equalTest(tests[i][1], 'MMM', i);
63945 equalTest(tests[i][0], 'MMMM', i);
63946 equalTest(tests[i][1], 'MMMM', i);
63947 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
63948 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
63949 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
63950 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
63951 }
63952 });
63953
63954 test('format', function (assert) {
63955 var a = [
63956 ['dddd, MMMM Do YYYY, a h:mm:ss', '星期日, 二月 14日 2010, 下午 3:25:50'],
63957 ['ddd, Ah', '周日, 下午3'],
63958 ['M Mo MM MMMM MMM', '2 2月 02 二月 2月'],
63959 ['YYYY YY', '2010 10'],
63960 ['D Do DD', '14 14日 14'],
63961 ['d do dddd ddd dd', '0 0日 星期日 周日 日'],
63962 ['DDD DDDo DDDD', '45 45日 045'],
63963 ['w wo ww', '6 6周 06'],
63964 ['h hh', '3 03'],
63965 ['H HH', '15 15'],
63966 ['m mm', '25 25'],
63967 ['s ss', '50 50'],
63968 ['a A', '下午 下午'],
63969 ['[这年的第] DDDo', '这年的第 45日'],
63970 ['LTS', '15:25:50'],
63971 ['L', '2010/02/14'],
63972 ['LL', '2010年2月14日'],
63973 ['LLL', '2010年2月14日下午3点25分'],
63974 ['LLLL', '2010年2月14日星期日下午3点25分'],
63975 ['l', '2010/2/14'],
63976 ['ll', '2010年2月14日'],
63977 ['lll', '2010年2月14日 15:25'],
63978 ['llll', '2010年2月14日星期日 15:25']
63979 ],
63980 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
63981 i;
63982
63983 for (i = 0; i < a.length; i++) {
63984 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
63985 }
63986 });
63987
63988 test('format month', function (assert) {
63989 var expected = '一月 1月_二月 2月_三月 3月_四月 4月_五月 5月_六月 6月_七月 7月_八月 8月_九月 9月_十月 10月_十一月 11月_十二月 12月'.split('_'), i;
63990
63991 for (i = 0; i < expected.length; i++) {
63992 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
63993 }
63994 });
63995
63996 test('format week', function (assert) {
63997 var expected = '星期日 周日 日_星期一 周一 一_星期二 周二 二_星期三 周三 三_星期四 周四 四_星期五 周五 五_星期六 周六 六'.split('_'), i;
63998
63999 for (i = 0; i < expected.length; i++) {
64000 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
64001 }
64002 });
64003
64004 test('from', function (assert) {
64005 var start = moment([2007, 1, 28]);
64006 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), '几秒', '44 seconds = a few seconds');
64007 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '1 分钟', '45 seconds = a minute');
64008 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '1 分钟', '89 seconds = a minute');
64009 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 分钟', '90 seconds = 2 minutes');
64010 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 分钟', '44 minutes = 44 minutes');
64011 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '1 小时', '45 minutes = an hour');
64012 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '1 小时', '89 minutes = an hour');
64013 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 小时', '90 minutes = 2 hours');
64014 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 小时', '5 hours = 5 hours');
64015 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 小时', '21 hours = 21 hours');
64016 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '1 天', '22 hours = a day');
64017 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '1 天', '35 hours = a day');
64018 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 天', '36 hours = 2 days');
64019 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '1 天', '1 day = a day');
64020 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 天', '5 days = 5 days');
64021 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 天', '25 days = 25 days');
64022 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '1 个月', '26 days = a month');
64023 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '1 个月', '30 days = a month');
64024 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '1 个月', '43 days = a month');
64025 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 个月', '46 days = 2 months');
64026 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 个月', '75 days = 2 months');
64027 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 个月', '76 days = 3 months');
64028 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '1 个月', '1 month = a month');
64029 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 个月', '5 months = 5 months');
64030 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '1 年', '345 days = a year');
64031 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 年', '548 days = 2 years');
64032 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '1 年', '1 year = a year');
64033 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 年', '5 years = 5 years');
64034 });
64035
64036 test('suffix', function (assert) {
64037 assert.equal(moment(30000).from(0), '几秒内', 'prefix');
64038 assert.equal(moment(0).from(30000), '几秒前', 'suffix');
64039 });
64040
64041 test('now from now', function (assert) {
64042 assert.equal(moment().fromNow(), '几秒前', 'now from now should display as in the past');
64043 });
64044
64045 test('fromNow', function (assert) {
64046 assert.equal(moment().add({s: 30}).fromNow(), '几秒内', 'in a few seconds');
64047 assert.equal(moment().add({d: 5}).fromNow(), '5 天内', 'in 5 days');
64048 });
64049
64050 test('calendar day', function (assert) {
64051 var a = moment().hours(12).minutes(0).seconds(0);
64052
64053 assert.equal(moment(a).calendar(), '今天12:00', 'today at the same time');
64054 assert.equal(moment(a).add({m: 25}).calendar(), '今天12:25', 'Now plus 25 min');
64055 assert.equal(moment(a).add({h: 1}).calendar(), '今天13:00', 'Now plus 1 hour');
64056 assert.equal(moment(a).add({d: 1}).calendar(), '明天12:00', 'tomorrow at the same time');
64057 assert.equal(moment(a).subtract({h: 1}).calendar(), '今天11:00', 'Now minus 1 hour');
64058 assert.equal(moment(a).subtract({d: 1}).calendar(), '昨天12:00', 'yesterday at the same time');
64059 });
64060
64061 test('calendar next week', function (assert) {
64062 var i, m;
64063 for (i = 2; i < 7; i++) {
64064 m = moment().add({d: i});
64065 assert.equal(m.calendar(), m.format('[下]ddddLT'), 'Today + ' + i + ' days current time');
64066 m.hours(0).minutes(0).seconds(0).milliseconds(0);
64067 assert.equal(m.calendar(), m.format('[下]ddddLT'), 'Today + ' + i + ' days beginning of day');
64068 m.hours(23).minutes(59).seconds(59).milliseconds(999);
64069 assert.equal(m.calendar(), m.format('[下]ddddLT'), 'Today + ' + i + ' days end of day');
d6651c21 64070 }
db71a655 64071 });
73f3c911 64072
db71a655
KM
64073 test('calendar last week', function (assert) {
64074 var i, m;
64075 for (i = 2; i < 7; i++) {
64076 m = moment().subtract({d: i});
64077 assert.equal(m.calendar(), m.format('[上]ddddLT'), 'Today - ' + i + ' days current time');
64078 m.hours(0).minutes(0).seconds(0).milliseconds(0);
64079 assert.equal(m.calendar(), m.format('[上]ddddLT'), 'Today - ' + i + ' days beginning of day');
64080 m.hours(23).minutes(59).seconds(59).milliseconds(999);
64081 assert.equal(m.calendar(), m.format('[上]ddddLT'), 'Today - ' + i + ' days end of day');
73f3c911 64082 }
db71a655 64083 });
c74a101d 64084
db71a655
KM
64085 test('calendar all else', function (assert) {
64086 var weeksAgo = moment().subtract({w: 1}),
64087 weeksFromNow = moment().add({w: 1});
c74a101d 64088
db71a655
KM
64089 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
64090 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
c74a101d 64091
db71a655
KM
64092 weeksAgo = moment().subtract({w: 2});
64093 weeksFromNow = moment().add({w: 2});
c74a101d 64094
db71a655
KM
64095 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
64096 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
64097 });
64098
64099 test('meridiem', function (assert) {
64100 assert.equal(moment([2011, 2, 23, 0, 0]).format('A'), '凌晨', 'before dawn');
64101 assert.equal(moment([2011, 2, 23, 6, 0]).format('A'), '早上', 'morning');
64102 assert.equal(moment([2011, 2, 23, 9, 0]).format('A'), '上午', 'before noon');
64103 assert.equal(moment([2011, 2, 23, 12, 0]).format('A'), '中午', 'noon');
64104 assert.equal(moment([2011, 2, 23, 13, 0]).format('A'), '下午', 'afternoon');
64105 assert.equal(moment([2011, 2, 23, 18, 0]).format('A'), '晚上', 'night');
64106 });
64107
64108 test('weeks year starting sunday format', function (assert) {
64109 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52周', 'Jan 1 2012 应该是第52周');
64110 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1周', 'Jan 7 2012 应该是第 1周');
64111 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2周', 'Jan 14 2012 应该是第 2周');
64112 });
73f3c911
IC
64113
64114})));
516f5f67 64115
516f5f67 64116
c74a101d
IC
64117;(function (global, factory) {
64118 typeof exports === 'object' && typeof module !== 'undefined'
64119 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
64120 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
64121 factory(global.moment)
73f3c911 64122}(this, (function (moment) { 'use strict';
516f5f67 64123
db71a655
KM
64124 function each(array, callback) {
64125 var i;
64126 for (i = 0; i < array.length; i++) {
64127 callback(array[i], i, array);
64128 }
b135bf1a
IC
64129 }
64130
c58511b9
KM
64131 function setupDeprecationHandler(test, moment$$1, scope) {
64132 test._expectedDeprecations = null;
64133 test._observedDeprecations = null;
64134 test._oldSupress = moment$$1.suppressDeprecationWarnings;
64135 moment$$1.suppressDeprecationWarnings = true;
64136 test.expectedDeprecations = function () {
64137 test._expectedDeprecations = arguments;
64138 test._observedDeprecations = [];
64139 };
64140 moment$$1.deprecationHandler = function (name, msg) {
64141 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
64142 if (deprecationId === -1) {
64143 throw new Error('Unexpected deprecation thrown name=' +
64144 name + ' msg=' + msg);
64145 }
64146 test._observedDeprecations[deprecationId] = 1;
64147 };
64148 }
64149
64150 function teardownDeprecationHandler(test, moment$$1, scope) {
64151 moment$$1.suppressDeprecationWarnings = test._oldSupress;
64152
64153 if (test._expectedDeprecations != null) {
64154 var missedDeprecations = [];
64155 each(test._expectedDeprecations, function (deprecationPattern, id) {
64156 if (test._observedDeprecations[id] !== 1) {
64157 missedDeprecations.push(deprecationPattern);
64158 }
64159 });
64160 if (missedDeprecations.length !== 0) {
64161 throw new Error('Expected deprecation warnings did not happen: ' +
64162 missedDeprecations.join(' '));
64163 }
64164 }
64165 }
64166
64167 function matchedDeprecation(name, msg, deprecations) {
64168 if (deprecations == null) {
64169 return -1;
64170 }
64171 for (var i = 0; i < deprecations.length; ++i) {
64172 if (name != null && name === deprecations[i]) {
64173 return i;
64174 }
64175 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
64176 return i;
64177 }
64178 }
64179 return -1;
64180 }
64181
64182 /*global QUnit:false*/
64183
64184 var test = QUnit.test;
64185
db71a655
KM
64186 function objectKeys(obj) {
64187 if (Object.keys) {
64188 return Object.keys(obj);
64189 } else {
64190 // IE8
64191 var res = [], i;
64192 for (i in obj) {
64193 if (obj.hasOwnProperty(i)) {
64194 res.push(i);
64195 }
b135bf1a 64196 }
db71a655 64197 return res;
b135bf1a 64198 }
b135bf1a
IC
64199 }
64200
db71a655 64201 // Pick the first defined of two or three arguments.
b135bf1a 64202
db71a655
KM
64203 function defineCommonLocaleTests(locale, options) {
64204 test('lenient day of month ordinal parsing', function (assert) {
64205 var i, ordinalStr, testMoment;
64206 for (i = 1; i <= 31; ++i) {
64207 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
64208 testMoment = moment(ordinalStr, 'YYYY MM Do');
64209 assert.equal(testMoment.year(), 2014,
64210 'lenient day of month ordinal parsing ' + i + ' year check');
64211 assert.equal(testMoment.month(), 0,
64212 'lenient day of month ordinal parsing ' + i + ' month check');
64213 assert.equal(testMoment.date(), i,
64214 'lenient day of month ordinal parsing ' + i + ' date check');
64215 }
64216 });
b135bf1a 64217
db71a655
KM
64218 test('lenient day of month ordinal parsing of number', function (assert) {
64219 var i, testMoment;
64220 for (i = 1; i <= 31; ++i) {
64221 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
64222 assert.equal(testMoment.year(), 2014,
64223 'lenient day of month ordinal parsing of number ' + i + ' year check');
64224 assert.equal(testMoment.month(), 0,
64225 'lenient day of month ordinal parsing of number ' + i + ' month check');
64226 assert.equal(testMoment.date(), i,
64227 'lenient day of month ordinal parsing of number ' + i + ' date check');
64228 }
64229 });
b135bf1a 64230
db71a655
KM
64231 test('strict day of month ordinal parsing', function (assert) {
64232 var i, ordinalStr, testMoment;
64233 for (i = 1; i <= 31; ++i) {
64234 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
64235 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
64236 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
64237 }
64238 });
b135bf1a 64239
db71a655
KM
64240 test('meridiem invariant', function (assert) {
64241 var h, m, t1, t2;
64242 for (h = 0; h < 24; ++h) {
64243 for (m = 0; m < 60; m += 15) {
64244 t1 = moment.utc([2000, 0, 1, h, m]);
64245 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
64246 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
64247 'meridiem at ' + t1.format('HH:mm'));
64248 }
64249 }
64250 });
64251
64252 test('date format correctness', function (assert) {
64253 var data, tokens;
64254 data = moment.localeData()._longDateFormat;
64255 tokens = objectKeys(data);
64256 each(tokens, function (srchToken) {
64257 // Check each format string to make sure it does not contain any
64258 // tokens that need to be expanded.
64259 each(tokens, function (baseToken) {
64260 // strip escaped sequences
64261 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
64262 assert.equal(false, !!~format.indexOf(srchToken),
64263 'contains ' + srchToken + ' in ' + baseToken);
64264 });
b135bf1a
IC
64265 });
64266 });
d6651c21 64267
db71a655
KM
64268 test('month parsing correctness', function (assert) {
64269 var i, m;
64270
64271 if (locale === 'tr') {
64272 // I can't fix it :(
c58511b9 64273 assert.expect(0);
db71a655
KM
64274 return;
64275 }
64276 function tester(format) {
64277 var r;
64278 r = moment(m.format(format), format);
64279 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
64280 if (locale !== 'ka') {
64281 r = moment(m.format(format).toLocaleUpperCase(), format);
64282 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
64283 }
db71a655
KM
64284 r = moment(m.format(format).toLocaleLowerCase(), format);
64285 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
64286
64287 r = moment(m.format(format), format, true);
64288 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
64289 if (locale !== 'ka') {
64290 r = moment(m.format(format).toLocaleUpperCase(), format, true);
64291 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
64292 }
db71a655
KM
64293 r = moment(m.format(format).toLocaleLowerCase(), format, true);
64294 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
64295 }
64296
64297 for (i = 0; i < 12; ++i) {
64298 m = moment([2015, i, 15, 18]);
64299 tester('MMM');
64300 tester('MMM.');
64301 tester('MMMM');
64302 tester('MMMM.');
64303 }
64304 });
d6651c21 64305
db71a655
KM
64306 test('weekday parsing correctness', function (assert) {
64307 var i, m;
64308
96d0d679 64309 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
64310 // tr, az: There is a lower-case letter (ı), that converted to
64311 // upper then lower changes to i
64312 // ro: there is the letter ț which behaves weird under IE8
64313 // mt: letter Ħ
96d0d679 64314 // ga: month with spaces
c58511b9 64315 assert.expect(0);
db71a655
KM
64316 return;
64317 }
64318 function tester(format) {
64319 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
64320 r = moment(m.format(format), format);
64321 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
64322 if (locale !== 'ka') {
64323 r = moment(m.format(format).toLocaleUpperCase(), format);
64324 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
64325 }
db71a655
KM
64326 r = moment(m.format(format).toLocaleLowerCase(), format);
64327 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
64328 r = moment(m.format(format), format, true);
64329 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
64330 if (locale !== 'ka') {
64331 r = moment(m.format(format).toLocaleUpperCase(), format, true);
64332 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
64333 }
db71a655
KM
64334 r = moment(m.format(format).toLocaleLowerCase(), format, true);
64335 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
64336 }
64337
64338 for (i = 0; i < 7; ++i) {
64339 m = moment.utc([2015, 0, i + 1, 18]);
64340 tester('dd');
64341 tester('ddd');
64342 tester('dddd');
64343 }
64344 });
d6651c21 64345
db71a655
KM
64346 test('valid localeData', function (assert) {
64347 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
64348 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
64349 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
64350 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
64351 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
64352 });
96d0d679
KM
64353
64354 test('localeData weekdays can localeSort', function (assert) {
64355 var weekdays = moment().localeData().weekdays();
64356 var weekdaysShort = moment().localeData().weekdaysShort();
64357 var weekdaysMin = moment().localeData().weekdaysMin();
64358 var shift = moment().localeData()._week.dow;
64359 assert.deepEqual(
64360 moment().localeData().weekdays(true),
64361 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
64362 'weekdays should localeSort');
64363 assert.deepEqual(
64364 moment().localeData().weekdaysShort(true),
64365 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
64366 'weekdaysShort should localeSort');
64367 assert.deepEqual(
64368 moment().localeData().weekdaysMin(true),
64369 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
64370 'weekdaysMin should localeSort');
64371 });
db71a655 64372 }
d6651c21 64373
db71a655 64374 /*global QUnit:false*/
c74a101d 64375
db71a655
KM
64376 function localeModule (name, lifecycle) {
64377 QUnit.module('locale:' + name, {
c58511b9 64378 beforeEach : function () {
db71a655
KM
64379 moment.locale(name);
64380 moment.createFromInputFallback = function (config) {
64381 throw new Error('input not handled by moment: ' + config._i);
64382 };
64383 setupDeprecationHandler(test, moment, 'locale');
64384 if (lifecycle && lifecycle.setup) {
64385 lifecycle.setup();
64386 }
64387 },
c58511b9 64388 afterEach : function () {
db71a655
KM
64389 moment.locale('en');
64390 teardownDeprecationHandler(test, moment, 'locale');
64391 if (lifecycle && lifecycle.teardown) {
64392 lifecycle.teardown();
64393 }
516f5f67
IC
64394 }
64395 });
db71a655
KM
64396 defineCommonLocaleTests(name, -1, -1);
64397 }
64398
64399 localeModule('zh-hk');
64400
64401 test('parse', function (assert) {
64402 var tests = '一月 1月_二月 2月_三月 3月_四月 4月_五月 5月_六月 6月_七月 7月_八月 8月_九月 9月_十月 10月_十一月 11月_十二月 12月'.split('_'), i;
64403 function equalTest(input, mmm, i) {
64404 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
64405 }
64406 for (i = 0; i < 12; i++) {
64407 tests[i] = tests[i].split(' ');
64408 equalTest(tests[i][0], 'MMM', i);
64409 equalTest(tests[i][1], 'MMM', i);
64410 equalTest(tests[i][0], 'MMMM', i);
64411 equalTest(tests[i][1], 'MMMM', i);
64412 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
64413 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
64414 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
64415 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
64416 }
64417 });
64418
64419 test('format', function (assert) {
64420 var a = [
64421 ['dddd, MMMM Do YYYY, a h:mm:ss', '星期日, 二月 14日 2010, 下午 3:25:50'],
64422 ['ddd, Ah', '週日, 下午3'],
64423 ['M Mo MM MMMM MMM', '2 2月 02 二月 2月'],
64424 ['YYYY YY', '2010 10'],
64425 ['D Do DD', '14 14日 14'],
64426 ['d do dddd ddd dd', '0 0日 星期日 週日 日'],
64427 ['DDD DDDo DDDD', '45 45日 045'],
64428 ['w wo ww', '8 8週 08'],
64429 ['h hh', '3 03'],
64430 ['H HH', '15 15'],
64431 ['m mm', '25 25'],
64432 ['s ss', '50 50'],
64433 ['a A', '下午 下午'],
64434 ['[這年的第] DDDo', '這年的第 45日'],
64435 ['LTS', '15:25:50'],
64436 ['L', '2010/02/14'],
64437 ['LL', '2010年2月14日'],
64438 ['LLL', '2010年2月14日 15:25'],
64439 ['LLLL', '2010年2月14日星期日 15:25'],
64440 ['l', '2010/2/14'],
64441 ['ll', '2010年2月14日'],
64442 ['lll', '2010年2月14日 15:25'],
64443 ['llll', '2010年2月14日星期日 15:25']
64444 ],
64445 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
64446 i;
64447
64448 for (i = 0; i < a.length; i++) {
64449 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
64450 }
64451 });
64452
64453 test('format month', function (assert) {
64454 var expected = '一月 1月_二月 2月_三月 3月_四月 4月_五月 5月_六月 6月_七月 7月_八月 8月_九月 9月_十月 10月_十一月 11月_十二月 12月'.split('_'), i;
64455
64456 for (i = 0; i < expected.length; i++) {
64457 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
64458 }
64459 });
64460
64461 test('format week', function (assert) {
64462 var expected = '星期日 週日 日_星期一 週一 一_星期二 週二 二_星期三 週三 三_星期四 週四 四_星期五 週五 五_星期六 週六 六'.split('_'), i;
64463
64464 for (i = 0; i < expected.length; i++) {
64465 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
64466 }
64467 });
64468
64469 test('from', function (assert) {
64470 var start = moment([2007, 1, 28]);
64471 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), '幾秒', '44 seconds = a few seconds');
64472 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '1 分鐘', '45 seconds = a minute');
64473 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '1 分鐘', '89 seconds = a minute');
64474 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 分鐘', '90 seconds = 2 minutes');
64475 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 分鐘', '44 minutes = 44 minutes');
64476 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '1 小時', '45 minutes = an hour');
64477 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '1 小時', '89 minutes = an hour');
64478 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 小時', '90 minutes = 2 hours');
64479 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 小時', '5 hours = 5 hours');
64480 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 小時', '21 hours = 21 hours');
64481 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '1 天', '22 hours = a day');
64482 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '1 天', '35 hours = a day');
64483 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 天', '36 hours = 2 days');
64484 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '1 天', '1 day = a day');
64485 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 天', '5 days = 5 days');
64486 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 天', '25 days = 25 days');
64487 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '1 個月', '26 days = a month');
64488 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '1 個月', '30 days = a month');
64489 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '1 個月', '43 days = a month');
64490 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 個月', '46 days = 2 months');
64491 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 個月', '75 days = 2 months');
64492 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 個月', '76 days = 3 months');
64493 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '1 個月', '1 month = a month');
64494 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 個月', '5 months = 5 months');
64495 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '1 年', '345 days = a year');
64496 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 年', '548 days = 2 years');
64497 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '1 年', '1 year = a year');
64498 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 年', '5 years = 5 years');
64499 });
64500
64501 test('suffix', function (assert) {
64502 assert.equal(moment(30000).from(0), '幾秒內', 'prefix');
64503 assert.equal(moment(0).from(30000), '幾秒前', 'suffix');
64504 });
64505
64506 test('now from now', function (assert) {
64507 assert.equal(moment().fromNow(), '幾秒前', 'now from now should display as in the past');
64508 });
64509
64510 test('fromNow', function (assert) {
64511 assert.equal(moment().add({s: 30}).fromNow(), '幾秒內', 'in a few seconds');
64512 assert.equal(moment().add({d: 5}).fromNow(), '5 天內', 'in 5 days');
64513 });
64514
64515 test('calendar day', function (assert) {
64516 var a = moment().hours(12).minutes(0).seconds(0);
64517
64518 assert.equal(moment(a).calendar(), '今天12:00', 'today at the same time');
64519 assert.equal(moment(a).add({m: 25}).calendar(), '今天12:25', 'Now plus 25 min');
64520 assert.equal(moment(a).add({h: 1}).calendar(), '今天13:00', 'Now plus 1 hour');
64521 assert.equal(moment(a).add({d: 1}).calendar(), '明天12:00', 'tomorrow at the same time');
64522 assert.equal(moment(a).subtract({h: 1}).calendar(), '今天11:00', 'Now minus 1 hour');
64523 assert.equal(moment(a).subtract({d: 1}).calendar(), '昨天12:00', 'yesterday at the same time');
64524 });
64525
64526 test('calendar next week', function (assert) {
64527 var i, m;
64528 for (i = 2; i < 7; i++) {
64529 m = moment().add({d: i});
64530 assert.equal(m.calendar(), m.format('[下]ddddLT'), 'Today + ' + i + ' days current time');
64531 m.hours(0).minutes(0).seconds(0).milliseconds(0);
64532 assert.equal(m.calendar(), m.format('[下]ddddLT'), 'Today + ' + i + ' days beginning of day');
64533 m.hours(23).minutes(59).seconds(59).milliseconds(999);
64534 assert.equal(m.calendar(), m.format('[下]ddddLT'), 'Today + ' + i + ' days end of day');
73f3c911 64535 }
db71a655 64536 });
516f5f67 64537
db71a655
KM
64538 test('calendar last week', function (assert) {
64539 var i, m;
64540 for (i = 2; i < 7; i++) {
64541 m = moment().subtract({d: i});
64542 assert.equal(m.calendar(), m.format('[上]ddddLT'), 'Today - ' + i + ' days current time');
64543 m.hours(0).minutes(0).seconds(0).milliseconds(0);
64544 assert.equal(m.calendar(), m.format('[上]ddddLT'), 'Today - ' + i + ' days beginning of day');
64545 m.hours(23).minutes(59).seconds(59).milliseconds(999);
64546 assert.equal(m.calendar(), m.format('[上]ddddLT'), 'Today - ' + i + ' days end of day');
516f5f67 64547 }
db71a655 64548 });
516f5f67 64549
db71a655
KM
64550 test('calendar all else', function (assert) {
64551 var weeksAgo = moment().subtract({w: 1}),
64552 weeksFromNow = moment().add({w: 1});
516f5f67 64553
db71a655
KM
64554 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
64555 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
516f5f67 64556
db71a655
KM
64557 weeksAgo = moment().subtract({w: 2});
64558 weeksFromNow = moment().add({w: 2});
516f5f67 64559
db71a655
KM
64560 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
64561 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
64562 });
64563
64564 test('meridiem', function (assert) {
64565 assert.equal(moment([2011, 2, 23, 0, 0]).format('a'), '凌晨', 'before dawn');
64566 assert.equal(moment([2011, 2, 23, 6, 0]).format('a'), '早上', 'morning');
64567 assert.equal(moment([2011, 2, 23, 9, 0]).format('a'), '上午', 'before noon');
64568 assert.equal(moment([2011, 2, 23, 12, 0]).format('a'), '中午', 'noon');
64569 assert.equal(moment([2011, 2, 23, 13, 0]).format('a'), '下午', 'after noon');
64570 assert.equal(moment([2011, 2, 23, 18, 0]).format('a'), '晚上', 'night');
64571
64572 assert.equal(moment([2011, 2, 23, 0, 0]).format('A'), '凌晨', 'before dawn');
64573 assert.equal(moment([2011, 2, 23, 6, 0]).format('A'), '早上', 'morning');
64574 assert.equal(moment([2011, 2, 23, 9, 0]).format('A'), '上午', 'before noon');
64575 assert.equal(moment([2011, 2, 23, 12, 0]).format('A'), '中午', 'noon');
64576 assert.equal(moment([2011, 2, 23, 13, 0]).format('A'), '下午', 'afternoon');
64577 assert.equal(moment([2011, 2, 23, 18, 0]).format('A'), '晚上', 'night');
64578 });
64579
64580 test('weeks year starting sunday format', function (assert) {
64581 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1週', 'Jan 1 2012 應該是第 1週');
64582 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1週', 'Jan 7 2012 應該是第 1週');
64583 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2週', 'Jan 8 2012 應該是第 2週');
64584 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2週', 'Jan 14 2012 應該是第 2週');
64585 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3週', 'Jan 15 2012 應該是第 3週');
64586 });
73f3c911
IC
64587
64588})));
64589
516f5f67 64590
c74a101d
IC
64591;(function (global, factory) {
64592 typeof exports === 'object' && typeof module !== 'undefined'
64593 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
64594 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
64595 factory(global.moment)
73f3c911 64596}(this, (function (moment) { 'use strict';
516f5f67 64597
db71a655
KM
64598 function each(array, callback) {
64599 var i;
64600 for (i = 0; i < array.length; i++) {
64601 callback(array[i], i, array);
64602 }
b135bf1a
IC
64603 }
64604
c58511b9
KM
64605 function setupDeprecationHandler(test, moment$$1, scope) {
64606 test._expectedDeprecations = null;
64607 test._observedDeprecations = null;
64608 test._oldSupress = moment$$1.suppressDeprecationWarnings;
64609 moment$$1.suppressDeprecationWarnings = true;
64610 test.expectedDeprecations = function () {
64611 test._expectedDeprecations = arguments;
64612 test._observedDeprecations = [];
64613 };
64614 moment$$1.deprecationHandler = function (name, msg) {
64615 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
64616 if (deprecationId === -1) {
64617 throw new Error('Unexpected deprecation thrown name=' +
64618 name + ' msg=' + msg);
64619 }
64620 test._observedDeprecations[deprecationId] = 1;
64621 };
64622 }
64623
64624 function teardownDeprecationHandler(test, moment$$1, scope) {
64625 moment$$1.suppressDeprecationWarnings = test._oldSupress;
64626
64627 if (test._expectedDeprecations != null) {
64628 var missedDeprecations = [];
64629 each(test._expectedDeprecations, function (deprecationPattern, id) {
64630 if (test._observedDeprecations[id] !== 1) {
64631 missedDeprecations.push(deprecationPattern);
64632 }
64633 });
64634 if (missedDeprecations.length !== 0) {
64635 throw new Error('Expected deprecation warnings did not happen: ' +
64636 missedDeprecations.join(' '));
64637 }
64638 }
64639 }
64640
64641 function matchedDeprecation(name, msg, deprecations) {
64642 if (deprecations == null) {
64643 return -1;
64644 }
64645 for (var i = 0; i < deprecations.length; ++i) {
64646 if (name != null && name === deprecations[i]) {
64647 return i;
64648 }
64649 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
64650 return i;
64651 }
64652 }
64653 return -1;
64654 }
64655
64656 /*global QUnit:false*/
64657
64658 var test = QUnit.test;
64659
db71a655
KM
64660 function objectKeys(obj) {
64661 if (Object.keys) {
64662 return Object.keys(obj);
64663 } else {
64664 // IE8
64665 var res = [], i;
64666 for (i in obj) {
64667 if (obj.hasOwnProperty(i)) {
64668 res.push(i);
64669 }
b135bf1a 64670 }
db71a655 64671 return res;
b135bf1a 64672 }
b135bf1a
IC
64673 }
64674
db71a655 64675 // Pick the first defined of two or three arguments.
b135bf1a 64676
db71a655
KM
64677 function defineCommonLocaleTests(locale, options) {
64678 test('lenient day of month ordinal parsing', function (assert) {
64679 var i, ordinalStr, testMoment;
64680 for (i = 1; i <= 31; ++i) {
64681 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
64682 testMoment = moment(ordinalStr, 'YYYY MM Do');
64683 assert.equal(testMoment.year(), 2014,
64684 'lenient day of month ordinal parsing ' + i + ' year check');
64685 assert.equal(testMoment.month(), 0,
64686 'lenient day of month ordinal parsing ' + i + ' month check');
64687 assert.equal(testMoment.date(), i,
64688 'lenient day of month ordinal parsing ' + i + ' date check');
64689 }
64690 });
b135bf1a 64691
db71a655
KM
64692 test('lenient day of month ordinal parsing of number', function (assert) {
64693 var i, testMoment;
64694 for (i = 1; i <= 31; ++i) {
64695 testMoment = moment('2014 01 ' + i, 'YYYY MM Do');
64696 assert.equal(testMoment.year(), 2014,
64697 'lenient day of month ordinal parsing of number ' + i + ' year check');
64698 assert.equal(testMoment.month(), 0,
64699 'lenient day of month ordinal parsing of number ' + i + ' month check');
64700 assert.equal(testMoment.date(), i,
64701 'lenient day of month ordinal parsing of number ' + i + ' date check');
64702 }
64703 });
b135bf1a 64704
db71a655
KM
64705 test('strict day of month ordinal parsing', function (assert) {
64706 var i, ordinalStr, testMoment;
64707 for (i = 1; i <= 31; ++i) {
64708 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do');
64709 testMoment = moment(ordinalStr, 'YYYY MM Do', true);
64710 assert.ok(testMoment.isValid(), 'strict day of month ordinal parsing ' + i);
64711 }
64712 });
b135bf1a 64713
db71a655
KM
64714 test('meridiem invariant', function (assert) {
64715 var h, m, t1, t2;
64716 for (h = 0; h < 24; ++h) {
64717 for (m = 0; m < 60; m += 15) {
64718 t1 = moment.utc([2000, 0, 1, h, m]);
64719 t2 = moment.utc(t1.format('A h:mm'), 'A h:mm');
64720 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'),
64721 'meridiem at ' + t1.format('HH:mm'));
64722 }
64723 }
64724 });
64725
64726 test('date format correctness', function (assert) {
64727 var data, tokens;
64728 data = moment.localeData()._longDateFormat;
64729 tokens = objectKeys(data);
64730 each(tokens, function (srchToken) {
64731 // Check each format string to make sure it does not contain any
64732 // tokens that need to be expanded.
64733 each(tokens, function (baseToken) {
64734 // strip escaped sequences
64735 var format = data[baseToken].replace(/(\[[^\]]*\])/g, '');
64736 assert.equal(false, !!~format.indexOf(srchToken),
64737 'contains ' + srchToken + ' in ' + baseToken);
64738 });
b135bf1a
IC
64739 });
64740 });
d6651c21 64741
db71a655
KM
64742 test('month parsing correctness', function (assert) {
64743 var i, m;
64744
64745 if (locale === 'tr') {
64746 // I can't fix it :(
c58511b9 64747 assert.expect(0);
db71a655
KM
64748 return;
64749 }
64750 function tester(format) {
64751 var r;
64752 r = moment(m.format(format), format);
64753 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format);
b8f4fe2b
KM
64754 if (locale !== 'ka') {
64755 r = moment(m.format(format).toLocaleUpperCase(), format);
64756 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper');
64757 }
db71a655
KM
64758 r = moment(m.format(format).toLocaleLowerCase(), format);
64759 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower');
64760
64761 r = moment(m.format(format), format, true);
64762 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' strict');
b8f4fe2b
KM
64763 if (locale !== 'ka') {
64764 r = moment(m.format(format).toLocaleUpperCase(), format, true);
64765 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' upper strict');
64766 }
db71a655
KM
64767 r = moment(m.format(format).toLocaleLowerCase(), format, true);
64768 assert.equal(r.month(), m.month(), 'month ' + i + ' fmt ' + format + ' lower strict');
64769 }
64770
64771 for (i = 0; i < 12; ++i) {
64772 m = moment([2015, i, 15, 18]);
64773 tester('MMM');
64774 tester('MMM.');
64775 tester('MMMM');
64776 tester('MMMM.');
64777 }
64778 });
d6651c21 64779
db71a655
KM
64780 test('weekday parsing correctness', function (assert) {
64781 var i, m;
64782
96d0d679 64783 if (locale === 'tr' || locale === 'az' || locale === 'ro' || locale === 'mt' || locale === 'ga') {
db71a655
KM
64784 // tr, az: There is a lower-case letter (ı), that converted to
64785 // upper then lower changes to i
64786 // ro: there is the letter ț which behaves weird under IE8
64787 // mt: letter Ħ
96d0d679 64788 // ga: month with spaces
c58511b9 64789 assert.expect(0);
db71a655
KM
64790 return;
64791 }
64792 function tester(format) {
64793 var r, baseMsg = 'weekday ' + m.weekday() + ' fmt ' + format + ' ' + m.toISOString();
64794 r = moment(m.format(format), format);
64795 assert.equal(r.weekday(), m.weekday(), baseMsg);
b8f4fe2b
KM
64796 if (locale !== 'ka') {
64797 r = moment(m.format(format).toLocaleUpperCase(), format);
64798 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper');
64799 }
db71a655
KM
64800 r = moment(m.format(format).toLocaleLowerCase(), format);
64801 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower');
64802 r = moment(m.format(format), format, true);
64803 assert.equal(r.weekday(), m.weekday(), baseMsg + ' strict');
b8f4fe2b
KM
64804 if (locale !== 'ka') {
64805 r = moment(m.format(format).toLocaleUpperCase(), format, true);
64806 assert.equal(r.weekday(), m.weekday(), baseMsg + ' upper strict');
64807 }
db71a655
KM
64808 r = moment(m.format(format).toLocaleLowerCase(), format, true);
64809 assert.equal(r.weekday(), m.weekday(), baseMsg + ' lower strict');
64810 }
64811
64812 for (i = 0; i < 7; ++i) {
64813 m = moment.utc([2015, 0, i + 1, 18]);
64814 tester('dd');
64815 tester('ddd');
64816 tester('dddd');
64817 }
64818 });
d6651c21 64819
db71a655
KM
64820 test('valid localeData', function (assert) {
64821 assert.equal(moment().localeData().months().length, 12, 'months should return 12 months');
64822 assert.equal(moment().localeData().monthsShort().length, 12, 'monthsShort should return 12 months');
64823 assert.equal(moment().localeData().weekdays().length, 7, 'weekdays should return 7 days');
64824 assert.equal(moment().localeData().weekdaysShort().length, 7, 'weekdaysShort should return 7 days');
64825 assert.equal(moment().localeData().weekdaysMin().length, 7, 'monthsShort should return 7 days');
64826 });
96d0d679
KM
64827
64828 test('localeData weekdays can localeSort', function (assert) {
64829 var weekdays = moment().localeData().weekdays();
64830 var weekdaysShort = moment().localeData().weekdaysShort();
64831 var weekdaysMin = moment().localeData().weekdaysMin();
64832 var shift = moment().localeData()._week.dow;
64833 assert.deepEqual(
64834 moment().localeData().weekdays(true),
64835 weekdays.slice(shift, 7).concat(weekdays.slice(0, shift)),
64836 'weekdays should localeSort');
64837 assert.deepEqual(
64838 moment().localeData().weekdaysShort(true),
64839 weekdaysShort.slice(shift, 7).concat(weekdaysShort.slice(0, shift)),
64840 'weekdaysShort should localeSort');
64841 assert.deepEqual(
64842 moment().localeData().weekdaysMin(true),
64843 weekdaysMin.slice(shift, 7).concat(weekdaysMin.slice(0, shift)),
64844 'weekdaysMin should localeSort');
64845 });
db71a655 64846 }
d6651c21 64847
db71a655
KM
64848 /*global QUnit:false*/
64849
db71a655
KM
64850 function localeModule (name, lifecycle) {
64851 QUnit.module('locale:' + name, {
c58511b9 64852 beforeEach : function () {
db71a655
KM
64853 moment.locale(name);
64854 moment.createFromInputFallback = function (config) {
64855 throw new Error('input not handled by moment: ' + config._i);
64856 };
64857 setupDeprecationHandler(test, moment, 'locale');
64858 if (lifecycle && lifecycle.setup) {
64859 lifecycle.setup();
64860 }
64861 },
c58511b9 64862 afterEach : function () {
db71a655
KM
64863 moment.locale('en');
64864 teardownDeprecationHandler(test, moment, 'locale');
64865 if (lifecycle && lifecycle.teardown) {
64866 lifecycle.teardown();
64867 }
516f5f67
IC
64868 }
64869 });
db71a655
KM
64870 defineCommonLocaleTests(name, -1, -1);
64871 }
64872
64873 localeModule('zh-tw');
64874
64875 test('parse', function (assert) {
64876 var tests = '一月 1月_二月 2月_三月 3月_四月 4月_五月 5月_六月 6月_七月 7月_八月 8月_九月 9月_十月 10月_十一月 11月_十二月 12月'.split('_'), i;
64877 function equalTest(input, mmm, i) {
64878 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1));
64879 }
64880 for (i = 0; i < 12; i++) {
64881 tests[i] = tests[i].split(' ');
64882 equalTest(tests[i][0], 'MMM', i);
64883 equalTest(tests[i][1], 'MMM', i);
64884 equalTest(tests[i][0], 'MMMM', i);
64885 equalTest(tests[i][1], 'MMMM', i);
64886 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i);
64887 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i);
64888 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i);
64889 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i);
64890 }
64891 });
64892
64893 test('format', function (assert) {
64894 var a = [
64895 ['dddd, MMMM Do YYYY, a h:mm:ss', '星期日, 二月 14日 2010, 下午 3:25:50'],
64896 ['ddd, Ah', '週日, 下午3'],
64897 ['M Mo MM MMMM MMM', '2 2月 02 二月 2月'],
64898 ['YYYY YY', '2010 10'],
64899 ['D Do DD', '14 14日 14'],
64900 ['d do dddd ddd dd', '0 0日 星期日 週日 日'],
64901 ['DDD DDDo DDDD', '45 45日 045'],
64902 ['w wo ww', '8 8週 08'],
64903 ['h hh', '3 03'],
64904 ['H HH', '15 15'],
64905 ['m mm', '25 25'],
64906 ['s ss', '50 50'],
64907 ['a A', '下午 下午'],
64908 ['[這年的第] DDDo', '這年的第 45日'],
64909 ['LTS', '15:25:50'],
64910 ['L', '2010/02/14'],
64911 ['LL', '2010年2月14日'],
64912 ['LLL', '2010年2月14日 15:25'],
64913 ['LLLL', '2010年2月14日星期日 15:25'],
64914 ['l', '2010/2/14'],
64915 ['ll', '2010年2月14日'],
64916 ['lll', '2010年2月14日 15:25'],
64917 ['llll', '2010年2月14日星期日 15:25']
64918 ],
64919 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
64920 i;
64921
64922 for (i = 0; i < a.length; i++) {
64923 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
64924 }
64925 });
64926
64927 test('format month', function (assert) {
64928 var expected = '一月 1月_二月 2月_三月 3月_四月 4月_五月 5月_六月 6月_七月 7月_八月 8月_九月 9月_十月 10月_十一月 11月_十二月 12月'.split('_'), i;
64929
64930 for (i = 0; i < expected.length; i++) {
64931 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]);
64932 }
64933 });
64934
64935 test('format week', function (assert) {
64936 var expected = '星期日 週日 日_星期一 週一 一_星期二 週二 二_星期三 週三 三_星期四 週四 四_星期五 週五 五_星期六 週六 六'.split('_'), i;
64937
64938 for (i = 0; i < expected.length; i++) {
64939 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]);
64940 }
64941 });
64942
64943 test('from', function (assert) {
64944 var start = moment([2007, 1, 28]);
64945 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), '幾秒', '44 seconds = a few seconds');
64946 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '1 分鐘', '45 seconds = a minute');
64947 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '1 分鐘', '89 seconds = a minute');
64948 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 分鐘', '90 seconds = 2 minutes');
64949 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 分鐘', '44 minutes = 44 minutes');
64950 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '1 小時', '45 minutes = an hour');
64951 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '1 小時', '89 minutes = an hour');
64952 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 小時', '90 minutes = 2 hours');
64953 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 小時', '5 hours = 5 hours');
64954 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 小時', '21 hours = 21 hours');
64955 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '1 天', '22 hours = a day');
64956 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '1 天', '35 hours = a day');
64957 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 天', '36 hours = 2 days');
64958 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '1 天', '1 day = a day');
64959 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 天', '5 days = 5 days');
64960 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 天', '25 days = 25 days');
64961 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '1 個月', '26 days = a month');
64962 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '1 個月', '30 days = a month');
64963 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '1 個月', '43 days = a month');
64964 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 個月', '46 days = 2 months');
64965 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 個月', '75 days = 2 months');
64966 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 個月', '76 days = 3 months');
64967 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '1 個月', '1 month = a month');
64968 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 個月', '5 months = 5 months');
64969 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '1 年', '345 days = a year');
64970 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 年', '548 days = 2 years');
64971 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '1 年', '1 year = a year');
64972 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 年', '5 years = 5 years');
64973 });
64974
64975 test('suffix', function (assert) {
64976 assert.equal(moment(30000).from(0), '幾秒內', 'prefix');
64977 assert.equal(moment(0).from(30000), '幾秒前', 'suffix');
64978 });
64979
64980 test('now from now', function (assert) {
64981 assert.equal(moment().fromNow(), '幾秒前', 'now from now should display as in the past');
64982 });
64983
64984 test('fromNow', function (assert) {
64985 assert.equal(moment().add({s: 30}).fromNow(), '幾秒內', 'in a few seconds');
64986 assert.equal(moment().add({d: 5}).fromNow(), '5 天內', 'in 5 days');
64987 });
64988
64989 test('calendar day', function (assert) {
64990 var a = moment().hours(12).minutes(0).seconds(0);
64991
64992 assert.equal(moment(a).calendar(), '今天 12:00', 'today at the same time');
64993 assert.equal(moment(a).add({m: 25}).calendar(), '今天 12:25', 'Now plus 25 min');
64994 assert.equal(moment(a).add({h: 1}).calendar(), '今天 13:00', 'Now plus 1 hour');
64995 assert.equal(moment(a).add({d: 1}).calendar(), '明天 12:00', 'tomorrow at the same time');
64996 assert.equal(moment(a).subtract({h: 1}).calendar(), '今天 11:00', 'Now minus 1 hour');
64997 assert.equal(moment(a).subtract({d: 1}).calendar(), '昨天 12:00', 'yesterday at the same time');
64998 });
64999
65000 test('calendar next week', function (assert) {
65001 var i, m;
65002 for (i = 2; i < 7; i++) {
65003 m = moment().add({d: i});
65004 assert.equal(m.calendar(), m.format('[下]dddd LT'), 'Today + ' + i + ' days current time');
65005 m.hours(0).minutes(0).seconds(0).milliseconds(0);
65006 assert.equal(m.calendar(), m.format('[下]dddd LT'), 'Today + ' + i + ' days beginning of day');
65007 m.hours(23).minutes(59).seconds(59).milliseconds(999);
65008 assert.equal(m.calendar(), m.format('[下]dddd LT'), 'Today + ' + i + ' days end of day');
73f3c911 65009 }
db71a655 65010 });
516f5f67 65011
db71a655
KM
65012 test('calendar last week', function (assert) {
65013 var i, m;
65014 for (i = 2; i < 7; i++) {
65015 m = moment().subtract({d: i});
65016 assert.equal(m.calendar(), m.format('[上]dddd LT'), 'Today - ' + i + ' days current time');
65017 m.hours(0).minutes(0).seconds(0).milliseconds(0);
65018 assert.equal(m.calendar(), m.format('[上]dddd LT'), 'Today - ' + i + ' days beginning of day');
65019 m.hours(23).minutes(59).seconds(59).milliseconds(999);
65020 assert.equal(m.calendar(), m.format('[上]dddd LT'), 'Today - ' + i + ' days end of day');
73f3c911 65021 }
db71a655 65022 });
c74a101d 65023
db71a655
KM
65024 test('calendar all else', function (assert) {
65025 var weeksAgo = moment().subtract({w: 1}),
65026 weeksFromNow = moment().add({w: 1});
c74a101d 65027
db71a655
KM
65028 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago');
65029 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week');
c74a101d 65030
db71a655
KM
65031 weeksAgo = moment().subtract({w: 2});
65032 weeksFromNow = moment().add({w: 2});
c74a101d 65033
db71a655
KM
65034 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago');
65035 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks');
7c4c091b 65036 });
7c4c091b 65037
db71a655
KM
65038 test('meridiem', function (assert) {
65039 assert.equal(moment([2011, 2, 23, 0, 0]).format('a'), '凌晨', 'before dawn');
65040 assert.equal(moment([2011, 2, 23, 6, 0]).format('a'), '早上', 'morning');
65041 assert.equal(moment([2011, 2, 23, 9, 0]).format('a'), '上午', 'before noon');
65042 assert.equal(moment([2011, 2, 23, 12, 0]).format('a'), '中午', 'noon');
65043 assert.equal(moment([2011, 2, 23, 13, 0]).format('a'), '下午', 'after noon');
65044 assert.equal(moment([2011, 2, 23, 18, 0]).format('a'), '晚上', 'night');
7c4c091b 65045
db71a655
KM
65046 assert.equal(moment([2011, 2, 23, 0, 0]).format('A'), '凌晨', 'before dawn');
65047 assert.equal(moment([2011, 2, 23, 6, 0]).format('A'), '早上', 'morning');
65048 assert.equal(moment([2011, 2, 23, 9, 0]).format('A'), '上午', 'before noon');
65049 assert.equal(moment([2011, 2, 23, 12, 0]).format('A'), '中午', 'noon');
65050 assert.equal(moment([2011, 2, 23, 13, 0]).format('A'), '下午', 'afternoon');
65051 assert.equal(moment([2011, 2, 23, 18, 0]).format('A'), '晚上', 'night');
65052 });
65053
65054 test('weeks year starting sunday format', function (assert) {
65055 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1週', 'Jan 1 2012 應該是第 1週');
65056 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1週', 'Jan 7 2012 應該是第 1週');
65057 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2週', 'Jan 8 2012 應該是第 2週');
65058 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2週', 'Jan 14 2012 應該是第 2週');
65059 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3週', 'Jan 15 2012 應該是第 3週');
65060 });
7c4c091b
KM
65061
65062})));
65063
65064
65065;(function (global, factory) {
65066 typeof exports === 'object' && typeof module !== 'undefined'
65067 && typeof require === 'function' ? factory(require('../../moment')) :
65068 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
65069 factory(global.moment)
65070}(this, (function (moment) { 'use strict';
65071
db71a655
KM
65072 function each(array, callback) {
65073 var i;
65074 for (i = 0; i < array.length; i++) {
65075 callback(array[i], i, array);
65076 }
7c4c091b 65077 }
7c4c091b 65078
db71a655
KM
65079 function setupDeprecationHandler(test, moment$$1, scope) {
65080 test._expectedDeprecations = null;
65081 test._observedDeprecations = null;
65082 test._oldSupress = moment$$1.suppressDeprecationWarnings;
65083 moment$$1.suppressDeprecationWarnings = true;
65084 test.expectedDeprecations = function () {
65085 test._expectedDeprecations = arguments;
65086 test._observedDeprecations = [];
65087 };
65088 moment$$1.deprecationHandler = function (name, msg) {
65089 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
65090 if (deprecationId === -1) {
65091 throw new Error('Unexpected deprecation thrown name=' +
65092 name + ' msg=' + msg);
7c4c091b 65093 }
db71a655
KM
65094 test._observedDeprecations[deprecationId] = 1;
65095 };
7c4c091b 65096 }
c74a101d 65097
db71a655
KM
65098 function teardownDeprecationHandler(test, moment$$1, scope) {
65099 moment$$1.suppressDeprecationWarnings = test._oldSupress;
7c4c091b 65100
db71a655
KM
65101 if (test._expectedDeprecations != null) {
65102 var missedDeprecations = [];
65103 each(test._expectedDeprecations, function (deprecationPattern, id) {
65104 if (test._observedDeprecations[id] !== 1) {
65105 missedDeprecations.push(deprecationPattern);
65106 }
65107 });
65108 if (missedDeprecations.length !== 0) {
65109 throw new Error('Expected deprecation warnings did not happen: ' +
65110 missedDeprecations.join(' '));
65111 }
7c4c091b 65112 }
db71a655 65113 }
7c4c091b 65114
db71a655
KM
65115 function matchedDeprecation(name, msg, deprecations) {
65116 if (deprecations == null) {
65117 return -1;
7c4c091b 65118 }
db71a655
KM
65119 for (var i = 0; i < deprecations.length; ++i) {
65120 if (name != null && name === deprecations[i]) {
65121 return i;
65122 }
65123 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
65124 return i;
65125 }
7c4c091b 65126 }
db71a655
KM
65127 return -1;
65128 }
7c4c091b 65129
db71a655 65130 /*global QUnit:false*/
7c4c091b 65131
db71a655
KM
65132 var test = QUnit.test;
65133
db71a655
KM
65134 function module$1 (name, lifecycle) {
65135 QUnit.module(name, {
c58511b9 65136 beforeEach : function () {
db71a655
KM
65137 moment.locale('en');
65138 moment.createFromInputFallback = function (config) {
65139 throw new Error('input not handled by moment: ' + config._i);
65140 };
65141 setupDeprecationHandler(test, moment, 'core');
65142 if (lifecycle && lifecycle.setup) {
65143 lifecycle.setup();
65144 }
65145 },
c58511b9 65146 afterEach : function () {
db71a655
KM
65147 teardownDeprecationHandler(test, moment, 'core');
65148 if (lifecycle && lifecycle.teardown) {
65149 lifecycle.teardown();
65150 }
65151 }
65152 });
65153 }
7c4c091b 65154
db71a655
KM
65155 module$1('add and subtract');
65156
65157 test('add short reverse args', function (assert) {
65158 var a = moment(), b, c, d;
65159 a.year(2011);
65160 a.month(9);
65161 a.date(12);
65162 a.hours(6);
65163 a.minutes(7);
65164 a.seconds(8);
65165 a.milliseconds(500);
65166
65167 assert.equal(a.add({ms: 50}).milliseconds(), 550, 'Add milliseconds');
65168 assert.equal(a.add({s: 1}).seconds(), 9, 'Add seconds');
65169 assert.equal(a.add({m: 1}).minutes(), 8, 'Add minutes');
65170 assert.equal(a.add({h: 1}).hours(), 7, 'Add hours');
65171 assert.equal(a.add({d: 1}).date(), 13, 'Add date');
65172 assert.equal(a.add({w: 1}).date(), 20, 'Add week');
65173 assert.equal(a.add({M: 1}).month(), 10, 'Add month');
65174 assert.equal(a.add({y: 1}).year(), 2012, 'Add year');
65175 assert.equal(a.add({Q: 1}).month(), 1, 'Add quarter');
65176
65177 b = moment([2010, 0, 31]).add({M: 1});
65178 c = moment([2010, 1, 28]).subtract({M: 1});
65179 d = moment([2010, 1, 28]).subtract({Q: 1});
65180
65181 assert.equal(b.month(), 1, 'add month, jan 31st to feb 28th');
65182 assert.equal(b.date(), 28, 'add month, jan 31st to feb 28th');
65183 assert.equal(c.month(), 0, 'subtract month, feb 28th to jan 28th');
65184 assert.equal(c.date(), 28, 'subtract month, feb 28th to jan 28th');
65185 assert.equal(d.month(), 10, 'subtract quarter, feb 28th 2010 to nov 28th 2009');
65186 assert.equal(d.date(), 28, 'subtract quarter, feb 28th 2010 to nov 28th 2009');
65187 assert.equal(d.year(), 2009, 'subtract quarter, feb 28th 2010 to nov 28th 2009');
65188 });
65189
65190 test('add long reverse args', function (assert) {
65191 var a = moment();
65192 a.year(2011);
65193 a.month(9);
65194 a.date(12);
65195 a.hours(6);
65196 a.minutes(7);
65197 a.seconds(8);
65198 a.milliseconds(500);
65199
65200 assert.equal(a.add({milliseconds: 50}).milliseconds(), 550, 'Add milliseconds');
65201 assert.equal(a.add({seconds: 1}).seconds(), 9, 'Add seconds');
65202 assert.equal(a.add({minutes: 1}).minutes(), 8, 'Add minutes');
65203 assert.equal(a.add({hours: 1}).hours(), 7, 'Add hours');
65204 assert.equal(a.add({days: 1}).date(), 13, 'Add date');
65205 assert.equal(a.add({weeks: 1}).date(), 20, 'Add week');
65206 assert.equal(a.add({months: 1}).month(), 10, 'Add month');
65207 assert.equal(a.add({years: 1}).year(), 2012, 'Add year');
65208 assert.equal(a.add({quarters: 1}).month(), 1, 'Add quarter');
65209 });
65210
65211 test('add long singular reverse args', function (assert) {
65212 var a = moment();
65213 a.year(2011);
65214 a.month(9);
65215 a.date(12);
65216 a.hours(6);
65217 a.minutes(7);
65218 a.seconds(8);
65219 a.milliseconds(500);
65220
65221 assert.equal(a.add({millisecond: 50}).milliseconds(), 550, 'Add milliseconds');
65222 assert.equal(a.add({second: 1}).seconds(), 9, 'Add seconds');
65223 assert.equal(a.add({minute: 1}).minutes(), 8, 'Add minutes');
65224 assert.equal(a.add({hour: 1}).hours(), 7, 'Add hours');
65225 assert.equal(a.add({day: 1}).date(), 13, 'Add date');
65226 assert.equal(a.add({week: 1}).date(), 20, 'Add week');
65227 assert.equal(a.add({month: 1}).month(), 10, 'Add month');
65228 assert.equal(a.add({year: 1}).year(), 2012, 'Add year');
65229 assert.equal(a.add({quarter: 1}).month(), 1, 'Add quarter');
65230 });
65231
65232 test('add string long reverse args', function (assert) {
65233 var a = moment(), b;
65234
65235 test.expectedDeprecations('moment().add(period, number)');
65236
65237 a.year(2011);
65238 a.month(9);
65239 a.date(12);
65240 a.hours(6);
65241 a.minutes(7);
65242 a.seconds(8);
65243 a.milliseconds(500);
65244
65245 b = a.clone();
65246
65247 assert.equal(a.add('millisecond', 50).milliseconds(), 550, 'Add milliseconds');
65248 assert.equal(a.add('second', 1).seconds(), 9, 'Add seconds');
65249 assert.equal(a.add('minute', 1).minutes(), 8, 'Add minutes');
65250 assert.equal(a.add('hour', 1).hours(), 7, 'Add hours');
65251 assert.equal(a.add('day', 1).date(), 13, 'Add date');
65252 assert.equal(a.add('week', 1).date(), 20, 'Add week');
65253 assert.equal(a.add('month', 1).month(), 10, 'Add month');
65254 assert.equal(a.add('year', 1).year(), 2012, 'Add year');
65255 assert.equal(b.add('day', '01').date(), 13, 'Add date');
65256 assert.equal(a.add('quarter', 1).month(), 1, 'Add quarter');
65257 });
65258
65259 test('add string long singular reverse args', function (assert) {
65260 var a = moment(), b;
65261
65262 test.expectedDeprecations('moment().add(period, number)');
65263
65264 a.year(2011);
65265 a.month(9);
65266 a.date(12);
65267 a.hours(6);
65268 a.minutes(7);
65269 a.seconds(8);
65270 a.milliseconds(500);
65271
65272 b = a.clone();
65273
65274 assert.equal(a.add('milliseconds', 50).milliseconds(), 550, 'Add milliseconds');
65275 assert.equal(a.add('seconds', 1).seconds(), 9, 'Add seconds');
65276 assert.equal(a.add('minutes', 1).minutes(), 8, 'Add minutes');
65277 assert.equal(a.add('hours', 1).hours(), 7, 'Add hours');
65278 assert.equal(a.add('days', 1).date(), 13, 'Add date');
65279 assert.equal(a.add('weeks', 1).date(), 20, 'Add week');
65280 assert.equal(a.add('months', 1).month(), 10, 'Add month');
65281 assert.equal(a.add('years', 1).year(), 2012, 'Add year');
65282 assert.equal(b.add('days', '01').date(), 13, 'Add date');
65283 assert.equal(a.add('quarters', 1).month(), 1, 'Add quarter');
65284 });
65285
65286 test('add string short reverse args', function (assert) {
65287 var a = moment();
65288 test.expectedDeprecations('moment().add(period, number)');
65289
65290 a.year(2011);
65291 a.month(9);
65292 a.date(12);
65293 a.hours(6);
65294 a.minutes(7);
65295 a.seconds(8);
65296 a.milliseconds(500);
65297
65298 assert.equal(a.add('ms', 50).milliseconds(), 550, 'Add milliseconds');
65299 assert.equal(a.add('s', 1).seconds(), 9, 'Add seconds');
65300 assert.equal(a.add('m', 1).minutes(), 8, 'Add minutes');
65301 assert.equal(a.add('h', 1).hours(), 7, 'Add hours');
65302 assert.equal(a.add('d', 1).date(), 13, 'Add date');
65303 assert.equal(a.add('w', 1).date(), 20, 'Add week');
65304 assert.equal(a.add('M', 1).month(), 10, 'Add month');
65305 assert.equal(a.add('y', 1).year(), 2012, 'Add year');
65306 assert.equal(a.add('Q', 1).month(), 1, 'Add quarter');
65307 });
65308
65309 test('add string long', function (assert) {
65310 var a = moment();
65311 a.year(2011);
65312 a.month(9);
65313 a.date(12);
65314 a.hours(6);
65315 a.minutes(7);
65316 a.seconds(8);
65317 a.milliseconds(500);
65318
65319 assert.equal(a.add(50, 'millisecond').milliseconds(), 550, 'Add milliseconds');
65320 assert.equal(a.add(1, 'second').seconds(), 9, 'Add seconds');
65321 assert.equal(a.add(1, 'minute').minutes(), 8, 'Add minutes');
65322 assert.equal(a.add(1, 'hour').hours(), 7, 'Add hours');
65323 assert.equal(a.add(1, 'day').date(), 13, 'Add date');
65324 assert.equal(a.add(1, 'week').date(), 20, 'Add week');
65325 assert.equal(a.add(1, 'month').month(), 10, 'Add month');
65326 assert.equal(a.add(1, 'year').year(), 2012, 'Add year');
65327 assert.equal(a.add(1, 'quarter').month(), 1, 'Add quarter');
65328 });
65329
65330 test('add string long singular', function (assert) {
65331 var a = moment();
65332 a.year(2011);
65333 a.month(9);
65334 a.date(12);
65335 a.hours(6);
65336 a.minutes(7);
65337 a.seconds(8);
65338 a.milliseconds(500);
65339
65340 assert.equal(a.add(50, 'milliseconds').milliseconds(), 550, 'Add milliseconds');
65341 assert.equal(a.add(1, 'seconds').seconds(), 9, 'Add seconds');
65342 assert.equal(a.add(1, 'minutes').minutes(), 8, 'Add minutes');
65343 assert.equal(a.add(1, 'hours').hours(), 7, 'Add hours');
65344 assert.equal(a.add(1, 'days').date(), 13, 'Add date');
65345 assert.equal(a.add(1, 'weeks').date(), 20, 'Add week');
65346 assert.equal(a.add(1, 'months').month(), 10, 'Add month');
65347 assert.equal(a.add(1, 'years').year(), 2012, 'Add year');
65348 assert.equal(a.add(1, 'quarters').month(), 1, 'Add quarter');
65349 });
65350
65351 test('add string short', function (assert) {
65352 var a = moment();
65353 a.year(2011);
65354 a.month(9);
65355 a.date(12);
65356 a.hours(6);
65357 a.minutes(7);
65358 a.seconds(8);
65359 a.milliseconds(500);
65360
65361 assert.equal(a.add(50, 'ms').milliseconds(), 550, 'Add milliseconds');
65362 assert.equal(a.add(1, 's').seconds(), 9, 'Add seconds');
65363 assert.equal(a.add(1, 'm').minutes(), 8, 'Add minutes');
65364 assert.equal(a.add(1, 'h').hours(), 7, 'Add hours');
65365 assert.equal(a.add(1, 'd').date(), 13, 'Add date');
65366 assert.equal(a.add(1, 'w').date(), 20, 'Add week');
65367 assert.equal(a.add(1, 'M').month(), 10, 'Add month');
65368 assert.equal(a.add(1, 'y').year(), 2012, 'Add year');
65369 assert.equal(a.add(1, 'Q').month(), 1, 'Add quarter');
65370 });
65371
65372 test('add strings string short reversed', function (assert) {
65373 var a = moment();
65374 test.expectedDeprecations('moment().add(period, number)');
65375
65376 a.year(2011);
65377 a.month(9);
65378 a.date(12);
65379 a.hours(6);
65380 a.minutes(7);
65381 a.seconds(8);
65382 a.milliseconds(500);
65383
65384 assert.equal(a.add('ms', '50').milliseconds(), 550, 'Add milliseconds');
65385 assert.equal(a.add('s', '1').seconds(), 9, 'Add seconds');
65386 assert.equal(a.add('m', '1').minutes(), 8, 'Add minutes');
65387 assert.equal(a.add('h', '1').hours(), 7, 'Add hours');
65388 assert.equal(a.add('d', '1').date(), 13, 'Add date');
65389 assert.equal(a.add('w', '1').date(), 20, 'Add week');
65390 assert.equal(a.add('M', '1').month(), 10, 'Add month');
65391 assert.equal(a.add('y', '1').year(), 2012, 'Add year');
65392 assert.equal(a.add('Q', '1').month(), 1, 'Add quarter');
65393 });
65394
65395 test('subtract strings string short reversed', function (assert) {
65396 var a = moment();
65397 test.expectedDeprecations('moment().subtract(period, number)');
65398
65399 a.year(2011);
65400 a.month(9);
65401 a.date(12);
65402 a.hours(6);
65403 a.minutes(7);
65404 a.seconds(8);
65405 a.milliseconds(500);
65406
65407 assert.equal(a.subtract('ms', '50').milliseconds(), 450, 'Subtract milliseconds');
65408 assert.equal(a.subtract('s', '1').seconds(), 7, 'Subtract seconds');
65409 assert.equal(a.subtract('m', '1').minutes(), 6, 'Subtract minutes');
65410 assert.equal(a.subtract('h', '1').hours(), 5, 'Subtract hours');
65411 assert.equal(a.subtract('d', '1').date(), 11, 'Subtract date');
65412 assert.equal(a.subtract('w', '1').date(), 4, 'Subtract week');
65413 assert.equal(a.subtract('M', '1').month(), 8, 'Subtract month');
65414 assert.equal(a.subtract('y', '1').year(), 2010, 'Subtract year');
65415 assert.equal(a.subtract('Q', '1').month(), 5, 'Subtract quarter');
65416 });
65417
65418 test('add strings string short', function (assert) {
65419 var a = moment();
65420 a.year(2011);
65421 a.month(9);
65422 a.date(12);
65423 a.hours(6);
65424 a.minutes(7);
65425 a.seconds(8);
65426 a.milliseconds(500);
65427
65428 assert.equal(a.add('50', 'ms').milliseconds(), 550, 'Add milliseconds');
65429 assert.equal(a.add('1', 's').seconds(), 9, 'Add seconds');
65430 assert.equal(a.add('1', 'm').minutes(), 8, 'Add minutes');
65431 assert.equal(a.add('1', 'h').hours(), 7, 'Add hours');
65432 assert.equal(a.add('1', 'd').date(), 13, 'Add date');
65433 assert.equal(a.add('1', 'w').date(), 20, 'Add week');
65434 assert.equal(a.add('1', 'M').month(), 10, 'Add month');
65435 assert.equal(a.add('1', 'y').year(), 2012, 'Add year');
65436 assert.equal(a.add('1', 'Q').month(), 1, 'Add quarter');
65437 });
65438
65439 test('add no string with milliseconds default', function (assert) {
65440 var a = moment();
65441 a.year(2011);
65442 a.month(9);
65443 a.date(12);
65444 a.hours(6);
65445 a.minutes(7);
65446 a.seconds(8);
65447 a.milliseconds(500);
65448
65449 assert.equal(a.add(50).milliseconds(), 550, 'Add milliseconds');
65450 });
65451
65452 test('subtract strings string short', function (assert) {
65453 var a = moment();
65454 a.year(2011);
65455 a.month(9);
65456 a.date(12);
65457 a.hours(6);
65458 a.minutes(7);
65459 a.seconds(8);
65460 a.milliseconds(500);
65461
65462 assert.equal(a.subtract('50', 'ms').milliseconds(), 450, 'Subtract milliseconds');
65463 assert.equal(a.subtract('1', 's').seconds(), 7, 'Subtract seconds');
65464 assert.equal(a.subtract('1', 'm').minutes(), 6, 'Subtract minutes');
65465 assert.equal(a.subtract('1', 'h').hours(), 5, 'Subtract hours');
65466 assert.equal(a.subtract('1', 'd').date(), 11, 'Subtract date');
65467 assert.equal(a.subtract('1', 'w').date(), 4, 'Subtract week');
65468 assert.equal(a.subtract('1', 'M').month(), 8, 'Subtract month');
65469 assert.equal(a.subtract('1', 'y').year(), 2010, 'Subtract year');
65470 assert.equal(a.subtract('1', 'Q').month(), 5, 'Subtract quarter');
65471 });
65472
65473 test('add across DST', function (assert) {
65474 // Detect Safari bug and bail. Hours on 13th March 2011 are shifted
65475 // with 1 ahead.
65476 if (new Date(2011, 2, 13, 5, 0, 0).getHours() !== 5) {
c58511b9 65477 assert.expect(0);
7c4c091b
KM
65478 return;
65479 }
7c4c091b 65480
db71a655
KM
65481 var a = moment(new Date(2011, 2, 12, 5, 0, 0)),
65482 b = moment(new Date(2011, 2, 12, 5, 0, 0)),
65483 c = moment(new Date(2011, 2, 12, 5, 0, 0)),
65484 d = moment(new Date(2011, 2, 12, 5, 0, 0)),
65485 e = moment(new Date(2011, 2, 12, 5, 0, 0));
65486 a.add(1, 'days');
65487 b.add(24, 'hours');
65488 c.add(1, 'months');
65489 e.add(1, 'quarter');
65490
65491 assert.equal(a.hours(), 5, 'adding days over DST difference should result in the same hour');
65492 if (b.isDST() && !d.isDST()) {
65493 assert.equal(b.hours(), 6, 'adding hours over DST difference should result in a different hour');
65494 } else if (!b.isDST() && d.isDST()) {
65495 assert.equal(b.hours(), 4, 'adding hours over DST difference should result in a different hour');
65496 } else {
65497 assert.equal(b.hours(), 5, 'adding hours over DST difference should result in a same hour if the timezone does not have daylight savings time');
65498 }
65499 assert.equal(c.hours(), 5, 'adding months over DST difference should result in the same hour');
65500 assert.equal(e.hours(), 5, 'adding quarters over DST difference should result in the same hour');
65501 });
65502
65503 test('add decimal values of days and months', function (assert) {
65504 assert.equal(moment([2016,3,3]).add(1.5, 'days').date(), 5, 'adding 1.5 days is rounded to adding 2 day');
65505 assert.equal(moment([2016,3,3]).add(-1.5, 'days').date(), 1, 'adding -1.5 days is rounded to adding -2 day');
65506 assert.equal(moment([2016,3,1]).add(-1.5, 'days').date(), 30, 'adding -1.5 days on first of month wraps around');
65507 assert.equal(moment([2016,3,3]).add(1.5, 'months').month(), 5, 'adding 1.5 months adds 2 months');
65508 assert.equal(moment([2016,3,3]).add(-1.5, 'months').month(), 1, 'adding -1.5 months adds -2 months');
65509 assert.equal(moment([2016,0,3]).add(-1.5, 'months').month(), 10, 'adding -1.5 months at start of year wraps back');
65510 assert.equal(moment([2016,3,3]).subtract(1.5, 'days').date(),1, 'subtract 1.5 days is rounded to subtract 2 day');
65511 assert.equal(moment([2016,3,2]).subtract(1.5, 'days').date(), 31, 'subtract 1.5 days subtracts 2 days');
65512 assert.equal(moment([2016,1,1]).subtract(1.1, 'days').date(), 31, 'subtract 1.1 days wraps to previous month');
65513 assert.equal(moment([2016,3,3]).subtract(-1.5, 'days').date(), 5, 'subtract -1.5 days is rounded to subtract -2 day');
65514 assert.equal(moment([2016,3,30]).subtract(-1.5, 'days').date(), 2, 'subtract -1.5 days on last of month wraps around');
65515 assert.equal(moment([2016,3,3]).subtract(1.5, 'months').month(), 1, 'subtract 1.5 months subtract 2 months');
65516 assert.equal(moment([2016,3,3]).subtract(-1.5, 'months').month(), 5, 'subtract -1.5 months subtract -2 month');
65517 assert.equal(moment([2016,11,31]).subtract(-1.5, 'months').month(),1, 'subtract -1.5 months at end of year wraps back');
65518 assert.equal(moment([2016, 0,1]).add(1.5, 'years').format('YYYY-MM-DD'), '2017-07-01', 'add 1.5 years adds 1 year six months');
65519 assert.equal(moment([2016, 0,1]).add(1.6, 'years').format('YYYY-MM-DD'), '2017-08-01', 'add 1.6 years becomes 1.6*12 = 19.2, round, 19 months');
65520 assert.equal(moment([2016,0,1]).add(1.1, 'quarters').format('YYYY-MM-DD'), '2016-04-01', 'add 1.1 quarters 1.1*3=3.3, round, 3 months');
7c4c091b
KM
65521 });
65522
b8f4fe2b
KM
65523 test('add/subtract ISO week', function (assert) {
65524 assert.equal(moment([2016,3,15]).subtract(1, 'W').date(), 8, 'subtract 1 iso week short');
65525 assert.equal(moment([2016,3,15]).subtract(1, 'isoweek').date(), 8, 'subtract 1 iso week long singular');
65526 assert.equal(moment([2016,3,15]).subtract(1, 'isoweeks').date(), 8, 'subtract 1 iso weeks long');
65527
65528 assert.equal(moment([2016,3,15]).add(1, 'W').date(), 22, 'add 1 iso week short');
65529 assert.equal(moment([2016,3,15]).add(1, 'isoweek').date(), 22, 'add 1 week long singular');
65530 assert.equal(moment([2016,3,15]).add(1, 'isoweeks').date(), 22, 'add 1 weeks long');
65531 });
65532
db71a655 65533})));
7c4c091b 65534
7c4c091b 65535
db71a655
KM
65536;(function (global, factory) {
65537 typeof exports === 'object' && typeof module !== 'undefined'
65538 && typeof require === 'function' ? factory(require('../../moment')) :
65539 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
65540 factory(global.moment)
65541}(this, (function (moment) { 'use strict';
65542
65543 function each(array, callback) {
65544 var i;
65545 for (i = 0; i < array.length; i++) {
65546 callback(array[i], i, array);
7c4c091b 65547 }
db71a655 65548 }
7c4c091b 65549
db71a655
KM
65550 function setupDeprecationHandler(test, moment$$1, scope) {
65551 test._expectedDeprecations = null;
65552 test._observedDeprecations = null;
65553 test._oldSupress = moment$$1.suppressDeprecationWarnings;
65554 moment$$1.suppressDeprecationWarnings = true;
65555 test.expectedDeprecations = function () {
65556 test._expectedDeprecations = arguments;
65557 test._observedDeprecations = [];
65558 };
65559 moment$$1.deprecationHandler = function (name, msg) {
65560 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
65561 if (deprecationId === -1) {
65562 throw new Error('Unexpected deprecation thrown name=' +
65563 name + ' msg=' + msg);
7c4c091b 65564 }
db71a655
KM
65565 test._observedDeprecations[deprecationId] = 1;
65566 };
7c4c091b 65567 }
7c4c091b 65568
db71a655
KM
65569 function teardownDeprecationHandler(test, moment$$1, scope) {
65570 moment$$1.suppressDeprecationWarnings = test._oldSupress;
65571
65572 if (test._expectedDeprecations != null) {
65573 var missedDeprecations = [];
65574 each(test._expectedDeprecations, function (deprecationPattern, id) {
65575 if (test._observedDeprecations[id] !== 1) {
65576 missedDeprecations.push(deprecationPattern);
65577 }
65578 });
65579 if (missedDeprecations.length !== 0) {
65580 throw new Error('Expected deprecation warnings did not happen: ' +
65581 missedDeprecations.join(' '));
65582 }
65583 }
7c4c091b 65584 }
db71a655
KM
65585
65586 function matchedDeprecation(name, msg, deprecations) {
65587 if (deprecations == null) {
65588 return -1;
7c4c091b 65589 }
db71a655
KM
65590 for (var i = 0; i < deprecations.length; ++i) {
65591 if (name != null && name === deprecations[i]) {
65592 return i;
65593 }
65594 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
65595 return i;
65596 }
7c4c091b 65597 }
db71a655 65598 return -1;
7c4c091b 65599 }
7c4c091b 65600
db71a655 65601 /*global QUnit:false*/
7c4c091b 65602
db71a655 65603 var test = QUnit.test;
7c4c091b 65604
db71a655
KM
65605 function module$1 (name, lifecycle) {
65606 QUnit.module(name, {
c58511b9 65607 beforeEach : function () {
db71a655
KM
65608 moment.locale('en');
65609 moment.createFromInputFallback = function (config) {
65610 throw new Error('input not handled by moment: ' + config._i);
65611 };
65612 setupDeprecationHandler(test, moment, 'core');
65613 if (lifecycle && lifecycle.setup) {
65614 lifecycle.setup();
65615 }
65616 },
c58511b9 65617 afterEach : function () {
db71a655
KM
65618 teardownDeprecationHandler(test, moment, 'core');
65619 if (lifecycle && lifecycle.teardown) {
65620 lifecycle.teardown();
65621 }
73f3c911 65622 }
db71a655
KM
65623 });
65624 }
65625
65626 // These tests are for locale independent features
65627
65628 module$1('calendar');
65629
65630 test('passing a function', function (assert) {
65631 var a = moment().hours(13).minutes(0).seconds(0);
65632 assert.equal(moment(a).calendar(null, {
65633 'sameDay': function () {
65634 return 'h:mmA';
65635 }
65636 }), '1:00PM', 'should equate');
65637 });
65638
65639 test('extending calendar options', function (assert) {
65640 var calendarFormat = moment.calendarFormat;
65641
65642 moment.calendarFormat = function (myMoment, now) {
65643 var diff = myMoment.diff(now, 'days', true);
65644 var nextMonth = now.clone().add(1, 'month');
65645
65646 var retVal = diff < -6 ? 'sameElse' :
65647 diff < -1 ? 'lastWeek' :
65648 diff < 0 ? 'lastDay' :
65649 diff < 1 ? 'sameDay' :
65650 diff < 2 ? 'nextDay' :
65651 diff < 7 ? 'nextWeek' :
65652 (myMoment.month() === now.month() && myMoment.year() === now.year()) ? 'thisMonth' :
65653 (nextMonth.month() === myMoment.month() && nextMonth.year() === myMoment.year()) ? 'nextMonth' : 'sameElse';
65654 return retVal;
65655 };
65656
65657 moment.updateLocale('en', {
65658 calendar : {
65659 sameDay : '[Today at] LT',
65660 nextDay : '[Tomorrow at] LT',
65661 nextWeek : 'dddd [at] LT',
65662 lastDay : '[Yesterday at] LT',
65663 lastWeek : '[Last] dddd [at] LT',
65664 thisMonth : '[This month on the] Do',
65665 nextMonth : '[Next month on the] Do',
65666 sameElse : 'L'
65667 }
65668 });
65669 var a = moment('2016-01-01').add(28, 'days');
65670 var b = moment('2016-01-01').add(1, 'month');
65671 try {
65672 assert.equal(a.calendar('2016-01-01'), 'This month on the 29th', 'Ad hoc calendar format for this month');
65673 assert.equal(b.calendar('2016-01-01'), 'Next month on the 1st', 'Ad hoc calendar format for next month');
65674 assert.equal(a.locale('fr').calendar('2016-01-01'), a.locale('fr').format('L'), 'French falls back to default because thisMonth is not defined in that locale');
65675 } finally {
65676 moment.calendarFormat = calendarFormat;
65677 moment.updateLocale('en', null);
65678 }
65679 });
73f3c911
IC
65680
65681})));
c74a101d 65682
c74a101d
IC
65683
65684;(function (global, factory) {
65685 typeof exports === 'object' && typeof module !== 'undefined'
65686 && typeof require === 'function' ? factory(require('../../moment')) :
65687 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
65688 factory(global.moment)
73f3c911 65689}(this, (function (moment) { 'use strict';
c74a101d 65690
db71a655
KM
65691 function each(array, callback) {
65692 var i;
65693 for (i = 0; i < array.length; i++) {
65694 callback(array[i], i, array);
65695 }
b135bf1a
IC
65696 }
65697
db71a655
KM
65698 function setupDeprecationHandler(test, moment$$1, scope) {
65699 test._expectedDeprecations = null;
65700 test._observedDeprecations = null;
65701 test._oldSupress = moment$$1.suppressDeprecationWarnings;
65702 moment$$1.suppressDeprecationWarnings = true;
65703 test.expectedDeprecations = function () {
65704 test._expectedDeprecations = arguments;
65705 test._observedDeprecations = [];
65706 };
65707 moment$$1.deprecationHandler = function (name, msg) {
65708 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
65709 if (deprecationId === -1) {
65710 throw new Error('Unexpected deprecation thrown name=' +
65711 name + ' msg=' + msg);
b135bf1a 65712 }
db71a655
KM
65713 test._observedDeprecations[deprecationId] = 1;
65714 };
b135bf1a
IC
65715 }
65716
db71a655
KM
65717 function teardownDeprecationHandler(test, moment$$1, scope) {
65718 moment$$1.suppressDeprecationWarnings = test._oldSupress;
b135bf1a 65719
db71a655
KM
65720 if (test._expectedDeprecations != null) {
65721 var missedDeprecations = [];
65722 each(test._expectedDeprecations, function (deprecationPattern, id) {
65723 if (test._observedDeprecations[id] !== 1) {
65724 missedDeprecations.push(deprecationPattern);
65725 }
65726 });
65727 if (missedDeprecations.length !== 0) {
65728 throw new Error('Expected deprecation warnings did not happen: ' +
65729 missedDeprecations.join(' '));
65730 }
73f3c911 65731 }
db71a655 65732 }
b135bf1a 65733
db71a655
KM
65734 function matchedDeprecation(name, msg, deprecations) {
65735 if (deprecations == null) {
65736 return -1;
73f3c911 65737 }
db71a655
KM
65738 for (var i = 0; i < deprecations.length; ++i) {
65739 if (name != null && name === deprecations[i]) {
65740 return i;
65741 }
65742 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
65743 return i;
65744 }
73f3c911 65745 }
db71a655
KM
65746 return -1;
65747 }
b135bf1a 65748
db71a655
KM
65749 /*global QUnit:false*/
65750
65751 var test = QUnit.test;
65752
db71a655
KM
65753 function module$1 (name, lifecycle) {
65754 QUnit.module(name, {
c58511b9 65755 beforeEach : function () {
db71a655
KM
65756 moment.locale('en');
65757 moment.createFromInputFallback = function (config) {
65758 throw new Error('input not handled by moment: ' + config._i);
65759 };
65760 setupDeprecationHandler(test, moment, 'core');
65761 if (lifecycle && lifecycle.setup) {
65762 lifecycle.setup();
65763 }
65764 },
c58511b9 65765 afterEach : function () {
db71a655
KM
65766 teardownDeprecationHandler(test, moment, 'core');
65767 if (lifecycle && lifecycle.teardown) {
65768 lifecycle.teardown();
65769 }
65770 }
b135bf1a 65771 });
db71a655 65772 }
d6651c21 65773
db71a655 65774 module$1('create');
d6651c21 65775
db71a655
KM
65776 test('array', function (assert) {
65777 assert.ok(moment([2010]).toDate() instanceof Date, '[2010]');
65778 assert.ok(moment([2010, 1]).toDate() instanceof Date, '[2010, 1]');
65779 assert.ok(moment([2010, 1, 12]).toDate() instanceof Date, '[2010, 1, 12]');
65780 assert.ok(moment([2010, 1, 12, 1]).toDate() instanceof Date, '[2010, 1, 12, 1]');
65781 assert.ok(moment([2010, 1, 12, 1, 1]).toDate() instanceof Date, '[2010, 1, 12, 1, 1]');
65782 assert.ok(moment([2010, 1, 12, 1, 1, 1]).toDate() instanceof Date, '[2010, 1, 12, 1, 1, 1]');
65783 assert.ok(moment([2010, 1, 12, 1, 1, 1, 1]).toDate() instanceof Date, '[2010, 1, 12, 1, 1, 1, 1]');
65784 assert.equal(+moment(new Date(2010, 1, 14, 15, 25, 50, 125)), +moment([2010, 1, 14, 15, 25, 50, 125]), 'constructing with array === constructing with new Date()');
65785 });
d6651c21 65786
db71a655
KM
65787 test('array with invalid arguments', function (assert) {
65788 assert.ok(!moment([2010, null, null]).isValid(), '[2010, null, null]');
65789 assert.ok(!moment([1945, null, null]).isValid(), '[1945, null, null] (pre-1970)');
65790 });
65791
65792 test('array copying', function (assert) {
65793 var importantArray = [2009, 11];
65794 moment(importantArray);
65795 assert.deepEqual(importantArray, [2009, 11], 'initializer should not mutate the original array');
65796 });
d6651c21 65797
db71a655
KM
65798 test('object', function (assert) {
65799 var fmt = 'YYYY-MM-DD HH:mm:ss.SSS',
65800 tests = [
65801 [{year: 2010}, '2010-01-01 00:00:00.000'],
65802 [{year: 2010, month: 1}, '2010-02-01 00:00:00.000'],
65803 [{year: 2010, month: 1, day: 12}, '2010-02-12 00:00:00.000'],
65804 [{year: 2010, month: 1, date: 12}, '2010-02-12 00:00:00.000'],
65805 [{year: 2010, month: 1, day: 12, hours: 1}, '2010-02-12 01:00:00.000'],
65806 [{year: 2010, month: 1, date: 12, hours: 1}, '2010-02-12 01:00:00.000'],
65807 [{year: 2010, month: 1, day: 12, hours: 1, minutes: 1}, '2010-02-12 01:01:00.000'],
65808 [{year: 2010, month: 1, date: 12, hours: 1, minutes: 1}, '2010-02-12 01:01:00.000'],
65809 [{year: 2010, month: 1, day: 12, hours: 1, minutes: 1, seconds: 1}, '2010-02-12 01:01:01.000'],
65810 [{year: 2010, month: 1, day: 12, hours: 1, minutes: 1, seconds: 1, milliseconds: 1}, '2010-02-12 01:01:01.001'],
65811 [{years: 2010, months: 1, days: 14, hours: 15, minutes: 25, seconds: 50, milliseconds: 125}, '2010-02-14 15:25:50.125'],
65812 [{year: 2010, month: 1, day: 14, hour: 15, minute: 25, second: 50, millisecond: 125}, '2010-02-14 15:25:50.125'],
65813 [{y: 2010, M: 1, d: 14, h: 15, m: 25, s: 50, ms: 125}, '2010-02-14 15:25:50.125']
65814 ], i;
65815 for (i = 0; i < tests.length; ++i) {
65816 assert.equal(moment(tests[i][0]).format(fmt), tests[i][1]);
d6651c21 65817 }
73f3c911
IC
65818 });
65819
db71a655
KM
65820 test('multi format array copying', function (assert) {
65821 var importantArray = ['MM/DD/YYYY', 'YYYY-MM-DD', 'MM-DD-YYYY'];
65822 moment('1999-02-13', importantArray);
65823 assert.deepEqual(importantArray, ['MM/DD/YYYY', 'YYYY-MM-DD', 'MM-DD-YYYY'], 'initializer should not mutate the original array');
65824 });
d6651c21 65825
db71a655
KM
65826 test('number', function (assert) {
65827 assert.ok(moment(1000).toDate() instanceof Date, '1000');
65828 assert.equal(moment(1000).valueOf(), 1000, 'asserting valueOf');
65829 assert.equal(moment.utc(1000).valueOf(), 1000, 'asserting valueOf');
65830 });
b135bf1a 65831
db71a655
KM
65832 test('unix', function (assert) {
65833 assert.equal(moment.unix(1).valueOf(), 1000, '1 unix timestamp == 1000 Date.valueOf');
65834 assert.equal(moment(1000).unix(), 1, '1000 Date.valueOf == 1 unix timestamp');
65835 assert.equal(moment.unix(1000).valueOf(), 1000000, '1000 unix timestamp == 1000000 Date.valueOf');
65836 assert.equal(moment(1500).unix(), 1, '1500 Date.valueOf == 1 unix timestamp');
65837 assert.equal(moment(1900).unix(), 1, '1900 Date.valueOf == 1 unix timestamp');
65838 assert.equal(moment(2100).unix(), 2, '2100 Date.valueOf == 2 unix timestamp');
65839 assert.equal(moment(1333129333524).unix(), 1333129333, '1333129333524 Date.valueOf == 1333129333 unix timestamp');
65840 assert.equal(moment(1333129333524000).unix(), 1333129333524, '1333129333524000 Date.valueOf == 1333129333524 unix timestamp');
65841 });
c74a101d 65842
db71a655
KM
65843 test('date', function (assert) {
65844 assert.ok(moment(new Date()).toDate() instanceof Date, 'new Date()');
65845 assert.equal(moment(new Date(2016,0,1), 'YYYY-MM-DD').format('YYYY-MM-DD'), '2016-01-01', 'If date is provided, format string is ignored');
65846 });
c74a101d 65847
db71a655
KM
65848 test('date with a format as an array', function (assert) {
65849 var tests = [
65850 new Date(2016, 9, 27),
65851 new Date(2016, 9, 28),
65852 new Date(2016, 9, 29),
65853 new Date(2016, 9, 30),
65854 new Date(2016, 9, 31)
65855 ], i;
c74a101d 65856
db71a655
KM
65857 for (i = 0; i < tests.length; i++) {
65858 assert.equal(moment(tests[i]).format(), moment(tests[i], ['MM/DD/YYYY'], false).format(), 'Passing date with a format array should still return the correct date');
1d986a17 65859 }
db71a655 65860 });
1d986a17 65861
db71a655
KM
65862 test('date mutation', function (assert) {
65863 var a = new Date();
65864 assert.ok(moment(a).toDate() !== a, 'the date moment uses should not be the date passed in');
65865 });
1d986a17 65866
db71a655
KM
65867 test('moment', function (assert) {
65868 assert.ok(moment(moment()).toDate() instanceof Date, 'moment(moment())');
65869 assert.ok(moment(moment(moment())).toDate() instanceof Date, 'moment(moment(moment()))');
65870 });
1d986a17 65871
db71a655
KM
65872 test('cloning moment should only copy own properties', function (assert) {
65873 assert.ok(!moment().clone().hasOwnProperty('month'), 'Should not clone prototype methods');
65874 });
1d986a17 65875
db71a655
KM
65876 test('cloning moment works with weird clones', function (assert) {
65877 var extend = function (a, b) {
65878 var i;
65879 for (i in b) {
65880 a[i] = b[i];
7c4c091b 65881 }
db71a655 65882 return a;
7c4c091b 65883 },
db71a655
KM
65884 now = moment(),
65885 nowu = moment.utc();
65886
65887 assert.equal(+extend({}, now).clone(), +now, 'cloning extend-ed now is now');
65888 assert.equal(+extend({}, nowu).clone(), +nowu, 'cloning extend-ed utc now is utc now');
65889 });
65890
65891 test('cloning respects moment.momentProperties', function (assert) {
65892 var m = moment();
65893
65894 assert.equal(m.clone()._special, undefined, 'cloning ignores extra properties');
65895 m._special = 'bacon';
65896 moment.momentProperties.push('_special');
65897 assert.equal(m.clone()._special, 'bacon', 'cloning respects momentProperties');
65898 moment.momentProperties.pop();
65899 });
65900
65901 test('undefined', function (assert) {
65902 assert.ok(moment().toDate() instanceof Date, 'undefined');
65903 });
65904
65905 test('iso with bad input', function (assert) {
65906 assert.ok(!moment('a', moment.ISO_8601).isValid(), 'iso parsing with invalid string');
65907 assert.ok(!moment('a', moment.ISO_8601, true).isValid(), 'iso parsing with invalid string, strict');
65908 });
65909
65910 test('iso format 24hrs', function (assert) {
65911 assert.equal(moment('2014-01-01T24:00:00.000').format('YYYY-MM-DD[T]HH:mm:ss.SSS'),
65912 '2014-01-02T00:00:00.000', 'iso format with 24:00 localtime');
65913 assert.equal(moment.utc('2014-01-01T24:00:00.000').format('YYYY-MM-DD[T]HH:mm:ss.SSS'),
65914 '2014-01-02T00:00:00.000', 'iso format with 24:00 utc');
65915 });
65916
65917 test('string without format - json', function (assert) {
65918 assert.equal(moment('Date(1325132654000)').valueOf(), 1325132654000, 'Date(1325132654000)');
65919 assert.equal(moment('Date(-1325132654000)').valueOf(), -1325132654000, 'Date(-1325132654000)');
65920 assert.equal(moment('/Date(1325132654000)/').valueOf(), 1325132654000, '/Date(1325132654000)/');
65921 assert.equal(moment('/Date(1325132654000+0700)/').valueOf(), 1325132654000, '/Date(1325132654000+0700)/');
65922 assert.equal(moment('/Date(1325132654000-0700)/').valueOf(), 1325132654000, '/Date(1325132654000-0700)/');
65923 });
7c4c091b 65924
db71a655
KM
65925 test('string with format dropped am/pm bug', function (assert) {
65926 moment.locale('en');
7c4c091b 65927
db71a655
KM
65928 assert.equal(moment('05/1/2012 12:25:00', 'MM/DD/YYYY h:m:s a').format('MM/DD/YYYY'), '05/01/2012', 'should not break if am/pm is left off from the parsing tokens');
65929 assert.equal(moment('05/1/2012 12:25:00 am', 'MM/DD/YYYY h:m:s a').format('MM/DD/YYYY'), '05/01/2012', 'should not break if am/pm is left off from the parsing tokens');
65930 assert.equal(moment('05/1/2012 12:25:00 pm', 'MM/DD/YYYY h:m:s a').format('MM/DD/YYYY'), '05/01/2012', 'should not break if am/pm is left off from the parsing tokens');
65931
65932 assert.ok(moment('05/1/2012 12:25:00', 'MM/DD/YYYY h:m:s a').isValid());
65933 assert.ok(moment('05/1/2012 12:25:00 am', 'MM/DD/YYYY h:m:s a').isValid());
65934 assert.ok(moment('05/1/2012 12:25:00 pm', 'MM/DD/YYYY h:m:s a').isValid());
65935 });
65936
65937 test('empty string with formats', function (assert) {
65938 assert.equal(moment('', 'MM').format('YYYY-MM-DD HH:mm:ss'), 'Invalid date');
65939 assert.equal(moment(' ', 'MM').format('YYYY-MM-DD HH:mm:ss'), 'Invalid date');
65940 assert.equal(moment(' ', 'DD').format('YYYY-MM-DD HH:mm:ss'), 'Invalid date');
65941 assert.equal(moment(' ', ['MM', 'DD']).format('YYYY-MM-DD HH:mm:ss'), 'Invalid date');
65942
65943 assert.ok(!moment('', 'MM').isValid());
65944 assert.ok(!moment(' ', 'MM').isValid());
65945 assert.ok(!moment(' ', 'DD').isValid());
65946 assert.ok(!moment(' ', ['MM', 'DD']).isValid());
65947 });
65948
65949 test('undefined argument with formats', function (assert) {
65950 assert.equal(moment(undefined, 'MM').format('YYYY-MM-DD HH:mm:ss'), 'Invalid date');
65951 assert.equal(moment(undefined, 'DD').format('YYYY-MM-DD HH:mm:ss'), 'Invalid date');
65952 assert.equal(moment(undefined, ['MM', 'DD']).format('YYYY-MM-DD HH:mm:ss'), 'Invalid date');
65953
65954 assert.ok(!moment(undefined, 'MM').isValid());
65955 assert.ok(!moment(undefined, 'MM').isValid());
65956 assert.ok(!moment(undefined, 'DD').isValid());
65957 assert.ok(!moment(undefined, ['MM', 'DD']).isValid());
65958 });
65959
65960 test('defaulting to current date', function (assert) {
65961 var now = moment();
65962 assert.equal(moment('12:13:14', 'hh:mm:ss').format('YYYY-MM-DD hh:mm:ss'),
65963 now.clone().hour(12).minute(13).second(14).format('YYYY-MM-DD hh:mm:ss'),
65964 'given only time default to current date');
65965 assert.equal(moment('05', 'DD').format('YYYY-MM-DD'),
65966 now.clone().date(5).format('YYYY-MM-DD'),
65967 'given day of month default to current month, year');
65968 assert.equal(moment('05', 'MM').format('YYYY-MM-DD'),
65969 now.clone().month(4).date(1).format('YYYY-MM-DD'),
65970 'given month default to current year');
65971 assert.equal(moment('1996', 'YYYY').format('YYYY-MM-DD'),
65972 now.clone().year(1996).month(0).date(1).format('YYYY-MM-DD'),
65973 'given year do not default');
65974 });
65975
65976 test('matching am/pm', function (assert) {
65977 assert.equal(moment('2012-09-03T03:00PM', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00PM', 'am/pm should parse correctly for PM');
65978 assert.equal(moment('2012-09-03T03:00P.M.', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00PM', 'am/pm should parse correctly for P.M.');
65979 assert.equal(moment('2012-09-03T03:00P', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00PM', 'am/pm should parse correctly for P');
65980 assert.equal(moment('2012-09-03T03:00pm', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00PM', 'am/pm should parse correctly for pm');
65981 assert.equal(moment('2012-09-03T03:00p.m.', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00PM', 'am/pm should parse correctly for p.m.');
65982 assert.equal(moment('2012-09-03T03:00p', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00PM', 'am/pm should parse correctly for p');
65983
65984 assert.equal(moment('2012-09-03T03:00AM', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00AM', 'am/pm should parse correctly for AM');
65985 assert.equal(moment('2012-09-03T03:00A.M.', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00AM', 'am/pm should parse correctly for A.M.');
65986 assert.equal(moment('2012-09-03T03:00A', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00AM', 'am/pm should parse correctly for A');
65987 assert.equal(moment('2012-09-03T03:00am', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00AM', 'am/pm should parse correctly for am');
65988 assert.equal(moment('2012-09-03T03:00a.m.', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00AM', 'am/pm should parse correctly for a.m.');
65989 assert.equal(moment('2012-09-03T03:00a', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00AM', 'am/pm should parse correctly for a');
65990
65991 assert.equal(moment('5:00p.m.March 4 2012', 'h:mmAMMMM D YYYY').format('YYYY-MM-DDThh:mmA'), '2012-03-04T05:00PM', 'am/pm should parse correctly before month names');
65992 });
65993
65994 test('string with format', function (assert) {
65995 moment.locale('en');
65996 var a = [
65997 ['YYYY-Q', '2014-4'],
65998 ['MM-DD-YYYY', '12-02-1999'],
65999 ['DD-MM-YYYY', '12-02-1999'],
66000 ['DD/MM/YYYY', '12/02/1999'],
66001 ['DD_MM_YYYY', '12_02_1999'],
66002 ['DD:MM:YYYY', '12:02:1999'],
66003 ['D-M-YY', '2-2-99'],
66004 ['YY', '99'],
66005 ['DDD-YYYY', '300-1999'],
66006 ['DD-MM-YYYY h:m:s', '12-02-1999 2:45:10'],
66007 ['DD-MM-YYYY h:m:s a', '12-02-1999 2:45:10 am'],
66008 ['DD-MM-YYYY h:m:s a', '12-02-1999 2:45:10 pm'],
66009 ['h:mm a', '12:00 pm'],
66010 ['h:mm a', '12:30 pm'],
66011 ['h:mm a', '12:00 am'],
66012 ['h:mm a', '12:30 am'],
66013 ['HH:mm', '12:00'],
66014 ['kk:mm', '12:00'],
66015 ['YYYY-MM-DDTHH:mm:ss', '2011-11-11T11:11:11'],
66016 ['MM-DD-YYYY [M]', '12-02-1999 M'],
66017 ['ddd MMM DD HH:mm:ss YYYY', 'Tue Apr 07 22:52:51 2009'],
66018 ['HH:mm:ss', '12:00:00'],
66019 ['HH:mm:ss', '12:30:00'],
66020 ['HH:mm:ss', '00:00:00'],
66021 ['HH:mm:ss S', '00:30:00 1'],
66022 ['HH:mm:ss SS', '00:30:00 12'],
66023 ['HH:mm:ss SSS', '00:30:00 123'],
66024 ['HH:mm:ss S', '00:30:00 7'],
66025 ['HH:mm:ss SS', '00:30:00 78'],
66026 ['HH:mm:ss SSS', '00:30:00 789'],
66027 ['kk:mm:ss', '12:00:00'],
66028 ['kk:mm:ss', '12:30:00'],
66029 ['kk:mm:ss', '24:00:00'],
66030 ['kk:mm:ss S', '24:30:00 1'],
66031 ['kk:mm:ss SS', '24:30:00 12'],
66032 ['kk:mm:ss SSS', '24:30:00 123'],
66033 ['kk:mm:ss S', '24:30:00 7'],
66034 ['kk:mm:ss SS', '24:30:00 78'],
66035 ['kk:mm:ss SSS', '24:30:00 789'],
66036 ['X', '1234567890'],
66037 ['x', '1234567890123'],
66038 ['LT', '12:30 AM'],
66039 ['LTS', '12:30:29 AM'],
66040 ['L', '09/02/1999'],
66041 ['l', '9/2/1999'],
66042 ['LL', 'September 2, 1999'],
66043 ['ll', 'Sep 2, 1999'],
66044 ['LLL', 'September 2, 1999 12:30 AM'],
66045 ['lll', 'Sep 2, 1999 12:30 AM'],
66046 ['LLLL', 'Thursday, September 2, 1999 12:30 AM'],
66047 ['llll', 'Thu, Sep 2, 1999 12:30 AM']
66048 ],
66049 m,
66050 i;
7c4c091b 66051
db71a655
KM
66052 for (i = 0; i < a.length; i++) {
66053 m = moment(a[i][1], a[i][0]);
66054 assert.ok(m.isValid());
66055 assert.equal(m.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
66056 }
66057 });
7c4c091b 66058
db71a655
KM
66059 test('2 digit year with YYYY format', function (assert) {
66060 assert.equal(moment('9/2/99', 'D/M/YYYY').format('DD/MM/YYYY'), '09/02/1999', 'D/M/YYYY ---> 9/2/99');
66061 assert.equal(moment('9/2/1999', 'D/M/YYYY').format('DD/MM/YYYY'), '09/02/1999', 'D/M/YYYY ---> 9/2/1999');
66062 assert.equal(moment('9/2/68', 'D/M/YYYY').format('DD/MM/YYYY'), '09/02/2068', 'D/M/YYYY ---> 9/2/68');
66063 assert.equal(moment('9/2/69', 'D/M/YYYY').format('DD/MM/YYYY'), '09/02/1969', 'D/M/YYYY ---> 9/2/69');
66064 });
7c4c091b 66065
db71a655
KM
66066 test('unix timestamp format', function (assert) {
66067 var formats = ['X', 'X.S', 'X.SS', 'X.SSS'], i, format;
1d986a17 66068
db71a655
KM
66069 for (i = 0; i < formats.length; i++) {
66070 format = formats[i];
66071 assert.equal(moment('1234567890', format).valueOf(), 1234567890 * 1000, format + ' matches timestamp without milliseconds');
66072 assert.equal(moment('1234567890.1', format).valueOf(), 1234567890 * 1000 + 100, format + ' matches timestamp with deciseconds');
66073 assert.equal(moment('1234567890.12', format).valueOf(), 1234567890 * 1000 + 120, format + ' matches timestamp with centiseconds');
66074 assert.equal(moment('1234567890.123', format).valueOf(), 1234567890 * 1000 + 123, format + ' matches timestamp with milliseconds');
7c4c091b 66075 }
db71a655 66076 });
7c4c091b 66077
db71a655
KM
66078 test('unix offset milliseconds', function (assert) {
66079 assert.equal(moment('1234567890123', 'x').valueOf(), 1234567890123, 'x matches unix offset in milliseconds');
66080 });
7c4c091b 66081
db71a655
KM
66082 test('milliseconds format', function (assert) {
66083 assert.equal(moment('1', 'S').get('ms'), 100, 'deciseconds');
66084 // assert.equal(moment('10', 'S', true).isValid(), false, 'deciseconds with two digits');
66085 // assert.equal(moment('1', 'SS', true).isValid(), false, 'centiseconds with one digits');
66086 assert.equal(moment('12', 'SS').get('ms'), 120, 'centiseconds');
66087 // assert.equal(moment('123', 'SS', true).isValid(), false, 'centiseconds with three digits');
66088 assert.equal(moment('123', 'SSS').get('ms'), 123, 'milliseconds');
66089 assert.equal(moment('1234', 'SSSS').get('ms'), 123, 'milliseconds with SSSS');
66090 assert.equal(moment('123456789101112', 'SSSS').get('ms'), 123, 'milliseconds with SSSS');
7c4c091b
KM
66091 });
66092
db71a655
KM
66093 test('string with format no separators', function (assert) {
66094 moment.locale('en');
66095 var a = [
66096 ['MMDDYYYY', '12021999'],
66097 ['DDMMYYYY', '12021999'],
66098 ['YYYYMMDD', '19991202'],
66099 ['DDMMMYYYY', '10Sep2001']
66100 ], i;
66101
66102 for (i = 0; i < a.length; i++) {
66103 assert.equal(moment(a[i][1], a[i][0]).format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]);
7c4c091b
KM
66104 }
66105 });
66106
db71a655
KM
66107 test('string with format (timezone)', function (assert) {
66108 assert.equal(moment('5 -0700', 'H ZZ').toDate().getUTCHours(), 12, 'parse hours \'5 -0700\' ---> \'H ZZ\'');
66109 assert.equal(moment('5 -07:00', 'H Z').toDate().getUTCHours(), 12, 'parse hours \'5 -07:00\' ---> \'H Z\'');
66110 assert.equal(moment('5 -0730', 'H ZZ').toDate().getUTCMinutes(), 30, 'parse hours \'5 -0730\' ---> \'H ZZ\'');
66111 assert.equal(moment('5 -07:30', 'H Z').toDate().getUTCMinutes(), 30, 'parse hours \'5 -07:0\' ---> \'H Z\'');
66112 assert.equal(moment('5 +0100', 'H ZZ').toDate().getUTCHours(), 4, 'parse hours \'5 +0100\' ---> \'H ZZ\'');
66113 assert.equal(moment('5 +01:00', 'H Z').toDate().getUTCHours(), 4, 'parse hours \'5 +01:00\' ---> \'H Z\'');
66114 assert.equal(moment('5 +0130', 'H ZZ').toDate().getUTCMinutes(), 30, 'parse hours \'5 +0130\' ---> \'H ZZ\'');
66115 assert.equal(moment('5 +01:30', 'H Z').toDate().getUTCMinutes(), 30, 'parse hours \'5 +01:30\' ---> \'H Z\'');
7c4c091b
KM
66116 });
66117
db71a655
KM
66118 test('string with format (timezone offset)', function (assert) {
66119 var a, b, c, d, e, f;
66120 a = new Date(Date.UTC(2011, 0, 1, 1));
66121 b = moment('2011 1 1 0 -01:00', 'YYYY MM DD HH Z');
66122 assert.equal(a.getHours(), b.hours(), 'date created with utc == parsed string with timezone offset');
66123 assert.equal(+a, +b, 'date created with utc == parsed string with timezone offset');
66124 c = moment('2011 2 1 10 -05:00', 'YYYY MM DD HH Z');
66125 d = moment('2011 2 1 8 -07:00', 'YYYY MM DD HH Z');
66126 assert.equal(c.hours(), d.hours(), '10 am central time == 8 am pacific time');
66127 e = moment.utc('20 07 2012 17:15:00', 'DD MM YYYY HH:mm:ss');
66128 f = moment.utc('20 07 2012 10:15:00 -0700', 'DD MM YYYY HH:mm:ss ZZ');
66129 assert.equal(e.hours(), f.hours(), 'parse timezone offset in utc');
7c4c091b
KM
66130 });
66131
db71a655
KM
66132 test('string with timezone around start of year', function (assert) {
66133 assert.equal(moment('2000-01-01T00:00:00.000+01:00').toISOString(), '1999-12-31T23:00:00.000Z', '+1:00 around 2000');
66134 assert.equal(moment('2000-01-01T00:00:00.000-01:00').toISOString(), '2000-01-01T01:00:00.000Z', '-1:00 around 2000');
66135 assert.equal(moment('1970-01-01T00:00:00.000+01:00').toISOString(), '1969-12-31T23:00:00.000Z', '+1:00 around 1970');
66136 assert.equal(moment('1970-01-01T00:00:00.000-01:00').toISOString(), '1970-01-01T01:00:00.000Z', '-1:00 around 1970');
66137 assert.equal(moment('1200-01-01T00:00:00.000+01:00').toISOString(), '1199-12-31T23:00:00.000Z', '+1:00 around 1200');
66138 assert.equal(moment('1200-01-01T00:00:00.000-01:00').toISOString(), '1200-01-01T01:00:00.000Z', '-1:00 around 1200');
66139 });
66140
66141 test('string with array of formats', function (assert) {
66142 var thursdayForCurrentWeek = moment()
66143 .day(4)
66144 .format('YYYY MM DD');
66145
66146 assert.equal(moment('11-02-1999', ['MM-DD-YYYY', 'DD-MM-YYYY']).format('MM DD YYYY'), '11 02 1999', 'switching month and day');
66147 assert.equal(moment('02-11-1999', ['MM/DD/YYYY', 'YYYY MM DD', 'MM-DD-YYYY']).format('MM DD YYYY'), '02 11 1999', 'year last');
66148 assert.equal(moment('1999-02-11', ['MM/DD/YYYY', 'YYYY MM DD', 'MM-DD-YYYY']).format('MM DD YYYY'), '02 11 1999', 'year first');
66149
66150 assert.equal(moment('02-11-1999', ['MM/DD/YYYY', 'YYYY MM DD']).format('MM DD YYYY'), '02 11 1999', 'year last');
66151 assert.equal(moment('1999-02-11', ['MM/DD/YYYY', 'YYYY MM DD']).format('MM DD YYYY'), '02 11 1999', 'year first');
66152 assert.equal(moment('02-11-1999', ['YYYY MM DD', 'MM/DD/YYYY']).format('MM DD YYYY'), '02 11 1999', 'year last');
66153 assert.equal(moment('1999-02-11', ['YYYY MM DD', 'MM/DD/YYYY']).format('MM DD YYYY'), '02 11 1999', 'year first');
66154
66155 assert.equal(moment('13-11-1999', ['MM/DD/YYYY', 'DD/MM/YYYY']).format('MM DD YYYY'), '11 13 1999', 'second must be month');
66156 assert.equal(moment('11-13-1999', ['MM/DD/YYYY', 'DD/MM/YYYY']).format('MM DD YYYY'), '11 13 1999', 'first must be month');
66157 assert.equal(moment('01-02-2000', ['MM/DD/YYYY', 'DD/MM/YYYY']).format('MM DD YYYY'), '01 02 2000', 'either can be a month, month first format');
66158 assert.equal(moment('02-01-2000', ['DD/MM/YYYY', 'MM/DD/YYYY']).format('MM DD YYYY'), '01 02 2000', 'either can be a month, day first format');
66159
66160 assert.equal(moment('11-02-10', ['MM/DD/YY', 'YY MM DD', 'DD-MM-YY']).format('MM DD YYYY'), '02 11 2010', 'all unparsed substrings have influence on format penalty');
66161 assert.equal(moment('11-02-10', ['MM-DD-YY HH:mm', 'YY MM DD']).format('MM DD YYYY'), '02 10 2011', 'prefer formats without extra tokens');
66162 assert.equal(moment('11-02-10 junk', ['MM-DD-YY', 'YY.MM.DD [junk]']).format('MM DD YYYY'), '02 10 2011', 'prefer formats that dont result in extra characters');
66163 assert.equal(moment('11-22-10', ['YY-MM-DD', 'YY-DD-MM']).format('MM DD YYYY'), '10 22 2011', 'prefer valid results');
66164
66165 assert.equal(moment('gibberish', ['YY-MM-DD', 'YY-DD-MM']).format('MM DD YYYY'), 'Invalid date', 'doest throw for invalid strings');
66166 assert.equal(moment('gibberish', []).format('MM DD YYYY'), 'Invalid date', 'doest throw for an empty array');
66167
66168 // https://github.com/moment/moment/issues/1143
66169 assert.equal(moment(
66170 'System Administrator and Database Assistant (7/1/2011), System Administrator and Database Assistant (7/1/2011), Database Coordinator (7/1/2011), Vice President (7/1/2011), System Administrator and Database Assistant (5/31/2012), Database Coordinator (7/1/2012), System Administrator and Database Assistant (7/1/2013)',
66171 ['MM/DD/YYYY', 'MM-DD-YYYY', 'YYYY-MM-DD', 'YYYY-MM-DDTHH:mm:ssZ'])
66172 .format('YYYY-MM-DD'), '2011-07-01', 'Works for long strings');
66173
66174 assert.equal(moment('11-02-10', ['MM.DD.YY', 'DD-MM-YY']).format('MM DD YYYY'), '02 11 2010', 'escape RegExp special characters on comparing');
66175
66176 assert.equal(moment('13-10-98', ['DD MM YY', 'DD MM YYYY'])._f, 'DD MM YY', 'use two digit year');
66177 assert.equal(moment('13-10-1998', ['DD MM YY', 'DD MM YYYY'])._f, 'DD MM YYYY', 'use four digit year');
66178
66179 assert.equal(moment('01', ['MM', 'DD'])._f, 'MM', 'Should use first valid format');
66180
66181 assert.equal(moment('Thursday 8:30pm', ['dddd h:mma']).format('YYYY MM DD dddd h:mma'), thursdayForCurrentWeek + ' Thursday 8:30pm', 'Default to current week');
66182 });
66183
66184 test('string with array of formats + ISO', function (assert) {
66185 assert.equal(moment('1994', [moment.ISO_8601, 'MM', 'HH:mm', 'YYYY']).year(), 1994, 'iso: assert parse YYYY');
66186 assert.equal(moment('17:15', [moment.ISO_8601, 'MM', 'HH:mm', 'YYYY']).hour(), 17, 'iso: assert parse HH:mm (1)');
66187 assert.equal(moment('24:15', [moment.ISO_8601, 'MM', 'kk:mm', 'YYYY']).hour(), 0, 'iso: assert parse kk:mm');
66188 assert.equal(moment('17:15', [moment.ISO_8601, 'MM', 'HH:mm', 'YYYY']).minutes(), 15, 'iso: assert parse HH:mm (2)');
66189 assert.equal(moment('06', [moment.ISO_8601, 'MM', 'HH:mm', 'YYYY']).month(), 6 - 1, 'iso: assert parse MM');
66190 assert.equal(moment('2012-06-01', [moment.ISO_8601, 'MM', 'HH:mm', 'YYYY']).parsingFlags().iso, true, 'iso: assert parse iso');
66191 assert.equal(moment('2014-05-05', [moment.ISO_8601, 'YYYY-MM-DD']).parsingFlags().iso, true, 'iso: edge case array precedence iso');
66192 assert.equal(moment('2014-05-05', ['YYYY-MM-DD', moment.ISO_8601]).parsingFlags().iso, false, 'iso: edge case array precedence not iso');
66193 });
66194
66195 test('string with format - years', function (assert) {
66196 assert.equal(moment('67', 'YY').format('YYYY'), '2067', '67 > 2067');
66197 assert.equal(moment('68', 'YY').format('YYYY'), '2068', '68 > 2068');
66198 assert.equal(moment('69', 'YY').format('YYYY'), '1969', '69 > 1969');
66199 assert.equal(moment('70', 'YY').format('YYYY'), '1970', '70 > 1970');
66200 });
66201
66202 test('implicit cloning', function (assert) {
66203 var momentA = moment([2011, 10, 10]),
66204 momentB = moment(momentA);
66205 momentA.month(5);
66206 assert.notEqual(momentA.month(), momentB.month(), 'Calling moment() on a moment will create a clone');
66207 });
66208
66209 test('explicit cloning', function (assert) {
66210 var momentA = moment([2011, 10, 10]),
66211 momentB = momentA.clone();
66212 momentA.month(5);
66213 assert.notEqual(momentA.month(), momentB.month(), 'Calling clone() on a moment will create a clone');
66214 });
66215
66216 test('cloning carrying over utc mode', function (assert) {
66217 assert.equal(moment().local().clone()._isUTC, false, 'An explicit cloned local moment should have _isUTC == false');
66218 assert.equal(moment().utc().clone()._isUTC, true, 'An cloned utc moment should have _isUTC == true');
66219 assert.equal(moment().clone()._isUTC, false, 'An explicit cloned local moment should have _isUTC == false');
66220 assert.equal(moment.utc().clone()._isUTC, true, 'An explicit cloned utc moment should have _isUTC == true');
66221 assert.equal(moment(moment().local())._isUTC, false, 'An implicit cloned local moment should have _isUTC == false');
66222 assert.equal(moment(moment().utc())._isUTC, true, 'An implicit cloned utc moment should have _isUTC == true');
66223 assert.equal(moment(moment())._isUTC, false, 'An implicit cloned local moment should have _isUTC == false');
66224 assert.equal(moment(moment.utc())._isUTC, true, 'An implicit cloned utc moment should have _isUTC == true');
66225 });
66226
66227 test('parsing RFC 2822', function (assert) {
66228 var testCases = {
66229 'Tue, 01 Nov 2016 01:23:45 UT': [2016, 10, 1, 1, 23, 45, 0],
66230 'Sun, 12 Apr 2015 05:06:07 GMT': [2015, 3, 12, 5, 6, 7, 0],
66231 'Tue, 01 Nov 2016 01:23:45 +0000': [2016, 10, 1, 1, 23, 45, 0],
66232 'Tue, 01 Nov 16 04:23:45 Z': [2016, 10, 1, 4, 23, 45, 0],
66233 '01 Nov 2016 05:23:45 z': [2016, 10, 1, 5, 23, 45, 0],
66234 '(Init Comment) Tue,\n 1 Nov 2016 (Split\n Comment) 07:23:45 +0000 (GMT)': [2016, 10, 1, 7, 23, 45, 0],
66235 'Mon, 02 Jan 2017 06:00:00 -0800': [2017, 0, 2, 6, 0, 0, -8 * 60],
66236 'Mon, 02 Jan 2017 06:00:00 +0800': [2017, 0, 2, 6, 0, 0, +8 * 60],
66237 'Mon, 02 Jan 2017 06:00:00 +0330': [2017, 0, 2, 6, 0, 0, +(3 * 60 + 30)],
66238 'Mon, 02 Jan 2017 06:00:00 -0330': [2017, 0, 2, 6, 0, 0, -(3 * 60 + 30)],
66239 'Mon, 02 Jan 2017 06:00:00 PST': [2017, 0, 2, 6, 0, 0, -8 * 60],
66240 'Mon, 02 Jan 2017 06:00:00 PDT': [2017, 0, 2, 6, 0, 0, -7 * 60],
66241 'Mon, 02 Jan 2017 06:00:00 MST': [2017, 0, 2, 6, 0, 0, -7 * 60],
66242 'Mon, 02 Jan 2017 06:00:00 MDT': [2017, 0, 2, 6, 0, 0, -6 * 60],
66243 'Mon, 02 Jan 2017 06:00:00 CST': [2017, 0, 2, 6, 0, 0, -6 * 60],
66244 'Mon, 02 Jan 2017 06:00:00 CDT': [2017, 0, 2, 6, 0, 0, -5 * 60],
66245 'Mon, 02 Jan 2017 06:00:00 EST': [2017, 0, 2, 6, 0, 0, -5 * 60],
66246 'Mon, 02 Jan 2017 06:00:00 EDT': [2017, 0, 2, 6, 0, 0, -4 * 60]
66247 };
7c4c091b 66248
db71a655 66249 var inp, tokens, parseResult, expResult;
7c4c091b 66250
db71a655
KM
66251 for (inp in testCases) {
66252 tokens = testCases[inp];
66253 parseResult = moment(inp, moment.RFC_2822, true).parseZone();
66254 expResult = moment.utc(tokens.slice(0, 6)).utcOffset(tokens[6], true);
66255 assert.ok(parseResult.isValid(), inp);
66256 assert.ok(parseResult.parsingFlags().rfc2822, inp + ' - rfc2822 parsingFlag');
66257 assert.equal(parseResult.utcOffset(), expResult.utcOffset(), inp + ' - zone');
66258 assert.equal(parseResult.valueOf(), expResult.valueOf(), inp + ' - correctness');
7c4c091b 66259 }
db71a655
KM
66260 });
66261
66262 test('non RFC 2822 strings', function (assert) {
66263 var testCases = {
66264 'RFC2822 datetime with all options but invalid day delimiter': 'Tue. 01 Nov 2016 01:23:45 GMT',
66265 'RFC2822 datetime with mismatching Day (weekday v date)': 'Mon, 01 Nov 2016 01:23:45 GMT'
66266 };
66267 var testCase;
7c4c091b 66268
db71a655
KM
66269 for (testCase in testCases) {
66270 var testResult = moment(testCases[testCase], moment.RFC_2822, true);
66271 assert.ok(!testResult.isValid(), testCase + ': ' + testResult + ' - is invalid rfc2822');
66272 assert.ok(!testResult.parsingFlags().rfc2822, testCase + ': ' + testResult + ' - rfc2822 parsingFlag');
7c4c091b
KM
66273 }
66274 });
66275
db71a655
KM
66276 test('parsing RFC 2822 in a different locale', function (assert) {
66277 var testCases = {
66278 'clean RFC2822 datetime with all options': 'Tue, 01 Nov 2016 01:23:45 UT',
66279 'clean RFC2822 datetime without comma': 'Tue 01 Nov 2016 02:23:45 GMT',
66280 'clean RFC2822 datetime without seconds': 'Tue, 01 Nov 2016 03:23 +0000',
66281 'clean RFC2822 datetime without century': 'Tue, 01 Nov 16 04:23:45 Z',
66282 'clean RFC2822 datetime without day': '01 Nov 2016 05:23:45 z',
66283 'clean RFC2822 datetime with single-digit day-of-month': 'Tue, 1 Nov 2016 06:23:45 GMT',
66284 'RFC2822 datetime with CFWSs': '(Init Comment) Tue,\n 1 Nov 2016 (Split\n Comment) 07:23:45 +0000 (GMT)'
66285 };
66286 var testCase;
7c4c091b 66287
db71a655
KM
66288 try {
66289 moment.locale('ru');
66290 for (testCase in testCases) {
66291 var testResult = moment(testCases[testCase], moment.RFC_2822, true);
66292 assert.ok(testResult.isValid(), testResult);
66293 assert.ok(testResult.parsingFlags().rfc2822, testResult + ' - rfc2822 parsingFlag');
66294 }
7c4c091b 66295 }
db71a655
KM
66296 finally {
66297 moment.locale('en');
7c4c091b 66298 }
db71a655 66299 });
7c4c091b 66300
db71a655
KM
66301 test('non RFC 2822 strings in a different locale', function (assert) {
66302 var testCases = {
66303 'RFC2822 datetime with all options but invalid day delimiter': 'Tue. 01 Nov 2016 01:23:45 GMT',
66304 'RFC2822 datetime with mismatching Day (week v date)': 'Mon, 01 Nov 2016 01:23:45 GMT'
66305 };
66306 var testCase;
7c4c091b 66307
db71a655
KM
66308 try {
66309 moment.locale('ru');
66310 for (testCase in testCases) {
66311 var testResult = moment(testCases[testCase], moment.RFC_2822, true);
66312 assert.ok(!testResult.isValid(), testResult);
66313 assert.ok(!testResult.parsingFlags().rfc2822, testResult + ' - rfc2822 parsingFlag');
7c4c091b 66314 }
7c4c091b 66315 }
db71a655
KM
66316 finally {
66317 moment.locale('en');
7c4c091b 66318 }
db71a655
KM
66319 });
66320
66321 test('parsing iso', function (assert) {
66322 var offset = moment([2011, 9, 8]).utcOffset(),
66323 pad = function (input) {
66324 if (input < 10) {
66325 return '0' + input;
66326 }
66327 return '' + input;
66328 },
66329 hourOffset = (offset > 0 ? Math.floor(offset / 60) : Math.ceil(offset / 60)),
66330 minOffset = offset - (hourOffset * 60),
66331 tz = (offset >= 0) ?
66332 '+' + pad(hourOffset) + ':' + pad(minOffset) :
66333 '-' + pad(-hourOffset) + ':' + pad(-minOffset),
66334 tz2 = tz.replace(':', ''),
66335 tz3 = tz2.slice(0, 3),
66336 //Tz3 removes minutes digit so will break the tests when parsed if they all use the same minutes digit
66337 minutesForTz3 = pad((4 + minOffset) % 60),
66338 formats = [
66339 ['2011-10-08', '2011-10-08T00:00:00.000' + tz],
66340 ['2011-10-08T18', '2011-10-08T18:00:00.000' + tz],
66341 ['2011-10-08T18:04', '2011-10-08T18:04:00.000' + tz],
66342 ['2011-10-08T18:04:20', '2011-10-08T18:04:20.000' + tz],
66343 ['2011-10-08T18:04' + tz, '2011-10-08T18:04:00.000' + tz],
66344 ['2011-10-08T18:04:20' + tz, '2011-10-08T18:04:20.000' + tz],
66345 ['2011-10-08T18:04' + tz2, '2011-10-08T18:04:00.000' + tz],
66346 ['2011-10-08T18:04:20' + tz2, '2011-10-08T18:04:20.000' + tz],
66347 ['2011-10-08T18:04' + tz3, '2011-10-08T18:' + minutesForTz3 + ':00.000' + tz],
66348 ['2011-10-08T18:04:20' + tz3, '2011-10-08T18:' + minutesForTz3 + ':20.000' + tz],
66349 ['2011-10-08T18:04:20.1' + tz2, '2011-10-08T18:04:20.100' + tz],
66350 ['2011-10-08T18:04:20.11' + tz2, '2011-10-08T18:04:20.110' + tz],
66351 ['2011-10-08T18:04:20.111' + tz2, '2011-10-08T18:04:20.111' + tz],
66352 ['2011-10-08 18', '2011-10-08T18:00:00.000' + tz],
66353 ['2011-10-08 18:04', '2011-10-08T18:04:00.000' + tz],
66354 ['2011-10-08 18:04:20', '2011-10-08T18:04:20.000' + tz],
66355 ['2011-10-08 18:04' + tz, '2011-10-08T18:04:00.000' + tz],
66356 ['2011-10-08 18:04:20' + tz, '2011-10-08T18:04:20.000' + tz],
66357 ['2011-10-08 18:04' + tz2, '2011-10-08T18:04:00.000' + tz],
66358 ['2011-10-08 18:04:20' + tz2, '2011-10-08T18:04:20.000' + tz],
66359 ['2011-10-08 18:04' + tz3, '2011-10-08T18:' + minutesForTz3 + ':00.000' + tz],
66360 ['2011-10-08 18:04:20' + tz3, '2011-10-08T18:' + minutesForTz3 + ':20.000' + tz],
66361 ['2011-10-08 18:04:20.1' + tz2, '2011-10-08T18:04:20.100' + tz],
66362 ['2011-10-08 18:04:20.11' + tz2, '2011-10-08T18:04:20.110' + tz],
66363 ['2011-10-08 18:04:20.111' + tz2, '2011-10-08T18:04:20.111' + tz],
66364 ['2011-W40', '2011-10-03T00:00:00.000' + tz],
66365 ['2011-W40-6', '2011-10-08T00:00:00.000' + tz],
66366 ['2011-W40-6T18', '2011-10-08T18:00:00.000' + tz],
66367 ['2011-W40-6T18:04', '2011-10-08T18:04:00.000' + tz],
66368 ['2011-W40-6T18:04:20', '2011-10-08T18:04:20.000' + tz],
66369 ['2011-W40-6T18:04' + tz, '2011-10-08T18:04:00.000' + tz],
66370 ['2011-W40-6T18:04:20' + tz, '2011-10-08T18:04:20.000' + tz],
66371 ['2011-W40-6T18:04' + tz2, '2011-10-08T18:04:00.000' + tz],
66372 ['2011-W40-6T18:04:20' + tz2, '2011-10-08T18:04:20.000' + tz],
66373 ['2011-W40-6T18:04' + tz3, '2011-10-08T18:' + minutesForTz3 + ':00.000' + tz],
66374 ['2011-W40-6T18:04:20' + tz3, '2011-10-08T18:' + minutesForTz3 + ':20.000' + tz],
66375 ['2011-W40-6T18:04:20.1' + tz2, '2011-10-08T18:04:20.100' + tz],
66376 ['2011-W40-6T18:04:20.11' + tz2, '2011-10-08T18:04:20.110' + tz],
66377 ['2011-W40-6T18:04:20.111' + tz2, '2011-10-08T18:04:20.111' + tz],
66378 ['2011-W40-6 18', '2011-10-08T18:00:00.000' + tz],
66379 ['2011-W40-6 18:04', '2011-10-08T18:04:00.000' + tz],
66380 ['2011-W40-6 18:04:20', '2011-10-08T18:04:20.000' + tz],
66381 ['2011-W40-6 18:04' + tz, '2011-10-08T18:04:00.000' + tz],
66382 ['2011-W40-6 18:04:20' + tz, '2011-10-08T18:04:20.000' + tz],
66383 ['2011-W40-6 18:04' + tz2, '2011-10-08T18:04:00.000' + tz],
66384 ['2011-W40-6 18:04:20' + tz2, '2011-10-08T18:04:20.000' + tz],
66385 ['2011-W40-6 18:04' + tz3, '2011-10-08T18:' + minutesForTz3 + ':00.000' + tz],
66386 ['2011-W40-6 18:04:20' + tz3, '2011-10-08T18:' + minutesForTz3 + ':20.000' + tz],
66387 ['2011-W40-6 18:04:20.1' + tz2, '2011-10-08T18:04:20.100' + tz],
66388 ['2011-W40-6 18:04:20.11' + tz2, '2011-10-08T18:04:20.110' + tz],
66389 ['2011-W40-6 18:04:20.111' + tz2, '2011-10-08T18:04:20.111' + tz],
66390 ['2011-281', '2011-10-08T00:00:00.000' + tz],
66391 ['2011-281T18', '2011-10-08T18:00:00.000' + tz],
66392 ['2011-281T18:04', '2011-10-08T18:04:00.000' + tz],
66393 ['2011-281T18:04:20', '2011-10-08T18:04:20.000' + tz],
66394 ['2011-281T18:04' + tz, '2011-10-08T18:04:00.000' + tz],
66395 ['2011-281T18:04:20' + tz, '2011-10-08T18:04:20.000' + tz],
66396 ['2011-281T18:04' + tz2, '2011-10-08T18:04:00.000' + tz],
66397 ['2011-281T18:04:20' + tz2, '2011-10-08T18:04:20.000' + tz],
66398 ['2011-281T18:04' + tz3, '2011-10-08T18:' + minutesForTz3 + ':00.000' + tz],
66399 ['2011-281T18:04:20' + tz3, '2011-10-08T18:' + minutesForTz3 + ':20.000' + tz],
66400 ['2011-281T18:04:20.1' + tz2, '2011-10-08T18:04:20.100' + tz],
66401 ['2011-281T18:04:20.11' + tz2, '2011-10-08T18:04:20.110' + tz],
66402 ['2011-281T18:04:20.111' + tz2, '2011-10-08T18:04:20.111' + tz],
66403 ['2011-281 18', '2011-10-08T18:00:00.000' + tz],
66404 ['2011-281 18:04', '2011-10-08T18:04:00.000' + tz],
66405 ['2011-281 18:04:20', '2011-10-08T18:04:20.000' + tz],
66406 ['2011-281 18:04' + tz, '2011-10-08T18:04:00.000' + tz],
66407 ['2011-281 18:04:20' + tz, '2011-10-08T18:04:20.000' + tz],
66408 ['2011-281 18:04' + tz2, '2011-10-08T18:04:00.000' + tz],
66409 ['2011-281 18:04:20' + tz2, '2011-10-08T18:04:20.000' + tz],
66410 ['2011-281 18:04' + tz3, '2011-10-08T18:' + minutesForTz3 + ':00.000' + tz],
66411 ['2011-281 18:04:20' + tz3, '2011-10-08T18:' + minutesForTz3 + ':20.000' + tz],
66412 ['2011-281 18:04:20.1' + tz2, '2011-10-08T18:04:20.100' + tz],
66413 ['2011-281 18:04:20.11' + tz2, '2011-10-08T18:04:20.110' + tz],
66414 ['2011-281 18:04:20.111' + tz2, '2011-10-08T18:04:20.111' + tz],
66415 ['20111008T18', '2011-10-08T18:00:00.000' + tz],
66416 ['20111008T1804', '2011-10-08T18:04:00.000' + tz],
66417 ['20111008T180420', '2011-10-08T18:04:20.000' + tz],
66418 ['20111008T1804' + tz, '2011-10-08T18:04:00.000' + tz],
66419 ['20111008T180420' + tz, '2011-10-08T18:04:20.000' + tz],
66420 ['20111008T1804' + tz2, '2011-10-08T18:04:00.000' + tz],
66421 ['20111008T180420' + tz2, '2011-10-08T18:04:20.000' + tz],
66422 ['20111008T1804' + tz3, '2011-10-08T18:' + minutesForTz3 + ':00.000' + tz],
66423 ['20111008T180420' + tz3, '2011-10-08T18:' + minutesForTz3 + ':20.000' + tz],
66424 ['20111008T180420,1' + tz2, '2011-10-08T18:04:20.100' + tz],
66425 ['20111008T180420,11' + tz2, '2011-10-08T18:04:20.110' + tz],
66426 ['20111008T180420,111' + tz2, '2011-10-08T18:04:20.111' + tz],
66427 ['20111008 18', '2011-10-08T18:00:00.000' + tz],
66428 ['20111008 1804', '2011-10-08T18:04:00.000' + tz],
66429 ['20111008 180420', '2011-10-08T18:04:20.000' + tz],
66430 ['20111008 1804' + tz, '2011-10-08T18:04:00.000' + tz],
66431 ['20111008 180420' + tz, '2011-10-08T18:04:20.000' + tz],
66432 ['20111008 1804' + tz2, '2011-10-08T18:04:00.000' + tz],
66433 ['20111008 180420' + tz2, '2011-10-08T18:04:20.000' + tz],
66434 ['20111008 1804' + tz3, '2011-10-08T18:' + minutesForTz3 + ':00.000' + tz],
66435 ['20111008 180420' + tz3, '2011-10-08T18:' + minutesForTz3 + ':20.000' + tz],
66436 ['20111008 180420,1' + tz2, '2011-10-08T18:04:20.100' + tz],
66437 ['20111008 180420,11' + tz2, '2011-10-08T18:04:20.110' + tz],
66438 ['20111008 180420,111' + tz2, '2011-10-08T18:04:20.111' + tz],
66439 ['2011W40', '2011-10-03T00:00:00.000' + tz],
66440 ['2011W406', '2011-10-08T00:00:00.000' + tz],
66441 ['2011W406T18', '2011-10-08T18:00:00.000' + tz],
66442 ['2011W406T1804', '2011-10-08T18:04:00.000' + tz],
66443 ['2011W406T180420', '2011-10-08T18:04:20.000' + tz],
66444 ['2011W406 1804' + tz2, '2011-10-08T18:04:00.000' + tz],
66445 ['2011W406T1804' + tz, '2011-10-08T18:04:00.000' + tz],
66446 ['2011W406T180420' + tz, '2011-10-08T18:04:20.000' + tz],
66447 ['2011W406T1804' + tz2, '2011-10-08T18:04:00.000' + tz],
66448 ['2011W406T180420' + tz2, '2011-10-08T18:04:20.000' + tz],
66449 ['2011W406T1804' + tz3, '2011-10-08T18:' + minutesForTz3 + ':00.000' + tz],
66450 ['2011W406T180420' + tz3, '2011-10-08T18:' + minutesForTz3 + ':20.000' + tz],
66451 ['2011W406T180420,1' + tz2, '2011-10-08T18:04:20.100' + tz],
66452 ['2011W406T180420,11' + tz2, '2011-10-08T18:04:20.110' + tz],
66453 ['2011W406T180420,111' + tz2, '2011-10-08T18:04:20.111' + tz],
66454 ['2011W406 18', '2011-10-08T18:00:00.000' + tz],
66455 ['2011W406 1804', '2011-10-08T18:04:00.000' + tz],
66456 ['2011W406 180420', '2011-10-08T18:04:20.000' + tz],
66457 ['2011W406 1804' + tz, '2011-10-08T18:04:00.000' + tz],
66458 ['2011W406 180420' + tz, '2011-10-08T18:04:20.000' + tz],
66459 ['2011W406 180420' + tz2, '2011-10-08T18:04:20.000' + tz],
66460 ['2011W406 1804' + tz3, '2011-10-08T18:' + minutesForTz3 + ':00.000' + tz],
66461 ['2011W406 180420' + tz3, '2011-10-08T18:' + minutesForTz3 + ':20.000' + tz],
66462 ['2011W406 180420,1' + tz2, '2011-10-08T18:04:20.100' + tz],
66463 ['2011W406 180420,11' + tz2, '2011-10-08T18:04:20.110' + tz],
66464 ['2011W406 180420,111' + tz2, '2011-10-08T18:04:20.111' + tz],
66465 ['2011281', '2011-10-08T00:00:00.000' + tz],
66466 ['2011281T18', '2011-10-08T18:00:00.000' + tz],
66467 ['2011281T1804', '2011-10-08T18:04:00.000' + tz],
66468 ['2011281T180420', '2011-10-08T18:04:20.000' + tz],
66469 ['2011281T1804' + tz, '2011-10-08T18:04:00.000' + tz],
66470 ['2011281T180420' + tz, '2011-10-08T18:04:20.000' + tz],
66471 ['2011281T1804' + tz2, '2011-10-08T18:04:00.000' + tz],
66472 ['2011281T180420' + tz2, '2011-10-08T18:04:20.000' + tz],
66473 ['2011281T1804' + tz3, '2011-10-08T18:' + minutesForTz3 + ':00.000' + tz],
66474 ['2011281T180420' + tz3, '2011-10-08T18:' + minutesForTz3 + ':20.000' + tz],
66475 ['2011281T180420,1' + tz2, '2011-10-08T18:04:20.100' + tz],
66476 ['2011281T180420,11' + tz2, '2011-10-08T18:04:20.110' + tz],
66477 ['2011281T180420,111' + tz2, '2011-10-08T18:04:20.111' + tz],
66478 ['2011281 18', '2011-10-08T18:00:00.000' + tz],
66479 ['2011281 1804', '2011-10-08T18:04:00.000' + tz],
66480 ['2011281 180420', '2011-10-08T18:04:20.000' + tz],
66481 ['2011281 1804' + tz, '2011-10-08T18:04:00.000' + tz],
66482 ['2011281 180420' + tz, '2011-10-08T18:04:20.000' + tz],
66483 ['2011281 1804' + tz2, '2011-10-08T18:04:00.000' + tz],
66484 ['2011281 180420' + tz2, '2011-10-08T18:04:20.000' + tz],
66485 ['2011281 1804' + tz3, '2011-10-08T18:' + minutesForTz3 + ':00.000' + tz],
66486 ['2011281 180420' + tz3, '2011-10-08T18:' + minutesForTz3 + ':20.000' + tz],
66487 ['2011281 180420,1' + tz2, '2011-10-08T18:04:20.100' + tz],
66488 ['2011281 180420,11' + tz2, '2011-10-08T18:04:20.110' + tz],
66489 ['2011281 180420,111' + tz2, '2011-10-08T18:04:20.111' + tz]
66490 ], i;
66491 for (i = 0; i < formats.length; i++) {
66492 assert.equal(moment(formats[i][0]).format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
66493 formats[i][1], 'moment should be able to parse ISO ' + formats[i][0]);
66494 assert.equal(moment(formats[i][0], moment.ISO_8601).format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
66495 formats[i][1], 'moment should be able to parse specified ISO ' + formats[i][0]);
66496 assert.equal(moment(formats[i][0], moment.ISO_8601, true).format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
66497 formats[i][1], 'moment should be able to parse specified strict ISO ' + formats[i][0]);
7c4c091b 66498 }
db71a655 66499 });
7c4c091b 66500
db71a655
KM
66501 test('non iso 8601 strings', function (assert) {
66502 assert.ok(!moment('2015-10T10:15', moment.ISO_8601, true).isValid(), 'incomplete date with time');
66503 assert.ok(!moment('2015-W10T10:15', moment.ISO_8601, true).isValid(), 'incomplete week date with time');
66504 assert.ok(!moment('201510', moment.ISO_8601, true).isValid(), 'basic YYYYMM is not allowed');
66505 assert.ok(!moment('2015W10T1015', moment.ISO_8601, true).isValid(), 'incomplete week date with time (basic)');
66506 assert.ok(!moment('2015-10-08T1015', moment.ISO_8601, true).isValid(), 'mixing extended and basic format');
66507 assert.ok(!moment('20151008T10:15', moment.ISO_8601, true).isValid(), 'mixing basic and extended format');
66508 assert.ok(!moment('2015-10-1', moment.ISO_8601, true).isValid(), 'missing zero padding for day');
66509 });
7c4c091b 66510
db71a655
KM
66511 test('parsing iso week year/week/weekday', function (assert) {
66512 assert.equal(moment.utc('2007-W01').format(), '2007-01-01T00:00:00Z', '2008 week 1 (1st Jan Mon)');
66513 assert.equal(moment.utc('2008-W01').format(), '2007-12-31T00:00:00Z', '2008 week 1 (1st Jan Tue)');
66514 assert.equal(moment.utc('2003-W01').format(), '2002-12-30T00:00:00Z', '2008 week 1 (1st Jan Wed)');
66515 assert.equal(moment.utc('2009-W01').format(), '2008-12-29T00:00:00Z', '2009 week 1 (1st Jan Thu)');
66516 assert.equal(moment.utc('2010-W01').format(), '2010-01-04T00:00:00Z', '2010 week 1 (1st Jan Fri)');
66517 assert.equal(moment.utc('2011-W01').format(), '2011-01-03T00:00:00Z', '2011 week 1 (1st Jan Sat)');
66518 assert.equal(moment.utc('2012-W01').format(), '2012-01-02T00:00:00Z', '2012 week 1 (1st Jan Sun)');
66519 });
7c4c091b 66520
db71a655
KM
66521 test('parsing weekdays verifies the day', function (assert) {
66522 // string with format
66523 assert.ok(!moment('Wed 08-10-2017', 'ddd MM-DD-YYYY').isValid(), 'because day of week is incorrect for the date');
66524 assert.ok(moment('Thu 08-10-2017', 'ddd MM-DD-YYYY').isValid(), 'because day of week is correct for the date');
66525 });
73f3c911 66526
db71a655
KM
66527 test('parsing weekday on utc dates verifies day acccording to utc time', function (assert) {
66528 assert.ok(moment.utc('Mon 03:59', 'ddd HH:mm').isValid(), 'Monday 03:59');
66529 });
73f3c911 66530
db71a655
KM
66531 test('parsing weekday on local dates verifies day acccording to local time', function (assert) {
66532 // this doesn't do much useful if you're not in the US or at least close to it
66533 assert.ok(moment('Mon 03:59', 'ddd HH:mm').isValid(), 'Monday 03:59');
66534 });
1d986a17 66535
db71a655
KM
66536 test('parsing weekday on utc dates with specified offsets verifies day acccording to that offset', function (assert) {
66537 assert.ok(moment.utc('Mon 03:59 +12:00', 'ddd HH:mm Z', true).isValid(), 'Monday 03:59');
66538 });
1d986a17 66539
db71a655
KM
66540 test('parsing weekday on local dates with specified offsets verifies day acccording to that offset', function (assert) {
66541 // if you're in the US, these times will all be sometime Sunday, but they shoud parse as Monday
66542 assert.ok(moment('Mon 03:59 +12:00', 'ddd HH:mm Z', true).isValid(), 'Monday 03:59');
66543 });
1d986a17 66544
db71a655
KM
66545 test('parsing week year/week/weekday (dow 1, doy 4)', function (assert) {
66546 moment.locale('dow:1,doy:4', {week: {dow: 1, doy: 4}});
b135bf1a 66547
db71a655
KM
66548 assert.equal(moment.utc('2007-01', 'gggg-ww').format(), '2007-01-01T00:00:00Z', '2007 week 1 (1st Jan Mon)');
66549 assert.equal(moment.utc('2008-01', 'gggg-ww').format(), '2007-12-31T00:00:00Z', '2008 week 1 (1st Jan Tue)');
66550 assert.equal(moment.utc('2003-01', 'gggg-ww').format(), '2002-12-30T00:00:00Z', '2003 week 1 (1st Jan Wed)');
66551 assert.equal(moment.utc('2009-01', 'gggg-ww').format(), '2008-12-29T00:00:00Z', '2009 week 1 (1st Jan Thu)');
66552 assert.equal(moment.utc('2010-01', 'gggg-ww').format(), '2010-01-04T00:00:00Z', '2010 week 1 (1st Jan Fri)');
66553 assert.equal(moment.utc('2011-01', 'gggg-ww').format(), '2011-01-03T00:00:00Z', '2011 week 1 (1st Jan Sat)');
66554 assert.equal(moment.utc('2012-01', 'gggg-ww').format(), '2012-01-02T00:00:00Z', '2012 week 1 (1st Jan Sun)');
b135bf1a 66555
db71a655
KM
66556 moment.defineLocale('dow:1,doy:4', null);
66557 });
b135bf1a 66558
db71a655
KM
66559 test('parsing week year/week/weekday (dow 1, doy 7)', function (assert) {
66560 moment.locale('dow:1,doy:7', {week: {dow: 1, doy: 7}});
66561
66562 assert.equal(moment.utc('2007-01', 'gggg-ww').format(), '2007-01-01T00:00:00Z', '2007 week 1 (1st Jan Mon)');
66563 assert.equal(moment.utc('2008-01', 'gggg-ww').format(), '2007-12-31T00:00:00Z', '2008 week 1 (1st Jan Tue)');
66564 assert.equal(moment.utc('2003-01', 'gggg-ww').format(), '2002-12-30T00:00:00Z', '2003 week 1 (1st Jan Wed)');
66565 assert.equal(moment.utc('2009-01', 'gggg-ww').format(), '2008-12-29T00:00:00Z', '2009 week 1 (1st Jan Thu)');
66566 assert.equal(moment.utc('2010-01', 'gggg-ww').format(), '2009-12-28T00:00:00Z', '2010 week 1 (1st Jan Fri)');
66567 assert.equal(moment.utc('2011-01', 'gggg-ww').format(), '2010-12-27T00:00:00Z', '2011 week 1 (1st Jan Sat)');
66568 assert.equal(moment.utc('2012-01', 'gggg-ww').format(), '2011-12-26T00:00:00Z', '2012 week 1 (1st Jan Sun)');
66569 moment.defineLocale('dow:1,doy:7', null);
66570 });
66571
66572 test('parsing week year/week/weekday (dow 0, doy 6)', function (assert) {
66573 moment.locale('dow:0,doy:6', {week: {dow: 0, doy: 6}});
66574
66575 assert.equal(moment.utc('2007-01', 'gggg-ww').format(), '2006-12-31T00:00:00Z', '2007 week 1 (1st Jan Mon)');
66576 assert.equal(moment.utc('2008-01', 'gggg-ww').format(), '2007-12-30T00:00:00Z', '2008 week 1 (1st Jan Tue)');
66577 assert.equal(moment.utc('2003-01', 'gggg-ww').format(), '2002-12-29T00:00:00Z', '2003 week 1 (1st Jan Wed)');
66578 assert.equal(moment.utc('2009-01', 'gggg-ww').format(), '2008-12-28T00:00:00Z', '2009 week 1 (1st Jan Thu)');
66579 assert.equal(moment.utc('2010-01', 'gggg-ww').format(), '2009-12-27T00:00:00Z', '2010 week 1 (1st Jan Fri)');
66580 assert.equal(moment.utc('2011-01', 'gggg-ww').format(), '2010-12-26T00:00:00Z', '2011 week 1 (1st Jan Sat)');
66581 assert.equal(moment.utc('2012-01', 'gggg-ww').format(), '2012-01-01T00:00:00Z', '2012 week 1 (1st Jan Sun)');
66582 moment.defineLocale('dow:0,doy:6', null);
66583 });
66584
66585 test('parsing week year/week/weekday (dow 6, doy 12)', function (assert) {
66586 moment.locale('dow:6,doy:12', {week: {dow: 6, doy: 12}});
66587
66588 assert.equal(moment.utc('2007-01', 'gggg-ww').format(), '2006-12-30T00:00:00Z', '2007 week 1 (1st Jan Mon)');
66589 assert.equal(moment.utc('2008-01', 'gggg-ww').format(), '2007-12-29T00:00:00Z', '2008 week 1 (1st Jan Tue)');
66590 assert.equal(moment.utc('2003-01', 'gggg-ww').format(), '2002-12-28T00:00:00Z', '2003 week 1 (1st Jan Wed)');
66591 assert.equal(moment.utc('2009-01', 'gggg-ww').format(), '2008-12-27T00:00:00Z', '2009 week 1 (1st Jan Thu)');
66592 assert.equal(moment.utc('2010-01', 'gggg-ww').format(), '2009-12-26T00:00:00Z', '2010 week 1 (1st Jan Fri)');
66593 assert.equal(moment.utc('2011-01', 'gggg-ww').format(), '2011-01-01T00:00:00Z', '2011 week 1 (1st Jan Sat)');
66594 assert.equal(moment.utc('2012-01', 'gggg-ww').format(), '2011-12-31T00:00:00Z', '2012 week 1 (1st Jan Sun)');
66595 moment.defineLocale('dow:6,doy:12', null);
66596 });
66597
66598 test('parsing ISO with Z', function (assert) {
66599 var i, mom, formats = [
66600 ['2011-10-08T18:04', '2011-10-08T18:04:00.000'],
66601 ['2011-10-08T18:04:20', '2011-10-08T18:04:20.000'],
66602 ['2011-10-08T18:04:20.1', '2011-10-08T18:04:20.100'],
66603 ['2011-10-08T18:04:20.11', '2011-10-08T18:04:20.110'],
66604 ['2011-10-08T18:04:20.111', '2011-10-08T18:04:20.111'],
66605 ['2011-W40-6T18', '2011-10-08T18:00:00.000'],
66606 ['2011-W40-6T18:04', '2011-10-08T18:04:00.000'],
66607 ['2011-W40-6T18:04:20', '2011-10-08T18:04:20.000'],
66608 ['2011-W40-6T18:04:20.1', '2011-10-08T18:04:20.100'],
66609 ['2011-W40-6T18:04:20.11', '2011-10-08T18:04:20.110'],
66610 ['2011-W40-6T18:04:20.111', '2011-10-08T18:04:20.111'],
66611 ['2011-281T18', '2011-10-08T18:00:00.000'],
66612 ['2011-281T18:04', '2011-10-08T18:04:00.000'],
66613 ['2011-281T18:04:20', '2011-10-08T18:04:20.000'],
66614 ['2011-281T18:04:20', '2011-10-08T18:04:20.000'],
66615 ['2011-281T18:04:20.1', '2011-10-08T18:04:20.100'],
66616 ['2011-281T18:04:20.11', '2011-10-08T18:04:20.110'],
66617 ['2011-281T18:04:20.111', '2011-10-08T18:04:20.111']
66618 ];
66619
66620 for (i = 0; i < formats.length; i++) {
66621 mom = moment(formats[i][0] + 'Z').utc();
66622 assert.equal(mom.format('YYYY-MM-DDTHH:mm:ss.SSS'), formats[i][1], 'moment should be able to parse ISO in UTC ' + formats[i][0] + 'Z');
66623
66624 mom = moment(formats[i][0] + ' Z').utc();
66625 assert.equal(mom.format('YYYY-MM-DDTHH:mm:ss.SSS'), formats[i][1], 'moment should be able to parse ISO in UTC ' + formats[i][0] + ' Z');
73f3c911
IC
66626 }
66627 });
b135bf1a 66628
db71a655
KM
66629 test('parsing iso with T', function (assert) {
66630 assert.equal(moment('2011-10-08T18')._f, 'YYYY-MM-DDTHH', 'should include \'T\' in the format');
66631 assert.equal(moment('2011-10-08T18:20')._f, 'YYYY-MM-DDTHH:mm', 'should include \'T\' in the format');
66632 assert.equal(moment('2011-10-08T18:20:13')._f, 'YYYY-MM-DDTHH:mm:ss', 'should include \'T\' in the format');
66633 assert.equal(moment('2011-10-08T18:20:13.321')._f, 'YYYY-MM-DDTHH:mm:ss.SSSS', 'should include \'T\' in the format');
66634
66635 assert.equal(moment('2011-10-08 18')._f, 'YYYY-MM-DD HH', 'should not include \'T\' in the format');
66636 assert.equal(moment('2011-10-08 18:20')._f, 'YYYY-MM-DD HH:mm', 'should not include \'T\' in the format');
66637 assert.equal(moment('2011-10-08 18:20:13')._f, 'YYYY-MM-DD HH:mm:ss', 'should not include \'T\' in the format');
66638 assert.equal(moment('2011-10-08 18:20:13.321')._f, 'YYYY-MM-DD HH:mm:ss.SSSS', 'should not include \'T\' in the format');
73f3c911 66639 });
b135bf1a 66640
db71a655
KM
66641 test('parsing iso Z timezone', function (assert) {
66642 var i,
66643 formats = [
66644 ['2011-10-08T18:04Z', '2011-10-08T18:04:00.000+00:00'],
66645 ['2011-10-08T18:04:20Z', '2011-10-08T18:04:20.000+00:00'],
66646 ['2011-10-08T18:04:20.111Z', '2011-10-08T18:04:20.111+00:00']
66647 ];
66648 for (i = 0; i < formats.length; i++) {
66649 assert.equal(moment.utc(formats[i][0]).format('YYYY-MM-DDTHH:mm:ss.SSSZ'), formats[i][1], 'moment should be able to parse ISO ' + formats[i][0]);
73f3c911
IC
66650 }
66651 });
b135bf1a 66652
db71a655
KM
66653 test('parsing iso Z timezone into local', function (assert) {
66654 var m = moment('2011-10-08T18:04:20.111Z');
66655
66656 assert.equal(m.utc().format('YYYY-MM-DDTHH:mm:ss.SSS'), '2011-10-08T18:04:20.111', 'moment should be able to parse ISO 2011-10-08T18:04:20.111Z');
73f3c911 66657 });
d6651c21 66658
db71a655
KM
66659 test('parsing iso with more subsecond precision digits', function (assert) {
66660 assert.equal(moment.utc('2013-07-31T22:00:00.0000000Z').format(), '2013-07-31T22:00:00Z', 'more than 3 subsecond digits');
66661 });
d6651c21 66662
db71a655
KM
66663 test('null or empty', function (assert) {
66664 assert.equal(moment('').isValid(), false, 'moment(\'\') is not valid');
66665 assert.equal(moment(null).isValid(), false, 'moment(null) is not valid');
66666 assert.equal(moment(null, 'YYYY-MM-DD').isValid(), false, 'moment(\'\', \'format\') is not valid');
66667 assert.equal(moment('', 'YYYY-MM-DD').isValid(), false, 'moment(\'\', \'format\') is not valid');
66668 assert.equal(moment.utc('').isValid(), false, 'moment.utc(\'\') is not valid');
66669 assert.equal(moment.utc(null).isValid(), false, 'moment.utc(null) is not valid');
66670 assert.equal(moment.utc(null, 'YYYY-MM-DD').isValid(), false, 'moment.utc(null) is not valid');
66671 assert.equal(moment.utc('', 'YYYY-MM-DD').isValid(), false, 'moment.utc(\'\', \'YYYY-MM-DD\') is not valid');
66672 });
d6651c21 66673
db71a655
KM
66674 test('first century', function (assert) {
66675 assert.equal(moment([0, 0, 1]).format('YYYY-MM-DD'), '0000-01-01', 'Year AD 0');
66676 assert.equal(moment([99, 0, 1]).format('YYYY-MM-DD'), '0099-01-01', 'Year AD 99');
66677 assert.equal(moment([999, 0, 1]).format('YYYY-MM-DD'), '0999-01-01', 'Year AD 999');
66678 assert.equal(moment('0 1 1', 'YYYY MM DD').format('YYYY-MM-DD'), '0000-01-01', 'Year AD 0');
66679 assert.equal(moment('999 1 1', 'YYYY MM DD').format('YYYY-MM-DD'), '0999-01-01', 'Year AD 999');
66680 assert.equal(moment('0 1 1', 'YYYYY MM DD').format('YYYYY-MM-DD'), '00000-01-01', 'Year AD 0');
66681 assert.equal(moment('99 1 1', 'YYYYY MM DD').format('YYYYY-MM-DD'), '00099-01-01', 'Year AD 99');
66682 assert.equal(moment('999 1 1', 'YYYYY MM DD').format('YYYYY-MM-DD'), '00999-01-01', 'Year AD 999');
66683 });
d6651c21 66684
db71a655
KM
66685 test('six digit years', function (assert) {
66686 assert.equal(moment([-270000, 0, 1]).format('YYYYY-MM-DD'), '-270000-01-01', 'format BC 270,001');
66687 assert.equal(moment([270000, 0, 1]).format('YYYYY-MM-DD'), '270000-01-01', 'format AD 270,000');
66688 assert.equal(moment('-270000-01-01', 'YYYYY-MM-DD').toDate().getFullYear(), -270000, 'parse BC 270,001');
66689 assert.equal(moment('270000-01-01', 'YYYYY-MM-DD').toDate().getFullYear(), 270000, 'parse AD 270,000');
66690 assert.equal(moment('+270000-01-01', 'YYYYY-MM-DD').toDate().getFullYear(), 270000, 'parse AD +270,000');
66691 assert.equal(moment.utc('-270000-01-01', 'YYYYY-MM-DD').toDate().getUTCFullYear(), -270000, 'parse utc BC 270,001');
66692 assert.equal(moment.utc('270000-01-01', 'YYYYY-MM-DD').toDate().getUTCFullYear(), 270000, 'parse utc AD 270,000');
66693 assert.equal(moment.utc('+270000-01-01', 'YYYYY-MM-DD').toDate().getUTCFullYear(), 270000, 'parse utc AD +270,000');
73f3c911
IC
66694 });
66695
db71a655
KM
66696 test('negative four digit years', function (assert) {
66697 assert.equal(moment('-1000-01-01', 'YYYYY-MM-DD').toDate().getFullYear(), -1000, 'parse BC 1,001');
66698 assert.equal(moment.utc('-1000-01-01', 'YYYYY-MM-DD').toDate().getUTCFullYear(), -1000, 'parse utc BC 1,001');
66699 });
d6651c21 66700
db71a655
KM
66701 test('strict parsing', function (assert) {
66702 assert.equal(moment('2014-', 'YYYY-Q', true).isValid(), false, 'fail missing quarter');
b135bf1a 66703
db71a655
KM
66704 assert.equal(moment('2012-05', 'YYYY-MM', true).format('YYYY-MM'), '2012-05', 'parse correct string');
66705 assert.equal(moment(' 2012-05', 'YYYY-MM', true).isValid(), false, 'fail on extra whitespace');
66706 assert.equal(moment('foo 2012-05', '[foo] YYYY-MM', true).format('YYYY-MM'), '2012-05', 'handle fixed text');
66707 assert.equal(moment('2012 05', 'YYYY-MM', true).isValid(), false, 'fail on different separator');
66708 assert.equal(moment('2012 05', 'YYYY MM DD', true).isValid(), false, 'fail on too many tokens');
1d986a17 66709
db71a655
KM
66710 assert.equal(moment('05 30 2010', ['DD MM YYYY', 'MM DD YYYY'], true).format('MM DD YYYY'), '05 30 2010', 'array with bad date');
66711 assert.equal(moment('05 30 2010', ['', 'MM DD YYYY'], true).format('MM DD YYYY'), '05 30 2010', 'array with invalid format');
66712 assert.equal(moment('05 30 2010', [' DD MM YYYY', 'MM DD YYYY'], true).format('MM DD YYYY'), '05 30 2010', 'array with non-matching format');
c74a101d 66713
db71a655
KM
66714 assert.equal(moment('2010.*...', 'YYYY.*', true).isValid(), false, 'invalid format with regex chars');
66715 assert.equal(moment('2010.*', 'YYYY.*', true).year(), 2010, 'valid format with regex chars');
66716 assert.equal(moment('.*2010.*', '.*YYYY.*', true).year(), 2010, 'valid format with regex chars on both sides');
1d986a17 66717
db71a655
KM
66718 //strict tokens
66719 assert.equal(moment('-5-05-25', 'YYYY-MM-DD', true).isValid(), false, 'invalid negative year');
66720 assert.equal(moment('2-05-25', 'YYYY-MM-DD', true).isValid(), false, 'invalid one-digit year');
66721 assert.equal(moment('20-05-25', 'YYYY-MM-DD', true).isValid(), false, 'invalid two-digit year');
66722 assert.equal(moment('201-05-25', 'YYYY-MM-DD', true).isValid(), false, 'invalid three-digit year');
66723 assert.equal(moment('2010-05-25', 'YYYY-MM-DD', true).isValid(), true, 'valid four-digit year');
66724 assert.equal(moment('22010-05-25', 'YYYY-MM-DD', true).isValid(), false, 'invalid five-digit year');
516f5f67 66725
db71a655
KM
66726 assert.equal(moment('12-05-25', 'YY-MM-DD', true).isValid(), true, 'valid two-digit year');
66727 assert.equal(moment('2012-05-25', 'YY-MM-DD', true).isValid(), false, 'invalid four-digit year');
516f5f67 66728
db71a655
KM
66729 assert.equal(moment('-5-05-25', 'Y-MM-DD', true).isValid(), true, 'valid negative year');
66730 assert.equal(moment('2-05-25', 'Y-MM-DD', true).isValid(), true, 'valid one-digit year');
66731 assert.equal(moment('20-05-25', 'Y-MM-DD', true).isValid(), true, 'valid two-digit year');
66732 assert.equal(moment('201-05-25', 'Y-MM-DD', true).isValid(), true, 'valid three-digit year');
516f5f67 66733
db71a655
KM
66734 assert.equal(moment('2012-5-25', 'YYYY-M-DD', true).isValid(), true, 'valid one-digit month');
66735 assert.equal(moment('2012-5-25', 'YYYY-MM-DD', true).isValid(), false, 'invalid one-digit month');
66736 assert.equal(moment('2012-05-25', 'YYYY-M-DD', true).isValid(), true, 'valid one-digit month');
66737 assert.equal(moment('2012-05-25', 'YYYY-MM-DD', true).isValid(), true, 'valid one-digit month');
516f5f67 66738
db71a655
KM
66739 assert.equal(moment('2012-05-2', 'YYYY-MM-D', true).isValid(), true, 'valid one-digit day');
66740 assert.equal(moment('2012-05-2', 'YYYY-MM-DD', true).isValid(), false, 'invalid one-digit day');
66741 assert.equal(moment('2012-05-02', 'YYYY-MM-D', true).isValid(), true, 'valid two-digit day');
66742 assert.equal(moment('2012-05-02', 'YYYY-MM-DD', true).isValid(), true, 'valid two-digit day');
73f3c911 66743
db71a655
KM
66744 assert.equal(moment('+002012-05-25', 'YYYYY-MM-DD', true).isValid(), true, 'valid six-digit year');
66745 assert.equal(moment('+2012-05-25', 'YYYYY-MM-DD', true).isValid(), false, 'invalid four-digit year');
516f5f67 66746
db71a655
KM
66747 //thse are kinda pointless, but they should work as expected
66748 assert.equal(moment('1', 'S', true).isValid(), true, 'valid one-digit milisecond');
66749 assert.equal(moment('12', 'S', true).isValid(), false, 'invalid two-digit milisecond');
66750 assert.equal(moment('123', 'S', true).isValid(), false, 'invalid three-digit milisecond');
66751
66752 assert.equal(moment('1', 'SS', true).isValid(), false, 'invalid one-digit milisecond');
66753 assert.equal(moment('12', 'SS', true).isValid(), true, 'valid two-digit milisecond');
66754 assert.equal(moment('123', 'SS', true).isValid(), false, 'invalid three-digit milisecond');
66755
66756 assert.equal(moment('1', 'SSS', true).isValid(), false, 'invalid one-digit milisecond');
66757 assert.equal(moment('12', 'SSS', true).isValid(), false, 'invalid two-digit milisecond');
66758 assert.equal(moment('123', 'SSS', true).isValid(), true, 'valid three-digit milisecond');
66759
66760 // strict parsing respects month length
66761 assert.ok(moment('1 January 2000', 'D MMMM YYYY', true).isValid(), 'capital long-month + MMMM');
66762 assert.ok(!moment('1 January 2000', 'D MMM YYYY', true).isValid(), 'capital long-month + MMM');
66763 assert.ok(!moment('1 Jan 2000', 'D MMMM YYYY', true).isValid(), 'capital short-month + MMMM');
66764 assert.ok(moment('1 Jan 2000', 'D MMM YYYY', true).isValid(), 'capital short-month + MMM');
66765 assert.ok(moment('1 january 2000', 'D MMMM YYYY', true).isValid(), 'lower long-month + MMMM');
66766 assert.ok(!moment('1 january 2000', 'D MMM YYYY', true).isValid(), 'lower long-month + MMM');
66767 assert.ok(!moment('1 jan 2000', 'D MMMM YYYY', true).isValid(), 'lower short-month + MMMM');
66768 assert.ok(moment('1 jan 2000', 'D MMM YYYY', true).isValid(), 'lower short-month + MMM');
66769 });
66770
66771 test('parsing into a locale', function (assert) {
66772 moment.defineLocale('parselocale', {
66773 months : 'one_two_three_four_five_six_seven_eight_nine_ten_eleven_twelve'.split('_'),
66774 monthsShort : 'one_two_three_four_five_six_seven_eight_nine_ten_eleven_twelve'.split('_')
66775 });
516f5f67 66776
db71a655 66777 moment.locale('en');
516f5f67 66778
db71a655 66779 assert.equal(moment('2012 seven', 'YYYY MMM', 'parselocale').month(), 6, 'should be able to parse in a specific locale');
b135bf1a 66780
db71a655
KM
66781 moment.locale('parselocale');
66782
66783 assert.equal(moment('2012 july', 'YYYY MMM', 'en').month(), 6, 'should be able to parse in a specific locale');
66784
66785 moment.defineLocale('parselocale', null);
66786 });
66787
66788 function getVerifier(test$$1) {
66789 return function (input, format, expected, description, asymetrical) {
66790 var m = moment(input, format);
66791 test$$1.equal(m.format('YYYY MM DD'), expected, 'compare: ' + description);
66792
66793 //test round trip
66794 if (!asymetrical) {
66795 test$$1.equal(m.format(format), input, 'round trip: ' + description);
b135bf1a 66796 }
db71a655 66797 };
b135bf1a
IC
66798 }
66799
db71a655
KM
66800 test('parsing week and weekday information', function (assert) {
66801 var ver = getVerifier(assert);
66802 var currentWeekOfYear = moment().weeks();
66803 var expectedDate2012 = moment([2012, 0, 1])
66804 .day(0)
66805 .add((currentWeekOfYear - 1), 'weeks')
66806 .format('YYYY MM DD');
66807 var expectedDate1999 = moment([1999, 0, 1])
66808 .day(0)
66809 .add((currentWeekOfYear - 1), 'weeks')
66810 .format('YYYY MM DD');
66811
66812 // year
66813 ver('12', 'gg', expectedDate2012, 'week-year two digits');
66814 ver('2012', 'gggg', expectedDate2012, 'week-year four digits');
66815 ver('99', 'gg', expectedDate1999, 'week-year two digits previous year');
66816 ver('1999', 'gggg', expectedDate1999, 'week-year four digits previous year');
66817
66818 ver('99', 'GG', '1999 01 04', 'iso week-year two digits');
66819 ver('1999', 'GGGG', '1999 01 04', 'iso week-year four digits');
66820
66821 ver('13', 'GG', '2012 12 31', 'iso week-year two digits previous year');
66822 ver('2013', 'GGGG', '2012 12 31', 'iso week-year four digits previous year');
66823
66824 // year + week
66825 ver('1999 37', 'gggg w', '1999 09 05', 'week');
66826 ver('1999 37', 'gggg ww', '1999 09 05', 'week double');
66827 ver('1999 37', 'GGGG W', '1999 09 13', 'iso week');
66828 ver('1999 37', 'GGGG WW', '1999 09 13', 'iso week double');
66829
66830 ver('1999 37 4', 'GGGG WW E', '1999 09 16', 'iso day');
66831 ver('1999 37 04', 'GGGG WW E', '1999 09 16', 'iso day wide', true);
66832
66833 ver('1999 37 4', 'gggg ww e', '1999 09 09', 'day');
66834 ver('1999 37 04', 'gggg ww e', '1999 09 09', 'day wide', true);
66835
66836 // year + week + day
66837 ver('1999 37 4', 'gggg ww d', '1999 09 09', 'd');
66838 ver('1999 37 Th', 'gggg ww dd', '1999 09 09', 'dd');
66839 ver('1999 37 Thu', 'gggg ww ddd', '1999 09 09', 'ddd');
66840 ver('1999 37 Thursday', 'gggg ww dddd', '1999 09 09', 'dddd');
66841
66842 // lower-order only
66843 assert.equal(moment('22', 'ww').week(), 22, 'week sets the week by itself');
66844 assert.equal(moment('22', 'ww').weekYear(), moment().weekYear(), 'week keeps this year');
66845 assert.equal(moment('2012 22', 'YYYY ww').weekYear(), 2012, 'week keeps parsed year');
66846
66847 assert.equal(moment('22', 'WW').isoWeek(), 22, 'iso week sets the week by itself');
66848 assert.equal(moment('2012 22', 'YYYY WW').weekYear(), 2012, 'iso week keeps parsed year');
66849 assert.equal(moment('22', 'WW').isoWeekYear(), moment().isoWeekYear(), 'iso week keeps this year');
66850
66851 // order
66852 ver('6 2013 2', 'e gggg w', '2013 01 12', 'order doesn\'t matter');
66853 ver('6 2013 2', 'E GGGG W', '2013 01 12', 'iso order doesn\'t matter');
66854
66855 //can parse other stuff too
66856 assert.equal(moment('1999-W37-4 3:30', 'GGGG-[W]WW-E HH:mm').format('YYYY MM DD HH:mm'), '1999 09 16 03:30', 'parsing weeks and hours');
66857
66858 // In safari, all years before 1300 are shifted back with one day.
66859 // http://stackoverflow.com/questions/20768975/safari-subtracts-1-day-from-dates-before-1300
66860 if (new Date('1300-01-01').getUTCFullYear() === 1300) {
66861 // Years less than 100
66862 ver('0098-06', 'GGGG-WW', '0098 02 03', 'small years work', true);
66863 }
66864 });
66865
66866 test('parsing localized weekdays', function (assert) {
66867 var ver = getVerifier(assert);
66868 try {
66869 moment.locale('dow:1,doy:4', {
66870 weekdays : 'dimanche_lundi_mardi_mercredi_jeudi_vendredi_samedi'.split('_'),
66871 weekdaysShort : 'dim._lun._mar._mer._jeu._ven._sam.'.split('_'),
66872 weekdaysMin : 'Di_Lu_Ma_Me_Je_Ve_Sa'.split('_'),
66873 week: {dow: 1, doy: 4}
66874 });
66875 ver('1999 37 4', 'GGGG WW E', '1999 09 16', 'iso ignores locale');
66876 ver('1999 37 7', 'GGGG WW E', '1999 09 19', 'iso ignores locale');
b135bf1a 66877
db71a655
KM
66878 ver('1999 37 0', 'gggg ww e', '1999 09 13', 'localized e uses local doy and dow: 0 = monday');
66879 ver('1999 37 4', 'gggg ww e', '1999 09 17', 'localized e uses local doy and dow: 4 = friday');
b135bf1a 66880
db71a655
KM
66881 ver('1999 37 1', 'gggg ww d', '1999 09 13', 'localized d uses 0-indexed days: 1 = monday');
66882 ver('1999 37 Lu', 'gggg ww dd', '1999 09 13', 'localized d uses 0-indexed days: Mo');
66883 ver('1999 37 lun.', 'gggg ww ddd', '1999 09 13', 'localized d uses 0-indexed days: Mon');
66884 ver('1999 37 lundi', 'gggg ww dddd', '1999 09 13', 'localized d uses 0-indexed days: Monday');
66885 ver('1999 37 4', 'gggg ww d', '1999 09 16', 'localized d uses 0-indexed days: 4');
66886
66887 //sunday goes at the end of the week
66888 ver('1999 37 0', 'gggg ww d', '1999 09 19', 'localized d uses 0-indexed days: 0 = sund');
66889 ver('1999 37 Di', 'gggg ww dd', '1999 09 19', 'localized d uses 0-indexed days: 0 = sund');
66890 }
66891 finally {
66892 moment.defineLocale('dow:1,doy:4', null);
66893 moment.locale('en');
73f3c911
IC
66894 }
66895 });
b135bf1a 66896
db71a655
KM
66897 test('parsing with customized two-digit year', function (assert) {
66898 var original = moment.parseTwoDigitYear;
66899 try {
66900 assert.equal(moment('68', 'YY').year(), 2068);
66901 assert.equal(moment('69', 'YY').year(), 1969);
66902 moment.parseTwoDigitYear = function (input) {
66903 return +input + (+input > 30 ? 1900 : 2000);
66904 };
66905 assert.equal(moment('68', 'YY').year(), 1968);
66906 assert.equal(moment('67', 'YY').year(), 1967);
66907 assert.equal(moment('31', 'YY').year(), 1931);
66908 assert.equal(moment('30', 'YY').year(), 2030);
66909 }
66910 finally {
66911 moment.parseTwoDigitYear = original;
73f3c911
IC
66912 }
66913 });
b135bf1a 66914
db71a655
KM
66915 test('array with strings', function (assert) {
66916 assert.equal(moment(['2014', '7', '31']).isValid(), true, 'string array + isValid');
73f3c911 66917 });
d6651c21 66918
db71a655
KM
66919 test('object with strings', function (assert) {
66920 assert.equal(moment({year: '2014', month: '7', day: '31'}).isValid(), true, 'string object + isValid');
66921 });
d6651c21 66922
db71a655
KM
66923 test('utc with array of formats', function (assert) {
66924 assert.equal(moment.utc('2014-01-01', ['YYYY-MM-DD', 'YYYY-MM']).format(), '2014-01-01T00:00:00Z', 'moment.utc works with array of formats');
66925 });
d6651c21 66926
db71a655
KM
66927 test('parsing invalid string weekdays', function (assert) {
66928 assert.equal(false, moment('a', 'dd').isValid(),
66929 'dd with invalid weekday, non-strict');
66930 assert.equal(false, moment('a', 'dd', true).isValid(),
66931 'dd with invalid weekday, strict');
66932 assert.equal(false, moment('a', 'ddd').isValid(),
66933 'ddd with invalid weekday, non-strict');
66934 assert.equal(false, moment('a', 'ddd', true).isValid(),
66935 'ddd with invalid weekday, strict');
66936 assert.equal(false, moment('a', 'dddd').isValid(),
66937 'dddd with invalid weekday, non-strict');
66938 assert.equal(false, moment('a', 'dddd', true).isValid(),
66939 'dddd with invalid weekday, strict');
73f3c911
IC
66940 });
66941
db71a655
KM
66942 test('milliseconds', function (assert) {
66943 assert.equal(moment('1', 'S').millisecond(), 100);
66944 assert.equal(moment('12', 'SS').millisecond(), 120);
66945 assert.equal(moment('123', 'SSS').millisecond(), 123);
66946 assert.equal(moment('1234', 'SSSS').millisecond(), 123);
66947 assert.equal(moment('12345', 'SSSSS').millisecond(), 123);
66948 assert.equal(moment('123456', 'SSSSSS').millisecond(), 123);
66949 assert.equal(moment('1234567', 'SSSSSSS').millisecond(), 123);
66950 assert.equal(moment('12345678', 'SSSSSSSS').millisecond(), 123);
66951 assert.equal(moment('123456789', 'SSSSSSSSS').millisecond(), 123);
66952 });
d6651c21 66953
db71a655
KM
66954 test('hmm', function (assert) {
66955 assert.equal(moment('123', 'hmm', true).format('HH:mm:ss'), '01:23:00', '123 with hmm');
66956 assert.equal(moment('123a', 'hmmA', true).format('HH:mm:ss'), '01:23:00', '123a with hmmA');
66957 assert.equal(moment('123p', 'hmmA', true).format('HH:mm:ss'), '13:23:00', '123p with hmmA');
b135bf1a 66958
db71a655
KM
66959 assert.equal(moment('1234', 'hmm', true).format('HH:mm:ss'), '12:34:00', '1234 with hmm');
66960 assert.equal(moment('1234a', 'hmmA', true).format('HH:mm:ss'), '00:34:00', '1234a with hmmA');
66961 assert.equal(moment('1234p', 'hmmA', true).format('HH:mm:ss'), '12:34:00', '1234p with hmmA');
516f5f67 66962
db71a655
KM
66963 assert.equal(moment('12345', 'hmmss', true).format('HH:mm:ss'), '01:23:45', '12345 with hmmss');
66964 assert.equal(moment('12345a', 'hmmssA', true).format('HH:mm:ss'), '01:23:45', '12345a with hmmssA');
66965 assert.equal(moment('12345p', 'hmmssA', true).format('HH:mm:ss'), '13:23:45', '12345p with hmmssA');
66966 assert.equal(moment('112345', 'hmmss', true).format('HH:mm:ss'), '11:23:45', '112345 with hmmss');
66967 assert.equal(moment('112345a', 'hmmssA', true).format('HH:mm:ss'), '11:23:45', '112345a with hmmssA');
66968 assert.equal(moment('112345p', 'hmmssA', true).format('HH:mm:ss'), '23:23:45', '112345p with hmmssA');
c74a101d 66969
db71a655
KM
66970 assert.equal(moment('023', 'Hmm', true).format('HH:mm:ss'), '00:23:00', '023 with Hmm');
66971 assert.equal(moment('123', 'Hmm', true).format('HH:mm:ss'), '01:23:00', '123 with Hmm');
66972 assert.equal(moment('1234', 'Hmm', true).format('HH:mm:ss'), '12:34:00', '1234 with Hmm');
66973 assert.equal(moment('1534', 'Hmm', true).format('HH:mm:ss'), '15:34:00', '1234 with Hmm');
66974 assert.equal(moment('12345', 'Hmmss', true).format('HH:mm:ss'), '01:23:45', '12345 with Hmmss');
66975 assert.equal(moment('112345', 'Hmmss', true).format('HH:mm:ss'), '11:23:45', '112345 with Hmmss');
66976 assert.equal(moment('172345', 'Hmmss', true).format('HH:mm:ss'), '17:23:45', '112345 with Hmmss');
66977 });
516f5f67 66978
db71a655
KM
66979 test('Y token', function (assert) {
66980 assert.equal(moment('1-1-2010', 'M-D-Y', true).year(), 2010, 'parsing Y');
66981 });
516f5f67 66982
db71a655
KM
66983 test('parsing flags retain parsed date parts', function (assert) {
66984 var a = moment('10 p', 'hh:mm a');
66985 assert.equal(a.parsingFlags().parsedDateParts[3], 10, 'parsed 10 as the hour');
66986 assert.equal(a.parsingFlags().parsedDateParts[0], undefined, 'year was not parsed');
66987 assert.equal(a.parsingFlags().meridiem, 'p', 'meridiem flag was added');
66988 var b = moment('10:30', ['MMDDYY', 'HH:mm']);
66989 assert.equal(b.parsingFlags().parsedDateParts[3], 10, 'multiple format parshing matched hour');
66990 assert.equal(b.parsingFlags().parsedDateParts[0], undefined, 'array is properly copied, no residual data from first token parse');
66991 });
516f5f67 66992
db71a655
KM
66993 test('parsing only meridiem results in invalid date', function (assert) {
66994 assert.ok(!moment('alkj', 'hh:mm a').isValid(), 'because an a token is used, a meridiem will be parsed but nothing else was so invalid');
66995 assert.ok(moment('02:30 p more extra stuff', 'hh:mm a').isValid(), 'because other tokens were parsed, date is valid');
66996 assert.ok(moment('1/1/2016 extra data', ['a', 'M/D/YYYY']).isValid(), 'took second format, does not pick up on meridiem parsed from first format (good copy)');
66997 });
516f5f67 66998
db71a655
KM
66999 test('invalid dates return invalid for methods that access the _d prop', function (assert) {
67000 var momentAsDate = moment(['2015', '12', '1']).toDate();
67001 assert.ok(momentAsDate instanceof Date, 'toDate returns a Date object');
67002 assert.ok(isNaN(momentAsDate.getTime()), 'toDate returns an invalid Date invalid');
67003 });
516f5f67 67004
db71a655
KM
67005 test('k, kk', function (assert) {
67006 for (var i = -1; i <= 24; i++) {
67007 var kVal = i + ':15:59';
67008 var kkVal = (i < 10 ? '0' : '') + i + ':15:59';
67009 if (i !== 24) {
67010 assert.ok(moment(kVal, 'k:mm:ss').isSame(moment(kVal, 'H:mm:ss')), kVal + ' k parsing');
67011 assert.ok(moment(kkVal, 'kk:mm:ss').isSame(moment(kkVal, 'HH:mm:ss')), kkVal + ' kk parsing');
67012 } else {
67013 assert.equal(moment(kVal, 'k:mm:ss').format('k:mm:ss'), kVal, kVal + ' k parsing');
67014 assert.equal(moment(kkVal, 'kk:mm:ss').format('kk:mm:ss'), kkVal, kkVal + ' skk parsing');
73f3c911 67015 }
db71a655
KM
67016 }
67017 });
73f3c911
IC
67018
67019})));
67020
516f5f67 67021
c74a101d
IC
67022;(function (global, factory) {
67023 typeof exports === 'object' && typeof module !== 'undefined'
67024 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
67025 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
67026 factory(global.moment)
73f3c911 67027}(this, (function (moment) { 'use strict';
516f5f67 67028
db71a655
KM
67029 function each(array, callback) {
67030 var i;
67031 for (i = 0; i < array.length; i++) {
67032 callback(array[i], i, array);
b135bf1a
IC
67033 }
67034 }
b135bf1a 67035
db71a655
KM
67036 function setupDeprecationHandler(test, moment$$1, scope) {
67037 test._expectedDeprecations = null;
67038 test._observedDeprecations = null;
67039 test._oldSupress = moment$$1.suppressDeprecationWarnings;
67040 moment$$1.suppressDeprecationWarnings = true;
67041 test.expectedDeprecations = function () {
67042 test._expectedDeprecations = arguments;
67043 test._observedDeprecations = [];
67044 };
67045 moment$$1.deprecationHandler = function (name, msg) {
67046 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
67047 if (deprecationId === -1) {
67048 throw new Error('Unexpected deprecation thrown name=' +
67049 name + ' msg=' + msg);
67050 }
67051 test._observedDeprecations[deprecationId] = 1;
67052 };
67053 }
b135bf1a 67054
db71a655
KM
67055 function teardownDeprecationHandler(test, moment$$1, scope) {
67056 moment$$1.suppressDeprecationWarnings = test._oldSupress;
b135bf1a 67057
db71a655
KM
67058 if (test._expectedDeprecations != null) {
67059 var missedDeprecations = [];
67060 each(test._expectedDeprecations, function (deprecationPattern, id) {
67061 if (test._observedDeprecations[id] !== 1) {
67062 missedDeprecations.push(deprecationPattern);
67063 }
b135bf1a 67064 });
db71a655
KM
67065 if (missedDeprecations.length !== 0) {
67066 throw new Error('Expected deprecation warnings did not happen: ' +
67067 missedDeprecations.join(' '));
67068 }
73f3c911 67069 }
db71a655 67070 }
d6651c21 67071
db71a655
KM
67072 function matchedDeprecation(name, msg, deprecations) {
67073 if (deprecations == null) {
67074 return -1;
73f3c911 67075 }
db71a655
KM
67076 for (var i = 0; i < deprecations.length; ++i) {
67077 if (name != null && name === deprecations[i]) {
67078 return i;
67079 }
67080 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
67081 return i;
67082 }
d6651c21 67083 }
db71a655
KM
67084 return -1;
67085 }
73f3c911 67086
db71a655 67087 /*global QUnit:false*/
b135bf1a 67088
db71a655 67089 var test = QUnit.test;
516f5f67 67090
c58511b9
KM
67091 function module$1 (name, lifecycle) {
67092 QUnit.module(name, {
67093 beforeEach : function () {
67094 moment.locale('en');
67095 moment.createFromInputFallback = function (config) {
67096 throw new Error('input not handled by moment: ' + config._i);
67097 };
67098 setupDeprecationHandler(test, moment, 'core');
67099 if (lifecycle && lifecycle.setup) {
67100 lifecycle.setup();
67101 }
67102 },
67103 afterEach : function () {
67104 teardownDeprecationHandler(test, moment, 'core');
67105 if (lifecycle && lifecycle.teardown) {
67106 lifecycle.teardown();
67107 }
67108 }
67109 });
67110 }
67111
67112 module$1('creation data');
67113
67114 test('valid date', function (assert) {
67115 var dat = moment('1992-10-22');
67116 var orig = dat.creationData();
67117
67118 assert.equal(dat.isValid(), true, '1992-10-22 is valid');
67119 assert.equal(orig.input, '1992-10-22', 'original input is not correct.');
67120 assert.equal(orig.format, 'YYYY-MM-DD', 'original format is defined.');
67121 assert.equal(orig.locale._abbr, 'en', 'default locale is en');
67122 assert.equal(orig.isUTC, false, 'not a UTC date');
67123 });
67124
67125 test('valid date at fr locale', function (assert) {
67126 var dat = moment('1992-10-22', 'YYYY-MM-DD', 'fr');
67127 var orig = dat.creationData();
67128
67129 assert.equal(orig.locale._abbr, 'fr', 'locale is fr');
67130 });
67131
67132 test('valid date with formats', function (assert) {
67133 var dat = moment('29-06-1995', ['MM-DD-YYYY', 'DD-MM', 'DD-MM-YYYY']);
67134 var orig = dat.creationData();
67135
67136 assert.equal(orig.format, 'DD-MM-YYYY', 'DD-MM-YYYY format is defined.');
67137 });
67138
67139 test('strict', function (assert) {
67140 assert.ok(moment('2015-01-02', 'YYYY-MM-DD', true).creationData().strict, 'strict is true');
67141 assert.ok(!moment('2015-01-02', 'YYYY-MM-DD').creationData().strict, 'strict is true');
67142 });
67143
67144})));
67145
67146
67147;(function (global, factory) {
67148 typeof exports === 'object' && typeof module !== 'undefined'
67149 && typeof require === 'function' ? factory(require('../../moment')) :
67150 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
67151 factory(global.moment)
67152}(this, (function (moment) { 'use strict';
67153
67154 function each(array, callback) {
67155 var i;
67156 for (i = 0; i < array.length; i++) {
67157 callback(array[i], i, array);
67158 }
67159 }
67160
67161 function setupDeprecationHandler(test, moment$$1, scope) {
67162 test._expectedDeprecations = null;
67163 test._observedDeprecations = null;
67164 test._oldSupress = moment$$1.suppressDeprecationWarnings;
67165 moment$$1.suppressDeprecationWarnings = true;
67166 test.expectedDeprecations = function () {
67167 test._expectedDeprecations = arguments;
67168 test._observedDeprecations = [];
67169 };
67170 moment$$1.deprecationHandler = function (name, msg) {
67171 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
67172 if (deprecationId === -1) {
67173 throw new Error('Unexpected deprecation thrown name=' +
67174 name + ' msg=' + msg);
67175 }
67176 test._observedDeprecations[deprecationId] = 1;
67177 };
67178 }
67179
67180 function teardownDeprecationHandler(test, moment$$1, scope) {
67181 moment$$1.suppressDeprecationWarnings = test._oldSupress;
67182
67183 if (test._expectedDeprecations != null) {
67184 var missedDeprecations = [];
67185 each(test._expectedDeprecations, function (deprecationPattern, id) {
67186 if (test._observedDeprecations[id] !== 1) {
67187 missedDeprecations.push(deprecationPattern);
67188 }
67189 });
67190 if (missedDeprecations.length !== 0) {
67191 throw new Error('Expected deprecation warnings did not happen: ' +
67192 missedDeprecations.join(' '));
67193 }
67194 }
67195 }
67196
67197 function matchedDeprecation(name, msg, deprecations) {
67198 if (deprecations == null) {
67199 return -1;
67200 }
67201 for (var i = 0; i < deprecations.length; ++i) {
67202 if (name != null && name === deprecations[i]) {
67203 return i;
67204 }
67205 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
67206 return i;
67207 }
67208 }
67209 return -1;
67210 }
67211
67212 /*global QUnit:false*/
67213
67214 var test = QUnit.test;
c74a101d 67215
db71a655
KM
67216 function module$1 (name, lifecycle) {
67217 QUnit.module(name, {
c58511b9 67218 beforeEach : function () {
db71a655
KM
67219 moment.locale('en');
67220 moment.createFromInputFallback = function (config) {
67221 throw new Error('input not handled by moment: ' + config._i);
67222 };
67223 setupDeprecationHandler(test, moment, 'core');
67224 if (lifecycle && lifecycle.setup) {
67225 lifecycle.setup();
67226 }
67227 },
c58511b9 67228 afterEach : function () {
db71a655
KM
67229 teardownDeprecationHandler(test, moment, 'core');
67230 if (lifecycle && lifecycle.teardown) {
67231 lifecycle.teardown();
67232 }
516f5f67
IC
67233 }
67234 });
67235 }
67236
db71a655
KM
67237 function hasOwnProp(a, b) {
67238 return Object.prototype.hasOwnProperty.call(a, b);
73f3c911 67239 }
db71a655
KM
67240
67241 function addUnitAlias (unit, shorthand) {
67242 var lowerCase = unit.toLowerCase();
73f3c911 67243 }
516f5f67 67244
db71a655
KM
67245 var hookCallback;
67246
67247 function hooks () {
67248 return hookCallback.apply(null, arguments);
67249 }
516f5f67 67250
db71a655
KM
67251 function isFunction(input) {
67252 return input instanceof Function || Object.prototype.toString.call(input) === '[object Function]';
67253 }
516f5f67 67254
db71a655
KM
67255 function zeroFill(number, targetLength, forceSign) {
67256 var absNumber = '' + Math.abs(number),
67257 zerosToFill = targetLength - absNumber.length,
67258 sign = number >= 0;
67259 return (sign ? (forceSign ? '+' : '') : '-') +
67260 Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1) + absNumber;
67261 }
516f5f67 67262
db71a655
KM
67263 var formatTokenFunctions = {};
67264
67265 // token: 'M'
67266 // padded: ['MM', 2]
67267 // ordinal: 'Mo'
67268 // callback: function () { this.month() + 1 }
67269 function addFormatToken (token, padded, ordinal, callback) {
67270 var func = callback;
67271 if (typeof callback === 'string') {
67272 func = function () {
67273 return this[callback]();
73f3c911 67274 };
db71a655
KM
67275 }
67276 if (token) {
67277 formatTokenFunctions[token] = func;
67278 }
67279 if (padded) {
67280 formatTokenFunctions[padded[0]] = function () {
67281 return zeroFill(func.apply(this, arguments), padded[1], padded[2]);
67282 };
67283 }
67284 if (ordinal) {
67285 formatTokenFunctions[ordinal] = function () {
67286 return this.localeData().ordinal(func.apply(this, arguments), token);
67287 };
67288 }
67289 }
73f3c911 67290
db71a655
KM
67291 var match2 = /\d\d/; // 00 - 99
67292 var match4 = /\d{4}/; // 0000 - 9999
67293 var match6 = /[+-]?\d{6}/; // -999999 - 999999
67294 var match1to2 = /\d\d?/; // 0 - 99
67295 var match3to4 = /\d\d\d\d?/; // 999 - 9999
67296 var match5to6 = /\d\d\d\d\d\d?/; // 99999 - 999999
67297 var match1to4 = /\d{1,4}/; // 0 - 9999
67298 var match1to6 = /[+-]?\d{1,6}/; // -999999 - 999999
67299 var matchSigned = /[+-]?\d+/; // -inf - inf
516f5f67 67300
db71a655 67301 var regexes = {};
516f5f67 67302
db71a655
KM
67303 function addRegexToken (token, regex, strictRegex) {
67304 regexes[token] = isFunction(regex) ? regex : function (isStrict, localeData) {
67305 return (isStrict && strictRegex) ? strictRegex : regex;
67306 };
67307 }
516f5f67 67308
db71a655
KM
67309 function isNumber(input) {
67310 return typeof input === 'number' || Object.prototype.toString.call(input) === '[object Number]';
b135bf1a
IC
67311 }
67312
db71a655
KM
67313 function absFloor (number) {
67314 if (number < 0) {
67315 // -0 -> 0
67316 return Math.ceil(number) || 0;
67317 } else {
67318 return Math.floor(number);
b135bf1a 67319 }
b135bf1a
IC
67320 }
67321
db71a655
KM
67322 function toInt(argumentForCoercion) {
67323 var coercedNumber = +argumentForCoercion,
67324 value = 0;
b135bf1a 67325
db71a655
KM
67326 if (coercedNumber !== 0 && isFinite(coercedNumber)) {
67327 value = absFloor(coercedNumber);
73f3c911 67328 }
b135bf1a 67329
db71a655
KM
67330 return value;
67331 }
67332
67333 var tokens = {};
67334
67335 function addParseToken (token, callback) {
67336 var i, func = callback;
67337 if (typeof token === 'string') {
67338 token = [token];
73f3c911 67339 }
db71a655
KM
67340 if (isNumber(callback)) {
67341 func = function (input, array) {
67342 array[callback] = toInt(input);
67343 };
67344 }
67345 for (i = 0; i < token.length; i++) {
67346 tokens[token[i]] = func;
67347 }
67348 }
b135bf1a 67349
db71a655
KM
67350 function addWeekParseToken (token, callback) {
67351 addParseToken(token, function (input, array, config, token) {
67352 config._w = config._w || {};
67353 callback(input, config._w, config, token);
b135bf1a 67354 });
db71a655
KM
67355 }
67356
67357 var YEAR = 0;
67358 var MONTH = 1;
67359 var HOUR = 3;
67360 var MINUTE = 4;
67361 var SECOND = 5;
67362
67363 // FORMATTING
67364
67365 addFormatToken('Y', 0, 0, function () {
67366 var y = this.year();
67367 return y <= 9999 ? '' + y : '+' + y;
73f3c911 67368 });
d6651c21 67369
db71a655
KM
67370 addFormatToken(0, ['YY', 2], 0, function () {
67371 return this.year() % 100;
67372 });
c587bf00 67373
db71a655
KM
67374 addFormatToken(0, ['YYYY', 4], 0, 'year');
67375 addFormatToken(0, ['YYYYY', 5], 0, 'year');
67376 addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');
c587bf00 67377
db71a655 67378 // ALIASES
c587bf00 67379
db71a655
KM
67380 addUnitAlias('year', 'y');
67381
67382 // PARSING
67383
67384 addRegexToken('Y', matchSigned);
67385 addRegexToken('YY', match1to2, match2);
67386 addRegexToken('YYYY', match1to4, match4);
67387 addRegexToken('YYYYY', match1to6, match6);
67388 addRegexToken('YYYYYY', match1to6, match6);
67389
67390 addParseToken(['YYYYY', 'YYYYYY'], YEAR);
67391 addParseToken('YYYY', function (input, array) {
67392 array[YEAR] = input.length === 2 ? hooks.parseTwoDigitYear(input) : toInt(input);
67393 });
67394 addParseToken('YY', function (input, array) {
67395 array[YEAR] = hooks.parseTwoDigitYear(input);
67396 });
67397 addParseToken('Y', function (input, array) {
67398 array[YEAR] = parseInt(input, 10);
c587bf00
IC
67399 });
67400
db71a655
KM
67401 function isLeapYear(year) {
67402 return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
67403 }
c587bf00 67404
db71a655 67405 // HOOKS
c587bf00 67406
db71a655
KM
67407 hooks.parseTwoDigitYear = function (input) {
67408 return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
73f3c911 67409 };
c587bf00 67410
db71a655
KM
67411 function mod(n, x) {
67412 return ((n % x) + x) % x;
67413 }
73f3c911 67414
db71a655
KM
67415 function extend(a, b) {
67416 for (var i in b) {
67417 if (hasOwnProp(b, i)) {
67418 a[i] = b[i];
c587bf00 67419 }
c587bf00 67420 }
db71a655
KM
67421
67422 if (hasOwnProp(b, 'toString')) {
67423 a.toString = b.toString;
67424 }
67425
67426 if (hasOwnProp(b, 'valueOf')) {
67427 a.valueOf = b.valueOf;
67428 }
67429
67430 return a;
c587bf00
IC
67431 }
67432
db71a655
KM
67433 function defaultParsingFlags() {
67434 // We need to deep clone this object.
67435 return {
67436 empty : false,
67437 unusedTokens : [],
67438 unusedInput : [],
67439 overflow : -2,
67440 charsLeftOver : 0,
67441 nullInput : false,
67442 invalidMonth : null,
67443 invalidFormat : false,
67444 userInvalidated : false,
67445 iso : false,
67446 parsedDateParts : [],
67447 meridiem : null,
67448 rfc2822 : false,
67449 weekdayMismatch : false
67450 };
73f3c911 67451 }
db71a655
KM
67452
67453 function getParsingFlags(m) {
67454 if (m._pf == null) {
67455 m._pf = defaultParsingFlags();
c587bf00 67456 }
db71a655 67457 return m._pf;
c587bf00
IC
67458 }
67459
db71a655
KM
67460 // Plugins that add properties should also add the key here (null value),
67461 // so we can properly clone ourselves.
67462 var momentProperties = hooks.momentProperties = [];
c587bf00 67463
db71a655
KM
67464 function warn(msg) {
67465 if (hooks.suppressDeprecationWarnings === false &&
67466 (typeof console !== 'undefined') && console.warn) {
67467 console.warn('Deprecation warning: ' + msg);
67468 }
67469 }
c587bf00 67470
db71a655
KM
67471 function deprecate(msg, fn) {
67472 var firstTime = true;
c587bf00 67473
db71a655
KM
67474 return extend(function () {
67475 if (hooks.deprecationHandler != null) {
67476 hooks.deprecationHandler(null, msg);
c587bf00 67477 }
db71a655
KM
67478 if (firstTime) {
67479 var args = [];
67480 var arg;
67481 for (var i = 0; i < arguments.length; i++) {
67482 arg = '';
67483 if (typeof arguments[i] === 'object') {
67484 arg += '\n[' + i + '] ';
67485 for (var key in arguments[0]) {
67486 arg += key + ': ' + arguments[0][key] + ', ';
67487 }
67488 arg = arg.slice(0, -2); // Remove trailing comma and space
67489 } else {
67490 arg = arguments[i];
67491 }
67492 args.push(arg);
67493 }
67494 warn(msg + '\nArguments: ' + Array.prototype.slice.call(args).join('') + '\n' + (new Error()).stack);
67495 firstTime = false;
67496 }
67497 return fn.apply(this, arguments);
67498 }, fn);
67499 }
73f3c911 67500
db71a655
KM
67501 hooks.suppressDeprecationWarnings = false;
67502 hooks.deprecationHandler = null;
c587bf00 67503
db71a655 67504 // FORMATTING
d6651c21 67505
db71a655
KM
67506 addFormatToken('w', ['ww', 2], 'wo', 'week');
67507 addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek');
d6651c21 67508
db71a655 67509 // ALIASES
d6651c21 67510
db71a655
KM
67511 addUnitAlias('week', 'w');
67512 addUnitAlias('isoWeek', 'W');
d6651c21 67513
db71a655 67514 // PARSING
b135bf1a 67515
db71a655
KM
67516 addRegexToken('w', match1to2);
67517 addRegexToken('ww', match1to2, match2);
67518 addRegexToken('W', match1to2);
67519 addRegexToken('WW', match1to2, match2);
67520
67521 addWeekParseToken(['w', 'ww', 'W', 'WW'], function (input, week, config, token) {
67522 week[token.substr(0, 1)] = toInt(input);
73f3c911 67523 });
516f5f67 67524
db71a655
KM
67525 // FORMATTING
67526
67527 addFormatToken('d', 0, 'do', 'day');
67528
67529 addFormatToken('dd', 0, 0, function (format) {
67530 return this.localeData().weekdaysMin(this, format);
73f3c911 67531 });
c74a101d 67532
db71a655
KM
67533 addFormatToken('ddd', 0, 0, function (format) {
67534 return this.localeData().weekdaysShort(this, format);
73f3c911 67535 });
516f5f67 67536
db71a655
KM
67537 addFormatToken('dddd', 0, 0, function (format) {
67538 return this.localeData().weekdays(this, format);
516f5f67 67539 });
73f3c911 67540
db71a655
KM
67541 addFormatToken('e', 0, 0, 'weekday');
67542 addFormatToken('E', 0, 0, 'isoWeekday');
c587bf00 67543
db71a655 67544 // ALIASES
516f5f67 67545
db71a655
KM
67546 addUnitAlias('day', 'd');
67547 addUnitAlias('weekday', 'e');
67548 addUnitAlias('isoWeekday', 'E');
67549
67550 // PARSING
67551
67552 addRegexToken('d', match1to2);
67553 addRegexToken('e', match1to2);
67554 addRegexToken('E', match1to2);
67555 addRegexToken('dd', function (isStrict, locale) {
67556 return locale.weekdaysMinRegex(isStrict);
67557 });
67558 addRegexToken('ddd', function (isStrict, locale) {
67559 return locale.weekdaysShortRegex(isStrict);
67560 });
67561 addRegexToken('dddd', function (isStrict, locale) {
67562 return locale.weekdaysRegex(isStrict);
67563 });
516f5f67 67564
db71a655
KM
67565 addWeekParseToken(['dd', 'ddd', 'dddd'], function (input, week, config, token) {
67566 var weekday = config._locale.weekdaysParse(input, token, config._strict);
67567 // if we didn't get a weekday name, mark the date as invalid
67568 if (weekday != null) {
67569 week.d = weekday;
67570 } else {
67571 getParsingFlags(config).invalidWeekday = input;
516f5f67
IC
67572 }
67573 });
67574
db71a655
KM
67575 addWeekParseToken(['d', 'e', 'E'], function (input, week, config, token) {
67576 week[token] = toInt(input);
67577 });
516f5f67 67578
db71a655 67579 // FORMATTING
516f5f67 67580
db71a655
KM
67581 function hFormat() {
67582 return this.hours() % 12 || 12;
67583 }
b135bf1a 67584
db71a655
KM
67585 function kFormat() {
67586 return this.hours() || 24;
67587 }
73f3c911 67588
db71a655
KM
67589 addFormatToken('H', ['HH', 2], 0, 'hour');
67590 addFormatToken('h', ['hh', 2], 0, hFormat);
67591 addFormatToken('k', ['kk', 2], 0, kFormat);
67592
67593 addFormatToken('hmm', 0, 0, function () {
67594 return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2);
67595 });
67596
67597 addFormatToken('hmmss', 0, 0, function () {
67598 return '' + hFormat.apply(this) + zeroFill(this.minutes(), 2) +
67599 zeroFill(this.seconds(), 2);
67600 });
67601
67602 addFormatToken('Hmm', 0, 0, function () {
67603 return '' + this.hours() + zeroFill(this.minutes(), 2);
67604 });
67605
67606 addFormatToken('Hmmss', 0, 0, function () {
67607 return '' + this.hours() + zeroFill(this.minutes(), 2) +
67608 zeroFill(this.seconds(), 2);
67609 });
67610
67611 function meridiem (token, lowercase) {
67612 addFormatToken(token, 0, 0, function () {
67613 return this.localeData().meridiem(this.hours(), this.minutes(), lowercase);
73f3c911 67614 });
b135bf1a
IC
67615 }
67616
db71a655
KM
67617 meridiem('a', true);
67618 meridiem('A', false);
67619
67620 // ALIASES
67621
67622 addUnitAlias('hour', 'h');
67623
67624 // PARSING
67625
67626 function matchMeridiem (isStrict, locale) {
67627 return locale._meridiemParse;
73f3c911 67628 }
db71a655
KM
67629
67630 addRegexToken('a', matchMeridiem);
67631 addRegexToken('A', matchMeridiem);
67632 addRegexToken('H', match1to2);
67633 addRegexToken('h', match1to2);
67634 addRegexToken('k', match1to2);
67635 addRegexToken('HH', match1to2, match2);
67636 addRegexToken('hh', match1to2, match2);
67637 addRegexToken('kk', match1to2, match2);
67638
67639 addRegexToken('hmm', match3to4);
67640 addRegexToken('hmmss', match5to6);
67641 addRegexToken('Hmm', match3to4);
67642 addRegexToken('Hmmss', match5to6);
67643
67644 addParseToken(['H', 'HH'], HOUR);
67645 addParseToken(['k', 'kk'], function (input, array, config) {
67646 var kInput = toInt(input);
67647 array[HOUR] = kInput === 24 ? 0 : kInput;
67648 });
67649 addParseToken(['a', 'A'], function (input, array, config) {
67650 config._isPm = config._locale.isPM(input);
67651 config._meridiem = input;
67652 });
67653 addParseToken(['h', 'hh'], function (input, array, config) {
67654 array[HOUR] = toInt(input);
67655 getParsingFlags(config).bigHour = true;
67656 });
67657 addParseToken('hmm', function (input, array, config) {
67658 var pos = input.length - 2;
67659 array[HOUR] = toInt(input.substr(0, pos));
67660 array[MINUTE] = toInt(input.substr(pos));
67661 getParsingFlags(config).bigHour = true;
67662 });
67663 addParseToken('hmmss', function (input, array, config) {
67664 var pos1 = input.length - 4;
67665 var pos2 = input.length - 2;
67666 array[HOUR] = toInt(input.substr(0, pos1));
67667 array[MINUTE] = toInt(input.substr(pos1, 2));
67668 array[SECOND] = toInt(input.substr(pos2));
67669 getParsingFlags(config).bigHour = true;
67670 });
67671 addParseToken('Hmm', function (input, array, config) {
67672 var pos = input.length - 2;
67673 array[HOUR] = toInt(input.substr(0, pos));
67674 array[MINUTE] = toInt(input.substr(pos));
67675 });
67676 addParseToken('Hmmss', function (input, array, config) {
67677 var pos1 = input.length - 4;
67678 var pos2 = input.length - 2;
67679 array[HOUR] = toInt(input.substr(0, pos1));
67680 array[MINUTE] = toInt(input.substr(pos1, 2));
67681 array[SECOND] = toInt(input.substr(pos2));
67682 });
67683
c58511b9
KM
67684 // Pick the first defined of two or three arguments.
67685
db71a655
KM
67686 hooks.createFromInputFallback = deprecate(
67687 'value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), ' +
67688 'which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are ' +
67689 'discouraged and will be removed in an upcoming major release. Please refer to ' +
67690 'http://momentjs.com/guides/#/warnings/js-date/ for more info.',
67691 function (config) {
67692 config._d = new Date(config._i + (config._useUTC ? ' UTC' : ''));
b135bf1a 67693 }
db71a655
KM
67694 );
67695
67696 // constant that refers to the ISO standard
67697 hooks.ISO_8601 = function () {};
67698
67699 // constant that refers to the RFC 2822 form
67700 hooks.RFC_2822 = function () {};
67701
67702 function daysInMonth(year, month) {
67703 if (isNaN(year) || isNaN(month)) {
67704 return NaN;
b135bf1a 67705 }
db71a655
KM
67706 var modMonth = mod(month, 12);
67707 year += (month - modMonth) / 12;
67708 return modMonth === 1 ? (isLeapYear(year) ? 29 : 28) : (31 - modMonth % 7 % 2);
b135bf1a
IC
67709 }
67710
db71a655 67711 // FORMATTING
b135bf1a 67712
db71a655
KM
67713 addFormatToken('M', ['MM', 2], 'Mo', function () {
67714 return this.month() + 1;
67715 });
b135bf1a 67716
db71a655
KM
67717 addFormatToken('MMM', 0, 0, function (format) {
67718 return this.localeData().monthsShort(this, format);
67719 });
b135bf1a 67720
db71a655
KM
67721 addFormatToken('MMMM', 0, 0, function (format) {
67722 return this.localeData().months(this, format);
67723 });
73f3c911 67724
db71a655 67725 // ALIASES
d6651c21 67726
db71a655 67727 addUnitAlias('month', 'M');
d6651c21 67728
db71a655 67729 // PARSING
d6651c21 67730
db71a655
KM
67731 addRegexToken('M', match1to2);
67732 addRegexToken('MM', match1to2, match2);
67733 addRegexToken('MMM', function (isStrict, locale) {
67734 return locale.monthsShortRegex(isStrict);
67735 });
67736 addRegexToken('MMMM', function (isStrict, locale) {
67737 return locale.monthsRegex(isStrict);
67738 });
d6651c21 67739
db71a655
KM
67740 addParseToken(['M', 'MM'], function (input, array) {
67741 array[MONTH] = toInt(input) - 1;
67742 });
67743
67744 addParseToken(['MMM', 'MMMM'], function (input, array, config, token) {
67745 var month = config._locale.monthsParse(input, token, config._strict);
67746 // if we didn't find a month name, mark the date as invalid.
67747 if (month != null) {
67748 array[MONTH] = month;
67749 } else {
67750 getParsingFlags(config).invalidMonth = input;
d6651c21 67751 }
db71a655 67752 });
d6651c21 67753
db71a655 67754 module$1('days in month');
d6651c21 67755
db71a655
KM
67756 test('days in month', function (assert) {
67757 each([31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], function (days, i) {
67758 var firstDay = moment([2012, i]),
67759 lastDay = moment([2012, i, days]);
67760 assert.equal(firstDay.daysInMonth(), days, firstDay.format('L') + ' should have ' + days + ' days.');
67761 assert.equal(lastDay.daysInMonth(), days, lastDay.format('L') + ' should have ' + days + ' days.');
67762 });
73f3c911 67763 });
d6651c21 67764
db71a655
KM
67765 test('days in month leap years', function (assert) {
67766 assert.equal(moment([2010, 1]).daysInMonth(), 28, 'Feb 2010 should have 28 days');
67767 assert.equal(moment([2100, 1]).daysInMonth(), 28, 'Feb 2100 should have 28 days');
67768 assert.equal(moment([2008, 1]).daysInMonth(), 29, 'Feb 2008 should have 29 days');
67769 assert.equal(moment([2000, 1]).daysInMonth(), 29, 'Feb 2000 should have 29 days');
73f3c911 67770 });
d6651c21 67771
db71a655
KM
67772 test('days in month with NaN inputs', function (assert) {
67773 assert.ok(isNaN(daysInMonth(2, NaN)), 'month NaN inputs should return NaN');
67774 assert.ok(isNaN(daysInMonth(NaN, 0)), 'year NaN inputs should return NaN');
67775 assert.ok(!moment([2010, null, null]).isValid(), 'Invalid date because month is NaN');
73f3c911 67776 });
d6651c21 67777
db71a655
KM
67778 test('days in month with overflow', function (assert) {
67779 assert.equal(daysInMonth(14, 22), daysInMonth(15, 10), 'positive overflow by 1');
67780 assert.equal(daysInMonth(14, 122), daysInMonth(24, 2), 'positive overflow by 10');
67781 assert.equal(daysInMonth(8, -2), daysInMonth(7, 10), 'negative overflow by 1');
67782 assert.equal(daysInMonth(-2380, -25), daysInMonth(-2383, 11), 'negative overflow by 3');
d6651c21
IC
67783 });
67784
db71a655
KM
67785 test('days in month consistent with Date()', function (assert) {
67786 var oldMethod = function (year, month) {
67787 return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
67788 };
67789 assert.equal(daysInMonth(14, 22), oldMethod(14, 22), 'positive overflow by 1');
67790 assert.equal(daysInMonth(14, 122), oldMethod(14, 122), 'positive overflow by 10');
67791 assert.equal(daysInMonth(8, -2), oldMethod(8, -2), 'negative overflow by 1');
67792 assert.equal(daysInMonth(-2380, -25), oldMethod(-2380, -25), 'negative overflow by 3');
67793 });
d6651c21 67794
db71a655 67795})));
d6651c21 67796
d6651c21 67797
db71a655
KM
67798;(function (global, factory) {
67799 typeof exports === 'object' && typeof module !== 'undefined'
67800 && typeof require === 'function' ? factory(require('../../moment')) :
67801 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
67802 factory(global.moment)
67803}(this, (function (moment) { 'use strict';
67804
67805 function each(array, callback) {
67806 var i;
67807 for (i = 0; i < array.length; i++) {
67808 callback(array[i], i, array);
73f3c911 67809 }
db71a655 67810 }
d6651c21 67811
db71a655
KM
67812 function setupDeprecationHandler(test, moment$$1, scope) {
67813 test._expectedDeprecations = null;
67814 test._observedDeprecations = null;
67815 test._oldSupress = moment$$1.suppressDeprecationWarnings;
67816 moment$$1.suppressDeprecationWarnings = true;
67817 test.expectedDeprecations = function () {
67818 test._expectedDeprecations = arguments;
67819 test._observedDeprecations = [];
67820 };
67821 moment$$1.deprecationHandler = function (name, msg) {
67822 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
67823 if (deprecationId === -1) {
67824 throw new Error('Unexpected deprecation thrown name=' +
67825 name + ' msg=' + msg);
67826 }
67827 test._observedDeprecations[deprecationId] = 1;
67828 };
67829 }
73f3c911 67830
db71a655
KM
67831 function teardownDeprecationHandler(test, moment$$1, scope) {
67832 moment$$1.suppressDeprecationWarnings = test._oldSupress;
73f3c911 67833
db71a655
KM
67834 if (test._expectedDeprecations != null) {
67835 var missedDeprecations = [];
67836 each(test._expectedDeprecations, function (deprecationPattern, id) {
67837 if (test._observedDeprecations[id] !== 1) {
67838 missedDeprecations.push(deprecationPattern);
67839 }
67840 });
67841 if (missedDeprecations.length !== 0) {
67842 throw new Error('Expected deprecation warnings did not happen: ' +
67843 missedDeprecations.join(' '));
d6651c21 67844 }
d6651c21
IC
67845 }
67846 }
67847
db71a655
KM
67848 function matchedDeprecation(name, msg, deprecations) {
67849 if (deprecations == null) {
67850 return -1;
d6651c21 67851 }
db71a655
KM
67852 for (var i = 0; i < deprecations.length; ++i) {
67853 if (name != null && name === deprecations[i]) {
67854 return i;
67855 }
67856 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
67857 return i;
67858 }
d6651c21 67859 }
db71a655 67860 return -1;
d6651c21
IC
67861 }
67862
db71a655 67863 /*global QUnit:false*/
d6651c21 67864
db71a655 67865 var test = QUnit.test;
d6651c21 67866
db71a655
KM
67867 function module$1 (name, lifecycle) {
67868 QUnit.module(name, {
c58511b9 67869 beforeEach : function () {
db71a655
KM
67870 moment.locale('en');
67871 moment.createFromInputFallback = function (config) {
67872 throw new Error('input not handled by moment: ' + config._i);
67873 };
67874 setupDeprecationHandler(test, moment, 'core');
67875 if (lifecycle && lifecycle.setup) {
67876 lifecycle.setup();
67877 }
67878 },
c58511b9 67879 afterEach : function () {
db71a655
KM
67880 teardownDeprecationHandler(test, moment, 'core');
67881 if (lifecycle && lifecycle.teardown) {
67882 lifecycle.teardown();
67883 }
d6651c21 67884 }
db71a655
KM
67885 });
67886 }
67887
67888 module$1('days in year');
67889
67890 // https://github.com/moment/moment/issues/3717
67891 test('YYYYDDD should not parse DDD=000', function (assert) {
67892 assert.equal(moment(7000000, moment.ISO_8601, true).isValid(), false);
67893 assert.equal(moment('7000000', moment.ISO_8601, true).isValid(), false);
67894 assert.equal(moment(7000000, moment.ISO_8601, false).isValid(), false);
67895 });
73f3c911
IC
67896
67897})));
d6651c21 67898
d6651c21 67899
73f3c911
IC
67900;(function (global, factory) {
67901 typeof exports === 'object' && typeof module !== 'undefined'
67902 && typeof require === 'function' ? factory(require('../../moment')) :
67903 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
67904 factory(global.moment)
67905}(this, (function (moment) { 'use strict';
d6651c21 67906
db71a655
KM
67907 function each(array, callback) {
67908 var i;
67909 for (i = 0; i < array.length; i++) {
67910 callback(array[i], i, array);
67911 }
d6651c21
IC
67912 }
67913
db71a655
KM
67914 function setupDeprecationHandler(test, moment$$1, scope) {
67915 test._expectedDeprecations = null;
67916 test._observedDeprecations = null;
67917 test._oldSupress = moment$$1.suppressDeprecationWarnings;
67918 moment$$1.suppressDeprecationWarnings = true;
67919 test.expectedDeprecations = function () {
67920 test._expectedDeprecations = arguments;
67921 test._observedDeprecations = [];
67922 };
67923 moment$$1.deprecationHandler = function (name, msg) {
67924 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
67925 if (deprecationId === -1) {
67926 throw new Error('Unexpected deprecation thrown name=' +
67927 name + ' msg=' + msg);
d6651c21 67928 }
db71a655
KM
67929 test._observedDeprecations[deprecationId] = 1;
67930 };
b135bf1a
IC
67931 }
67932
db71a655
KM
67933 function teardownDeprecationHandler(test, moment$$1, scope) {
67934 moment$$1.suppressDeprecationWarnings = test._oldSupress;
516f5f67 67935
db71a655
KM
67936 if (test._expectedDeprecations != null) {
67937 var missedDeprecations = [];
67938 each(test._expectedDeprecations, function (deprecationPattern, id) {
67939 if (test._observedDeprecations[id] !== 1) {
67940 missedDeprecations.push(deprecationPattern);
67941 }
67942 });
67943 if (missedDeprecations.length !== 0) {
67944 throw new Error('Expected deprecation warnings did not happen: ' +
67945 missedDeprecations.join(' '));
67946 }
516f5f67 67947 }
db71a655 67948 }
516f5f67 67949
db71a655
KM
67950 function matchedDeprecation(name, msg, deprecations) {
67951 if (deprecations == null) {
67952 return -1;
516f5f67 67953 }
db71a655
KM
67954 for (var i = 0; i < deprecations.length; ++i) {
67955 if (name != null && name === deprecations[i]) {
67956 return i;
67957 }
67958 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
67959 return i;
67960 }
516f5f67 67961 }
db71a655
KM
67962 return -1;
67963 }
516f5f67 67964
db71a655
KM
67965 /*global QUnit:false*/
67966
67967 var test = QUnit.test;
67968
db71a655
KM
67969 function module$1 (name, lifecycle) {
67970 QUnit.module(name, {
c58511b9 67971 beforeEach : function () {
db71a655
KM
67972 moment.locale('en');
67973 moment.createFromInputFallback = function (config) {
67974 throw new Error('input not handled by moment: ' + config._i);
67975 };
67976 setupDeprecationHandler(test, moment, 'core');
67977 if (lifecycle && lifecycle.setup) {
67978 lifecycle.setup();
67979 }
67980 },
c58511b9 67981 afterEach : function () {
db71a655
KM
67982 teardownDeprecationHandler(test, moment, 'core');
67983 if (lifecycle && lifecycle.teardown) {
67984 lifecycle.teardown();
67985 }
67986 }
73f3c911 67987 });
db71a655 67988 }
516f5f67 67989
db71a655
KM
67990 function hasOwnProp(a, b) {
67991 return Object.prototype.hasOwnProperty.call(a, b);
67992 }
516f5f67 67993
db71a655
KM
67994 function extend(a, b) {
67995 for (var i in b) {
67996 if (hasOwnProp(b, i)) {
67997 a[i] = b[i];
67998 }
73f3c911 67999 }
516f5f67 68000
db71a655
KM
68001 if (hasOwnProp(b, 'toString')) {
68002 a.toString = b.toString;
73f3c911 68003 }
516f5f67 68004
db71a655
KM
68005 if (hasOwnProp(b, 'valueOf')) {
68006 a.valueOf = b.valueOf;
73f3c911 68007 }
c587bf00 68008
db71a655
KM
68009 return a;
68010 }
c587bf00 68011
db71a655 68012 var hookCallback;
c587bf00 68013
db71a655
KM
68014 function hooks () {
68015 return hookCallback.apply(null, arguments);
68016 }
68017
68018 function warn(msg) {
68019 if (hooks.suppressDeprecationWarnings === false &&
68020 (typeof console !== 'undefined') && console.warn) {
68021 console.warn('Deprecation warning: ' + msg);
73f3c911 68022 }
db71a655 68023 }
516f5f67 68024
db71a655
KM
68025 function deprecate(msg, fn) {
68026 var firstTime = true;
516f5f67 68027
db71a655
KM
68028 return extend(function () {
68029 if (hooks.deprecationHandler != null) {
68030 hooks.deprecationHandler(null, msg);
c587bf00 68031 }
db71a655
KM
68032 if (firstTime) {
68033 var args = [];
68034 var arg;
68035 for (var i = 0; i < arguments.length; i++) {
68036 arg = '';
68037 if (typeof arguments[i] === 'object') {
68038 arg += '\n[' + i + '] ';
68039 for (var key in arguments[0]) {
68040 arg += key + ': ' + arguments[0][key] + ', ';
68041 }
68042 arg = arg.slice(0, -2); // Remove trailing comma and space
68043 } else {
68044 arg = arguments[i];
68045 }
68046 args.push(arg);
68047 }
68048 warn(msg + '\nArguments: ' + Array.prototype.slice.call(args).join('') + '\n' + (new Error()).stack);
68049 firstTime = false;
68050 }
68051 return fn.apply(this, arguments);
68052 }, fn);
68053 }
68054
68055 hooks.suppressDeprecationWarnings = false;
68056 hooks.deprecationHandler = null;
68057
68058 module$1('deprecate');
68059
68060 test('deprecate', function (assert) {
68061 // NOTE: hooks inside deprecate.js and moment are different, so this is can
68062 // not be test.expectedDeprecations(...)
68063 var fn = function () {};
68064 var deprecatedFn = deprecate('testing deprecation', fn);
68065 deprecatedFn();
68066
c58511b9 68067 assert.expect(0);
db71a655
KM
68068 });
68069
68070})));
68071
68072
68073;(function (global, factory) {
68074 typeof exports === 'object' && typeof module !== 'undefined'
68075 && typeof require === 'function' ? factory(require('../../moment')) :
68076 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
68077 factory(global.moment)
68078}(this, (function (moment) { 'use strict';
68079
68080 function each(array, callback) {
68081 var i;
68082 for (i = 0; i < array.length; i++) {
68083 callback(array[i], i, array);
516f5f67 68084 }
73f3c911 68085 }
516f5f67 68086
db71a655
KM
68087 function setupDeprecationHandler(test, moment$$1, scope) {
68088 test._expectedDeprecations = null;
68089 test._observedDeprecations = null;
68090 test._oldSupress = moment$$1.suppressDeprecationWarnings;
68091 moment$$1.suppressDeprecationWarnings = true;
68092 test.expectedDeprecations = function () {
68093 test._expectedDeprecations = arguments;
68094 test._observedDeprecations = [];
68095 };
68096 moment$$1.deprecationHandler = function (name, msg) {
68097 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
68098 if (deprecationId === -1) {
68099 throw new Error('Unexpected deprecation thrown name=' +
68100 name + ' msg=' + msg);
68101 }
68102 test._observedDeprecations[deprecationId] = 1;
68103 };
68104 }
68105
68106 function teardownDeprecationHandler(test, moment$$1, scope) {
68107 moment$$1.suppressDeprecationWarnings = test._oldSupress;
68108
68109 if (test._expectedDeprecations != null) {
68110 var missedDeprecations = [];
68111 each(test._expectedDeprecations, function (deprecationPattern, id) {
68112 if (test._observedDeprecations[id] !== 1) {
68113 missedDeprecations.push(deprecationPattern);
68114 }
68115 });
68116 if (missedDeprecations.length !== 0) {
68117 throw new Error('Expected deprecation warnings did not happen: ' +
68118 missedDeprecations.join(' '));
68119 }
68120 }
73f3c911 68121 }
db71a655
KM
68122
68123 function matchedDeprecation(name, msg, deprecations) {
68124 if (deprecations == null) {
68125 return -1;
73f3c911 68126 }
db71a655
KM
68127 for (var i = 0; i < deprecations.length; ++i) {
68128 if (name != null && name === deprecations[i]) {
68129 return i;
68130 }
68131 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
68132 return i;
68133 }
73f3c911 68134 }
db71a655 68135 return -1;
73f3c911 68136 }
516f5f67 68137
db71a655 68138 /*global QUnit:false*/
516f5f67 68139
db71a655 68140 var test = QUnit.test;
516f5f67 68141
db71a655
KM
68142 function module$1 (name, lifecycle) {
68143 QUnit.module(name, {
c58511b9 68144 beforeEach : function () {
db71a655
KM
68145 moment.locale('en');
68146 moment.createFromInputFallback = function (config) {
68147 throw new Error('input not handled by moment: ' + config._i);
68148 };
68149 setupDeprecationHandler(test, moment, 'core');
68150 if (lifecycle && lifecycle.setup) {
68151 lifecycle.setup();
68152 }
68153 },
c58511b9 68154 afterEach : function () {
db71a655
KM
68155 teardownDeprecationHandler(test, moment, 'core');
68156 if (lifecycle && lifecycle.teardown) {
68157 lifecycle.teardown();
68158 }
73f3c911 68159 }
db71a655
KM
68160 });
68161 }
68162
68163 function equal(assert, a, b, message) {
68164 assert.ok(Math.abs(a - b) < 0.00000001, '(' + a + ' === ' + b + ') ' + message);
68165 }
68166
68167 function dstForYear(year) {
68168 var start = moment([year]),
68169 end = moment([year + 1]),
68170 current = start.clone(),
68171 last;
68172
68173 while (current < end) {
68174 last = current.clone();
68175 current.add(24, 'hour');
68176 if (last.utcOffset() !== current.utcOffset()) {
68177 end = current.clone();
68178 current = last.clone();
68179 break;
68180 }
68181 }
68182
68183 while (current < end) {
68184 last = current.clone();
68185 current.add(1, 'hour');
68186 if (last.utcOffset() !== current.utcOffset()) {
68187 return {
68188 moment : last,
68189 diff : -(current.utcOffset() - last.utcOffset()) / 60
68190 };
68191 }
68192 }
68193 }
68194
68195 module$1('diff');
68196
68197 test('diff', function (assert) {
68198 assert.equal(moment(1000).diff(0), 1000, '1 second - 0 = 1000');
68199 assert.equal(moment(1000).diff(500), 500, '1 second - 0.5 seconds = 500');
68200 assert.equal(moment(0).diff(1000), -1000, '0 - 1 second = -1000');
68201 assert.equal(moment(new Date(1000)).diff(1000), 0, '1 second - 1 second = 0');
68202 var oneHourDate = new Date(2015, 5, 21),
68203 nowDate = new Date(+oneHourDate);
68204 oneHourDate.setHours(oneHourDate.getHours() + 1);
68205 assert.equal(moment(oneHourDate).diff(nowDate), 60 * 60 * 1000, '1 hour from now = 3600000');
68206 });
68207
68208 test('diff key after', function (assert) {
68209 assert.equal(moment([2010]).diff([2011], 'years'), -1, 'year diff');
68210 assert.equal(moment([2010]).diff([2010, 2], 'months'), -2, 'month diff');
68211 assert.equal(moment([2010]).diff([2010, 0, 7], 'weeks'), 0, 'week diff');
68212 assert.equal(moment([2010]).diff([2010, 0, 8], 'weeks'), -1, 'week diff');
68213 assert.equal(moment([2010]).diff([2010, 0, 21], 'weeks'), -2, 'week diff');
68214 assert.equal(moment([2010]).diff([2010, 0, 22], 'weeks'), -3, 'week diff');
68215 assert.equal(moment([2010]).diff([2010, 0, 4], 'days'), -3, 'day diff');
68216 assert.equal(moment([2010]).diff([2010, 0, 1, 4], 'hours'), -4, 'hour diff');
68217 assert.equal(moment([2010]).diff([2010, 0, 1, 0, 5], 'minutes'), -5, 'minute diff');
68218 assert.equal(moment([2010]).diff([2010, 0, 1, 0, 0, 6], 'seconds'), -6, 'second diff');
68219 });
68220
68221 test('diff key before', function (assert) {
68222 assert.equal(moment([2011]).diff([2010], 'years'), 1, 'year diff');
68223 assert.equal(moment([2010, 2]).diff([2010], 'months'), 2, 'month diff');
68224 assert.equal(moment([2010, 0, 4]).diff([2010], 'days'), 3, 'day diff');
68225 assert.equal(moment([2010, 0, 7]).diff([2010], 'weeks'), 0, 'week diff');
68226 assert.equal(moment([2010, 0, 8]).diff([2010], 'weeks'), 1, 'week diff');
68227 assert.equal(moment([2010, 0, 21]).diff([2010], 'weeks'), 2, 'week diff');
68228 assert.equal(moment([2010, 0, 22]).diff([2010], 'weeks'), 3, 'week diff');
68229 assert.equal(moment([2010, 0, 1, 4]).diff([2010], 'hours'), 4, 'hour diff');
68230 assert.equal(moment([2010, 0, 1, 0, 5]).diff([2010], 'minutes'), 5, 'minute diff');
68231 assert.equal(moment([2010, 0, 1, 0, 0, 6]).diff([2010], 'seconds'), 6, 'second diff');
68232 });
68233
68234 test('diff key before singular', function (assert) {
68235 assert.equal(moment([2011]).diff([2010], 'year'), 1, 'year diff singular');
68236 assert.equal(moment([2010, 2]).diff([2010], 'month'), 2, 'month diff singular');
68237 assert.equal(moment([2010, 0, 4]).diff([2010], 'day'), 3, 'day diff singular');
68238 assert.equal(moment([2010, 0, 7]).diff([2010], 'week'), 0, 'week diff singular');
68239 assert.equal(moment([2010, 0, 8]).diff([2010], 'week'), 1, 'week diff singular');
68240 assert.equal(moment([2010, 0, 21]).diff([2010], 'week'), 2, 'week diff singular');
68241 assert.equal(moment([2010, 0, 22]).diff([2010], 'week'), 3, 'week diff singular');
68242 assert.equal(moment([2010, 0, 1, 4]).diff([2010], 'hour'), 4, 'hour diff singular');
68243 assert.equal(moment([2010, 0, 1, 0, 5]).diff([2010], 'minute'), 5, 'minute diff singular');
68244 assert.equal(moment([2010, 0, 1, 0, 0, 6]).diff([2010], 'second'), 6, 'second diff singular');
68245 });
68246
68247 test('diff key before abbreviated', function (assert) {
68248 assert.equal(moment([2011]).diff([2010], 'y'), 1, 'year diff abbreviated');
68249 assert.equal(moment([2010, 2]).diff([2010], 'M'), 2, 'month diff abbreviated');
68250 assert.equal(moment([2010, 0, 4]).diff([2010], 'd'), 3, 'day diff abbreviated');
68251 assert.equal(moment([2010, 0, 7]).diff([2010], 'w'), 0, 'week diff abbreviated');
68252 assert.equal(moment([2010, 0, 8]).diff([2010], 'w'), 1, 'week diff abbreviated');
68253 assert.equal(moment([2010, 0, 21]).diff([2010], 'w'), 2, 'week diff abbreviated');
68254 assert.equal(moment([2010, 0, 22]).diff([2010], 'w'), 3, 'week diff abbreviated');
68255 assert.equal(moment([2010, 0, 1, 4]).diff([2010], 'h'), 4, 'hour diff abbreviated');
68256 assert.equal(moment([2010, 0, 1, 0, 5]).diff([2010], 'm'), 5, 'minute diff abbreviated');
68257 assert.equal(moment([2010, 0, 1, 0, 0, 6]).diff([2010], 's'), 6, 'second diff abbreviated');
68258 });
68259
68260 test('diff month', function (assert) {
68261 assert.equal(moment([2011, 0, 31]).diff([2011, 2, 1], 'months'), -1, 'month diff');
68262 });
68263
68264 test('diff across DST', function (assert) {
68265 var dst = dstForYear(2012), a, b, daysInMonth;
68266 if (!dst) {
68267 assert.equal(42, 42, 'at least one assertion');
68268 return;
68269 }
73f3c911 68270
db71a655
KM
68271 a = dst.moment;
68272 b = a.clone().utc().add(12, 'hours').local();
68273 daysInMonth = (a.daysInMonth() + b.daysInMonth()) / 2;
68274 assert.equal(b.diff(a, 'milliseconds', true), 12 * 60 * 60 * 1000,
68275 'ms diff across DST');
68276 assert.equal(b.diff(a, 'seconds', true), 12 * 60 * 60,
68277 'second diff across DST');
68278 assert.equal(b.diff(a, 'minutes', true), 12 * 60,
68279 'minute diff across DST');
68280 assert.equal(b.diff(a, 'hours', true), 12,
68281 'hour diff across DST');
68282 assert.equal(b.diff(a, 'days', true), (12 - dst.diff) / 24,
68283 'day diff across DST');
68284 equal(assert, b.diff(a, 'weeks', true), (12 - dst.diff) / 24 / 7,
68285 'week diff across DST');
68286 assert.ok(0.95 / (2 * 31) < b.diff(a, 'months', true),
68287 'month diff across DST, lower bound');
68288 assert.ok(b.diff(a, 'month', true) < 1.05 / (2 * 28),
68289 'month diff across DST, upper bound');
68290 assert.ok(0.95 / (2 * 31 * 12) < b.diff(a, 'years', true),
68291 'year diff across DST, lower bound');
68292 assert.ok(b.diff(a, 'year', true) < 1.05 / (2 * 28 * 12),
68293 'year diff across DST, upper bound');
68294
68295 a = dst.moment;
68296 b = a.clone().utc().add(12 + dst.diff, 'hours').local();
68297 daysInMonth = (a.daysInMonth() + b.daysInMonth()) / 2;
68298
68299 assert.equal(b.diff(a, 'milliseconds', true),
68300 (12 + dst.diff) * 60 * 60 * 1000,
68301 'ms diff across DST');
68302 assert.equal(b.diff(a, 'seconds', true), (12 + dst.diff) * 60 * 60,
68303 'second diff across DST');
68304 assert.equal(b.diff(a, 'minutes', true), (12 + dst.diff) * 60,
68305 'minute diff across DST');
68306 assert.equal(b.diff(a, 'hours', true), (12 + dst.diff),
68307 'hour diff across DST');
68308 assert.equal(b.diff(a, 'days', true), 12 / 24, 'day diff across DST');
68309 equal(assert, b.diff(a, 'weeks', true), 12 / 24 / 7,
68310 'week diff across DST');
68311 assert.ok(0.95 / (2 * 31) < b.diff(a, 'months', true),
68312 'month diff across DST, lower bound');
68313 assert.ok(b.diff(a, 'month', true) < 1.05 / (2 * 28),
68314 'month diff across DST, upper bound');
68315 assert.ok(0.95 / (2 * 31 * 12) < b.diff(a, 'years', true),
68316 'year diff across DST, lower bound');
68317 assert.ok(b.diff(a, 'year', true) < 1.05 / (2 * 28 * 12),
68318 'year diff across DST, upper bound');
68319 });
68320
68321 test('diff overflow', function (assert) {
68322 assert.equal(moment([2011]).diff([2010], 'months'), 12, 'month diff');
68323 assert.equal(moment([2010, 0, 2]).diff([2010], 'hours'), 24, 'hour diff');
68324 assert.equal(moment([2010, 0, 1, 2]).diff([2010], 'minutes'), 120, 'minute diff');
68325 assert.equal(moment([2010, 0, 1, 0, 4]).diff([2010], 'seconds'), 240, 'second diff');
68326 });
68327
68328 test('diff between utc and local', function (assert) {
68329 if (moment([2012]).utcOffset() === moment([2011]).utcOffset()) {
68330 // Russia's utc offset on 1st of Jan 2012 vs 2011 is different
68331 assert.equal(moment([2012]).utc().diff([2011], 'years'), 1, 'year diff');
68332 }
68333 assert.equal(moment([2010, 2, 2]).utc().diff([2010, 0, 2], 'months'), 2, 'month diff');
68334 assert.equal(moment([2010, 0, 4]).utc().diff([2010], 'days'), 3, 'day diff');
68335 assert.equal(moment([2010, 0, 22]).utc().diff([2010], 'weeks'), 3, 'week diff');
68336 assert.equal(moment([2010, 0, 1, 4]).utc().diff([2010], 'hours'), 4, 'hour diff');
68337 assert.equal(moment([2010, 0, 1, 0, 5]).utc().diff([2010], 'minutes'), 5, 'minute diff');
68338 assert.equal(moment([2010, 0, 1, 0, 0, 6]).utc().diff([2010], 'seconds'), 6, 'second diff');
68339 });
68340
68341 test('diff floored', function (assert) {
68342 assert.equal(moment([2010, 0, 1, 23]).diff([2010], 'day'), 0, '23 hours = 0 days');
68343 assert.equal(moment([2010, 0, 1, 23, 59]).diff([2010], 'day'), 0, '23:59 hours = 0 days');
68344 assert.equal(moment([2010, 0, 1, 24]).diff([2010], 'day'), 1, '24 hours = 1 day');
68345 assert.equal(moment([2010, 0, 2]).diff([2011, 0, 1], 'year'), 0, 'year rounded down');
68346 assert.equal(moment([2011, 0, 1]).diff([2010, 0, 2], 'year'), 0, 'year rounded down');
68347 assert.equal(moment([2010, 0, 2]).diff([2011, 0, 2], 'year'), -1, 'year rounded down');
68348 assert.equal(moment([2011, 0, 2]).diff([2010, 0, 2], 'year'), 1, 'year rounded down');
68349 });
68350
68351 test('year diffs include dates', function (assert) {
68352 assert.ok(moment([2012, 1, 19]).diff(moment([2002, 1, 20]), 'years', true) < 10, 'year diff should include date of month');
68353 });
68354
68355 test('month diffs', function (assert) {
68356 // due to floating point math errors, these tests just need to be accurate within 0.00000001
68357 assert.equal(moment([2012, 0, 1]).diff([2012, 1, 1], 'months', true), -1, 'Jan 1 to Feb 1 should be 1 month');
68358 equal(assert, moment([2012, 0, 1]).diff([2012, 0, 1, 12], 'months', true), -0.5 / 31, 'Jan 1 to Jan 1 noon should be 0.5 / 31 months');
68359 assert.equal(moment([2012, 0, 15]).diff([2012, 1, 15], 'months', true), -1, 'Jan 15 to Feb 15 should be 1 month');
68360 assert.equal(moment([2012, 0, 28]).diff([2012, 1, 28], 'months', true), -1, 'Jan 28 to Feb 28 should be 1 month');
68361 assert.ok(moment([2012, 0, 31]).diff([2012, 1, 29], 'months', true), -1, 'Jan 31 to Feb 29 should be 1 month');
68362 assert.ok(-1 > moment([2012, 0, 31]).diff([2012, 2, 1], 'months', true), 'Jan 31 to Mar 1 should be more than 1 month');
68363 assert.ok(-30 / 28 < moment([2012, 0, 31]).diff([2012, 2, 1], 'months', true), 'Jan 31 to Mar 1 should be less than 1 month and 1 day');
68364 equal(assert, moment([2012, 0, 1]).diff([2012, 0, 31], 'months', true), -(30 / 31), 'Jan 1 to Jan 31 should be 30 / 31 months');
68365 assert.ok(0 < moment('2014-02-01').diff(moment('2014-01-31'), 'months', true), 'jan-31 to feb-1 diff is positive');
68366 });
68367
68368 test('exact month diffs', function (assert) {
68369 // generate all pairs of months and compute month diff, with fixed day
68370 // of month = 15.
68371
68372 var m1, m2;
68373 for (m1 = 0; m1 < 12; ++m1) {
68374 for (m2 = m1; m2 < 12; ++m2) {
68375 assert.equal(moment([2013, m2, 15]).diff(moment([2013, m1, 15]), 'months', true), m2 - m1,
68376 'month diff from 2013-' + m1 + '-15 to 2013-' + m2 + '-15');
68377 }
68378 }
68379 });
68380
68381 test('year diffs', function (assert) {
68382 // due to floating point math errors, these tests just need to be accurate within 0.00000001
68383 equal(assert, moment([2012, 0, 1]).diff([2013, 0, 1], 'years', true), -1, 'Jan 1 2012 to Jan 1 2013 should be 1 year');
68384 equal(assert, moment([2012, 1, 28]).diff([2013, 1, 28], 'years', true), -1, 'Feb 28 2012 to Feb 28 2013 should be 1 year');
68385 equal(assert, moment([2012, 2, 1]).diff([2013, 2, 1], 'years', true), -1, 'Mar 1 2012 to Mar 1 2013 should be 1 year');
68386 equal(assert, moment([2012, 11, 1]).diff([2013, 11, 1], 'years', true), -1, 'Dec 1 2012 to Dec 1 2013 should be 1 year');
68387 equal(assert, moment([2012, 11, 31]).diff([2013, 11, 31], 'years', true), -1, 'Dec 31 2012 to Dec 31 2013 should be 1 year');
68388 equal(assert, moment([2012, 0, 1]).diff([2013, 6, 1], 'years', true), -1.5, 'Jan 1 2012 to Jul 1 2013 should be 1.5 years');
68389 equal(assert, moment([2012, 0, 31]).diff([2013, 6, 31], 'years', true), -1.5, 'Jan 31 2012 to Jul 31 2013 should be 1.5 years');
68390 equal(assert, moment([2012, 0, 1]).diff([2013, 0, 1, 12], 'years', true), -1 - (0.5 / 31) / 12, 'Jan 1 2012 to Jan 1 2013 noon should be 1+(0.5 / 31) / 12 years');
68391 equal(assert, moment([2012, 0, 1]).diff([2013, 6, 1, 12], 'years', true), -1.5 - (0.5 / 31) / 12, 'Jan 1 2012 to Jul 1 2013 noon should be 1.5+(0.5 / 31) / 12 years');
68392 equal(assert, moment([2012, 1, 29]).diff([2013, 1, 28], 'years', true), -1, 'Feb 29 2012 to Feb 28 2013 should be 1-(1 / 28.5) / 12 years');
68393 });
68394
68395 test('negative zero', function (assert) {
68396 function isNegative (n) {
68397 return (1 / n) < 0;
68398 }
68399 assert.ok(!isNegative(moment([2012, 0, 1]).diff(moment([2012, 0, 1]), 'months')), 'month diff on same date is zero, not -0');
68400 assert.ok(!isNegative(moment([2012, 0, 1]).diff(moment([2012, 0, 1]), 'years')), 'year diff on same date is zero, not -0');
68401 assert.ok(!isNegative(moment([2012, 0, 1]).diff(moment([2012, 0, 1]), 'quarters')), 'quarter diff on same date is zero, not -0');
68402 assert.ok(!isNegative(moment([2012, 0, 1]).diff(moment([2012, 0, 1, 1]), 'days')), 'days diff on same date is zero, not -0');
68403 assert.ok(!isNegative(moment([2012, 0, 1]).diff(moment([2012, 0, 1, 0, 1]), 'hours')), 'hour diff on same hour is zero, not -0');
68404 assert.ok(!isNegative(moment([2012, 0, 1]).diff(moment([2012, 0, 1, 0, 0, 1]), 'minutes')), 'minute diff on same minute is zero, not -0');
68405 assert.ok(!isNegative(moment([2012, 0, 1]).diff(moment([2012, 0, 1, 0, 0, 0, 1]), 'seconds')), 'second diff on same second is zero, not -0');
68406 });
73f3c911
IC
68407
68408})));
68409
516f5f67 68410
c74a101d
IC
68411;(function (global, factory) {
68412 typeof exports === 'object' && typeof module !== 'undefined'
68413 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
68414 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
68415 factory(global.moment)
73f3c911 68416}(this, (function (moment) { 'use strict';
516f5f67 68417
db71a655
KM
68418 function each(array, callback) {
68419 var i;
68420 for (i = 0; i < array.length; i++) {
68421 callback(array[i], i, array);
68422 }
b135bf1a
IC
68423 }
68424
db71a655
KM
68425 function setupDeprecationHandler(test, moment$$1, scope) {
68426 test._expectedDeprecations = null;
68427 test._observedDeprecations = null;
68428 test._oldSupress = moment$$1.suppressDeprecationWarnings;
68429 moment$$1.suppressDeprecationWarnings = true;
68430 test.expectedDeprecations = function () {
68431 test._expectedDeprecations = arguments;
68432 test._observedDeprecations = [];
68433 };
68434 moment$$1.deprecationHandler = function (name, msg) {
68435 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
68436 if (deprecationId === -1) {
68437 throw new Error('Unexpected deprecation thrown name=' +
68438 name + ' msg=' + msg);
b135bf1a 68439 }
db71a655
KM
68440 test._observedDeprecations[deprecationId] = 1;
68441 };
b135bf1a
IC
68442 }
68443
db71a655
KM
68444 function teardownDeprecationHandler(test, moment$$1, scope) {
68445 moment$$1.suppressDeprecationWarnings = test._oldSupress;
b135bf1a 68446
db71a655
KM
68447 if (test._expectedDeprecations != null) {
68448 var missedDeprecations = [];
68449 each(test._expectedDeprecations, function (deprecationPattern, id) {
68450 if (test._observedDeprecations[id] !== 1) {
68451 missedDeprecations.push(deprecationPattern);
68452 }
68453 });
68454 if (missedDeprecations.length !== 0) {
68455 throw new Error('Expected deprecation warnings did not happen: ' +
68456 missedDeprecations.join(' '));
68457 }
73f3c911 68458 }
db71a655 68459 }
b135bf1a 68460
db71a655
KM
68461 function matchedDeprecation(name, msg, deprecations) {
68462 if (deprecations == null) {
68463 return -1;
73f3c911 68464 }
db71a655
KM
68465 for (var i = 0; i < deprecations.length; ++i) {
68466 if (name != null && name === deprecations[i]) {
68467 return i;
68468 }
68469 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
68470 return i;
68471 }
73f3c911 68472 }
db71a655
KM
68473 return -1;
68474 }
68475
68476 /*global QUnit:false*/
68477
68478 var test = QUnit.test;
68479
db71a655
KM
68480 function module$1 (name, lifecycle) {
68481 QUnit.module(name, {
c58511b9 68482 beforeEach : function () {
db71a655
KM
68483 moment.locale('en');
68484 moment.createFromInputFallback = function (config) {
68485 throw new Error('input not handled by moment: ' + config._i);
68486 };
68487 setupDeprecationHandler(test, moment, 'core');
68488 if (lifecycle && lifecycle.setup) {
68489 lifecycle.setup();
68490 }
68491 },
c58511b9 68492 afterEach : function () {
db71a655
KM
68493 teardownDeprecationHandler(test, moment, 'core');
68494 if (lifecycle && lifecycle.teardown) {
68495 lifecycle.teardown();
68496 }
68497 }
68498 });
68499 }
68500
68501 module$1('duration');
68502
68503 test('object instantiation', function (assert) {
68504 var d = moment.duration({
68505 years: 2,
68506 months: 3,
68507 weeks: 2,
68508 days: 1,
68509 hours: 8,
68510 minutes: 9,
68511 seconds: 20,
68512 milliseconds: 12
68513 });
68514
68515 assert.equal(d.years(), 2, 'years');
68516 assert.equal(d.months(), 3, 'months');
68517 assert.equal(d.weeks(), 2, 'weeks');
68518 assert.equal(d.days(), 15, 'days'); // two weeks + 1 day
68519 assert.equal(d.hours(), 8, 'hours');
68520 assert.equal(d.minutes(), 9, 'minutes');
68521 assert.equal(d.seconds(), 20, 'seconds');
68522 assert.equal(d.milliseconds(), 12, 'milliseconds');
68523 });
68524
68525 test('object instantiation with strings', function (assert) {
68526 var d = moment.duration({
68527 years: '2',
68528 months: '3',
68529 weeks: '2',
68530 days: '1',
68531 hours: '8',
68532 minutes: '9',
68533 seconds: '20',
68534 milliseconds: '12'
68535 });
68536
68537 assert.equal(d.years(), 2, 'years');
68538 assert.equal(d.months(), 3, 'months');
68539 assert.equal(d.weeks(), 2, 'weeks');
68540 assert.equal(d.days(), 15, 'days'); // two weeks + 1 day
68541 assert.equal(d.hours(), 8, 'hours');
68542 assert.equal(d.minutes(), 9, 'minutes');
68543 assert.equal(d.seconds(), 20, 'seconds');
68544 assert.equal(d.milliseconds(), 12, 'milliseconds');
68545 });
68546
68547 test('milliseconds instantiation', function (assert) {
68548 assert.equal(moment.duration(72).milliseconds(), 72, 'milliseconds');
68549 assert.equal(moment.duration(72).humanize(), 'a few seconds', 'Duration should be valid');
68550 });
68551
68552 test('undefined instantiation', function (assert) {
68553 assert.equal(moment.duration(undefined).milliseconds(), 0, 'milliseconds');
68554 assert.equal(moment.duration(undefined).isValid(), true, '_isValid');
68555 assert.equal(moment.duration(undefined).humanize(), 'a few seconds', 'Duration should be valid');
68556 });
68557
68558 test('null instantiation', function (assert) {
68559 assert.equal(moment.duration(null).milliseconds(), 0, 'milliseconds');
68560 assert.equal(moment.duration(null).isValid(), true, '_isValid');
68561 assert.equal(moment.duration(null).humanize(), 'a few seconds', 'Duration should be valid');
68562 });
68563
68564 test('NaN instantiation', function (assert) {
68565 assert.ok(isNaN(moment.duration(NaN).milliseconds()), 'milliseconds should be NaN');
68566 assert.equal(moment.duration(NaN).isValid(), false, '_isValid');
68567 assert.equal(moment.duration(NaN).humanize(), 'Invalid date', 'Duration should be invalid');
68568 });
68569
68570 test('instantiation by type', function (assert) {
68571 assert.equal(moment.duration(1, 'years').years(), 1, 'years');
68572 assert.equal(moment.duration(1, 'y').years(), 1, 'y');
68573 assert.equal(moment.duration(2, 'months').months(), 2, 'months');
68574 assert.equal(moment.duration(2, 'M').months(), 2, 'M');
68575 assert.equal(moment.duration(3, 'weeks').weeks(), 3, 'weeks');
68576 assert.equal(moment.duration(3, 'w').weeks(), 3, 'weeks');
68577 assert.equal(moment.duration(4, 'days').days(), 4, 'days');
68578 assert.equal(moment.duration(4, 'd').days(), 4, 'd');
68579 assert.equal(moment.duration(5, 'hours').hours(), 5, 'hours');
68580 assert.equal(moment.duration(5, 'h').hours(), 5, 'h');
68581 assert.equal(moment.duration(6, 'minutes').minutes(), 6, 'minutes');
68582 assert.equal(moment.duration(6, 'm').minutes(), 6, 'm');
68583 assert.equal(moment.duration(7, 'seconds').seconds(), 7, 'seconds');
68584 assert.equal(moment.duration(7, 's').seconds(), 7, 's');
68585 assert.equal(moment.duration(8, 'milliseconds').milliseconds(), 8, 'milliseconds');
68586 assert.equal(moment.duration(8, 'ms').milliseconds(), 8, 'ms');
68587 });
68588
68589 test('shortcuts', function (assert) {
68590 assert.equal(moment.duration({y: 1}).years(), 1, 'years = y');
68591 assert.equal(moment.duration({M: 2}).months(), 2, 'months = M');
68592 assert.equal(moment.duration({w: 3}).weeks(), 3, 'weeks = w');
68593 assert.equal(moment.duration({d: 4}).days(), 4, 'days = d');
68594 assert.equal(moment.duration({h: 5}).hours(), 5, 'hours = h');
68595 assert.equal(moment.duration({m: 6}).minutes(), 6, 'minutes = m');
68596 assert.equal(moment.duration({s: 7}).seconds(), 7, 'seconds = s');
68597 assert.equal(moment.duration({ms: 8}).milliseconds(), 8, 'milliseconds = ms');
68598 });
68599
68600 test('generic getter', function (assert) {
68601 assert.equal(moment.duration(1, 'years').get('years'), 1, 'years');
68602 assert.equal(moment.duration(1, 'years').get('year'), 1, 'years = year');
68603 assert.equal(moment.duration(1, 'years').get('y'), 1, 'years = y');
68604 assert.equal(moment.duration(2, 'months').get('months'), 2, 'months');
68605 assert.equal(moment.duration(2, 'months').get('month'), 2, 'months = month');
68606 assert.equal(moment.duration(2, 'months').get('M'), 2, 'months = M');
68607 assert.equal(moment.duration(3, 'weeks').get('weeks'), 3, 'weeks');
68608 assert.equal(moment.duration(3, 'weeks').get('week'), 3, 'weeks = week');
68609 assert.equal(moment.duration(3, 'weeks').get('w'), 3, 'weeks = w');
68610 assert.equal(moment.duration(4, 'days').get('days'), 4, 'days');
68611 assert.equal(moment.duration(4, 'days').get('day'), 4, 'days = day');
68612 assert.equal(moment.duration(4, 'days').get('d'), 4, 'days = d');
68613 assert.equal(moment.duration(5, 'hours').get('hours'), 5, 'hours');
68614 assert.equal(moment.duration(5, 'hours').get('hour'), 5, 'hours = hour');
68615 assert.equal(moment.duration(5, 'hours').get('h'), 5, 'hours = h');
68616 assert.equal(moment.duration(6, 'minutes').get('minutes'), 6, 'minutes');
68617 assert.equal(moment.duration(6, 'minutes').get('minute'), 6, 'minutes = minute');
68618 assert.equal(moment.duration(6, 'minutes').get('m'), 6, 'minutes = m');
68619 assert.equal(moment.duration(7, 'seconds').get('seconds'), 7, 'seconds');
68620 assert.equal(moment.duration(7, 'seconds').get('second'), 7, 'seconds = second');
68621 assert.equal(moment.duration(7, 'seconds').get('s'), 7, 'seconds = s');
68622 assert.equal(moment.duration(8, 'milliseconds').get('milliseconds'), 8, 'milliseconds');
68623 assert.equal(moment.duration(8, 'milliseconds').get('millisecond'), 8, 'milliseconds = millisecond');
68624 assert.equal(moment.duration(8, 'milliseconds').get('ms'), 8, 'milliseconds = ms');
68625 });
68626
68627 test('instantiation from another duration', function (assert) {
68628 var simple = moment.duration(1234),
68629 lengthy = moment.duration(60 * 60 * 24 * 360 * 1e3),
68630 complicated = moment.duration({
68631 years: 2,
68632 months: 3,
68633 weeks: 4,
68634 days: 1,
68635 hours: 8,
68636 minutes: 9,
68637 seconds: 20,
68638 milliseconds: 12
68639 }),
68640 modified = moment.duration(1, 'day').add(moment.duration(1, 'day'));
68641
68642 assert.deepEqual(moment.duration(simple), simple, 'simple clones are equal');
68643 assert.deepEqual(moment.duration(lengthy), lengthy, 'lengthy clones are equal');
68644 assert.deepEqual(moment.duration(complicated), complicated, 'complicated clones are equal');
68645 assert.deepEqual(moment.duration(modified), modified, 'cloning modified duration works');
68646 });
68647
68648 test('explicit cloning', function (assert) {
68649 var durationA = moment.duration(5, 'milliseconds');
68650 var durationB = durationA.clone();
68651 durationA.add(5, 'milliseconds');
68652 assert.notEqual(durationA.milliseconds(), durationB.milliseconds(), 'Calling duration.clone() on a duration will create a clone');
68653 });
68654
68655 test('instantiation from 24-hour time zero', function (assert) {
68656 assert.equal(moment.duration('00:00').years(), 0, '0 years');
68657 assert.equal(moment.duration('00:00').days(), 0, '0 days');
68658 assert.equal(moment.duration('00:00').hours(), 0, '0 hours');
68659 assert.equal(moment.duration('00:00').minutes(), 0, '0 minutes');
68660 assert.equal(moment.duration('00:00').seconds(), 0, '0 seconds');
68661 assert.equal(moment.duration('00:00').milliseconds(), 0, '0 milliseconds');
68662 });
68663
68664 test('instantiation from 24-hour time <24 hours', function (assert) {
68665 assert.equal(moment.duration('06:45').years(), 0, '0 years');
68666 assert.equal(moment.duration('06:45').days(), 0, '0 days');
68667 assert.equal(moment.duration('06:45').hours(), 6, '6 hours');
68668 assert.equal(moment.duration('06:45').minutes(), 45, '45 minutes');
68669 assert.equal(moment.duration('06:45').seconds(), 0, '0 seconds');
68670 assert.equal(moment.duration('06:45').milliseconds(), 0, '0 milliseconds');
68671 });
68672
68673 test('instantiation from 24-hour time >24 hours', function (assert) {
68674 assert.equal(moment.duration('26:45').years(), 0, '0 years');
68675 assert.equal(moment.duration('26:45').days(), 1, '0 days');
68676 assert.equal(moment.duration('26:45').hours(), 2, '2 hours');
68677 assert.equal(moment.duration('26:45').minutes(), 45, '45 minutes');
68678 assert.equal(moment.duration('26:45').seconds(), 0, '0 seconds');
68679 assert.equal(moment.duration('26:45').milliseconds(), 0, '0 milliseconds');
68680 });
68681
68682 test('instatiation from serialized C# TimeSpan zero', function (assert) {
68683 assert.equal(moment.duration('00:00:00').years(), 0, '0 years');
68684 assert.equal(moment.duration('00:00:00').days(), 0, '0 days');
68685 assert.equal(moment.duration('00:00:00').hours(), 0, '0 hours');
68686 assert.equal(moment.duration('00:00:00').minutes(), 0, '0 minutes');
68687 assert.equal(moment.duration('00:00:00').seconds(), 0, '0 seconds');
68688 assert.equal(moment.duration('00:00:00').milliseconds(), 0, '0 milliseconds');
68689 });
68690
68691 test('instatiation from serialized C# TimeSpan with days', function (assert) {
68692 assert.equal(moment.duration('1.02:03:04.9999999').years(), 0, '0 years');
68693 assert.equal(moment.duration('1.02:03:04.9999999').days(), 1, '1 day');
68694 assert.equal(moment.duration('1.02:03:04.9999999').hours(), 2, '2 hours');
68695 assert.equal(moment.duration('1.02:03:04.9999999').minutes(), 3, '3 minutes');
68696 assert.equal(moment.duration('1.02:03:04.9999999').seconds(), 5, '5 seconds');
68697 assert.equal(moment.duration('1.02:03:04.9999999').milliseconds(), 0, '0 milliseconds');
68698
68699 assert.equal(moment.duration('1 02:03:04.9999999').years(), 0, '0 years');
68700 assert.equal(moment.duration('1 02:03:04.9999999').days(), 1, '1 day');
68701 assert.equal(moment.duration('1 02:03:04.9999999').hours(), 2, '2 hours');
68702 assert.equal(moment.duration('1 02:03:04.9999999').minutes(), 3, '3 minutes');
68703 assert.equal(moment.duration('1 02:03:04.9999999').seconds(), 5, '5 seconds');
68704 assert.equal(moment.duration('1 02:03:04.9999999').milliseconds(), 0, '0 milliseconds');
68705 });
68706
68707 test('instatiation from serialized C# TimeSpan without days', function (assert) {
68708 assert.equal(moment.duration('01:02:03.9999999').years(), 0, '0 years');
68709 assert.equal(moment.duration('01:02:03.9999999').days(), 0, '0 days');
68710 assert.equal(moment.duration('01:02:03.9999999').hours(), 1, '1 hour');
68711 assert.equal(moment.duration('01:02:03.9999999').minutes(), 2, '2 minutes');
68712 assert.equal(moment.duration('01:02:03.9999999').seconds(), 4, '4 seconds');
68713 assert.equal(moment.duration('01:02:03.9999999').milliseconds(), 0, '0 milliseconds');
68714
68715 assert.equal(moment.duration('23:59:59.9999999').days(), 1, '1 days');
68716 assert.equal(moment.duration('23:59:59.9999999').hours(), 0, '0 hours');
68717 assert.equal(moment.duration('23:59:59.9999999').minutes(), 0, '0 minutes');
68718 assert.equal(moment.duration('23:59:59.9999999').seconds(), 0, '0 seconds');
68719 assert.equal(moment.duration('23:59:59.9999999').milliseconds(), 0, '0 milliseconds');
68720
68721 assert.equal(moment.duration('500:59:59.8888888').days(), 20, '500 hours overflows to 20 days');
68722 assert.equal(moment.duration('500:59:59.8888888').hours(), 20, '500 hours overflows to 20 hours');
73f3c911 68723 });
b135bf1a 68724
db71a655
KM
68725 test('instatiation from serialized C# TimeSpan without days or milliseconds', function (assert) {
68726 assert.equal(moment.duration('01:02:03').years(), 0, '0 years');
68727 assert.equal(moment.duration('01:02:03').days(), 0, '0 days');
68728 assert.equal(moment.duration('01:02:03').hours(), 1, '1 hour');
68729 assert.equal(moment.duration('01:02:03').minutes(), 2, '2 minutes');
68730 assert.equal(moment.duration('01:02:03').seconds(), 3, '3 seconds');
68731 assert.equal(moment.duration('01:02:03').milliseconds(), 0, '0 milliseconds');
68732 });
68733
68734 test('instatiation from serialized C# TimeSpan without milliseconds', function (assert) {
68735 assert.equal(moment.duration('1.02:03:04').years(), 0, '0 years');
68736 assert.equal(moment.duration('1.02:03:04').days(), 1, '1 day');
68737 assert.equal(moment.duration('1.02:03:04').hours(), 2, '2 hours');
68738 assert.equal(moment.duration('1.02:03:04').minutes(), 3, '3 minutes');
68739 assert.equal(moment.duration('1.02:03:04').seconds(), 4, '4 seconds');
68740 assert.equal(moment.duration('1.02:03:04').milliseconds(), 0, '0 milliseconds');
68741 });
68742
68743 test('instantiation from serialized C# TimeSpan with low millisecond precision', function (assert) {
68744 assert.equal(moment.duration('00:00:15.72').years(), 0, '0 years');
68745 assert.equal(moment.duration('00:00:15.72').days(), 0, '0 days');
68746 assert.equal(moment.duration('00:00:15.72').hours(), 0, '0 hours');
68747 assert.equal(moment.duration('00:00:15.72').minutes(), 0, '0 minutes');
68748 assert.equal(moment.duration('00:00:15.72').seconds(), 15, '15 seconds');
68749 assert.equal(moment.duration('00:00:15.72').milliseconds(), 720, '720 milliseconds');
68750
68751 assert.equal(moment.duration('00:00:15.7').milliseconds(), 700, '700 milliseconds');
68752
68753 assert.equal(moment.duration('00:00:15.').milliseconds(), 0, '0 milliseconds');
68754 });
68755
68756 test('instantiation from serialized C# TimeSpan with high millisecond precision', function (assert) {
68757 assert.equal(moment.duration('00:00:15.7200000').seconds(), 15, '15 seconds');
68758 assert.equal(moment.duration('00:00:15.7200000').milliseconds(), 720, '720 milliseconds');
68759
68760 assert.equal(moment.duration('00:00:15.7209999').seconds(), 15, '15 seconds');
68761 assert.equal(moment.duration('00:00:15.7209999').milliseconds(), 721, '721 milliseconds');
68762
68763 assert.equal(moment.duration('00:00:15.7205000').seconds(), 15, '15 seconds');
68764 assert.equal(moment.duration('00:00:15.7205000').milliseconds(), 721, '721 milliseconds');
68765
68766 assert.equal(moment.duration('-00:00:15.7205000').seconds(), -15, '15 seconds');
68767 assert.equal(moment.duration('-00:00:15.7205000').milliseconds(), -721, '721 milliseconds');
68768
68769 assert.equal(moment.duration('+00:00:15.7205000').seconds(), 15, '15 seconds');
68770 assert.equal(moment.duration('+00:00:15.7205000').milliseconds(), 721, '721 milliseconds');
68771 });
68772
68773 test('instatiation from serialized C# TimeSpan maxValue', function (assert) {
68774 var d = moment.duration('10675199.02:48:05.4775807');
68775
68776 assert.equal(d.years(), 29227, '29227 years');
68777 assert.equal(d.months(), 8, '8 months');
68778 assert.equal(d.days(), 12, '12 day'); // if you have to change this value -- just do it
68779
68780 assert.equal(d.hours(), 2, '2 hours');
68781 assert.equal(d.minutes(), 48, '48 minutes');
68782 assert.equal(d.seconds(), 5, '5 seconds');
68783 assert.equal(d.milliseconds(), 478, '478 milliseconds');
68784 });
68785
68786 test('instatiation from serialized C# TimeSpan minValue', function (assert) {
68787 var d = moment.duration('-10675199.02:48:05.4775808');
68788
68789 assert.equal(d.years(), -29227, '29653 years');
68790 assert.equal(d.months(), -8, '8 day');
68791 assert.equal(d.days(), -12, '12 day'); // if you have to change this value -- just do it
68792
68793 assert.equal(d.hours(), -2, '2 hours');
68794 assert.equal(d.minutes(), -48, '48 minutes');
68795 assert.equal(d.seconds(), -5, '5 seconds');
68796 assert.equal(d.milliseconds(), -478, '478 milliseconds');
68797 });
68798
68799 test('instatiation from serialized C# TimeSpan maxValue with + sign', function (assert) {
68800 var d = moment.duration('+10675199.02:48:05.4775808');
68801
68802 assert.equal(d.years(), 29227, '29653 years');
68803 assert.equal(d.months(), 8, '8 day');
68804 assert.equal(d.days(), 12, '12 day'); // if you have to change this value -- just do it
68805
68806 assert.equal(d.hours(), 2, '2 hours');
68807 assert.equal(d.minutes(), 48, '48 minutes');
68808 assert.equal(d.seconds(), 5, '5 seconds');
68809 assert.equal(d.milliseconds(), 478, '478 milliseconds');
68810 });
68811
68812 test('instantiation from ISO 8601 duration', function (assert) {
68813 assert.equal(moment.duration('P1Y2M3DT4H5M6S').asSeconds(), moment.duration({y: 1, M: 2, d: 3, h: 4, m: 5, s: 6}).asSeconds(), 'all fields');
68814 assert.equal(moment.duration('P3W3D').asSeconds(), moment.duration({w: 3, d: 3}).asSeconds(), 'week and day fields');
68815 assert.equal(moment.duration('P1M').asSeconds(), moment.duration({M: 1}).asSeconds(), 'single month field');
68816 assert.equal(moment.duration('PT1M').asSeconds(), moment.duration({m: 1}).asSeconds(), 'single minute field');
68817 assert.equal(moment.duration('P1MT2H').asSeconds(), moment.duration({M: 1, h: 2}).asSeconds(), 'random fields missing');
68818 assert.equal(moment.duration('-P60D').asSeconds(), moment.duration({d: -60}).asSeconds(), 'negative days');
68819 assert.equal(moment.duration('+P60D').asSeconds(), moment.duration({d: 60}).asSeconds(), 'positive days');
68820 assert.equal(moment.duration('PT0.5S').asSeconds(), moment.duration({s: 0.5}).asSeconds(), 'fractional seconds');
68821 assert.equal(moment.duration('PT0,5S').asSeconds(), moment.duration({s: 0.5}).asSeconds(), 'fractional seconds (comma)');
68822 });
68823
68824 test('serialization to ISO 8601 duration strings', function (assert) {
68825 assert.equal(moment.duration({y: 1, M: 2, d: 3, h: 4, m: 5, s: 6}).toISOString(), 'P1Y2M3DT4H5M6S', 'all fields');
68826 assert.equal(moment.duration({M: -1}).toISOString(), '-P1M', 'one month ago');
68827 assert.equal(moment.duration({m: -1}).toISOString(), '-PT1M', 'one minute ago');
68828 assert.equal(moment.duration({s: -0.5}).toISOString(), '-PT0.5S', 'one half second ago');
68829 assert.equal(moment.duration({y: -1, M: 1}).toISOString(), '-P11M', 'a month after a year ago');
68830 assert.equal(moment.duration({y: -1, h: 1}).toISOString(), '-P1YT-1H', 'an hour after a year ago');
68831 assert.equal(moment.duration({y: -1, h: 1, m: -1}).toISOString(), '-P1YT-59M', '59 minutes after a year ago');
68832 assert.equal(moment.duration({y: -1, h: 1, s: -1}).toISOString(), '-P1YT-59M-59S', '59 minutes 59 seconds after a year ago');
68833 assert.equal(moment.duration({y: -1, h: -1, s: 1}).toISOString(), '-P1YT59M59S', '59 minutes 59 seconds after a year ago');
68834 assert.equal(moment.duration({y: -1, d: 2}).toISOString(), '-P1Y-2D', '1 year less 2 days ago');
68835 assert.equal(moment.duration({M: +1}).toISOString(), 'P1M', 'one month ago');
68836 assert.equal(moment.duration({m: +1}).toISOString(), 'PT1M', 'one minute ago');
68837 assert.equal(moment.duration({s: +0.5}).toISOString(), 'PT0.5S', 'one half second ago');
68838 assert.equal(moment.duration({y: +1, M: 1}).toISOString(), 'P1Y1M', 'a month after a year in future');
68839 assert.equal(moment.duration({y: -1, h: 1}).toISOString(), '-P1YT-1H', 'an hour after a year ago');
68840 assert.equal(moment.duration({}).toISOString(), 'P0D', 'zero duration');
68841 assert.equal(moment.duration({M: 16, d:40, s: 86465}).toISOString(), 'P1Y4M40DT24H1M5S', 'all fields');
68842 assert.equal(moment.duration({ms: 123456789}).toISOString(), 'PT34H17M36.789S', 'check floating-point errors');
68843 assert.equal(moment.duration({ms: 31952}).toISOString(), 'PT31.952S', 'check floating-point errors');
68844 });
68845
68846 test('toString acts as toISOString', function (assert) {
68847 assert.equal(moment.duration({y: 1, M: 2, d: 3, h: 4, m: 5, s: 6}).toString(), 'P1Y2M3DT4H5M6S', 'all fields');
68848 assert.equal(moment.duration({M: -1}).toString(), '-P1M', 'one month ago');
68849 assert.equal(moment.duration({m: -1}).toString(), '-PT1M', 'one minute ago');
68850 assert.equal(moment.duration({s: -0.5}).toString(), '-PT0.5S', 'one half second ago');
68851 assert.equal(moment.duration({y: -1, M: 1}).toString(), '-P11M', 'a month after a year ago');
68852 assert.equal(moment.duration({M: +1}).toString(), 'P1M', 'one month ago');
68853 assert.equal(moment.duration({m: +1}).toString(), 'PT1M', 'one minute ago');
68854 assert.equal(moment.duration({s: +0.5}).toString(), 'PT0.5S', 'one half second ago');
68855 assert.equal(moment.duration({y: +1, M: 1}).toString(), 'P1Y1M', 'a month after a year in future');
68856 assert.equal(moment.duration({}).toString(), 'P0D', 'zero duration');
68857 assert.equal(moment.duration({M: 16, d:40, s: 86465}).toString(), 'P1Y4M40DT24H1M5S', 'all fields');
68858 });
68859
68860 test('toIsoString deprecation', function (assert) {
68861 test.expectedDeprecations('toIsoString()');
68862
68863 assert.equal(moment.duration({}).toIsoString(), moment.duration({}).toISOString(), 'toIsoString delegates to toISOString');
68864 });
68865
68866 test('`isodate` (python) test cases', function (assert) {
68867 assert.equal(moment.duration('P18Y9M4DT11H9M8S').asSeconds(), moment.duration({y: 18, M: 9, d: 4, h: 11, m: 9, s: 8}).asSeconds(), 'python isodate 1');
68868 assert.equal(moment.duration('P2W').asSeconds(), moment.duration({w: 2}).asSeconds(), 'python isodate 2');
68869 assert.equal(moment.duration('P3Y6M4DT12H30M5S').asSeconds(), moment.duration({y: 3, M: 6, d: 4, h: 12, m: 30, s: 5}).asSeconds(), 'python isodate 3');
68870 assert.equal(moment.duration('P23DT23H').asSeconds(), moment.duration({d: 23, h: 23}).asSeconds(), 'python isodate 4');
68871 assert.equal(moment.duration('P4Y').asSeconds(), moment.duration({y: 4}).asSeconds(), 'python isodate 5');
68872 assert.equal(moment.duration('P1M').asSeconds(), moment.duration({M: 1}).asSeconds(), 'python isodate 6');
68873 assert.equal(moment.duration('PT1M').asSeconds(), moment.duration({m: 1}).asSeconds(), 'python isodate 7');
68874 assert.equal(moment.duration('P0.5Y').asSeconds(), moment.duration({y: 0.5}).asSeconds(), 'python isodate 8');
68875 assert.equal(moment.duration('PT36H').asSeconds(), moment.duration({h: 36}).asSeconds(), 'python isodate 9');
68876 assert.equal(moment.duration('P1DT12H').asSeconds(), moment.duration({d: 1, h: 12}).asSeconds(), 'python isodate 10');
68877 assert.equal(moment.duration('-P2W').asSeconds(), moment.duration({w: -2}).asSeconds(), 'python isodate 11');
68878 assert.equal(moment.duration('-P2.2W').asSeconds(), moment.duration({w: -2.2}).asSeconds(), 'python isodate 12');
68879 assert.equal(moment.duration('+P2W').asSeconds(), moment.duration({w: 2}).asSeconds(), 'python isodate 11');
68880 assert.equal(moment.duration('+P2.2W').asSeconds(), moment.duration({w: 2.2}).asSeconds(), 'python isodate 12');
68881 assert.equal(moment.duration('P1DT2H3M4S').asSeconds(), moment.duration({d: 1, h: 2, m: 3, s: 4}).asSeconds(), 'python isodate 13');
68882 assert.equal(moment.duration('P1DT2H3M').asSeconds(), moment.duration({d: 1, h: 2, m: 3}).asSeconds(), 'python isodate 14');
68883 assert.equal(moment.duration('P1DT2H').asSeconds(), moment.duration({d: 1, h: 2}).asSeconds(), 'python isodate 15');
68884 assert.equal(moment.duration('PT2H').asSeconds(), moment.duration({h: 2}).asSeconds(), 'python isodate 16');
68885 assert.equal(moment.duration('PT2.3H').asSeconds(), moment.duration({h: 2.3}).asSeconds(), 'python isodate 17');
68886 assert.equal(moment.duration('PT2H3M4S').asSeconds(), moment.duration({h: 2, m: 3, s: 4}).asSeconds(), 'python isodate 18');
68887 assert.equal(moment.duration('PT3M4S').asSeconds(), moment.duration({m: 3, s: 4}).asSeconds(), 'python isodate 19');
68888 assert.equal(moment.duration('PT22S').asSeconds(), moment.duration({s: 22}).asSeconds(), 'python isodate 20');
68889 assert.equal(moment.duration('PT22.22S').asSeconds(), moment.duration({s: 22.22}).asSeconds(), 'python isodate 21');
68890 assert.equal(moment.duration('-P2Y').asSeconds(), moment.duration({y: -2}).asSeconds(), 'python isodate 22');
68891 assert.equal(moment.duration('-P3Y6M4DT12H30M5S').asSeconds(), moment.duration({y: -3, M: -6, d: -4, h: -12, m: -30, s: -5}).asSeconds(), 'python isodate 23');
68892 assert.equal(moment.duration('-P1DT2H3M4S').asSeconds(), moment.duration({d: -1, h: -2, m: -3, s: -4}).asSeconds(), 'python isodate 24');
68893 assert.equal(moment.duration('PT-6H3M').asSeconds(), moment.duration({h: -6, m: 3}).asSeconds(), 'python isodate 25');
68894 assert.equal(moment.duration('-PT-6H3M').asSeconds(), moment.duration({h: 6, m: -3}).asSeconds(), 'python isodate 26');
68895 assert.equal(moment.duration('-P-3Y-6M-4DT-12H-30M-5S').asSeconds(), moment.duration({y: 3, M: 6, d: 4, h: 12, m: 30, s: 5}).asSeconds(), 'python isodate 27');
68896 assert.equal(moment.duration('P-3Y-6M-4DT-12H-30M-5S').asSeconds(), moment.duration({y: -3, M: -6, d: -4, h: -12, m: -30, s: -5}).asSeconds(), 'python isodate 28');
68897 assert.equal(moment.duration('-P-2W').asSeconds(), moment.duration({w: 2}).asSeconds(), 'python isodate 29');
68898 assert.equal(moment.duration('P-2W').asSeconds(), moment.duration({w: -2}).asSeconds(), 'python isodate 30');
68899 assert.equal(moment.duration('+P2Y').asSeconds(), moment.duration({y: 2}).asSeconds(), 'python isodate 31');
68900 assert.equal(moment.duration('+P3Y6M4DT12H30M5S').asSeconds(), moment.duration({y: 3, M: 6, d: 4, h: 12, m: 30, s: 5}).asSeconds(), 'python isodate 32');
68901 assert.equal(moment.duration('+P1DT2H3M4S').asSeconds(), moment.duration({d: 1, h: 2, m: 3, s: 4}).asSeconds(), 'python isodate 34');
68902 assert.equal(moment.duration('PT+6H3M').asSeconds(), moment.duration({h: 6, m: 3}).asSeconds(), 'python isodate 35');
68903 assert.equal(moment.duration('+PT+6H3M').asSeconds(), moment.duration({h: 6, m: 3}).asSeconds(), 'python isodate 36');
68904 assert.equal(moment.duration('+PT-6H3M').asSeconds(), moment.duration({h: -6, m: 3}).asSeconds(), 'python isodate 37');
68905 assert.equal(moment.duration('+P+3Y+6M+4DT+12H+30M+5S').asSeconds(), moment.duration({y: 3, M: 6, d: 4, h: 12, m: 30, s: 5}).asSeconds(), 'python isodate 38');
68906 assert.equal(moment.duration('+P-3Y-6M-4DT-12H-30M-5S').asSeconds(), moment.duration({y: -3, M: -6, d: -4, h: -12, m: -30, s: -5}).asSeconds(), 'python isodate 39');
68907 assert.equal(moment.duration('P+3Y+6M+4DT+12H+30M+5S').asSeconds(), moment.duration({y: 3, M: 6, d: 4, h: 12, m: 30, s: 5}).asSeconds(), 'python isodate 40');
68908 assert.equal(moment.duration('+P+2W').asSeconds(), moment.duration({w: 2}).asSeconds(), 'python isodate 41');
68909 assert.equal(moment.duration('+P-2W').asSeconds(), moment.duration({w: -2}).asSeconds(), 'python isodate 41');
68910 assert.equal(moment.duration('P+2W').asSeconds(), moment.duration({w: 2}).asSeconds(), 'python isodate 43');
68911 });
68912
68913 test('ISO 8601 misuse cases', function (assert) {
68914 assert.equal(moment.duration('P').asSeconds(), 0, 'lonely P');
68915 assert.equal(moment.duration('PT').asSeconds(), 0, 'just P and T');
68916 assert.equal(moment.duration('P1H').asSeconds(), 0, 'missing T');
68917 assert.equal(moment.duration('P1D1Y').asSeconds(), 0, 'out of order');
68918 assert.equal(moment.duration('PT.5S').asSeconds(), 0.5, 'accept no leading zero for decimal');
68919 assert.equal(moment.duration('PT1,S').asSeconds(), 1, 'accept trailing decimal separator');
68920 assert.equal(moment.duration('PT1M0,,5S').asSeconds(), 60, 'extra decimal separators are ignored as 0');
68921 });
68922
68923 test('humanize', function (assert) {
68924 moment.locale('en');
68925 assert.equal(moment.duration({seconds: 44}).humanize(), 'a few seconds', '44 seconds = a few seconds');
68926 assert.equal(moment.duration({seconds: 45}).humanize(), 'a minute', '45 seconds = a minute');
68927 assert.equal(moment.duration({seconds: 89}).humanize(), 'a minute', '89 seconds = a minute');
68928 assert.equal(moment.duration({seconds: 90}).humanize(), '2 minutes', '90 seconds = 2 minutes');
68929 assert.equal(moment.duration({minutes: 44}).humanize(), '44 minutes', '44 minutes = 44 minutes');
68930 assert.equal(moment.duration({minutes: 45}).humanize(), 'an hour', '45 minutes = an hour');
68931 assert.equal(moment.duration({minutes: 89}).humanize(), 'an hour', '89 minutes = an hour');
68932 assert.equal(moment.duration({minutes: 90}).humanize(), '2 hours', '90 minutes = 2 hours');
68933 assert.equal(moment.duration({hours: 5}).humanize(), '5 hours', '5 hours = 5 hours');
68934 assert.equal(moment.duration({hours: 21}).humanize(), '21 hours', '21 hours = 21 hours');
68935 assert.equal(moment.duration({hours: 22}).humanize(), 'a day', '22 hours = a day');
68936 assert.equal(moment.duration({hours: 35}).humanize(), 'a day', '35 hours = a day');
68937 assert.equal(moment.duration({hours: 36}).humanize(), '2 days', '36 hours = 2 days');
68938 assert.equal(moment.duration({days: 1}).humanize(), 'a day', '1 day = a day');
68939 assert.equal(moment.duration({days: 5}).humanize(), '5 days', '5 days = 5 days');
68940 assert.equal(moment.duration({weeks: 1}).humanize(), '7 days', '1 week = 7 days');
68941 assert.equal(moment.duration({days: 25}).humanize(), '25 days', '25 days = 25 days');
68942 assert.equal(moment.duration({days: 26}).humanize(), 'a month', '26 days = a month');
68943 assert.equal(moment.duration({days: 30}).humanize(), 'a month', '30 days = a month');
68944 assert.equal(moment.duration({days: 45}).humanize(), 'a month', '45 days = a month');
68945 assert.equal(moment.duration({days: 46}).humanize(), '2 months', '46 days = 2 months');
68946 assert.equal(moment.duration({days: 74}).humanize(), '2 months', '74 days = 2 months');
68947 assert.equal(moment.duration({days: 77}).humanize(), '3 months', '77 days = 3 months');
68948 assert.equal(moment.duration({months: 1}).humanize(), 'a month', '1 month = a month');
68949 assert.equal(moment.duration({months: 5}).humanize(), '5 months', '5 months = 5 months');
68950 assert.equal(moment.duration({days: 344}).humanize(), 'a year', '344 days = a year');
68951 assert.equal(moment.duration({days: 345}).humanize(), 'a year', '345 days = a year');
68952 assert.equal(moment.duration({days: 547}).humanize(), 'a year', '547 days = a year');
68953 assert.equal(moment.duration({days: 548}).humanize(), '2 years', '548 days = 2 years');
68954 assert.equal(moment.duration({years: 1}).humanize(), 'a year', '1 year = a year');
68955 assert.equal(moment.duration({years: 5}).humanize(), '5 years', '5 years = 5 years');
68956 assert.equal(moment.duration(7200000).humanize(), '2 hours', '7200000 = 2 minutes');
68957 });
68958
68959 test('humanize duration with suffix', function (assert) {
68960 moment.locale('en');
68961 assert.equal(moment.duration({seconds: 44}).humanize(true), 'in a few seconds', '44 seconds = a few seconds');
68962 assert.equal(moment.duration({seconds: -44}).humanize(true), 'a few seconds ago', '44 seconds = a few seconds');
68963 assert.equal(moment.duration({seconds: +44}).humanize(true), 'in a few seconds', '44 seconds = a few seconds');
68964 });
68965
68966 test('bubble value up', function (assert) {
68967 assert.equal(moment.duration({milliseconds: 61001}).milliseconds(), 1, '61001 milliseconds has 1 millisecond left over');
68968 assert.equal(moment.duration({milliseconds: 61001}).seconds(), 1, '61001 milliseconds has 1 second left over');
68969 assert.equal(moment.duration({milliseconds: 61001}).minutes(), 1, '61001 milliseconds has 1 minute left over');
68970
68971 assert.equal(moment.duration({minutes: 350}).minutes(), 50, '350 minutes has 50 minutes left over');
68972 assert.equal(moment.duration({minutes: 350}).hours(), 5, '350 minutes has 5 hours left over');
68973 });
68974
68975 test('clipping', function (assert) {
68976 assert.equal(moment.duration({months: 11}).months(), 11, '11 months is 11 months');
68977 assert.equal(moment.duration({months: 11}).years(), 0, '11 months makes no year');
68978 assert.equal(moment.duration({months: 12}).months(), 0, '12 months is 0 months left over');
68979 assert.equal(moment.duration({months: 12}).years(), 1, '12 months makes 1 year');
68980 assert.equal(moment.duration({months: 13}).months(), 1, '13 months is 1 month left over');
68981 assert.equal(moment.duration({months: 13}).years(), 1, '13 months makes 1 year');
68982
68983 assert.equal(moment.duration({days: 30}).days(), 30, '30 days is 30 days');
68984 assert.equal(moment.duration({days: 30}).months(), 0, '30 days makes no month');
68985 assert.equal(moment.duration({days: 31}).days(), 0, '31 days is 0 days left over');
68986 assert.equal(moment.duration({days: 31}).months(), 1, '31 days is a month');
68987 assert.equal(moment.duration({days: 32}).days(), 1, '32 days is 1 day left over');
68988 assert.equal(moment.duration({days: 32}).months(), 1, '32 days is a month');
68989
68990 assert.equal(moment.duration({hours: 23}).hours(), 23, '23 hours is 23 hours');
68991 assert.equal(moment.duration({hours: 23}).days(), 0, '23 hours makes no day');
68992 assert.equal(moment.duration({hours: 24}).hours(), 0, '24 hours is 0 hours left over');
68993 assert.equal(moment.duration({hours: 24}).days(), 1, '24 hours makes 1 day');
68994 assert.equal(moment.duration({hours: 25}).hours(), 1, '25 hours is 1 hour left over');
68995 assert.equal(moment.duration({hours: 25}).days(), 1, '25 hours makes 1 day');
68996 });
68997
68998 test('bubbling consistency', function (assert) {
68999 var days = 0, months = 0, newDays, newMonths, totalDays, d;
69000 for (totalDays = 1; totalDays <= 500; ++totalDays) {
69001 d = moment.duration(totalDays, 'days');
69002 newDays = d.days();
69003 newMonths = d.months() + d.years() * 12;
69004 assert.ok(
69005 (months === newMonths && days + 1 === newDays) ||
69006 (months + 1 === newMonths && newDays === 0),
69007 'consistent total days ' + totalDays +
69008 ' was ' + months + ' ' + days +
69009 ' now ' + newMonths + ' ' + newDays);
69010 days = newDays;
69011 months = newMonths;
69012 }
69013 });
69014
69015 test('effective equivalency', function (assert) {
69016 assert.deepEqual(moment.duration({seconds: 1})._data, moment.duration({milliseconds: 1000})._data, '1 second is the same as 1000 milliseconds');
69017 assert.deepEqual(moment.duration({seconds: 60})._data, moment.duration({minutes: 1})._data, '1 minute is the same as 60 seconds');
69018 assert.deepEqual(moment.duration({minutes: 60})._data, moment.duration({hours: 1})._data, '1 hour is the same as 60 minutes');
69019 assert.deepEqual(moment.duration({hours: 24})._data, moment.duration({days: 1})._data, '1 day is the same as 24 hours');
69020 assert.deepEqual(moment.duration({days: 7})._data, moment.duration({weeks: 1})._data, '1 week is the same as 7 days');
69021 assert.deepEqual(moment.duration({days: 31})._data, moment.duration({months: 1})._data, '1 month is the same as 30 days');
69022 assert.deepEqual(moment.duration({months: 12})._data, moment.duration({years: 1})._data, '1 years is the same as 12 months');
69023 });
69024
69025 test('asGetters', function (assert) {
69026 // 400 years have exactly 146097 days
69027
69028 // years
69029 assert.equal(moment.duration(1, 'year').asYears(), 1, '1 year as years');
96d0d679 69030 assert.equal(moment.duration(1, 'year').asQuarters(), 4, '1 year as quarters');
db71a655
KM
69031 assert.equal(moment.duration(1, 'year').asMonths(), 12, '1 year as months');
69032 assert.equal(moment.duration(400, 'year').asMonths(), 4800, '400 years as months');
69033 assert.equal(moment.duration(1, 'year').asWeeks().toFixed(3), 52.143, '1 year as weeks');
69034 assert.equal(moment.duration(1, 'year').asDays(), 365, '1 year as days');
69035 assert.equal(moment.duration(2, 'year').asDays(), 730, '2 years as days');
69036 assert.equal(moment.duration(3, 'year').asDays(), 1096, '3 years as days');
69037 assert.equal(moment.duration(4, 'year').asDays(), 1461, '4 years as days');
69038 assert.equal(moment.duration(400, 'year').asDays(), 146097, '400 years as days');
69039 assert.equal(moment.duration(1, 'year').asHours(), 8760, '1 year as hours');
69040 assert.equal(moment.duration(1, 'year').asMinutes(), 525600, '1 year as minutes');
69041 assert.equal(moment.duration(1, 'year').asSeconds(), 31536000, '1 year as seconds');
69042 assert.equal(moment.duration(1, 'year').asMilliseconds(), 31536000000, '1 year as milliseconds');
69043
96d0d679
KM
69044 // quarters
69045 assert.equal(moment.duration(1, 'quarter').asYears(), 0.25, '1 quarter as years');
69046 assert.equal(moment.duration(1, 'quarter').asQuarters(), 1, '1 quarter as quarters');
69047 assert.equal(moment.duration(1, 'quarter').asMonths(), 3, '1 quarter as months');
69048 assert.equal(moment.duration(2, 'quarter').asWeeks().toFixed(3), 26.143, '2 month as quarters');
69049 assert.equal(moment.duration(1, 'quarter').asDays(), 91, '1 quarter as days');
69050 assert.equal(moment.duration(2, 'quarter').asDays(), 183, '2 quarter as days');
69051 assert.equal(moment.duration(3, 'quarter').asDays(), 274, '4 quarter as days');
69052 assert.equal(moment.duration(4, 'quarter').asDays(), 365, '4 quarter as days');
69053 assert.equal(moment.duration(1, 'quarter').asHours(), 2184, '1 quarter as hours');
69054 assert.equal(moment.duration(3, 'quarter').asHours(), 6576, '3 quarter as hours');
69055 assert.equal(moment.duration(2, 'quarter').asMinutes(), 263520, '2 quarter as minutes');
69056 assert.equal(moment.duration(3, 'quarter').asSeconds(), 23673600, '3 quarter as seconds');
69057 assert.equal(moment.duration(1, 'quarter').asMilliseconds(), 7862400000, '1 quarter as milliseconds');
69058
db71a655
KM
69059 // months
69060 assert.equal(moment.duration(1, 'month').asYears().toFixed(4), 0.0833, '1 month as years');
96d0d679 69061 assert.equal(moment.duration(6, 'month').asQuarters(), 2, '6 month as quarters');
db71a655
KM
69062 assert.equal(moment.duration(1, 'month').asMonths(), 1, '1 month as months');
69063 assert.equal(moment.duration(1, 'month').asWeeks().toFixed(3), 4.286, '1 month as weeks');
69064 assert.equal(moment.duration(1, 'month').asDays(), 30, '1 month as days');
69065 assert.equal(moment.duration(2, 'month').asDays(), 61, '2 months as days');
69066 assert.equal(moment.duration(3, 'month').asDays(), 91, '3 months as days');
69067 assert.equal(moment.duration(4, 'month').asDays(), 122, '4 months as days');
69068 assert.equal(moment.duration(5, 'month').asDays(), 152, '5 months as days');
69069 assert.equal(moment.duration(6, 'month').asDays(), 183, '6 months as days');
69070 assert.equal(moment.duration(7, 'month').asDays(), 213, '7 months as days');
69071 assert.equal(moment.duration(8, 'month').asDays(), 243, '8 months as days');
69072 assert.equal(moment.duration(9, 'month').asDays(), 274, '9 months as days');
69073 assert.equal(moment.duration(10, 'month').asDays(), 304, '10 months as days');
69074 assert.equal(moment.duration(11, 'month').asDays(), 335, '11 months as days');
69075 assert.equal(moment.duration(12, 'month').asDays(), 365, '12 months as days');
69076 assert.equal(moment.duration(24, 'month').asDays(), 730, '24 months as days');
69077 assert.equal(moment.duration(36, 'month').asDays(), 1096, '36 months as days');
69078 assert.equal(moment.duration(48, 'month').asDays(), 1461, '48 months as days');
69079 assert.equal(moment.duration(4800, 'month').asDays(), 146097, '4800 months as days');
69080 assert.equal(moment.duration(1, 'month').asHours(), 720, '1 month as hours');
69081 assert.equal(moment.duration(1, 'month').asMinutes(), 43200, '1 month as minutes');
69082 assert.equal(moment.duration(1, 'month').asSeconds(), 2592000, '1 month as seconds');
69083 assert.equal(moment.duration(1, 'month').asMilliseconds(), 2592000000, '1 month as milliseconds');
69084
69085 // weeks
96d0d679
KM
69086 assert.equal(moment.duration(1, 'week').asYears().toFixed(4), 0.0192, '1 week as years');
69087 assert.equal(moment.duration(1, 'week').asQuarters().toFixed(4), 0.0767, '1 week as quarters');
69088 assert.equal(moment.duration(1, 'week').asMonths().toFixed(3), 0.230, '1 week as months');
69089 assert.equal(moment.duration(1, 'week').asWeeks(), 1, '1 week as weeks');
69090 assert.equal(moment.duration(1, 'week').asDays(), 7, '1 week as days');
69091 assert.equal(moment.duration(1, 'week').asHours(), 168, '1 week as hours');
69092 assert.equal(moment.duration(1, 'week').asMinutes(), 10080, '1 week as minutes');
69093 assert.equal(moment.duration(1, 'week').asSeconds(), 604800, '1 week as seconds');
69094 assert.equal(moment.duration(1, 'week').asMilliseconds(), 604800000, '1 week as milliseconds');
db71a655
KM
69095
69096 // days
96d0d679
KM
69097 assert.equal(moment.duration(1, 'day').asYears().toFixed(4), 0.0027, '1 day as years');
69098 assert.equal(moment.duration(1, 'day').asQuarters().toFixed(4), 0.0110, '1 day as quarters');
69099 assert.equal(moment.duration(1, 'day').asMonths().toFixed(3), 0.033, '1 day as months');
69100 assert.equal(moment.duration(1, 'day').asWeeks().toFixed(3), 0.143, '1 day as weeks');
69101 assert.equal(moment.duration(1, 'day').asDays(), 1, '1 day as days');
69102 assert.equal(moment.duration(1, 'day').asHours(), 24, '1 day as hours');
69103 assert.equal(moment.duration(1, 'day').asMinutes(), 1440, '1 day as minutes');
69104 assert.equal(moment.duration(1, 'day').asSeconds(), 86400, '1 day as seconds');
69105 assert.equal(moment.duration(1, 'day').asMilliseconds(), 86400000, '1 day as milliseconds');
db71a655
KM
69106
69107 // hours
96d0d679
KM
69108 assert.equal(moment.duration(1, 'hour').asYears().toFixed(6), 0.000114, '1 hour as years');
69109 assert.equal(moment.duration(1, 'hour').asQuarters().toFixed(6), 0.000456, '1 hour as quarters');
69110 assert.equal(moment.duration(1, 'hour').asMonths().toFixed(5), 0.00137, '1 hour as months');
69111 assert.equal(moment.duration(1, 'hour').asWeeks().toFixed(5), 0.00595, '1 hour as weeks');
69112 assert.equal(moment.duration(1, 'hour').asDays().toFixed(4), 0.0417, '1 hour as days');
69113 assert.equal(moment.duration(1, 'hour').asHours(), 1, '1 hour as hours');
69114 assert.equal(moment.duration(1, 'hour').asMinutes(), 60, '1 hour as minutes');
69115 assert.equal(moment.duration(1, 'hour').asSeconds(), 3600, '1 hour as seconds');
69116 assert.equal(moment.duration(1, 'hour').asMilliseconds(), 3600000, '1 hour as milliseconds');
db71a655
KM
69117
69118 // minutes
96d0d679
KM
69119 assert.equal(moment.duration(1, 'minute').asYears().toFixed(8), 0.00000190, '1 minute as years');
69120 assert.equal(moment.duration(1, 'minute').asQuarters().toFixed(8), 0.00000761, '1 minute as quarters');
69121 assert.equal(moment.duration(1, 'minute').asMonths().toFixed(7), 0.0000228, '1 minute as months');
69122 assert.equal(moment.duration(1, 'minute').asWeeks().toFixed(7), 0.0000992, '1 minute as weeks');
69123 assert.equal(moment.duration(1, 'minute').asDays().toFixed(6), 0.000694, '1 minute as days');
69124 assert.equal(moment.duration(1, 'minute').asHours().toFixed(4), 0.0167, '1 minute as hours');
69125 assert.equal(moment.duration(1, 'minute').asMinutes(), 1, '1 minute as minutes');
69126 assert.equal(moment.duration(1, 'minute').asSeconds(), 60, '1 minute as seconds');
69127 assert.equal(moment.duration(1, 'minute').asMilliseconds(), 60000, '1 minute as milliseconds');
db71a655
KM
69128
69129 // seconds
96d0d679
KM
69130 assert.equal(moment.duration(1, 'second').asYears().toFixed(10), 0.0000000317, '1 second as years');
69131 assert.equal(moment.duration(1, 'second').asQuarters().toFixed(10), 0.0000001268, '1 second as quarters');
69132 assert.equal(moment.duration(1, 'second').asMonths().toFixed(9), 0.000000380, '1 second as months');
69133 assert.equal(moment.duration(1, 'second').asWeeks().toFixed(8), 0.00000165, '1 second as weeks');
69134 assert.equal(moment.duration(1, 'second').asDays().toFixed(7), 0.0000116, '1 second as days');
69135 assert.equal(moment.duration(1, 'second').asHours().toFixed(6), 0.000278, '1 second as hours');
69136 assert.equal(moment.duration(1, 'second').asMinutes().toFixed(4), 0.0167, '1 second as minutes');
69137 assert.equal(moment.duration(1, 'second').asSeconds(), 1, '1 second as seconds');
69138 assert.equal(moment.duration(1, 'second').asMilliseconds(), 1000, '1 second as milliseconds');
db71a655
KM
69139
69140 // milliseconds
96d0d679
KM
69141 assert.equal(moment.duration(1, 'millisecond').asYears().toFixed(13), 0.0000000000317, '1 millisecond as years');
69142 assert.equal(moment.duration(1, 'millisecond').asQuarters().toFixed(13), 0.0000000001268, '1 millisecond as quarters');
69143 assert.equal(moment.duration(1, 'millisecond').asMonths().toFixed(12), 0.000000000380, '1 millisecond as months');
69144 assert.equal(moment.duration(1, 'millisecond').asWeeks().toFixed(11), 0.00000000165, '1 millisecond as weeks');
69145 assert.equal(moment.duration(1, 'millisecond').asDays().toFixed(10), 0.0000000116, '1 millisecond as days');
69146 assert.equal(moment.duration(1, 'millisecond').asHours().toFixed(9), 0.000000278, '1 millisecond as hours');
69147 assert.equal(moment.duration(1, 'millisecond').asMinutes().toFixed(7), 0.0000167, '1 millisecond as minutes');
69148 assert.equal(moment.duration(1, 'millisecond').asSeconds(), 0.001, '1 millisecond as seconds');
69149 assert.equal(moment.duration(1, 'millisecond').asMilliseconds(), 1, '1 millisecond as milliseconds');
db71a655
KM
69150 });
69151
69152 test('as getters for small units', function (assert) {
69153 var dS = moment.duration(1, 'milliseconds'),
69154 ds = moment.duration(3, 'seconds'),
69155 dm = moment.duration(13, 'minutes');
69156
69157 // Tests for issue #1867.
69158 // Floating point errors for small duration units were introduced in version 2.8.0.
69159 assert.equal(dS.as('milliseconds'), 1, 'as("milliseconds")');
69160 assert.equal(dS.asMilliseconds(), 1, 'asMilliseconds()');
69161 assert.equal(ds.as('seconds'), 3, 'as("seconds")');
69162 assert.equal(ds.asSeconds(), 3, 'asSeconds()');
69163 assert.equal(dm.as('minutes'), 13, 'as("minutes")');
69164 assert.equal(dm.asMinutes(), 13, 'asMinutes()');
69165 });
69166
69167 test('minutes getter for floating point hours', function (assert) {
69168 // Tests for issue #2978.
69169 // For certain floating point hours, .minutes() getter produced incorrect values due to the rounding errors
69170 assert.equal(moment.duration(2.3, 'h').minutes(), 18, 'minutes()');
69171 assert.equal(moment.duration(4.1, 'h').minutes(), 6, 'minutes()');
69172 });
69173
69174 test('isDuration', function (assert) {
69175 assert.ok(moment.isDuration(moment.duration(12345678)), 'correctly says true');
69176 assert.ok(!moment.isDuration(moment()), 'moment object is not a duration');
69177 assert.ok(!moment.isDuration({milliseconds: 1}), 'plain object is not a duration');
69178 });
69179
69180 test('add', function (assert) {
69181 var d = moment.duration({months: 4, weeks: 3, days: 2});
69182 // for some reason, d._data._months does not get updated; use d._months instead.
69183 assert.equal(d.add(1, 'month')._months, 5, 'Add months');
69184 assert.equal(d.add(5, 'days')._days, 28, 'Add days');
69185 assert.equal(d.add(10000)._milliseconds, 10000, 'Add milliseconds');
69186 assert.equal(d.add({h: 23, m: 59})._milliseconds, 23 * 60 * 60 * 1000 + 59 * 60 * 1000 + 10000, 'Add hour:minute');
69187 });
69188
69189 test('add to moment', function (assert) {
69190 var d = moment.duration({months: 1, seconds: -1});
69191 var m = moment('2017-03-01').add(d);
69192 assert.equal(m.month(), 2, 'Adds months before time');
69193 assert.equal(m.date(), 31, 'Adds time after months');
69194 });
69195
69196 test('add and bubble', function (assert) {
69197 var d;
69198
69199 assert.equal(moment.duration(1, 'second').add(1000, 'milliseconds').seconds(), 2, 'Adding milliseconds should bubble up to seconds');
69200 assert.equal(moment.duration(1, 'minute').add(60, 'second').minutes(), 2, 'Adding seconds should bubble up to minutes');
69201 assert.equal(moment.duration(1, 'hour').add(60, 'minutes').hours(), 2, 'Adding minutes should bubble up to hours');
69202 assert.equal(moment.duration(1, 'day').add(24, 'hours').days(), 2, 'Adding hours should bubble up to days');
69203
69204 d = moment.duration(-1, 'day').add(1, 'hour');
69205 assert.equal(d.hours(), -23, '-1 day + 1 hour == -23 hour (component)');
69206 assert.equal(d.asHours(), -23, '-1 day + 1 hour == -23 hours');
69207
69208 d = moment.duration(+1, 'day').add(1, 'hour');
69209 assert.equal(d.hours(), 1, '1 day + 1 hour == 1 hour (component)');
69210 assert.equal(d.asHours(), 25, '1 day + 1 hour == 25 hour');
69211
69212 d = moment.duration(-1, 'year').add(1, 'day');
69213 assert.equal(d.days(), -30, '- 1 year + 1 day == -30 days (component)');
69214 assert.equal(d.months(), -11, '- 1 year + 1 day == -11 months (component)');
69215 assert.equal(d.years(), 0, '- 1 year + 1 day == 0 years (component)');
69216 assert.equal(d.asDays(), -364, '- 1 year + 1 day == -364 days');
69217
69218 d = moment.duration(+1, 'year').add(1, 'day');
69219 assert.equal(d.days(), 1, '+ 1 year + 1 day == 1 days (component)');
69220 assert.equal(d.months(), 0, '+ 1 year + 1 day == 0 month (component)');
69221 assert.equal(d.years(), 1, '+ 1 year + 1 day == 1 year (component)');
69222 assert.equal(d.asDays(), 366, '+ 1 year + 1 day == +366 day');
69223
69224 d = moment.duration(-1, 'year').add(1, 'hour');
69225 assert.equal(d.hours(), -23, '- 1 year + 1 hour == -23 hours (component)');
69226 assert.equal(d.days(), -30, '- 1 year + 1 hour == -30 days (component)');
69227 assert.equal(d.months(), -11, '- 1 year + 1 hour == -11 months (component)');
69228 assert.equal(d.years(), 0, '- 1 year + 1 hour == 0 years (component)');
69229
69230 d = moment.duration(+1, 'year').add(1, 'hour');
69231 assert.equal(d.hours(), 1, '+ 1 year + 1 hour == 1 hour (component)');
69232 assert.equal(d.days(), 0, '+ 1 year + 1 hour == 1 day (component)');
69233 assert.equal(d.months(), 0, '+ 1 year + 1 hour == 1 month (component)');
69234 assert.equal(d.years(), 1, '+ 1 year + 1 hour == 1 year (component)');
69235 });
69236
69237 test('subtract and bubble', function (assert) {
69238 var d;
69239
69240 assert.equal(moment.duration(2, 'second').subtract(1000, 'milliseconds').seconds(), 1, 'Subtracting milliseconds should bubble up to seconds');
69241 assert.equal(moment.duration(2, 'minute').subtract(60, 'second').minutes(), 1, 'Subtracting seconds should bubble up to minutes');
69242 assert.equal(moment.duration(2, 'hour').subtract(60, 'minutes').hours(), 1, 'Subtracting minutes should bubble up to hours');
69243 assert.equal(moment.duration(2, 'day').subtract(24, 'hours').days(), 1, 'Subtracting hours should bubble up to days');
69244
69245 d = moment.duration(1, 'day').subtract(1, 'hour');
69246 assert.equal(d.hours(), 23, '1 day - 1 hour == 23 hour (component)');
69247 assert.equal(d.asHours(), 23, '1 day - 1 hour == 23 hours');
69248
69249 d = moment.duration(1, 'year').subtract(1, 'day');
69250 assert.equal(d.days(), 30, '1 year - 1 day == 30 days (component)');
69251 assert.equal(d.months(), 11, '1 year - 1 day == 11 months (component)');
69252 assert.equal(d.years(), 0, '1 year - 1 day == 0 years (component)');
69253 assert.equal(d.asDays(), 364, '1 year - 1 day == 364 days');
69254
69255 d = moment.duration(1, 'year').subtract(1, 'hour');
69256 assert.equal(d.hours(), 23, '1 year - 1 hour == 23 hours (component)');
69257 assert.equal(d.days(), 30, '1 year - 1 hour == 30 days (component)');
69258 assert.equal(d.months(), 11, '1 year - 1 hour == 11 months (component)');
69259 assert.equal(d.years(), 0, '1 year - 1 hour == 0 years (component)');
73f3c911 69260 });
d6651c21 69261
db71a655
KM
69262 test('subtract', function (assert) {
69263 var d = moment.duration({months: 2, weeks: 2, days: 0, hours: 5});
69264 // for some reason, d._data._months does not get updated; use d._months instead.
69265 assert.equal(d.subtract(1, 'months')._months, 1, 'Subtract months');
69266 assert.equal(d.subtract(14, 'days')._days, 0, 'Subtract days');
69267 assert.equal(d.subtract(10000)._milliseconds, 5 * 60 * 60 * 1000 - 10000, 'Subtract milliseconds');
69268 assert.equal(d.subtract({h: 1, m: 59})._milliseconds, 3 * 60 * 60 * 1000 + 1 * 60 * 1000 - 10000, 'Subtract hour:minute');
69269 });
d6651c21 69270
db71a655
KM
69271 test('JSON.stringify duration', function (assert) {
69272 var d = moment.duration(1024, 'h');
d6651c21 69273
db71a655
KM
69274 assert.equal(JSON.stringify(d), '"' + d.toISOString() + '"', 'JSON.stringify on duration should return ISO string');
69275 });
d6651c21 69276
db71a655
KM
69277 test('duration plugins', function (assert) {
69278 var durationObject = moment.duration();
69279 moment.duration.fn.foo = function (arg) {
69280 assert.equal(this, durationObject);
69281 assert.equal(arg, 5);
69282 };
69283 durationObject.foo(5);
73f3c911
IC
69284 });
69285
db71a655 69286})));
d6651c21 69287
b135bf1a 69288
db71a655
KM
69289;(function (global, factory) {
69290 typeof exports === 'object' && typeof module !== 'undefined'
69291 && typeof require === 'function' ? factory(require('../../moment')) :
69292 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
69293 factory(global.moment)
69294}(this, (function (moment) { 'use strict';
69295
69296 function each(array, callback) {
69297 var i;
69298 for (i = 0; i < array.length; i++) {
69299 callback(array[i], i, array);
73f3c911 69300 }
db71a655 69301 }
516f5f67 69302
db71a655
KM
69303 function setupDeprecationHandler(test, moment$$1, scope) {
69304 test._expectedDeprecations = null;
69305 test._observedDeprecations = null;
69306 test._oldSupress = moment$$1.suppressDeprecationWarnings;
69307 moment$$1.suppressDeprecationWarnings = true;
69308 test.expectedDeprecations = function () {
69309 test._expectedDeprecations = arguments;
69310 test._observedDeprecations = [];
69311 };
69312 moment$$1.deprecationHandler = function (name, msg) {
69313 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
69314 if (deprecationId === -1) {
69315 throw new Error('Unexpected deprecation thrown name=' +
69316 name + ' msg=' + msg);
516f5f67 69317 }
db71a655
KM
69318 test._observedDeprecations[deprecationId] = 1;
69319 };
516f5f67
IC
69320 }
69321
db71a655
KM
69322 function teardownDeprecationHandler(test, moment$$1, scope) {
69323 moment$$1.suppressDeprecationWarnings = test._oldSupress;
69324
69325 if (test._expectedDeprecations != null) {
69326 var missedDeprecations = [];
69327 each(test._expectedDeprecations, function (deprecationPattern, id) {
69328 if (test._observedDeprecations[id] !== 1) {
69329 missedDeprecations.push(deprecationPattern);
69330 }
69331 });
69332 if (missedDeprecations.length !== 0) {
69333 throw new Error('Expected deprecation warnings did not happen: ' +
69334 missedDeprecations.join(' '));
69335 }
69336 }
73f3c911 69337 }
db71a655
KM
69338
69339 function matchedDeprecation(name, msg, deprecations) {
69340 if (deprecations == null) {
69341 return -1;
516f5f67 69342 }
db71a655
KM
69343 for (var i = 0; i < deprecations.length; ++i) {
69344 if (name != null && name === deprecations[i]) {
69345 return i;
69346 }
69347 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
69348 return i;
69349 }
516f5f67 69350 }
db71a655 69351 return -1;
73f3c911 69352 }
516f5f67 69353
db71a655 69354 /*global QUnit:false*/
516f5f67 69355
db71a655 69356 var test = QUnit.test;
516f5f67 69357
db71a655
KM
69358 function module$1 (name, lifecycle) {
69359 QUnit.module(name, {
c58511b9 69360 beforeEach : function () {
db71a655
KM
69361 moment.locale('en');
69362 moment.createFromInputFallback = function (config) {
69363 throw new Error('input not handled by moment: ' + config._i);
69364 };
69365 setupDeprecationHandler(test, moment, 'core');
69366 if (lifecycle && lifecycle.setup) {
69367 lifecycle.setup();
69368 }
69369 },
c58511b9 69370 afterEach : function () {
db71a655
KM
69371 teardownDeprecationHandler(test, moment, 'core');
69372 if (lifecycle && lifecycle.teardown) {
69373 lifecycle.teardown();
69374 }
73f3c911 69375 }
db71a655
KM
69376 });
69377 }
73f3c911 69378
db71a655 69379 module$1('duration from moments');
516f5f67 69380
db71a655
KM
69381 test('pure year diff', function (assert) {
69382 var m1 = moment('2012-01-01T00:00:00.000Z'),
69383 m2 = moment('2013-01-01T00:00:00.000Z');
516f5f67 69384
db71a655
KM
69385 assert.equal(moment.duration({from: m1, to: m2}).as('years'), 1, 'year moment difference');
69386 assert.equal(moment.duration({from: m2, to: m1}).as('years'), -1, 'negative year moment difference');
69387 });
b135bf1a 69388
db71a655
KM
69389 test('month and day diff', function (assert) {
69390 var m1 = moment('2012-01-15T00:00:00.000Z'),
69391 m2 = moment('2012-02-17T00:00:00.000Z'),
69392 d = moment.duration({from: m1, to: m2});
516f5f67 69393
db71a655
KM
69394 assert.equal(d.get('days'), 2);
69395 assert.equal(d.get('months'), 1);
69396 });
516f5f67 69397
db71a655
KM
69398 test('day diff, separate months', function (assert) {
69399 var m1 = moment('2012-01-15T00:00:00.000Z'),
69400 m2 = moment('2012-02-13T00:00:00.000Z'),
69401 d = moment.duration({from: m1, to: m2});
73f3c911 69402
db71a655 69403 assert.equal(d.as('days'), 29);
73f3c911
IC
69404 });
69405
db71a655
KM
69406 test('hour diff', function (assert) {
69407 var m1 = moment('2012-01-15T17:00:00.000Z'),
69408 m2 = moment('2012-01-16T03:00:00.000Z'),
69409 d = moment.duration({from: m1, to: m2});
516f5f67 69410
db71a655 69411 assert.equal(d.as('hours'), 10);
73f3c911 69412 });
516f5f67 69413
db71a655
KM
69414 test('minute diff', function (assert) {
69415 var m1 = moment('2012-01-15T17:45:00.000Z'),
69416 m2 = moment('2012-01-16T03:15:00.000Z'),
69417 d = moment.duration({from: m1, to: m2});
69418
69419 assert.equal(d.as('hours'), 9.5);
73f3c911 69420 });
b135bf1a 69421
db71a655 69422})));
b135bf1a 69423
b135bf1a 69424
db71a655
KM
69425;(function (global, factory) {
69426 typeof exports === 'object' && typeof module !== 'undefined'
69427 && typeof require === 'function' ? factory(require('../../moment')) :
69428 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
69429 factory(global.moment)
69430}(this, (function (moment) { 'use strict';
d6651c21 69431
db71a655
KM
69432 function each(array, callback) {
69433 var i;
69434 for (i = 0; i < array.length; i++) {
69435 callback(array[i], i, array);
73f3c911 69436 }
db71a655 69437 }
d6651c21 69438
db71a655
KM
69439 function setupDeprecationHandler(test, moment$$1, scope) {
69440 test._expectedDeprecations = null;
69441 test._observedDeprecations = null;
69442 test._oldSupress = moment$$1.suppressDeprecationWarnings;
69443 moment$$1.suppressDeprecationWarnings = true;
69444 test.expectedDeprecations = function () {
69445 test._expectedDeprecations = arguments;
69446 test._observedDeprecations = [];
69447 };
69448 moment$$1.deprecationHandler = function (name, msg) {
69449 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
69450 if (deprecationId === -1) {
69451 throw new Error('Unexpected deprecation thrown name=' +
69452 name + ' msg=' + msg);
69453 }
69454 test._observedDeprecations[deprecationId] = 1;
69455 };
69456 }
516f5f67 69457
db71a655
KM
69458 function teardownDeprecationHandler(test, moment$$1, scope) {
69459 moment$$1.suppressDeprecationWarnings = test._oldSupress;
c74a101d 69460
db71a655
KM
69461 if (test._expectedDeprecations != null) {
69462 var missedDeprecations = [];
69463 each(test._expectedDeprecations, function (deprecationPattern, id) {
69464 if (test._observedDeprecations[id] !== 1) {
69465 missedDeprecations.push(deprecationPattern);
69466 }
69467 });
69468 if (missedDeprecations.length !== 0) {
69469 throw new Error('Expected deprecation warnings did not happen: ' +
69470 missedDeprecations.join(' '));
516f5f67 69471 }
73f3c911 69472 }
516f5f67
IC
69473 }
69474
db71a655
KM
69475 function matchedDeprecation(name, msg, deprecations) {
69476 if (deprecations == null) {
69477 return -1;
516f5f67 69478 }
db71a655
KM
69479 for (var i = 0; i < deprecations.length; ++i) {
69480 if (name != null && name === deprecations[i]) {
69481 return i;
69482 }
69483 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
69484 return i;
69485 }
516f5f67 69486 }
db71a655 69487 return -1;
73f3c911 69488 }
516f5f67 69489
db71a655 69490 /*global QUnit:false*/
516f5f67 69491
db71a655 69492 var test = QUnit.test;
516f5f67 69493
db71a655
KM
69494 function module$1 (name, lifecycle) {
69495 QUnit.module(name, {
c58511b9 69496 beforeEach : function () {
db71a655
KM
69497 moment.locale('en');
69498 moment.createFromInputFallback = function (config) {
69499 throw new Error('input not handled by moment: ' + config._i);
69500 };
69501 setupDeprecationHandler(test, moment, 'core');
69502 if (lifecycle && lifecycle.setup) {
69503 lifecycle.setup();
69504 }
69505 },
c58511b9 69506 afterEach : function () {
db71a655
KM
69507 teardownDeprecationHandler(test, moment, 'core');
69508 if (lifecycle && lifecycle.teardown) {
69509 lifecycle.teardown();
69510 }
4710a793 69511 }
db71a655
KM
69512 });
69513 }
69514
69515 module$1('invalid');
69516
69517 test('invalid duration', function (assert) {
69518 var m = moment.duration.invalid(); // should be invalid
69519 assert.equal(m.isValid(), false);
69520 assert.ok(isNaN(m.valueOf()));
4710a793 69521 });
4710a793 69522
db71a655
KM
69523 test('valid duration', function (assert) {
69524 var m = moment.duration({d: null}); // should be valid, for now
69525 assert.equal(m.isValid(), true);
69526 assert.equal(m.valueOf(), 0);
69527 });
4710a793 69528
db71a655
KM
69529 test('invalid duration - only smallest unit can have decimal', function (assert) {
69530 var m = moment.duration({'days': 3.5, 'hours': 1.1}); // should be invalid
69531 assert.equal(m.isValid(), false);
69532 assert.ok(isNaN(m.valueOf())); // .valueOf() returns NaN for invalid durations
69533 });
4710a793 69534
db71a655
KM
69535 test('valid duration - smallest unit can have decimal', function (assert) {
69536 var m = moment.duration({'days': 3, 'hours': 1.1}); // should be valid
69537 assert.equal(m.isValid(), true);
69538 assert.equal(m.asHours(), 73.1);
69539 });
4710a793 69540
db71a655
KM
69541 test('invalid duration with two arguments', function (assert) {
69542 var m = moment.duration(NaN, 'days');
69543 assert.equal(m.isValid(), false);
69544 assert.ok(isNaN(m.valueOf()));
69545 });
69546
69547 test('invalid duration operations', function (assert) {
69548 var invalids = [
69549 moment.duration(NaN),
69550 moment.duration(NaN, 'days'),
69551 moment.duration.invalid()
69552 ],
69553 i,
69554 invalid,
69555 valid = moment.duration();
69556
69557 for (i = 0; i < invalids.length; ++i) {
69558 invalid = invalids[i];
69559
69560 assert.ok(!invalid.add(5, 'hours').isValid(), 'invalid.add is invalid; i=' + i);
69561 assert.ok(!invalid.subtract(30, 'days').isValid(), 'invalid.subtract is invalid; i=' + i);
69562 assert.ok(!invalid.abs().isValid(), 'invalid.abs is invalid; i=' + i);
69563 assert.ok(isNaN(invalid.as('years')), 'invalid.as is NaN; i=' + i);
69564 assert.ok(isNaN(invalid.asMilliseconds()), 'invalid.asMilliseconds is NaN; i=' + i);
69565 assert.ok(isNaN(invalid.asSeconds()), 'invalid.asSeconds is NaN; i=' + i);
69566 assert.ok(isNaN(invalid.asMinutes()), 'invalid.asMinutes is NaN; i=' + i);
69567 assert.ok(isNaN(invalid.asHours()), 'invalid.asHours is NaN; i=' + i);
69568 assert.ok(isNaN(invalid.asDays()), 'invalid.asDays is NaN; i=' + i);
69569 assert.ok(isNaN(invalid.asWeeks()), 'invalid.asWeeks is NaN; i=' + i);
69570 assert.ok(isNaN(invalid.asMonths()), 'invalid.asMonths is NaN; i=' + i);
96d0d679 69571 assert.ok(isNaN(invalid.asQuarters()), 'invalid.asQuarters is NaN; i=' + i);
db71a655
KM
69572 assert.ok(isNaN(invalid.asYears()), 'invalid.asYears is NaN; i=' + i);
69573 assert.ok(isNaN(invalid.valueOf()), 'invalid.valueOf is NaN; i=' + i);
69574 assert.ok(isNaN(invalid.get('hours')), 'invalid.get is NaN; i=' + i);
69575
69576 assert.ok(isNaN(invalid.milliseconds()), 'invalid.milliseconds is NaN; i=' + i);
69577 assert.ok(isNaN(invalid.seconds()), 'invalid.seconds is NaN; i=' + i);
69578 assert.ok(isNaN(invalid.minutes()), 'invalid.minutes is NaN; i=' + i);
69579 assert.ok(isNaN(invalid.hours()), 'invalid.hours is NaN; i=' + i);
69580 assert.ok(isNaN(invalid.days()), 'invalid.days is NaN; i=' + i);
69581 assert.ok(isNaN(invalid.weeks()), 'invalid.weeks is NaN; i=' + i);
69582 assert.ok(isNaN(invalid.months()), 'invalid.months is NaN; i=' + i);
69583 assert.ok(isNaN(invalid.years()), 'invalid.years is NaN; i=' + i);
69584
69585 assert.equal(invalid.humanize(),
69586 invalid.localeData().invalidDate(),
69587 'invalid.humanize is localized invalid duration string; i=' + i);
69588 assert.equal(invalid.toISOString(),
69589 invalid.localeData().invalidDate(),
69590 'invalid.toISOString is localized invalid duration string; i=' + i);
69591 assert.equal(invalid.toString(),
69592 invalid.localeData().invalidDate(),
69593 'invalid.toString is localized invalid duration string; i=' + i);
69594 assert.equal(invalid.toJSON(), invalid.localeData().invalidDate(), 'invalid.toJSON is null; i=' + i);
69595 assert.equal(invalid.locale(), 'en', 'invalid.locale; i=' + i);
69596 assert.equal(invalid.localeData()._abbr, 'en', 'invalid.localeData()._abbr; i=' + i);
69597 }
69598 });
4710a793
IC
69599
69600})));
69601
69602
69603;(function (global, factory) {
69604 typeof exports === 'object' && typeof module !== 'undefined'
69605 && typeof require === 'function' ? factory(require('../../moment')) :
69606 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
69607 factory(global.moment)
69608}(this, (function (moment) { 'use strict';
69609
db71a655
KM
69610 function each(array, callback) {
69611 var i;
69612 for (i = 0; i < array.length; i++) {
69613 callback(array[i], i, array);
69614 }
4710a793 69615 }
4710a793 69616
db71a655
KM
69617 function setupDeprecationHandler(test, moment$$1, scope) {
69618 test._expectedDeprecations = null;
69619 test._observedDeprecations = null;
69620 test._oldSupress = moment$$1.suppressDeprecationWarnings;
69621 moment$$1.suppressDeprecationWarnings = true;
69622 test.expectedDeprecations = function () {
69623 test._expectedDeprecations = arguments;
69624 test._observedDeprecations = [];
69625 };
69626 moment$$1.deprecationHandler = function (name, msg) {
69627 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
69628 if (deprecationId === -1) {
69629 throw new Error('Unexpected deprecation thrown name=' +
69630 name + ' msg=' + msg);
4710a793 69631 }
db71a655
KM
69632 test._observedDeprecations[deprecationId] = 1;
69633 };
4710a793 69634 }
4710a793 69635
db71a655
KM
69636 function teardownDeprecationHandler(test, moment$$1, scope) {
69637 moment$$1.suppressDeprecationWarnings = test._oldSupress;
4710a793 69638
db71a655
KM
69639 if (test._expectedDeprecations != null) {
69640 var missedDeprecations = [];
69641 each(test._expectedDeprecations, function (deprecationPattern, id) {
69642 if (test._observedDeprecations[id] !== 1) {
69643 missedDeprecations.push(deprecationPattern);
69644 }
69645 });
69646 if (missedDeprecations.length !== 0) {
69647 throw new Error('Expected deprecation warnings did not happen: ' +
69648 missedDeprecations.join(' '));
69649 }
69650 }
69651 }
69652
69653 function matchedDeprecation(name, msg, deprecations) {
69654 if (deprecations == null) {
69655 return -1;
69656 }
69657 for (var i = 0; i < deprecations.length; ++i) {
69658 if (name != null && name === deprecations[i]) {
69659 return i;
69660 }
69661 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
69662 return i;
69663 }
4710a793 69664 }
db71a655
KM
69665 return -1;
69666 }
69667
69668 /*global QUnit:false*/
69669
69670 var test = QUnit.test;
69671
db71a655
KM
69672 function module$1 (name, lifecycle) {
69673 QUnit.module(name, {
c58511b9 69674 beforeEach : function () {
db71a655
KM
69675 moment.locale('en');
69676 moment.createFromInputFallback = function (config) {
69677 throw new Error('input not handled by moment: ' + config._i);
69678 };
69679 setupDeprecationHandler(test, moment, 'core');
69680 if (lifecycle && lifecycle.setup) {
69681 lifecycle.setup();
69682 }
69683 },
c58511b9 69684 afterEach : function () {
db71a655
KM
69685 teardownDeprecationHandler(test, moment, 'core');
69686 if (lifecycle && lifecycle.teardown) {
69687 lifecycle.teardown();
69688 }
69689 }
69690 });
69691 }
69692
69693 module$1('format');
69694
69695 test('format using constants', function (assert) {
b8f4fe2b
KM
69696 var m = moment('2016-01-02T23:40:40.678');
69697 assert.equal(m.format(moment.HTML5_FMT.DATETIME_LOCAL), '2016-01-02T23:40', 'datetime local format constant');
69698 assert.equal(m.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS), '2016-01-02T23:40:40', 'datetime local format constant');
69699 assert.equal(m.format(moment.HTML5_FMT.DATETIME_LOCAL_MS), '2016-01-02T23:40:40.678', 'datetime local format constant with seconds and millis');
69700 assert.equal(m.format(moment.HTML5_FMT.DATE), '2016-01-02', 'date format constant');
db71a655
KM
69701 assert.equal(m.format(moment.HTML5_FMT.TIME), '23:40', 'time format constant');
69702 assert.equal(m.format(moment.HTML5_FMT.TIME_SECONDS), '23:40:40', 'time format constant with seconds');
69703 assert.equal(m.format(moment.HTML5_FMT.TIME_MS), '23:40:40.678', 'time format constant with seconds and millis');
b8f4fe2b
KM
69704 assert.equal(m.format(moment.HTML5_FMT.WEEK), '2015-W53', 'week format constant');
69705 assert.equal(m.format(moment.HTML5_FMT.MONTH), '2016-01', 'month format constant');
4710a793
IC
69706 });
69707
db71a655
KM
69708 test('format YY', function (assert) {
69709 var b = moment(new Date(2009, 1, 14, 15, 25, 50, 125));
69710 assert.equal(b.format('YY'), '09', 'YY ---> 09');
69711 });
69712
69713 test('format escape brackets', function (assert) {
69714 moment.locale('en');
69715
69716 var b = moment(new Date(2009, 1, 14, 15, 25, 50, 125));
69717 assert.equal(b.format('[day]'), 'day', 'Single bracket');
69718 assert.equal(b.format('[day] YY [YY]'), 'day 09 YY', 'Double bracket');
69719 assert.equal(b.format('[YY'), '[09', 'Un-ended bracket');
69720 assert.equal(b.format('[[YY]]'), '[YY]', 'Double nested brackets');
69721 assert.equal(b.format('[[]'), '[', 'Escape open bracket');
69722 assert.equal(b.format('[Last]'), 'Last', 'localized tokens');
69723 assert.equal(b.format('[L] L'), 'L 02/14/2009', 'localized tokens with escaped localized tokens');
69724 assert.equal(b.format('[L LL LLL LLLL aLa]'), 'L LL LLL LLLL aLa', 'localized tokens with escaped localized tokens');
69725 assert.equal(b.format('[LLL] LLL'), 'LLL February 14, 2009 3:25 PM', 'localized tokens with escaped localized tokens (recursion)');
69726 assert.equal(b.format('YYYY[\n]DD[\n]'), '2009\n14\n', 'Newlines');
69727 });
69728
69729 test('handle negative years', function (assert) {
69730 moment.locale('en');
69731 assert.equal(moment.utc().year(-1).format('YY'), '-01', 'YY with negative year');
69732 assert.equal(moment.utc().year(-1).format('YYYY'), '-0001', 'YYYY with negative year');
69733 assert.equal(moment.utc().year(-12).format('YY'), '-12', 'YY with negative year');
69734 assert.equal(moment.utc().year(-12).format('YYYY'), '-0012', 'YYYY with negative year');
69735 assert.equal(moment.utc().year(-123).format('YY'), '-23', 'YY with negative year');
69736 assert.equal(moment.utc().year(-123).format('YYYY'), '-0123', 'YYYY with negative year');
69737 assert.equal(moment.utc().year(-1234).format('YY'), '-34', 'YY with negative year');
69738 assert.equal(moment.utc().year(-1234).format('YYYY'), '-1234', 'YYYY with negative year');
69739 assert.equal(moment.utc().year(-12345).format('YY'), '-45', 'YY with negative year');
69740 assert.equal(moment.utc().year(-12345).format('YYYY'), '-12345', 'YYYY with negative year');
69741 });
69742
69743 test('format milliseconds', function (assert) {
69744 var b = moment(new Date(2009, 1, 14, 15, 25, 50, 123));
69745 assert.equal(b.format('S'), '1', 'Deciseconds');
69746 assert.equal(b.format('SS'), '12', 'Centiseconds');
69747 assert.equal(b.format('SSS'), '123', 'Milliseconds');
69748 b.milliseconds(789);
69749 assert.equal(b.format('S'), '7', 'Deciseconds');
69750 assert.equal(b.format('SS'), '78', 'Centiseconds');
69751 assert.equal(b.format('SSS'), '789', 'Milliseconds');
69752 });
69753
69754 test('format timezone', function (assert) {
69755 var b = moment(new Date(2010, 1, 14, 15, 25, 50, 125));
69756 assert.ok(b.format('Z').match(/^[\+\-]\d\d:\d\d$/), b.format('Z') + ' should be something like \'+07:30\'');
69757 assert.ok(b.format('ZZ').match(/^[\+\-]\d{4}$/), b.format('ZZ') + ' should be something like \'+0700\'');
69758 });
69759
69760 test('format multiple with utc offset', function (assert) {
69761 var b = moment('2012-10-08 -1200', ['YYYY-MM-DD HH:mm ZZ', 'YYYY-MM-DD ZZ', 'YYYY-MM-DD']);
69762 assert.equal(b.format('YYYY-MM'), '2012-10', 'Parsing multiple formats should not crash with different sized formats');
69763 });
69764
69765 test('isDST', function (assert) {
69766 var janOffset = new Date(2011, 0, 1).getTimezoneOffset(),
69767 julOffset = new Date(2011, 6, 1).getTimezoneOffset(),
69768 janIsDst = janOffset < julOffset,
69769 julIsDst = julOffset < janOffset,
69770 jan1 = moment([2011]),
69771 jul1 = moment([2011, 6]);
69772
69773 if (janIsDst && julIsDst) {
69774 assert.ok(0, 'January and July cannot both be in DST');
69775 assert.ok(0, 'January and July cannot both be in DST');
69776 } else if (janIsDst) {
69777 assert.ok(jan1.isDST(), 'January 1 is DST');
69778 assert.ok(!jul1.isDST(), 'July 1 is not DST');
69779 } else if (julIsDst) {
69780 assert.ok(!jan1.isDST(), 'January 1 is not DST');
69781 assert.ok(jul1.isDST(), 'July 1 is DST');
69782 } else {
69783 assert.ok(!jan1.isDST(), 'January 1 is not DST');
69784 assert.ok(!jul1.isDST(), 'July 1 is not DST');
4710a793
IC
69785 }
69786 });
69787
db71a655
KM
69788 test('unix timestamp', function (assert) {
69789 var m = moment('1234567890.123', 'X');
69790 assert.equal(m.format('X'), '1234567890', 'unix timestamp without milliseconds');
69791 assert.equal(m.format('X.S'), '1234567890.1', 'unix timestamp with deciseconds');
69792 assert.equal(m.format('X.SS'), '1234567890.12', 'unix timestamp with centiseconds');
69793 assert.equal(m.format('X.SSS'), '1234567890.123', 'unix timestamp with milliseconds');
69794
69795 m = moment(1234567890.123, 'X');
69796 assert.equal(m.format('X'), '1234567890', 'unix timestamp as integer');
69797 });
69798
69799 test('unix offset milliseconds', function (assert) {
69800 var m = moment('1234567890123', 'x');
69801 assert.equal(m.format('x'), '1234567890123', 'unix offset in milliseconds');
69802
69803 m = moment(1234567890123, 'x');
69804 assert.equal(m.format('x'), '1234567890123', 'unix offset in milliseconds as integer');
69805 });
69806
69807 test('utcOffset sanity checks', function (assert) {
69808 assert.equal(moment().utcOffset() % 15, 0,
69809 'utc offset should be a multiple of 15 (was ' + moment().utcOffset() + ')');
69810
69811 assert.equal(moment().utcOffset(), -(new Date()).getTimezoneOffset(),
69812 'utcOffset should return the opposite of getTimezoneOffset');
69813 });
69814
69815 test('default format', function (assert) {
69816 var isoRegex = /\d{4}.\d\d.\d\dT\d\d.\d\d.\d\d[\+\-]\d\d:\d\d/;
69817 assert.ok(isoRegex.exec(moment().format()), 'default format (' + moment().format() + ') should match ISO');
4710a793
IC
69818 });
69819
db71a655
KM
69820 test('default UTC format', function (assert) {
69821 var isoRegex = /\d{4}.\d\d.\d\dT\d\d.\d\d.\d\dZ/;
69822 assert.ok(isoRegex.exec(moment.utc().format()), 'default UTC format (' + moment.utc().format() + ') should match ISO');
4710a793
IC
69823 });
69824
db71a655
KM
69825 test('toJSON', function (assert) {
69826 var supportsJson = typeof JSON !== 'undefined' && JSON.stringify && JSON.stringify.call,
69827 date = moment('2012-10-09T21:30:40.678+0100');
4710a793 69828
db71a655 69829 assert.equal(date.toJSON(), '2012-10-09T20:30:40.678Z', 'should output ISO8601 on moment.fn.toJSON');
4710a793 69830
db71a655
KM
69831 if (supportsJson) {
69832 assert.equal(JSON.stringify({
69833 date : date
69834 }), '{"date":"2012-10-09T20:30:40.678Z"}', 'should output ISO8601 on JSON.stringify');
4710a793 69835 }
db71a655 69836 });
4710a793 69837
db71a655
KM
69838 test('toISOString', function (assert) {
69839 var date = moment.utc('2012-10-09T20:30:40.678');
69840
69841 assert.equal(date.toISOString(), '2012-10-09T20:30:40.678Z', 'should output ISO8601 on moment.fn.toISOString');
69842
69843 // big years
69844 date = moment.utc('+020123-10-09T20:30:40.678');
69845 assert.equal(date.toISOString(), '+020123-10-09T20:30:40.678Z', 'ISO8601 format on big positive year');
69846 // negative years
69847 date = moment.utc('-000001-10-09T20:30:40.678');
69848 assert.equal(date.toISOString(), '-000001-10-09T20:30:40.678Z', 'ISO8601 format on negative year');
69849 // big negative years
69850 date = moment.utc('-020123-10-09T20:30:40.678');
69851 assert.equal(date.toISOString(), '-020123-10-09T20:30:40.678Z', 'ISO8601 format on big negative year');
69852
69853 //invalid dates
69854 date = moment.utc('2017-12-32');
69855 assert.equal(date.toISOString(), null, 'An invalid date to iso string is null');
4710a793
IC
69856 });
69857
db71a655
KM
69858 test('toISOString without UTC conversion', function (assert) {
69859 var date = moment.utc('2016-12-31T19:53:45.678').utcOffset('+05:30');
4710a793 69860
db71a655 69861 assert.equal(date.toISOString(true), '2017-01-01T01:23:45.678+05:30', 'should output ISO8601 on moment.fn.toISOString');
4710a793 69862
db71a655
KM
69863 // big years
69864 date = moment.utc('+020122-12-31T19:53:45.678').utcOffset('+05:30');
69865 assert.equal(date.toISOString(true), '+020123-01-01T01:23:45.678+05:30', 'ISO8601 format on big positive year');
69866 // negative years
69867 date = moment.utc('-000002-12-31T19:53:45.678').utcOffset('+05:30');
69868 assert.equal(date.toISOString(true), '-000001-01-01T01:23:45.678+05:30', 'ISO8601 format on negative year');
69869 // big negative years
69870 date = moment.utc('-020124-12-31T19:53:45.678').utcOffset('+05:30');
69871 assert.equal(date.toISOString(true), '-020123-01-01T01:23:45.678+05:30', 'ISO8601 format on big negative year');
4710a793 69872
db71a655
KM
69873 //invalid dates
69874 date = moment.utc('2017-12-32').utcOffset('+05:30');
69875 assert.equal(date.toISOString(true), null, 'An invalid date to iso string is null');
69876 });
4710a793 69877
db71a655
KM
69878 // See https://nodejs.org/dist/latest/docs/api/util.html#util_custom_inspect_function_on_objects
69879 test('inspect', function (assert) {
69880 function roundtrip(m) {
69881 /*jshint evil:true */
69882 return (new Function('moment', 'return ' + m.inspect()))(moment);
4710a793 69883 }
db71a655
KM
69884 function testInspect(date, string) {
69885 var inspected = date.inspect();
69886 assert.equal(inspected, string);
69887 assert.ok(date.isSame(roundtrip(date)), 'Tried to parse ' + inspected);
4710a793 69888 }
db71a655
KM
69889
69890 testInspect(
69891 moment('2012-10-09T20:30:40.678'),
69892 'moment("2012-10-09T20:30:40.678")'
69893 );
69894 testInspect(
69895 moment('+020123-10-09T20:30:40.678'),
69896 'moment("+020123-10-09T20:30:40.678")'
69897 );
69898 testInspect(
69899 moment.utc('2012-10-09T20:30:40.678'),
69900 'moment.utc("2012-10-09T20:30:40.678+00:00")'
69901 );
69902 testInspect(
69903 moment.utc('+020123-10-09T20:30:40.678'),
69904 'moment.utc("+020123-10-09T20:30:40.678+00:00")'
69905 );
69906 testInspect(
69907 moment.utc('+020123-10-09T20:30:40.678+01:00'),
69908 'moment.utc("+020123-10-09T19:30:40.678+00:00")'
69909 );
69910 testInspect(
69911 moment.parseZone('2016-06-11T17:30:40.678+0430'),
69912 'moment.parseZone("2016-06-11T17:30:40.678+04:30")'
69913 );
69914 testInspect(
69915 moment.parseZone('+112016-06-11T17:30:40.678+0430'),
69916 'moment.parseZone("+112016-06-11T17:30:40.678+04:30")'
69917 );
69918
69919 assert.equal(
69920 moment(new Date('nope')).inspect(),
69921 'moment.invalid(/* Invalid Date */)'
69922 );
69923 assert.equal(
69924 moment('blah', 'YYYY').inspect(),
69925 'moment.invalid(/* blah */)'
69926 );
69927 });
69928
69929 test('long years', function (assert) {
69930 assert.equal(moment.utc().year(2).format('YYYYYY'), '+000002', 'small year with YYYYYY');
69931 assert.equal(moment.utc().year(2012).format('YYYYYY'), '+002012', 'regular year with YYYYYY');
69932 assert.equal(moment.utc().year(20123).format('YYYYYY'), '+020123', 'big year with YYYYYY');
69933
69934 assert.equal(moment.utc().year(-1).format('YYYYYY'), '-000001', 'small negative year with YYYYYY');
69935 assert.equal(moment.utc().year(-2012).format('YYYYYY'), '-002012', 'negative year with YYYYYY');
69936 assert.equal(moment.utc().year(-20123).format('YYYYYY'), '-020123', 'big negative year with YYYYYY');
69937 });
69938
69939 test('toISOString() when 0 year', function (assert) {
69940 // https://github.com/moment/moment/issues/3765
69941 var date = moment('0000-01-01T21:00:00.000Z');
69942 assert.equal(date.toISOString(), '0000-01-01T21:00:00.000Z');
69943 assert.equal(date.toDate().toISOString(), '0000-01-01T21:00:00.000Z');
69944 });
69945
69946 test('iso week formats', function (assert) {
69947 // https://en.wikipedia.org/wiki/ISO_week_date
69948 var cases = {
69949 '2005-01-02': '2004-53',
69950 '2005-12-31': '2005-52',
69951 '2007-01-01': '2007-01',
69952 '2007-12-30': '2007-52',
69953 '2007-12-31': '2008-01',
69954 '2008-01-01': '2008-01',
69955 '2008-12-28': '2008-52',
69956 '2008-12-29': '2009-01',
69957 '2008-12-30': '2009-01',
69958 '2008-12-31': '2009-01',
69959 '2009-01-01': '2009-01',
69960 '2009-12-31': '2009-53',
69961 '2010-01-01': '2009-53',
69962 '2010-01-02': '2009-53',
69963 '2010-01-03': '2009-53',
69964 '404-12-31': '0404-53',
69965 '405-12-31': '0405-52'
69966 }, i, isoWeek, formatted2, formatted1;
69967
69968 for (i in cases) {
69969 isoWeek = cases[i].split('-').pop();
69970 formatted2 = moment(i, 'YYYY-MM-DD').format('WW');
69971 assert.equal(isoWeek, formatted2, i + ': WW should be ' + isoWeek + ', but ' + formatted2);
69972 isoWeek = isoWeek.replace(/^0+/, '');
69973 formatted1 = moment(i, 'YYYY-MM-DD').format('W');
69974 assert.equal(isoWeek, formatted1, i + ': W should be ' + isoWeek + ', but ' + formatted1);
69975 }
69976 });
69977
69978 test('iso week year formats', function (assert) {
69979 // https://en.wikipedia.org/wiki/ISO_week_date
69980 var cases = {
69981 '2005-01-02': '2004-53',
69982 '2005-12-31': '2005-52',
69983 '2007-01-01': '2007-01',
69984 '2007-12-30': '2007-52',
69985 '2007-12-31': '2008-01',
69986 '2008-01-01': '2008-01',
69987 '2008-12-28': '2008-52',
69988 '2008-12-29': '2009-01',
69989 '2008-12-30': '2009-01',
69990 '2008-12-31': '2009-01',
69991 '2009-01-01': '2009-01',
69992 '2009-12-31': '2009-53',
69993 '2010-01-01': '2009-53',
69994 '2010-01-02': '2009-53',
69995 '2010-01-03': '2009-53',
69996 '404-12-31': '0404-53',
69997 '405-12-31': '0405-52'
69998 }, i, isoWeekYear, formatted5, formatted4, formatted2;
69999
70000 for (i in cases) {
70001 isoWeekYear = cases[i].split('-')[0];
70002 formatted5 = moment(i, 'YYYY-MM-DD').format('GGGGG');
70003 assert.equal('0' + isoWeekYear, formatted5, i + ': GGGGG should be ' + isoWeekYear + ', but ' + formatted5);
70004 formatted4 = moment(i, 'YYYY-MM-DD').format('GGGG');
70005 assert.equal(isoWeekYear, formatted4, i + ': GGGG should be ' + isoWeekYear + ', but ' + formatted4);
70006 formatted2 = moment(i, 'YYYY-MM-DD').format('GG');
70007 assert.equal(isoWeekYear.slice(2, 4), formatted2, i + ': GG should be ' + isoWeekYear + ', but ' + formatted2);
70008 }
70009 });
70010
70011 test('week year formats', function (assert) {
70012 // https://en.wikipedia.org/wiki/ISO_week_date
70013 var cases = {
70014 '2005-01-02': '2004-53',
70015 '2005-12-31': '2005-52',
70016 '2007-01-01': '2007-01',
70017 '2007-12-30': '2007-52',
70018 '2007-12-31': '2008-01',
70019 '2008-01-01': '2008-01',
70020 '2008-12-28': '2008-52',
70021 '2008-12-29': '2009-01',
70022 '2008-12-30': '2009-01',
70023 '2008-12-31': '2009-01',
70024 '2009-01-01': '2009-01',
70025 '2009-12-31': '2009-53',
70026 '2010-01-01': '2009-53',
70027 '2010-01-02': '2009-53',
70028 '2010-01-03': '2009-53',
70029 '404-12-31': '0404-53',
70030 '405-12-31': '0405-52'
70031 }, i, isoWeekYear, formatted5, formatted4, formatted2;
70032
70033 moment.defineLocale('dow:1,doy:4', {week: {dow: 1, doy: 4}});
70034
70035 for (i in cases) {
70036 isoWeekYear = cases[i].split('-')[0];
70037 formatted5 = moment(i, 'YYYY-MM-DD').format('ggggg');
70038 assert.equal('0' + isoWeekYear, formatted5, i + ': ggggg should be ' + isoWeekYear + ', but ' + formatted5);
70039 formatted4 = moment(i, 'YYYY-MM-DD').format('gggg');
70040 assert.equal(isoWeekYear, formatted4, i + ': gggg should be ' + isoWeekYear + ', but ' + formatted4);
70041 formatted2 = moment(i, 'YYYY-MM-DD').format('gg');
70042 assert.equal(isoWeekYear.slice(2, 4), formatted2, i + ': gg should be ' + isoWeekYear + ', but ' + formatted2);
4710a793 70043 }
db71a655
KM
70044 moment.defineLocale('dow:1,doy:4', null);
70045 });
4710a793 70046
db71a655
KM
70047 test('iso weekday formats', function (assert) {
70048 assert.equal(moment([1985, 1, 4]).format('E'), '1', 'Feb 4 1985 is Monday -- 1st day');
70049 assert.equal(moment([2029, 8, 18]).format('E'), '2', 'Sep 18 2029 is Tuesday -- 2nd day');
70050 assert.equal(moment([2013, 3, 24]).format('E'), '3', 'Apr 24 2013 is Wednesday -- 3rd day');
70051 assert.equal(moment([2015, 2, 5]).format('E'), '4', 'Mar 5 2015 is Thursday -- 4th day');
70052 assert.equal(moment([1970, 0, 2]).format('E'), '5', 'Jan 2 1970 is Friday -- 5th day');
70053 assert.equal(moment([2001, 4, 12]).format('E'), '6', 'May 12 2001 is Saturday -- 6th day');
70054 assert.equal(moment([2000, 0, 2]).format('E'), '7', 'Jan 2 2000 is Sunday -- 7th day');
70055 });
4710a793 70056
db71a655
KM
70057 test('weekday formats', function (assert) {
70058 moment.defineLocale('dow: 3,doy: 5', {week: {dow: 3, doy: 5}});
70059 assert.equal(moment([1985, 1, 6]).format('e'), '0', 'Feb 6 1985 is Wednesday -- 0th day');
70060 assert.equal(moment([2029, 8, 20]).format('e'), '1', 'Sep 20 2029 is Thursday -- 1st day');
70061 assert.equal(moment([2013, 3, 26]).format('e'), '2', 'Apr 26 2013 is Friday -- 2nd day');
70062 assert.equal(moment([2015, 2, 7]).format('e'), '3', 'Mar 7 2015 is Saturday -- 3nd day');
70063 assert.equal(moment([1970, 0, 4]).format('e'), '4', 'Jan 4 1970 is Sunday -- 4th day');
70064 assert.equal(moment([2001, 4, 14]).format('e'), '5', 'May 14 2001 is Monday -- 5th day');
70065 assert.equal(moment([2000, 0, 4]).format('e'), '6', 'Jan 4 2000 is Tuesday -- 6th day');
70066 moment.defineLocale('dow: 3,doy: 5', null);
70067 });
4710a793 70068
db71a655
KM
70069 test('toString is just human readable format', function (assert) {
70070 var b = moment(new Date(2009, 1, 5, 15, 25, 50, 125));
70071 assert.equal(b.toString(), b.format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ'));
70072 });
4710a793 70073
db71a655
KM
70074 test('toJSON skips postformat', function (assert) {
70075 moment.defineLocale('postformat', {
70076 postformat: function (s) {
70077 s.replace(/./g, 'X');
73f3c911 70078 }
db71a655
KM
70079 });
70080 assert.equal(moment.utc([2000, 0, 1]).toJSON(), '2000-01-01T00:00:00.000Z', 'toJSON doesn\'t postformat');
70081 moment.defineLocale('postformat', null);
70082 });
516f5f67 70083
db71a655
KM
70084 test('calendar day timezone', function (assert) {
70085 moment.locale('en');
70086 var zones = [60, -60, 90, -90, 360, -360, 720, -720],
70087 b = moment().utc().startOf('day').subtract({m : 1}),
70088 c = moment().local().startOf('day').subtract({m : 1}),
70089 d = moment().local().startOf('day').subtract({d : 2}),
70090 i, z, a;
70091
70092 for (i = 0; i < zones.length; ++i) {
70093 z = zones[i];
70094 a = moment().utcOffset(z).startOf('day').subtract({m: 1});
70095 assert.equal(moment(a).utcOffset(z).calendar(), 'Yesterday at 11:59 PM',
70096 'Yesterday at 11:59 PM, not Today, or the wrong time, tz = ' + z);
70097 }
70098
70099 assert.equal(moment(b).utc().calendar(), 'Yesterday at 11:59 PM', 'Yesterday at 11:59 PM, not Today, or the wrong time');
70100 assert.equal(moment(c).local().calendar(), 'Yesterday at 11:59 PM', 'Yesterday at 11:59 PM, not Today, or the wrong time');
70101 assert.equal(moment(c).local().calendar(d), 'Tomorrow at 11:59 PM', 'Tomorrow at 11:59 PM, not Yesterday, or the wrong time');
70102 });
70103
70104 test('calendar with custom formats', function (assert) {
70105 assert.equal(moment().calendar(null, {sameDay: '[Today]'}), 'Today', 'Today');
70106 assert.equal(moment().add(1, 'days').calendar(null, {nextDay: '[Tomorrow]'}), 'Tomorrow', 'Tomorrow');
70107 assert.equal(moment([1985, 1, 4]).calendar(null, {sameElse: 'YYYY-MM-DD'}), '1985-02-04', 'Else');
70108 });
70109
70110 test('invalid', function (assert) {
70111 assert.equal(moment.invalid().format(), 'Invalid date');
70112 assert.equal(moment.invalid().format('YYYY-MM-DD'), 'Invalid date');
70113 });
70114
70115 test('quarter formats', function (assert) {
70116 assert.equal(moment([1985, 1, 4]).format('Q'), '1', 'Feb 4 1985 is Q1');
70117 assert.equal(moment([2029, 8, 18]).format('Q'), '3', 'Sep 18 2029 is Q3');
70118 assert.equal(moment([2013, 3, 24]).format('Q'), '2', 'Apr 24 2013 is Q2');
70119 assert.equal(moment([2015, 2, 5]).format('Q'), '1', 'Mar 5 2015 is Q1');
70120 assert.equal(moment([1970, 0, 2]).format('Q'), '1', 'Jan 2 1970 is Q1');
70121 assert.equal(moment([2001, 11, 12]).format('Q'), '4', 'Dec 12 2001 is Q4');
70122 assert.equal(moment([2000, 0, 2]).format('[Q]Q-YYYY'), 'Q1-2000', 'Jan 2 2000 is Q1');
70123 });
70124
70125 test('quarter ordinal formats', function (assert) {
70126 assert.equal(moment([1985, 1, 4]).format('Qo'), '1st', 'Feb 4 1985 is 1st quarter');
70127 assert.equal(moment([2029, 8, 18]).format('Qo'), '3rd', 'Sep 18 2029 is 3rd quarter');
70128 assert.equal(moment([2013, 3, 24]).format('Qo'), '2nd', 'Apr 24 2013 is 2nd quarter');
70129 assert.equal(moment([2015, 2, 5]).format('Qo'), '1st', 'Mar 5 2015 is 1st quarter');
70130 assert.equal(moment([1970, 0, 2]).format('Qo'), '1st', 'Jan 2 1970 is 1st quarter');
70131 assert.equal(moment([2001, 11, 12]).format('Qo'), '4th', 'Dec 12 2001 is 4th quarter');
70132 assert.equal(moment([2000, 0, 2]).format('Qo [quarter] YYYY'), '1st quarter 2000', 'Jan 2 2000 is 1st quarter');
70133 });
70134
70135 // test('full expanded format is returned from abbreviated formats', function (assert) {
70136 // function objectKeys(obj) {
70137 // if (Object.keys) {
70138 // return Object.keys(obj);
70139 // } else {
70140 // // IE8
70141 // var res = [], i;
70142 // for (i in obj) {
70143 // if (obj.hasOwnProperty(i)) {
70144 // res.push(i);
70145 // }
70146 // }
70147 // return res;
70148 // }
70149 // }
70150
70151 // var locales =
70152 // 'ar-sa ar-tn ar az be bg bn bo br bs ca cs cv cy da de-at de dv el ' +
70153 // 'en-au en-ca en-gb en-ie en-nz eo es et eu fa fi fo fr-ca fr-ch fr fy ' +
70154 // 'gd gl he hi hr hu hy-am id is it ja jv ka kk km ko lb lo lt lv me mk ml ' +
70155 // 'mr ms-my ms my nb ne nl nn pl pt-br pt ro ru se si sk sl sq sr-cyrl ' +
70156 // 'sr sv sw ta te th tl-ph tlh tr tzl tzm-latn tzm uk uz vi zh-cn zh-tw';
70157
70158 // each(locales.split(' '), function (locale) {
70159 // var data, tokens;
70160 // data = moment().locale(locale).localeData()._longDateFormat;
70161 // tokens = objectKeys(data);
70162 // each(tokens, function (token) {
70163 // // Check each format string to make sure it does not contain any
70164 // // tokens that need to be expanded.
70165 // each(tokens, function (i) {
70166 // // strip escaped sequences
70167 // var format = data[i].replace(/(\[[^\]]*\])/g, '');
70168 // assert.equal(false, !!~format.indexOf(token), 'locale ' + locale + ' contains ' + token + ' in ' + i);
70169 // });
70170 // });
70171 // });
70172 // });
70173
70174 test('milliseconds', function (assert) {
70175 var m = moment('123', 'SSS');
70176
70177 assert.equal(m.format('S'), '1');
70178 assert.equal(m.format('SS'), '12');
70179 assert.equal(m.format('SSS'), '123');
70180 assert.equal(m.format('SSSS'), '1230');
70181 assert.equal(m.format('SSSSS'), '12300');
70182 assert.equal(m.format('SSSSSS'), '123000');
70183 assert.equal(m.format('SSSSSSS'), '1230000');
70184 assert.equal(m.format('SSSSSSSS'), '12300000');
70185 assert.equal(m.format('SSSSSSSSS'), '123000000');
70186 });
70187
70188 test('hmm and hmmss', function (assert) {
70189 assert.equal(moment('12:34:56', 'HH:mm:ss').format('hmm'), '1234');
70190 assert.equal(moment('01:34:56', 'HH:mm:ss').format('hmm'), '134');
70191 assert.equal(moment('13:34:56', 'HH:mm:ss').format('hmm'), '134');
70192
70193 assert.equal(moment('12:34:56', 'HH:mm:ss').format('hmmss'), '123456');
70194 assert.equal(moment('01:34:56', 'HH:mm:ss').format('hmmss'), '13456');
70195 assert.equal(moment('13:34:56', 'HH:mm:ss').format('hmmss'), '13456');
70196 });
70197
70198 test('Hmm and Hmmss', function (assert) {
70199 assert.equal(moment('12:34:56', 'HH:mm:ss').format('Hmm'), '1234');
70200 assert.equal(moment('01:34:56', 'HH:mm:ss').format('Hmm'), '134');
70201 assert.equal(moment('13:34:56', 'HH:mm:ss').format('Hmm'), '1334');
70202
70203 assert.equal(moment('12:34:56', 'HH:mm:ss').format('Hmmss'), '123456');
70204 assert.equal(moment('01:34:56', 'HH:mm:ss').format('Hmmss'), '13456');
70205 assert.equal(moment('08:34:56', 'HH:mm:ss').format('Hmmss'), '83456');
70206 assert.equal(moment('18:34:56', 'HH:mm:ss').format('Hmmss'), '183456');
70207 });
70208
70209 test('k and kk', function (assert) {
70210 assert.equal(moment('01:23:45', 'HH:mm:ss').format('k'), '1');
70211 assert.equal(moment('12:34:56', 'HH:mm:ss').format('k'), '12');
70212 assert.equal(moment('01:23:45', 'HH:mm:ss').format('kk'), '01');
70213 assert.equal(moment('12:34:56', 'HH:mm:ss').format('kk'), '12');
70214 assert.equal(moment('00:34:56', 'HH:mm:ss').format('kk'), '24');
70215 assert.equal(moment('00:00:00', 'HH:mm:ss').format('kk'), '24');
70216 });
70217
70218 test('Y token', function (assert) {
70219 assert.equal(moment('2010-01-01', 'YYYY-MM-DD', true).format('Y'), '2010', 'format 2010 with Y');
70220 assert.equal(moment('-123-01-01', 'Y-MM-DD', true).format('Y'), '-123', 'format -123 with Y');
70221 assert.equal(moment('12345-01-01', 'Y-MM-DD', true).format('Y'), '+12345', 'format 12345 with Y');
70222 assert.equal(moment('0-01-01', 'Y-MM-DD', true).format('Y'), '0', 'format 0 with Y');
70223 assert.equal(moment('1-01-01', 'Y-MM-DD', true).format('Y'), '1', 'format 1 with Y');
70224 assert.equal(moment('9999-01-01', 'Y-MM-DD', true).format('Y'), '9999', 'format 9999 with Y');
70225 assert.equal(moment('10000-01-01', 'Y-MM-DD', true).format('Y'), '+10000', 'format 10000 with Y');
70226 });
73f3c911 70227
b8f4fe2b
KM
70228 test('HTML5_FMT.WEEK', function (assert) {
70229 assert.equal(moment('2004-W01', moment.HTML5_FMT.WEEK).format(moment.HTML5_FMT.WEEK), '2004-W01', 'issue #4698 regression');
70230 assert.equal(moment('2019-W01').format(moment.HTML5_FMT.WEEK), '2019-W01', 'issue #4833 regression');
70231 });
70232
73f3c911 70233})));
516f5f67 70234
516f5f67 70235
b135bf1a
IC
70236;(function (global, factory) {
70237 typeof exports === 'object' && typeof module !== 'undefined'
70238 && typeof require === 'function' ? factory(require('../../moment')) :
70239 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
70240 factory(global.moment)
73f3c911 70241}(this, (function (moment) { 'use strict';
b135bf1a 70242
db71a655
KM
70243 function each(array, callback) {
70244 var i;
70245 for (i = 0; i < array.length; i++) {
70246 callback(array[i], i, array);
516f5f67 70247 }
b135bf1a 70248 }
516f5f67 70249
db71a655
KM
70250 function setupDeprecationHandler(test, moment$$1, scope) {
70251 test._expectedDeprecations = null;
70252 test._observedDeprecations = null;
70253 test._oldSupress = moment$$1.suppressDeprecationWarnings;
70254 moment$$1.suppressDeprecationWarnings = true;
70255 test.expectedDeprecations = function () {
70256 test._expectedDeprecations = arguments;
70257 test._observedDeprecations = [];
70258 };
70259 moment$$1.deprecationHandler = function (name, msg) {
70260 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
70261 if (deprecationId === -1) {
70262 throw new Error('Unexpected deprecation thrown name=' +
70263 name + ' msg=' + msg);
70264 }
70265 test._observedDeprecations[deprecationId] = 1;
70266 };
70267 }
b135bf1a 70268
db71a655
KM
70269 function teardownDeprecationHandler(test, moment$$1, scope) {
70270 moment$$1.suppressDeprecationWarnings = test._oldSupress;
b135bf1a 70271
db71a655
KM
70272 if (test._expectedDeprecations != null) {
70273 var missedDeprecations = [];
70274 each(test._expectedDeprecations, function (deprecationPattern, id) {
70275 if (test._observedDeprecations[id] !== 1) {
70276 missedDeprecations.push(deprecationPattern);
70277 }
b135bf1a 70278 });
db71a655
KM
70279 if (missedDeprecations.length !== 0) {
70280 throw new Error('Expected deprecation warnings did not happen: ' +
70281 missedDeprecations.join(' '));
70282 }
d6651c21 70283 }
db71a655 70284 }
d6651c21 70285
db71a655
KM
70286 function matchedDeprecation(name, msg, deprecations) {
70287 if (deprecations == null) {
70288 return -1;
d6651c21 70289 }
db71a655
KM
70290 for (var i = 0; i < deprecations.length; ++i) {
70291 if (name != null && name === deprecations[i]) {
70292 return i;
70293 }
70294 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
70295 return i;
70296 }
73f3c911 70297 }
db71a655
KM
70298 return -1;
70299 }
516f5f67 70300
db71a655 70301 /*global QUnit:false*/
b135bf1a 70302
db71a655 70303 var test = QUnit.test;
d6651c21 70304
db71a655
KM
70305 function module$1 (name, lifecycle) {
70306 QUnit.module(name, {
c58511b9 70307 beforeEach : function () {
db71a655
KM
70308 moment.locale('en');
70309 moment.createFromInputFallback = function (config) {
70310 throw new Error('input not handled by moment: ' + config._i);
70311 };
70312 setupDeprecationHandler(test, moment, 'core');
70313 if (lifecycle && lifecycle.setup) {
70314 lifecycle.setup();
70315 }
70316 },
c58511b9 70317 afterEach : function () {
db71a655
KM
70318 teardownDeprecationHandler(test, moment, 'core');
70319 if (lifecycle && lifecycle.teardown) {
70320 lifecycle.teardown();
70321 }
d6651c21
IC
70322 }
70323 });
d6651c21
IC
70324 }
70325
db71a655 70326 module$1('from_to');
b135bf1a 70327
db71a655
KM
70328 test('from', function (assert) {
70329 var start = moment();
70330 moment.locale('en');
70331 assert.equal(start.from(start.clone().add(5, 'seconds')), 'a few seconds ago', '5 seconds = a few seconds ago');
70332 assert.equal(start.from(start.clone().add(1, 'minute')), 'a minute ago', '1 minute = a minute ago');
70333 assert.equal(start.from(start.clone().add(5, 'minutes')), '5 minutes ago', '5 minutes = 5 minutes ago');
516f5f67 70334
db71a655
KM
70335 assert.equal(start.from(start.clone().subtract(5, 'seconds')), 'in a few seconds', '5 seconds = in a few seconds');
70336 assert.equal(start.from(start.clone().subtract(1, 'minute')), 'in a minute', '1 minute = in a minute');
70337 assert.equal(start.from(start.clone().subtract(5, 'minutes')), 'in 5 minutes', '5 minutes = in 5 minutes');
70338 });
516f5f67 70339
db71a655
KM
70340 test('from with absolute duration', function (assert) {
70341 var start = moment();
70342 moment.locale('en');
70343 assert.equal(start.from(start.clone().add(5, 'seconds'), true), 'a few seconds', '5 seconds = a few seconds');
70344 assert.equal(start.from(start.clone().add(1, 'minute'), true), 'a minute', '1 minute = a minute');
70345 assert.equal(start.from(start.clone().add(5, 'minutes'), true), '5 minutes', '5 minutes = 5 minutes');
516f5f67 70346
db71a655
KM
70347 assert.equal(start.from(start.clone().subtract(5, 'seconds'), true), 'a few seconds', '5 seconds = a few seconds');
70348 assert.equal(start.from(start.clone().subtract(1, 'minute'), true), 'a minute', '1 minute = a minute');
70349 assert.equal(start.from(start.clone().subtract(5, 'minutes'), true), '5 minutes', '5 minutes = 5 minutes');
70350 });
d40760af 70351
db71a655
KM
70352 test('to', function (assert) {
70353 var start = moment();
70354 moment.locale('en');
70355 assert.equal(start.to(start.clone().subtract(5, 'seconds')), 'a few seconds ago', '5 seconds = a few seconds ago');
70356 assert.equal(start.to(start.clone().subtract(1, 'minute')), 'a minute ago', '1 minute = a minute ago');
70357 assert.equal(start.to(start.clone().subtract(5, 'minutes')), '5 minutes ago', '5 minutes = 5 minutes ago');
70358
70359 assert.equal(start.to(start.clone().add(5, 'seconds')), 'in a few seconds', '5 seconds = in a few seconds');
70360 assert.equal(start.to(start.clone().add(1, 'minute')), 'in a minute', '1 minute = in a minute');
70361 assert.equal(start.to(start.clone().add(5, 'minutes')), 'in 5 minutes', '5 minutes = in 5 minutes');
70362 });
70363
70364 test('to with absolute duration', function (assert) {
70365 var start = moment();
70366 moment.locale('en');
70367 assert.equal(start.to(start.clone().add(5, 'seconds'), true), 'a few seconds', '5 seconds = a few seconds');
70368 assert.equal(start.to(start.clone().add(1, 'minute'), true), 'a minute', '1 minute = a minute');
70369 assert.equal(start.to(start.clone().add(5, 'minutes'), true), '5 minutes', '5 minutes = 5 minutes');
70370
70371 assert.equal(start.to(start.clone().subtract(5, 'seconds'), true), 'a few seconds', '5 seconds = a few seconds');
70372 assert.equal(start.to(start.clone().subtract(1, 'minute'), true), 'a minute', '1 minute = a minute');
70373 assert.equal(start.to(start.clone().subtract(5, 'minutes'), true), '5 minutes', '5 minutes = 5 minutes');
70374 });
73f3c911
IC
70375
70376})));
d40760af 70377
c74a101d
IC
70378
70379;(function (global, factory) {
70380 typeof exports === 'object' && typeof module !== 'undefined'
70381 && typeof require === 'function' ? factory(require('../../moment')) :
70382 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
70383 factory(global.moment)
73f3c911 70384}(this, (function (moment) { 'use strict';
c74a101d 70385
db71a655
KM
70386 function each(array, callback) {
70387 var i;
70388 for (i = 0; i < array.length; i++) {
70389 callback(array[i], i, array);
70390 }
b135bf1a
IC
70391 }
70392
db71a655
KM
70393 function setupDeprecationHandler(test, moment$$1, scope) {
70394 test._expectedDeprecations = null;
70395 test._observedDeprecations = null;
70396 test._oldSupress = moment$$1.suppressDeprecationWarnings;
70397 moment$$1.suppressDeprecationWarnings = true;
70398 test.expectedDeprecations = function () {
70399 test._expectedDeprecations = arguments;
70400 test._observedDeprecations = [];
70401 };
70402 moment$$1.deprecationHandler = function (name, msg) {
70403 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
70404 if (deprecationId === -1) {
70405 throw new Error('Unexpected deprecation thrown name=' +
70406 name + ' msg=' + msg);
b135bf1a 70407 }
db71a655
KM
70408 test._observedDeprecations[deprecationId] = 1;
70409 };
b135bf1a
IC
70410 }
70411
db71a655
KM
70412 function teardownDeprecationHandler(test, moment$$1, scope) {
70413 moment$$1.suppressDeprecationWarnings = test._oldSupress;
b135bf1a 70414
db71a655
KM
70415 if (test._expectedDeprecations != null) {
70416 var missedDeprecations = [];
70417 each(test._expectedDeprecations, function (deprecationPattern, id) {
70418 if (test._observedDeprecations[id] !== 1) {
70419 missedDeprecations.push(deprecationPattern);
70420 }
70421 });
70422 if (missedDeprecations.length !== 0) {
70423 throw new Error('Expected deprecation warnings did not happen: ' +
70424 missedDeprecations.join(' '));
70425 }
73f3c911 70426 }
db71a655 70427 }
b135bf1a 70428
db71a655
KM
70429 function matchedDeprecation(name, msg, deprecations) {
70430 if (deprecations == null) {
70431 return -1;
73f3c911 70432 }
db71a655
KM
70433 for (var i = 0; i < deprecations.length; ++i) {
70434 if (name != null && name === deprecations[i]) {
70435 return i;
70436 }
70437 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
70438 return i;
70439 }
73f3c911 70440 }
db71a655
KM
70441 return -1;
70442 }
b135bf1a 70443
db71a655 70444 /*global QUnit:false*/
d6651c21 70445
db71a655 70446 var test = QUnit.test;
d6651c21 70447
db71a655
KM
70448 function module$1 (name, lifecycle) {
70449 QUnit.module(name, {
c58511b9 70450 beforeEach : function () {
db71a655
KM
70451 moment.locale('en');
70452 moment.createFromInputFallback = function (config) {
70453 throw new Error('input not handled by moment: ' + config._i);
70454 };
70455 setupDeprecationHandler(test, moment, 'core');
70456 if (lifecycle && lifecycle.setup) {
70457 lifecycle.setup();
70458 }
70459 },
c58511b9 70460 afterEach : function () {
db71a655
KM
70461 teardownDeprecationHandler(test, moment, 'core');
70462 if (lifecycle && lifecycle.teardown) {
70463 lifecycle.teardown();
70464 }
70465 }
70466 });
70467 }
d6651c21 70468
db71a655
KM
70469 module$1('getters and setters');
70470
70471 test('getters', function (assert) {
70472 var a = moment([2011, 9, 12, 6, 7, 8, 9]);
70473 assert.equal(a.year(), 2011, 'year');
70474 assert.equal(a.month(), 9, 'month');
70475 assert.equal(a.date(), 12, 'date');
70476 assert.equal(a.day(), 3, 'day');
70477 assert.equal(a.hours(), 6, 'hour');
70478 assert.equal(a.minutes(), 7, 'minute');
70479 assert.equal(a.seconds(), 8, 'second');
70480 assert.equal(a.milliseconds(), 9, 'milliseconds');
70481 });
70482
70483 test('getters programmatic', function (assert) {
70484 var a = moment([2011, 9, 12, 6, 7, 8, 9]);
70485 assert.equal(a.get('year'), 2011, 'year');
70486 assert.equal(a.get('month'), 9, 'month');
70487 assert.equal(a.get('date'), 12, 'date');
70488 assert.equal(a.get('day'), 3, 'day');
70489 assert.equal(a.get('hour'), 6, 'hour');
70490 assert.equal(a.get('minute'), 7, 'minute');
70491 assert.equal(a.get('second'), 8, 'second');
70492 assert.equal(a.get('milliseconds'), 9, 'milliseconds');
70493
70494 //actual getters tested elsewhere
70495 assert.equal(a.get('weekday'), a.weekday(), 'weekday');
70496 assert.equal(a.get('isoWeekday'), a.isoWeekday(), 'isoWeekday');
70497 assert.equal(a.get('week'), a.week(), 'week');
70498 assert.equal(a.get('isoWeek'), a.isoWeek(), 'isoWeek');
70499 assert.equal(a.get('dayOfYear'), a.dayOfYear(), 'dayOfYear');
70500
70501 //getter no longer sets values when passed an object
70502 assert.equal(moment([2016,0,1]).get({year:2015}).year(), 2016, 'getter no longer sets values when passed an object');
70503 });
70504
70505 test('setters plural', function (assert) {
70506 var a = moment();
70507 test.expectedDeprecations('years accessor', 'months accessor', 'dates accessor');
70508
70509 a.years(2011);
70510 a.months(9);
70511 a.dates(12);
70512 a.hours(6);
70513 a.minutes(7);
70514 a.seconds(8);
70515 a.milliseconds(9);
70516 assert.equal(a.years(), 2011, 'years');
70517 assert.equal(a.months(), 9, 'months');
70518 assert.equal(a.dates(), 12, 'dates');
70519 assert.equal(a.days(), 3, 'days');
70520 assert.equal(a.hours(), 6, 'hours');
70521 assert.equal(a.minutes(), 7, 'minutes');
70522 assert.equal(a.seconds(), 8, 'seconds');
70523 assert.equal(a.milliseconds(), 9, 'milliseconds');
70524 });
70525
70526 test('setters singular', function (assert) {
70527 var a = moment();
70528 a.year(2011);
70529 a.month(9);
70530 a.date(12);
70531 a.hour(6);
70532 a.minute(7);
70533 a.second(8);
70534 a.millisecond(9);
70535 assert.equal(a.year(), 2011, 'year');
70536 assert.equal(a.month(), 9, 'month');
70537 assert.equal(a.date(), 12, 'date');
70538 assert.equal(a.day(), 3, 'day');
70539 assert.equal(a.hour(), 6, 'hour');
70540 assert.equal(a.minute(), 7, 'minute');
70541 assert.equal(a.second(), 8, 'second');
70542 assert.equal(a.millisecond(), 9, 'milliseconds');
70543 });
70544
70545 test('setters', function (assert) {
70546 var a = moment();
70547 a.year(2011);
70548 a.month(9);
70549 a.date(12);
70550 a.hours(6);
70551 a.minutes(7);
70552 a.seconds(8);
70553 a.milliseconds(9);
70554 assert.equal(a.year(), 2011, 'year');
70555 assert.equal(a.month(), 9, 'month');
70556 assert.equal(a.date(), 12, 'date');
70557 assert.equal(a.day(), 3, 'day');
70558 assert.equal(a.hours(), 6, 'hour');
70559 assert.equal(a.minutes(), 7, 'minute');
70560 assert.equal(a.seconds(), 8, 'second');
70561 assert.equal(a.milliseconds(), 9, 'milliseconds');
70562
70563 // Test month() behavior. See https://github.com/timrwood/moment/pull/822
70564 a = moment('20130531', 'YYYYMMDD');
70565 a.month(3);
70566 assert.equal(a.month(), 3, 'month edge case');
70567 });
70568
70569 test('setters should handle garbage input', function (assert) {
70570 var a = moment();
70571 a.set('year', 2011);
70572 a.set('month', 9);
70573 a.set('date', 12);
70574 a.set('hours', 6);
70575 a.set('minutes', 7);
70576 a.set('seconds', 8);
70577 a.set('milliseconds', 9);
70578
70579 a.year(undefined);
70580 a.month('foo');
70581 a.date(null);
70582 a.day({a:2,b:3});
70583 a.hours('[1]');
70584 a.minutes(undefined);
70585 a.seconds(null);
70586 a.milliseconds(NaN);
70587
70588 assert.equal(a.year(), 2011, 'year - provided undefined');
70589 assert.equal(a.month(), 9, 'month - provided null');
70590 assert.equal(a.date(), 12, 'date - provided [1]');
70591 assert.equal(a.day(), 3, 'day - provided Infinity');
70592 assert.equal(a.hours(), 6, 'hour - provided new Date');
70593 assert.equal(a.minutes(), 7, 'minute - provided {a:1,b:2}');
70594 assert.equal(a.seconds(), 8, 'second - provided foo');
70595 assert.equal(a.milliseconds(), 9, 'milliseconds - provided Infinity');
70596 });
70597
70598 test('setter programmatic', function (assert) {
70599 var a = moment();
70600 a.set('year', 2011);
70601 a.set('month', 9);
70602 a.set('date', 12);
70603 a.set('hours', 6);
70604 a.set('minutes', 7);
70605 a.set('seconds', 8);
70606 a.set('milliseconds', 9);
70607 assert.equal(a.year(), 2011, 'year');
70608 assert.equal(a.month(), 9, 'month');
70609 assert.equal(a.date(), 12, 'date');
70610 assert.equal(a.day(), 3, 'day');
70611 assert.equal(a.hours(), 6, 'hour');
70612 assert.equal(a.minutes(), 7, 'minute');
70613 assert.equal(a.seconds(), 8, 'second');
70614 assert.equal(a.milliseconds(), 9, 'milliseconds');
70615
70616 // Test month() behavior. See https://github.com/timrwood/moment/pull/822
70617 a = moment('20130531', 'YYYYMMDD');
70618 a.month(3);
70619 assert.equal(a.month(), 3, 'month edge case');
70620 });
70621
70622 test('setters programatic with weeks', function (assert) {
70623 var a = moment();
70624 a.set('weekYear', 2001);
70625 a.set('week', 49);
70626 a.set('day', 4);
70627
70628 assert.equal(a.weekYear(), 2001, 'weekYear');
70629 assert.equal(a.week(), 49, 'week');
70630 assert.equal(a.day(), 4, 'day');
70631
70632 a.set('weekday', 1);
70633 assert.equal(a.weekday(), 1, 'weekday');
70634 });
70635
70636 test('setters programatic with weeks ISO', function (assert) {
70637 var a = moment();
70638 a.set('isoWeekYear', 2001);
70639 a.set('isoWeek', 49);
70640 a.set('isoWeekday', 4);
70641
70642 assert.equal(a.isoWeekYear(), 2001, 'isoWeekYear');
70643 assert.equal(a.isoWeek(), 49, 'isoWeek');
70644 assert.equal(a.isoWeekday(), 4, 'isoWeekday');
70645 });
70646
70647 test('setters strings', function (assert) {
70648 var a = moment([2012]).locale('en');
70649 assert.equal(a.clone().day(0).day('Wednesday').day(), 3, 'day full name');
70650 assert.equal(a.clone().day(0).day('Wed').day(), 3, 'day short name');
70651 assert.equal(a.clone().day(0).day('We').day(), 3, 'day minimal name');
70652 assert.equal(a.clone().day(0).day('invalid').day(), 0, 'invalid day name');
70653 assert.equal(a.clone().month(0).month('April').month(), 3, 'month full name');
70654 assert.equal(a.clone().month(0).month('Apr').month(), 3, 'month short name');
70655 assert.equal(a.clone().month(0).month('invalid').month(), 0, 'invalid month name');
70656 });
70657
70658 test('setters - falsey values', function (assert) {
70659 var a = moment();
70660 // ensure minutes wasn't coincidentally 0 already
70661 a.minutes(1);
70662 a.minutes(0);
70663 assert.equal(a.minutes(), 0, 'falsey value');
70664 });
70665
70666 test('chaining setters', function (assert) {
70667 var a = moment();
70668 a.year(2011)
70669 .month(9)
70670 .date(12)
70671 .hours(6)
70672 .minutes(7)
70673 .seconds(8);
70674 assert.equal(a.year(), 2011, 'year');
70675 assert.equal(a.month(), 9, 'month');
70676 assert.equal(a.date(), 12, 'date');
70677 assert.equal(a.day(), 3, 'day');
70678 assert.equal(a.hours(), 6, 'hour');
70679 assert.equal(a.minutes(), 7, 'minute');
70680 assert.equal(a.seconds(), 8, 'second');
70681 });
70682
70683 test('setter with multiple unit values', function (assert) {
70684 var a = moment();
70685 a.set({
70686 year: 2011,
70687 month: 9,
70688 date: 12,
70689 hours: 6,
70690 minutes: 7,
70691 seconds: 8,
70692 milliseconds: 9
70693 });
70694 assert.equal(a.year(), 2011, 'year');
70695 assert.equal(a.month(), 9, 'month');
70696 assert.equal(a.date(), 12, 'date');
70697 assert.equal(a.day(), 3, 'day');
70698 assert.equal(a.hours(), 6, 'hour');
70699 assert.equal(a.minutes(), 7, 'minute');
70700 assert.equal(a.seconds(), 8, 'second');
70701 assert.equal(a.milliseconds(), 9, 'milliseconds');
70702
70703 var c = moment([2016,0,1]);
70704 assert.equal(c.set({weekYear: 2016}).weekYear(), 2016, 'week year correctly sets with object syntax');
70705 assert.equal(c.set({quarter: 3}).quarter(), 3, 'quarter sets correctly with object syntax');
70706 });
70707
70708 test('day setter', function (assert) {
70709 var a = moment([2011, 0, 15]);
70710 assert.equal(moment(a).day(0).date(), 9, 'set from saturday to sunday');
70711 assert.equal(moment(a).day(6).date(), 15, 'set from saturday to saturday');
70712 assert.equal(moment(a).day(3).date(), 12, 'set from saturday to wednesday');
70713
70714 a = moment([2011, 0, 9]);
70715 assert.equal(moment(a).day(0).date(), 9, 'set from sunday to sunday');
70716 assert.equal(moment(a).day(6).date(), 15, 'set from sunday to saturday');
70717 assert.equal(moment(a).day(3).date(), 12, 'set from sunday to wednesday');
70718
70719 a = moment([2011, 0, 12]);
70720 assert.equal(moment(a).day(0).date(), 9, 'set from wednesday to sunday');
70721 assert.equal(moment(a).day(6).date(), 15, 'set from wednesday to saturday');
70722 assert.equal(moment(a).day(3).date(), 12, 'set from wednesday to wednesday');
70723
70724 assert.equal(moment(a).day(-7).date(), 2, 'set from wednesday to last sunday');
70725 assert.equal(moment(a).day(-1).date(), 8, 'set from wednesday to last saturday');
70726 assert.equal(moment(a).day(-4).date(), 5, 'set from wednesday to last wednesday');
70727
70728 assert.equal(moment(a).day(7).date(), 16, 'set from wednesday to next sunday');
70729 assert.equal(moment(a).day(13).date(), 22, 'set from wednesday to next saturday');
70730 assert.equal(moment(a).day(10).date(), 19, 'set from wednesday to next wednesday');
70731
70732 assert.equal(moment(a).day(14).date(), 23, 'set from wednesday to second next sunday');
70733 assert.equal(moment(a).day(20).date(), 29, 'set from wednesday to second next saturday');
70734 assert.equal(moment(a).day(17).date(), 26, 'set from wednesday to second next wednesday');
70735 });
70736
70737 test('year setter', function (assert) {
70738 var a = moment([2015, 3, 15]);
70739 assert.equal(moment(a).year(2016).format('YYYY-MM-DD'), '2016-04-15', 'set from 2015 to 2016');
70740 assert.equal(moment(a).year(2011).format('YYYY-MM-DD'), '2011-04-15', 'set from 2015 to 2011');
70741
70742 var b = moment([2012, 1, 29]);
70743 assert.equal(moment(b).year(2017).format('YYYY-MM-DD'), '2017-02-28', 'set from last day of february on a leap year to a non leap year');
70744 assert.equal(moment(b).year(2004).format('YYYY-MM-DD'), '2004-02-29', 'set from last day of february on a leap year to a leap year');
70745
70746 var c = moment([2012, 9, 4]);
70747 assert.equal(moment(c).year(2017).format('YYYY-MM-DD'), '2017-10-04', 'set from a random day on a leap year to a non leap year');
70748 assert.equal(moment(c).year(2004).format('YYYY-MM-DD'), '2004-10-04', 'set from a random day on a leap year to a leap year');
70749 });
70750
70751 test('object set ordering', function (assert) {
70752 var a = moment([2016,3,30]);
70753 assert.equal(a.set({date:31, month:4}).date(), 31, 'setter order automatically arranged by size');
70754 var b = moment([2015,1,28]);
70755 assert.equal(b.set({date:29, year: 2016}).format('YYYY-MM-DD'), '2016-02-29', 'year is prioritized over date');
70756 //check a nonexistent time in US isn't set
70757 var c = moment([2016,2,13]);
70758 c.set({
70759 hour:2,
70760 minutes:30,
70761 date: 14
70762 });
70763 assert.equal(c.format('YYYY-MM-DDTHH:mm'), '2016-03-14T02:30', 'setting hours, minutes date puts date first allowing time set to work');
70764 });
70765
70766 test('string setters', function (assert) {
70767 var a = moment();
70768 a.year('2011');
70769 a.month('9');
70770 a.date('12');
70771 a.hours('6');
70772 a.minutes('7');
70773 a.seconds('8');
70774 a.milliseconds('9');
70775 assert.equal(a.year(), 2011, 'year');
70776 assert.equal(a.month(), 9, 'month');
70777 assert.equal(a.date(), 12, 'date');
70778 assert.equal(a.day(), 3, 'day');
70779 assert.equal(a.hours(), 6, 'hour');
70780 assert.equal(a.minutes(), 7, 'minute');
70781 assert.equal(a.seconds(), 8, 'second');
70782 assert.equal(a.milliseconds(), 9, 'milliseconds');
70783 });
70784
70785 test('setters across DST +1', function (assert) {
70786 var oldUpdateOffset = moment.updateOffset,
70787 // Based on a real story somewhere in America/Los_Angeles
70788 dstAt = moment('2014-03-09T02:00:00-08:00').parseZone(),
70789 m;
70790
70791 moment.updateOffset = function (mom, keepTime) {
70792 if (mom.isBefore(dstAt)) {
70793 mom.utcOffset(-8, keepTime);
70794 } else {
70795 mom.utcOffset(-7, keepTime);
70796 }
70797 };
73f3c911 70798
db71a655
KM
70799 m = moment('2014-03-15T00:00:00-07:00').parseZone();
70800 m.year(2013);
70801 assert.equal(m.format(), '2013-03-15T00:00:00-08:00', 'year across +1');
d6651c21 70802
db71a655
KM
70803 m = moment('2014-03-15T00:00:00-07:00').parseZone();
70804 m.month(0);
70805 assert.equal(m.format(), '2014-01-15T00:00:00-08:00', 'month across +1');
b135bf1a 70806
db71a655
KM
70807 m = moment('2014-03-15T00:00:00-07:00').parseZone();
70808 m.date(1);
70809 assert.equal(m.format(), '2014-03-01T00:00:00-08:00', 'date across +1');
c74a101d 70810
db71a655
KM
70811 m = moment('2014-03-09T03:05:00-07:00').parseZone();
70812 m.hour(0);
70813 assert.equal(m.format(), '2014-03-09T00:05:00-08:00', 'hour across +1');
c74a101d 70814
db71a655
KM
70815 moment.updateOffset = oldUpdateOffset;
70816 });
c74a101d 70817
db71a655
KM
70818 test('setters across DST -1', function (assert) {
70819 var oldUpdateOffset = moment.updateOffset,
70820 // Based on a real story somewhere in America/Los_Angeles
70821 dstAt = moment('2014-11-02T02:00:00-07:00').parseZone(),
70822 m;
516f5f67 70823
db71a655
KM
70824 moment.updateOffset = function (mom, keepTime) {
70825 if (mom.isBefore(dstAt)) {
70826 mom.utcOffset(-7, keepTime);
70827 } else {
70828 mom.utcOffset(-8, keepTime);
70829 }
70830 };
c74a101d 70831
db71a655
KM
70832 m = moment('2014-11-15T00:00:00-08:00').parseZone();
70833 m.year(2013);
70834 assert.equal(m.format(), '2013-11-15T00:00:00-07:00', 'year across -1');
516f5f67 70835
db71a655
KM
70836 m = moment('2014-11-15T00:00:00-08:00').parseZone();
70837 m.month(0);
70838 assert.equal(m.format(), '2014-01-15T00:00:00-07:00', 'month across -1');
516f5f67 70839
db71a655
KM
70840 m = moment('2014-11-15T00:00:00-08:00').parseZone();
70841 m.date(1);
70842 assert.equal(m.format(), '2014-11-01T00:00:00-07:00', 'date across -1');
70843
70844 m = moment('2014-11-02T03:30:00-08:00').parseZone();
70845 m.hour(0);
70846 assert.equal(m.format(), '2014-11-02T00:30:00-07:00', 'hour across -1');
516f5f67 70847
db71a655
KM
70848 moment.updateOffset = oldUpdateOffset;
70849 });
73f3c911
IC
70850
70851})));
516f5f67 70852
516f5f67 70853
73f3c911
IC
70854;(function (global, factory) {
70855 typeof exports === 'object' && typeof module !== 'undefined'
70856 && typeof require === 'function' ? factory(require('../../moment')) :
70857 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
70858 factory(global.moment)
70859}(this, (function (moment) { 'use strict';
516f5f67 70860
db71a655
KM
70861 function each(array, callback) {
70862 var i;
70863 for (i = 0; i < array.length; i++) {
70864 callback(array[i], i, array);
70865 }
73f3c911 70866 }
516f5f67 70867
db71a655
KM
70868 function setupDeprecationHandler(test, moment$$1, scope) {
70869 test._expectedDeprecations = null;
70870 test._observedDeprecations = null;
70871 test._oldSupress = moment$$1.suppressDeprecationWarnings;
70872 moment$$1.suppressDeprecationWarnings = true;
70873 test.expectedDeprecations = function () {
70874 test._expectedDeprecations = arguments;
70875 test._observedDeprecations = [];
70876 };
70877 moment$$1.deprecationHandler = function (name, msg) {
70878 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
70879 if (deprecationId === -1) {
70880 throw new Error('Unexpected deprecation thrown name=' +
70881 name + ' msg=' + msg);
70882 }
70883 test._observedDeprecations[deprecationId] = 1;
70884 };
70885 }
516f5f67 70886
db71a655
KM
70887 function teardownDeprecationHandler(test, moment$$1, scope) {
70888 moment$$1.suppressDeprecationWarnings = test._oldSupress;
516f5f67 70889
db71a655
KM
70890 if (test._expectedDeprecations != null) {
70891 var missedDeprecations = [];
70892 each(test._expectedDeprecations, function (deprecationPattern, id) {
70893 if (test._observedDeprecations[id] !== 1) {
70894 missedDeprecations.push(deprecationPattern);
70895 }
70896 });
70897 if (missedDeprecations.length !== 0) {
70898 throw new Error('Expected deprecation warnings did not happen: ' +
70899 missedDeprecations.join(' '));
73f3c911 70900 }
516f5f67 70901 }
73f3c911 70902 }
73f3c911 70903
db71a655
KM
70904 function matchedDeprecation(name, msg, deprecations) {
70905 if (deprecations == null) {
70906 return -1;
73f3c911 70907 }
db71a655
KM
70908 for (var i = 0; i < deprecations.length; ++i) {
70909 if (name != null && name === deprecations[i]) {
70910 return i;
70911 }
70912 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
70913 return i;
70914 }
73f3c911 70915 }
db71a655 70916 return -1;
73f3c911 70917 }
73f3c911 70918
db71a655 70919 /*global QUnit:false*/
73f3c911 70920
db71a655 70921 var test = QUnit.test;
73f3c911 70922
db71a655
KM
70923 function module$1 (name, lifecycle) {
70924 QUnit.module(name, {
c58511b9 70925 beforeEach : function () {
db71a655
KM
70926 moment.locale('en');
70927 moment.createFromInputFallback = function (config) {
70928 throw new Error('input not handled by moment: ' + config._i);
70929 };
70930 setupDeprecationHandler(test, moment, 'core');
70931 if (lifecycle && lifecycle.setup) {
70932 lifecycle.setup();
70933 }
70934 },
c58511b9 70935 afterEach : function () {
db71a655
KM
70936 teardownDeprecationHandler(test, moment, 'core');
70937 if (lifecycle && lifecycle.teardown) {
70938 lifecycle.teardown();
70939 }
516f5f67 70940 }
db71a655
KM
70941 });
70942 }
70943
70944 module$1('instanceof');
70945
70946 test('instanceof', function (assert) {
70947 var mm = moment([2010, 0, 1]);
70948
70949 var extend = function (a, b) {
70950 var i;
70951 for (i in b) {
70952 a[i] = b[i];
70953 }
70954 return a;
70955 };
70956
70957 assert.equal(moment() instanceof moment, true, 'simple moment object');
70958 assert.equal(extend({}, moment()) instanceof moment, false, 'extended moment object');
70959 assert.equal(moment(null) instanceof moment, true, 'invalid moment object');
70960
70961 assert.equal(new Date() instanceof moment, false, 'date object is not moment object');
70962 assert.equal(Object instanceof moment, false, 'Object is not moment object');
70963 assert.equal('foo' instanceof moment, false, 'string is not moment object');
70964 assert.equal(1 instanceof moment, false, 'number is not moment object');
70965 assert.equal(NaN instanceof moment, false, 'NaN is not moment object');
70966 assert.equal(null instanceof moment, false, 'null is not moment object');
70967 assert.equal(undefined instanceof moment, false, 'undefined is not moment object');
70968 });
73f3c911
IC
70969
70970})));
516f5f67 70971
516f5f67 70972
73f3c911
IC
70973;(function (global, factory) {
70974 typeof exports === 'object' && typeof module !== 'undefined'
70975 && typeof require === 'function' ? factory(require('../../moment')) :
70976 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
70977 factory(global.moment)
70978}(this, (function (moment) { 'use strict';
516f5f67 70979
db71a655
KM
70980 function each(array, callback) {
70981 var i;
70982 for (i = 0; i < array.length; i++) {
70983 callback(array[i], i, array);
70984 }
73f3c911 70985 }
516f5f67 70986
db71a655
KM
70987 function setupDeprecationHandler(test, moment$$1, scope) {
70988 test._expectedDeprecations = null;
70989 test._observedDeprecations = null;
70990 test._oldSupress = moment$$1.suppressDeprecationWarnings;
70991 moment$$1.suppressDeprecationWarnings = true;
70992 test.expectedDeprecations = function () {
70993 test._expectedDeprecations = arguments;
70994 test._observedDeprecations = [];
70995 };
70996 moment$$1.deprecationHandler = function (name, msg) {
70997 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
70998 if (deprecationId === -1) {
70999 throw new Error('Unexpected deprecation thrown name=' +
71000 name + ' msg=' + msg);
71001 }
71002 test._observedDeprecations[deprecationId] = 1;
71003 };
71004 }
516f5f67 71005
db71a655
KM
71006 function teardownDeprecationHandler(test, moment$$1, scope) {
71007 moment$$1.suppressDeprecationWarnings = test._oldSupress;
516f5f67 71008
db71a655
KM
71009 if (test._expectedDeprecations != null) {
71010 var missedDeprecations = [];
71011 each(test._expectedDeprecations, function (deprecationPattern, id) {
71012 if (test._observedDeprecations[id] !== 1) {
71013 missedDeprecations.push(deprecationPattern);
71014 }
71015 });
71016 if (missedDeprecations.length !== 0) {
71017 throw new Error('Expected deprecation warnings did not happen: ' +
71018 missedDeprecations.join(' '));
73f3c911 71019 }
73f3c911
IC
71020 }
71021 }
516f5f67 71022
db71a655
KM
71023 function matchedDeprecation(name, msg, deprecations) {
71024 if (deprecations == null) {
71025 return -1;
73f3c911 71026 }
db71a655
KM
71027 for (var i = 0; i < deprecations.length; ++i) {
71028 if (name != null && name === deprecations[i]) {
71029 return i;
71030 }
71031 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
71032 return i;
71033 }
73f3c911 71034 }
db71a655 71035 return -1;
73f3c911 71036 }
516f5f67 71037
db71a655 71038 /*global QUnit:false*/
516f5f67 71039
db71a655 71040 var test = QUnit.test;
516f5f67 71041
db71a655
KM
71042 function module$1 (name, lifecycle) {
71043 QUnit.module(name, {
c58511b9 71044 beforeEach : function () {
db71a655
KM
71045 moment.locale('en');
71046 moment.createFromInputFallback = function (config) {
71047 throw new Error('input not handled by moment: ' + config._i);
71048 };
71049 setupDeprecationHandler(test, moment, 'core');
71050 if (lifecycle && lifecycle.setup) {
71051 lifecycle.setup();
71052 }
71053 },
c58511b9 71054 afterEach : function () {
db71a655
KM
71055 teardownDeprecationHandler(test, moment, 'core');
71056 if (lifecycle && lifecycle.teardown) {
71057 lifecycle.teardown();
71058 }
73f3c911 71059 }
db71a655
KM
71060 });
71061 }
73f3c911 71062
db71a655 71063 module$1('invalid');
73f3c911 71064
db71a655
KM
71065 test('invalid', function (assert) {
71066 var m = moment.invalid();
71067 assert.equal(m.isValid(), false);
71068 assert.equal(m.parsingFlags().userInvalidated, true);
71069 assert.ok(isNaN(m.valueOf()));
71070 });
73f3c911 71071
db71a655
KM
71072 test('invalid with existing flag', function (assert) {
71073 var m = moment.invalid({invalidMonth : 'whatchamacallit'});
71074 assert.equal(m.isValid(), false);
71075 assert.equal(m.parsingFlags().userInvalidated, false);
71076 assert.equal(m.parsingFlags().invalidMonth, 'whatchamacallit');
71077 assert.ok(isNaN(m.valueOf()));
71078 });
73f3c911 71079
db71a655
KM
71080 test('invalid with custom flag', function (assert) {
71081 var m = moment.invalid({tooBusyWith : 'reiculating splines'});
71082 assert.equal(m.isValid(), false);
71083 assert.equal(m.parsingFlags().userInvalidated, false);
71084 assert.equal(m.parsingFlags().tooBusyWith, 'reiculating splines');
71085 assert.ok(isNaN(m.valueOf()));
71086 });
71087
71088 test('invalid operations', function (assert) {
71089 var invalids = [
71090 moment.invalid(),
71091 moment('xyz', 'l'),
71092 moment('2015-01-35', 'YYYY-MM-DD'),
71093 moment('2015-01-25 a', 'YYYY-MM-DD', true)
71094 ],
71095 i,
71096 invalid,
71097 valid = moment();
71098
71099 test.expectedDeprecations('moment().min', 'moment().max', 'isDSTShifted');
71100
71101 for (i = 0; i < invalids.length; ++i) {
71102 invalid = invalids[i];
71103
71104 assert.ok(!invalid.clone().add(5, 'hours').isValid(), 'invalid.add is invalid');
71105 assert.equal(invalid.calendar(), 'Invalid date', 'invalid.calendar is \'Invalid date\'');
71106 assert.ok(!invalid.clone().isValid(), 'invalid.clone is invalid');
71107 assert.ok(isNaN(invalid.diff(valid)), 'invalid.diff(valid) is NaN');
71108 assert.ok(isNaN(valid.diff(invalid)), 'valid.diff(invalid) is NaN');
71109 assert.ok(isNaN(invalid.diff(invalid)), 'invalid.diff(invalid) is NaN');
71110 assert.ok(!invalid.clone().endOf('month').isValid(), 'invalid.endOf is invalid');
71111 assert.equal(invalid.format(), 'Invalid date', 'invalid.format is \'Invalid date\'');
71112 assert.equal(invalid.from(), 'Invalid date');
71113 assert.equal(invalid.from(valid), 'Invalid date');
71114 assert.equal(valid.from(invalid), 'Invalid date');
71115 assert.equal(invalid.fromNow(), 'Invalid date');
71116 assert.equal(invalid.to(), 'Invalid date');
71117 assert.equal(invalid.to(valid), 'Invalid date');
71118 assert.equal(valid.to(invalid), 'Invalid date');
71119 assert.equal(invalid.toNow(), 'Invalid date');
71120 assert.ok(isNaN(invalid.get('year')), 'invalid.get is NaN');
71121 // TODO invalidAt
71122 assert.ok(!invalid.isAfter(valid));
71123 assert.ok(!valid.isAfter(invalid));
71124 assert.ok(!invalid.isAfter(invalid));
71125 assert.ok(!invalid.isBefore(valid));
71126 assert.ok(!valid.isBefore(invalid));
71127 assert.ok(!invalid.isBefore(invalid));
71128 assert.ok(!invalid.isBetween(valid, valid));
71129 assert.ok(!valid.isBetween(invalid, valid));
71130 assert.ok(!valid.isBetween(valid, invalid));
71131 assert.ok(!invalid.isSame(invalid));
71132 assert.ok(!invalid.isSame(valid));
71133 assert.ok(!valid.isSame(invalid));
71134 assert.ok(!invalid.isValid());
71135 assert.equal(invalid.locale(), 'en');
71136 assert.equal(invalid.localeData()._abbr, 'en');
71137 assert.ok(!invalid.clone().max(valid).isValid());
71138 assert.ok(!valid.clone().max(invalid).isValid());
71139 assert.ok(!invalid.clone().max(invalid).isValid());
71140 assert.ok(!invalid.clone().min(valid).isValid());
71141 assert.ok(!valid.clone().min(invalid).isValid());
71142 assert.ok(!invalid.clone().min(invalid).isValid());
71143 assert.ok(!moment.min(invalid, valid).isValid());
71144 assert.ok(!moment.min(valid, invalid).isValid());
71145 assert.ok(!moment.max(invalid, valid).isValid());
71146 assert.ok(!moment.max(valid, invalid).isValid());
71147 assert.ok(!invalid.clone().set('year', 2005).isValid());
71148 assert.ok(!invalid.clone().startOf('month').isValid());
71149
71150 assert.ok(!invalid.clone().subtract(5, 'days').isValid());
71151 assert.deepEqual(invalid.toArray(), [NaN, NaN, NaN, NaN, NaN, NaN, NaN]);
71152 assert.deepEqual(invalid.toObject(), {
71153 years: NaN,
71154 months: NaN,
71155 date: NaN,
71156 hours: NaN,
71157 minutes: NaN,
71158 seconds: NaN,
71159 milliseconds: NaN
71160 });
71161 assert.ok(moment.isDate(invalid.toDate()));
71162 assert.ok(isNaN(invalid.toDate().valueOf()));
71163 assert.equal(invalid.toJSON(), null);
71164 assert.equal(invalid.toString(), 'Invalid date');
71165 assert.ok(isNaN(invalid.unix()));
71166 assert.ok(isNaN(invalid.valueOf()));
71167
71168 assert.ok(isNaN(invalid.year()));
71169 assert.ok(isNaN(invalid.weekYear()));
71170 assert.ok(isNaN(invalid.isoWeekYear()));
71171 assert.ok(isNaN(invalid.quarter()));
71172 assert.ok(isNaN(invalid.quarters()));
71173 assert.ok(isNaN(invalid.month()));
71174 assert.ok(isNaN(invalid.daysInMonth()));
71175 assert.ok(isNaN(invalid.week()));
71176 assert.ok(isNaN(invalid.weeks()));
71177 assert.ok(isNaN(invalid.isoWeek()));
71178 assert.ok(isNaN(invalid.isoWeeks()));
71179 assert.ok(isNaN(invalid.weeksInYear()));
71180 assert.ok(isNaN(invalid.isoWeeksInYear()));
71181 assert.ok(isNaN(invalid.date()));
71182 assert.ok(isNaN(invalid.day()));
71183 assert.ok(isNaN(invalid.days()));
71184 assert.ok(isNaN(invalid.weekday()));
71185 assert.ok(isNaN(invalid.isoWeekday()));
71186 assert.ok(isNaN(invalid.dayOfYear()));
71187 assert.ok(isNaN(invalid.hour()));
71188 assert.ok(isNaN(invalid.hours()));
71189 assert.ok(isNaN(invalid.minute()));
71190 assert.ok(isNaN(invalid.minutes()));
71191 assert.ok(isNaN(invalid.second()));
71192 assert.ok(isNaN(invalid.seconds()));
71193 assert.ok(isNaN(invalid.millisecond()));
71194 assert.ok(isNaN(invalid.milliseconds()));
71195 assert.ok(isNaN(invalid.utcOffset()));
71196
71197 assert.ok(!invalid.clone().year(2001).isValid());
71198 assert.ok(!invalid.clone().weekYear(2001).isValid());
71199 assert.ok(!invalid.clone().isoWeekYear(2001).isValid());
71200 assert.ok(!invalid.clone().quarter(1).isValid());
71201 assert.ok(!invalid.clone().quarters(1).isValid());
71202 assert.ok(!invalid.clone().month(1).isValid());
71203 assert.ok(!invalid.clone().week(1).isValid());
71204 assert.ok(!invalid.clone().weeks(1).isValid());
71205 assert.ok(!invalid.clone().isoWeek(1).isValid());
71206 assert.ok(!invalid.clone().isoWeeks(1).isValid());
71207 assert.ok(!invalid.clone().date(1).isValid());
71208 assert.ok(!invalid.clone().day(1).isValid());
71209 assert.ok(!invalid.clone().days(1).isValid());
71210 assert.ok(!invalid.clone().weekday(1).isValid());
71211 assert.ok(!invalid.clone().isoWeekday(1).isValid());
71212 assert.ok(!invalid.clone().dayOfYear(1).isValid());
71213 assert.ok(!invalid.clone().hour(1).isValid());
71214 assert.ok(!invalid.clone().hours(1).isValid());
71215 assert.ok(!invalid.clone().minute(1).isValid());
71216 assert.ok(!invalid.clone().minutes(1).isValid());
71217 assert.ok(!invalid.clone().second(1).isValid());
71218 assert.ok(!invalid.clone().seconds(1).isValid());
71219 assert.ok(!invalid.clone().millisecond(1).isValid());
71220 assert.ok(!invalid.clone().milliseconds(1).isValid());
71221 assert.ok(!invalid.clone().utcOffset(1).isValid());
71222
71223 assert.ok(!invalid.clone().utc().isValid());
71224 assert.ok(!invalid.clone().local().isValid());
71225 assert.ok(!invalid.clone().parseZone('05:30').isValid());
71226 assert.ok(!invalid.hasAlignedHourOffset());
71227 assert.ok(!invalid.isDST());
71228 assert.ok(!invalid.isDSTShifted());
71229 assert.ok(!invalid.isLocal());
71230 assert.ok(!invalid.isUtcOffset());
71231 assert.ok(!invalid.isUtc());
71232 assert.ok(!invalid.isUTC());
71233
71234 assert.ok(!invalid.isLeapYear());
71235
71236 assert.equal(moment.duration({from: invalid, to: valid}).asMilliseconds(), 0);
71237 assert.equal(moment.duration({from: valid, to: invalid}).asMilliseconds(), 0);
71238 assert.equal(moment.duration({from: invalid, to: invalid}).asMilliseconds(), 0);
71239 }
73f3c911 71240 });
516f5f67 71241
73f3c911 71242})));
516f5f67 71243
516f5f67 71244
73f3c911
IC
71245;(function (global, factory) {
71246 typeof exports === 'object' && typeof module !== 'undefined'
71247 && typeof require === 'function' ? factory(require('../../moment')) :
71248 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
71249 factory(global.moment)
71250}(this, (function (moment) { 'use strict';
516f5f67 71251
db71a655
KM
71252 function each(array, callback) {
71253 var i;
71254 for (i = 0; i < array.length; i++) {
71255 callback(array[i], i, array);
71256 }
73f3c911 71257 }
516f5f67 71258
db71a655
KM
71259 function setupDeprecationHandler(test, moment$$1, scope) {
71260 test._expectedDeprecations = null;
71261 test._observedDeprecations = null;
71262 test._oldSupress = moment$$1.suppressDeprecationWarnings;
71263 moment$$1.suppressDeprecationWarnings = true;
71264 test.expectedDeprecations = function () {
71265 test._expectedDeprecations = arguments;
71266 test._observedDeprecations = [];
71267 };
71268 moment$$1.deprecationHandler = function (name, msg) {
71269 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
71270 if (deprecationId === -1) {
71271 throw new Error('Unexpected deprecation thrown name=' +
71272 name + ' msg=' + msg);
71273 }
71274 test._observedDeprecations[deprecationId] = 1;
71275 };
71276 }
516f5f67 71277
db71a655
KM
71278 function teardownDeprecationHandler(test, moment$$1, scope) {
71279 moment$$1.suppressDeprecationWarnings = test._oldSupress;
1d986a17 71280
db71a655
KM
71281 if (test._expectedDeprecations != null) {
71282 var missedDeprecations = [];
71283 each(test._expectedDeprecations, function (deprecationPattern, id) {
71284 if (test._observedDeprecations[id] !== 1) {
71285 missedDeprecations.push(deprecationPattern);
71286 }
71287 });
71288 if (missedDeprecations.length !== 0) {
71289 throw new Error('Expected deprecation warnings did not happen: ' +
71290 missedDeprecations.join(' '));
73f3c911 71291 }
73f3c911
IC
71292 }
71293 }
1d986a17 71294
db71a655
KM
71295 function matchedDeprecation(name, msg, deprecations) {
71296 if (deprecations == null) {
71297 return -1;
73f3c911 71298 }
db71a655
KM
71299 for (var i = 0; i < deprecations.length; ++i) {
71300 if (name != null && name === deprecations[i]) {
71301 return i;
71302 }
71303 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
71304 return i;
71305 }
73f3c911 71306 }
db71a655 71307 return -1;
73f3c911 71308 }
c74a101d 71309
db71a655 71310 /*global QUnit:false*/
c74a101d 71311
db71a655 71312 var test = QUnit.test;
c74a101d 71313
db71a655
KM
71314 function module$1 (name, lifecycle) {
71315 QUnit.module(name, {
c58511b9 71316 beforeEach : function () {
db71a655
KM
71317 moment.locale('en');
71318 moment.createFromInputFallback = function (config) {
71319 throw new Error('input not handled by moment: ' + config._i);
71320 };
71321 setupDeprecationHandler(test, moment, 'core');
71322 if (lifecycle && lifecycle.setup) {
71323 lifecycle.setup();
71324 }
71325 },
c58511b9 71326 afterEach : function () {
db71a655
KM
71327 teardownDeprecationHandler(test, moment, 'core');
71328 if (lifecycle && lifecycle.teardown) {
71329 lifecycle.teardown();
71330 }
73f3c911 71331 }
db71a655
KM
71332 });
71333 }
9483e2a4 71334
db71a655
KM
71335 module$1('is after');
71336
71337 test('is after without units', function (assert) {
71338 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
71339 assert.equal(m.isAfter(moment(new Date(2012, 3, 2, 3, 5, 5, 10))), false, 'year is later');
71340 assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 3, 5, 10))), true, 'year is earlier');
71341 assert.equal(m.isAfter(moment(new Date(2011, 4, 2, 3, 4, 5, 10))), false, 'month is later');
71342 assert.equal(m.isAfter(moment(new Date(2011, 2, 2, 3, 4, 5, 10))), true, 'month is earlier');
71343 assert.equal(m.isAfter(moment(new Date(2011, 3, 3, 3, 4, 5, 10))), false, 'day is later');
71344 assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 3, 4, 5, 10))), true, 'day is earlier');
71345 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 4, 4, 5, 10))), false, 'hour is later');
71346 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 2, 4, 5, 10))), true, 'hour is earlier');
71347 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 5, 5, 10))), false, 'minute is later');
71348 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 3, 5, 10))), true, 'minute is earlier');
71349 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 6, 10))), false, 'second is later');
71350 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 4, 11))), true, 'second is earlier');
71351 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'millisecond match');
71352 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 11))), false, 'millisecond is later');
71353 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 9))), true, 'millisecond is earlier');
71354 assert.equal(m.isAfter(m), false, 'moments are not after themselves');
71355 assert.equal(+m, +mCopy, 'isAfter second should not change moment');
71356 });
71357
71358 test('is after year', function (assert) {
71359 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
71360 assert.equal(m.isAfter(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year match');
71361 assert.equal(m.isAfter(moment(new Date(2010, 5, 6, 7, 8, 9, 10)), 'years'), true, 'plural should work');
71362 assert.equal(m.isAfter(moment(new Date(2013, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year is later');
71363 assert.equal(m.isAfter(moment(new Date(2010, 5, 6, 7, 8, 9, 10)), 'year'), true, 'year is earlier');
71364 assert.equal(m.isAfter(moment(new Date(2011, 0, 1, 0, 0, 0, 0)), 'year'), false, 'exact start of year');
71365 assert.equal(m.isAfter(moment(new Date(2011, 11, 31, 23, 59, 59, 999)), 'year'), false, 'exact end of year');
71366 assert.equal(m.isAfter(moment(new Date(2012, 0, 1, 0, 0, 0, 0)), 'year'), false, 'start of next year');
71367 assert.equal(m.isAfter(moment(new Date(2010, 11, 31, 23, 59, 59, 999)), 'year'), true, 'end of previous year');
71368 assert.equal(m.isAfter(moment(new Date(1980, 11, 31, 23, 59, 59, 999)), 'year'), true, 'end of year far before');
71369 assert.equal(m.isAfter(m, 'year'), false, 'same moments are not after the same year');
71370 assert.equal(+m, +mCopy, 'isAfter year should not change moment');
71371 });
71372
71373 test('is after month', function (assert) {
71374 var m = moment(new Date(2011, 2, 3, 4, 5, 6, 7)), mCopy = moment(m);
71375 assert.equal(m.isAfter(moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'month'), false, 'month match');
71376 assert.equal(m.isAfter(moment(new Date(2010, 2, 6, 7, 8, 9, 10)), 'months'), true, 'plural should work');
71377 assert.equal(m.isAfter(moment(new Date(2012, 2, 6, 7, 8, 9, 10)), 'month'), false, 'year is later');
71378 assert.equal(m.isAfter(moment(new Date(2010, 2, 6, 7, 8, 9, 10)), 'month'), true, 'year is earlier');
71379 assert.equal(m.isAfter(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'month'), false, 'month is later');
71380 assert.equal(m.isAfter(moment(new Date(2011, 1, 6, 7, 8, 9, 10)), 'month'), true, 'month is earlier');
71381 assert.equal(m.isAfter(moment(new Date(2011, 2, 1, 0, 0, 0, 0)), 'month'), false, 'exact start of month');
71382 assert.equal(m.isAfter(moment(new Date(2011, 2, 31, 23, 59, 59, 999)), 'month'), false, 'exact end of month');
71383 assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 0, 0, 0, 0)), 'month'), false, 'start of next month');
71384 assert.equal(m.isAfter(moment(new Date(2011, 1, 27, 23, 59, 59, 999)), 'month'), true, 'end of previous month');
71385 assert.equal(m.isAfter(moment(new Date(2010, 12, 31, 23, 59, 59, 999)), 'month'), true, 'later month but earlier year');
71386 assert.equal(m.isAfter(m, 'month'), false, 'same moments are not after the same month');
71387 assert.equal(+m, +mCopy, 'isAfter month should not change moment');
71388 });
71389
71390 test('is after day', function (assert) {
71391 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 6)), mCopy = moment(m);
71392 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 7, 8, 9, 10)), 'day'), false, 'day match');
71393 assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 7, 8, 9, 10)), 'days'), true, 'plural should work');
71394 assert.equal(m.isAfter(moment(new Date(2012, 3, 2, 7, 8, 9, 10)), 'day'), false, 'year is later');
71395 assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 7, 8, 9, 10)), 'day'), true, 'year is earlier');
71396 assert.equal(m.isAfter(moment(new Date(2011, 4, 2, 7, 8, 9, 10)), 'day'), false, 'month is later');
71397 assert.equal(m.isAfter(moment(new Date(2011, 2, 2, 7, 8, 9, 10)), 'day'), true, 'month is earlier');
71398 assert.equal(m.isAfter(moment(new Date(2011, 3, 3, 7, 8, 9, 10)), 'day'), false, 'day is later');
71399 assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 7, 8, 9, 10)), 'day'), true, 'day is earlier');
71400 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 0, 0, 0, 0)), 'day'), false, 'exact start of day');
71401 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 23, 59, 59, 999)), 'day'), false, 'exact end of day');
71402 assert.equal(m.isAfter(moment(new Date(2011, 3, 3, 0, 0, 0, 0)), 'day'), false, 'start of next day');
71403 assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 23, 59, 59, 999)), 'day'), true, 'end of previous day');
71404 assert.equal(m.isAfter(moment(new Date(2010, 3, 10, 0, 0, 0, 0)), 'day'), true, 'later day but earlier year');
71405 assert.equal(m.isAfter(m, 'day'), false, 'same moments are not after the same day');
71406 assert.equal(+m, +mCopy, 'isAfter day should not change moment');
71407 });
71408
71409 test('is after hour', function (assert) {
71410 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 6)), mCopy = moment(m);
71411 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 8, 9, 10)), 'hour'), false, 'hour match');
71412 assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 8, 9, 10)), 'hours'), true, 'plural should work');
71413 assert.equal(m.isAfter(moment(new Date(2012, 3, 2, 3, 8, 9, 10)), 'hour'), false, 'year is later');
71414 assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 8, 9, 10)), 'hour'), true, 'year is earlier');
71415 assert.equal(m.isAfter(moment(new Date(2011, 4, 2, 3, 8, 9, 10)), 'hour'), false, 'month is later');
71416 assert.equal(m.isAfter(moment(new Date(2011, 1, 2, 3, 8, 9, 10)), 'hour'), true, 'month is earlier');
71417 assert.equal(m.isAfter(moment(new Date(2011, 3, 3, 3, 8, 9, 10)), 'hour'), false, 'day is later');
71418 assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 3, 8, 9, 10)), 'hour'), true, 'day is earlier');
71419 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 4, 8, 9, 10)), 'hour'), false, 'hour is later');
71420 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 8, 9, 10)), 'hour'), false, 'hour is earlier');
71421 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 0, 0, 0)), 'hour'), false, 'exact start of hour');
71422 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 59, 59, 999)), 'hour'), false, 'exact end of hour');
71423 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 4, 0, 0, 0)), 'hour'), false, 'start of next hour');
71424 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 2, 59, 59, 999)), 'hour'), true, 'end of previous hour');
71425 assert.equal(m.isAfter(m, 'hour'), false, 'same moments are not after the same hour');
71426 assert.equal(+m, +mCopy, 'isAfter hour should not change moment');
71427 });
71428
71429 test('is after minute', function (assert) {
71430 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 6)), mCopy = moment(m);
71431 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 9, 10)), 'minute'), false, 'minute match');
71432 assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 4, 9, 10)), 'minutes'), true, 'plural should work');
71433 assert.equal(m.isAfter(moment(new Date(2012, 3, 2, 3, 4, 9, 10)), 'minute'), false, 'year is later');
71434 assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 4, 9, 10)), 'minute'), true, 'year is earlier');
71435 assert.equal(m.isAfter(moment(new Date(2011, 4, 2, 3, 4, 9, 10)), 'minute'), false, 'month is later');
71436 assert.equal(m.isAfter(moment(new Date(2011, 2, 2, 3, 4, 9, 10)), 'minute'), true, 'month is earlier');
71437 assert.equal(m.isAfter(moment(new Date(2011, 3, 3, 3, 4, 9, 10)), 'minute'), false, 'day is later');
71438 assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 3, 4, 9, 10)), 'minute'), true, 'day is earlier');
71439 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 4, 4, 9, 10)), 'minute'), false, 'hour is later');
71440 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 2, 4, 9, 10)), 'minute'), true, 'hour is earler');
71441 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 5, 9, 10)), 'minute'), false, 'minute is later');
71442 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 3, 9, 10)), 'minute'), true, 'minute is earlier');
71443 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 0, 0)), 'minute'), false, 'exact start of minute');
71444 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 59, 999)), 'minute'), false, 'exact end of minute');
71445 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 5, 0, 0)), 'minute'), false, 'start of next minute');
71446 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 3, 59, 999)), 'minute'), true, 'end of previous minute');
71447 assert.equal(m.isAfter(m, 'minute'), false, 'same moments are not after the same minute');
71448 assert.equal(+m, +mCopy, 'isAfter minute should not change moment');
71449 });
71450
71451 test('is after second', function (assert) {
71452 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
71453 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'second'), false, 'second match');
71454 assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'seconds'), true, 'plural should work');
71455 assert.equal(m.isAfter(moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'second'), false, 'year is later');
71456 assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'second'), true, 'year is earlier');
71457 assert.equal(m.isAfter(moment(new Date(2011, 4, 2, 3, 4, 5, 10)), 'second'), false, 'month is later');
71458 assert.equal(m.isAfter(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'second'), true, 'month is earlier');
71459 assert.equal(m.isAfter(moment(new Date(2011, 3, 3, 3, 4, 5, 10)), 'second'), false, 'day is later');
71460 assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 1, 4, 5, 10)), 'second'), true, 'day is earlier');
71461 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 4, 4, 5, 10)), 'second'), false, 'hour is later');
71462 assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 4, 1, 5, 10)), 'second'), true, 'hour is earlier');
71463 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 5, 5, 10)), 'second'), false, 'minute is later');
71464 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 3, 5, 10)), 'second'), true, 'minute is earlier');
71465 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 6, 10)), 'second'), false, 'second is later');
71466 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 4, 5)), 'second'), true, 'second is earlier');
71467 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 0)), 'second'), false, 'exact start of second');
71468 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 999)), 'second'), false, 'exact end of second');
71469 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 6, 0)), 'second'), false, 'start of next second');
71470 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 4, 999)), 'second'), true, 'end of previous second');
71471 assert.equal(m.isAfter(m, 'second'), false, 'same moments are not after the same second');
71472 assert.equal(+m, +mCopy, 'isAfter second should not change moment');
71473 });
71474
71475 test('is after millisecond', function (assert) {
71476 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
71477 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'millisecond'), false, 'millisecond match');
71478 assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'milliseconds'), true, 'plural should work');
71479 assert.equal(m.isAfter(moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'millisecond'), false, 'year is later');
71480 assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'millisecond'), true, 'year is earlier');
71481 assert.equal(m.isAfter(moment(new Date(2011, 4, 2, 3, 4, 5, 10)), 'millisecond'), false, 'month is later');
71482 assert.equal(m.isAfter(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'millisecond'), true, 'month is earlier');
71483 assert.equal(m.isAfter(moment(new Date(2011, 3, 3, 3, 4, 5, 10)), 'millisecond'), false, 'day is later');
71484 assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 1, 4, 5, 10)), 'millisecond'), true, 'day is earlier');
71485 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 4, 4, 5, 10)), 'millisecond'), false, 'hour is later');
71486 assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 4, 1, 5, 10)), 'millisecond'), true, 'hour is earlier');
71487 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 5, 5, 10)), 'millisecond'), false, 'minute is later');
71488 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 3, 5, 10)), 'millisecond'), true, 'minute is earlier');
71489 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 6, 10)), 'millisecond'), false, 'second is later');
71490 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 4, 5)), 'millisecond'), true, 'second is earlier');
71491 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 6, 11)), 'millisecond'), false, 'millisecond is later');
71492 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 4, 9)), 'millisecond'), true, 'millisecond is earlier');
71493 assert.equal(m.isAfter(m, 'millisecond'), false, 'same moments are not after the same millisecond');
71494 assert.equal(+m, +mCopy, 'isAfter millisecond should not change moment');
71495 });
71496
71497 test('is after invalid', function (assert) {
71498 var m = moment(), invalid = moment.invalid();
71499 assert.equal(m.isAfter(invalid), false, 'valid moment is not after invalid moment');
71500 assert.equal(invalid.isAfter(m), false, 'invalid moment is not after valid moment');
71501 assert.equal(m.isAfter(invalid, 'year'), false, 'invalid moment year');
71502 assert.equal(m.isAfter(invalid, 'month'), false, 'invalid moment month');
71503 assert.equal(m.isAfter(invalid, 'day'), false, 'invalid moment day');
71504 assert.equal(m.isAfter(invalid, 'hour'), false, 'invalid moment hour');
71505 assert.equal(m.isAfter(invalid, 'minute'), false, 'invalid moment minute');
71506 assert.equal(m.isAfter(invalid, 'second'), false, 'invalid moment second');
71507 assert.equal(m.isAfter(invalid, 'milliseconds'), false, 'invalid moment milliseconds');
71508 });
9483e2a4 71509
db71a655 71510})));
9483e2a4 71511
f2af24d5 71512
db71a655
KM
71513;(function (global, factory) {
71514 typeof exports === 'object' && typeof module !== 'undefined'
71515 && typeof require === 'function' ? factory(require('../../moment')) :
71516 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
71517 factory(global.moment)
71518}(this, (function (moment) { 'use strict';
f2af24d5 71519
db71a655 71520 /*global QUnit:false*/
d731fe7e 71521
db71a655 71522 var test = QUnit.test;
d6651c21 71523
db71a655
KM
71524 function isArray(input) {
71525 return input instanceof Array || Object.prototype.toString.call(input) === '[object Array]';
f2af24d5 71526 }
db71a655
KM
71527
71528 test('isArray recognizes Array objects', function (assert) {
71529 assert.ok(isArray([1,2,3]), 'array args');
71530 assert.ok(isArray([]), 'empty array');
71531 assert.ok(isArray(new Array(1,2,3)), 'array constructor');
71532 });
71533
71534 test('isArray rejects non-Array objects', function (assert) {
71535 assert.ok(!isArray(), 'nothing');
71536 assert.ok(!isArray(undefined), 'undefined');
71537 assert.ok(!isArray(null), 'null');
71538 assert.ok(!isArray(123), 'number');
71539 assert.ok(!isArray('[1,2,3]'), 'string');
71540 assert.ok(!isArray(new Date()), 'date');
71541 assert.ok(!isArray({a:1,b:2}), 'object');
71542 });
f2af24d5 71543
73f3c911 71544})));
d6651c21 71545
c74a101d
IC
71546
71547;(function (global, factory) {
71548 typeof exports === 'object' && typeof module !== 'undefined'
71549 && typeof require === 'function' ? factory(require('../../moment')) :
71550 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
71551 factory(global.moment)
73f3c911 71552}(this, (function (moment) { 'use strict';
c74a101d 71553
db71a655
KM
71554 function each(array, callback) {
71555 var i;
71556 for (i = 0; i < array.length; i++) {
71557 callback(array[i], i, array);
71558 }
b135bf1a
IC
71559 }
71560
db71a655
KM
71561 function setupDeprecationHandler(test, moment$$1, scope) {
71562 test._expectedDeprecations = null;
71563 test._observedDeprecations = null;
71564 test._oldSupress = moment$$1.suppressDeprecationWarnings;
71565 moment$$1.suppressDeprecationWarnings = true;
71566 test.expectedDeprecations = function () {
71567 test._expectedDeprecations = arguments;
71568 test._observedDeprecations = [];
71569 };
71570 moment$$1.deprecationHandler = function (name, msg) {
71571 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
71572 if (deprecationId === -1) {
71573 throw new Error('Unexpected deprecation thrown name=' +
71574 name + ' msg=' + msg);
71575 }
71576 test._observedDeprecations[deprecationId] = 1;
71577 };
71578 }
73f3c911 71579
db71a655
KM
71580 function teardownDeprecationHandler(test, moment$$1, scope) {
71581 moment$$1.suppressDeprecationWarnings = test._oldSupress;
73f3c911 71582
db71a655
KM
71583 if (test._expectedDeprecations != null) {
71584 var missedDeprecations = [];
71585 each(test._expectedDeprecations, function (deprecationPattern, id) {
71586 if (test._observedDeprecations[id] !== 1) {
71587 missedDeprecations.push(deprecationPattern);
71588 }
71589 });
71590 if (missedDeprecations.length !== 0) {
71591 throw new Error('Expected deprecation warnings did not happen: ' +
71592 missedDeprecations.join(' '));
d6651c21
IC
71593 }
71594 }
73f3c911 71595 }
73f3c911 71596
db71a655
KM
71597 function matchedDeprecation(name, msg, deprecations) {
71598 if (deprecations == null) {
71599 return -1;
73f3c911 71600 }
db71a655
KM
71601 for (var i = 0; i < deprecations.length; ++i) {
71602 if (name != null && name === deprecations[i]) {
71603 return i;
c74a101d 71604 }
db71a655
KM
71605 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
71606 return i;
c74a101d 71607 }
73f3c911 71608 }
db71a655
KM
71609 return -1;
71610 }
c74a101d 71611
db71a655 71612 /*global QUnit:false*/
c74a101d 71613
db71a655 71614 var test = QUnit.test;
c74a101d 71615
db71a655
KM
71616 function module$1 (name, lifecycle) {
71617 QUnit.module(name, {
c58511b9 71618 beforeEach : function () {
db71a655
KM
71619 moment.locale('en');
71620 moment.createFromInputFallback = function (config) {
71621 throw new Error('input not handled by moment: ' + config._i);
71622 };
71623 setupDeprecationHandler(test, moment, 'core');
71624 if (lifecycle && lifecycle.setup) {
71625 lifecycle.setup();
71626 }
71627 },
c58511b9 71628 afterEach : function () {
db71a655
KM
71629 teardownDeprecationHandler(test, moment, 'core');
71630 if (lifecycle && lifecycle.teardown) {
71631 lifecycle.teardown();
71632 }
71633 }
71634 });
71635 }
c74a101d 71636
db71a655
KM
71637 module$1('is before');
71638
71639 test('is after without units', function (assert) {
71640 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
71641 assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 5, 5, 10))), true, 'year is later');
71642 assert.equal(m.isBefore(moment(new Date(2010, 3, 2, 3, 3, 5, 10))), false, 'year is earlier');
71643 assert.equal(m.isBefore(moment(new Date(2011, 4, 2, 3, 4, 5, 10))), true, 'month is later');
71644 assert.equal(m.isBefore(moment(new Date(2011, 2, 2, 3, 4, 5, 10))), false, 'month is earlier');
71645 assert.equal(m.isBefore(moment(new Date(2011, 3, 3, 3, 4, 5, 10))), true, 'day is later');
71646 assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 3, 4, 5, 10))), false, 'day is earlier');
71647 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 4, 4, 5, 10))), true, 'hour is later');
71648 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 2, 4, 5, 10))), false, 'hour is earlier');
71649 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 5, 5, 10))), true, 'minute is later');
71650 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 3, 5, 10))), false, 'minute is earlier');
71651 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 6, 10))), true, 'second is later');
71652 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 4, 11))), false, 'second is earlier');
71653 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'millisecond match');
71654 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 11))), true, 'millisecond is later');
71655 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 9))), false, 'millisecond is earlier');
71656 assert.equal(m.isBefore(m), false, 'moments are not before themselves');
71657 assert.equal(+m, +mCopy, 'isBefore second should not change moment');
71658 });
71659
71660 test('is before year', function (assert) {
71661 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
71662 assert.equal(m.isBefore(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year match');
71663 assert.equal(m.isBefore(moment(new Date(2012, 5, 6, 7, 8, 9, 10)), 'years'), true, 'plural should work');
71664 assert.equal(m.isBefore(moment(new Date(2013, 5, 6, 7, 8, 9, 10)), 'year'), true, 'year is later');
71665 assert.equal(m.isBefore(moment(new Date(2010, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year is earlier');
71666 assert.equal(m.isBefore(moment(new Date(2011, 0, 1, 0, 0, 0, 0)), 'year'), false, 'exact start of year');
71667 assert.equal(m.isBefore(moment(new Date(2011, 11, 31, 23, 59, 59, 999)), 'year'), false, 'exact end of year');
71668 assert.equal(m.isBefore(moment(new Date(2012, 0, 1, 0, 0, 0, 0)), 'year'), true, 'start of next year');
71669 assert.equal(m.isBefore(moment(new Date(2010, 11, 31, 23, 59, 59, 999)), 'year'), false, 'end of previous year');
71670 assert.equal(m.isBefore(moment(new Date(1980, 11, 31, 23, 59, 59, 999)), 'year'), false, 'end of year far before');
71671 assert.equal(m.isBefore(m, 'year'), false, 'same moments are not before the same year');
71672 assert.equal(+m, +mCopy, 'isBefore year should not change moment');
71673 });
71674
71675 test('is before month', function (assert) {
71676 var m = moment(new Date(2011, 2, 3, 4, 5, 6, 7)), mCopy = moment(m);
71677 assert.equal(m.isBefore(moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'month'), false, 'month match');
71678 assert.equal(m.isBefore(moment(new Date(2012, 2, 6, 7, 8, 9, 10)), 'months'), true, 'plural should work');
71679 assert.equal(m.isBefore(moment(new Date(2012, 2, 6, 7, 8, 9, 10)), 'month'), true, 'year is later');
71680 assert.equal(m.isBefore(moment(new Date(2010, 2, 6, 7, 8, 9, 10)), 'month'), false, 'year is earlier');
71681 assert.equal(m.isBefore(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'month'), true, 'month is later');
71682 assert.equal(m.isBefore(moment(new Date(2011, 1, 6, 7, 8, 9, 10)), 'month'), false, 'month is earlier');
71683 assert.equal(m.isBefore(moment(new Date(2011, 2, 1, 0, 0, 0, 0)), 'month'), false, 'exact start of month');
71684 assert.equal(m.isBefore(moment(new Date(2011, 2, 31, 23, 59, 59, 999)), 'month'), false, 'exact end of month');
71685 assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 0, 0, 0, 0)), 'month'), true, 'start of next month');
71686 assert.equal(m.isBefore(moment(new Date(2011, 1, 27, 23, 59, 59, 999)), 'month'), false, 'end of previous month');
71687 assert.equal(m.isBefore(moment(new Date(2010, 12, 31, 23, 59, 59, 999)), 'month'), false, 'later month but earlier year');
71688 assert.equal(m.isBefore(m, 'month'), false, 'same moments are not before the same month');
71689 assert.equal(+m, +mCopy, 'isBefore month should not change moment');
71690 });
71691
71692 test('is before day', function (assert) {
71693 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 6)), mCopy = moment(m);
71694 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 7, 8, 9, 10)), 'day'), false, 'day match');
71695 assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 7, 8, 9, 10)), 'days'), true, 'plural should work');
71696 assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 7, 8, 9, 10)), 'day'), true, 'year is later');
71697 assert.equal(m.isBefore(moment(new Date(2010, 3, 2, 7, 8, 9, 10)), 'day'), false, 'year is earlier');
71698 assert.equal(m.isBefore(moment(new Date(2011, 4, 2, 7, 8, 9, 10)), 'day'), true, 'month is later');
71699 assert.equal(m.isBefore(moment(new Date(2011, 2, 2, 7, 8, 9, 10)), 'day'), false, 'month is earlier');
71700 assert.equal(m.isBefore(moment(new Date(2011, 3, 3, 7, 8, 9, 10)), 'day'), true, 'day is later');
71701 assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 7, 8, 9, 10)), 'day'), false, 'day is earlier');
71702 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 0, 0, 0, 0)), 'day'), false, 'exact start of day');
71703 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 23, 59, 59, 999)), 'day'), false, 'exact end of day');
71704 assert.equal(m.isBefore(moment(new Date(2011, 3, 3, 0, 0, 0, 0)), 'day'), true, 'start of next day');
71705 assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 23, 59, 59, 999)), 'day'), false, 'end of previous day');
71706 assert.equal(m.isBefore(moment(new Date(2010, 3, 10, 0, 0, 0, 0)), 'day'), false, 'later day but earlier year');
71707 assert.equal(m.isBefore(m, 'day'), false, 'same moments are not before the same day');
71708 assert.equal(+m, +mCopy, 'isBefore day should not change moment');
71709 });
71710
71711 test('is before hour', function (assert) {
71712 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 6)), mCopy = moment(m);
71713 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 8, 9, 10)), 'hour'), false, 'hour match');
71714 assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 8, 9, 10)), 'hours'), true, 'plural should work');
71715 assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 8, 9, 10)), 'hour'), true, 'year is later');
71716 assert.equal(m.isBefore(moment(new Date(2010, 3, 2, 3, 8, 9, 10)), 'hour'), false, 'year is earlier');
71717 assert.equal(m.isBefore(moment(new Date(2011, 4, 2, 3, 8, 9, 10)), 'hour'), true, 'month is later');
71718 assert.equal(m.isBefore(moment(new Date(2011, 1, 2, 3, 8, 9, 10)), 'hour'), false, 'month is earlier');
71719 assert.equal(m.isBefore(moment(new Date(2011, 3, 3, 3, 8, 9, 10)), 'hour'), true, 'day is later');
71720 assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 3, 8, 9, 10)), 'hour'), false, 'day is earlier');
71721 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 4, 8, 9, 10)), 'hour'), true, 'hour is later');
71722 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 8, 9, 10)), 'hour'), false, 'hour is earlier');
71723 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 0, 0, 0)), 'hour'), false, 'exact start of hour');
71724 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 59, 59, 999)), 'hour'), false, 'exact end of hour');
71725 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 4, 0, 0, 0)), 'hour'), true, 'start of next hour');
71726 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 2, 59, 59, 999)), 'hour'), false, 'end of previous hour');
71727 assert.equal(m.isBefore(m, 'hour'), false, 'same moments are not before the same hour');
71728 assert.equal(+m, +mCopy, 'isBefore hour should not change moment');
71729 });
71730
71731 test('is before minute', function (assert) {
71732 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 6)), mCopy = moment(m);
71733 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 9, 10)), 'minute'), false, 'minute match');
71734 assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 4, 9, 10)), 'minutes'), true, 'plural should work');
71735 assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 4, 9, 10)), 'minute'), true, 'year is later');
71736 assert.equal(m.isBefore(moment(new Date(2010, 3, 2, 3, 4, 9, 10)), 'minute'), false, 'year is earlier');
71737 assert.equal(m.isBefore(moment(new Date(2011, 4, 2, 3, 4, 9, 10)), 'minute'), true, 'month is later');
71738 assert.equal(m.isBefore(moment(new Date(2011, 2, 2, 3, 4, 9, 10)), 'minute'), false, 'month is earlier');
71739 assert.equal(m.isBefore(moment(new Date(2011, 3, 3, 3, 4, 9, 10)), 'minute'), true, 'day is later');
71740 assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 3, 4, 9, 10)), 'minute'), false, 'day is earlier');
71741 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 4, 4, 9, 10)), 'minute'), true, 'hour is later');
71742 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 2, 4, 9, 10)), 'minute'), false, 'hour is earler');
71743 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 5, 9, 10)), 'minute'), true, 'minute is later');
71744 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 3, 9, 10)), 'minute'), false, 'minute is earlier');
71745 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 0, 0)), 'minute'), false, 'exact start of minute');
71746 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 59, 999)), 'minute'), false, 'exact end of minute');
71747 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 5, 0, 0)), 'minute'), true, 'start of next minute');
71748 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 3, 59, 999)), 'minute'), false, 'end of previous minute');
71749 assert.equal(m.isBefore(m, 'minute'), false, 'same moments are not before the same minute');
71750 assert.equal(+m, +mCopy, 'isBefore minute should not change moment');
71751 });
71752
71753 test('is before second', function (assert) {
71754 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
71755 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'second'), false, 'second match');
71756 assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'seconds'), true, 'plural should work');
71757 assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'second'), true, 'year is later');
71758 assert.equal(m.isBefore(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'second'), false, 'year is earlier');
71759 assert.equal(m.isBefore(moment(new Date(2011, 4, 2, 3, 4, 5, 10)), 'second'), true, 'month is later');
71760 assert.equal(m.isBefore(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'second'), false, 'month is earlier');
71761 assert.equal(m.isBefore(moment(new Date(2011, 3, 3, 3, 4, 5, 10)), 'second'), true, 'day is later');
71762 assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 1, 4, 5, 10)), 'second'), false, 'day is earlier');
71763 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 4, 4, 5, 10)), 'second'), true, 'hour is later');
71764 assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 4, 1, 5, 10)), 'second'), false, 'hour is earlier');
71765 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 5, 5, 10)), 'second'), true, 'minute is later');
71766 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 3, 5, 10)), 'second'), false, 'minute is earlier');
71767 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 6, 10)), 'second'), true, 'second is later');
71768 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 4, 5)), 'second'), false, 'second is earlier');
71769 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 0)), 'second'), false, 'exact start of second');
71770 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 999)), 'second'), false, 'exact end of second');
71771 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 6, 0)), 'second'), true, 'start of next second');
71772 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 4, 999)), 'second'), false, 'end of previous second');
71773 assert.equal(m.isBefore(m, 'second'), false, 'same moments are not before the same second');
71774 assert.equal(+m, +mCopy, 'isBefore second should not change moment');
71775 });
71776
71777 test('is before millisecond', function (assert) {
71778 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
71779 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'millisecond'), false, 'millisecond match');
71780 assert.equal(m.isBefore(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'milliseconds'), false, 'plural should work');
71781 assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'millisecond'), true, 'year is later');
71782 assert.equal(m.isBefore(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'millisecond'), false, 'year is earlier');
71783 assert.equal(m.isBefore(moment(new Date(2011, 4, 2, 3, 4, 5, 10)), 'millisecond'), true, 'month is later');
71784 assert.equal(m.isBefore(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'millisecond'), false, 'month is earlier');
71785 assert.equal(m.isBefore(moment(new Date(2011, 3, 3, 3, 4, 5, 10)), 'millisecond'), true, 'day is later');
71786 assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 1, 4, 5, 10)), 'millisecond'), false, 'day is earlier');
71787 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 4, 4, 5, 10)), 'millisecond'), true, 'hour is later');
71788 assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 4, 1, 5, 10)), 'millisecond'), false, 'hour is earlier');
71789 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 5, 5, 10)), 'millisecond'), true, 'minute is later');
71790 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 3, 5, 10)), 'millisecond'), false, 'minute is earlier');
71791 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 6, 10)), 'millisecond'), true, 'second is later');
71792 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 4, 5)), 'millisecond'), false, 'second is earlier');
71793 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 6, 11)), 'millisecond'), true, 'millisecond is later');
71794 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 4, 9)), 'millisecond'), false, 'millisecond is earlier');
71795 assert.equal(m.isBefore(m, 'millisecond'), false, 'same moments are not before the same millisecond');
71796 assert.equal(+m, +mCopy, 'isBefore millisecond should not change moment');
71797 });
71798
71799 test('is before invalid', function (assert) {
71800 var m = moment(), invalid = moment.invalid();
71801 assert.equal(m.isBefore(invalid), false, 'valid moment is not before invalid moment');
71802 assert.equal(invalid.isBefore(m), false, 'invalid moment is not before valid moment');
71803 assert.equal(m.isBefore(invalid, 'year'), false, 'invalid moment year');
71804 assert.equal(m.isBefore(invalid, 'month'), false, 'invalid moment month');
71805 assert.equal(m.isBefore(invalid, 'day'), false, 'invalid moment day');
71806 assert.equal(m.isBefore(invalid, 'hour'), false, 'invalid moment hour');
71807 assert.equal(m.isBefore(invalid, 'minute'), false, 'invalid moment minute');
71808 assert.equal(m.isBefore(invalid, 'second'), false, 'invalid moment second');
71809 assert.equal(m.isBefore(invalid, 'milliseconds'), false, 'invalid moment milliseconds');
71810 });
73f3c911
IC
71811
71812})));
c74a101d 71813
516f5f67 71814
c74a101d
IC
71815;(function (global, factory) {
71816 typeof exports === 'object' && typeof module !== 'undefined'
71817 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
71818 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
71819 factory(global.moment)
73f3c911 71820}(this, (function (moment) { 'use strict';
516f5f67 71821
db71a655
KM
71822 function each(array, callback) {
71823 var i;
71824 for (i = 0; i < array.length; i++) {
71825 callback(array[i], i, array);
71826 }
b135bf1a
IC
71827 }
71828
db71a655
KM
71829 function setupDeprecationHandler(test, moment$$1, scope) {
71830 test._expectedDeprecations = null;
71831 test._observedDeprecations = null;
71832 test._oldSupress = moment$$1.suppressDeprecationWarnings;
71833 moment$$1.suppressDeprecationWarnings = true;
71834 test.expectedDeprecations = function () {
71835 test._expectedDeprecations = arguments;
71836 test._observedDeprecations = [];
71837 };
71838 moment$$1.deprecationHandler = function (name, msg) {
71839 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
71840 if (deprecationId === -1) {
71841 throw new Error('Unexpected deprecation thrown name=' +
71842 name + ' msg=' + msg);
71843 }
71844 test._observedDeprecations[deprecationId] = 1;
71845 };
71846 }
73f3c911 71847
db71a655
KM
71848 function teardownDeprecationHandler(test, moment$$1, scope) {
71849 moment$$1.suppressDeprecationWarnings = test._oldSupress;
73f3c911 71850
db71a655
KM
71851 if (test._expectedDeprecations != null) {
71852 var missedDeprecations = [];
71853 each(test._expectedDeprecations, function (deprecationPattern, id) {
71854 if (test._observedDeprecations[id] !== 1) {
71855 missedDeprecations.push(deprecationPattern);
71856 }
71857 });
71858 if (missedDeprecations.length !== 0) {
71859 throw new Error('Expected deprecation warnings did not happen: ' +
71860 missedDeprecations.join(' '));
d6651c21
IC
71861 }
71862 }
73f3c911 71863 }
73f3c911 71864
db71a655
KM
71865 function matchedDeprecation(name, msg, deprecations) {
71866 if (deprecations == null) {
71867 return -1;
73f3c911 71868 }
db71a655
KM
71869 for (var i = 0; i < deprecations.length; ++i) {
71870 if (name != null && name === deprecations[i]) {
71871 return i;
516f5f67 71872 }
db71a655
KM
71873 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
71874 return i;
516f5f67 71875 }
73f3c911 71876 }
db71a655
KM
71877 return -1;
71878 }
9483e2a4 71879
db71a655 71880 /*global QUnit:false*/
9483e2a4 71881
db71a655 71882 var test = QUnit.test;
9483e2a4 71883
db71a655
KM
71884 function module$1 (name, lifecycle) {
71885 QUnit.module(name, {
c58511b9 71886 beforeEach : function () {
db71a655
KM
71887 moment.locale('en');
71888 moment.createFromInputFallback = function (config) {
71889 throw new Error('input not handled by moment: ' + config._i);
71890 };
71891 setupDeprecationHandler(test, moment, 'core');
71892 if (lifecycle && lifecycle.setup) {
71893 lifecycle.setup();
71894 }
71895 },
c58511b9 71896 afterEach : function () {
db71a655
KM
71897 teardownDeprecationHandler(test, moment, 'core');
71898 if (lifecycle && lifecycle.teardown) {
71899 lifecycle.teardown();
71900 }
71901 }
71902 });
9483e2a4 71903 }
9483e2a4 71904
db71a655
KM
71905 module$1('is between');
71906
71907 test('is between without units', function (assert) {
71908 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
71909 assert.equal(m.isBetween(
71910 moment(new Date(2009, 3, 2, 3, 4, 5, 10)),
71911 moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'year is later');
71912 assert.equal(m.isBetween(
71913 moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
71914 moment(new Date(2013, 3, 2, 3, 4, 5, 10))), false, 'year is earlier');
71915 assert.equal(m.isBetween(
71916 moment(new Date(2010, 3, 2, 3, 4, 5, 10)),
71917 moment(new Date(2012, 3, 2, 3, 4, 5, 10))), true, 'year is between');
71918 assert.equal(m.isBetween(
71919 moment(new Date(2011, 1, 2, 3, 4, 5, 10)),
71920 moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'month is later');
71921 assert.equal(m.isBetween(
71922 moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
71923 moment(new Date(2011, 5, 2, 3, 4, 5, 10))), false, 'month is earlier');
71924 assert.equal(m.isBetween(
71925 moment(new Date(2011, 2, 2, 3, 4, 5, 10)),
71926 moment(new Date(2011, 4, 2, 3, 4, 5, 10))), true, 'month is between');
71927 assert.equal(m.isBetween(
71928 moment(new Date(2011, 3, 1, 3, 4, 5, 10)),
71929 moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'day is later');
71930 assert.equal(m.isBetween(
71931 moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
71932 moment(new Date(2011, 3, 4, 3, 4, 5, 10))), false, 'day is earlier');
71933 assert.equal(m.isBetween(
71934 moment(new Date(2011, 3, 1, 3, 4, 5, 10)),
71935 moment(new Date(2011, 3, 3, 3, 4, 5, 10))), true, 'day is between');
71936 assert.equal(m.isBetween(
71937 moment(new Date(2011, 3, 2, 1, 4, 5, 10)),
71938 moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'hour is later');
71939 assert.equal(m.isBetween(
71940 moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
71941 moment(new Date(2011, 3, 2, 5, 4, 5, 10))), false, 'hour is earlier');
71942 assert.equal(m.isBetween(
71943 moment(new Date(2011, 3, 2, 2, 4, 5, 10)),
71944 moment(new Date(2011, 3, 2, 4, 4, 5, 10))), true, 'hour is between');
71945 assert.equal(m.isBetween(
71946 moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
71947 moment(new Date(2011, 3, 2, 3, 6, 5, 10))), false, 'minute is later');
71948 assert.equal(m.isBetween(
71949 moment(new Date(2011, 3, 2, 3, 2, 5, 10)),
71950 moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'minute is earlier');
71951 assert.equal(m.isBetween(
71952 moment(new Date(2011, 3, 2, 3, 3, 5, 10)),
71953 moment(new Date(2011, 3, 2, 3, 5, 5, 10))), true, 'minute is between');
71954 assert.equal(m.isBetween(
71955 moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
71956 moment(new Date(2011, 3, 2, 3, 4, 7, 10))), false, 'second is later');
71957 assert.equal(m.isBetween(
71958 moment(new Date(2011, 3, 2, 3, 4, 3, 10)),
71959 moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'second is earlier');
71960 assert.equal(m.isBetween(
71961 moment(new Date(2011, 3, 2, 3, 4, 4, 10)),
71962 moment(new Date(2011, 3, 2, 3, 4, 6, 10))), true, 'second is between');
71963 assert.equal(m.isBetween(
71964 moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
71965 moment(new Date(2011, 3, 2, 3, 4, 5, 12))), false, 'millisecond is later');
71966 assert.equal(m.isBetween(
71967 moment(new Date(2011, 3, 2, 3, 4, 5, 8)),
71968 moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'millisecond is earlier');
71969 assert.equal(m.isBetween(
71970 moment(new Date(2011, 3, 2, 3, 4, 5, 9)),
71971 moment(new Date(2011, 3, 2, 3, 4, 5, 11))), true, 'millisecond is between');
71972 assert.equal(m.isBetween(m, m), false, 'moments are not between themselves');
71973 assert.equal(+m, +mCopy, 'isBetween second should not change moment');
71974 });
71975
71976 test('is between without units inclusivity', function (assert) {
71977 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
71978 assert.equal(m.isBetween(
71979 moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
71980 moment(new Date(2012, 3, 2, 3, 4, 5, 10)), null, '()'), false, 'start and end are excluded, start is equal to moment');
71981 assert.equal(m.isBetween(
71982 moment(new Date(2010, 3, 2, 3, 4, 5, 10)),
71983 moment(new Date(2011, 3, 2, 3, 4, 5, 10)), null, '()'), false, 'start and end are excluded, end is equal to moment');
71984 assert.equal(m.isBetween(
71985 moment(new Date(2010, 3, 2, 3, 4, 5, 10)),
71986 moment(new Date(2012, 3, 2, 3, 4, 5, 10)), null, '()'), true, 'start and end are excluded, is between');
71987 assert.equal(m.isBetween(
71988 moment(new Date(2009, 3, 2, 3, 4, 5, 10)),
71989 moment(new Date(2010, 3, 2, 3, 4, 5, 10)), null, '()'), false, 'start and end are excluded, is not between');
71990 assert.equal(m.isBetween(
71991 moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
71992 moment(new Date(2011, 3, 2, 3, 4, 5, 10)), null, '()'), false, 'start and end are excluded, should fail on same start/end date.');
71993
71994 assert.equal(m.isBetween(
71995 moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
71996 moment(new Date(2012, 3, 2, 3, 4, 5, 10)), null, '(]'), false, 'start is excluded and end is included should fail on same start date');
71997 assert.equal(m.isBetween(
71998 moment(new Date(2010, 3, 2, 3, 4, 5, 10)),
71999 moment(new Date(2011, 3, 2, 3, 4, 5, 10)), null, '(]'), true, 'start is excluded and end is included should succeed on end date');
72000 assert.equal(m.isBetween(
72001 moment(new Date(2010, 3, 2, 3, 4, 5, 10)),
72002 moment(new Date(2012, 3, 2, 3, 4, 5, 10)), null, '(]'), true, 'start is excluded and end is included, is between');
72003 assert.equal(m.isBetween(
72004 moment(new Date(2009, 3, 2, 3, 4, 5, 10)),
72005 moment(new Date(2010, 3, 2, 3, 4, 5, 10)), null, '(]'), false, 'start is excluded and end is included, is not between');
72006 assert.equal(m.isBetween(
72007 moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
72008 moment(new Date(2011, 3, 2, 3, 4, 5, 10)), null, '(]'), false, 'start is excluded and end is included, should fail on same start/end date.');
72009
72010 assert.equal(m.isBetween(
72011 moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
72012 moment(new Date(2012, 3, 2, 3, 4, 5, 10)), null, '[)'), true, 'start is included and end is excluded should succeed on same start date');
72013 assert.equal(m.isBetween(
72014 moment(new Date(2010, 3, 2, 3, 4, 5, 10)),
72015 moment(new Date(2011, 3, 2, 3, 4, 5, 10)), null, '[)'), false, 'start is included and end is excluded should fail on same end date');
72016 assert.equal(m.isBetween(
72017 moment(new Date(2010, 3, 2, 3, 4, 5, 10)),
72018 moment(new Date(2012, 3, 2, 3, 4, 5, 10)), null, '[)'), true, 'start is included and end is excluded, is between');
72019 assert.equal(m.isBetween(
72020 moment(new Date(2009, 3, 2, 3, 4, 5, 10)),
72021 moment(new Date(2010, 3, 2, 3, 4, 5, 10)), null, '[)'), false, 'start is included and end is excluded, is not between');
72022 assert.equal(m.isBetween(
72023 moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
72024 moment(new Date(2011, 3, 2, 3, 4, 5, 10)), null, '[)'), false, 'start is included and end is excluded, should fail on same end and start date');
72025
72026 assert.equal(m.isBetween(
72027 moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
72028 moment(new Date(2012, 3, 2, 3, 4, 5, 10)), null, '[]'), true, 'start and end inclusive should succeed on same start date');
72029 assert.equal(m.isBetween(
72030 moment(new Date(2010, 3, 2, 3, 4, 5, 10)),
72031 moment(new Date(2011, 3, 2, 3, 4, 5, 10)), null, '[]'), true, 'start and end inclusive should succeed on same end date');
72032 assert.equal(m.isBetween(
72033 moment(new Date(2010, 3, 2, 3, 4, 5, 10)),
72034 moment(new Date(2012, 3, 2, 3, 4, 5, 10)), null, '[]'), true, 'start and end inclusive, is between');
72035 assert.equal(m.isBetween(
72036 moment(new Date(2009, 3, 2, 3, 4, 5, 10)),
72037 moment(new Date(2010, 3, 2, 3, 4, 5, 10)), null, '[]'), false, 'start and end inclusive, is not between');
72038 assert.equal(m.isBetween(
72039 moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
72040 moment(new Date(2011, 3, 2, 3, 4, 5, 10)), null, '[]'), true, 'start and end inclusive, should handle same end and start date');
72041 });
72042
72043 test('is between milliseconds inclusivity', function (assert) {
72044 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
72045 assert.equal(m.isBetween(
72046 moment(new Date(2010, 3, 2, 3, 4, 5, 10)),
72047 moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'milliseconds'), true, 'options, no inclusive');
72048 assert.equal(m.isBetween(
72049 moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
72050 moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'milliseconds', '()'), false, 'start and end are excluded, start is equal to moment');
72051 assert.equal(m.isBetween(
72052 moment(new Date(2010, 3, 2, 3, 4, 5, 10)),
72053 moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'milliseconds', '()'), false, 'start and end are excluded, end is equal to moment');
72054 assert.equal(m.isBetween(
72055 moment(new Date(2010, 3, 2, 3, 4, 5, 10)),
72056 moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'milliseconds', '()'), true, 'start and end are excluded, is between');
72057 assert.equal(m.isBetween(
72058 moment(new Date(2009, 3, 2, 3, 4, 5, 10)),
72059 moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'milliseconds', '()'), false, 'start and end are excluded, is not between');
72060 assert.equal(m.isBetween(
72061 moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
72062 moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'milliseconds', '()'), false, 'start and end are excluded, should fail on same start/end date.');
72063
72064 assert.equal(m.isBetween(
72065 moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
72066 moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'milliseconds', '(]'), false, 'start is excluded and end is included should fail on same start date');
72067 assert.equal(m.isBetween(
72068 moment(new Date(2010, 3, 2, 3, 4, 5, 10)),
72069 moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'milliseconds', '(]'), true, 'start is excluded and end is included should succeed on end date');
72070 assert.equal(m.isBetween(
72071 moment(new Date(2010, 3, 2, 3, 4, 5, 10)),
72072 moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'milliseconds', '(]'), true, 'start is excluded and end is included, is between');
72073 assert.equal(m.isBetween(
72074 moment(new Date(2009, 3, 2, 3, 4, 5, 10)),
72075 moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'milliseconds', '(]'), false, 'start is excluded and end is included, is not between');
72076 assert.equal(m.isBetween(
72077 moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
72078 moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'milliseconds', '(]'), false, 'start is excluded and end is included, should fail on same start/end date.');
72079
72080 assert.equal(m.isBetween(
72081 moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
72082 moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'milliseconds', '[)'), true, 'start is included and end is excluded should succeed on same start date');
72083 assert.equal(m.isBetween(
72084 moment(new Date(2010, 3, 2, 3, 4, 5, 10)),
72085 moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'milliseconds', '[)'), false, 'start is included and end is excluded should fail on same end date');
72086 assert.equal(m.isBetween(
72087 moment(new Date(2010, 3, 2, 3, 4, 5, 10)),
72088 moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'milliseconds', '[)'), true, 'start is included and end is excluded, is between');
72089 assert.equal(m.isBetween(
72090 moment(new Date(2009, 3, 2, 3, 4, 5, 10)),
72091 moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'milliseconds', '[)'), false, 'start is included and end is excluded, is not between');
72092 assert.equal(m.isBetween(
72093 moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
72094 moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'milliseconds', '[)'), false, 'start is included and end is excluded, should fail on same end and start date');
72095
72096 assert.equal(m.isBetween(
72097 moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
72098 moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'milliseconds', '[]'), true, 'start and end inclusive should succeed on same start date');
72099 assert.equal(m.isBetween(
72100 moment(new Date(2010, 3, 2, 3, 4, 5, 10)),
72101 moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'milliseconds', '[]'), true, 'start and end inclusive should succeed on same end date');
72102 assert.equal(m.isBetween(
72103 moment(new Date(2010, 3, 2, 3, 4, 5, 10)),
72104 moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'milliseconds', '[]'), true, 'start and end inclusive, is between');
72105 assert.equal(m.isBetween(
72106 moment(new Date(2009, 3, 2, 3, 4, 5, 10)),
72107 moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'milliseconds', '[]'), false, 'start and end inclusive, is not between');
72108 assert.equal(m.isBetween(
72109 moment(new Date(2011, 3, 2, 3, 4, 5, 10)),
72110 moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'milliseconds', '[]'), true, 'start and end inclusive, should handle same end and start date');
72111 });
72112
72113 test('is between year', function (assert) {
72114 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
72115 assert.equal(m.isBetween(
72116 moment(new Date(2011, 5, 6, 7, 8, 9, 10)),
72117 moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year match');
72118 assert.equal(m.isBetween(
72119 moment(new Date(2010, 5, 6, 7, 8, 9, 10)),
72120 moment(new Date(2012, 5, 6, 7, 8, 9, 10)), 'years'), true, 'plural should work');
72121 assert.equal(m.isBetween(
72122 moment(new Date(2010, 5, 6, 7, 8, 9, 10)),
72123 moment(new Date(2012, 5, 6, 7, 8, 9, 10)), 'year'), true, 'year is between');
72124 assert.equal(m.isBetween(
72125 moment(new Date(2011, 5, 6, 7, 8, 9, 10)),
72126 moment(new Date(2013, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year is earlier');
72127 assert.equal(m.isBetween(
72128 moment(new Date(2010, 5, 6, 7, 8, 9, 10)),
72129 moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year is later');
b8f4fe2b 72130 assert.equal(m.isBetween(m, m, 'year'), false, 'same moments are not between the same year');
db71a655
KM
72131 assert.equal(+m, +mCopy, 'isBetween year should not change moment');
72132 });
72133
72134 test('is between month', function (assert) {
72135 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
72136 assert.equal(m.isBetween(
72137 moment(new Date(2011, 1, 6, 7, 8, 9, 10)),
72138 moment(new Date(2011, 1, 6, 7, 8, 9, 10)), 'month'), false, 'month match');
72139 assert.equal(m.isBetween(
72140 moment(new Date(2011, 0, 6, 7, 8, 9, 10)),
72141 moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'months'), true, 'plural should work');
72142 assert.equal(m.isBetween(
72143 moment(new Date(2011, 0, 31, 23, 59, 59, 999)),
72144 moment(new Date(2011, 2, 1, 0, 0, 0, 0)), 'month'), true, 'month is between');
72145 assert.equal(m.isBetween(
72146 moment(new Date(2011, 1, 6, 7, 8, 9, 10)),
72147 moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'month'), false, 'month is earlier');
72148 assert.equal(m.isBetween(
72149 moment(new Date(2011, 11, 6, 7, 8, 9, 10)),
72150 moment(new Date(2011, 1, 6, 7, 8, 9, 10)), 'month'), false, 'month is later');
b8f4fe2b 72151 assert.equal(m.isBetween(m, m, 'month'), false, 'same moments are not between the same month');
db71a655
KM
72152 assert.equal(+m, +mCopy, 'isBetween month should not change moment');
72153 });
72154
72155 test('is between day', function (assert) {
72156 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
72157 assert.equal(m.isBetween(
72158 moment(new Date(2011, 1, 2, 7, 8, 9, 10)),
72159 moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'day'), false, 'day match');
72160 assert.equal(m.isBetween(
72161 moment(new Date(2011, 1, 1, 7, 8, 9, 10)),
72162 moment(new Date(2011, 1, 3, 7, 8, 9, 10)), 'days'), true, 'plural should work');
72163 assert.equal(m.isBetween(
72164 moment(new Date(2011, 1, 1, 7, 8, 9, 10)),
72165 moment(new Date(2011, 1, 3, 7, 8, 9, 10)), 'day'), true, 'day is between');
72166 assert.equal(m.isBetween(
72167 moment(new Date(2011, 1, 2, 7, 8, 9, 10)),
72168 moment(new Date(2011, 1, 4, 7, 8, 9, 10)), 'day'), false, 'day is earlier');
72169 assert.equal(m.isBetween(
72170 moment(new Date(2011, 1, 1, 7, 8, 9, 10)),
72171 moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'day'), false, 'day is later');
b8f4fe2b 72172 assert.equal(m.isBetween(m, m, 'day'), false, 'same moments are not between the same day');
db71a655
KM
72173 assert.equal(+m, +mCopy, 'isBetween day should not change moment');
72174 });
72175
72176 test('is between hour', function (assert) {
72177 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
72178 assert.equal(m.isBetween(
72179 moment(new Date(2011, 1, 2, 3, 5, 9, 10)),
72180 moment(new Date(2011, 1, 2, 3, 9, 9, 10)), 'hour'), false, 'hour match');
72181 assert.equal(m.isBetween(
72182 moment(new Date(2011, 1, 2, 1, 59, 59, 999)),
72183 moment(new Date(2011, 1, 2, 4, 0, 0, 0)), 'hours'), true, 'plural should work');
72184 assert.equal(m.isBetween(
72185 moment(new Date(2011, 1, 2, 2, 59, 59, 999)),
72186 moment(new Date(2011, 1, 2, 4, 0, 0, 0)), 'hour'), true, 'hour is between');
72187 assert.equal(m.isBetween(
72188 moment(new Date(2011, 1, 2, 7, 8, 9, 10)),
72189 moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'hour'), false, 'hour is earlier');
72190 assert.equal(m.isBetween(
72191 moment(new Date(2011, 1, 2, 7, 8, 9, 10)),
72192 moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'hour'), false, 'hour is later');
b8f4fe2b 72193 assert.equal(m.isBetween(m, m, 'hour'), false, 'same moments are not between the same hour');
db71a655
KM
72194 assert.equal(+m, +mCopy, 'isBetween hour should not change moment');
72195 });
72196
72197 test('is between minute', function (assert) {
72198 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
72199 assert.equal(m.isBetween(
72200 moment(new Date(2011, 1, 2, 3, 4, 9, 10)),
72201 moment(new Date(2011, 1, 2, 3, 4, 9, 10)), 'minute'), false, 'minute match');
72202 assert.equal(m.isBetween(
72203 moment(new Date(2011, 1, 2, 3, 3, 9, 10)),
72204 moment(new Date(2011, 1, 2, 3, 5, 9, 10)), 'minutes'), true, 'plural should work');
72205 assert.equal(m.isBetween(
72206 moment(new Date(2011, 1, 2, 3, 3, 59, 999)),
72207 moment(new Date(2011, 1, 2, 3, 5, 0, 0)), 'minute'), true, 'minute is between');
72208 assert.equal(m.isBetween(
72209 moment(new Date(2011, 1, 2, 3, 5, 0, 0)),
72210 moment(new Date(2011, 1, 2, 3, 8, 9, 10)), 'minute'), false, 'minute is earlier');
72211 assert.equal(m.isBetween(
72212 moment(new Date(2011, 1, 2, 3, 2, 9, 10)),
72213 moment(new Date(2011, 1, 2, 3, 3, 59, 999)), 'minute'), false, 'minute is later');
b8f4fe2b 72214 assert.equal(m.isBetween(m, m, 'minute'), false, 'same moments are not between the same minute');
db71a655
KM
72215 assert.equal(+m, +mCopy, 'isBetween minute should not change moment');
72216 });
72217
72218 test('is between second', function (assert) {
72219 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
72220 assert.equal(m.isBetween(
72221 moment(new Date(2011, 1, 2, 3, 4, 5, 10)),
72222 moment(new Date(2011, 1, 2, 3, 4, 5, 10)), 'second'), false, 'second match');
72223 assert.equal(m.isBetween(
72224 moment(new Date(2011, 1, 2, 3, 4, 4, 10)),
72225 moment(new Date(2011, 1, 2, 3, 4, 6, 10)), 'seconds'), true, 'plural should work');
72226 assert.equal(m.isBetween(
72227 moment(new Date(2011, 1, 2, 3, 4, 4, 999)),
72228 moment(new Date(2011, 1, 2, 3, 4, 6, 0)), 'second'), true, 'second is between');
72229 assert.equal(m.isBetween(
72230 moment(new Date(2011, 1, 2, 3, 4, 6, 0)),
72231 moment(new Date(2011, 1, 2, 3, 4, 7, 10)), 'second'), false, 'second is earlier');
72232 assert.equal(m.isBetween(
72233 moment(new Date(2011, 1, 2, 3, 4, 3, 10)),
72234 moment(new Date(2011, 1, 2, 3, 4, 4, 999)), 'second'), false, 'second is later');
b8f4fe2b 72235 assert.equal(m.isBetween(m, m, 'second'), false, 'same moments are not between the same second');
db71a655
KM
72236 assert.equal(+m, +mCopy, 'isBetween second should not change moment');
72237 });
72238
72239 test('is between millisecond', function (assert) {
72240 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
72241 assert.equal(m.isBetween(
72242 moment(new Date(2011, 1, 2, 3, 4, 5, 6)),
72243 moment(new Date(2011, 1, 2, 3, 4, 5, 6)), 'millisecond'), false, 'millisecond match');
72244 assert.equal(m.isBetween(
72245 moment(new Date(2011, 1, 2, 3, 4, 5, 5)),
72246 moment(new Date(2011, 1, 2, 3, 4, 5, 7)), 'milliseconds'), true, 'plural should work');
72247 assert.equal(m.isBetween(
72248 moment(new Date(2011, 1, 2, 3, 4, 5, 5)),
72249 moment(new Date(2011, 1, 2, 3, 4, 5, 7)), 'millisecond'), true, 'millisecond is between');
72250 assert.equal(m.isBetween(
72251 moment(new Date(2011, 1, 2, 3, 4, 5, 7)),
72252 moment(new Date(2011, 1, 2, 3, 4, 5, 10)), 'millisecond'), false, 'millisecond is earlier');
72253 assert.equal(m.isBetween(
72254 moment(new Date(2011, 1, 2, 3, 4, 5, 4)),
72255 moment(new Date(2011, 1, 2, 3, 4, 5, 6)), 'millisecond'), false, 'millisecond is later');
b8f4fe2b 72256 assert.equal(m.isBetween(m, m, 'millisecond'), false, 'same moments are not between the same millisecond');
db71a655
KM
72257 assert.equal(+m, +mCopy, 'isBetween millisecond should not change moment');
72258 });
9483e2a4 72259
b8f4fe2b
KM
72260 test('is between invalid', function (assert) {
72261 var invalid = moment(NaN),
72262 valid = moment(new Date(2011, 1, 2, 3, 4, 5, 6)),
72263 validFrom = moment(new Date(2010, 1, 2, 3, 4, 5, 6)),
72264 validTo = moment(new Date(2012, 1, 2, 3, 4, 5, 6));
72265 assert.equal(invalid.isBetween(validFrom, validTo), false, 'this instance invalid');
72266 assert.equal(invalid.isBetween(validFrom, validTo, '[]'), false, 'this instance invalid []');
72267 assert.equal(invalid.isBetween(validFrom, validTo, '[)'), false, 'this instance invalid [)');
72268 assert.equal(invalid.isBetween(validFrom, validTo, '(]'), false, 'this instance invalid (]');
72269 assert.equal(invalid.isBetween(validFrom, validTo, '()'), false, 'this instance invalid ()');
72270
72271 assert.equal(valid.isBetween(invalid, validTo), false, 'from invalid moment');
72272 assert.equal(valid.isBetween(invalid, validTo, '[]'), false, 'from invalid moment []');
72273 assert.equal(valid.isBetween(invalid, validTo, '[)'), false, 'from invalid moment [)');
72274 assert.equal(valid.isBetween(invalid, validTo, '(]'), false, 'from invalid moment (]');
72275 assert.equal(valid.isBetween(invalid, validTo, '()'), false, 'from invalid moment ()');
72276
72277 assert.equal(valid.isBetween(validFrom, invalid), false, 'to invalid moment');
72278 assert.equal(valid.isBetween(validFrom, invalid, '[]'), false, 'to invalid moment []');
72279 assert.equal(valid.isBetween(validFrom, invalid, '[)'), false, 'to invalid moment [)');
72280 assert.equal(valid.isBetween(validFrom, invalid, '(]'), false, 'to invalid moment (]');
72281 assert.equal(valid.isBetween(validFrom, invalid, '()'), false, 'to invalid moment ()');
72282 });
72283
db71a655 72284})));
9483e2a4 72285
9483e2a4 72286
db71a655
KM
72287;(function (global, factory) {
72288 typeof exports === 'object' && typeof module !== 'undefined'
72289 && typeof require === 'function' ? factory(require('../../moment')) :
72290 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
72291 factory(global.moment)
72292}(this, (function (moment) { 'use strict';
9483e2a4 72293
db71a655
KM
72294 function each(array, callback) {
72295 var i;
72296 for (i = 0; i < array.length; i++) {
72297 callback(array[i], i, array);
72298 }
9483e2a4
IC
72299 }
72300
db71a655
KM
72301 function setupDeprecationHandler(test, moment$$1, scope) {
72302 test._expectedDeprecations = null;
72303 test._observedDeprecations = null;
72304 test._oldSupress = moment$$1.suppressDeprecationWarnings;
72305 moment$$1.suppressDeprecationWarnings = true;
72306 test.expectedDeprecations = function () {
72307 test._expectedDeprecations = arguments;
72308 test._observedDeprecations = [];
72309 };
72310 moment$$1.deprecationHandler = function (name, msg) {
72311 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
72312 if (deprecationId === -1) {
72313 throw new Error('Unexpected deprecation thrown name=' +
72314 name + ' msg=' + msg);
72315 }
72316 test._observedDeprecations[deprecationId] = 1;
9483e2a4
IC
72317 };
72318 }
9483e2a4 72319
db71a655
KM
72320 function teardownDeprecationHandler(test, moment$$1, scope) {
72321 moment$$1.suppressDeprecationWarnings = test._oldSupress;
9483e2a4 72322
db71a655
KM
72323 if (test._expectedDeprecations != null) {
72324 var missedDeprecations = [];
72325 each(test._expectedDeprecations, function (deprecationPattern, id) {
72326 if (test._observedDeprecations[id] !== 1) {
72327 missedDeprecations.push(deprecationPattern);
72328 }
72329 });
72330 if (missedDeprecations.length !== 0) {
72331 throw new Error('Expected deprecation warnings did not happen: ' +
72332 missedDeprecations.join(' '));
72333 }
72334 }
72335 }
516f5f67 72336
db71a655
KM
72337 function matchedDeprecation(name, msg, deprecations) {
72338 if (deprecations == null) {
72339 return -1;
72340 }
72341 for (var i = 0; i < deprecations.length; ++i) {
72342 if (name != null && name === deprecations[i]) {
72343 return i;
72344 }
72345 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
72346 return i;
72347 }
72348 }
72349 return -1;
72350 }
73f3c911 72351
db71a655 72352 /*global QUnit:false*/
516f5f67 72353
db71a655 72354 var test = QUnit.test;
516f5f67 72355
db71a655
KM
72356 function module$1 (name, lifecycle) {
72357 QUnit.module(name, {
c58511b9 72358 beforeEach : function () {
db71a655
KM
72359 moment.locale('en');
72360 moment.createFromInputFallback = function (config) {
72361 throw new Error('input not handled by moment: ' + config._i);
72362 };
72363 setupDeprecationHandler(test, moment, 'core');
72364 if (lifecycle && lifecycle.setup) {
72365 lifecycle.setup();
72366 }
72367 },
c58511b9 72368 afterEach : function () {
db71a655
KM
72369 teardownDeprecationHandler(test, moment, 'core');
72370 if (lifecycle && lifecycle.teardown) {
72371 lifecycle.teardown();
72372 }
72373 }
72374 });
72375 }
9483e2a4 72376
db71a655 72377 module$1('is date');
9483e2a4 72378
db71a655
KM
72379 test('isDate recognizes Date objects', function (assert) {
72380 assert.ok(moment.isDate(new Date()), 'no args (now)');
72381 assert.ok(moment.isDate(new Date([2014, 2, 15])), 'array args');
72382 assert.ok(moment.isDate(new Date('2014-03-15')), 'string args');
72383 assert.ok(moment.isDate(new Date('does NOT look like a date')), 'invalid date');
72384 });
9483e2a4 72385
db71a655
KM
72386 test('isDate rejects non-Date objects', function (assert) {
72387 assert.ok(!moment.isDate(), 'nothing');
72388 assert.ok(!moment.isDate(undefined), 'undefined');
72389 assert.ok(!moment.isDate(null), 'string args');
72390 assert.ok(!moment.isDate(42), 'number');
72391 assert.ok(!moment.isDate('2014-03-15'), 'string');
72392 assert.ok(!moment.isDate([2014, 2, 15]), 'array');
72393 assert.ok(!moment.isDate({year: 2014, month: 2, day: 15}), 'object');
72394 assert.ok(!moment.isDate({
72395 toString: function () {
72396 return '[object Date]';
72397 }
72398 }), 'lying object');
72399 });
b135bf1a 72400
db71a655 72401})));
9483e2a4 72402
9483e2a4 72403
db71a655
KM
72404;(function (global, factory) {
72405 typeof exports === 'object' && typeof module !== 'undefined'
72406 && typeof require === 'function' ? factory(require('../../moment')) :
72407 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
72408 factory(global.moment)
72409}(this, (function (moment) { 'use strict';
9483e2a4 72410
db71a655
KM
72411 function each(array, callback) {
72412 var i;
72413 for (i = 0; i < array.length; i++) {
72414 callback(array[i], i, array);
9483e2a4 72415 }
b135bf1a 72416 }
9483e2a4 72417
db71a655
KM
72418 function setupDeprecationHandler(test, moment$$1, scope) {
72419 test._expectedDeprecations = null;
72420 test._observedDeprecations = null;
72421 test._oldSupress = moment$$1.suppressDeprecationWarnings;
72422 moment$$1.suppressDeprecationWarnings = true;
72423 test.expectedDeprecations = function () {
72424 test._expectedDeprecations = arguments;
72425 test._observedDeprecations = [];
72426 };
72427 moment$$1.deprecationHandler = function (name, msg) {
72428 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
72429 if (deprecationId === -1) {
72430 throw new Error('Unexpected deprecation thrown name=' +
72431 name + ' msg=' + msg);
72432 }
72433 test._observedDeprecations[deprecationId] = 1;
72434 };
9483e2a4
IC
72435 }
72436
db71a655
KM
72437 function teardownDeprecationHandler(test, moment$$1, scope) {
72438 moment$$1.suppressDeprecationWarnings = test._oldSupress;
b135bf1a 72439
db71a655
KM
72440 if (test._expectedDeprecations != null) {
72441 var missedDeprecations = [];
72442 each(test._expectedDeprecations, function (deprecationPattern, id) {
72443 if (test._observedDeprecations[id] !== 1) {
72444 missedDeprecations.push(deprecationPattern);
9483e2a4 72445 }
db71a655
KM
72446 });
72447 if (missedDeprecations.length !== 0) {
72448 throw new Error('Expected deprecation warnings did not happen: ' +
72449 missedDeprecations.join(' '));
9483e2a4 72450 }
9483e2a4 72451 }
db71a655 72452 }
b135bf1a 72453
db71a655
KM
72454 function matchedDeprecation(name, msg, deprecations) {
72455 if (deprecations == null) {
72456 return -1;
72457 }
72458 for (var i = 0; i < deprecations.length; ++i) {
72459 if (name != null && name === deprecations[i]) {
72460 return i;
72461 }
72462 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
72463 return i;
72464 }
72465 }
72466 return -1;
72467 }
9483e2a4 72468
db71a655 72469 /*global QUnit:false*/
9483e2a4 72470
db71a655 72471 var test = QUnit.test;
9483e2a4 72472
db71a655
KM
72473 function module$1 (name, lifecycle) {
72474 QUnit.module(name, {
c58511b9 72475 beforeEach : function () {
db71a655
KM
72476 moment.locale('en');
72477 moment.createFromInputFallback = function (config) {
72478 throw new Error('input not handled by moment: ' + config._i);
72479 };
72480 setupDeprecationHandler(test, moment, 'core');
72481 if (lifecycle && lifecycle.setup) {
72482 lifecycle.setup();
72483 }
72484 },
c58511b9 72485 afterEach : function () {
db71a655
KM
72486 teardownDeprecationHandler(test, moment, 'core');
72487 if (lifecycle && lifecycle.teardown) {
72488 lifecycle.teardown();
72489 }
72490 }
72491 });
72492 }
9483e2a4 72493
db71a655 72494 module$1('is moment');
9483e2a4 72495
db71a655
KM
72496 test('is moment object', function (assert) {
72497 var MyObj = function () {},
72498 extend = function (a, b) {
72499 var i;
72500 for (i in b) {
72501 a[i] = b[i];
72502 }
72503 return a;
72504 };
72505 MyObj.prototype.toDate = function () {
72506 return new Date();
72507 };
9483e2a4 72508
db71a655
KM
72509 assert.ok(moment.isMoment(moment()), 'simple moment object');
72510 assert.ok(moment.isMoment(moment(null)), 'invalid moment object');
72511 assert.ok(moment.isMoment(extend({}, moment())), 'externally cloned moments are moments');
72512 assert.ok(moment.isMoment(extend({}, moment.utc())), 'externally cloned utc moments are moments');
72513
72514 assert.ok(!moment.isMoment(new MyObj()), 'myObj is not moment object');
72515 assert.ok(!moment.isMoment(moment), 'moment function is not moment object');
72516 assert.ok(!moment.isMoment(new Date()), 'date object is not moment object');
72517 assert.ok(!moment.isMoment(Object), 'Object is not moment object');
72518 assert.ok(!moment.isMoment('foo'), 'string is not moment object');
72519 assert.ok(!moment.isMoment(1), 'number is not moment object');
72520 assert.ok(!moment.isMoment(NaN), 'NaN is not moment object');
72521 assert.ok(!moment.isMoment(null), 'null is not moment object');
72522 assert.ok(!moment.isMoment(undefined), 'undefined is not moment object');
72523 });
72524
72525 test('is moment with hacked hasOwnProperty', function (assert) {
72526 var obj = {};
72527 // HACK to suppress jshint warning about bad property name
72528 obj['hasOwnMoney'.replace('Money', 'Property')] = function () {
72529 return true;
72530 };
9483e2a4 72531
db71a655
KM
72532 assert.ok(!moment.isMoment(obj), 'isMoment works even if passed object has a wrong hasOwnProperty implementation (ie8)');
72533 });
9483e2a4 72534
db71a655 72535})));
9483e2a4 72536
9483e2a4 72537
db71a655
KM
72538;(function (global, factory) {
72539 typeof exports === 'object' && typeof module !== 'undefined'
72540 && typeof require === 'function' ? factory(require('../../moment')) :
72541 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
72542 factory(global.moment)
72543}(this, (function (moment) { 'use strict';
9483e2a4 72544
db71a655 72545 /*global QUnit:false*/
9483e2a4 72546
db71a655 72547 var test = QUnit.test;
9483e2a4 72548
db71a655
KM
72549 function isNumber(input) {
72550 return typeof input === 'number' || Object.prototype.toString.call(input) === '[object Number]';
72551 }
9483e2a4 72552
db71a655
KM
72553 test('isNumber recognizes numbers', function (assert) {
72554 assert.ok(isNumber(1), 'simple integer');
72555 assert.ok(isNumber(0), 'simple number');
72556 assert.ok(isNumber(-0), 'silly number');
72557 assert.ok(isNumber(1010010293029), 'large number');
72558 assert.ok(isNumber(Infinity), 'largest number');
72559 assert.ok(isNumber(-Infinity), 'smallest number');
72560 assert.ok(isNumber(NaN), 'not number');
72561 assert.ok(isNumber(1.100393830000), 'decimal numbers');
72562 assert.ok(isNumber(Math.LN2), 'natural log of two');
72563 assert.ok(isNumber(Math.PI), 'delicious number');
72564 assert.ok(isNumber(5e10), 'scientifically notated number');
72565 assert.ok(isNumber(new Number(1)), 'number primitive wrapped in an object'); // jshint ignore:line
72566 });
9483e2a4 72567
db71a655
KM
72568 test('isNumber rejects non-numbers', function (assert) {
72569 assert.ok(!isNumber(), 'nothing');
72570 assert.ok(!isNumber(undefined), 'undefined');
72571 assert.ok(!isNumber(null), 'null');
72572 assert.ok(!isNumber([1]), 'array');
72573 assert.ok(!isNumber('[1,2,3]'), 'string');
72574 assert.ok(!isNumber(new Date()), 'date');
72575 assert.ok(!isNumber({a:1,b:2}), 'object');
72576 });
9483e2a4
IC
72577
72578})));
72579
72580
72581;(function (global, factory) {
72582 typeof exports === 'object' && typeof module !== 'undefined'
72583 && typeof require === 'function' ? factory(require('../../moment')) :
72584 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
72585 factory(global.moment)
72586}(this, (function (moment) { 'use strict';
72587
db71a655
KM
72588 function each(array, callback) {
72589 var i;
72590 for (i = 0; i < array.length; i++) {
72591 callback(array[i], i, array);
72592 }
9483e2a4 72593 }
f2af24d5 72594
db71a655
KM
72595 function setupDeprecationHandler(test, moment$$1, scope) {
72596 test._expectedDeprecations = null;
72597 test._observedDeprecations = null;
72598 test._oldSupress = moment$$1.suppressDeprecationWarnings;
72599 moment$$1.suppressDeprecationWarnings = true;
72600 test.expectedDeprecations = function () {
72601 test._expectedDeprecations = arguments;
72602 test._observedDeprecations = [];
72603 };
72604 moment$$1.deprecationHandler = function (name, msg) {
72605 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
72606 if (deprecationId === -1) {
72607 throw new Error('Unexpected deprecation thrown name=' +
72608 name + ' msg=' + msg);
72609 }
72610 test._observedDeprecations[deprecationId] = 1;
72611 };
72612 }
f2af24d5 72613
db71a655
KM
72614 function teardownDeprecationHandler(test, moment$$1, scope) {
72615 moment$$1.suppressDeprecationWarnings = test._oldSupress;
f2af24d5 72616
db71a655
KM
72617 if (test._expectedDeprecations != null) {
72618 var missedDeprecations = [];
72619 each(test._expectedDeprecations, function (deprecationPattern, id) {
72620 if (test._observedDeprecations[id] !== 1) {
72621 missedDeprecations.push(deprecationPattern);
72622 }
72623 });
72624 if (missedDeprecations.length !== 0) {
72625 throw new Error('Expected deprecation warnings did not happen: ' +
72626 missedDeprecations.join(' '));
f2af24d5 72627 }
f2af24d5
IC
72628 }
72629 }
f2af24d5 72630
db71a655
KM
72631 function matchedDeprecation(name, msg, deprecations) {
72632 if (deprecations == null) {
72633 return -1;
f2af24d5 72634 }
db71a655
KM
72635 for (var i = 0; i < deprecations.length; ++i) {
72636 if (name != null && name === deprecations[i]) {
72637 return i;
72638 }
72639 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
72640 return i;
72641 }
f2af24d5 72642 }
db71a655 72643 return -1;
f2af24d5 72644 }
f2af24d5 72645
db71a655 72646 /*global QUnit:false*/
f2af24d5 72647
db71a655 72648 var test = QUnit.test;
f2af24d5 72649
db71a655
KM
72650 function module$1 (name, lifecycle) {
72651 QUnit.module(name, {
c58511b9 72652 beforeEach : function () {
db71a655
KM
72653 moment.locale('en');
72654 moment.createFromInputFallback = function (config) {
72655 throw new Error('input not handled by moment: ' + config._i);
72656 };
72657 setupDeprecationHandler(test, moment, 'core');
72658 if (lifecycle && lifecycle.setup) {
72659 lifecycle.setup();
72660 }
72661 },
c58511b9 72662 afterEach : function () {
db71a655
KM
72663 teardownDeprecationHandler(test, moment, 'core');
72664 if (lifecycle && lifecycle.teardown) {
72665 lifecycle.teardown();
72666 }
f2af24d5 72667 }
db71a655
KM
72668 });
72669 }
f2af24d5 72670
db71a655
KM
72671 module$1('is same');
72672
72673 test('is same without units', function (assert) {
72674 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
72675 assert.equal(m.isSame(moment(new Date(2012, 3, 2, 3, 5, 5, 10))), false, 'year is later');
72676 assert.equal(m.isSame(moment(new Date(2010, 3, 2, 3, 3, 5, 10))), false, 'year is earlier');
72677 assert.equal(m.isSame(moment(new Date(2011, 4, 2, 3, 4, 5, 10))), false, 'month is later');
72678 assert.equal(m.isSame(moment(new Date(2011, 2, 2, 3, 4, 5, 10))), false, 'month is earlier');
72679 assert.equal(m.isSame(moment(new Date(2011, 3, 3, 3, 4, 5, 10))), false, 'day is later');
72680 assert.equal(m.isSame(moment(new Date(2011, 3, 1, 3, 4, 5, 10))), false, 'day is earlier');
72681 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 4, 4, 5, 10))), false, 'hour is later');
72682 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 2, 4, 5, 10))), false, 'hour is earlier');
72683 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 5, 5, 10))), false, 'minute is later');
72684 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 3, 5, 10))), false, 'minute is earlier');
72685 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 6, 10))), false, 'second is later');
72686 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 4, 11))), false, 'second is earlier');
72687 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 5, 10))), true, 'millisecond match');
72688 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 5, 11))), false, 'millisecond is later');
72689 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 5, 9))), false, 'millisecond is earlier');
72690 assert.equal(m.isSame(m), true, 'moments are the same as themselves');
72691 assert.equal(+m, +mCopy, 'isSame second should not change moment');
72692 });
72693
72694 test('is same year', function (assert) {
72695 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
72696 assert.equal(m.isSame(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'year'), true, 'year match');
72697 assert.equal(m.isSame(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'years'), true, 'plural should work');
72698 assert.equal(m.isSame(moment(new Date(2012, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year mismatch');
72699 assert.equal(m.isSame(moment(new Date(2011, 0, 1, 0, 0, 0, 0)), 'year'), true, 'exact start of year');
72700 assert.equal(m.isSame(moment(new Date(2011, 11, 31, 23, 59, 59, 999)), 'year'), true, 'exact end of year');
72701 assert.equal(m.isSame(moment(new Date(2012, 0, 1, 0, 0, 0, 0)), 'year'), false, 'start of next year');
72702 assert.equal(m.isSame(moment(new Date(2010, 11, 31, 23, 59, 59, 999)), 'year'), false, 'end of previous year');
72703 assert.equal(m.isSame(m, 'year'), true, 'same moments are in the same year');
72704 assert.equal(+m, +mCopy, 'isSame year should not change moment');
72705 });
72706
72707 test('is same month', function (assert) {
72708 var m = moment(new Date(2011, 2, 3, 4, 5, 6, 7)), mCopy = moment(m);
72709 assert.equal(m.isSame(moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'month'), true, 'month match');
72710 assert.equal(m.isSame(moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'months'), true, 'plural should work');
72711 assert.equal(m.isSame(moment(new Date(2012, 2, 6, 7, 8, 9, 10)), 'month'), false, 'year mismatch');
72712 assert.equal(m.isSame(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'month'), false, 'month mismatch');
72713 assert.equal(m.isSame(moment(new Date(2011, 2, 1, 0, 0, 0, 0)), 'month'), true, 'exact start of month');
72714 assert.equal(m.isSame(moment(new Date(2011, 2, 31, 23, 59, 59, 999)), 'month'), true, 'exact end of month');
72715 assert.equal(m.isSame(moment(new Date(2011, 3, 1, 0, 0, 0, 0)), 'month'), false, 'start of next month');
72716 assert.equal(m.isSame(moment(new Date(2011, 1, 27, 23, 59, 59, 999)), 'month'), false, 'end of previous month');
72717 assert.equal(m.isSame(m, 'month'), true, 'same moments are in the same month');
72718 assert.equal(+m, +mCopy, 'isSame month should not change moment');
72719 });
72720
72721 test('is same day', function (assert) {
72722 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
72723 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'day'), true, 'day match');
72724 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'days'), true, 'plural should work');
72725 assert.equal(m.isSame(moment(new Date(2012, 1, 2, 7, 8, 9, 10)), 'day'), false, 'year mismatch');
72726 assert.equal(m.isSame(moment(new Date(2011, 2, 2, 7, 8, 9, 10)), 'day'), false, 'month mismatch');
72727 assert.equal(m.isSame(moment(new Date(2011, 1, 3, 7, 8, 9, 10)), 'day'), false, 'day mismatch');
72728 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 0, 0, 0, 0)), 'day'), true, 'exact start of day');
72729 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 23, 59, 59, 999)), 'day'), true, 'exact end of day');
72730 assert.equal(m.isSame(moment(new Date(2011, 1, 3, 0, 0, 0, 0)), 'day'), false, 'start of next day');
72731 assert.equal(m.isSame(moment(new Date(2011, 1, 1, 23, 59, 59, 999)), 'day'), false, 'end of previous day');
72732 assert.equal(m.isSame(m, 'day'), true, 'same moments are in the same day');
72733 assert.equal(+m, +mCopy, 'isSame day should not change moment');
72734 });
72735
72736 test('is same hour', function (assert) {
72737 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
72738 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 8, 9, 10)), 'hour'), true, 'hour match');
72739 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 8, 9, 10)), 'hours'), true, 'plural should work');
72740 assert.equal(m.isSame(moment(new Date(2012, 1, 2, 3, 8, 9, 10)), 'hour'), false, 'year mismatch');
72741 assert.equal(m.isSame(moment(new Date(2011, 2, 2, 3, 8, 9, 10)), 'hour'), false, 'month mismatch');
72742 assert.equal(m.isSame(moment(new Date(2011, 1, 3, 3, 8, 9, 10)), 'hour'), false, 'day mismatch');
72743 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 4, 8, 9, 10)), 'hour'), false, 'hour mismatch');
72744 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 0, 0, 0)), 'hour'), true, 'exact start of hour');
72745 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 59, 59, 999)), 'hour'), true, 'exact end of hour');
72746 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 4, 0, 0, 0)), 'hour'), false, 'start of next hour');
72747 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 2, 59, 59, 999)), 'hour'), false, 'end of previous hour');
72748 assert.equal(m.isSame(m, 'hour'), true, 'same moments are in the same hour');
72749 assert.equal(+m, +mCopy, 'isSame hour should not change moment');
72750 });
72751
72752 test('is same minute', function (assert) {
72753 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
72754 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 9, 10)), 'minute'), true, 'minute match');
72755 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 9, 10)), 'minutes'), true, 'plural should work');
72756 assert.equal(m.isSame(moment(new Date(2012, 1, 2, 3, 4, 9, 10)), 'minute'), false, 'year mismatch');
72757 assert.equal(m.isSame(moment(new Date(2011, 2, 2, 3, 4, 9, 10)), 'minute'), false, 'month mismatch');
72758 assert.equal(m.isSame(moment(new Date(2011, 1, 3, 3, 4, 9, 10)), 'minute'), false, 'day mismatch');
72759 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 4, 4, 9, 10)), 'minute'), false, 'hour mismatch');
72760 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 5, 9, 10)), 'minute'), false, 'minute mismatch');
72761 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 0, 0)), 'minute'), true, 'exact start of minute');
72762 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 59, 999)), 'minute'), true, 'exact end of minute');
72763 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 5, 0, 0)), 'minute'), false, 'start of next minute');
72764 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 3, 59, 999)), 'minute'), false, 'end of previous minute');
72765 assert.equal(m.isSame(m, 'minute'), true, 'same moments are in the same minute');
72766 assert.equal(+m, +mCopy, 'isSame minute should not change moment');
72767 });
72768
72769 test('is same second', function (assert) {
72770 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
72771 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 5, 10)), 'second'), true, 'second match');
72772 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 5, 10)), 'seconds'), true, 'plural should work');
72773 assert.equal(m.isSame(moment(new Date(2012, 1, 2, 3, 4, 5, 10)), 'second'), false, 'year mismatch');
72774 assert.equal(m.isSame(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'second'), false, 'month mismatch');
72775 assert.equal(m.isSame(moment(new Date(2011, 1, 3, 3, 4, 5, 10)), 'second'), false, 'day mismatch');
72776 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 4, 4, 5, 10)), 'second'), false, 'hour mismatch');
72777 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 5, 5, 10)), 'second'), false, 'minute mismatch');
72778 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 6, 10)), 'second'), false, 'second mismatch');
72779 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 5, 0)), 'second'), true, 'exact start of second');
72780 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 5, 999)), 'second'), true, 'exact end of second');
72781 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 6, 0)), 'second'), false, 'start of next second');
72782 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 4, 999)), 'second'), false, 'end of previous second');
72783 assert.equal(m.isSame(m, 'second'), true, 'same moments are in the same second');
72784 assert.equal(+m, +mCopy, 'isSame second should not change moment');
72785 });
72786
72787 test('is same millisecond', function (assert) {
72788 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
72789 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'millisecond'), true, 'millisecond match');
72790 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'milliseconds'), true, 'plural should work');
72791 assert.equal(m.isSame(moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'millisecond'), false, 'year is later');
72792 assert.equal(m.isSame(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'millisecond'), false, 'year is earlier');
72793 assert.equal(m.isSame(moment(new Date(2011, 4, 2, 3, 4, 5, 10)), 'millisecond'), false, 'month is later');
72794 assert.equal(m.isSame(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'millisecond'), false, 'month is earlier');
72795 assert.equal(m.isSame(moment(new Date(2011, 3, 3, 3, 4, 5, 10)), 'millisecond'), false, 'day is later');
72796 assert.equal(m.isSame(moment(new Date(2011, 3, 1, 1, 4, 5, 10)), 'millisecond'), false, 'day is earlier');
72797 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 4, 4, 5, 10)), 'millisecond'), false, 'hour is later');
72798 assert.equal(m.isSame(moment(new Date(2011, 3, 1, 4, 1, 5, 10)), 'millisecond'), false, 'hour is earlier');
72799 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 5, 5, 10)), 'millisecond'), false, 'minute is later');
72800 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 3, 5, 10)), 'millisecond'), false, 'minute is earlier');
72801 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 6, 10)), 'millisecond'), false, 'second is later');
72802 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 4, 5)), 'millisecond'), false, 'second is earlier');
72803 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 6, 11)), 'millisecond'), false, 'millisecond is later');
72804 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 4, 9)), 'millisecond'), false, 'millisecond is earlier');
72805 assert.equal(m.isSame(m, 'millisecond'), true, 'same moments are in the same millisecond');
72806 assert.equal(+m, +mCopy, 'isSame millisecond should not change moment');
72807 });
72808
72809 test('is same with utc offset moments', function (assert) {
72810 assert.ok(moment.parseZone('2013-02-01T00:00:00-05:00').isSame(moment('2013-02-01'), 'year'), 'zoned vs local moment');
72811 assert.ok(moment('2013-02-01').isSame(moment('2013-02-01').utcOffset('-05:00'), 'year'), 'local vs zoned moment');
72812 assert.ok(moment.parseZone('2013-02-01T00:00:00-05:00').isSame(moment.parseZone('2013-02-01T00:00:00-06:30'), 'year'),
72813 'zoned vs (differently) zoned moment');
72814 });
72815
72816 test('is same with invalid moments', function (assert) {
72817 assert.equal(moment.invalid().isSame(moment.invalid()), false, 'invalid moments are not considered equal');
72818 });
f2af24d5
IC
72819
72820})));
72821
72822
72823;(function (global, factory) {
72824 typeof exports === 'object' && typeof module !== 'undefined'
72825 && typeof require === 'function' ? factory(require('../../moment')) :
72826 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
72827 factory(global.moment)
72828}(this, (function (moment) { 'use strict';
72829
db71a655
KM
72830 function each(array, callback) {
72831 var i;
72832 for (i = 0; i < array.length; i++) {
72833 callback(array[i], i, array);
72834 }
f2af24d5 72835 }
f2af24d5 72836
db71a655
KM
72837 function setupDeprecationHandler(test, moment$$1, scope) {
72838 test._expectedDeprecations = null;
72839 test._observedDeprecations = null;
72840 test._oldSupress = moment$$1.suppressDeprecationWarnings;
72841 moment$$1.suppressDeprecationWarnings = true;
72842 test.expectedDeprecations = function () {
72843 test._expectedDeprecations = arguments;
72844 test._observedDeprecations = [];
72845 };
72846 moment$$1.deprecationHandler = function (name, msg) {
72847 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
72848 if (deprecationId === -1) {
72849 throw new Error('Unexpected deprecation thrown name=' +
72850 name + ' msg=' + msg);
72851 }
72852 test._observedDeprecations[deprecationId] = 1;
72853 };
72854 }
c74a101d 72855
db71a655
KM
72856 function teardownDeprecationHandler(test, moment$$1, scope) {
72857 moment$$1.suppressDeprecationWarnings = test._oldSupress;
c74a101d 72858
db71a655
KM
72859 if (test._expectedDeprecations != null) {
72860 var missedDeprecations = [];
72861 each(test._expectedDeprecations, function (deprecationPattern, id) {
72862 if (test._observedDeprecations[id] !== 1) {
72863 missedDeprecations.push(deprecationPattern);
72864 }
72865 });
72866 if (missedDeprecations.length !== 0) {
72867 throw new Error('Expected deprecation warnings did not happen: ' +
72868 missedDeprecations.join(' '));
c74a101d 72869 }
73f3c911 72870 }
c74a101d
IC
72871 }
72872
db71a655
KM
72873 function matchedDeprecation(name, msg, deprecations) {
72874 if (deprecations == null) {
72875 return -1;
73f3c911 72876 }
db71a655
KM
72877 for (var i = 0; i < deprecations.length; ++i) {
72878 if (name != null && name === deprecations[i]) {
72879 return i;
73f3c911 72880 }
db71a655
KM
72881 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
72882 return i;
c74a101d
IC
72883 }
72884 }
db71a655 72885 return -1;
c74a101d
IC
72886 }
72887
db71a655 72888 /*global QUnit:false*/
73f3c911 72889
db71a655 72890 var test = QUnit.test;
c74a101d 72891
db71a655
KM
72892 function module$1 (name, lifecycle) {
72893 QUnit.module(name, {
c58511b9 72894 beforeEach : function () {
db71a655
KM
72895 moment.locale('en');
72896 moment.createFromInputFallback = function (config) {
72897 throw new Error('input not handled by moment: ' + config._i);
72898 };
72899 setupDeprecationHandler(test, moment, 'core');
72900 if (lifecycle && lifecycle.setup) {
72901 lifecycle.setup();
72902 }
72903 },
c58511b9 72904 afterEach : function () {
db71a655
KM
72905 teardownDeprecationHandler(test, moment, 'core');
72906 if (lifecycle && lifecycle.teardown) {
72907 lifecycle.teardown();
c587bf00 72908 }
c74a101d 72909 }
db71a655
KM
72910 });
72911 }
73f3c911 72912
db71a655
KM
72913 module$1('is same or after');
72914
72915 test('is same or after without units', function (assert) {
72916 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
72917 assert.equal(m.isSameOrAfter(moment(new Date(2012, 3, 2, 3, 5, 5, 10))), false, 'year is later');
72918 assert.equal(m.isSameOrAfter(moment(new Date(2010, 3, 2, 3, 3, 5, 10))), true, 'year is earlier');
72919 assert.equal(m.isSameOrAfter(moment(new Date(2011, 4, 2, 3, 4, 5, 10))), false, 'month is later');
72920 assert.equal(m.isSameOrAfter(moment(new Date(2011, 2, 2, 3, 4, 5, 10))), true, 'month is earlier');
72921 assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 3, 3, 4, 5, 10))), false, 'day is later');
72922 assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 1, 3, 4, 5, 10))), true, 'day is earlier');
72923 assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 4, 4, 5, 10))), false, 'hour is later');
72924 assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 2, 4, 5, 10))), true, 'hour is earlier');
72925 assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 5, 5, 10))), false, 'minute is later');
72926 assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 3, 5, 10))), true, 'minute is earlier');
72927 assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 4, 6, 10))), false, 'second is later');
72928 assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 4, 4, 11))), true, 'second is earlier');
72929 assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 10))), true, 'millisecond match');
72930 assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 11))), false, 'millisecond is later');
72931 assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 9))), true, 'millisecond is earlier');
72932 assert.equal(m.isSameOrAfter(m), true, 'moments are the same as themselves');
72933 assert.equal(+m, +mCopy, 'isSameOrAfter second should not change moment');
72934 });
72935
72936 test('is same or after year', function (assert) {
72937 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
72938 assert.equal(m.isSameOrAfter(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'year'), true, 'year match');
72939 assert.equal(m.isSameOrAfter(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'years'), true, 'plural should work');
72940 assert.equal(m.isSameOrAfter(moment(new Date(2012, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year is later');
72941 assert.equal(m.isSameOrAfter(moment(new Date(2010, 5, 6, 7, 8, 9, 10)), 'year'), true, 'year is earlier');
72942 assert.equal(m.isSameOrAfter(moment(new Date(2011, 0, 1, 0, 0, 0, 0)), 'year'), true, 'exact start of year');
72943 assert.equal(m.isSameOrAfter(moment(new Date(2011, 11, 31, 23, 59, 59, 999)), 'year'), true, 'exact end of year');
72944 assert.equal(m.isSameOrAfter(moment(new Date(2012, 0, 1, 0, 0, 0, 0)), 'year'), false, 'start of next year');
72945 assert.equal(m.isSameOrAfter(moment(new Date(2010, 11, 31, 23, 59, 59, 999)), 'year'), true, 'end of previous year');
72946 assert.equal(m.isSameOrAfter(m, 'year'), true, 'same moments are in the same year');
72947 assert.equal(+m, +mCopy, 'isSameOrAfter year should not change moment');
72948 });
72949
72950 test('is same or after month', function (assert) {
72951 var m = moment(new Date(2011, 2, 3, 4, 5, 6, 7)), mCopy = moment(m);
72952 assert.equal(m.isSameOrAfter(moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'month'), true, 'month match');
72953 assert.equal(m.isSameOrAfter(moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'months'), true, 'plural should work');
72954 assert.equal(m.isSameOrAfter(moment(new Date(2012, 2, 6, 7, 8, 9, 10)), 'month'), false, 'year is later');
72955 assert.equal(m.isSameOrAfter(moment(new Date(2010, 2, 6, 7, 8, 9, 10)), 'month'), true, 'year is earlier');
72956 assert.equal(m.isSameOrAfter(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'month'), false, 'month is later');
72957 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 6, 7, 8, 9, 10)), 'month'), true, 'month is earlier');
72958 assert.equal(m.isSameOrAfter(moment(new Date(2011, 2, 1, 0, 0, 0, 0)), 'month'), true, 'exact start of month');
72959 assert.equal(m.isSameOrAfter(moment(new Date(2011, 2, 31, 23, 59, 59, 999)), 'month'), true, 'exact end of month');
72960 assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 1, 0, 0, 0, 0)), 'month'), false, 'start of next month');
72961 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 27, 23, 59, 59, 999)), 'month'), true, 'end of previous month');
72962 assert.equal(m.isSameOrAfter(m, 'month'), true, 'same moments are in the same month');
72963 assert.equal(+m, +mCopy, 'isSameOrAfter month should not change moment');
72964 });
72965
72966 test('is same or after day', function (assert) {
72967 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
72968 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'day'), true, 'day match');
72969 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'days'), true, 'plural should work');
72970 assert.equal(m.isSameOrAfter(moment(new Date(2012, 1, 2, 7, 8, 9, 10)), 'day'), false, 'year is later');
72971 assert.equal(m.isSameOrAfter(moment(new Date(2010, 1, 2, 7, 8, 9, 10)), 'day'), true, 'year is earlier');
72972 assert.equal(m.isSameOrAfter(moment(new Date(2011, 2, 2, 7, 8, 9, 10)), 'day'), false, 'month is later');
72973 assert.equal(m.isSameOrAfter(moment(new Date(2010, 12, 2, 7, 8, 9, 10)), 'day'), true, 'month is earlier');
72974 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 3, 7, 8, 9, 10)), 'day'), false, 'day is later');
72975 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 1, 7, 8, 9, 10)), 'day'), true, 'day is earlier');
72976 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 0, 0, 0, 0)), 'day'), true, 'exact start of day');
72977 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 23, 59, 59, 999)), 'day'), true, 'exact end of day');
72978 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 3, 0, 0, 0, 0)), 'day'), false, 'start of next day');
72979 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 1, 23, 59, 59, 999)), 'day'), true, 'end of previous day');
72980 assert.equal(m.isSameOrAfter(m, 'day'), true, 'same moments are in the same day');
72981 assert.equal(+m, +mCopy, 'isSameOrAfter day should not change moment');
72982 });
72983
72984 test('is same or after hour', function (assert) {
72985 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
72986 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 8, 9, 10)), 'hour'), true, 'hour match');
72987 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 8, 9, 10)), 'hours'), true, 'plural should work');
72988 assert.equal(m.isSameOrAfter(moment(new Date(2012, 1, 2, 3, 8, 9, 10)), 'hour'), false, 'year is later');
72989 assert.equal(m.isSameOrAfter(moment(new Date(2010, 1, 2, 3, 8, 9, 10)), 'hour'), true, 'year is earlier');
72990 assert.equal(m.isSameOrAfter(moment(new Date(2011, 2, 2, 3, 8, 9, 10)), 'hour'), false, 'month is later');
72991 assert.equal(m.isSameOrAfter(moment(new Date(2010, 12, 2, 3, 8, 9, 10)), 'hour'), true, 'month is earlier');
72992 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 3, 3, 8, 9, 10)), 'hour'), false, 'day is later');
72993 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 1, 3, 8, 9, 10)), 'hour'), true, 'day is earlier');
72994 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 4, 8, 9, 10)), 'hour'), false, 'hour is later');
72995 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 2, 8, 9, 10)), 'hour'), true, 'hour is earlier');
72996 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 0, 0, 0)), 'hour'), true, 'exact start of hour');
72997 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 59, 59, 999)), 'hour'), true, 'exact end of hour');
72998 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 4, 0, 0, 0)), 'hour'), false, 'start of next hour');
72999 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 2, 59, 59, 999)), 'hour'), true, 'end of previous hour');
73000 assert.equal(m.isSameOrAfter(m, 'hour'), true, 'same moments are in the same hour');
73001 assert.equal(+m, +mCopy, 'isSameOrAfter hour should not change moment');
73002 });
73003
73004 test('is same or after minute', function (assert) {
73005 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
73006 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 4, 9, 10)), 'minute'), true, 'minute match');
73007 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 4, 9, 10)), 'minutes'), true, 'plural should work');
73008 assert.equal(m.isSameOrAfter(moment(new Date(2012, 1, 2, 3, 4, 9, 10)), 'minute'), false, 'year is later');
73009 assert.equal(m.isSameOrAfter(moment(new Date(2010, 1, 2, 3, 4, 9, 10)), 'minute'), true, 'year is earlier');
73010 assert.equal(m.isSameOrAfter(moment(new Date(2011, 2, 2, 3, 4, 9, 10)), 'minute'), false, 'month is later');
73011 assert.equal(m.isSameOrAfter(moment(new Date(2010, 12, 2, 3, 4, 9, 10)), 'minute'), true, 'month is earlier');
73012 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 3, 3, 4, 9, 10)), 'minute'), false, 'day is later');
73013 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 1, 3, 4, 9, 10)), 'minute'), true, 'day is earlier');
73014 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 4, 4, 9, 10)), 'minute'), false, 'hour is later');
73015 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 2, 4, 9, 10)), 'minute'), true, 'hour is earlier');
73016 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 5, 9, 10)), 'minute'), false, 'minute is later');
73017 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 3, 9, 10)), 'minute'), true, 'minute is earlier');
73018 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 4, 0, 0)), 'minute'), true, 'exact start of minute');
73019 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 4, 59, 999)), 'minute'), true, 'exact end of minute');
73020 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 5, 0, 0)), 'minute'), false, 'start of next minute');
73021 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 3, 59, 999)), 'minute'), true, 'end of previous minute');
73022 assert.equal(m.isSameOrAfter(m, 'minute'), true, 'same moments are in the same minute');
73023 assert.equal(+m, +mCopy, 'isSameOrAfter minute should not change moment');
73024 });
73025
73026 test('is same or after second', function (assert) {
73027 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
73028 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 4, 5, 10)), 'second'), true, 'second match');
73029 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 4, 5, 10)), 'seconds'), true, 'plural should work');
73030 assert.equal(m.isSameOrAfter(moment(new Date(2012, 1, 2, 3, 4, 5, 10)), 'second'), false, 'year is later');
73031 assert.equal(m.isSameOrAfter(moment(new Date(2010, 1, 2, 3, 4, 5, 10)), 'second'), true, 'year is earlier');
73032 assert.equal(m.isSameOrAfter(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'second'), false, 'month is later');
73033 assert.equal(m.isSameOrAfter(moment(new Date(2010, 12, 2, 3, 4, 5, 10)), 'second'), true, 'month is earlier');
73034 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 3, 3, 4, 5, 10)), 'second'), false, 'day is later');
73035 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 1, 3, 4, 5, 10)), 'second'), true, 'day is earlier');
73036 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 4, 4, 5, 10)), 'second'), false, 'hour is later');
73037 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 2, 4, 5, 10)), 'second'), true, 'hour is earlier');
73038 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 5, 5, 10)), 'second'), false, 'minute is later');
73039 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 3, 5, 10)), 'second'), true, 'minute is earlier');
73040 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 4, 6, 10)), 'second'), false, 'second is later');
73041 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 4, 4, 10)), 'second'), true, 'second is earlier');
73042 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 4, 5, 0)), 'second'), true, 'exact start of second');
73043 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 4, 5, 999)), 'second'), true, 'exact end of second');
73044 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 4, 6, 0)), 'second'), false, 'start of next second');
73045 assert.equal(m.isSameOrAfter(moment(new Date(2011, 1, 2, 3, 4, 4, 999)), 'second'), true, 'end of previous second');
73046 assert.equal(m.isSameOrAfter(m, 'second'), true, 'same moments are in the same second');
73047 assert.equal(+m, +mCopy, 'isSameOrAfter second should not change moment');
73048 });
73049
73050 test('is same or after millisecond', function (assert) {
73051 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
73052 assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'millisecond'), true, 'millisecond match');
73053 assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'milliseconds'), true, 'plural should work');
73054 assert.equal(m.isSameOrAfter(moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'millisecond'), false, 'year is later');
73055 assert.equal(m.isSameOrAfter(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'millisecond'), true, 'year is earlier');
73056 assert.equal(m.isSameOrAfter(moment(new Date(2011, 4, 2, 3, 4, 5, 10)), 'millisecond'), false, 'month is later');
73057 assert.equal(m.isSameOrAfter(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'millisecond'), true, 'month is earlier');
73058 assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 3, 3, 4, 5, 10)), 'millisecond'), false, 'day is later');
73059 assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 1, 1, 4, 5, 10)), 'millisecond'), true, 'day is earlier');
73060 assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 4, 4, 5, 10)), 'millisecond'), false, 'hour is later');
73061 assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 1, 4, 1, 5, 10)), 'millisecond'), true, 'hour is earlier');
73062 assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 5, 5, 10)), 'millisecond'), false, 'minute is later');
73063 assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 3, 5, 10)), 'millisecond'), true, 'minute is earlier');
73064 assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 4, 6, 10)), 'millisecond'), false, 'second is later');
73065 assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 4, 4, 5)), 'millisecond'), true, 'second is earlier');
73066 assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 4, 6, 11)), 'millisecond'), false, 'millisecond is later');
73067 assert.equal(m.isSameOrAfter(moment(new Date(2011, 3, 2, 3, 4, 4, 9)), 'millisecond'), true, 'millisecond is earlier');
73068 assert.equal(m.isSameOrAfter(m, 'millisecond'), true, 'same moments are in the same millisecond');
73069 assert.equal(+m, +mCopy, 'isSameOrAfter millisecond should not change moment');
73070 });
73071
73072 test('is same or after with utc offset moments', function (assert) {
73073 assert.ok(moment.parseZone('2013-02-01T00:00:00-05:00').isSameOrAfter(moment('2013-02-01'), 'year'), 'zoned vs local moment');
73074 assert.ok(moment('2013-02-01').isSameOrAfter(moment('2013-02-01').utcOffset('-05:00'), 'year'), 'local vs zoned moment');
73075 assert.ok(moment.parseZone('2013-02-01T00:00:00-05:00').isSameOrAfter(moment.parseZone('2013-02-01T00:00:00-06:30'), 'year'),
73076 'zoned vs (differently) zoned moment');
73077 });
73078
73079 test('is same or after with invalid moments', function (assert) {
73080 var m = moment(), invalid = moment.invalid();
73081 assert.equal(invalid.isSameOrAfter(invalid), false, 'invalid moments are not considered equal');
73082 assert.equal(m.isSameOrAfter(invalid), false, 'valid moment is not after invalid moment');
73083 assert.equal(invalid.isSameOrAfter(m), false, 'invalid moment is not after valid moment');
73084 assert.equal(m.isSameOrAfter(invalid, 'year'), false, 'invalid moment year');
73085 assert.equal(m.isSameOrAfter(invalid, 'month'), false, 'invalid moment month');
73086 assert.equal(m.isSameOrAfter(invalid, 'day'), false, 'invalid moment day');
73087 assert.equal(m.isSameOrAfter(invalid, 'hour'), false, 'invalid moment hour');
73088 assert.equal(m.isSameOrAfter(invalid, 'minute'), false, 'invalid moment minute');
73089 assert.equal(m.isSameOrAfter(invalid, 'second'), false, 'invalid moment second');
73090 assert.equal(m.isSameOrAfter(invalid, 'milliseconds'), false, 'invalid moment milliseconds');
73091 });
73f3c911
IC
73092
73093})));
c74a101d 73094
c74a101d
IC
73095
73096;(function (global, factory) {
73097 typeof exports === 'object' && typeof module !== 'undefined'
73098 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
73099 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
73100 factory(global.moment)
73f3c911 73101}(this, (function (moment) { 'use strict';
516f5f67 73102
db71a655
KM
73103 function each(array, callback) {
73104 var i;
73105 for (i = 0; i < array.length; i++) {
73106 callback(array[i], i, array);
73107 }
b135bf1a
IC
73108 }
73109
db71a655
KM
73110 function setupDeprecationHandler(test, moment$$1, scope) {
73111 test._expectedDeprecations = null;
73112 test._observedDeprecations = null;
73113 test._oldSupress = moment$$1.suppressDeprecationWarnings;
73114 moment$$1.suppressDeprecationWarnings = true;
73115 test.expectedDeprecations = function () {
73116 test._expectedDeprecations = arguments;
73117 test._observedDeprecations = [];
73118 };
73119 moment$$1.deprecationHandler = function (name, msg) {
73120 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
73121 if (deprecationId === -1) {
73122 throw new Error('Unexpected deprecation thrown name=' +
73123 name + ' msg=' + msg);
73124 }
73125 test._observedDeprecations[deprecationId] = 1;
73126 };
73127 }
516f5f67 73128
db71a655
KM
73129 function teardownDeprecationHandler(test, moment$$1, scope) {
73130 moment$$1.suppressDeprecationWarnings = test._oldSupress;
c74a101d 73131
db71a655
KM
73132 if (test._expectedDeprecations != null) {
73133 var missedDeprecations = [];
73134 each(test._expectedDeprecations, function (deprecationPattern, id) {
73135 if (test._observedDeprecations[id] !== 1) {
73136 missedDeprecations.push(deprecationPattern);
73137 }
73138 });
73139 if (missedDeprecations.length !== 0) {
73140 throw new Error('Expected deprecation warnings did not happen: ' +
73141 missedDeprecations.join(' '));
516f5f67 73142 }
73f3c911 73143 }
516f5f67
IC
73144 }
73145
db71a655
KM
73146 function matchedDeprecation(name, msg, deprecations) {
73147 if (deprecations == null) {
73148 return -1;
73f3c911 73149 }
db71a655
KM
73150 for (var i = 0; i < deprecations.length; ++i) {
73151 if (name != null && name === deprecations[i]) {
73152 return i;
73153 }
73154 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
73155 return i;
73156 }
73f3c911 73157 }
db71a655 73158 return -1;
516f5f67
IC
73159 }
73160
db71a655 73161 /*global QUnit:false*/
516f5f67 73162
db71a655 73163 var test = QUnit.test;
73f3c911 73164
db71a655
KM
73165 function module$1 (name, lifecycle) {
73166 QUnit.module(name, {
c58511b9 73167 beforeEach : function () {
db71a655
KM
73168 moment.locale('en');
73169 moment.createFromInputFallback = function (config) {
73170 throw new Error('input not handled by moment: ' + config._i);
73171 };
73172 setupDeprecationHandler(test, moment, 'core');
73173 if (lifecycle && lifecycle.setup) {
73174 lifecycle.setup();
73175 }
73176 },
c58511b9 73177 afterEach : function () {
db71a655
KM
73178 teardownDeprecationHandler(test, moment, 'core');
73179 if (lifecycle && lifecycle.teardown) {
73180 lifecycle.teardown();
73181 }
516f5f67 73182 }
db71a655 73183 });
73f3c911
IC
73184 }
73185
db71a655
KM
73186 module$1('is same or before');
73187
73188 test('is same or before without units', function (assert) {
73189 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
73190 assert.equal(m.isSameOrBefore(moment(new Date(2012, 3, 2, 3, 5, 5, 10))), true, 'year is later');
73191 assert.equal(m.isSameOrBefore(moment(new Date(2010, 3, 2, 3, 3, 5, 10))), false, 'year is earlier');
73192 assert.equal(m.isSameOrBefore(moment(new Date(2011, 4, 2, 3, 4, 5, 10))), true, 'month is later');
73193 assert.equal(m.isSameOrBefore(moment(new Date(2011, 2, 2, 3, 4, 5, 10))), false, 'month is earlier');
73194 assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 3, 3, 4, 5, 10))), true, 'day is later');
73195 assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 1, 3, 4, 5, 10))), false, 'day is earlier');
73196 assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 4, 4, 5, 10))), true, 'hour is later');
73197 assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 2, 4, 5, 10))), false, 'hour is earlier');
73198 assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 5, 5, 10))), true, 'minute is later');
73199 assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 3, 5, 10))), false, 'minute is earlier');
73200 assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 4, 6, 10))), true, 'second is later');
73201 assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 4, 4, 11))), false, 'second is earlier');
73202 assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 10))), true, 'millisecond match');
73203 assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 11))), true, 'millisecond is later');
73204 assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 9))), false, 'millisecond is earlier');
73205 assert.equal(m.isSameOrBefore(m), true, 'moments are the same as themselves');
73206 assert.equal(+m, +mCopy, 'isSameOrBefore second should not change moment');
73207 });
73208
73209 test('is same or before year', function (assert) {
73210 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
73211 assert.equal(m.isSameOrBefore(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'year'), true, 'year match');
73212 assert.equal(m.isSameOrBefore(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'years'), true, 'plural should work');
73213 assert.equal(m.isSameOrBefore(moment(new Date(2012, 5, 6, 7, 8, 9, 10)), 'year'), true, 'year is later');
73214 assert.equal(m.isSameOrBefore(moment(new Date(2010, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year is earlier');
73215 assert.equal(m.isSameOrBefore(moment(new Date(2011, 0, 1, 0, 0, 0, 0)), 'year'), true, 'exact start of year');
73216 assert.equal(m.isSameOrBefore(moment(new Date(2011, 11, 31, 23, 59, 59, 999)), 'year'), true, 'exact end of year');
73217 assert.equal(m.isSameOrBefore(moment(new Date(2012, 0, 1, 0, 0, 0, 0)), 'year'), true, 'start of next year');
73218 assert.equal(m.isSameOrBefore(moment(new Date(2010, 11, 31, 23, 59, 59, 999)), 'year'), false, 'end of previous year');
73219 assert.equal(m.isSameOrBefore(m, 'year'), true, 'same moments are in the same year');
73220 assert.equal(+m, +mCopy, 'isSameOrBefore year should not change moment');
73221 });
73222
73223 test('is same or before month', function (assert) {
73224 var m = moment(new Date(2011, 2, 3, 4, 5, 6, 7)), mCopy = moment(m);
73225 assert.equal(m.isSameOrBefore(moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'month'), true, 'month match');
73226 assert.equal(m.isSameOrBefore(moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'months'), true, 'plural should work');
73227 assert.equal(m.isSameOrBefore(moment(new Date(2012, 2, 6, 7, 8, 9, 10)), 'month'), true, 'year is later');
73228 assert.equal(m.isSameOrBefore(moment(new Date(2010, 2, 6, 7, 8, 9, 10)), 'month'), false, 'year is earlier');
73229 assert.equal(m.isSameOrBefore(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'month'), true, 'month is later');
73230 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 6, 7, 8, 9, 10)), 'month'), false, 'month is earlier');
73231 assert.equal(m.isSameOrBefore(moment(new Date(2011, 2, 1, 0, 0, 0, 0)), 'month'), true, 'exact start of month');
73232 assert.equal(m.isSameOrBefore(moment(new Date(2011, 2, 31, 23, 59, 59, 999)), 'month'), true, 'exact end of month');
73233 assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 1, 0, 0, 0, 0)), 'month'), true, 'start of next month');
73234 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 27, 23, 59, 59, 999)), 'month'), false, 'end of previous month');
73235 assert.equal(m.isSameOrBefore(m, 'month'), true, 'same moments are in the same month');
73236 assert.equal(+m, +mCopy, 'isSameOrBefore month should not change moment');
73237 });
73238
73239 test('is same or before day', function (assert) {
73240 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
73241 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'day'), true, 'day match');
73242 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'days'), true, 'plural should work');
73243 assert.equal(m.isSameOrBefore(moment(new Date(2012, 1, 2, 7, 8, 9, 10)), 'day'), true, 'year is later');
73244 assert.equal(m.isSameOrBefore(moment(new Date(2010, 1, 2, 7, 8, 9, 10)), 'day'), false, 'year is earlier');
73245 assert.equal(m.isSameOrBefore(moment(new Date(2011, 2, 2, 7, 8, 9, 10)), 'day'), true, 'month is later');
73246 assert.equal(m.isSameOrBefore(moment(new Date(2010, 12, 2, 7, 8, 9, 10)), 'day'), false, 'month is earlier');
73247 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 3, 7, 8, 9, 10)), 'day'), true, 'day is later');
73248 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 1, 7, 8, 9, 10)), 'day'), false, 'day is earlier');
73249 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 0, 0, 0, 0)), 'day'), true, 'exact start of day');
73250 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 23, 59, 59, 999)), 'day'), true, 'exact end of day');
73251 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 3, 0, 0, 0, 0)), 'day'), true, 'start of next day');
73252 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 1, 23, 59, 59, 999)), 'day'), false, 'end of previous day');
73253 assert.equal(m.isSameOrBefore(m, 'day'), true, 'same moments are in the same day');
73254 assert.equal(+m, +mCopy, 'isSameOrBefore day should not change moment');
73255 });
73256
73257 test('is same or before hour', function (assert) {
73258 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
73259 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 8, 9, 10)), 'hour'), true, 'hour match');
73260 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 8, 9, 10)), 'hours'), true, 'plural should work');
73261 assert.equal(m.isSameOrBefore(moment(new Date(2012, 1, 2, 3, 8, 9, 10)), 'hour'), true, 'year is later');
73262 assert.equal(m.isSameOrBefore(moment(new Date(2010, 1, 2, 3, 8, 9, 10)), 'hour'), false, 'year is earlier');
73263 assert.equal(m.isSameOrBefore(moment(new Date(2011, 2, 2, 3, 8, 9, 10)), 'hour'), true, 'month is later');
73264 assert.equal(m.isSameOrBefore(moment(new Date(2010, 12, 2, 3, 8, 9, 10)), 'hour'), false, 'month is earlier');
73265 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 3, 3, 8, 9, 10)), 'hour'), true, 'day is later');
73266 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 1, 3, 8, 9, 10)), 'hour'), false, 'day is earlier');
73267 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 4, 8, 9, 10)), 'hour'), true, 'hour is later');
73268 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 2, 8, 9, 10)), 'hour'), false, 'hour is earlier');
73269 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 0, 0, 0)), 'hour'), true, 'exact start of hour');
73270 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 59, 59, 999)), 'hour'), true, 'exact end of hour');
73271 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 4, 0, 0, 0)), 'hour'), true, 'start of next hour');
73272 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 2, 59, 59, 999)), 'hour'), false, 'end of previous hour');
73273 assert.equal(m.isSameOrBefore(m, 'hour'), true, 'same moments are in the same hour');
73274 assert.equal(+m, +mCopy, 'isSameOrBefore hour should not change moment');
73275 });
73276
73277 test('is same or before minute', function (assert) {
73278 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
73279 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 4, 9, 10)), 'minute'), true, 'minute match');
73280 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 4, 9, 10)), 'minutes'), true, 'plural should work');
73281 assert.equal(m.isSameOrBefore(moment(new Date(2012, 1, 2, 3, 4, 9, 10)), 'minute'), true, 'year is later');
73282 assert.equal(m.isSameOrBefore(moment(new Date(2010, 1, 2, 3, 4, 9, 10)), 'minute'), false, 'year is earlier');
73283 assert.equal(m.isSameOrBefore(moment(new Date(2011, 2, 2, 3, 4, 9, 10)), 'minute'), true, 'month is later');
73284 assert.equal(m.isSameOrBefore(moment(new Date(2010, 12, 2, 3, 4, 9, 10)), 'minute'), false, 'month is earlier');
73285 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 3, 3, 4, 9, 10)), 'minute'), true, 'day is later');
73286 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 1, 3, 4, 9, 10)), 'minute'), false, 'day is earlier');
73287 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 4, 4, 9, 10)), 'minute'), true, 'hour is later');
73288 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 2, 4, 9, 10)), 'minute'), false, 'hour is earlier');
73289 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 5, 9, 10)), 'minute'), true, 'minute is later');
73290 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 3, 9, 10)), 'minute'), false, 'minute is earlier');
73291 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 4, 0, 0)), 'minute'), true, 'exact start of minute');
73292 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 4, 59, 999)), 'minute'), true, 'exact end of minute');
73293 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 5, 0, 0)), 'minute'), true, 'start of next minute');
73294 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 3, 59, 999)), 'minute'), false, 'end of previous minute');
73295 assert.equal(m.isSameOrBefore(m, 'minute'), true, 'same moments are in the same minute');
73296 assert.equal(+m, +mCopy, 'isSameOrBefore minute should not change moment');
73297 });
73298
73299 test('is same or before second', function (assert) {
73300 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
73301 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 4, 5, 10)), 'second'), true, 'second match');
73302 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 4, 5, 10)), 'seconds'), true, 'plural should work');
73303 assert.equal(m.isSameOrBefore(moment(new Date(2012, 1, 2, 3, 4, 5, 10)), 'second'), true, 'year is later');
73304 assert.equal(m.isSameOrBefore(moment(new Date(2010, 1, 2, 3, 4, 5, 10)), 'second'), false, 'year is earlier');
73305 assert.equal(m.isSameOrBefore(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'second'), true, 'month is later');
73306 assert.equal(m.isSameOrBefore(moment(new Date(2010, 12, 2, 3, 4, 5, 10)), 'second'), false, 'month is earlier');
73307 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 3, 3, 4, 5, 10)), 'second'), true, 'day is later');
73308 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 1, 3, 4, 5, 10)), 'second'), false, 'day is earlier');
73309 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 4, 4, 5, 10)), 'second'), true, 'hour is later');
73310 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 2, 4, 5, 10)), 'second'), false, 'hour is earlier');
73311 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 5, 5, 10)), 'second'), true, 'minute is later');
73312 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 3, 5, 10)), 'second'), false, 'minute is earlier');
73313 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 4, 6, 10)), 'second'), true, 'second is later');
73314 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 4, 4, 10)), 'second'), false, 'second is earlier');
73315 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 4, 5, 0)), 'second'), true, 'exact start of second');
73316 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 4, 5, 999)), 'second'), true, 'exact end of second');
73317 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 4, 6, 0)), 'second'), true, 'start of next second');
73318 assert.equal(m.isSameOrBefore(moment(new Date(2011, 1, 2, 3, 4, 4, 999)), 'second'), false, 'end of previous second');
73319 assert.equal(m.isSameOrBefore(m, 'second'), true, 'same moments are in the same second');
73320 assert.equal(+m, +mCopy, 'isSameOrBefore second should not change moment');
73321 });
73322
73323 test('is same or before millisecond', function (assert) {
73324 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
73325 assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'millisecond'), true, 'millisecond match');
73326 assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'milliseconds'), true, 'plural should work');
73327 assert.equal(m.isSameOrBefore(moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'millisecond'), true, 'year is later');
73328 assert.equal(m.isSameOrBefore(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'millisecond'), false, 'year is earlier');
73329 assert.equal(m.isSameOrBefore(moment(new Date(2011, 4, 2, 3, 4, 5, 10)), 'millisecond'), true, 'month is later');
73330 assert.equal(m.isSameOrBefore(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'millisecond'), false, 'month is earlier');
73331 assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 3, 3, 4, 5, 10)), 'millisecond'), true, 'day is later');
73332 assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 1, 1, 4, 5, 10)), 'millisecond'), false, 'day is earlier');
73333 assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 4, 4, 5, 10)), 'millisecond'), true, 'hour is later');
73334 assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 1, 4, 1, 5, 10)), 'millisecond'), false, 'hour is earlier');
73335 assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 5, 5, 10)), 'millisecond'), true, 'minute is later');
73336 assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 3, 5, 10)), 'millisecond'), false, 'minute is earlier');
73337 assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 4, 6, 10)), 'millisecond'), true, 'second is later');
73338 assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 4, 4, 5)), 'millisecond'), false, 'second is earlier');
73339 assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 4, 6, 11)), 'millisecond'), true, 'millisecond is later');
73340 assert.equal(m.isSameOrBefore(moment(new Date(2011, 3, 2, 3, 4, 4, 9)), 'millisecond'), false, 'millisecond is earlier');
73341 assert.equal(m.isSameOrBefore(m, 'millisecond'), true, 'same moments are in the same millisecond');
73342 assert.equal(+m, +mCopy, 'isSameOrBefore millisecond should not change moment');
73343 });
73344
73345 test('is same with utc offset moments', function (assert) {
73346 assert.ok(moment.parseZone('2013-02-01T00:00:00-05:00').isSameOrBefore(moment('2013-02-01'), 'year'), 'zoned vs local moment');
73347 assert.ok(moment('2013-02-01').isSameOrBefore(moment('2013-02-01').utcOffset('-05:00'), 'year'), 'local vs zoned moment');
73348 assert.ok(
73349 moment.parseZone('2013-02-01T00:00:00-05:00').isSameOrBefore(moment.parseZone('2013-02-01T00:00:00-06:30'), 'year'),
73350 'zoned vs (differently) zoned moment'
73351 );
73352 });
73353
73354 test('is same with invalid moments', function (assert) {
73355 var m = moment(), invalid = moment.invalid();
73356 assert.equal(invalid.isSameOrBefore(invalid), false, 'invalid moments are not considered equal');
73357 assert.equal(m.isSameOrBefore(invalid), false, 'valid moment is not before invalid moment');
73358 assert.equal(invalid.isSameOrBefore(m), false, 'invalid moment is not before valid moment');
73359 assert.equal(m.isSameOrBefore(invalid, 'year'), false, 'invalid moment year');
73360 assert.equal(m.isSameOrBefore(invalid, 'month'), false, 'invalid moment month');
73361 assert.equal(m.isSameOrBefore(invalid, 'day'), false, 'invalid moment day');
73362 assert.equal(m.isSameOrBefore(invalid, 'hour'), false, 'invalid moment hour');
73363 assert.equal(m.isSameOrBefore(invalid, 'minute'), false, 'invalid moment minute');
73364 assert.equal(m.isSameOrBefore(invalid, 'second'), false, 'invalid moment second');
73365 assert.equal(m.isSameOrBefore(invalid, 'milliseconds'), false, 'invalid moment milliseconds');
73366 });
73f3c911
IC
73367
73368})));
516f5f67 73369
516f5f67 73370
c74a101d
IC
73371;(function (global, factory) {
73372 typeof exports === 'object' && typeof module !== 'undefined'
73373 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
73374 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
73375 factory(global.moment)
73f3c911 73376}(this, (function (moment) { 'use strict';
516f5f67 73377
db71a655
KM
73378 function each(array, callback) {
73379 var i;
73380 for (i = 0; i < array.length; i++) {
73381 callback(array[i], i, array);
73382 }
b135bf1a
IC
73383 }
73384
db71a655
KM
73385 function setupDeprecationHandler(test, moment$$1, scope) {
73386 test._expectedDeprecations = null;
73387 test._observedDeprecations = null;
73388 test._oldSupress = moment$$1.suppressDeprecationWarnings;
73389 moment$$1.suppressDeprecationWarnings = true;
73390 test.expectedDeprecations = function () {
73391 test._expectedDeprecations = arguments;
73392 test._observedDeprecations = [];
73393 };
73394 moment$$1.deprecationHandler = function (name, msg) {
73395 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
73396 if (deprecationId === -1) {
73397 throw new Error('Unexpected deprecation thrown name=' +
73398 name + ' msg=' + msg);
73399 }
73400 test._observedDeprecations[deprecationId] = 1;
73401 };
73402 }
516f5f67 73403
db71a655
KM
73404 function teardownDeprecationHandler(test, moment$$1, scope) {
73405 moment$$1.suppressDeprecationWarnings = test._oldSupress;
c74a101d 73406
db71a655
KM
73407 if (test._expectedDeprecations != null) {
73408 var missedDeprecations = [];
73409 each(test._expectedDeprecations, function (deprecationPattern, id) {
73410 if (test._observedDeprecations[id] !== 1) {
73411 missedDeprecations.push(deprecationPattern);
73412 }
73413 });
73414 if (missedDeprecations.length !== 0) {
73415 throw new Error('Expected deprecation warnings did not happen: ' +
73416 missedDeprecations.join(' '));
516f5f67 73417 }
73f3c911 73418 }
516f5f67
IC
73419 }
73420
db71a655
KM
73421 function matchedDeprecation(name, msg, deprecations) {
73422 if (deprecations == null) {
73423 return -1;
73424 }
73425 for (var i = 0; i < deprecations.length; ++i) {
73426 if (name != null && name === deprecations[i]) {
73427 return i;
73428 }
73429 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
73430 return i;
73431 }
73432 }
73f3c911
IC
73433 return -1;
73434 }
db71a655
KM
73435
73436 /*global QUnit:false*/
73437
73438 var test = QUnit.test;
73439
db71a655
KM
73440 function module$1 (name, lifecycle) {
73441 QUnit.module(name, {
c58511b9 73442 beforeEach : function () {
db71a655
KM
73443 moment.locale('en');
73444 moment.createFromInputFallback = function (config) {
73445 throw new Error('input not handled by moment: ' + config._i);
73446 };
73447 setupDeprecationHandler(test, moment, 'core');
73448 if (lifecycle && lifecycle.setup) {
73449 lifecycle.setup();
73450 }
73451 },
c58511b9 73452 afterEach : function () {
db71a655
KM
73453 teardownDeprecationHandler(test, moment, 'core');
73454 if (lifecycle && lifecycle.teardown) {
73455 lifecycle.teardown();
73456 }
73457 }
73458 });
73459 }
73460
73461 module$1('is valid');
73462
73463 test('array bad month', function (assert) {
73464 assert.equal(moment([2010, -1]).isValid(), false, 'month -1 invalid');
73465 assert.equal(moment([2100, 12]).isValid(), false, 'month 12 invalid');
73466 });
73467
73468 test('array good month', function (assert) {
73469 for (var i = 0; i < 12; i++) {
73470 assert.equal(moment([2010, i]).isValid(), true, 'month ' + i);
73471 assert.equal(moment.utc([2010, i]).isValid(), true, 'month ' + i);
73f3c911 73472 }
db71a655
KM
73473 });
73474
73475 test('Feb 29 0000 is valid', function (assert) {
73476 // https://github.com/moment/moment/issues/3358
73477 assert.ok(moment({year:0, month:1, date:29}).isValid(), 'Feb 29 0000 must be valid');
73478 assert.ok(moment({year:0, month:1, date:28}).add(1, 'd').isValid(), 'Feb 28 0000 + 1 day must be valid');
73479 });
73480
73481 test('array bad date', function (assert) {
73482 var tests = [
73483 moment([2010, 0, 0]),
73484 moment([2100, 0, 32]),
73485 moment.utc([2010, 0, 0]),
73486 moment.utc([2100, 0, 32])
73487 ],
73488 i, m;
73489
73490 for (i in tests) {
73491 m = tests[i];
73492 assert.equal(m.isValid(), false);
73f3c911 73493 }
db71a655 73494 });
73f3c911 73495
db71a655
KM
73496 test('h/hh with hour > 12', function (assert) {
73497 assert.ok(moment('06/20/2014 11:51 PM', 'MM/DD/YYYY hh:mm A', true).isValid(), '11 for hh');
73498 assert.ok(moment('06/20/2014 11:51 AM', 'MM/DD/YYYY hh:mm A', true).isValid(), '11 for hh');
73499 assert.ok(moment('06/20/2014 23:51 PM', 'MM/DD/YYYY hh:mm A').isValid(), 'non-strict validity 23 for hh');
73500 assert.ok(moment('06/20/2014 23:51 PM', 'MM/DD/YYYY hh:mm A').parsingFlags().bigHour, 'non-strict bigHour 23 for hh');
73501 assert.ok(!moment('06/20/2014 23:51 PM', 'MM/DD/YYYY hh:mm A', true).isValid(), 'validity 23 for hh');
73502 assert.ok(moment('06/20/2014 23:51 PM', 'MM/DD/YYYY hh:mm A', true).parsingFlags().bigHour, 'bigHour 23 for hh');
73503 });
516f5f67 73504
db71a655
KM
73505 test('array bad date leap year', function (assert) {
73506 assert.equal(moment([2010, 1, 29]).isValid(), false, '2010 feb 29');
73507 assert.equal(moment([2100, 1, 29]).isValid(), false, '2100 feb 29');
73508 assert.equal(moment([2008, 1, 30]).isValid(), false, '2008 feb 30');
73509 assert.equal(moment([2000, 1, 30]).isValid(), false, '2000 feb 30');
516f5f67 73510
db71a655
KM
73511 assert.equal(moment.utc([2010, 1, 29]).isValid(), false, 'utc 2010 feb 29');
73512 assert.equal(moment.utc([2100, 1, 29]).isValid(), false, 'utc 2100 feb 29');
73513 assert.equal(moment.utc([2008, 1, 30]).isValid(), false, 'utc 2008 feb 30');
73514 assert.equal(moment.utc([2000, 1, 30]).isValid(), false, 'utc 2000 feb 30');
73515 });
73f3c911 73516
db71a655
KM
73517 test('string + formats bad date', function (assert) {
73518 assert.equal(moment('2020-00-00', []).isValid(), false, 'invalid on empty array');
73519 assert.equal(moment('2020-00-00', ['YYYY-MM-DD', 'DD-MM-YYYY']).isValid(), false, 'invalid on all in array');
73520 assert.equal(moment('2020-00-00', ['DD-MM-YYYY', 'YYYY-MM-DD']).isValid(), false, 'invalid on all in array');
73521 assert.equal(moment('2020-01-01', ['YYYY-MM-DD', 'DD-MM-YYYY']).isValid(), true, 'valid on first');
73522 assert.equal(moment('2020-01-01', ['DD-MM-YYYY', 'YYYY-MM-DD']).isValid(), true, 'valid on last');
73523 assert.equal(moment('2020-01-01', ['YYYY-MM-DD', 'YYYY-DD-MM']).isValid(), true, 'valid on both');
73524 assert.equal(moment('2020-13-01', ['YYYY-MM-DD', 'YYYY-DD-MM']).isValid(), true, 'valid on last');
73f3c911 73525
db71a655
KM
73526 assert.equal(moment('12-13-2012', ['DD-MM-YYYY', 'YYYY-MM-DD']).isValid(), false, 'month rollover');
73527 assert.equal(moment('12-13-2012', ['DD-MM-YYYY', 'DD-MM-YYYY']).isValid(), false, 'month rollover');
73528 assert.equal(moment('38-12-2012', ['DD-MM-YYYY']).isValid(), false, 'day rollover');
73529 });
516f5f67 73530
db71a655
KM
73531 test('string nonsensical with format', function (assert) {
73532 assert.equal(moment('fail', 'MM-DD-YYYY').isValid(), false, 'string \'fail\' with format \'MM-DD-YYYY\'');
73533 assert.equal(moment('xx-xx-2001', 'DD-MM-YYY').isValid(), true, 'string \'xx-xx-2001\' with format \'MM-DD-YYYY\'');
73534 });
516f5f67 73535
db71a655
KM
73536 test('string with bad month name', function (assert) {
73537 assert.equal(moment('01-Nam-2012', 'DD-MMM-YYYY').isValid(), false, '\'Nam\' is an invalid month');
73538 assert.equal(moment('01-Aug-2012', 'DD-MMM-YYYY').isValid(), true, '\'Aug\' is a valid month');
73539 });
516f5f67 73540
db71a655
KM
73541 test('string with spaceless format', function (assert) {
73542 assert.equal(moment('10Sep2001', 'DDMMMYYYY').isValid(), true, 'Parsing 10Sep2001 should result in a valid date');
73543 });
b135bf1a 73544
db71a655
KM
73545 test('invalid string iso 8601', function (assert) {
73546 var tests = [
73547 '2010-00-00',
73548 '2010-01-00',
73549 '2010-01-40',
73550 '2010-01-01T24:01', // 24:00:00 is actually valid
73551 '2010-01-01T23:60',
73552 '2010-01-01T23:59:60'
73553 ], i;
b135bf1a 73554
db71a655
KM
73555 for (i = 0; i < tests.length; i++) {
73556 assert.equal(moment(tests[i], moment.ISO_8601).isValid(), false, tests[i] + ' should be invalid');
73557 assert.equal(moment.utc(tests[i], moment.ISO_8601).isValid(), false, tests[i] + ' should be invalid');
73f3c911 73558 }
db71a655 73559 });
516f5f67 73560
db71a655
KM
73561 test('invalid string iso 8601 + timezone', function (assert) {
73562 var tests = [
73563 '2010-00-00T+00:00',
73564 '2010-01-00T+00:00',
73565 '2010-01-40T+00:00',
73566 '2010-01-40T24:01+00:00',
73567 '2010-01-40T23:60+00:00',
73568 '2010-01-40T23:59:60+00:00',
73569 '2010-01-40T23:59:59.9999+00:00',
73570 '2010-01-40T23:59:59,9999+00:00'
73571 ], i;
c74a101d 73572
db71a655
KM
73573 for (i = 0; i < tests.length; i++) {
73574 assert.equal(moment(tests[i], moment.ISO_8601).isValid(), false, tests[i] + ' should be invalid');
73575 assert.equal(moment.utc(tests[i], moment.ISO_8601).isValid(), false, tests[i] + ' should be invalid');
73f3c911 73576 }
db71a655 73577 });
516f5f67 73578
db71a655
KM
73579 test('valid string iso 8601 - not strict', function (assert) {
73580 var tests = [
73581 '2010-01-30 00:00:00,000Z',
73582 '20100101',
73583 '20100130',
73584 '20100130T23+00:00',
73585 '20100130T2359+0000',
73586 '20100130T235959+0000',
73587 '20100130T235959,999+0000',
73588 '20100130T235959,999-0700',
73589 '20100130T000000,000+0700',
73590 '20100130 000000,000Z'
73591 ];
73f3c911 73592
db71a655
KM
73593 for (var i = 0; i < tests.length; i++) {
73594 assert.equal(moment(tests[i]).isValid(), true, tests[i] + ' should be valid in normal');
73595 assert.equal(moment.utc(tests[i]).isValid(), true, tests[i] + ' should be valid in normal');
73596 }
73597 });
73598
73599 test('valid string iso 8601 + timezone', function (assert) {
73600 var tests = [
73601 '2010-01-01',
73602 '2010-01-30',
73603 '2010-01-30T23+00:00',
73604 '2010-01-30T23:59+00:00',
73605 '2010-01-30T23:59:59+00:00',
73606 '2010-01-30T23:59:59.999+00:00',
73607 '2010-01-30T23:59:59.999-07:00',
73608 '2010-01-30T00:00:00.000+07:00',
73609 '2010-01-30T23:59:59.999-07',
73610 '2010-01-30T00:00:00.000+07',
73611 '2010-01-30 00:00:00.000Z'
73612 ], i;
516f5f67 73613
db71a655
KM
73614 for (i = 0; i < tests.length; i++) {
73615 assert.equal(moment(tests[i]).isValid(), true, tests[i] + ' should be valid in normal');
73616 assert.equal(moment.utc(tests[i]).isValid(), true, tests[i] + ' should be valid in normal');
73617 assert.equal(moment(tests[i], moment.ISO_8601, true).isValid(), true, tests[i] + ' should be valid in strict');
73618 assert.equal(moment.utc(tests[i], moment.ISO_8601, true).isValid(), true, tests[i] + ' should be valid in strict');
73619 }
73620 });
73621
73622 test('invalidAt', function (assert) {
73623 assert.equal(moment([2000, 12]).invalidAt(), 1, 'month 12 is invalid: 0-11');
73624 assert.equal(moment([2000, 1, 30]).invalidAt(), 2, '30 is not a valid february day');
73625 assert.equal(moment([2000, 1, 29, 25]).invalidAt(), 3, '25 is invalid hour');
73626 assert.equal(moment([2000, 1, 29, 24, 1]).invalidAt(), 3, '24:01 is invalid hour');
73627 assert.equal(moment([2000, 1, 29, 23, 60]).invalidAt(), 4, '60 is invalid minute');
73628 assert.equal(moment([2000, 1, 29, 23, 59, 60]).invalidAt(), 5, '60 is invalid second');
73629 assert.equal(moment([2000, 1, 29, 23, 59, 59, 1000]).invalidAt(), 6, '1000 is invalid millisecond');
73630 assert.equal(moment([2000, 1, 29, 23, 59, 59, 999]).invalidAt(), -1, '-1 if everything is fine');
73631 });
73632
73633 test('valid Unix timestamp', function (assert) {
73634 assert.equal(moment(1371065286, 'X').isValid(), true, 'number integer');
73635 assert.equal(moment(1379066897.0, 'X').isValid(), true, 'number whole 1dp');
73636 assert.equal(moment(1379066897.7, 'X').isValid(), true, 'number 1dp');
73637 assert.equal(moment(1379066897.00, 'X').isValid(), true, 'number whole 2dp');
73638 assert.equal(moment(1379066897.07, 'X').isValid(), true, 'number 2dp');
73639 assert.equal(moment(1379066897.17, 'X').isValid(), true, 'number 2dp');
73640 assert.equal(moment(1379066897.000, 'X').isValid(), true, 'number whole 3dp');
73641 assert.equal(moment(1379066897.007, 'X').isValid(), true, 'number 3dp');
73642 assert.equal(moment(1379066897.017, 'X').isValid(), true, 'number 3dp');
73643 assert.equal(moment(1379066897.157, 'X').isValid(), true, 'number 3dp');
73644 assert.equal(moment('1371065286', 'X').isValid(), true, 'string integer');
73645 assert.equal(moment('1379066897.', 'X').isValid(), true, 'string trailing .');
73646 assert.equal(moment('1379066897.0', 'X').isValid(), true, 'string whole 1dp');
73647 assert.equal(moment('1379066897.7', 'X').isValid(), true, 'string 1dp');
73648 assert.equal(moment('1379066897.00', 'X').isValid(), true, 'string whole 2dp');
73649 assert.equal(moment('1379066897.07', 'X').isValid(), true, 'string 2dp');
73650 assert.equal(moment('1379066897.17', 'X').isValid(), true, 'string 2dp');
73651 assert.equal(moment('1379066897.000', 'X').isValid(), true, 'string whole 3dp');
73652 assert.equal(moment('1379066897.007', 'X').isValid(), true, 'string 3dp');
73653 assert.equal(moment('1379066897.017', 'X').isValid(), true, 'string 3dp');
73654 assert.equal(moment('1379066897.157', 'X').isValid(), true, 'string 3dp');
73655 });
516f5f67 73656
db71a655
KM
73657 test('invalid Unix timestamp', function (assert) {
73658 assert.equal(moment(undefined, 'X').isValid(), false, 'undefined');
73659 assert.equal(moment('undefined', 'X').isValid(), false, 'string undefined');
73660 try {
73661 assert.equal(moment(null, 'X').isValid(), false, 'null');
73662 } catch (e) {
73663 assert.ok(true, 'null');
73664 }
516f5f67 73665
db71a655
KM
73666 assert.equal(moment('null', 'X').isValid(), false, 'string null');
73667 assert.equal(moment([], 'X').isValid(), false, 'array');
73668 assert.equal(moment('{}', 'X').isValid(), false, 'object');
73669 try {
73670 assert.equal(moment('', 'X').isValid(), false, 'string empty');
73671 } catch (e) {
73672 assert.ok(true, 'string empty');
73f3c911 73673 }
516f5f67 73674
db71a655
KM
73675 assert.equal(moment(' ', 'X').isValid(), false, 'string space');
73676 });
516f5f67 73677
db71a655
KM
73678 test('valid Unix offset milliseconds', function (assert) {
73679 assert.equal(moment(1234567890123, 'x').isValid(), true, 'number integer');
73680 assert.equal(moment('1234567890123', 'x').isValid(), true, 'string integer');
73681 });
516f5f67 73682
db71a655
KM
73683 test('invalid Unix offset milliseconds', function (assert) {
73684 assert.equal(moment(undefined, 'x').isValid(), false, 'undefined');
73685 assert.equal(moment('undefined', 'x').isValid(), false, 'string undefined');
73686 try {
73687 assert.equal(moment(null, 'x').isValid(), false, 'null');
73688 } catch (e) {
73689 assert.ok(true, 'null');
73690 }
516f5f67 73691
db71a655
KM
73692 assert.equal(moment('null', 'x').isValid(), false, 'string null');
73693 assert.equal(moment([], 'x').isValid(), false, 'array');
73694 assert.equal(moment('{}', 'x').isValid(), false, 'object');
73695 try {
73696 assert.equal(moment('', 'x').isValid(), false, 'string empty');
73697 } catch (e) {
73698 assert.ok(true, 'string empty');
73699 }
516f5f67 73700
db71a655
KM
73701 assert.equal(moment(' ', 'x').isValid(), false, 'string space');
73702 });
516f5f67 73703
db71a655
KM
73704 test('empty', function (assert) {
73705 assert.equal(moment(null).isValid(), false, 'null');
73706 assert.equal(moment('').isValid(), false, 'empty string');
73707 assert.equal(moment(null, 'YYYY').isValid(), false, 'format + null');
73708 assert.equal(moment('', 'YYYY').isValid(), false, 'format + empty string');
73709 assert.equal(moment(' ', 'YYYY').isValid(), false, 'format + empty when trimmed');
73710 });
516f5f67 73711
db71a655
KM
73712 test('days of the year', function (assert) {
73713 assert.equal(moment('2010 300', 'YYYY DDDD').isValid(), true, 'day 300 of year valid');
73714 assert.equal(moment('2010 365', 'YYYY DDDD').isValid(), true, 'day 365 of year valid');
73715 assert.equal(moment('2010 366', 'YYYY DDDD').isValid(), false, 'day 366 of year invalid');
73716 assert.equal(moment('2012 365', 'YYYY DDDD').isValid(), true, 'day 365 of leap year valid');
73717 assert.equal(moment('2012 366', 'YYYY DDDD').isValid(), true, 'day 366 of leap year valid');
73718 assert.equal(moment('2012 367', 'YYYY DDDD').isValid(), false, 'day 367 of leap year invalid');
73719 });
516f5f67 73720
db71a655
KM
73721 test('24:00:00.000 is valid', function (assert) {
73722 assert.equal(moment('2014-01-01 24', 'YYYY-MM-DD HH').isValid(), true, '24 is valid');
73723 assert.equal(moment('2014-01-01 24:00', 'YYYY-MM-DD HH:mm').isValid(), true, '24:00 is valid');
73724 assert.equal(moment('2014-01-01 24:01', 'YYYY-MM-DD HH:mm').isValid(), false, '24:01 is not valid');
73725 });
73f3c911 73726
db71a655
KM
73727 test('oddball permissiveness', function (assert) {
73728 // https://github.com/moment/moment/issues/1128
73729 assert.ok(moment('2010-10-3199', ['MM/DD/YYYY', 'MM-DD-YYYY', 'YYYY-MM-DD']).isValid());
73f3c911 73730
db71a655
KM
73731 // https://github.com/moment/moment/issues/1122
73732 assert.ok(moment('3:25', ['h:mma', 'hh:mma', 'H:mm', 'HH:mm']).isValid());
73733 });
73f3c911 73734
db71a655
KM
73735 test('0 hour is invalid in strict', function (assert) {
73736 assert.equal(moment('00:01', 'hh:mm', true).isValid(), false, '00 hour is invalid in strict');
73737 assert.equal(moment('00:01', 'hh:mm').isValid(), true, '00 hour is valid in normal');
73738 assert.equal(moment('0:01', 'h:mm', true).isValid(), false, '0 hour is invalid in strict');
73739 assert.equal(moment('0:01', 'h:mm').isValid(), true, '0 hour is valid in normal');
73740 });
73f3c911
IC
73741
73742})));
516f5f67 73743
516f5f67 73744
c74a101d
IC
73745;(function (global, factory) {
73746 typeof exports === 'object' && typeof module !== 'undefined'
73747 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
73748 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
73749 factory(global.moment)
73f3c911 73750}(this, (function (moment) { 'use strict';
516f5f67 73751
db71a655
KM
73752 function each(array, callback) {
73753 var i;
73754 for (i = 0; i < array.length; i++) {
73755 callback(array[i], i, array);
73756 }
b135bf1a
IC
73757 }
73758
db71a655
KM
73759 function setupDeprecationHandler(test, moment$$1, scope) {
73760 test._expectedDeprecations = null;
73761 test._observedDeprecations = null;
73762 test._oldSupress = moment$$1.suppressDeprecationWarnings;
73763 moment$$1.suppressDeprecationWarnings = true;
73764 test.expectedDeprecations = function () {
73765 test._expectedDeprecations = arguments;
73766 test._observedDeprecations = [];
73767 };
73768 moment$$1.deprecationHandler = function (name, msg) {
73769 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
73770 if (deprecationId === -1) {
73771 throw new Error('Unexpected deprecation thrown name=' +
73772 name + ' msg=' + msg);
73773 }
73774 test._observedDeprecations[deprecationId] = 1;
73775 };
73776 }
f2af24d5 73777
db71a655
KM
73778 function teardownDeprecationHandler(test, moment$$1, scope) {
73779 moment$$1.suppressDeprecationWarnings = test._oldSupress;
f2af24d5 73780
db71a655
KM
73781 if (test._expectedDeprecations != null) {
73782 var missedDeprecations = [];
73783 each(test._expectedDeprecations, function (deprecationPattern, id) {
73784 if (test._observedDeprecations[id] !== 1) {
73785 missedDeprecations.push(deprecationPattern);
73786 }
73787 });
73788 if (missedDeprecations.length !== 0) {
73789 throw new Error('Expected deprecation warnings did not happen: ' +
73790 missedDeprecations.join(' '));
f2af24d5 73791 }
f2af24d5
IC
73792 }
73793 }
f2af24d5 73794
db71a655
KM
73795 function matchedDeprecation(name, msg, deprecations) {
73796 if (deprecations == null) {
73797 return -1;
f2af24d5 73798 }
db71a655
KM
73799 for (var i = 0; i < deprecations.length; ++i) {
73800 if (name != null && name === deprecations[i]) {
73801 return i;
73802 }
73803 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
73804 return i;
73805 }
f2af24d5 73806 }
db71a655 73807 return -1;
f2af24d5 73808 }
f2af24d5 73809
db71a655 73810 /*global QUnit:false*/
f2af24d5 73811
db71a655 73812 var test = QUnit.test;
f2af24d5 73813
db71a655
KM
73814 function module$1 (name, lifecycle) {
73815 QUnit.module(name, {
c58511b9 73816 beforeEach : function () {
db71a655
KM
73817 moment.locale('en');
73818 moment.createFromInputFallback = function (config) {
73819 throw new Error('input not handled by moment: ' + config._i);
73820 };
73821 setupDeprecationHandler(test, moment, 'core');
73822 if (lifecycle && lifecycle.setup) {
73823 lifecycle.setup();
73824 }
73825 },
c58511b9 73826 afterEach : function () {
db71a655
KM
73827 teardownDeprecationHandler(test, moment, 'core');
73828 if (lifecycle && lifecycle.teardown) {
73829 lifecycle.teardown();
73830 }
f2af24d5 73831 }
db71a655
KM
73832 });
73833 }
73834
73835 module$1('leap year');
73836
73837 test('leap year', function (assert) {
73838 assert.equal(moment([2010, 0, 1]).isLeapYear(), false, '2010');
73839 assert.equal(moment([2100, 0, 1]).isLeapYear(), false, '2100');
73840 assert.equal(moment([2008, 0, 1]).isLeapYear(), true, '2008');
73841 assert.equal(moment([2000, 0, 1]).isLeapYear(), true, '2000');
73842 });
f2af24d5
IC
73843
73844})));
73845
73846
73847;(function (global, factory) {
73848 typeof exports === 'object' && typeof module !== 'undefined'
73849 && typeof require === 'function' ? factory(require('../../moment')) :
73850 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
73851 factory(global.moment)
73852}(this, (function (moment) { 'use strict';
73853
db71a655
KM
73854 function each(array, callback) {
73855 var i;
73856 for (i = 0; i < array.length; i++) {
73857 callback(array[i], i, array);
73858 }
f2af24d5 73859 }
f2af24d5 73860
db71a655
KM
73861 function setupDeprecationHandler(test, moment$$1, scope) {
73862 test._expectedDeprecations = null;
73863 test._observedDeprecations = null;
73864 test._oldSupress = moment$$1.suppressDeprecationWarnings;
73865 moment$$1.suppressDeprecationWarnings = true;
73866 test.expectedDeprecations = function () {
73867 test._expectedDeprecations = arguments;
73868 test._observedDeprecations = [];
73869 };
73870 moment$$1.deprecationHandler = function (name, msg) {
73871 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
73872 if (deprecationId === -1) {
73873 throw new Error('Unexpected deprecation thrown name=' +
73874 name + ' msg=' + msg);
73875 }
73876 test._observedDeprecations[deprecationId] = 1;
73877 };
73878 }
73f3c911 73879
db71a655
KM
73880 function teardownDeprecationHandler(test, moment$$1, scope) {
73881 moment$$1.suppressDeprecationWarnings = test._oldSupress;
73f3c911 73882
db71a655
KM
73883 if (test._expectedDeprecations != null) {
73884 var missedDeprecations = [];
73885 each(test._expectedDeprecations, function (deprecationPattern, id) {
73886 if (test._observedDeprecations[id] !== 1) {
73887 missedDeprecations.push(deprecationPattern);
73888 }
73889 });
73890 if (missedDeprecations.length !== 0) {
73891 throw new Error('Expected deprecation warnings did not happen: ' +
73892 missedDeprecations.join(' '));
d6651c21
IC
73893 }
73894 }
73f3c911 73895 }
73f3c911 73896
db71a655
KM
73897 function matchedDeprecation(name, msg, deprecations) {
73898 if (deprecations == null) {
73899 return -1;
73f3c911 73900 }
db71a655
KM
73901 for (var i = 0; i < deprecations.length; ++i) {
73902 if (name != null && name === deprecations[i]) {
73903 return i;
73904 }
73905 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
73906 return i;
73907 }
73f3c911 73908 }
db71a655 73909 return -1;
73f3c911 73910 }
b135bf1a 73911
db71a655 73912 /*global QUnit:false*/
516f5f67 73913
db71a655 73914 var test = QUnit.test;
516f5f67 73915
db71a655
KM
73916 function module$1 (name, lifecycle) {
73917 QUnit.module(name, {
c58511b9 73918 beforeEach : function () {
db71a655
KM
73919 moment.locale('en');
73920 moment.createFromInputFallback = function (config) {
73921 throw new Error('input not handled by moment: ' + config._i);
73922 };
73923 setupDeprecationHandler(test, moment, 'core');
73924 if (lifecycle && lifecycle.setup) {
73925 lifecycle.setup();
73926 }
73927 },
c58511b9 73928 afterEach : function () {
db71a655
KM
73929 teardownDeprecationHandler(test, moment, 'core');
73930 if (lifecycle && lifecycle.teardown) {
73931 lifecycle.teardown();
73932 }
516f5f67 73933 }
db71a655
KM
73934 });
73935 }
73f3c911 73936
db71a655
KM
73937 module$1('listers');
73938
73939 test('default', function (assert) {
73940 assert.deepEqual(moment.months(), ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']);
73941 assert.deepEqual(moment.monthsShort(), ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']);
73942 assert.deepEqual(moment.weekdays(), ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']);
73943 assert.deepEqual(moment.weekdaysShort(), ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']);
73944 assert.deepEqual(moment.weekdaysMin(), ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']);
73945 });
73946
73947 test('index', function (assert) {
73948 assert.equal(moment.months(0), 'January');
73949 assert.equal(moment.months(2), 'March');
73950 assert.equal(moment.monthsShort(0), 'Jan');
73951 assert.equal(moment.monthsShort(2), 'Mar');
73952 assert.equal(moment.weekdays(0), 'Sunday');
73953 assert.equal(moment.weekdays(2), 'Tuesday');
73954 assert.equal(moment.weekdaysShort(0), 'Sun');
73955 assert.equal(moment.weekdaysShort(2), 'Tue');
73956 assert.equal(moment.weekdaysMin(0), 'Su');
73957 assert.equal(moment.weekdaysMin(2), 'Tu');
73958 });
73959
73960 test('localized', function (assert) {
73961 var months = 'one_two_three_four_five_six_seven_eight_nine_ten_eleven_twelve'.split('_'),
73962 monthsShort = 'on_tw_th_fo_fi_si_se_ei_ni_te_el_tw'.split('_'),
73963 weekdays = 'one_two_three_four_five_six_seven'.split('_'),
73964 weekdaysShort = 'on_tw_th_fo_fi_si_se'.split('_'),
73965 weekdaysMin = '1_2_3_4_5_6_7'.split('_'),
73966 weekdaysLocale = 'four_five_six_seven_one_two_three'.split('_'),
73967 weekdaysShortLocale = 'fo_fi_si_se_on_tw_th'.split('_'),
73968 weekdaysMinLocale = '4_5_6_7_1_2_3'.split('_'),
73969 week = {
73970 dow : 3,
73971 doy : 6
73972 };
516f5f67 73973
db71a655
KM
73974 moment.locale('numerologists', {
73975 months : months,
73976 monthsShort : monthsShort,
73977 weekdays : weekdays,
73978 weekdaysShort: weekdaysShort,
73979 weekdaysMin: weekdaysMin,
73980 week : week
73981 });
b135bf1a 73982
db71a655
KM
73983 assert.deepEqual(moment.months(), months);
73984 assert.deepEqual(moment.monthsShort(), monthsShort);
73985 assert.deepEqual(moment.weekdays(), weekdays);
73986 assert.deepEqual(moment.weekdaysShort(), weekdaysShort);
73987 assert.deepEqual(moment.weekdaysMin(), weekdaysMin);
b135bf1a 73988
db71a655
KM
73989 assert.equal(moment.months(0), 'one');
73990 assert.equal(moment.monthsShort(0), 'on');
73991 assert.equal(moment.weekdays(0), 'one');
73992 assert.equal(moment.weekdaysShort(0), 'on');
73993 assert.equal(moment.weekdaysMin(0), '1');
f2af24d5 73994
db71a655
KM
73995 assert.equal(moment.months(2), 'three');
73996 assert.equal(moment.monthsShort(2), 'th');
73997 assert.equal(moment.weekdays(2), 'three');
73998 assert.equal(moment.weekdaysShort(2), 'th');
73999 assert.equal(moment.weekdaysMin(2), '3');
b135bf1a 74000
db71a655
KM
74001 assert.deepEqual(moment.weekdays(true), weekdaysLocale);
74002 assert.deepEqual(moment.weekdaysShort(true), weekdaysShortLocale);
74003 assert.deepEqual(moment.weekdaysMin(true), weekdaysMinLocale);
9483e2a4 74004
db71a655
KM
74005 assert.equal(moment.weekdays(true, 0), 'four');
74006 assert.equal(moment.weekdaysShort(true, 0), 'fo');
74007 assert.equal(moment.weekdaysMin(true, 0), '4');
74008
74009 assert.equal(moment.weekdays(false, 2), 'three');
74010 assert.equal(moment.weekdaysShort(false, 2), 'th');
74011 assert.equal(moment.weekdaysMin(false, 2), '3');
74012 });
d6651c21 74013
db71a655
KM
74014 test('with functions', function (assert) {
74015 var monthsShort = 'one_two_three_four_five_six_seven_eight_nine_ten_eleven_twelve'.split('_'),
74016 monthsShortWeird = 'onesy_twosy_threesy_foursy_fivesy_sixsy_sevensy_eightsy_ninesy_tensy_elevensy_twelvesy'.split('_');
d6651c21 74017
db71a655
KM
74018 moment.locale('difficult', {
74019
74020 monthsShort: function (m, format) {
74021 var arr = format.match(/-MMM-/) ? monthsShortWeird : monthsShort;
74022 return arr[m.month()];
d6651c21
IC
74023 }
74024 });
d6651c21 74025
db71a655
KM
74026 assert.deepEqual(moment.monthsShort(), monthsShort);
74027 assert.deepEqual(moment.monthsShort('MMM'), monthsShort);
74028 assert.deepEqual(moment.monthsShort('-MMM-'), monthsShortWeird);
b135bf1a 74029
db71a655
KM
74030 assert.deepEqual(moment.monthsShort('MMM', 2), 'three');
74031 assert.deepEqual(moment.monthsShort('-MMM-', 2), 'threesy');
74032 assert.deepEqual(moment.monthsShort(2), 'three');
74033 });
25cc720f 74034
db71a655
KM
74035 test('with locale data', function (assert) {
74036 var months = 'one_two_three_four_five_six_seven_eight_nine_ten_eleven_twelve'.split('_'),
74037 monthsShort = 'on_tw_th_fo_fi_si_se_ei_ni_te_el_tw'.split('_'),
74038 weekdays = 'one_two_three_four_five_six_seven'.split('_'),
74039 weekdaysShort = 'on_tw_th_fo_fi_si_se'.split('_'),
74040 weekdaysMin = '1_2_3_4_5_6_7'.split('_');
25cc720f 74041
db71a655 74042 var customLocale = moment.localeData('numerologists');
c74a101d 74043
db71a655
KM
74044 assert.deepEqual(customLocale.months(), months);
74045 assert.deepEqual(customLocale.monthsShort(), monthsShort);
74046 assert.deepEqual(customLocale.weekdays(), weekdays);
74047 assert.deepEqual(customLocale.weekdaysShort(), weekdaysShort);
74048 assert.deepEqual(customLocale.weekdaysMin(), weekdaysMin);
74049 });
73f3c911
IC
74050
74051})));
25cc720f 74052
25cc720f 74053
c74a101d
IC
74054;(function (global, factory) {
74055 typeof exports === 'object' && typeof module !== 'undefined'
74056 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
74057 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
74058 factory(global.moment)
73f3c911 74059}(this, (function (moment) { 'use strict';
516f5f67 74060
db71a655
KM
74061 function each(array, callback) {
74062 var i;
74063 for (i = 0; i < array.length; i++) {
74064 callback(array[i], i, array);
74065 }
b135bf1a
IC
74066 }
74067
db71a655
KM
74068 function setupDeprecationHandler(test, moment$$1, scope) {
74069 test._expectedDeprecations = null;
74070 test._observedDeprecations = null;
74071 test._oldSupress = moment$$1.suppressDeprecationWarnings;
74072 moment$$1.suppressDeprecationWarnings = true;
74073 test.expectedDeprecations = function () {
74074 test._expectedDeprecations = arguments;
74075 test._observedDeprecations = [];
74076 };
74077 moment$$1.deprecationHandler = function (name, msg) {
74078 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
74079 if (deprecationId === -1) {
74080 throw new Error('Unexpected deprecation thrown name=' +
74081 name + ' msg=' + msg);
74082 }
74083 test._observedDeprecations[deprecationId] = 1;
74084 };
74085 }
73f3c911 74086
db71a655
KM
74087 function teardownDeprecationHandler(test, moment$$1, scope) {
74088 moment$$1.suppressDeprecationWarnings = test._oldSupress;
73f3c911 74089
db71a655
KM
74090 if (test._expectedDeprecations != null) {
74091 var missedDeprecations = [];
74092 each(test._expectedDeprecations, function (deprecationPattern, id) {
74093 if (test._observedDeprecations[id] !== 1) {
74094 missedDeprecations.push(deprecationPattern);
74095 }
74096 });
74097 if (missedDeprecations.length !== 0) {
74098 throw new Error('Expected deprecation warnings did not happen: ' +
74099 missedDeprecations.join(' '));
d6651c21
IC
74100 }
74101 }
73f3c911 74102 }
73f3c911 74103
db71a655
KM
74104 function matchedDeprecation(name, msg, deprecations) {
74105 if (deprecations == null) {
74106 return -1;
73f3c911 74107 }
db71a655
KM
74108 for (var i = 0; i < deprecations.length; ++i) {
74109 if (name != null && name === deprecations[i]) {
74110 return i;
74111 }
74112 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
74113 return i;
74114 }
73f3c911 74115 }
db71a655 74116 return -1;
73f3c911 74117 }
b135bf1a 74118
db71a655
KM
74119 /*global QUnit:false*/
74120
74121 var test = QUnit.test;
74122
db71a655
KM
74123 function module$1 (name, lifecycle) {
74124 QUnit.module(name, {
c58511b9 74125 beforeEach : function () {
db71a655
KM
74126 moment.locale('en');
74127 moment.createFromInputFallback = function (config) {
74128 throw new Error('input not handled by moment: ' + config._i);
74129 };
74130 setupDeprecationHandler(test, moment, 'core');
74131 if (lifecycle && lifecycle.setup) {
74132 lifecycle.setup();
74133 }
74134 },
c58511b9 74135 afterEach : function () {
db71a655
KM
74136 teardownDeprecationHandler(test, moment, 'core');
74137 if (lifecycle && lifecycle.teardown) {
74138 lifecycle.teardown();
74139 }
74140 }
74141 });
74142 }
516f5f67 74143
db71a655 74144 var indexOf;
516f5f67 74145
db71a655
KM
74146 if (Array.prototype.indexOf) {
74147 indexOf = Array.prototype.indexOf;
74148 } else {
74149 indexOf = function (o) {
74150 // I know
74151 var i;
74152 for (i = 0; i < this.length; ++i) {
74153 if (this[i] === o) {
74154 return i;
74155 }
74156 }
74157 return -1;
74158 };
74159 }
c74a101d 74160
db71a655 74161 module$1('locale', {
73f3c911 74162 setup : function () {
db71a655
KM
74163 // TODO: Remove once locales are switched to ES6
74164 each([{
74165 name: 'en-gb',
74166 data: {}
74167 }, {
74168 name: 'en-ca',
74169 data: {}
74170 }, {
74171 name: 'es',
74172 data: {
74173 relativeTime: {past: 'hace %s', s: 'unos segundos', d: 'un día'},
74174 months: 'enero_febrero_marzo_abril_mayo_junio_julio_agosto_septiembre_octubre_noviembre_diciembre'.split('_')
74175 }
74176 }, {
74177 name: 'fr',
74178 data: {}
74179 }, {
74180 name: 'fr-ca',
74181 data: {}
74182 }, {
74183 name: 'it',
74184 data: {}
74185 }, {
74186 name: 'zh-cn',
74187 data: {
74188 months: '一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月'.split('_')
74189 }
74190 }], function (locale) {
74191 if (moment.locale(locale.name) !== locale.name) {
74192 moment.defineLocale(locale.name, locale.data);
74193 }
74194 });
73f3c911 74195 moment.locale('en');
73f3c911 74196 }
db71a655 74197 });
516f5f67 74198
db71a655
KM
74199 test('library getters and setters', function (assert) {
74200 var r = moment.locale('en');
d6651c21 74201
db71a655
KM
74202 assert.equal(r, 'en', 'locale should return en by default');
74203 assert.equal(moment.locale(), 'en', 'locale should return en by default');
d6651c21 74204
db71a655
KM
74205 moment.locale('fr');
74206 assert.equal(moment.locale(), 'fr', 'locale should return the changed locale');
d6651c21 74207
db71a655
KM
74208 moment.locale('en-gb');
74209 assert.equal(moment.locale(), 'en-gb', 'locale should return the changed locale');
d6651c21 74210
db71a655
KM
74211 moment.locale('en');
74212 assert.equal(moment.locale(), 'en', 'locale should reset');
d6651c21 74213
db71a655
KM
74214 moment.locale('does-not-exist');
74215 assert.equal(moment.locale(), 'en', 'locale should reset');
d6651c21 74216
db71a655
KM
74217 moment.locale('EN');
74218 assert.equal(moment.locale(), 'en', 'Normalize locale key case');
d6651c21 74219
db71a655
KM
74220 moment.locale('EN_gb');
74221 assert.equal(moment.locale(), 'en-gb', 'Normalize locale key underscore');
74222 });
d6651c21 74223
db71a655
KM
74224 test('library setter array of locales', function (assert) {
74225 assert.equal(moment.locale(['non-existent', 'fr', 'also-non-existent']), 'fr', 'passing an array uses the first valid locale');
74226 assert.equal(moment.locale(['es', 'fr', 'also-non-existent']), 'es', 'passing an array uses the first valid locale');
74227 });
d6651c21 74228
db71a655
KM
74229 test('library setter locale substrings', function (assert) {
74230 assert.equal(moment.locale('fr-crap'), 'fr', 'use substrings');
74231 assert.equal(moment.locale('fr-does-not-exist'), 'fr', 'uses deep substrings');
74232 assert.equal(moment.locale('fr-CA-does-not-exist'), 'fr-ca', 'uses deepest substring');
74233 });
d6651c21 74234
db71a655
KM
74235 test('library getter locale array and substrings', function (assert) {
74236 assert.equal(moment.locale(['en-CH', 'fr']), 'en', 'prefer root locale to shallower ones');
74237 assert.equal(moment.locale(['en-gb-leeds', 'en-CA']), 'en-gb', 'prefer root locale to shallower ones');
74238 assert.equal(moment.locale(['en-fake', 'en-CA']), 'en-ca', 'prefer alternatives with shared roots');
74239 assert.equal(moment.locale(['en-fake', 'en-fake2', 'en-ca']), 'en-ca', 'prefer alternatives with shared roots');
74240 assert.equal(moment.locale(['fake-CA', 'fake-MX', 'fr']), 'fr', 'always find something if possible');
74241 assert.equal(moment.locale(['fake-CA', 'fake-MX', 'fr']), 'fr', 'always find something if possible');
74242 assert.equal(moment.locale(['fake-CA', 'fake-MX', 'fr-fake-fake-fake']), 'fr', 'always find something if possible');
74243 assert.equal(moment.locale(['en', 'en-CA']), 'en', 'prefer earlier if it works');
74244 });
d6651c21 74245
db71a655
KM
74246 test('library ensure inheritance', function (assert) {
74247 moment.locale('made-up', {
74248 // I put them out of order
74249 months : 'February_March_April_May_June_July_August_September_October_November_December_January'.split('_')
74250 // the rest of the properties should be inherited.
74251 });
d6651c21 74252
db71a655
KM
74253 assert.equal(moment([2012, 5, 6]).format('MMMM'), 'July', 'Override some of the configs');
74254 assert.equal(moment([2012, 5, 6]).format('MMM'), 'Jun', 'But not all of them');
74255 });
d6651c21 74256
db71a655
KM
74257 test('library ensure inheritance LT L LL LLL LLLL', function (assert) {
74258 var locale = 'test-inherit-lt';
516f5f67 74259
db71a655
KM
74260 moment.defineLocale(locale, {
74261 longDateFormat : {
74262 LT : '-[LT]-',
74263 L : '-[L]-',
74264 LL : '-[LL]-',
74265 LLL : '-[LLL]-',
74266 LLLL : '-[LLLL]-'
74267 },
74268 calendar : {
74269 sameDay : '[sameDay] LT',
74270 nextDay : '[nextDay] L',
74271 nextWeek : '[nextWeek] LL',
74272 lastDay : '[lastDay] LLL',
74273 lastWeek : '[lastWeek] LLLL',
74274 sameElse : 'L'
74275 }
74276 });
516f5f67 74277
db71a655 74278 moment.locale('es');
b135bf1a 74279
db71a655
KM
74280 assert.equal(moment().locale(locale).calendar(), 'sameDay -LT-', 'Should use instance locale in LT formatting');
74281 assert.equal(moment().add(1, 'days').locale(locale).calendar(), 'nextDay -L-', 'Should use instance locale in L formatting');
74282 assert.equal(moment().add(-1, 'days').locale(locale).calendar(), 'lastDay -LLL-', 'Should use instance locale in LL formatting');
74283 assert.equal(moment().add(4, 'days').locale(locale).calendar(), 'nextWeek -LL-', 'Should use instance locale in LLL formatting');
74284 assert.equal(moment().add(-4, 'days').locale(locale).calendar(), 'lastWeek -LLLL-', 'Should use instance locale in LLLL formatting');
74285 });
73f3c911 74286
db71a655
KM
74287 test('library localeData', function (assert) {
74288 moment.locale('en');
f2af24d5 74289
db71a655 74290 var jan = moment([2000, 0]);
f2af24d5 74291
db71a655
KM
74292 assert.equal(moment.localeData().months(jan), 'January', 'no arguments returns global');
74293 assert.equal(moment.localeData('zh-cn').months(jan), '一月', 'a string returns the locale based on key');
74294 assert.equal(moment.localeData(moment().locale('es')).months(jan), 'enero', 'if you pass in a moment it uses the moment\'s locale');
74295 });
74296
74297 test('library deprecations', function (assert) {
74298 test.expectedDeprecations('moment.lang');
74299 moment.lang('dude', {months: ['Movember']});
74300 assert.equal(moment.locale(), 'dude', 'setting the lang sets the locale');
74301 assert.equal(moment.lang(), moment.locale());
74302 assert.equal(moment.langData(), moment.localeData(), 'langData is localeData');
74303 moment.defineLocale('dude', null);
74304 });
74305
74306 test('defineLocale', function (assert) {
74307 moment.locale('en');
74308 moment.defineLocale('dude', {months: ['Movember']});
74309 assert.equal(moment().locale(), 'dude', 'defineLocale also sets it');
74310 assert.equal(moment().locale('dude').locale(), 'dude', 'defineLocale defines a locale');
74311 moment.defineLocale('dude', null);
74312 });
74313
74314 test('locales', function (assert) {
74315 moment.defineLocale('dude', {months: ['Movember']});
74316 assert.equal(true, !!~indexOf.call(moment.locales(), 'dude'), 'locales returns an array of defined locales');
74317 assert.equal(true, !!~indexOf.call(moment.locales(), 'en'), 'locales should always include english');
74318 moment.defineLocale('dude', null);
74319 });
74320
74321 test('library convenience', function (assert) {
74322 moment.locale('something', {week: {dow: 3}});
74323 moment.locale('something');
74324 assert.equal(moment.locale(), 'something', 'locale can be used to create the locale too');
74325 moment.defineLocale('something', null);
74326 });
74327
74328 test('firstDayOfWeek firstDayOfYear locale getters', function (assert) {
74329 moment.locale('something', {week: {dow: 3, doy: 4}});
74330 moment.locale('something');
74331 assert.equal(moment.localeData().firstDayOfWeek(), 3, 'firstDayOfWeek');
74332 assert.equal(moment.localeData().firstDayOfYear(), 4, 'firstDayOfYear');
74333 moment.defineLocale('something', null);
74334 });
74335
74336 test('instance locale method', function (assert) {
74337 moment.locale('en');
f2af24d5 74338
db71a655
KM
74339 assert.equal(moment([2012, 5, 6]).format('MMMM'), 'June', 'Normally default to global');
74340 assert.equal(moment([2012, 5, 6]).locale('es').format('MMMM'), 'junio', 'Use the instance specific locale');
74341 assert.equal(moment([2012, 5, 6]).format('MMMM'), 'June', 'Using an instance specific locale does not affect other moments');
74342 });
f2af24d5 74343
db71a655
KM
74344 test('instance locale method with array', function (assert) {
74345 var m = moment().locale(['non-existent', 'fr', 'also-non-existent']);
74346 assert.equal(m.locale(), 'fr', 'passing an array uses the first valid locale');
74347 m = moment().locale(['es', 'fr', 'also-non-existent']);
74348 assert.equal(m.locale(), 'es', 'passing an array uses the first valid locale');
74349 });
f2af24d5 74350
db71a655
KM
74351 test('instance getter locale substrings', function (assert) {
74352 var m = moment();
f2af24d5 74353
db71a655
KM
74354 m.locale('fr-crap');
74355 assert.equal(m.locale(), 'fr', 'use substrings');
f2af24d5 74356
db71a655
KM
74357 m.locale('fr-does-not-exist');
74358 assert.equal(m.locale(), 'fr', 'uses deep substrings');
73f3c911
IC
74359 });
74360
db71a655
KM
74361 test('instance locale persists with manipulation', function (assert) {
74362 moment.locale('en');
b135bf1a 74363
db71a655
KM
74364 assert.equal(moment([2012, 5, 6]).locale('es').add({days: 1}).format('MMMM'), 'junio', 'With addition');
74365 assert.equal(moment([2012, 5, 6]).locale('es').day(0).format('MMMM'), 'junio', 'With day getter');
74366 assert.equal(moment([2012, 5, 6]).locale('es').endOf('day').format('MMMM'), 'junio', 'With endOf');
74367 });
d6651c21 74368
db71a655
KM
74369 test('instance locale persists with cloning', function (assert) {
74370 moment.locale('en');
d6651c21 74371
db71a655
KM
74372 var a = moment([2012, 5, 6]).locale('es'),
74373 b = a.clone(),
74374 c = moment(a);
d6651c21 74375
db71a655
KM
74376 assert.equal(b.format('MMMM'), 'junio', 'using moment.fn.clone()');
74377 assert.equal(b.format('MMMM'), 'junio', 'using moment()');
74378 });
d6651c21 74379
db71a655
KM
74380 test('duration locale method', function (assert) {
74381 moment.locale('en');
d6651c21 74382
db71a655
KM
74383 assert.equal(moment.duration({seconds: 44}).humanize(), 'a few seconds', 'Normally default to global');
74384 assert.equal(moment.duration({seconds: 44}).locale('es').humanize(), 'unos segundos', 'Use the instance specific locale');
74385 assert.equal(moment.duration({seconds: 44}).humanize(), 'a few seconds', 'Using an instance specific locale does not affect other durations');
74386 });
d6651c21 74387
db71a655
KM
74388 test('duration locale persists with cloning', function (assert) {
74389 moment.locale('en');
73f3c911 74390
db71a655
KM
74391 var a = moment.duration({seconds: 44}).locale('es'),
74392 b = moment.duration(a);
74393
74394 assert.equal(b.humanize(), 'unos segundos', 'using moment.duration()');
74395 });
74396
74397 test('changing the global locale doesn\'t affect existing duration instances', function (assert) {
74398 var mom = moment.duration();
74399 moment.locale('fr');
74400 assert.equal('en', mom.locale());
74401 });
74402
74403 test('duration deprecations', function (assert) {
74404 test.expectedDeprecations('moment().lang()');
74405 assert.equal(moment.duration().lang(), moment.duration().localeData(), 'duration.lang is the same as duration.localeData');
74406 });
74407
74408 test('from and fromNow with invalid date', function (assert) {
74409 assert.equal(moment(NaN).from(), 'Invalid date', 'moment.from with invalid moment');
74410 assert.equal(moment(NaN).fromNow(), 'Invalid date', 'moment.fromNow with invalid moment');
74411 });
74412
74413 test('from relative time future', function (assert) {
74414 var start = moment([2007, 1, 28]);
74415
74416 assert.equal(start.from(moment([2007, 1, 28]).subtract({s: 44})), 'in a few seconds', '44 seconds = a few seconds');
74417 assert.equal(start.from(moment([2007, 1, 28]).subtract({s: 45})), 'in a minute', '45 seconds = a minute');
74418 assert.equal(start.from(moment([2007, 1, 28]).subtract({s: 89})), 'in a minute', '89 seconds = a minute');
74419 assert.equal(start.from(moment([2007, 1, 28]).subtract({s: 90})), 'in 2 minutes', '90 seconds = 2 minutes');
74420 assert.equal(start.from(moment([2007, 1, 28]).subtract({m: 44})), 'in 44 minutes', '44 minutes = 44 minutes');
74421 assert.equal(start.from(moment([2007, 1, 28]).subtract({m: 45})), 'in an hour', '45 minutes = an hour');
74422 assert.equal(start.from(moment([2007, 1, 28]).subtract({m: 89})), 'in an hour', '89 minutes = an hour');
74423 assert.equal(start.from(moment([2007, 1, 28]).subtract({m: 90})), 'in 2 hours', '90 minutes = 2 hours');
74424 assert.equal(start.from(moment([2007, 1, 28]).subtract({h: 5})), 'in 5 hours', '5 hours = 5 hours');
74425 assert.equal(start.from(moment([2007, 1, 28]).subtract({h: 21})), 'in 21 hours', '21 hours = 21 hours');
74426 assert.equal(start.from(moment([2007, 1, 28]).subtract({h: 22})), 'in a day', '22 hours = a day');
74427 assert.equal(start.from(moment([2007, 1, 28]).subtract({h: 35})), 'in a day', '35 hours = a day');
74428 assert.equal(start.from(moment([2007, 1, 28]).subtract({h: 36})), 'in 2 days', '36 hours = 2 days');
74429 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 1})), 'in a day', '1 day = a day');
74430 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 5})), 'in 5 days', '5 days = 5 days');
74431 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 25})), 'in 25 days', '25 days = 25 days');
74432 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 26})), 'in a month', '26 days = a month');
74433 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 30})), 'in a month', '30 days = a month');
74434 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 45})), 'in a month', '45 days = a month');
74435 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 47})), 'in 2 months', '47 days = 2 months');
74436 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 74})), 'in 2 months', '74 days = 2 months');
74437 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 78})), 'in 3 months', '78 days = 3 months');
74438 assert.equal(start.from(moment([2007, 1, 28]).subtract({M: 1})), 'in a month', '1 month = a month');
74439 assert.equal(start.from(moment([2007, 1, 28]).subtract({M: 5})), 'in 5 months', '5 months = 5 months');
74440 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 315})), 'in 10 months', '315 days = 10 months');
74441 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 344})), 'in a year', '344 days = a year');
74442 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 345})), 'in a year', '345 days = a year');
74443 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 548})), 'in 2 years', '548 days = in 2 years');
74444 assert.equal(start.from(moment([2007, 1, 28]).subtract({y: 1})), 'in a year', '1 year = a year');
74445 assert.equal(start.from(moment([2007, 1, 28]).subtract({y: 5})), 'in 5 years', '5 years = 5 years');
74446 });
74447
74448 test('from relative time past', function (assert) {
74449 var start = moment([2007, 1, 28]);
74450
74451 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44})), 'a few seconds ago', '44 seconds = a few seconds');
74452 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45})), 'a minute ago', '45 seconds = a minute');
74453 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89})), 'a minute ago', '89 seconds = a minute');
74454 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90})), '2 minutes ago', '90 seconds = 2 minutes');
74455 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44})), '44 minutes ago', '44 minutes = 44 minutes');
74456 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45})), 'an hour ago', '45 minutes = an hour');
74457 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89})), 'an hour ago', '89 minutes = an hour');
74458 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90})), '2 hours ago', '90 minutes = 2 hours');
74459 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5})), '5 hours ago', '5 hours = 5 hours');
74460 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21})), '21 hours ago', '21 hours = 21 hours');
74461 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22})), 'a day ago', '22 hours = a day');
74462 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35})), 'a day ago', '35 hours = a day');
74463 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36})), '2 days ago', '36 hours = 2 days');
74464 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1})), 'a day ago', '1 day = a day');
74465 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5})), '5 days ago', '5 days = 5 days');
74466 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25})), '25 days ago', '25 days = 25 days');
74467 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26})), 'a month ago', '26 days = a month');
74468 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30})), 'a month ago', '30 days = a month');
74469 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43})), 'a month ago', '43 days = a month');
74470 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46})), '2 months ago', '46 days = 2 months');
74471 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74})), '2 months ago', '75 days = 2 months');
74472 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76})), '3 months ago', '76 days = 3 months');
74473 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1})), 'a month ago', '1 month = a month');
74474 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5})), '5 months ago', '5 months = 5 months');
74475 assert.equal(start.from(moment([2007, 1, 28]).add({d: 315})), '10 months ago', '315 days = 10 months');
74476 assert.equal(start.from(moment([2007, 1, 28]).add({d: 344})), 'a year ago', '344 days = a year');
74477 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345})), 'a year ago', '345 days = a year');
74478 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548})), '2 years ago', '548 days = 2 years');
74479 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1})), 'a year ago', '1 year = a year');
74480 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5})), '5 years ago', '5 years = 5 years');
74481 });
74482
74483 test('instance locale used with from', function (assert) {
74484 moment.locale('en');
c74a101d 74485
db71a655
KM
74486 var a = moment([2012, 5, 6]).locale('es'),
74487 b = moment([2012, 5, 7]);
9483e2a4 74488
db71a655
KM
74489 assert.equal(a.from(b), 'hace un día', 'preserve locale of first moment');
74490 assert.equal(b.from(a), 'in a day', 'do not preserve locale of second moment');
74491 });
c74a101d 74492
db71a655
KM
74493 test('instance localeData', function (assert) {
74494 moment.defineLocale('dude', {week: {dow: 3}});
74495 assert.equal(moment().locale('dude').localeData()._week.dow, 3);
74496 moment.defineLocale('dude', null);
74497 });
c74a101d 74498
db71a655
KM
74499 test('month name callback function', function (assert) {
74500 function fakeReplace(m, format) {
74501 if (/test/.test(format)) {
74502 return 'test';
c74a101d 74503 }
db71a655
KM
74504 if (m.date() === 1) {
74505 return 'date';
74506 }
74507 return 'default';
73f3c911 74508 }
c74a101d 74509
db71a655
KM
74510 moment.locale('made-up-2', {
74511 months : fakeReplace,
74512 monthsShort : fakeReplace,
74513 weekdays : fakeReplace,
74514 weekdaysShort : fakeReplace,
74515 weekdaysMin : fakeReplace
74516 });
516f5f67 74517
db71a655
KM
74518 assert.equal(moment().format('[test] dd ddd dddd MMM MMMM'), 'test test test test test test', 'format month name function should be able to access the format string');
74519 assert.equal(moment([2011, 0, 1]).format('dd ddd dddd MMM MMMM'), 'date date date date date', 'format month name function should be able to access the moment object');
74520 assert.equal(moment([2011, 0, 2]).format('dd ddd dddd MMM MMMM'), 'default default default default default', 'format month name function should be able to access the moment object');
74521 });
516f5f67 74522
db71a655
KM
74523 test('changing parts of a locale config', function (assert) {
74524 test.expectedDeprecations('defineLocaleOverride');
516f5f67 74525
db71a655
KM
74526 moment.locale('partial-lang', {
74527 months : 'a b c d e f g h i j k l'.split(' ')
74528 });
73f3c911 74529
db71a655 74530 assert.equal(moment([2011, 0, 1]).format('MMMM'), 'a', 'should be able to set locale values when creating the localeuage');
73f3c911 74531
db71a655
KM
74532 moment.locale('partial-lang', {
74533 monthsShort : 'A B C D E F G H I J K L'.split(' ')
74534 });
516f5f67 74535
db71a655 74536 assert.equal(moment([2011, 0, 1]).format('MMMM MMM'), 'a A', 'should be able to set locale values after creating the localeuage');
516f5f67 74537
db71a655
KM
74538 moment.defineLocale('partial-lang', null);
74539 });
516f5f67 74540
db71a655
KM
74541 test('start/endOf week feature for first-day-is-monday locales', function (assert) {
74542 moment.locale('monday-lang', {
74543 week : {
74544 dow : 1 // Monday is the first day of the week
74545 }
74546 });
b135bf1a 74547
db71a655
KM
74548 moment.locale('monday-lang');
74549 assert.equal(moment([2013, 0, 1]).startOf('week').day(), 1, 'for locale monday-lang first day of the week should be monday');
74550 assert.equal(moment([2013, 0, 1]).endOf('week').day(), 0, 'for locale monday-lang last day of the week should be sunday');
74551 moment.defineLocale('monday-lang', null);
74552 });
73f3c911 74553
db71a655
KM
74554 test('meridiem parsing', function (assert) {
74555 moment.locale('meridiem-parsing', {
74556 meridiemParse : /[bd]/i,
74557 isPM : function (input) {
74558 return input === 'b';
74559 }
74560 });
73f3c911 74561
db71a655
KM
74562 moment.locale('meridiem-parsing');
74563 assert.equal(moment('2012-01-01 3b', 'YYYY-MM-DD ha').hour(), 15, 'Custom parsing of meridiem should work');
74564 assert.equal(moment('2012-01-01 3d', 'YYYY-MM-DD ha').hour(), 3, 'Custom parsing of meridiem should work');
74565 moment.defineLocale('meridiem-parsing', null);
74566 });
73f3c911 74567
db71a655
KM
74568 test('invalid date formatting', function (assert) {
74569 moment.locale('has-invalid', {
74570 invalidDate: 'KHAAAAAAAAAAAN!'
73f3c911 74571 });
73f3c911 74572
db71a655
KM
74573 assert.equal(moment.invalid().format(), 'KHAAAAAAAAAAAN!');
74574 assert.equal(moment.invalid().format('YYYY-MM-DD'), 'KHAAAAAAAAAAAN!');
74575 moment.defineLocale('has-invalid', null);
74576 });
b135bf1a 74577
db71a655
KM
74578 test('return locale name', function (assert) {
74579 var registered = moment.locale('return-this', {});
516f5f67 74580
db71a655
KM
74581 assert.equal(registered, 'return-this', 'returns the locale configured');
74582 moment.locale('return-this', null);
74583 });
516f5f67 74584
db71a655
KM
74585 test('changing the global locale doesn\'t affect existing instances', function (assert) {
74586 var mom = moment();
74587 moment.locale('fr');
74588 assert.equal('en', mom.locale());
74589 });
c74a101d 74590
db71a655
KM
74591 test('setting a language on instance returns the original moment for chaining', function (assert) {
74592 test.expectedDeprecations('moment().lang()');
74593 var mom = moment();
73f3c911 74594
db71a655
KM
74595 assert.equal(mom.lang('fr'), mom, 'setting the language (lang) returns the original moment for chaining');
74596 assert.equal(mom.locale('it'), mom, 'setting the language (locale) returns the original moment for chaining');
74597 });
516f5f67 74598
db71a655
KM
74599 test('lang(key) changes the language of the instance', function (assert) {
74600 test.expectedDeprecations('moment().lang()');
74601 var m = moment().month(0);
74602 m.lang('fr');
74603 assert.equal(m.locale(), 'fr', 'm.lang(key) changes instance locale');
74604 });
516f5f67 74605
db71a655
KM
74606 test('moment#locale(false) resets to global locale', function (assert) {
74607 var m = moment();
74608
74609 moment.locale('fr');
74610 m.locale('it');
74611
74612 assert.equal(moment.locale(), 'fr', 'global locale is it');
74613 assert.equal(m.locale(), 'it', 'instance locale is it');
74614 m.locale(false);
74615 assert.equal(m.locale(), 'fr', 'instance locale reset to global locale');
74616 });
74617
74618 test('moment().locale with missing key doesn\'t change locale', function (assert) {
74619 assert.equal(moment().locale('boo').localeData(), moment.localeData(),
74620 'preserve global locale in case of bad locale id');
74621 });
9483e2a4 74622
db71a655
KM
74623 test('moment().lang with missing key doesn\'t change locale', function (assert) {
74624 test.expectedDeprecations('moment().lang()');
74625 assert.equal(moment().lang('boo').localeData(), moment.localeData(),
74626 'preserve global locale in case of bad locale id');
74627 });
b135bf1a 74628
2e2a5b35
KM
74629 test('when in strict mode with inexact parsing, treat periods in short weekdays literally, not as the regex-period', function (assert) {
74630 moment.defineLocale('periods-in-short-weekdays', {
74631 weekdays : 'Monday_Tuesday_Wednesday_Thursday_Friday_Saturday_Sunday'.split('_'),
74632 weekdaysShort : 'mon_t...s_wed_thurs_fri_sat_sun'.split('_'),
74633 weekdaysParseExact : false
74634 });
74635
74636 moment().locale('periods-in-short-weekdays');
74637 assert.equal(moment('thurs', 'ddd', true).format('dddd'), 'Thursday');
74638 });
74639
74640 test('when in strict mode with inexact parsing, treat periods in full weekdays literally, not as the regex-period', function (assert) {
74641 moment.defineLocale('periods-in-full-weekdays', {
74642 weekdays : 'Monday_T....day_Wednesday_Thursday_Friday_Saturday_Sunday'.split('_'),
74643 weekdaysShort : 'mon_tues_wed_thurs_fri_sat_sun'.split('_'),
74644 weekdaysParseExact : false
74645 });
74646
74647 moment().locale('periods-in-full-weekdays');
74648 assert.equal(moment('Thursday', 'dddd', true).format('ddd'), 'thurs');
74649 });
74650
74651 test('when in strict mode with inexact parsing, treat periods in min-weekdays literally, not as the regex-period', function (assert) {
74652 moment.defineLocale('periods-in-min-weekdays', {
74653 weekdays : 'Monday_Tuesday_Wednesday_Thursday_Friday_Saturday_Sunday'.split('_'),
74654 weekdaysMin : 'mon_t...s_wed_thurs_fri_sat_sun'.split('_'),
74655 weekdaysParseExact : false
74656 });
74657
74658 moment().locale('periods-in-min-weekdays');
74659 assert.equal(moment('thurs', 'dd', true).format('dddd'), 'Thursday');
74660 });
74661
b135bf1a 74662
db71a655
KM
74663 // TODO: Enable this after fixing pl months parse hack hack
74664 // test('monthsParseExact', function (assert) {
74665 // var locale = 'test-months-parse-exact';
b135bf1a 74666
db71a655
KM
74667 // moment.defineLocale(locale, {
74668 // monthsParseExact: true,
74669 // months: 'A_AA_AAA_B_B B_BB B_C_C-C_C,C2C_D_D+D_D`D*D'.split('_'),
74670 // monthsShort: 'E_EE_EEE_F_FF_FFF_G_GG_GGG_H_HH_HHH'.split('_')
74671 // });
4caa2683 74672
db71a655
KM
74673 // assert.equal(moment('A', 'MMMM', true).month(), 0, 'parse long month 0 with MMMM');
74674 // assert.equal(moment('AA', 'MMMM', true).month(), 1, 'parse long month 1 with MMMM');
74675 // assert.equal(moment('AAA', 'MMMM', true).month(), 2, 'parse long month 2 with MMMM');
74676 // assert.equal(moment('B B', 'MMMM', true).month(), 4, 'parse long month 4 with MMMM');
74677 // assert.equal(moment('BB B', 'MMMM', true).month(), 5, 'parse long month 5 with MMMM');
74678 // assert.equal(moment('C-C', 'MMMM', true).month(), 7, 'parse long month 7 with MMMM');
74679 // assert.equal(moment('C,C2C', 'MMMM', true).month(), 8, 'parse long month 8 with MMMM');
74680 // assert.equal(moment('D+D', 'MMMM', true).month(), 10, 'parse long month 10 with MMMM');
74681 // assert.equal(moment('D`D*D', 'MMMM', true).month(), 11, 'parse long month 11 with MMMM');
b135bf1a 74682
db71a655
KM
74683 // assert.equal(moment('E', 'MMM', true).month(), 0, 'parse long month 0 with MMM');
74684 // assert.equal(moment('EE', 'MMM', true).month(), 1, 'parse long month 1 with MMM');
74685 // assert.equal(moment('EEE', 'MMM', true).month(), 2, 'parse long month 2 with MMM');
b135bf1a 74686
db71a655
KM
74687 // assert.equal(moment('A', 'MMM').month(), 0, 'non-strict parse long month 0 with MMM');
74688 // assert.equal(moment('AA', 'MMM').month(), 1, 'non-strict parse long month 1 with MMM');
74689 // assert.equal(moment('AAA', 'MMM').month(), 2, 'non-strict parse long month 2 with MMM');
74690 // assert.equal(moment('E', 'MMMM').month(), 0, 'non-strict parse short month 0 with MMMM');
74691 // assert.equal(moment('EE', 'MMMM').month(), 1, 'non-strict parse short month 1 with MMMM');
74692 // assert.equal(moment('EEE', 'MMMM').month(), 2, 'non-strict parse short month 2 with MMMM');
74693 // });
b135bf1a 74694
73f3c911 74695})));
b135bf1a 74696
b135bf1a
IC
74697
74698;(function (global, factory) {
74699 typeof exports === 'object' && typeof module !== 'undefined'
74700 && typeof require === 'function' ? factory(require('../../moment')) :
74701 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
74702 factory(global.moment)
73f3c911 74703}(this, (function (moment) { 'use strict';
b135bf1a 74704
db71a655
KM
74705 function each(array, callback) {
74706 var i;
74707 for (i = 0; i < array.length; i++) {
74708 callback(array[i], i, array);
74709 }
b135bf1a
IC
74710 }
74711
db71a655
KM
74712 function setupDeprecationHandler(test, moment$$1, scope) {
74713 test._expectedDeprecations = null;
74714 test._observedDeprecations = null;
74715 test._oldSupress = moment$$1.suppressDeprecationWarnings;
74716 moment$$1.suppressDeprecationWarnings = true;
74717 test.expectedDeprecations = function () {
74718 test._expectedDeprecations = arguments;
74719 test._observedDeprecations = [];
74720 };
74721 moment$$1.deprecationHandler = function (name, msg) {
74722 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
74723 if (deprecationId === -1) {
74724 throw new Error('Unexpected deprecation thrown name=' +
74725 name + ' msg=' + msg);
74726 }
74727 test._observedDeprecations[deprecationId] = 1;
74728 };
74729 }
73f3c911 74730
db71a655
KM
74731 function teardownDeprecationHandler(test, moment$$1, scope) {
74732 moment$$1.suppressDeprecationWarnings = test._oldSupress;
73f3c911 74733
db71a655
KM
74734 if (test._expectedDeprecations != null) {
74735 var missedDeprecations = [];
74736 each(test._expectedDeprecations, function (deprecationPattern, id) {
74737 if (test._observedDeprecations[id] !== 1) {
74738 missedDeprecations.push(deprecationPattern);
74739 }
74740 });
74741 if (missedDeprecations.length !== 0) {
74742 throw new Error('Expected deprecation warnings did not happen: ' +
74743 missedDeprecations.join(' '));
d6651c21
IC
74744 }
74745 }
73f3c911 74746 }
73f3c911 74747
db71a655
KM
74748 function matchedDeprecation(name, msg, deprecations) {
74749 if (deprecations == null) {
74750 return -1;
73f3c911 74751 }
db71a655
KM
74752 for (var i = 0; i < deprecations.length; ++i) {
74753 if (name != null && name === deprecations[i]) {
74754 return i;
74755 }
74756 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
74757 return i;
74758 }
73f3c911 74759 }
db71a655 74760 return -1;
73f3c911 74761 }
b135bf1a 74762
db71a655 74763 /*global QUnit:false*/
516f5f67 74764
db71a655 74765 var test = QUnit.test;
516f5f67 74766
db71a655
KM
74767 function module$1 (name, lifecycle) {
74768 QUnit.module(name, {
c58511b9 74769 beforeEach : function () {
db71a655
KM
74770 moment.locale('en');
74771 moment.createFromInputFallback = function (config) {
74772 throw new Error('input not handled by moment: ' + config._i);
74773 };
74774 setupDeprecationHandler(test, moment, 'core');
74775 if (lifecycle && lifecycle.setup) {
74776 lifecycle.setup();
74777 }
74778 },
c58511b9 74779 afterEach : function () {
db71a655
KM
74780 teardownDeprecationHandler(test, moment, 'core');
74781 if (lifecycle && lifecycle.teardown) {
74782 lifecycle.teardown();
74783 }
516f5f67 74784 }
db71a655 74785 });
b135bf1a
IC
74786 }
74787
db71a655 74788 module$1('locale inheritance');
73f3c911 74789
db71a655
KM
74790 test('calendar', function (assert) {
74791 moment.defineLocale('base-cal', {
74792 calendar : {
74793 sameDay: '[Today at] HH:mm',
74794 nextDay: '[Tomorrow at] HH:mm',
74795 nextWeek: '[Next week at] HH:mm',
74796 lastDay: '[Yesterday at] HH:mm',
74797 lastWeek: '[Last week at] HH:mm',
74798 sameElse: '[whatever]'
74799 }
74800 });
74801 moment.defineLocale('child-cal', {
74802 parentLocale: 'base-cal',
74803 calendar: {
74804 sameDay: '[Today] HH:mm',
74805 nextDay: '[Tomorrow] HH:mm',
74806 nextWeek: '[Next week] HH:mm'
d6651c21 74807 }
73f3c911 74808 });
73f3c911 74809
db71a655
KM
74810 moment.locale('child-cal');
74811 var anchor = moment.utc('2015-05-05T12:00:00', moment.ISO_8601);
74812 assert.equal(anchor.clone().add(3, 'hours').calendar(anchor), 'Today 15:00', 'today uses child version');
74813 assert.equal(anchor.clone().add(1, 'day').calendar(anchor), 'Tomorrow 12:00', 'tomorrow uses child version');
74814 assert.equal(anchor.clone().add(3, 'days').calendar(anchor), 'Next week 12:00', 'next week uses child version');
74815
74816 assert.equal(anchor.clone().subtract(1, 'day').calendar(anchor), 'Yesterday at 12:00', 'yesterday uses parent version');
74817 assert.equal(anchor.clone().subtract(3, 'days').calendar(anchor), 'Last week at 12:00', 'last week uses parent version');
74818 assert.equal(anchor.clone().subtract(7, 'days').calendar(anchor), 'whatever', 'sameElse uses parent version -');
74819 assert.equal(anchor.clone().add(7, 'days').calendar(anchor), 'whatever', 'sameElse uses parent version +');
74820 });
b135bf1a 74821
db71a655
KM
74822 test('missing', function (assert) {
74823 moment.defineLocale('base-cal-2', {
74824 calendar: {
74825 sameDay: '[Today at] HH:mm',
74826 nextDay: '[Tomorrow at] HH:mm',
74827 nextWeek: '[Next week at] HH:mm',
74828 lastDay: '[Yesterday at] HH:mm',
74829 lastWeek: '[Last week at] HH:mm',
74830 sameElse: '[whatever]'
74831 }
74832 });
74833 moment.defineLocale('child-cal-2', {
74834 parentLocale: 'base-cal-2'
74835 });
74836 moment.locale('child-cal-2');
74837 var anchor = moment.utc('2015-05-05T12:00:00', moment.ISO_8601);
74838 assert.equal(anchor.clone().add(3, 'hours').calendar(anchor), 'Today at 15:00', 'today uses parent version');
74839 assert.equal(anchor.clone().add(1, 'day').calendar(anchor), 'Tomorrow at 12:00', 'tomorrow uses parent version');
74840 assert.equal(anchor.clone().add(3, 'days').calendar(anchor), 'Next week at 12:00', 'next week uses parent version');
74841 assert.equal(anchor.clone().subtract(1, 'day').calendar(anchor), 'Yesterday at 12:00', 'yesterday uses parent version');
74842 assert.equal(anchor.clone().subtract(3, 'days').calendar(anchor), 'Last week at 12:00', 'last week uses parent version');
74843 assert.equal(anchor.clone().subtract(7, 'days').calendar(anchor), 'whatever', 'sameElse uses parent version -');
74844 assert.equal(anchor.clone().add(7, 'days').calendar(anchor), 'whatever', 'sameElse uses parent version +');
74845 });
74846
74847 // Test function vs obj both directions
74848
74849 test('long date format', function (assert) {
74850 moment.defineLocale('base-ldf', {
74851 longDateFormat : {
74852 LTS : 'h:mm:ss A',
74853 LT : 'h:mm A',
74854 L : 'MM/DD/YYYY',
74855 LL : 'MMMM D, YYYY',
74856 LLL : 'MMMM D, YYYY h:mm A',
74857 LLLL : 'dddd, MMMM D, YYYY h:mm A'
74858 }
74859 });
74860 moment.defineLocale('child-ldf', {
74861 parentLocale: 'base-ldf',
74862 longDateFormat: {
74863 LLL : '[child] MMMM D, YYYY h:mm A',
74864 LLLL : '[child] dddd, MMMM D, YYYY h:mm A'
74865 }
74866 });
516f5f67 74867
db71a655
KM
74868 moment.locale('child-ldf');
74869 var anchor = moment.utc('2015-09-06T12:34:56', moment.ISO_8601);
74870 assert.equal(anchor.format('LTS'), '12:34:56 PM', 'LTS uses base');
74871 assert.equal(anchor.format('LT'), '12:34 PM', 'LT uses base');
74872 assert.equal(anchor.format('L'), '09/06/2015', 'L uses base');
74873 assert.equal(anchor.format('l'), '9/6/2015', 'l uses base');
74874 assert.equal(anchor.format('LL'), 'September 6, 2015', 'LL uses base');
74875 assert.equal(anchor.format('ll'), 'Sep 6, 2015', 'll uses base');
74876 assert.equal(anchor.format('LLL'), 'child September 6, 2015 12:34 PM', 'LLL uses child');
74877 assert.equal(anchor.format('lll'), 'child Sep 6, 2015 12:34 PM', 'lll uses child');
74878 assert.equal(anchor.format('LLLL'), 'child Sunday, September 6, 2015 12:34 PM', 'LLLL uses child');
74879 assert.equal(anchor.format('llll'), 'child Sun, Sep 6, 2015 12:34 PM', 'llll uses child');
74880 });
74881
74882 test('ordinal', function (assert) {
74883 moment.defineLocale('base-ordinal-1', {
74884 ordinal : '%dx'
74885 });
74886 moment.defineLocale('child-ordinal-1', {
74887 parentLocale: 'base-ordinal-1',
74888 ordinal : '%dy'
74889 });
516f5f67 74890
db71a655 74891 assert.equal(moment.utc('2015-02-03', moment.ISO_8601).format('Do'), '3y', 'ordinal uses child string');
c74a101d 74892
db71a655
KM
74893 moment.defineLocale('base-ordinal-2', {
74894 ordinal : '%dx'
74895 });
74896 moment.defineLocale('child-ordinal-2', {
74897 parentLocale: 'base-ordinal-2',
74898 ordinal : function (num) {
74899 return num + 'y';
516f5f67 74900 }
db71a655 74901 });
d6651c21 74902
db71a655 74903 assert.equal(moment.utc('2015-02-03', moment.ISO_8601).format('Do'), '3y', 'ordinal uses child function');
d6651c21 74904
db71a655
KM
74905 moment.defineLocale('base-ordinal-3', {
74906 ordinal : function (num) {
74907 return num + 'x';
74908 }
74909 });
74910 moment.defineLocale('child-ordinal-3', {
74911 parentLocale: 'base-ordinal-3',
74912 ordinal : '%dy'
74913 });
d6651c21 74914
db71a655
KM
74915 assert.equal(moment.utc('2015-02-03', moment.ISO_8601).format('Do'), '3y', 'ordinal uses child string (overwrite parent function)');
74916 });
f2af24d5 74917
db71a655
KM
74918 test('ordinal parse', function (assert) {
74919 moment.defineLocale('base-ordinal-parse-1', {
74920 dayOfMonthOrdinalParse : /\d{1,2}x/
74921 });
74922 moment.defineLocale('child-ordinal-parse-1', {
74923 parentLocale: 'base-ordinal-parse-1',
74924 dayOfMonthOrdinalParse : /\d{1,2}y/
74925 });
d6651c21 74926
db71a655 74927 assert.ok(moment.utc('2015-01-1y', 'YYYY-MM-Do', true).isValid(), 'ordinal parse uses child');
9483e2a4 74928
db71a655
KM
74929 moment.defineLocale('base-ordinal-parse-2', {
74930 dayOfMonthOrdinalParse : /\d{1,2}x/
74931 });
74932 moment.defineLocale('child-ordinal-parse-2', {
74933 parentLocale: 'base-ordinal-parse-2',
74934 dayOfMonthOrdinalParse : /\d{1,2}/
74935 });
73f3c911 74936
db71a655
KM
74937 assert.ok(moment.utc('2015-01-1', 'YYYY-MM-Do', true).isValid(), 'ordinal parse uses child (default)');
74938 });
73f3c911 74939
db71a655
KM
74940 test('months', function (assert) {
74941 moment.defineLocale('base-months', {
74942 months : 'One_Two_Three_Four_Five_Six_Seven_Eight_Nine_Ten_Eleven_Twelve'.split('_')
73f3c911 74943 });
db71a655
KM
74944 moment.defineLocale('child-months', {
74945 parentLocale: 'base-months',
74946 months : 'First_Second_Third_Fourth_Fifth_Sixth_Seventh_Eighth_Ninth_Tenth_Eleventh_Twelveth '.split('_')
74947 });
74948 assert.ok(moment.utc('2015-01-01', 'YYYY-MM-DD').format('MMMM'), 'First', 'months uses child');
74949 });
73f3c911 74950
db71a655
KM
74951 test('define child locale before parent', function (assert) {
74952 moment.defineLocale('months-x', null);
74953 moment.defineLocale('base-months-x', null);
b135bf1a 74954
db71a655
KM
74955 moment.defineLocale('months-x', {
74956 parentLocale: 'base-months-x',
74957 months : 'First_Second_Third_Fourth_Fifth_Sixth_Seventh_Eighth_Ninth_Tenth_Eleventh_Twelveth '.split('_')
74958 });
74959 assert.equal(moment.locale(), 'en', 'failed to set a locale requiring missing parent');
516f5f67 74960
db71a655 74961 assert.equal(moment('00:00:00 01/January/2017', 'HH:mm:ss DD/MMM/YYYY', 'months-x').locale(), 'en', 'creating moment using child with undefined parent defaults to global');
516f5f67 74962
db71a655
KM
74963 moment.defineLocale('base-months-x', {
74964 months : 'One_Two_Three_Four_Five_Six_Seven_Eight_Nine_Ten_Eleven_Twelve'.split('_')
74965 });
74966 assert.equal(moment.locale(), 'base-months-x', 'defineLocale should also set the locale (regardless of child locales)');
c74a101d 74967
db71a655 74968 assert.equal(moment().locale('months-x').month(0).format('MMMM'), 'First', 'loading child before parent locale works');
73f3c911 74969 });
516f5f67 74970
db71a655
KM
74971 test('lazy load parentLocale', function (assert) {
74972 moment.defineLocale('de_test', {
74973 parentLocale: 'de',
74974 monthsShort: ['M1', 'M2', 'M3', 'M4', 'M5', 'M6', 'M7', 'M8', 'M9', 'M10', 'M11', 'M12']
74975 });
74976 assert.equal(moment.locale(), 'de_test', 'failed to lazy load parentLocale');
74977 });
73f3c911
IC
74978
74979})));
516f5f67 74980
516f5f67 74981
c74a101d
IC
74982;(function (global, factory) {
74983 typeof exports === 'object' && typeof module !== 'undefined'
74984 && typeof require === 'function' ? factory(require('../../moment')) :
74985 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
74986 factory(global.moment)
73f3c911 74987}(this, (function (moment) { 'use strict';
c74a101d 74988
db71a655
KM
74989 function each(array, callback) {
74990 var i;
74991 for (i = 0; i < array.length; i++) {
74992 callback(array[i], i, array);
74993 }
b135bf1a
IC
74994 }
74995
db71a655
KM
74996 function setupDeprecationHandler(test, moment$$1, scope) {
74997 test._expectedDeprecations = null;
74998 test._observedDeprecations = null;
74999 test._oldSupress = moment$$1.suppressDeprecationWarnings;
75000 moment$$1.suppressDeprecationWarnings = true;
75001 test.expectedDeprecations = function () {
75002 test._expectedDeprecations = arguments;
75003 test._observedDeprecations = [];
75004 };
75005 moment$$1.deprecationHandler = function (name, msg) {
75006 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
75007 if (deprecationId === -1) {
75008 throw new Error('Unexpected deprecation thrown name=' +
75009 name + ' msg=' + msg);
75010 }
75011 test._observedDeprecations[deprecationId] = 1;
75012 };
75013 }
73f3c911 75014
db71a655
KM
75015 function teardownDeprecationHandler(test, moment$$1, scope) {
75016 moment$$1.suppressDeprecationWarnings = test._oldSupress;
73f3c911 75017
db71a655
KM
75018 if (test._expectedDeprecations != null) {
75019 var missedDeprecations = [];
75020 each(test._expectedDeprecations, function (deprecationPattern, id) {
75021 if (test._observedDeprecations[id] !== 1) {
75022 missedDeprecations.push(deprecationPattern);
75023 }
75024 });
75025 if (missedDeprecations.length !== 0) {
75026 throw new Error('Expected deprecation warnings did not happen: ' +
75027 missedDeprecations.join(' '));
d6651c21
IC
75028 }
75029 }
73f3c911 75030 }
73f3c911 75031
db71a655
KM
75032 function matchedDeprecation(name, msg, deprecations) {
75033 if (deprecations == null) {
75034 return -1;
73f3c911 75035 }
db71a655
KM
75036 for (var i = 0; i < deprecations.length; ++i) {
75037 if (name != null && name === deprecations[i]) {
75038 return i;
75039 }
75040 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
75041 return i;
75042 }
73f3c911 75043 }
db71a655
KM
75044 return -1;
75045 }
75046
75047 /*global QUnit:false*/
75048
75049 var test = QUnit.test;
75050
db71a655
KM
75051 function module$1 (name, lifecycle) {
75052 QUnit.module(name, {
c58511b9 75053 beforeEach : function () {
db71a655
KM
75054 moment.locale('en');
75055 moment.createFromInputFallback = function (config) {
75056 throw new Error('input not handled by moment: ' + config._i);
75057 };
75058 setupDeprecationHandler(test, moment, 'core');
75059 if (lifecycle && lifecycle.setup) {
75060 lifecycle.setup();
75061 }
75062 },
c58511b9 75063 afterEach : function () {
db71a655
KM
75064 teardownDeprecationHandler(test, moment, 'core');
75065 if (lifecycle && lifecycle.teardown) {
75066 lifecycle.teardown();
75067 }
75068 }
75069 });
73f3c911 75070 }
b135bf1a 75071
db71a655
KM
75072 module$1('locale update');
75073
75074 test('calendar', function (assert) {
75075 moment.defineLocale('cal', null);
75076 moment.defineLocale('cal', {
75077 calendar : {
75078 sameDay: '[Today at] HH:mm',
75079 nextDay: '[Tomorrow at] HH:mm',
75080 nextWeek: '[Next week at] HH:mm',
75081 lastDay: '[Yesterday at] HH:mm',
75082 lastWeek: '[Last week at] HH:mm',
75083 sameElse: '[whatever]'
75084 }
75085 });
75086 moment.updateLocale('cal', {
75087 calendar: {
75088 sameDay: '[Today] HH:mm',
75089 nextDay: '[Tomorrow] HH:mm',
75090 nextWeek: '[Next week] HH:mm'
75091 }
75092 });
75093
75094 moment.locale('cal');
75095 var anchor = moment.utc('2015-05-05T12:00:00', moment.ISO_8601);
75096 assert.equal(anchor.clone().add(3, 'hours').calendar(anchor), 'Today 15:00', 'today uses child version');
75097 assert.equal(anchor.clone().add(1, 'day').calendar(anchor), 'Tomorrow 12:00', 'tomorrow uses child version');
75098 assert.equal(anchor.clone().add(3, 'days').calendar(anchor), 'Next week 12:00', 'next week uses child version');
75099
75100 assert.equal(anchor.clone().subtract(1, 'day').calendar(anchor), 'Yesterday at 12:00', 'yesterday uses parent version');
75101 assert.equal(anchor.clone().subtract(3, 'days').calendar(anchor), 'Last week at 12:00', 'last week uses parent version');
75102 assert.equal(anchor.clone().subtract(7, 'days').calendar(anchor), 'whatever', 'sameElse uses parent version -');
75103 assert.equal(anchor.clone().add(7, 'days').calendar(anchor), 'whatever', 'sameElse uses parent version +');
75104 });
75105
75106 test('missing', function (assert) {
75107 moment.defineLocale('cal-2', null);
75108 moment.defineLocale('cal-2', {
75109 calendar: {
75110 sameDay: '[Today at] HH:mm',
75111 nextDay: '[Tomorrow at] HH:mm',
75112 nextWeek: '[Next week at] HH:mm',
75113 lastDay: '[Yesterday at] HH:mm',
75114 lastWeek: '[Last week at] HH:mm',
75115 sameElse: '[whatever]'
75116 }
75117 });
75118 moment.updateLocale('cal-2', {
75119 });
75120 moment.locale('cal-2');
75121 var anchor = moment.utc('2015-05-05T12:00:00', moment.ISO_8601);
75122 assert.equal(anchor.clone().add(3, 'hours').calendar(anchor), 'Today at 15:00', 'today uses parent version');
75123 assert.equal(anchor.clone().add(1, 'day').calendar(anchor), 'Tomorrow at 12:00', 'tomorrow uses parent version');
75124 assert.equal(anchor.clone().add(3, 'days').calendar(anchor), 'Next week at 12:00', 'next week uses parent version');
75125 assert.equal(anchor.clone().subtract(1, 'day').calendar(anchor), 'Yesterday at 12:00', 'yesterday uses parent version');
75126 assert.equal(anchor.clone().subtract(3, 'days').calendar(anchor), 'Last week at 12:00', 'last week uses parent version');
75127 assert.equal(anchor.clone().subtract(7, 'days').calendar(anchor), 'whatever', 'sameElse uses parent version -');
75128 assert.equal(anchor.clone().add(7, 'days').calendar(anchor), 'whatever', 'sameElse uses parent version +');
75129 });
75130
75131 // Test function vs obj both directions
75132
75133 test('long date format', function (assert) {
75134 moment.defineLocale('ldf', null);
75135 moment.defineLocale('ldf', {
75136 longDateFormat : {
75137 LTS : 'h:mm:ss A',
75138 LT : 'h:mm A',
75139 L : 'MM/DD/YYYY',
75140 LL : 'MMMM D, YYYY',
75141 LLL : 'MMMM D, YYYY h:mm A',
75142 LLLL : 'dddd, MMMM D, YYYY h:mm A'
75143 }
75144 });
75145 moment.updateLocale('ldf', {
75146 longDateFormat: {
75147 LLL : '[child] MMMM D, YYYY h:mm A',
75148 LLLL : '[child] dddd, MMMM D, YYYY h:mm A'
75149 }
75150 });
c74a101d 75151
db71a655
KM
75152 moment.locale('ldf');
75153 var anchor = moment.utc('2015-09-06T12:34:56', moment.ISO_8601);
75154 assert.equal(anchor.format('LTS'), '12:34:56 PM', 'LTS uses base');
75155 assert.equal(anchor.format('LT'), '12:34 PM', 'LT uses base');
75156 assert.equal(anchor.format('L'), '09/06/2015', 'L uses base');
75157 assert.equal(anchor.format('l'), '9/6/2015', 'l uses base');
75158 assert.equal(anchor.format('LL'), 'September 6, 2015', 'LL uses base');
75159 assert.equal(anchor.format('ll'), 'Sep 6, 2015', 'll uses base');
75160 assert.equal(anchor.format('LLL'), 'child September 6, 2015 12:34 PM', 'LLL uses child');
75161 assert.equal(anchor.format('lll'), 'child Sep 6, 2015 12:34 PM', 'lll uses child');
75162 assert.equal(anchor.format('LLLL'), 'child Sunday, September 6, 2015 12:34 PM', 'LLLL uses child');
75163 assert.equal(anchor.format('llll'), 'child Sun, Sep 6, 2015 12:34 PM', 'llll uses child');
75164 });
75165
75166 test('ordinal', function (assert) {
75167 moment.defineLocale('ordinal-1', null);
75168 moment.defineLocale('ordinal-1', {
75169 ordinal : '%dx'
75170 });
75171 moment.updateLocale('ordinal-1', {
75172 ordinal : '%dy'
75173 });
c74a101d 75174
db71a655 75175 assert.equal(moment.utc('2015-02-03', moment.ISO_8601).format('Do'), '3y', 'ordinal uses child string');
c74a101d 75176
db71a655
KM
75177 moment.defineLocale('ordinal-2', null);
75178 moment.defineLocale('ordinal-2', {
75179 ordinal : '%dx'
75180 });
75181 moment.updateLocale('ordinal-2', {
75182 ordinal : function (num) {
75183 return num + 'y';
c74a101d 75184 }
db71a655 75185 });
c74a101d 75186
db71a655 75187 assert.equal(moment.utc('2015-02-03', moment.ISO_8601).format('Do'), '3y', 'ordinal uses child function');
c74a101d 75188
db71a655
KM
75189 moment.defineLocale('ordinal-3', null);
75190 moment.defineLocale('ordinal-3', {
75191 ordinal : function (num) {
75192 return num + 'x';
73f3c911 75193 }
db71a655
KM
75194 });
75195 moment.updateLocale('ordinal-3', {
75196 ordinal : '%dy'
75197 });
73f3c911 75198
db71a655
KM
75199 assert.equal(moment.utc('2015-02-03', moment.ISO_8601).format('Do'), '3y', 'ordinal uses child string (overwrite parent function)');
75200 });
73f3c911 75201
db71a655
KM
75202 test('ordinal parse', function (assert) {
75203 moment.defineLocale('ordinal-parse-1', null);
75204 moment.defineLocale('ordinal-parse-1', {
75205 dayOfMonthOrdinalParse : /\d{1,2}x/
75206 });
75207 moment.updateLocale('ordinal-parse-1', {
75208 dayOfMonthOrdinalParse : /\d{1,2}y/
75209 });
9483e2a4 75210
db71a655 75211 assert.ok(moment.utc('2015-01-1y', 'YYYY-MM-Do', true).isValid(), 'ordinal parse uses child');
9483e2a4 75212
db71a655
KM
75213 moment.defineLocale('ordinal-parse-2', null);
75214 moment.defineLocale('ordinal-parse-2', {
75215 dayOfMonthOrdinalParse : /\d{1,2}x/
75216 });
75217 moment.updateLocale('ordinal-parse-2', {
75218 dayOfMonthOrdinalParse : /\d{1,2}/
75219 });
9483e2a4 75220
db71a655
KM
75221 assert.ok(moment.utc('2015-01-1', 'YYYY-MM-Do', true).isValid(), 'ordinal parse uses child (default)');
75222 });
75223
75224 test('months', function (assert) {
75225 moment.defineLocale('months', null);
75226 moment.defineLocale('months', {
75227 months : 'One_Two_Three_Four_Five_Six_Seven_Eight_Nine_Ten_Eleven_Twelve'.split('_')
75228 });
75229 moment.updateLocale('months', {
75230 parentLocale: 'base-months',
75231 months : 'First_Second_Third_Fourth_Fifth_Sixth_Seventh_Eighth_Ninth_Tenth_Eleventh_Twelveth '.split('_')
75232 });
75233 assert.ok(moment.utc('2015-01-01', 'YYYY-MM-DD').format('MMMM'), 'First', 'months uses child');
75234 });
9483e2a4 75235
db71a655
KM
75236 test('update existing locale', function (assert) {
75237 moment.updateLocale('de', {
75238 monthsShort: ['JAN', 'FEB', 'MÄR', 'APR', 'MAI', 'JUN', 'JUL', 'AUG', 'SEP', 'OKT', 'NOV', 'DEZ']
75239 });
75240 assert.equal(moment('2017-02-01').format('YYYY MMM MMMM'), '2017 FEB Februar');
75241 moment.updateLocale('de', null);
75242 });
73f3c911
IC
75243
75244})));
c74a101d 75245
c74a101d
IC
75246
75247;(function (global, factory) {
75248 typeof exports === 'object' && typeof module !== 'undefined'
75249 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
75250 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
75251 factory(global.moment)
73f3c911 75252}(this, (function (moment) { 'use strict';
516f5f67 75253
db71a655
KM
75254 function each(array, callback) {
75255 var i;
75256 for (i = 0; i < array.length; i++) {
75257 callback(array[i], i, array);
75258 }
b135bf1a
IC
75259 }
75260
db71a655
KM
75261 function setupDeprecationHandler(test, moment$$1, scope) {
75262 test._expectedDeprecations = null;
75263 test._observedDeprecations = null;
75264 test._oldSupress = moment$$1.suppressDeprecationWarnings;
75265 moment$$1.suppressDeprecationWarnings = true;
75266 test.expectedDeprecations = function () {
75267 test._expectedDeprecations = arguments;
75268 test._observedDeprecations = [];
75269 };
75270 moment$$1.deprecationHandler = function (name, msg) {
75271 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
75272 if (deprecationId === -1) {
75273 throw new Error('Unexpected deprecation thrown name=' +
75274 name + ' msg=' + msg);
75275 }
75276 test._observedDeprecations[deprecationId] = 1;
75277 };
75278 }
73f3c911 75279
db71a655
KM
75280 function teardownDeprecationHandler(test, moment$$1, scope) {
75281 moment$$1.suppressDeprecationWarnings = test._oldSupress;
73f3c911 75282
db71a655
KM
75283 if (test._expectedDeprecations != null) {
75284 var missedDeprecations = [];
75285 each(test._expectedDeprecations, function (deprecationPattern, id) {
75286 if (test._observedDeprecations[id] !== 1) {
75287 missedDeprecations.push(deprecationPattern);
75288 }
75289 });
75290 if (missedDeprecations.length !== 0) {
75291 throw new Error('Expected deprecation warnings did not happen: ' +
75292 missedDeprecations.join(' '));
d6651c21
IC
75293 }
75294 }
73f3c911 75295 }
73f3c911 75296
db71a655
KM
75297 function matchedDeprecation(name, msg, deprecations) {
75298 if (deprecations == null) {
75299 return -1;
73f3c911 75300 }
db71a655
KM
75301 for (var i = 0; i < deprecations.length; ++i) {
75302 if (name != null && name === deprecations[i]) {
75303 return i;
75304 }
75305 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
75306 return i;
75307 }
73f3c911 75308 }
db71a655 75309 return -1;
73f3c911 75310 }
b135bf1a 75311
db71a655 75312 /*global QUnit:false*/
516f5f67 75313
db71a655 75314 var test = QUnit.test;
516f5f67 75315
db71a655
KM
75316 function module$1 (name, lifecycle) {
75317 QUnit.module(name, {
c58511b9 75318 beforeEach : function () {
db71a655
KM
75319 moment.locale('en');
75320 moment.createFromInputFallback = function (config) {
75321 throw new Error('input not handled by moment: ' + config._i);
75322 };
75323 setupDeprecationHandler(test, moment, 'core');
75324 if (lifecycle && lifecycle.setup) {
75325 lifecycle.setup();
75326 }
75327 },
c58511b9 75328 afterEach : function () {
db71a655
KM
75329 teardownDeprecationHandler(test, moment, 'core');
75330 if (lifecycle && lifecycle.teardown) {
75331 lifecycle.teardown();
75332 }
516f5f67 75333 }
db71a655 75334 });
b135bf1a
IC
75335 }
75336
db71a655 75337 module$1('min max');
73f3c911 75338
db71a655
KM
75339 test('min', function (assert) {
75340 var now = moment(),
75341 future = now.clone().add(1, 'month'),
75342 past = now.clone().subtract(1, 'month'),
75343 invalid = moment.invalid();
73f3c911 75344
db71a655
KM
75345 assert.equal(moment.min(now, future, past), past, 'min(now, future, past)');
75346 assert.equal(moment.min(future, now, past), past, 'min(future, now, past)');
75347 assert.equal(moment.min(future, past, now), past, 'min(future, past, now)');
75348 assert.equal(moment.min(past, future, now), past, 'min(past, future, now)');
75349 assert.equal(moment.min(now, past), past, 'min(now, past)');
75350 assert.equal(moment.min(past, now), past, 'min(past, now)');
75351 assert.equal(moment.min(now), now, 'min(now, past)');
73f3c911 75352
db71a655
KM
75353 assert.equal(moment.min([now, future, past]), past, 'min([now, future, past])');
75354 assert.equal(moment.min([now, past]), past, 'min(now, past)');
75355 assert.equal(moment.min([now]), now, 'min(now)');
73f3c911 75356
db71a655
KM
75357 assert.equal(moment.min([now, invalid]), invalid, 'min(now, invalid)');
75358 assert.equal(moment.min([invalid, now]), invalid, 'min(invalid, now)');
75359 });
b135bf1a 75360
db71a655
KM
75361 test('max', function (assert) {
75362 var now = moment(),
75363 future = now.clone().add(1, 'month'),
75364 past = now.clone().subtract(1, 'month'),
75365 invalid = moment.invalid();
516f5f67 75366
db71a655
KM
75367 assert.equal(moment.max(now, future, past), future, 'max(now, future, past)');
75368 assert.equal(moment.max(future, now, past), future, 'max(future, now, past)');
75369 assert.equal(moment.max(future, past, now), future, 'max(future, past, now)');
75370 assert.equal(moment.max(past, future, now), future, 'max(past, future, now)');
75371 assert.equal(moment.max(now, past), now, 'max(now, past)');
75372 assert.equal(moment.max(past, now), now, 'max(past, now)');
75373 assert.equal(moment.max(now), now, 'max(now, past)');
516f5f67 75374
db71a655
KM
75375 assert.equal(moment.max([now, future, past]), future, 'max([now, future, past])');
75376 assert.equal(moment.max([now, past]), now, 'max(now, past)');
75377 assert.equal(moment.max([now]), now, 'max(now)');
c74a101d 75378
db71a655
KM
75379 assert.equal(moment.max([now, invalid]), invalid, 'max(now, invalid)');
75380 assert.equal(moment.max([invalid, now]), invalid, 'max(invalid, now)');
75381 });
73f3c911
IC
75382
75383})));
516f5f67 75384
516f5f67 75385
9483e2a4
IC
75386;(function (global, factory) {
75387 typeof exports === 'object' && typeof module !== 'undefined'
75388 && typeof require === 'function' ? factory(require('../../moment')) :
75389 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
75390 factory(global.moment)
75391}(this, (function (moment) { 'use strict';
75392
db71a655
KM
75393 function each(array, callback) {
75394 var i;
75395 for (i = 0; i < array.length; i++) {
75396 callback(array[i], i, array);
75397 }
9483e2a4 75398 }
516f5f67 75399
db71a655
KM
75400 function setupDeprecationHandler(test, moment$$1, scope) {
75401 test._expectedDeprecations = null;
75402 test._observedDeprecations = null;
75403 test._oldSupress = moment$$1.suppressDeprecationWarnings;
75404 moment$$1.suppressDeprecationWarnings = true;
75405 test.expectedDeprecations = function () {
75406 test._expectedDeprecations = arguments;
75407 test._observedDeprecations = [];
75408 };
75409 moment$$1.deprecationHandler = function (name, msg) {
75410 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
75411 if (deprecationId === -1) {
75412 throw new Error('Unexpected deprecation thrown name=' +
75413 name + ' msg=' + msg);
75414 }
75415 test._observedDeprecations[deprecationId] = 1;
75416 };
75417 }
516f5f67 75418
db71a655
KM
75419 function teardownDeprecationHandler(test, moment$$1, scope) {
75420 moment$$1.suppressDeprecationWarnings = test._oldSupress;
c74a101d 75421
db71a655
KM
75422 if (test._expectedDeprecations != null) {
75423 var missedDeprecations = [];
75424 each(test._expectedDeprecations, function (deprecationPattern, id) {
75425 if (test._observedDeprecations[id] !== 1) {
75426 missedDeprecations.push(deprecationPattern);
75427 }
75428 });
75429 if (missedDeprecations.length !== 0) {
75430 throw new Error('Expected deprecation warnings did not happen: ' +
75431 missedDeprecations.join(' '));
516f5f67 75432 }
73f3c911 75433 }
516f5f67
IC
75434 }
75435
db71a655
KM
75436 function matchedDeprecation(name, msg, deprecations) {
75437 if (deprecations == null) {
75438 return -1;
73f3c911 75439 }
db71a655
KM
75440 for (var i = 0; i < deprecations.length; ++i) {
75441 if (name != null && name === deprecations[i]) {
75442 return i;
75443 }
75444 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
75445 return i;
75446 }
73f3c911 75447 }
db71a655 75448 return -1;
73f3c911 75449 }
516f5f67 75450
db71a655 75451 /*global QUnit:false*/
516f5f67 75452
db71a655 75453 var test = QUnit.test;
516f5f67 75454
db71a655
KM
75455 function module$1 (name, lifecycle) {
75456 QUnit.module(name, {
c58511b9 75457 beforeEach : function () {
db71a655
KM
75458 moment.locale('en');
75459 moment.createFromInputFallback = function (config) {
75460 throw new Error('input not handled by moment: ' + config._i);
75461 };
75462 setupDeprecationHandler(test, moment, 'core');
75463 if (lifecycle && lifecycle.setup) {
75464 lifecycle.setup();
75465 }
75466 },
c58511b9 75467 afterEach : function () {
db71a655
KM
75468 teardownDeprecationHandler(test, moment, 'core');
75469 if (lifecycle && lifecycle.teardown) {
75470 lifecycle.teardown();
75471 }
d6651c21 75472 }
db71a655
KM
75473 });
75474 }
75475
75476 module$1('mutable');
75477
75478 test('manipulation methods', function (assert) {
75479 var m = moment();
75480
75481 assert.equal(m, m.year(2011), 'year() should be mutable');
75482 assert.equal(m, m.month(1), 'month() should be mutable');
75483 assert.equal(m, m.hours(7), 'hours() should be mutable');
75484 assert.equal(m, m.minutes(33), 'minutes() should be mutable');
75485 assert.equal(m, m.seconds(44), 'seconds() should be mutable');
75486 assert.equal(m, m.milliseconds(55), 'milliseconds() should be mutable');
75487 assert.equal(m, m.day(2), 'day() should be mutable');
75488 assert.equal(m, m.startOf('week'), 'startOf() should be mutable');
75489 assert.equal(m, m.add(1, 'days'), 'add() should be mutable');
75490 assert.equal(m, m.subtract(2, 'years'), 'subtract() should be mutable');
75491 assert.equal(m, m.local(), 'local() should be mutable');
75492 assert.equal(m, m.utc(), 'utc() should be mutable');
75493 });
75494
75495 test('non mutable methods', function (assert) {
75496 var m = moment();
75497 assert.notEqual(m, m.clone(), 'clone() should not be mutable');
75498 });
73f3c911
IC
75499
75500})));
c587bf00 75501
d6651c21
IC
75502
75503;(function (global, factory) {
75504 typeof exports === 'object' && typeof module !== 'undefined'
75505 && typeof require === 'function' ? factory(require('../../moment')) :
75506 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
75507 factory(global.moment)
73f3c911 75508}(this, (function (moment) { 'use strict';
d6651c21 75509
db71a655
KM
75510 function each(array, callback) {
75511 var i;
75512 for (i = 0; i < array.length; i++) {
75513 callback(array[i], i, array);
75514 }
d6651c21
IC
75515 }
75516
db71a655
KM
75517 function setupDeprecationHandler(test, moment$$1, scope) {
75518 test._expectedDeprecations = null;
75519 test._observedDeprecations = null;
75520 test._oldSupress = moment$$1.suppressDeprecationWarnings;
75521 moment$$1.suppressDeprecationWarnings = true;
75522 test.expectedDeprecations = function () {
75523 test._expectedDeprecations = arguments;
75524 test._observedDeprecations = [];
75525 };
75526 moment$$1.deprecationHandler = function (name, msg) {
75527 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
75528 if (deprecationId === -1) {
75529 throw new Error('Unexpected deprecation thrown name=' +
75530 name + ' msg=' + msg);
75531 }
75532 test._observedDeprecations[deprecationId] = 1;
75533 };
75534 }
516f5f67 75535
db71a655
KM
75536 function teardownDeprecationHandler(test, moment$$1, scope) {
75537 moment$$1.suppressDeprecationWarnings = test._oldSupress;
516f5f67 75538
db71a655
KM
75539 if (test._expectedDeprecations != null) {
75540 var missedDeprecations = [];
75541 each(test._expectedDeprecations, function (deprecationPattern, id) {
75542 if (test._observedDeprecations[id] !== 1) {
75543 missedDeprecations.push(deprecationPattern);
75544 }
75545 });
75546 if (missedDeprecations.length !== 0) {
75547 throw new Error('Expected deprecation warnings did not happen: ' +
75548 missedDeprecations.join(' '));
73f3c911 75549 }
73f3c911
IC
75550 }
75551 }
516f5f67 75552
db71a655
KM
75553 function matchedDeprecation(name, msg, deprecations) {
75554 if (deprecations == null) {
75555 return -1;
73f3c911 75556 }
db71a655
KM
75557 for (var i = 0; i < deprecations.length; ++i) {
75558 if (name != null && name === deprecations[i]) {
75559 return i;
75560 }
75561 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
75562 return i;
75563 }
73f3c911 75564 }
db71a655 75565 return -1;
73f3c911 75566 }
516f5f67 75567
db71a655 75568 /*global QUnit:false*/
516f5f67 75569
db71a655 75570 var test = QUnit.test;
516f5f67 75571
db71a655
KM
75572 function module$1 (name, lifecycle) {
75573 QUnit.module(name, {
c58511b9 75574 beforeEach : function () {
db71a655
KM
75575 moment.locale('en');
75576 moment.createFromInputFallback = function (config) {
75577 throw new Error('input not handled by moment: ' + config._i);
75578 };
75579 setupDeprecationHandler(test, moment, 'core');
75580 if (lifecycle && lifecycle.setup) {
75581 lifecycle.setup();
75582 }
75583 },
c58511b9 75584 afterEach : function () {
db71a655
KM
75585 teardownDeprecationHandler(test, moment, 'core');
75586 if (lifecycle && lifecycle.teardown) {
75587 lifecycle.teardown();
75588 }
73f3c911 75589 }
db71a655 75590 });
73f3c911 75591 }
9483e2a4 75592
db71a655 75593 module$1('normalize units');
516f5f67 75594
db71a655
KM
75595 test('normalize units', function (assert) {
75596 var fullKeys = ['year', 'quarter', 'month', 'isoWeek', 'week', 'day', 'hour', 'minute', 'second', 'millisecond', 'date', 'dayOfYear', 'weekday', 'isoWeekday', 'weekYear', 'isoWeekYear'],
75597 aliases = ['y', 'Q', 'M', 'W', 'w', 'd', 'h', 'm', 's', 'ms', 'D', 'DDD', 'e', 'E', 'gg', 'GG'],
75598 length = fullKeys.length,
75599 fullKey,
75600 fullKeyCaps,
75601 fullKeyPlural,
75602 fullKeyCapsPlural,
75603 fullKeyLower,
75604 alias,
75605 index;
516f5f67 75606
db71a655
KM
75607 for (index = 0; index < length; index += 1) {
75608 fullKey = fullKeys[index];
75609 fullKeyCaps = fullKey.toUpperCase();
75610 fullKeyLower = fullKey.toLowerCase();
75611 fullKeyPlural = fullKey + 's';
75612 fullKeyCapsPlural = fullKeyCaps + 's';
75613 alias = aliases[index];
75614 assert.equal(moment.normalizeUnits(fullKey), fullKey, 'Testing full key ' + fullKey);
75615 assert.equal(moment.normalizeUnits(fullKeyCaps), fullKey, 'Testing full key capitalised ' + fullKey);
75616 assert.equal(moment.normalizeUnits(fullKeyPlural), fullKey, 'Testing full key plural ' + fullKey);
75617 assert.equal(moment.normalizeUnits(fullKeyCapsPlural), fullKey, 'Testing full key capitalised and plural ' + fullKey);
75618 assert.equal(moment.normalizeUnits(alias), fullKey, 'Testing alias ' + fullKey);
75619 }
75620 });
73f3c911
IC
75621
75622})));
516f5f67 75623
516f5f67 75624
73f3c911
IC
75625;(function (global, factory) {
75626 typeof exports === 'object' && typeof module !== 'undefined'
75627 && typeof require === 'function' ? factory(require('../../moment')) :
75628 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
75629 factory(global.moment)
75630}(this, (function (moment) { 'use strict';
b135bf1a 75631
db71a655
KM
75632 function each(array, callback) {
75633 var i;
75634 for (i = 0; i < array.length; i++) {
75635 callback(array[i], i, array);
75636 }
73f3c911 75637 }
b135bf1a 75638
db71a655
KM
75639 function setupDeprecationHandler(test, moment$$1, scope) {
75640 test._expectedDeprecations = null;
75641 test._observedDeprecations = null;
75642 test._oldSupress = moment$$1.suppressDeprecationWarnings;
75643 moment$$1.suppressDeprecationWarnings = true;
75644 test.expectedDeprecations = function () {
75645 test._expectedDeprecations = arguments;
75646 test._observedDeprecations = [];
75647 };
75648 moment$$1.deprecationHandler = function (name, msg) {
75649 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
75650 if (deprecationId === -1) {
75651 throw new Error('Unexpected deprecation thrown name=' +
75652 name + ' msg=' + msg);
75653 }
75654 test._observedDeprecations[deprecationId] = 1;
75655 };
75656 }
f2af24d5 75657
db71a655
KM
75658 function teardownDeprecationHandler(test, moment$$1, scope) {
75659 moment$$1.suppressDeprecationWarnings = test._oldSupress;
f2af24d5 75660
db71a655
KM
75661 if (test._expectedDeprecations != null) {
75662 var missedDeprecations = [];
75663 each(test._expectedDeprecations, function (deprecationPattern, id) {
75664 if (test._observedDeprecations[id] !== 1) {
75665 missedDeprecations.push(deprecationPattern);
75666 }
75667 });
75668 if (missedDeprecations.length !== 0) {
75669 throw new Error('Expected deprecation warnings did not happen: ' +
75670 missedDeprecations.join(' '));
f2af24d5 75671 }
f2af24d5
IC
75672 }
75673 }
f2af24d5 75674
db71a655
KM
75675 function matchedDeprecation(name, msg, deprecations) {
75676 if (deprecations == null) {
75677 return -1;
f2af24d5 75678 }
db71a655
KM
75679 for (var i = 0; i < deprecations.length; ++i) {
75680 if (name != null && name === deprecations[i]) {
75681 return i;
75682 }
75683 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
75684 return i;
75685 }
f2af24d5 75686 }
db71a655 75687 return -1;
f2af24d5 75688 }
f2af24d5 75689
db71a655 75690 /*global QUnit:false*/
f2af24d5 75691
db71a655 75692 var test = QUnit.test;
f2af24d5 75693
db71a655
KM
75694 function module$1 (name, lifecycle) {
75695 QUnit.module(name, {
c58511b9 75696 beforeEach : function () {
db71a655
KM
75697 moment.locale('en');
75698 moment.createFromInputFallback = function (config) {
75699 throw new Error('input not handled by moment: ' + config._i);
75700 };
75701 setupDeprecationHandler(test, moment, 'core');
75702 if (lifecycle && lifecycle.setup) {
75703 lifecycle.setup();
75704 }
75705 },
c58511b9 75706 afterEach : function () {
db71a655
KM
75707 teardownDeprecationHandler(test, moment, 'core');
75708 if (lifecycle && lifecycle.teardown) {
75709 lifecycle.teardown();
75710 }
f2af24d5 75711 }
db71a655
KM
75712 });
75713 }
75714
75715 module$1('now');
75716
75717 test('now', function (assert) {
75718 var startOfTest = new Date().valueOf(),
75719 momentNowTime = moment.now(),
75720 afterMomentCreationTime = new Date().valueOf();
75721
75722 assert.ok(startOfTest <= momentNowTime, 'moment now() time should be now, not in the past');
75723 assert.ok(momentNowTime <= afterMomentCreationTime, 'moment now() time should be now, not in the future');
75724 });
75725
75726 test('now - Date mocked', function (assert) {
75727 // We need to test mocking the global Date object, so disable 'Read Only' jshint check
75728 /* jshint -W020 */
75729 var RealDate = Date,
75730 customTimeMs = moment('2015-01-01T01:30:00.000Z').valueOf();
75731
75732 function MockDate() {
75733 return new RealDate(customTimeMs);
75734 }
75735
75736 MockDate.now = function () {
75737 return new MockDate().valueOf();
75738 };
75739
75740 MockDate.prototype = RealDate.prototype;
75741
75742 Date = MockDate;
75743
75744 try {
75745 assert.equal(moment().valueOf(), customTimeMs, 'moment now() time should use the global Date object');
75746 } finally {
75747 Date = RealDate;
f2af24d5
IC
75748 }
75749 });
f2af24d5 75750
db71a655
KM
75751 test('now - custom value', function (assert) {
75752 var customTimeStr = '2015-01-01T01:30:00.000Z',
75753 customTime = moment(customTimeStr, moment.ISO_8601).valueOf(),
75754 oldFn = moment.now;
f2af24d5 75755
db71a655
KM
75756 moment.now = function () {
75757 return customTime;
75758 };
75759
75760 try {
75761 assert.equal(moment().toISOString(), customTimeStr, 'moment() constructor should use the function defined by moment.now, but it did not');
75762 assert.equal(moment.utc().toISOString(), customTimeStr, 'moment() constructor should use the function defined by moment.now, but it did not');
75763 } finally {
75764 moment.now = oldFn;
75765 }
75766 });
75767
75768 test('empty object, empty array', function (assert) {
75769 function assertIsNow(gen, msg) {
75770 var before = +(new Date()),
75771 mid = gen(),
75772 after = +(new Date());
75773 assert.ok(before <= +mid && +mid <= after, 'should be now : ' + msg);
75774 }
75775 assertIsNow(function () {
75776 return moment();
75777 }, 'moment()');
75778 assertIsNow(function () {
75779 return moment([]);
75780 }, 'moment([])');
75781 assertIsNow(function () {
75782 return moment({});
75783 }, 'moment({})');
75784 assertIsNow(function () {
75785 return moment.utc();
75786 }, 'moment.utc()');
75787 assertIsNow(function () {
75788 return moment.utc([]);
75789 }, 'moment.utc([])');
75790 assertIsNow(function () {
75791 return moment.utc({});
75792 }, 'moment.utc({})');
75793 });
f2af24d5
IC
75794
75795})));
75796
75797
75798;(function (global, factory) {
75799 typeof exports === 'object' && typeof module !== 'undefined'
75800 && typeof require === 'function' ? factory(require('../../moment')) :
75801 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
75802 factory(global.moment)
75803}(this, (function (moment) { 'use strict';
75804
db71a655
KM
75805 function each(array, callback) {
75806 var i;
75807 for (i = 0; i < array.length; i++) {
75808 callback(array[i], i, array);
75809 }
f2af24d5 75810 }
f2af24d5 75811
db71a655
KM
75812 function setupDeprecationHandler(test, moment$$1, scope) {
75813 test._expectedDeprecations = null;
75814 test._observedDeprecations = null;
75815 test._oldSupress = moment$$1.suppressDeprecationWarnings;
75816 moment$$1.suppressDeprecationWarnings = true;
75817 test.expectedDeprecations = function () {
75818 test._expectedDeprecations = arguments;
75819 test._observedDeprecations = [];
75820 };
75821 moment$$1.deprecationHandler = function (name, msg) {
75822 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
75823 if (deprecationId === -1) {
75824 throw new Error('Unexpected deprecation thrown name=' +
75825 name + ' msg=' + msg);
75826 }
75827 test._observedDeprecations[deprecationId] = 1;
75828 };
75829 }
b135bf1a 75830
db71a655
KM
75831 function teardownDeprecationHandler(test, moment$$1, scope) {
75832 moment$$1.suppressDeprecationWarnings = test._oldSupress;
b135bf1a 75833
db71a655
KM
75834 if (test._expectedDeprecations != null) {
75835 var missedDeprecations = [];
75836 each(test._expectedDeprecations, function (deprecationPattern, id) {
75837 if (test._observedDeprecations[id] !== 1) {
75838 missedDeprecations.push(deprecationPattern);
75839 }
75840 });
75841 if (missedDeprecations.length !== 0) {
75842 throw new Error('Expected deprecation warnings did not happen: ' +
75843 missedDeprecations.join(' '));
b135bf1a 75844 }
73f3c911
IC
75845 }
75846 }
b135bf1a 75847
db71a655
KM
75848 function matchedDeprecation(name, msg, deprecations) {
75849 if (deprecations == null) {
75850 return -1;
73f3c911 75851 }
db71a655
KM
75852 for (var i = 0; i < deprecations.length; ++i) {
75853 if (name != null && name === deprecations[i]) {
75854 return i;
75855 }
75856 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
75857 return i;
75858 }
73f3c911 75859 }
db71a655 75860 return -1;
73f3c911 75861 }
b135bf1a 75862
db71a655 75863 /*global QUnit:false*/
73f3c911 75864
db71a655 75865 var test = QUnit.test;
73f3c911 75866
db71a655
KM
75867 function module$1 (name, lifecycle) {
75868 QUnit.module(name, {
c58511b9 75869 beforeEach : function () {
db71a655
KM
75870 moment.locale('en');
75871 moment.createFromInputFallback = function (config) {
75872 throw new Error('input not handled by moment: ' + config._i);
75873 };
75874 setupDeprecationHandler(test, moment, 'core');
75875 if (lifecycle && lifecycle.setup) {
75876 lifecycle.setup();
75877 }
75878 },
c58511b9 75879 afterEach : function () {
db71a655
KM
75880 teardownDeprecationHandler(test, moment, 'core');
75881 if (lifecycle && lifecycle.teardown) {
75882 lifecycle.teardown();
75883 }
75884 }
75885 });
75886 }
73f3c911 75887
db71a655
KM
75888 module$1('parsing flags');
75889
75890 function flags () {
75891 return moment.apply(null, arguments).parsingFlags();
75892 }
75893
75894 test('overflow with array', function (assert) {
75895 //months
75896 assert.equal(flags([2010, 0]).overflow, -1, 'month 0 valid');
75897 assert.equal(flags([2010, 1]).overflow, -1, 'month 1 valid');
75898 assert.equal(flags([2010, -1]).overflow, 1, 'month -1 invalid');
75899 assert.equal(flags([2100, 12]).overflow, 1, 'month 12 invalid');
75900
75901 //days
75902 assert.equal(flags([2010, 1, 16]).overflow, -1, 'date valid');
75903 assert.equal(flags([2010, 1, -1]).overflow, 2, 'date -1 invalid');
75904 assert.equal(flags([2010, 1, 0]).overflow, 2, 'date 0 invalid');
75905 assert.equal(flags([2010, 1, 32]).overflow, 2, 'date 32 invalid');
75906 assert.equal(flags([2012, 1, 29]).overflow, -1, 'date leap year valid');
75907 assert.equal(flags([2010, 1, 29]).overflow, 2, 'date leap year invalid');
75908
75909 //hours
75910 assert.equal(flags([2010, 1, 1, 8]).overflow, -1, 'hour valid');
75911 assert.equal(flags([2010, 1, 1, 0]).overflow, -1, 'hour 0 valid');
75912 assert.equal(flags([2010, 1, 1, -1]).overflow, 3, 'hour -1 invalid');
75913 assert.equal(flags([2010, 1, 1, 25]).overflow, 3, 'hour 25 invalid');
75914 assert.equal(flags([2010, 1, 1, 24, 1]).overflow, 3, 'hour 24:01 invalid');
75915
75916 //minutes
75917 assert.equal(flags([2010, 1, 1, 8, 15]).overflow, -1, 'minute valid');
75918 assert.equal(flags([2010, 1, 1, 8, 0]).overflow, -1, 'minute 0 valid');
75919 assert.equal(flags([2010, 1, 1, 8, -1]).overflow, 4, 'minute -1 invalid');
75920 assert.equal(flags([2010, 1, 1, 8, 60]).overflow, 4, 'minute 60 invalid');
75921
75922 //seconds
75923 assert.equal(flags([2010, 1, 1, 8, 15, 12]).overflow, -1, 'second valid');
75924 assert.equal(flags([2010, 1, 1, 8, 15, 0]).overflow, -1, 'second 0 valid');
75925 assert.equal(flags([2010, 1, 1, 8, 15, -1]).overflow, 5, 'second -1 invalid');
75926 assert.equal(flags([2010, 1, 1, 8, 15, 60]).overflow, 5, 'second 60 invalid');
75927
75928 //milliseconds
75929 assert.equal(flags([2010, 1, 1, 8, 15, 12, 345]).overflow, -1, 'millisecond valid');
75930 assert.equal(flags([2010, 1, 1, 8, 15, 12, 0]).overflow, -1, 'millisecond 0 valid');
75931 assert.equal(flags([2010, 1, 1, 8, 15, 12, -1]).overflow, 6, 'millisecond -1 invalid');
75932 assert.equal(flags([2010, 1, 1, 8, 15, 12, 1000]).overflow, 6, 'millisecond 1000 invalid');
75933
75934 // 24 hrs
75935 assert.equal(flags([2010, 1, 1, 24, 0, 0, 0]).overflow, -1, '24:00:00.000 is fine');
75936 assert.equal(flags([2010, 1, 1, 24, 1, 0, 0]).overflow, 3, '24:01:00.000 is wrong hour');
75937 assert.equal(flags([2010, 1, 1, 24, 0, 1, 0]).overflow, 3, '24:00:01.000 is wrong hour');
75938 assert.equal(flags([2010, 1, 1, 24, 0, 0, 1]).overflow, 3, '24:00:00.001 is wrong hour');
75939 });
75940
75941 test('overflow without format', function (assert) {
75942 //months
75943 assert.equal(flags('2001-01', 'YYYY-MM').overflow, -1, 'month 1 valid');
75944 assert.equal(flags('2001-12', 'YYYY-MM').overflow, -1, 'month 12 valid');
75945 assert.equal(flags('2001-13', 'YYYY-MM').overflow, 1, 'month 13 invalid');
75946
75947 //days
75948 assert.equal(flags('2010-01-16', 'YYYY-MM-DD').overflow, -1, 'date 16 valid');
75949 assert.equal(flags('2010-01-0', 'YYYY-MM-DD').overflow, 2, 'date 0 invalid');
75950 assert.equal(flags('2010-01-32', 'YYYY-MM-DD').overflow, 2, 'date 32 invalid');
75951 assert.equal(flags('2012-02-29', 'YYYY-MM-DD').overflow, -1, 'date leap year valid');
75952 assert.equal(flags('2010-02-29', 'YYYY-MM-DD').overflow, 2, 'date leap year invalid');
75953
75954 //days of the year
75955 assert.equal(flags('2010 300', 'YYYY DDDD').overflow, -1, 'day 300 of year valid');
75956 assert.equal(flags('2010 365', 'YYYY DDDD').overflow, -1, 'day 365 of year valid');
75957 assert.equal(flags('2010 366', 'YYYY DDDD').overflow, 2, 'day 366 of year invalid');
75958 assert.equal(flags('2012 366', 'YYYY DDDD').overflow, -1, 'day 366 of leap year valid');
75959 assert.equal(flags('2012 367', 'YYYY DDDD').overflow, 2, 'day 367 of leap year invalid');
75960
75961 //hours
75962 assert.equal(flags('08', 'HH').overflow, -1, 'hour valid');
75963 assert.equal(flags('00', 'HH').overflow, -1, 'hour 0 valid');
75964 assert.equal(flags('25', 'HH').overflow, 3, 'hour 25 invalid');
75965 assert.equal(flags('24:01', 'HH:mm').overflow, 3, 'hour 24:01 invalid');
75966
75967 //minutes
75968 assert.equal(flags('08:15', 'HH:mm').overflow, -1, 'minute valid');
75969 assert.equal(flags('08:00', 'HH:mm').overflow, -1, 'minute 0 valid');
75970 assert.equal(flags('08:60', 'HH:mm').overflow, 4, 'minute 60 invalid');
75971
75972 //seconds
75973 assert.equal(flags('08:15:12', 'HH:mm:ss').overflow, -1, 'second valid');
75974 assert.equal(flags('08:15:00', 'HH:mm:ss').overflow, -1, 'second 0 valid');
75975 assert.equal(flags('08:15:60', 'HH:mm:ss').overflow, 5, 'second 60 invalid');
75976
75977 //milliseconds
75978 assert.equal(flags('08:15:12:345', 'HH:mm:ss:SSSS').overflow, -1, 'millisecond valid');
75979 assert.equal(flags('08:15:12:000', 'HH:mm:ss:SSSS').overflow, -1, 'millisecond 0 valid');
75980
75981 //this is OK because we don't match the last digit, so it's 100 ms
75982 assert.equal(flags('08:15:12:1000', 'HH:mm:ss:SSSS').overflow, -1, 'millisecond 1000 actually valid');
75983 });
75984
75985 test('extra tokens', function (assert) {
75986 assert.deepEqual(flags('1982-05-25', 'YYYY-MM-DD').unusedTokens, [], 'nothing extra');
75987 assert.deepEqual(flags('1982-05', 'YYYY-MM-DD').unusedTokens, ['DD'], 'extra formatting token');
75988 assert.deepEqual(flags('1982', 'YYYY-MM-DD').unusedTokens, ['MM', 'DD'], 'multiple extra formatting tokens');
75989 assert.deepEqual(flags('1982-05', 'YYYY-MM-').unusedTokens, [], 'extra non-formatting token');
75990 assert.deepEqual(flags('1982-05-', 'YYYY-MM-DD').unusedTokens, ['DD'], 'non-extra non-formatting token');
75991 assert.deepEqual(flags('1982 05 1982', 'YYYY-MM-DD').unusedTokens, [], 'different non-formatting token');
75992 });
75993
75994 test('extra tokens strict', function (assert) {
75995 assert.deepEqual(flags('1982-05-25', 'YYYY-MM-DD', true).unusedTokens, [], 'nothing extra');
75996 assert.deepEqual(flags('1982-05', 'YYYY-MM-DD', true).unusedTokens, ['-', 'DD'], 'extra formatting token');
75997 assert.deepEqual(flags('1982', 'YYYY-MM-DD', true).unusedTokens, ['-', 'MM', '-', 'DD'], 'multiple extra formatting tokens');
75998 assert.deepEqual(flags('1982-05', 'YYYY-MM-', true).unusedTokens, ['-'], 'extra non-formatting token');
75999 assert.deepEqual(flags('1982-05-', 'YYYY-MM-DD', true).unusedTokens, ['DD'], 'non-extra non-formatting token');
76000 assert.deepEqual(flags('1982 05 1982', 'YYYY-MM-DD', true).unusedTokens, ['-', '-'], 'different non-formatting token');
76001 });
76002
76003 test('unused input', function (assert) {
76004 assert.deepEqual(flags('1982-05-25', 'YYYY-MM-DD').unusedInput, [], 'normal input');
76005 assert.deepEqual(flags('1982-05-25 this is more stuff', 'YYYY-MM-DD').unusedInput, [' this is more stuff'], 'trailing nonsense');
76006 assert.deepEqual(flags('1982-05-25 09:30', 'YYYY-MM-DD').unusedInput, [' 09:30'], ['trailing legit-looking input']);
76007 assert.deepEqual(flags('1982-05-25 some junk', 'YYYY-MM-DD [some junk]').unusedInput, [], 'junk that actually gets matched');
76008 assert.deepEqual(flags('stuff at beginning 1982-05-25', 'YYYY-MM-DD').unusedInput, ['stuff at beginning '], 'leading junk');
76009 assert.deepEqual(flags('junk 1982 more junk 05 yet more junk25', 'YYYY-MM-DD').unusedInput, ['junk ', ' more junk ', ' yet more junk'], 'interstitial junk');
76010 });
76011
76012 test('unused input strict', function (assert) {
76013 assert.deepEqual(flags('1982-05-25', 'YYYY-MM-DD', true).unusedInput, [], 'normal input');
76014 assert.deepEqual(flags('1982-05-25 this is more stuff', 'YYYY-MM-DD', true).unusedInput, [' this is more stuff'], 'trailing nonsense');
76015 assert.deepEqual(flags('1982-05-25 09:30', 'YYYY-MM-DD', true).unusedInput, [' 09:30'], ['trailing legit-looking input']);
76016 assert.deepEqual(flags('1982-05-25 some junk', 'YYYY-MM-DD [some junk]', true).unusedInput, [], 'junk that actually gets matched');
76017 assert.deepEqual(flags('stuff at beginning 1982-05-25', 'YYYY-MM-DD', true).unusedInput, ['stuff at beginning '], 'leading junk');
76018 assert.deepEqual(flags('junk 1982 more junk 05 yet more junk25', 'YYYY-MM-DD', true).unusedInput, ['junk ', ' more junk ', ' yet more junk'], 'interstitial junk');
76019 });
76020
76021 test('chars left over', function (assert) {
76022 assert.equal(flags('1982-05-25', 'YYYY-MM-DD').charsLeftOver, 0, 'normal input');
76023 assert.equal(flags('1982-05-25 this is more stuff', 'YYYY-MM-DD').charsLeftOver, ' this is more stuff'.length, 'trailing nonsense');
76024 assert.equal(flags('1982-05-25 09:30', 'YYYY-MM-DD').charsLeftOver, ' 09:30'.length, 'trailing legit-looking input');
76025 assert.equal(flags('stuff at beginning 1982-05-25', 'YYYY-MM-DD').charsLeftOver, 'stuff at beginning '.length, 'leading junk');
76026 assert.equal(flags('1982 junk 05 more junk25', 'YYYY-MM-DD').charsLeftOver, [' junk ', ' more junk'].join('').length, 'interstitial junk');
76027 assert.equal(flags('stuff at beginning 1982 junk 05 more junk25', 'YYYY-MM-DD').charsLeftOver, ['stuff at beginning ', ' junk ', ' more junk'].join('').length, 'leading and interstitial junk');
76028 });
73f3c911 76029
db71a655
KM
76030 test('empty', function (assert) {
76031 assert.equal(flags('1982-05-25', 'YYYY-MM-DD').empty, false, 'normal input');
76032 assert.equal(flags('nothing here', 'YYYY-MM-DD').empty, true, 'pure garbage');
76033 assert.equal(flags('junk but has the number 2000 in it', 'YYYY-MM-DD').empty, false, 'only mostly garbage');
76034 assert.equal(flags('', 'YYYY-MM-DD').empty, true, 'empty string');
76035 assert.equal(flags('', 'YYYY-MM-DD').empty, true, 'blank string');
73f3c911
IC
76036 });
76037
db71a655
KM
76038 test('null', function (assert) {
76039 assert.equal(flags('1982-05-25', 'YYYY-MM-DD').nullInput, false, 'normal input');
76040 assert.equal(flags(null).nullInput, true, 'just null');
76041 assert.equal(flags(null, 'YYYY-MM-DD').nullInput, true, 'null with format');
76042 });
73f3c911 76043
db71a655
KM
76044 test('invalid month', function (assert) {
76045 assert.equal(flags('1982 May', 'YYYY MMMM').invalidMonth, null, 'normal input');
76046 assert.equal(flags('1982 Laser', 'YYYY MMMM').invalidMonth, 'Laser', 'bad month name');
76047 });
b135bf1a 76048
db71a655
KM
76049 test('empty format array', function (assert) {
76050 assert.equal(flags('1982 May', ['YYYY MMM']).invalidFormat, false, 'empty format array');
76051 assert.equal(flags('1982 May', []).invalidFormat, true, 'empty format array');
76052 });
b135bf1a 76053
db71a655
KM
76054 test('weekday mismatch', function (assert) {
76055 // string with format
76056 assert.equal(flags('Wed 08-10-2017', 'ddd MM-DD-YYYY').weekdayMismatch, true, 'day of week does not match date');
76057 assert.equal(flags('Thu 08-10-2017', 'ddd MM-DD-YYYY').weekdayMismatch, false, 'day of week matches date');
76058 });
516f5f67 76059
73f3c911 76060})));
516f5f67 76061
b135bf1a
IC
76062
76063;(function (global, factory) {
76064 typeof exports === 'object' && typeof module !== 'undefined'
76065 && typeof require === 'function' ? factory(require('../../moment')) :
76066 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
76067 factory(global.moment)
73f3c911 76068}(this, (function (moment) { 'use strict';
b135bf1a 76069
db71a655
KM
76070 function each(array, callback) {
76071 var i;
76072 for (i = 0; i < array.length; i++) {
76073 callback(array[i], i, array);
76074 }
b135bf1a
IC
76075 }
76076
db71a655
KM
76077 function setupDeprecationHandler(test, moment$$1, scope) {
76078 test._expectedDeprecations = null;
76079 test._observedDeprecations = null;
76080 test._oldSupress = moment$$1.suppressDeprecationWarnings;
76081 moment$$1.suppressDeprecationWarnings = true;
76082 test.expectedDeprecations = function () {
76083 test._expectedDeprecations = arguments;
76084 test._observedDeprecations = [];
76085 };
76086 moment$$1.deprecationHandler = function (name, msg) {
76087 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
76088 if (deprecationId === -1) {
76089 throw new Error('Unexpected deprecation thrown name=' +
76090 name + ' msg=' + msg);
76091 }
76092 test._observedDeprecations[deprecationId] = 1;
76093 };
76094 }
b135bf1a 76095
db71a655
KM
76096 function teardownDeprecationHandler(test, moment$$1, scope) {
76097 moment$$1.suppressDeprecationWarnings = test._oldSupress;
b135bf1a 76098
db71a655
KM
76099 if (test._expectedDeprecations != null) {
76100 var missedDeprecations = [];
76101 each(test._expectedDeprecations, function (deprecationPattern, id) {
76102 if (test._observedDeprecations[id] !== 1) {
76103 missedDeprecations.push(deprecationPattern);
76104 }
76105 });
76106 if (missedDeprecations.length !== 0) {
76107 throw new Error('Expected deprecation warnings did not happen: ' +
76108 missedDeprecations.join(' '));
516f5f67 76109 }
73f3c911 76110 }
b135bf1a 76111 }
516f5f67 76112
db71a655
KM
76113 function matchedDeprecation(name, msg, deprecations) {
76114 if (deprecations == null) {
76115 return -1;
73f3c911 76116 }
db71a655
KM
76117 for (var i = 0; i < deprecations.length; ++i) {
76118 if (name != null && name === deprecations[i]) {
76119 return i;
b135bf1a 76120 }
db71a655 76121 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
73f3c911 76122 return i;
b135bf1a 76123 }
73f3c911
IC
76124 }
76125 return -1;
73f3c911 76126 }
b135bf1a 76127
db71a655 76128 /*global QUnit:false*/
b135bf1a 76129
db71a655 76130 var test = QUnit.test;
b135bf1a 76131
db71a655
KM
76132 function module$1 (name, lifecycle) {
76133 QUnit.module(name, {
c58511b9 76134 beforeEach : function () {
db71a655
KM
76135 moment.locale('en');
76136 moment.createFromInputFallback = function (config) {
76137 throw new Error('input not handled by moment: ' + config._i);
76138 };
76139 setupDeprecationHandler(test, moment, 'core');
76140 if (lifecycle && lifecycle.setup) {
76141 lifecycle.setup();
76142 }
76143 },
c58511b9 76144 afterEach : function () {
db71a655
KM
76145 teardownDeprecationHandler(test, moment, 'core');
76146 if (lifecycle && lifecycle.teardown) {
76147 lifecycle.teardown();
76148 }
76149 }
76150 });
76151 }
d6651c21 76152
db71a655
KM
76153 var symbolMap = {
76154 '1': '!',
76155 '2': '@',
76156 '3': '#',
76157 '4': '$',
76158 '5': '%',
76159 '6': '^',
76160 '7': '&',
76161 '8': '*',
76162 '9': '(',
76163 '0': ')'
73f3c911 76164 },
db71a655
KM
76165 numberMap = {
76166 '!': '1',
76167 '@': '2',
76168 '#': '3',
76169 '$': '4',
76170 '%': '5',
76171 '^': '6',
76172 '&': '7',
76173 '*': '8',
76174 '(': '9',
76175 ')': '0'
76176 };
d6651c21 76177
db71a655
KM
76178 module$1('preparse and postformat', {
76179 setup: function () {
76180 moment.locale('symbol', {
76181 preparse: function (string) {
76182 return string.replace(/[!@#$%\^&*()]/g, function (match) {
76183 return numberMap[match];
76184 });
76185 },
76186
76187 postformat: function (string) {
76188 return string.replace(/\d/g, function (match) {
76189 return symbolMap[match];
76190 });
76191 }
76192 });
76193 },
76194 teardown: function () {
76195 moment.defineLocale('symbol', null);
76196 }
73f3c911 76197 });
d6651c21 76198
db71a655
KM
76199 test('transform', function (assert) {
76200 assert.equal(moment.utc('@)!@-)*-@&', 'YYYY-MM-DD').unix(), 1346025600, 'preparse string + format');
76201 assert.equal(moment.utc('@)!@-)*-@&').unix(), 1346025600, 'preparse ISO8601 string');
76202 assert.equal(moment.unix(1346025600).utc().format('YYYY-MM-DD'), '@)!@-)*-@&', 'postformat');
76203 });
516f5f67 76204
db71a655
KM
76205 test('transform from', function (assert) {
76206 var start = moment([2007, 1, 28]);
516f5f67 76207
db71a655
KM
76208 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '@ minutes', 'postformat should work on moment.fn.from');
76209 assert.equal(moment().add(6, 'd').fromNow(true), '^ days', 'postformat should work on moment.fn.fromNow');
76210 assert.equal(moment.duration(10, 'h').humanize(), '!) hours', 'postformat should work on moment.duration.fn.humanize');
76211 });
516f5f67 76212
db71a655
KM
76213 test('calendar day', function (assert) {
76214 var a = moment().hours(12).minutes(0).seconds(0);
1d986a17 76215
db71a655
KM
76216 assert.equal(moment(a).calendar(), 'Today at !@:)) PM', 'today at the same time');
76217 assert.equal(moment(a).add({m: 25}).calendar(), 'Today at !@:@% PM', 'Now plus 25 min');
76218 assert.equal(moment(a).add({h: 1}).calendar(), 'Today at !:)) PM', 'Now plus 1 hour');
76219 assert.equal(moment(a).add({d: 1}).calendar(), 'Tomorrow at !@:)) PM', 'tomorrow at the same time');
76220 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Today at !!:)) AM', 'Now minus 1 hour');
76221 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Yesterday at !@:)) PM', 'yesterday at the same time');
76222 });
73f3c911
IC
76223
76224})));
516f5f67 76225
516f5f67 76226
9483e2a4
IC
76227;(function (global, factory) {
76228 typeof exports === 'object' && typeof module !== 'undefined'
76229 && typeof require === 'function' ? factory(require('../../moment')) :
76230 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
76231 factory(global.moment)
76232}(this, (function (moment) { 'use strict';
76233
db71a655
KM
76234 function each(array, callback) {
76235 var i;
76236 for (i = 0; i < array.length; i++) {
76237 callback(array[i], i, array);
76238 }
9483e2a4 76239 }
d6651c21 76240
db71a655
KM
76241 function setupDeprecationHandler(test, moment$$1, scope) {
76242 test._expectedDeprecations = null;
76243 test._observedDeprecations = null;
76244 test._oldSupress = moment$$1.suppressDeprecationWarnings;
76245 moment$$1.suppressDeprecationWarnings = true;
76246 test.expectedDeprecations = function () {
76247 test._expectedDeprecations = arguments;
76248 test._observedDeprecations = [];
76249 };
76250 moment$$1.deprecationHandler = function (name, msg) {
76251 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
76252 if (deprecationId === -1) {
76253 throw new Error('Unexpected deprecation thrown name=' +
76254 name + ' msg=' + msg);
76255 }
76256 test._observedDeprecations[deprecationId] = 1;
76257 };
76258 }
d6651c21 76259
db71a655
KM
76260 function teardownDeprecationHandler(test, moment$$1, scope) {
76261 moment$$1.suppressDeprecationWarnings = test._oldSupress;
d6651c21 76262
db71a655
KM
76263 if (test._expectedDeprecations != null) {
76264 var missedDeprecations = [];
76265 each(test._expectedDeprecations, function (deprecationPattern, id) {
76266 if (test._observedDeprecations[id] !== 1) {
76267 missedDeprecations.push(deprecationPattern);
76268 }
76269 });
76270 if (missedDeprecations.length !== 0) {
76271 throw new Error('Expected deprecation warnings did not happen: ' +
76272 missedDeprecations.join(' '));
d6651c21 76273 }
73f3c911 76274 }
d6651c21
IC
76275 }
76276
db71a655
KM
76277 function matchedDeprecation(name, msg, deprecations) {
76278 if (deprecations == null) {
76279 return -1;
73f3c911 76280 }
db71a655
KM
76281 for (var i = 0; i < deprecations.length; ++i) {
76282 if (name != null && name === deprecations[i]) {
76283 return i;
76284 }
76285 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
76286 return i;
76287 }
73f3c911 76288 }
db71a655 76289 return -1;
d6651c21
IC
76290 }
76291
db71a655 76292 /*global QUnit:false*/
d6651c21 76293
db71a655 76294 var test = QUnit.test;
d6651c21 76295
db71a655
KM
76296 function module$1 (name, lifecycle) {
76297 QUnit.module(name, {
c58511b9 76298 beforeEach : function () {
db71a655
KM
76299 moment.locale('en');
76300 moment.createFromInputFallback = function (config) {
76301 throw new Error('input not handled by moment: ' + config._i);
76302 };
76303 setupDeprecationHandler(test, moment, 'core');
76304 if (lifecycle && lifecycle.setup) {
76305 lifecycle.setup();
76306 }
76307 },
c58511b9 76308 afterEach : function () {
db71a655
KM
76309 teardownDeprecationHandler(test, moment, 'core');
76310 if (lifecycle && lifecycle.teardown) {
76311 lifecycle.teardown();
76312 }
73f3c911 76313 }
db71a655
KM
76314 });
76315 }
d6651c21 76316
db71a655
KM
76317 module$1('quarter');
76318
76319 test('library quarter getter', function (assert) {
76320 assert.equal(moment([1985, 1, 4]).quarter(), 1, 'Feb 4 1985 is Q1');
76321 assert.equal(moment([2029, 8, 18]).quarter(), 3, 'Sep 18 2029 is Q3');
76322 assert.equal(moment([2013, 3, 24]).quarter(), 2, 'Apr 24 2013 is Q2');
76323 assert.equal(moment([2015, 2, 5]).quarter(), 1, 'Mar 5 2015 is Q1');
76324 assert.equal(moment([1970, 0, 2]).quarter(), 1, 'Jan 2 1970 is Q1');
76325 assert.equal(moment([2001, 11, 12]).quarter(), 4, 'Dec 12 2001 is Q4');
76326 assert.equal(moment([2000, 0, 2]).quarter(), 1, 'Jan 2 2000 is Q1');
76327 });
76328
76329 test('quarter setter singular', function (assert) {
76330 var m = moment([2014, 4, 11]);
76331 assert.equal(m.quarter(2).month(), 4, 'set same quarter');
76332 assert.equal(m.quarter(3).month(), 7, 'set 3rd quarter');
76333 assert.equal(m.quarter(1).month(), 1, 'set 1st quarter');
76334 assert.equal(m.quarter(4).month(), 10, 'set 4th quarter');
76335 });
76336
76337 test('quarter setter plural', function (assert) {
76338 var m = moment([2014, 4, 11]);
76339 assert.equal(m.quarters(2).month(), 4, 'set same quarter');
76340 assert.equal(m.quarters(3).month(), 7, 'set 3rd quarter');
76341 assert.equal(m.quarters(1).month(), 1, 'set 1st quarter');
76342 assert.equal(m.quarters(4).month(), 10, 'set 4th quarter');
76343 });
76344
76345 test('quarter setter programmatic', function (assert) {
76346 var m = moment([2014, 4, 11]);
76347 assert.equal(m.set('quarter', 2).month(), 4, 'set same quarter');
76348 assert.equal(m.set('quarter', 3).month(), 7, 'set 3rd quarter');
76349 assert.equal(m.set('quarter', 1).month(), 1, 'set 1st quarter');
76350 assert.equal(m.set('quarter', 4).month(), 10, 'set 4th quarter');
76351 });
76352
76353 test('quarter setter programmatic plural', function (assert) {
76354 var m = moment([2014, 4, 11]);
76355 assert.equal(m.set('quarters', 2).month(), 4, 'set same quarter');
76356 assert.equal(m.set('quarters', 3).month(), 7, 'set 3rd quarter');
76357 assert.equal(m.set('quarters', 1).month(), 1, 'set 1st quarter');
76358 assert.equal(m.set('quarters', 4).month(), 10, 'set 4th quarter');
76359 });
76360
76361 test('quarter setter programmatic abbr', function (assert) {
76362 var m = moment([2014, 4, 11]);
76363 assert.equal(m.set('Q', 2).month(), 4, 'set same quarter');
76364 assert.equal(m.set('Q', 3).month(), 7, 'set 3rd quarter');
76365 assert.equal(m.set('Q', 1).month(), 1, 'set 1st quarter');
76366 assert.equal(m.set('Q', 4).month(), 10, 'set 4th quarter');
76367 });
76368
76369 test('quarter setter only month changes', function (assert) {
76370 var m = moment([2014, 4, 11, 1, 2, 3, 4]).quarter(4);
76371 assert.equal(m.year(), 2014, 'keep year');
76372 assert.equal(m.month(), 10, 'set month');
76373 assert.equal(m.date(), 11, 'keep date');
76374 assert.equal(m.hour(), 1, 'keep hour');
76375 assert.equal(m.minute(), 2, 'keep minutes');
76376 assert.equal(m.second(), 3, 'keep seconds');
76377 assert.equal(m.millisecond(), 4, 'keep milliseconds');
76378 });
76379
76380 test('quarter setter bubble to next year', function (assert) {
76381 var m = moment([2014, 4, 11, 1, 2, 3, 4]).quarter(7);
76382 assert.equal(m.year(), 2015, 'year bubbled');
76383 assert.equal(m.month(), 7, 'set month');
76384 assert.equal(m.date(), 11, 'keep date');
76385 assert.equal(m.hour(), 1, 'keep hour');
76386 assert.equal(m.minute(), 2, 'keep minutes');
76387 assert.equal(m.second(), 3, 'keep seconds');
76388 assert.equal(m.millisecond(), 4, 'keep milliseconds');
76389 });
76390
76391 test('quarter diff', function (assert) {
76392 assert.equal(moment('2014-01-01').diff(moment('2014-04-01'), 'quarter'),
76393 -1, 'diff -1 quarter');
76394 assert.equal(moment('2014-04-01').diff(moment('2014-01-01'), 'quarter'),
76395 1, 'diff 1 quarter');
76396 assert.equal(moment('2014-05-01').diff(moment('2014-01-01'), 'quarter'),
76397 1, 'diff 1 quarter');
76398 assert.ok(Math.abs((4 / 3) - moment('2014-05-01').diff(
76399 moment('2014-01-01'), 'quarter', true)) < 0.00001,
76400 'diff 1 1/3 quarter');
76401 assert.equal(moment('2015-01-01').diff(moment('2014-01-01'), 'quarter'),
76402 4, 'diff 4 quarters');
76403 });
76404
76405 test('quarter setter bubble to previous year', function (assert) {
76406 var m = moment([2014, 4, 11, 1, 2, 3, 4]).quarter(-3);
76407 assert.equal(m.year(), 2013, 'year bubbled');
76408 assert.equal(m.month(), 1, 'set month');
76409 assert.equal(m.date(), 11, 'keep date');
76410 assert.equal(m.hour(), 1, 'keep hour');
76411 assert.equal(m.minute(), 2, 'keep minutes');
76412 assert.equal(m.second(), 3, 'keep seconds');
76413 assert.equal(m.millisecond(), 4, 'keep milliseconds');
76414 });
d6651c21 76415
db71a655 76416})));
d6651c21 76417
d6651c21 76418
db71a655
KM
76419;(function (global, factory) {
76420 typeof exports === 'object' && typeof module !== 'undefined'
76421 && typeof require === 'function' ? factory(require('../../moment')) :
76422 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
76423 factory(global.moment)
76424}(this, (function (moment) { 'use strict';
d6651c21 76425
db71a655
KM
76426 function each(array, callback) {
76427 var i;
76428 for (i = 0; i < array.length; i++) {
76429 callback(array[i], i, array);
d6651c21 76430 }
db71a655 76431 }
d6651c21 76432
db71a655
KM
76433 function setupDeprecationHandler(test, moment$$1, scope) {
76434 test._expectedDeprecations = null;
76435 test._observedDeprecations = null;
76436 test._oldSupress = moment$$1.suppressDeprecationWarnings;
76437 moment$$1.suppressDeprecationWarnings = true;
76438 test.expectedDeprecations = function () {
76439 test._expectedDeprecations = arguments;
76440 test._observedDeprecations = [];
76441 };
76442 moment$$1.deprecationHandler = function (name, msg) {
76443 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
76444 if (deprecationId === -1) {
76445 throw new Error('Unexpected deprecation thrown name=' +
76446 name + ' msg=' + msg);
76447 }
76448 test._observedDeprecations[deprecationId] = 1;
76449 };
76450 }
d6651c21 76451
db71a655
KM
76452 function teardownDeprecationHandler(test, moment$$1, scope) {
76453 moment$$1.suppressDeprecationWarnings = test._oldSupress;
d6651c21 76454
db71a655
KM
76455 if (test._expectedDeprecations != null) {
76456 var missedDeprecations = [];
76457 each(test._expectedDeprecations, function (deprecationPattern, id) {
76458 if (test._observedDeprecations[id] !== 1) {
76459 missedDeprecations.push(deprecationPattern);
76460 }
76461 });
76462 if (missedDeprecations.length !== 0) {
76463 throw new Error('Expected deprecation warnings did not happen: ' +
76464 missedDeprecations.join(' '));
76465 }
73f3c911 76466 }
db71a655 76467 }
b135bf1a 76468
db71a655
KM
76469 function matchedDeprecation(name, msg, deprecations) {
76470 if (deprecations == null) {
76471 return -1;
73f3c911 76472 }
db71a655
KM
76473 for (var i = 0; i < deprecations.length; ++i) {
76474 if (name != null && name === deprecations[i]) {
76475 return i;
76476 }
76477 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
76478 return i;
76479 }
76480 }
76481 return -1;
76482 }
516f5f67 76483
db71a655 76484 /*global QUnit:false*/
b135bf1a 76485
db71a655 76486 var test = QUnit.test;
d6651c21 76487
db71a655
KM
76488 function module$1 (name, lifecycle) {
76489 QUnit.module(name, {
c58511b9 76490 beforeEach : function () {
db71a655
KM
76491 moment.locale('en');
76492 moment.createFromInputFallback = function (config) {
76493 throw new Error('input not handled by moment: ' + config._i);
76494 };
76495 setupDeprecationHandler(test, moment, 'core');
76496 if (lifecycle && lifecycle.setup) {
76497 lifecycle.setup();
76498 }
76499 },
c58511b9 76500 afterEach : function () {
db71a655
KM
76501 teardownDeprecationHandler(test, moment, 'core');
76502 if (lifecycle && lifecycle.teardown) {
76503 lifecycle.teardown();
76504 }
76505 }
76506 });
76507 }
b135bf1a 76508
db71a655
KM
76509 module$1('relative time');
76510
76511 test('default thresholds fromNow', function (assert) {
76512 var a = moment();
76513
76514 // Seconds to minutes threshold
76515 a.subtract(44, 'seconds');
76516 assert.equal(a.fromNow(), 'a few seconds ago', 'Below default seconds to minutes threshold');
76517 a.subtract(1, 'seconds');
76518 assert.equal(a.fromNow(), 'a minute ago', 'Above default seconds to minutes threshold');
76519
76520 // Minutes to hours threshold
76521 a = moment();
76522 a.subtract(44, 'minutes');
76523 assert.equal(a.fromNow(), '44 minutes ago', 'Below default minute to hour threshold');
76524 a.subtract(1, 'minutes');
76525 assert.equal(a.fromNow(), 'an hour ago', 'Above default minute to hour threshold');
76526
76527 // Hours to days threshold
76528 a = moment();
76529 a.subtract(21, 'hours');
76530 assert.equal(a.fromNow(), '21 hours ago', 'Below default hours to day threshold');
76531 a.subtract(1, 'hours');
76532 assert.equal(a.fromNow(), 'a day ago', 'Above default hours to day threshold');
76533
76534 // Days to month threshold
76535 a = moment();
76536 a.subtract(25, 'days');
76537 assert.equal(a.fromNow(), '25 days ago', 'Below default days to month (singular) threshold');
76538 a.subtract(1, 'days');
76539 assert.equal(a.fromNow(), 'a month ago', 'Above default days to month (singular) threshold');
76540
76541 // months to year threshold
76542 a = moment();
76543 a.subtract(10, 'months');
76544 assert.equal(a.fromNow(), '10 months ago', 'Below default days to years threshold');
76545 a.subtract(1, 'month');
76546 assert.equal(a.fromNow(), 'a year ago', 'Above default days to years threshold');
76547 });
76548
76549 test('default thresholds toNow', function (assert) {
76550 var a = moment();
76551
76552 // Seconds to minutes threshold
76553 a.subtract(44, 'seconds');
76554 assert.equal(a.toNow(), 'in a few seconds', 'Below default seconds to minutes threshold');
76555 a.subtract(1, 'seconds');
76556 assert.equal(a.toNow(), 'in a minute', 'Above default seconds to minutes threshold');
76557
76558 // Minutes to hours threshold
76559 a = moment();
76560 a.subtract(44, 'minutes');
76561 assert.equal(a.toNow(), 'in 44 minutes', 'Below default minute to hour threshold');
76562 a.subtract(1, 'minutes');
76563 assert.equal(a.toNow(), 'in an hour', 'Above default minute to hour threshold');
76564
76565 // Hours to days threshold
76566 a = moment();
76567 a.subtract(21, 'hours');
76568 assert.equal(a.toNow(), 'in 21 hours', 'Below default hours to day threshold');
76569 a.subtract(1, 'hours');
76570 assert.equal(a.toNow(), 'in a day', 'Above default hours to day threshold');
76571
76572 // Days to month threshold
76573 a = moment();
76574 a.subtract(25, 'days');
76575 assert.equal(a.toNow(), 'in 25 days', 'Below default days to month (singular) threshold');
76576 a.subtract(1, 'days');
76577 assert.equal(a.toNow(), 'in a month', 'Above default days to month (singular) threshold');
76578
76579 // months to year threshold
76580 a = moment();
76581 a.subtract(10, 'months');
76582 assert.equal(a.toNow(), 'in 10 months', 'Below default days to years threshold');
76583 a.subtract(1, 'month');
76584 assert.equal(a.toNow(), 'in a year', 'Above default days to years threshold');
76585 });
76586
76587 test('custom thresholds', function (assert) {
76588 var a;
76589
76590 // Seconds to minute threshold, under 30
76591 moment.relativeTimeThreshold('s', 25);
76592
76593 a = moment();
76594 a.subtract(24, 'seconds');
76595 assert.equal(a.fromNow(), 'a few seconds ago', 'Below custom seconds to minute threshold, s < 30');
76596 a.subtract(1, 'seconds');
76597 assert.equal(a.fromNow(), 'a minute ago', 'Above custom seconds to minute threshold, s < 30');
76598
76599 // Seconds to minutes threshold
76600 moment.relativeTimeThreshold('s', 55);
76601
76602 a = moment();
76603 a.subtract(54, 'seconds');
76604 assert.equal(a.fromNow(), 'a few seconds ago', 'Below custom seconds to minutes threshold');
76605 a.subtract(1, 'seconds');
76606 assert.equal(a.fromNow(), 'a minute ago', 'Above custom seconds to minutes threshold');
76607
76608 moment.relativeTimeThreshold('s', 45);
76609
76610 // A few seconds to seconds threshold
76611 moment.relativeTimeThreshold('ss', 3);
76612
76613 a = moment();
76614 a.subtract(3, 'seconds');
76615 assert.equal(a.fromNow(), 'a few seconds ago', 'Below custom a few seconds to seconds threshold');
76616 a.subtract(1, 'seconds');
76617 assert.equal(a.fromNow(), '4 seconds ago', 'Above custom a few seconds to seconds threshold');
76618
76619 moment.relativeTimeThreshold('ss', 44);
76620
76621 // Minutes to hours threshold
76622 moment.relativeTimeThreshold('m', 55);
76623 a = moment();
76624 a.subtract(54, 'minutes');
76625 assert.equal(a.fromNow(), '54 minutes ago', 'Below custom minutes to hours threshold');
76626 a.subtract(1, 'minutes');
76627 assert.equal(a.fromNow(), 'an hour ago', 'Above custom minutes to hours threshold');
76628 moment.relativeTimeThreshold('m', 45);
76629
76630 // Hours to days threshold
76631 moment.relativeTimeThreshold('h', 24);
76632 a = moment();
76633 a.subtract(23, 'hours');
76634 assert.equal(a.fromNow(), '23 hours ago', 'Below custom hours to days threshold');
76635 a.subtract(1, 'hours');
76636 assert.equal(a.fromNow(), 'a day ago', 'Above custom hours to days threshold');
76637 moment.relativeTimeThreshold('h', 22);
76638
76639 // Days to month threshold
76640 moment.relativeTimeThreshold('d', 28);
76641 a = moment();
76642 a.subtract(27, 'days');
76643 assert.equal(a.fromNow(), '27 days ago', 'Below custom days to month (singular) threshold');
76644 a.subtract(1, 'days');
76645 assert.equal(a.fromNow(), 'a month ago', 'Above custom days to month (singular) threshold');
76646 moment.relativeTimeThreshold('d', 26);
76647
76648 // months to years threshold
76649 moment.relativeTimeThreshold('M', 9);
76650 a = moment();
76651 a.subtract(8, 'months');
76652 assert.equal(a.fromNow(), '8 months ago', 'Below custom days to years threshold');
76653 a.subtract(1, 'months');
76654 assert.equal(a.fromNow(), 'a year ago', 'Above custom days to years threshold');
76655 moment.relativeTimeThreshold('M', 11);
96d0d679
KM
76656
76657 // multiple thresholds
76658 moment.relativeTimeThreshold('ss', 3);
76659 a = moment();
76660 a.subtract(4, 'seconds');
76661 assert.equal(a.fromNow(), '4 seconds ago', 'Before setting s relative time threshold');
76662 moment.relativeTimeThreshold('s', 59);
76663 assert.equal(a.fromNow(), 'a few seconds ago', 'After setting s relative time threshold');
76664 moment.relativeTimeThreshold('ss', 44);
76665 moment.relativeTimeThreshold('s', 45);
db71a655
KM
76666 });
76667
76668 test('custom rounding', function (assert) {
76669 var roundingDefault = moment.relativeTimeRounding();
76670
76671 // Round relative time evaluation down
76672 moment.relativeTimeRounding(Math.floor);
76673
76674 moment.relativeTimeThreshold('s', 60);
76675 moment.relativeTimeThreshold('m', 60);
76676 moment.relativeTimeThreshold('h', 24);
76677 moment.relativeTimeThreshold('d', 27);
76678 moment.relativeTimeThreshold('M', 12);
76679
76680 var a = moment.utc();
76681 a.subtract({minutes: 59, seconds: 59});
76682 assert.equal(a.toNow(), 'in 59 minutes', 'Round down towards the nearest minute');
76683
76684 a = moment.utc();
76685 a.subtract({hours: 23, minutes: 59, seconds: 59});
76686 assert.equal(a.toNow(), 'in 23 hours', 'Round down towards the nearest hour');
76687
76688 a = moment.utc();
76689 a.subtract({days: 26, hours: 23, minutes: 59});
76690 assert.equal(a.toNow(), 'in 26 days', 'Round down towards the nearest day (just under)');
76691
76692 a = moment.utc();
76693 a.subtract({days: 27});
76694 assert.equal(a.toNow(), 'in a month', 'Round down towards the nearest day (just over)');
76695
76696 a = moment.utc();
76697 a.subtract({days: 364});
76698 assert.equal(a.toNow(), 'in 11 months', 'Round down towards the nearest month');
76699
76700 a = moment.utc();
76701 a.subtract({years: 1, days: 364});
76702 assert.equal(a.toNow(), 'in a year', 'Round down towards the nearest year');
76703
76704 // Do not round relative time evaluation
76705 var retainValue = function (value) {
76706 return value.toFixed(3);
76707 };
76708 moment.relativeTimeRounding(retainValue);
516f5f67 76709
db71a655
KM
76710 a = moment.utc();
76711 a.subtract({hours: 39});
76712 assert.equal(a.toNow(), 'in 1.625 days', 'Round down towards the nearest year');
516f5f67 76713
db71a655
KM
76714 // Restore defaults
76715 moment.relativeTimeThreshold('s', 45);
76716 moment.relativeTimeThreshold('m', 45);
76717 moment.relativeTimeThreshold('h', 22);
76718 moment.relativeTimeThreshold('d', 26);
76719 moment.relativeTimeThreshold('M', 11);
76720 moment.relativeTimeRounding(roundingDefault);
73f3c911 76721 });
7c4c091b 76722
db71a655
KM
76723 test('retrieve rounding settings', function (assert) {
76724 moment.relativeTimeRounding(Math.round);
76725 var roundingFunction = moment.relativeTimeRounding();
7c4c091b 76726
db71a655 76727 assert.equal(roundingFunction, Math.round, 'Can retrieve rounding setting');
73f3c911 76728 });
c74a101d 76729
db71a655
KM
76730 test('retrieve threshold settings', function (assert) {
76731 moment.relativeTimeThreshold('m', 45);
76732 var minuteThreshold = moment.relativeTimeThreshold('m');
73f3c911 76733
db71a655 76734 assert.equal(minuteThreshold, 45, 'Can retrieve minute setting');
7c4c091b 76735 });
7c4c091b 76736
73f3c911
IC
76737})));
76738
76739
76740;(function (global, factory) {
76741 typeof exports === 'object' && typeof module !== 'undefined'
76742 && typeof require === 'function' ? factory(require('../../moment')) :
76743 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
76744 factory(global.moment)
76745}(this, (function (moment) { 'use strict';
76746
db71a655
KM
76747 function each(array, callback) {
76748 var i;
76749 for (i = 0; i < array.length; i++) {
76750 callback(array[i], i, array);
76751 }
516f5f67
IC
76752 }
76753
db71a655
KM
76754 function setupDeprecationHandler(test, moment$$1, scope) {
76755 test._expectedDeprecations = null;
76756 test._observedDeprecations = null;
76757 test._oldSupress = moment$$1.suppressDeprecationWarnings;
76758 moment$$1.suppressDeprecationWarnings = true;
76759 test.expectedDeprecations = function () {
76760 test._expectedDeprecations = arguments;
76761 test._observedDeprecations = [];
76762 };
76763 moment$$1.deprecationHandler = function (name, msg) {
76764 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
76765 if (deprecationId === -1) {
76766 throw new Error('Unexpected deprecation thrown name=' +
76767 name + ' msg=' + msg);
76768 }
76769 test._observedDeprecations[deprecationId] = 1;
76770 };
76771 }
d6651c21 76772
db71a655
KM
76773 function teardownDeprecationHandler(test, moment$$1, scope) {
76774 moment$$1.suppressDeprecationWarnings = test._oldSupress;
d6651c21 76775
db71a655
KM
76776 if (test._expectedDeprecations != null) {
76777 var missedDeprecations = [];
76778 each(test._expectedDeprecations, function (deprecationPattern, id) {
76779 if (test._observedDeprecations[id] !== 1) {
76780 missedDeprecations.push(deprecationPattern);
76781 }
76782 });
76783 if (missedDeprecations.length !== 0) {
76784 throw new Error('Expected deprecation warnings did not happen: ' +
76785 missedDeprecations.join(' '));
d6651c21 76786 }
73f3c911 76787 }
d6651c21
IC
76788 }
76789
db71a655
KM
76790 function matchedDeprecation(name, msg, deprecations) {
76791 if (deprecations == null) {
76792 return -1;
73f3c911 76793 }
db71a655
KM
76794 for (var i = 0; i < deprecations.length; ++i) {
76795 if (name != null && name === deprecations[i]) {
76796 return i;
76797 }
76798 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
76799 return i;
76800 }
d6651c21 76801 }
db71a655 76802 return -1;
d6651c21
IC
76803 }
76804
db71a655 76805 /*global QUnit:false*/
73f3c911 76806
db71a655 76807 var test = QUnit.test;
73f3c911 76808
db71a655
KM
76809 function module$1 (name, lifecycle) {
76810 QUnit.module(name, {
c58511b9 76811 beforeEach : function () {
db71a655
KM
76812 moment.locale('en');
76813 moment.createFromInputFallback = function (config) {
76814 throw new Error('input not handled by moment: ' + config._i);
76815 };
76816 setupDeprecationHandler(test, moment, 'core');
76817 if (lifecycle && lifecycle.setup) {
76818 lifecycle.setup();
76819 }
76820 },
c58511b9 76821 afterEach : function () {
db71a655
KM
76822 teardownDeprecationHandler(test, moment, 'core');
76823 if (lifecycle && lifecycle.teardown) {
76824 lifecycle.teardown();
76825 }
d6651c21 76826 }
db71a655
KM
76827 });
76828 }
516f5f67 76829
db71a655
KM
76830 module$1('start and end of units');
76831
76832 test('start of year', function (assert) {
76833 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('year'),
76834 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('years'),
76835 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('y');
76836 assert.equal(+m, +ms, 'Plural or singular should work');
76837 assert.equal(+m, +ma, 'Full or abbreviated should work');
76838 assert.equal(m.year(), 2011, 'keep the year');
76839 assert.equal(m.month(), 0, 'strip out the month');
76840 assert.equal(m.date(), 1, 'strip out the day');
76841 assert.equal(m.hours(), 0, 'strip out the hours');
76842 assert.equal(m.minutes(), 0, 'strip out the minutes');
76843 assert.equal(m.seconds(), 0, 'strip out the seconds');
76844 assert.equal(m.milliseconds(), 0, 'strip out the milliseconds');
76845 });
76846
76847 test('end of year', function (assert) {
76848 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('year'),
76849 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('years'),
76850 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('y');
76851 assert.equal(+m, +ms, 'Plural or singular should work');
76852 assert.equal(+m, +ma, 'Full or abbreviated should work');
76853 assert.equal(m.year(), 2011, 'keep the year');
76854 assert.equal(m.month(), 11, 'set the month');
76855 assert.equal(m.date(), 31, 'set the day');
76856 assert.equal(m.hours(), 23, 'set the hours');
76857 assert.equal(m.minutes(), 59, 'set the minutes');
76858 assert.equal(m.seconds(), 59, 'set the seconds');
76859 assert.equal(m.milliseconds(), 999, 'set the seconds');
76860 });
76861
76862 test('start of quarter', function (assert) {
76863 var m = moment(new Date(2011, 4, 2, 3, 4, 5, 6)).startOf('quarter'),
76864 ms = moment(new Date(2011, 4, 2, 3, 4, 5, 6)).startOf('quarters'),
76865 ma = moment(new Date(2011, 4, 2, 3, 4, 5, 6)).startOf('Q');
76866 assert.equal(+m, +ms, 'Plural or singular should work');
76867 assert.equal(+m, +ma, 'Full or abbreviated should work');
76868 assert.equal(m.year(), 2011, 'keep the year');
76869 assert.equal(m.quarter(), 2, 'keep the quarter');
76870 assert.equal(m.month(), 3, 'strip out the month');
76871 assert.equal(m.date(), 1, 'strip out the day');
76872 assert.equal(m.hours(), 0, 'strip out the hours');
76873 assert.equal(m.minutes(), 0, 'strip out the minutes');
76874 assert.equal(m.seconds(), 0, 'strip out the seconds');
76875 assert.equal(m.milliseconds(), 0, 'strip out the milliseconds');
76876 });
76877
76878 test('end of quarter', function (assert) {
76879 var m = moment(new Date(2011, 4, 2, 3, 4, 5, 6)).endOf('quarter'),
76880 ms = moment(new Date(2011, 4, 2, 3, 4, 5, 6)).endOf('quarters'),
76881 ma = moment(new Date(2011, 4, 2, 3, 4, 5, 6)).endOf('Q');
76882 assert.equal(+m, +ms, 'Plural or singular should work');
76883 assert.equal(+m, +ma, 'Full or abbreviated should work');
76884 assert.equal(m.year(), 2011, 'keep the year');
76885 assert.equal(m.quarter(), 2, 'keep the quarter');
76886 assert.equal(m.month(), 5, 'set the month');
76887 assert.equal(m.date(), 30, 'set the day');
76888 assert.equal(m.hours(), 23, 'set the hours');
76889 assert.equal(m.minutes(), 59, 'set the minutes');
76890 assert.equal(m.seconds(), 59, 'set the seconds');
76891 assert.equal(m.milliseconds(), 999, 'set the seconds');
76892 });
76893
76894 test('start of month', function (assert) {
76895 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('month'),
76896 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('months'),
76897 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('M');
76898 assert.equal(+m, +ms, 'Plural or singular should work');
76899 assert.equal(+m, +ma, 'Full or abbreviated should work');
76900 assert.equal(m.year(), 2011, 'keep the year');
76901 assert.equal(m.month(), 1, 'keep the month');
76902 assert.equal(m.date(), 1, 'strip out the day');
76903 assert.equal(m.hours(), 0, 'strip out the hours');
76904 assert.equal(m.minutes(), 0, 'strip out the minutes');
76905 assert.equal(m.seconds(), 0, 'strip out the seconds');
76906 assert.equal(m.milliseconds(), 0, 'strip out the milliseconds');
76907 });
76908
76909 test('end of month', function (assert) {
76910 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('month'),
76911 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('months'),
76912 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('M');
76913 assert.equal(+m, +ms, 'Plural or singular should work');
76914 assert.equal(+m, +ma, 'Full or abbreviated should work');
76915 assert.equal(m.year(), 2011, 'keep the year');
76916 assert.equal(m.month(), 1, 'keep the month');
76917 assert.equal(m.date(), 28, 'set the day');
76918 assert.equal(m.hours(), 23, 'set the hours');
76919 assert.equal(m.minutes(), 59, 'set the minutes');
76920 assert.equal(m.seconds(), 59, 'set the seconds');
76921 assert.equal(m.milliseconds(), 999, 'set the seconds');
76922 });
76923
76924 test('start of week', function (assert) {
76925 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('week'),
76926 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('weeks'),
76927 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('w');
76928 assert.equal(+m, +ms, 'Plural or singular should work');
76929 assert.equal(+m, +ma, 'Full or abbreviated should work');
76930 assert.equal(m.year(), 2011, 'keep the year');
76931 assert.equal(m.month(), 0, 'rolls back to January');
76932 assert.equal(m.day(), 0, 'set day of week');
76933 assert.equal(m.date(), 30, 'set correct date');
76934 assert.equal(m.hours(), 0, 'strip out the hours');
76935 assert.equal(m.minutes(), 0, 'strip out the minutes');
76936 assert.equal(m.seconds(), 0, 'strip out the seconds');
76937 assert.equal(m.milliseconds(), 0, 'strip out the milliseconds');
76938 });
76939
76940 test('end of week', function (assert) {
76941 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('week'),
76942 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('weeks'),
76943 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('weeks');
76944 assert.equal(+m, +ms, 'Plural or singular should work');
76945 assert.equal(+m, +ma, 'Full or abbreviated should work');
76946 assert.equal(m.year(), 2011, 'keep the year');
76947 assert.equal(m.month(), 1, 'keep the month');
76948 assert.equal(m.day(), 6, 'set the day of the week');
76949 assert.equal(m.date(), 5, 'set the day');
76950 assert.equal(m.hours(), 23, 'set the hours');
76951 assert.equal(m.minutes(), 59, 'set the minutes');
76952 assert.equal(m.seconds(), 59, 'set the seconds');
76953 assert.equal(m.milliseconds(), 999, 'set the seconds');
76954 });
76955
76956 test('start of iso-week', function (assert) {
76957 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('isoWeek'),
76958 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('isoWeeks'),
76959 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('W');
76960 assert.equal(+m, +ms, 'Plural or singular should work');
76961 assert.equal(+m, +ma, 'Full or abbreviated should work');
76962 assert.equal(m.year(), 2011, 'keep the year');
76963 assert.equal(m.month(), 0, 'rollback to January');
76964 assert.equal(m.isoWeekday(), 1, 'set day of iso-week');
76965 assert.equal(m.date(), 31, 'set correct date');
76966 assert.equal(m.hours(), 0, 'strip out the hours');
76967 assert.equal(m.minutes(), 0, 'strip out the minutes');
76968 assert.equal(m.seconds(), 0, 'strip out the seconds');
76969 assert.equal(m.milliseconds(), 0, 'strip out the milliseconds');
76970 });
76971
76972 test('end of iso-week', function (assert) {
76973 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('isoWeek'),
76974 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('isoWeeks'),
76975 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('W');
76976 assert.equal(+m, +ms, 'Plural or singular should work');
76977 assert.equal(+m, +ma, 'Full or abbreviated should work');
76978 assert.equal(m.year(), 2011, 'keep the year');
76979 assert.equal(m.month(), 1, 'keep the month');
76980 assert.equal(m.isoWeekday(), 7, 'set the day of the week');
76981 assert.equal(m.date(), 6, 'set the day');
76982 assert.equal(m.hours(), 23, 'set the hours');
76983 assert.equal(m.minutes(), 59, 'set the minutes');
76984 assert.equal(m.seconds(), 59, 'set the seconds');
76985 assert.equal(m.milliseconds(), 999, 'set the seconds');
76986 });
76987
76988 test('start of day', function (assert) {
76989 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('day'),
76990 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('days'),
76991 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('d');
76992 assert.equal(+m, +ms, 'Plural or singular should work');
76993 assert.equal(+m, +ma, 'Full or abbreviated should work');
76994 assert.equal(m.year(), 2011, 'keep the year');
76995 assert.equal(m.month(), 1, 'keep the month');
76996 assert.equal(m.date(), 2, 'keep the day');
76997 assert.equal(m.hours(), 0, 'strip out the hours');
76998 assert.equal(m.minutes(), 0, 'strip out the minutes');
76999 assert.equal(m.seconds(), 0, 'strip out the seconds');
77000 assert.equal(m.milliseconds(), 0, 'strip out the milliseconds');
77001 });
77002
77003 test('end of day', function (assert) {
77004 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('day'),
77005 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('days'),
77006 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('d');
77007 assert.equal(+m, +ms, 'Plural or singular should work');
77008 assert.equal(+m, +ma, 'Full or abbreviated should work');
77009 assert.equal(m.year(), 2011, 'keep the year');
77010 assert.equal(m.month(), 1, 'keep the month');
77011 assert.equal(m.date(), 2, 'keep the day');
77012 assert.equal(m.hours(), 23, 'set the hours');
77013 assert.equal(m.minutes(), 59, 'set the minutes');
77014 assert.equal(m.seconds(), 59, 'set the seconds');
77015 assert.equal(m.milliseconds(), 999, 'set the seconds');
77016 });
77017
77018 test('start of date', function (assert) {
77019 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('date'),
77020 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('dates');
77021
77022 assert.equal(+m, +ms, 'Plural or singular should work');
77023 assert.equal(m.year(), 2011, 'keep the year');
77024 assert.equal(m.month(), 1, 'keep the month');
77025 assert.equal(m.date(), 2, 'keep the day');
77026 assert.equal(m.hours(), 0, 'strip out the hours');
77027 assert.equal(m.minutes(), 0, 'strip out the minutes');
77028 assert.equal(m.seconds(), 0, 'strip out the seconds');
77029 assert.equal(m.milliseconds(), 0, 'strip out the milliseconds');
77030 });
77031
77032 test('end of date', function (assert) {
77033 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('date'),
77034 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('dates');
77035
77036 assert.equal(+m, +ms, 'Plural or singular should work');
77037 assert.equal(m.year(), 2011, 'keep the year');
77038 assert.equal(m.month(), 1, 'keep the month');
77039 assert.equal(m.date(), 2, 'keep the day');
77040 assert.equal(m.hours(), 23, 'set the hours');
77041 assert.equal(m.minutes(), 59, 'set the minutes');
77042 assert.equal(m.seconds(), 59, 'set the seconds');
77043 assert.equal(m.milliseconds(), 999, 'set the seconds');
77044 });
77045
77046
77047 test('start of hour', function (assert) {
77048 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('hour'),
77049 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('hours'),
77050 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('h');
77051 assert.equal(+m, +ms, 'Plural or singular should work');
77052 assert.equal(+m, +ma, 'Full or abbreviated should work');
77053 assert.equal(m.year(), 2011, 'keep the year');
77054 assert.equal(m.month(), 1, 'keep the month');
77055 assert.equal(m.date(), 2, 'keep the day');
77056 assert.equal(m.hours(), 3, 'keep the hours');
77057 assert.equal(m.minutes(), 0, 'strip out the minutes');
77058 assert.equal(m.seconds(), 0, 'strip out the seconds');
77059 assert.equal(m.milliseconds(), 0, 'strip out the milliseconds');
77060 });
77061
77062 test('end of hour', function (assert) {
77063 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('hour'),
77064 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('hours'),
77065 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('h');
77066 assert.equal(+m, +ms, 'Plural or singular should work');
77067 assert.equal(+m, +ma, 'Full or abbreviated should work');
77068 assert.equal(m.year(), 2011, 'keep the year');
77069 assert.equal(m.month(), 1, 'keep the month');
77070 assert.equal(m.date(), 2, 'keep the day');
77071 assert.equal(m.hours(), 3, 'keep the hours');
77072 assert.equal(m.minutes(), 59, 'set the minutes');
77073 assert.equal(m.seconds(), 59, 'set the seconds');
77074 assert.equal(m.milliseconds(), 999, 'set the seconds');
77075 });
77076
77077 test('start of minute', function (assert) {
77078 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('minute'),
77079 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('minutes'),
77080 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('m');
77081 assert.equal(+m, +ms, 'Plural or singular should work');
77082 assert.equal(+m, +ma, 'Full or abbreviated should work');
77083 assert.equal(m.year(), 2011, 'keep the year');
77084 assert.equal(m.month(), 1, 'keep the month');
77085 assert.equal(m.date(), 2, 'keep the day');
77086 assert.equal(m.hours(), 3, 'keep the hours');
77087 assert.equal(m.minutes(), 4, 'keep the minutes');
77088 assert.equal(m.seconds(), 0, 'strip out the seconds');
77089 assert.equal(m.milliseconds(), 0, 'strip out the milliseconds');
77090 });
77091
77092 test('end of minute', function (assert) {
77093 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('minute'),
77094 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('minutes'),
77095 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('m');
77096 assert.equal(+m, +ms, 'Plural or singular should work');
77097 assert.equal(+m, +ma, 'Full or abbreviated should work');
77098 assert.equal(m.year(), 2011, 'keep the year');
77099 assert.equal(m.month(), 1, 'keep the month');
77100 assert.equal(m.date(), 2, 'keep the day');
77101 assert.equal(m.hours(), 3, 'keep the hours');
77102 assert.equal(m.minutes(), 4, 'keep the minutes');
77103 assert.equal(m.seconds(), 59, 'set the seconds');
77104 assert.equal(m.milliseconds(), 999, 'set the seconds');
77105 });
77106
77107 test('start of second', function (assert) {
77108 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('second'),
77109 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('seconds'),
77110 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('s');
77111 assert.equal(+m, +ms, 'Plural or singular should work');
77112 assert.equal(+m, +ma, 'Full or abbreviated should work');
77113 assert.equal(m.year(), 2011, 'keep the year');
77114 assert.equal(m.month(), 1, 'keep the month');
77115 assert.equal(m.date(), 2, 'keep the day');
77116 assert.equal(m.hours(), 3, 'keep the hours');
77117 assert.equal(m.minutes(), 4, 'keep the minutes');
2e2a5b35 77118 assert.equal(m.seconds(), 5, 'keep the seconds');
db71a655
KM
77119 assert.equal(m.milliseconds(), 0, 'strip out the milliseconds');
77120 });
77121
77122 test('end of second', function (assert) {
77123 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('second'),
77124 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('seconds'),
77125 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('s');
77126 assert.equal(+m, +ms, 'Plural or singular should work');
77127 assert.equal(+m, +ma, 'Full or abbreviated should work');
77128 assert.equal(m.year(), 2011, 'keep the year');
77129 assert.equal(m.month(), 1, 'keep the month');
77130 assert.equal(m.date(), 2, 'keep the day');
77131 assert.equal(m.hours(), 3, 'keep the hours');
77132 assert.equal(m.minutes(), 4, 'keep the minutes');
77133 assert.equal(m.seconds(), 5, 'keep the seconds');
77134 assert.equal(m.milliseconds(), 999, 'set the seconds');
77135 });
77136
77137 test('startOf across DST +1', function (assert) {
77138 var oldUpdateOffset = moment.updateOffset,
77139 // Based on a real story somewhere in America/Los_Angeles
77140 dstAt = moment('2014-03-09T02:00:00-08:00').parseZone(),
77141 m;
77142
77143 moment.updateOffset = function (mom, keepTime) {
77144 if (mom.isBefore(dstAt)) {
77145 mom.utcOffset(-8, keepTime);
77146 } else {
77147 mom.utcOffset(-7, keepTime);
77148 }
77149 };
516f5f67 77150
db71a655
KM
77151 m = moment('2014-03-15T00:00:00-07:00').parseZone();
77152 m.startOf('y');
77153 assert.equal(m.format(), '2014-01-01T00:00:00-08:00', 'startOf(\'year\') across +1');
c74a101d 77154
db71a655
KM
77155 m = moment('2014-03-15T00:00:00-07:00').parseZone();
77156 m.startOf('M');
77157 assert.equal(m.format(), '2014-03-01T00:00:00-08:00', 'startOf(\'month\') across +1');
516f5f67 77158
db71a655
KM
77159 m = moment('2014-03-09T09:00:00-07:00').parseZone();
77160 m.startOf('d');
77161 assert.equal(m.format(), '2014-03-09T00:00:00-08:00', 'startOf(\'day\') across +1');
73f3c911 77162
db71a655
KM
77163 m = moment('2014-03-09T03:05:00-07:00').parseZone();
77164 m.startOf('h');
77165 assert.equal(m.format(), '2014-03-09T03:00:00-07:00', 'startOf(\'hour\') after +1');
c74a101d 77166
db71a655
KM
77167 m = moment('2014-03-09T01:35:00-08:00').parseZone();
77168 m.startOf('h');
77169 assert.equal(m.format(), '2014-03-09T01:00:00-08:00', 'startOf(\'hour\') before +1');
c74a101d 77170
db71a655 77171 // There is no such time as 2:30-7 to try startOf('hour') across that
c74a101d 77172
db71a655 77173 moment.updateOffset = oldUpdateOffset;
c74a101d
IC
77174 });
77175
db71a655
KM
77176 test('startOf across DST -1', function (assert) {
77177 var oldUpdateOffset = moment.updateOffset,
77178 // Based on a real story somewhere in America/Los_Angeles
77179 dstAt = moment('2014-11-02T02:00:00-07:00').parseZone(),
77180 m;
d731fe7e 77181
db71a655
KM
77182 moment.updateOffset = function (mom, keepTime) {
77183 if (mom.isBefore(dstAt)) {
77184 mom.utcOffset(-7, keepTime);
77185 } else {
77186 mom.utcOffset(-8, keepTime);
77187 }
77188 };
d731fe7e 77189
db71a655
KM
77190 m = moment('2014-11-15T00:00:00-08:00').parseZone();
77191 m.startOf('y');
77192 assert.equal(m.format(), '2014-01-01T00:00:00-07:00', 'startOf(\'year\') across -1');
d731fe7e 77193
db71a655
KM
77194 m = moment('2014-11-15T00:00:00-08:00').parseZone();
77195 m.startOf('M');
77196 assert.equal(m.format(), '2014-11-01T00:00:00-07:00', 'startOf(\'month\') across -1');
d731fe7e 77197
db71a655
KM
77198 m = moment('2014-11-02T09:00:00-08:00').parseZone();
77199 m.startOf('d');
77200 assert.equal(m.format(), '2014-11-02T00:00:00-07:00', 'startOf(\'day\') across -1');
d731fe7e 77201
db71a655
KM
77202 // note that utc offset is -8
77203 m = moment('2014-11-02T01:30:00-08:00').parseZone();
77204 m.startOf('h');
77205 assert.equal(m.format(), '2014-11-02T01:00:00-08:00', 'startOf(\'hour\') after +1');
d731fe7e 77206
db71a655
KM
77207 // note that utc offset is -7
77208 m = moment('2014-11-02T01:30:00-07:00').parseZone();
77209 m.startOf('h');
77210 assert.equal(m.format(), '2014-11-02T01:00:00-07:00', 'startOf(\'hour\') before +1');
c74a101d 77211
db71a655 77212 moment.updateOffset = oldUpdateOffset;
73f3c911 77213 });
73f3c911 77214
db71a655
KM
77215 test('endOf millisecond and no-arg', function (assert) {
77216 var m = moment();
77217 assert.equal(+m, +m.clone().endOf(), 'endOf without argument should change time');
77218 assert.equal(+m, +m.clone().endOf('ms'), 'endOf with ms argument should change time');
77219 assert.equal(+m, +m.clone().endOf('millisecond'), 'endOf with millisecond argument should change time');
77220 assert.equal(+m, +m.clone().endOf('milliseconds'), 'endOf with milliseconds argument should change time');
328d51e7 77221 });
328d51e7 77222
96d0d679
KM
77223 test('startOf for year zero', function (assert) {
77224 var m = moment('0000-02-29T12:34:56.789Z').parseZone();
77225 assert.equal(m.clone().startOf('ms').toISOString(), '0000-02-29T12:34:56.789Z', 'startOf millisecond should preserve year');
77226 assert.equal(m.clone().startOf('s').toISOString(), '0000-02-29T12:34:56.000Z', 'startOf second should preserve year');
77227 assert.equal(m.clone().startOf('m').toISOString(), '0000-02-29T12:34:00.000Z', 'startOf minute should preserve year');
77228 assert.equal(m.clone().startOf('h').toISOString(), '0000-02-29T12:00:00.000Z', 'startOf hour should preserve year');
77229 assert.equal(m.clone().startOf('d').toISOString(), '0000-02-29T00:00:00.000Z', 'startOf day should preserve year');
77230 assert.equal(m.clone().startOf('M').toISOString(), '0000-02-01T00:00:00.000Z', 'startOf month should preserve year');
77231 assert.equal(m.clone().startOf('Q').toISOString(), '0000-01-01T00:00:00.000Z', 'startOf quarter should preserve year');
77232 assert.equal(m.clone().startOf('y').toISOString(), '0000-01-01T00:00:00.000Z', 'startOf year should preserve year');
77233 });
77234
77235 test('endOf for year zero', function (assert) {
77236 var m = moment('0000-02-29T12:34:56.789Z').parseZone();
77237 assert.equal(m.clone().endOf('ms').toISOString(), '0000-02-29T12:34:56.789Z', 'endOf millisecond should preserve year');
77238 assert.equal(m.clone().endOf('s').toISOString(), '0000-02-29T12:34:56.999Z', 'endOf second should preserve year');
77239 assert.equal(m.clone().endOf('m').toISOString(), '0000-02-29T12:34:59.999Z', 'endOf minute should preserve year');
77240 assert.equal(m.clone().endOf('h').toISOString(), '0000-02-29T12:59:59.999Z', 'endOf hour should preserve year');
77241 assert.equal(m.clone().endOf('d').toISOString(), '0000-02-29T23:59:59.999Z', 'endOf day should preserve year');
77242 assert.equal(m.clone().endOf('M').toISOString(), '0000-02-29T23:59:59.999Z', 'endOf month should preserve year');
77243 assert.equal(m.clone().endOf('Q').toISOString(), '0000-03-31T23:59:59.999Z', 'endOf quarter should preserve year');
77244 assert.equal(m.clone().endOf('y').toISOString(), '0000-12-31T23:59:59.999Z', 'endOf year should preserve year');
77245 });
77246
73f3c911 77247})));
c74a101d 77248
c74a101d
IC
77249
77250;(function (global, factory) {
77251 typeof exports === 'object' && typeof module !== 'undefined'
77252 && typeof require === 'function' ? factory(require('../../moment')) :
77253 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
77254 factory(global.moment)
73f3c911 77255}(this, (function (moment) { 'use strict';
c74a101d 77256
db71a655
KM
77257 function each(array, callback) {
77258 var i;
77259 for (i = 0; i < array.length; i++) {
77260 callback(array[i], i, array);
77261 }
b135bf1a
IC
77262 }
77263
db71a655
KM
77264 function setupDeprecationHandler(test, moment$$1, scope) {
77265 test._expectedDeprecations = null;
77266 test._observedDeprecations = null;
77267 test._oldSupress = moment$$1.suppressDeprecationWarnings;
77268 moment$$1.suppressDeprecationWarnings = true;
77269 test.expectedDeprecations = function () {
77270 test._expectedDeprecations = arguments;
77271 test._observedDeprecations = [];
77272 };
77273 moment$$1.deprecationHandler = function (name, msg) {
77274 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
77275 if (deprecationId === -1) {
77276 throw new Error('Unexpected deprecation thrown name=' +
77277 name + ' msg=' + msg);
77278 }
77279 test._observedDeprecations[deprecationId] = 1;
77280 };
77281 }
73f3c911 77282
db71a655
KM
77283 function teardownDeprecationHandler(test, moment$$1, scope) {
77284 moment$$1.suppressDeprecationWarnings = test._oldSupress;
73f3c911 77285
db71a655
KM
77286 if (test._expectedDeprecations != null) {
77287 var missedDeprecations = [];
77288 each(test._expectedDeprecations, function (deprecationPattern, id) {
77289 if (test._observedDeprecations[id] !== 1) {
77290 missedDeprecations.push(deprecationPattern);
77291 }
77292 });
77293 if (missedDeprecations.length !== 0) {
77294 throw new Error('Expected deprecation warnings did not happen: ' +
77295 missedDeprecations.join(' '));
d6651c21
IC
77296 }
77297 }
73f3c911 77298 }
73f3c911 77299
db71a655
KM
77300 function matchedDeprecation(name, msg, deprecations) {
77301 if (deprecations == null) {
77302 return -1;
73f3c911 77303 }
db71a655
KM
77304 for (var i = 0; i < deprecations.length; ++i) {
77305 if (name != null && name === deprecations[i]) {
77306 return i;
c74a101d 77307 }
db71a655
KM
77308 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
77309 return i;
516f5f67 77310 }
73f3c911 77311 }
db71a655
KM
77312 return -1;
77313 }
516f5f67 77314
db71a655 77315 /*global QUnit:false*/
516f5f67 77316
db71a655 77317 var test = QUnit.test;
73f3c911 77318
db71a655
KM
77319 function module$1 (name, lifecycle) {
77320 QUnit.module(name, {
c58511b9 77321 beforeEach : function () {
db71a655
KM
77322 moment.locale('en');
77323 moment.createFromInputFallback = function (config) {
77324 throw new Error('input not handled by moment: ' + config._i);
77325 };
77326 setupDeprecationHandler(test, moment, 'core');
77327 if (lifecycle && lifecycle.setup) {
77328 lifecycle.setup();
77329 }
77330 },
c58511b9 77331 afterEach : function () {
db71a655
KM
77332 teardownDeprecationHandler(test, moment, 'core');
77333 if (lifecycle && lifecycle.teardown) {
77334 lifecycle.teardown();
77335 }
77336 }
77337 });
77338 }
73f3c911 77339
db71a655 77340 module$1('string prototype');
73f3c911 77341
db71a655
KM
77342 test('string prototype overrides call', function (assert) {
77343 var prior = String.prototype.call, b;
77344 String.prototype.call = function () {
77345 return null;
77346 };
73f3c911 77347
db71a655
KM
77348 b = moment(new Date(2011, 7, 28, 15, 25, 50, 125));
77349 assert.equal(b.format('MMMM Do YYYY, h:mm a'), 'August 28th 2011, 3:25 pm');
73f3c911 77350
db71a655
KM
77351 String.prototype.call = prior;
77352 });
b135bf1a 77353
9483e2a4 77354})));
f2af24d5 77355
9483e2a4
IC
77356
77357;(function (global, factory) {
77358 typeof exports === 'object' && typeof module !== 'undefined'
77359 && typeof require === 'function' ? factory(require('../../moment')) :
77360 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
77361 factory(global.moment)
77362}(this, (function (moment) { 'use strict';
77363
db71a655
KM
77364 function each(array, callback) {
77365 var i;
77366 for (i = 0; i < array.length; i++) {
77367 callback(array[i], i, array);
77368 }
9483e2a4 77369 }
b135bf1a 77370
db71a655
KM
77371 function setupDeprecationHandler(test, moment$$1, scope) {
77372 test._expectedDeprecations = null;
77373 test._observedDeprecations = null;
77374 test._oldSupress = moment$$1.suppressDeprecationWarnings;
77375 moment$$1.suppressDeprecationWarnings = true;
77376 test.expectedDeprecations = function () {
77377 test._expectedDeprecations = arguments;
77378 test._observedDeprecations = [];
77379 };
77380 moment$$1.deprecationHandler = function (name, msg) {
77381 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
77382 if (deprecationId === -1) {
77383 throw new Error('Unexpected deprecation thrown name=' +
77384 name + ' msg=' + msg);
77385 }
77386 test._observedDeprecations[deprecationId] = 1;
77387 };
77388 }
d6651c21 77389
db71a655
KM
77390 function teardownDeprecationHandler(test, moment$$1, scope) {
77391 moment$$1.suppressDeprecationWarnings = test._oldSupress;
d6651c21 77392
db71a655
KM
77393 if (test._expectedDeprecations != null) {
77394 var missedDeprecations = [];
77395 each(test._expectedDeprecations, function (deprecationPattern, id) {
77396 if (test._observedDeprecations[id] !== 1) {
77397 missedDeprecations.push(deprecationPattern);
77398 }
77399 });
77400 if (missedDeprecations.length !== 0) {
77401 throw new Error('Expected deprecation warnings did not happen: ' +
77402 missedDeprecations.join(' '));
d6651c21 77403 }
d6651c21
IC
77404 }
77405 }
77406
db71a655
KM
77407 function matchedDeprecation(name, msg, deprecations) {
77408 if (deprecations == null) {
77409 return -1;
d6651c21 77410 }
db71a655
KM
77411 for (var i = 0; i < deprecations.length; ++i) {
77412 if (name != null && name === deprecations[i]) {
77413 return i;
77414 }
77415 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
77416 return i;
77417 }
d6651c21 77418 }
db71a655 77419 return -1;
b135bf1a
IC
77420 }
77421
db71a655 77422 /*global QUnit:false*/
516f5f67 77423
db71a655 77424 var test = QUnit.test;
c74a101d 77425
db71a655
KM
77426 function module$1 (name, lifecycle) {
77427 QUnit.module(name, {
c58511b9 77428 beforeEach : function () {
db71a655
KM
77429 moment.locale('en');
77430 moment.createFromInputFallback = function (config) {
77431 throw new Error('input not handled by moment: ' + config._i);
77432 };
77433 setupDeprecationHandler(test, moment, 'core');
77434 if (lifecycle && lifecycle.setup) {
77435 lifecycle.setup();
77436 }
77437 },
c58511b9 77438 afterEach : function () {
db71a655
KM
77439 teardownDeprecationHandler(test, moment, 'core');
77440 if (lifecycle && lifecycle.teardown) {
77441 lifecycle.teardown();
77442 }
73f3c911 77443 }
db71a655
KM
77444 });
77445 }
77446
77447 module$1('to type');
77448
77449 test('toObject', function (assert) {
77450 var expected = {
77451 years:2010,
77452 months:3,
77453 date:5,
77454 hours:15,
77455 minutes:10,
77456 seconds:3,
77457 milliseconds:123
77458 };
77459 assert.deepEqual(moment(expected).toObject(), expected, 'toObject invalid');
516f5f67
IC
77460 });
77461
db71a655
KM
77462 test('toArray', function (assert) {
77463 var expected = [2014, 11, 26, 11, 46, 58, 17];
77464 assert.deepEqual(moment(expected).toArray(), expected, 'toArray invalid');
77465 });
516f5f67 77466
db71a655
KM
77467 test('toDate returns a copy of the internal date', function (assert) {
77468 var m = moment();
77469 var d = m.toDate();
77470 m.year(0);
77471 assert.notEqual(d, m.toDate());
77472 });
516f5f67 77473
db71a655
KM
77474 test('toJSON', function (assert) {
77475 if (Date.prototype.toISOString) {
77476 var expected = new Date().toISOString();
77477 assert.deepEqual(moment(expected).toJSON(), expected, 'toJSON invalid');
77478 } else {
77479 // IE8
c58511b9 77480 assert.expect(0);
db71a655
KM
77481 }
77482 });
516f5f67 77483
db71a655
KM
77484 test('toJSON works when moment is frozen', function (assert) {
77485 if (Date.prototype.toISOString) {
77486 var expected = new Date().toISOString();
77487 var m = moment(expected);
77488 if (Object.freeze != null) {
77489 Object.freeze(m);
77490 }
77491 assert.deepEqual(m.toJSON(), expected, 'toJSON when frozen invalid');
77492 } else {
77493 // IE8
c58511b9 77494 assert.expect(0);
db71a655
KM
77495 }
77496 });
516f5f67 77497
73f3c911 77498})));
516f5f67 77499
516f5f67 77500
c74a101d
IC
77501;(function (global, factory) {
77502 typeof exports === 'object' && typeof module !== 'undefined'
77503 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
77504 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
77505 factory(global.moment)
73f3c911 77506}(this, (function (moment) { 'use strict';
516f5f67 77507
db71a655
KM
77508 function each(array, callback) {
77509 var i;
77510 for (i = 0; i < array.length; i++) {
77511 callback(array[i], i, array);
77512 }
b135bf1a
IC
77513 }
77514
db71a655
KM
77515 function setupDeprecationHandler(test, moment$$1, scope) {
77516 test._expectedDeprecations = null;
77517 test._observedDeprecations = null;
77518 test._oldSupress = moment$$1.suppressDeprecationWarnings;
77519 moment$$1.suppressDeprecationWarnings = true;
77520 test.expectedDeprecations = function () {
77521 test._expectedDeprecations = arguments;
77522 test._observedDeprecations = [];
77523 };
77524 moment$$1.deprecationHandler = function (name, msg) {
77525 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
77526 if (deprecationId === -1) {
77527 throw new Error('Unexpected deprecation thrown name=' +
77528 name + ' msg=' + msg);
77529 }
77530 test._observedDeprecations[deprecationId] = 1;
77531 };
77532 }
c74a101d 77533
db71a655
KM
77534 function teardownDeprecationHandler(test, moment$$1, scope) {
77535 moment$$1.suppressDeprecationWarnings = test._oldSupress;
516f5f67 77536
db71a655
KM
77537 if (test._expectedDeprecations != null) {
77538 var missedDeprecations = [];
77539 each(test._expectedDeprecations, function (deprecationPattern, id) {
77540 if (test._observedDeprecations[id] !== 1) {
77541 missedDeprecations.push(deprecationPattern);
77542 }
77543 });
77544 if (missedDeprecations.length !== 0) {
77545 throw new Error('Expected deprecation warnings did not happen: ' +
77546 missedDeprecations.join(' '));
516f5f67 77547 }
b135bf1a
IC
77548 }
77549 }
77550
db71a655
KM
77551 function matchedDeprecation(name, msg, deprecations) {
77552 if (deprecations == null) {
77553 return -1;
b135bf1a 77554 }
db71a655
KM
77555 for (var i = 0; i < deprecations.length; ++i) {
77556 if (name != null && name === deprecations[i]) {
77557 return i;
77558 }
77559 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
77560 return i;
77561 }
b135bf1a 77562 }
db71a655 77563 return -1;
b135bf1a
IC
77564 }
77565
db71a655 77566 /*global QUnit:false*/
b135bf1a 77567
db71a655 77568 var test = QUnit.test;
b135bf1a 77569
db71a655
KM
77570 function module$1 (name, lifecycle) {
77571 QUnit.module(name, {
c58511b9 77572 beforeEach : function () {
db71a655
KM
77573 moment.locale('en');
77574 moment.createFromInputFallback = function (config) {
77575 throw new Error('input not handled by moment: ' + config._i);
77576 };
77577 setupDeprecationHandler(test, moment, 'core');
77578 if (lifecycle && lifecycle.setup) {
77579 lifecycle.setup();
77580 }
77581 },
c58511b9 77582 afterEach : function () {
db71a655
KM
77583 teardownDeprecationHandler(test, moment, 'core');
77584 if (lifecycle && lifecycle.teardown) {
77585 lifecycle.teardown();
77586 }
b135bf1a 77587 }
db71a655
KM
77588 });
77589 }
77590
77591 module$1('utc');
77592
77593 test('utc and local', function (assert) {
77594 var m = moment(Date.UTC(2011, 1, 2, 3, 4, 5, 6)), offset, expected;
77595 m.utc();
77596 // utc
77597 assert.equal(m.date(), 2, 'the day should be correct for utc');
77598 assert.equal(m.day(), 3, 'the date should be correct for utc');
77599 assert.equal(m.hours(), 3, 'the hours should be correct for utc');
77600
77601 // local
77602 m.local();
77603 if (m.utcOffset() < -180) {
77604 assert.equal(m.date(), 1, 'the date should be correct for local');
77605 assert.equal(m.day(), 2, 'the day should be correct for local');
77606 } else {
77607 assert.equal(m.date(), 2, 'the date should be correct for local');
77608 assert.equal(m.day(), 3, 'the day should be correct for local');
77609 }
77610 offset = Math.floor(m.utcOffset() / 60);
77611 expected = (24 + 3 + offset) % 24;
77612 assert.equal(m.hours(), expected, 'the hours (' + m.hours() + ') should be correct for local');
77613 assert.equal(moment().utc().utcOffset(), 0, 'timezone in utc should always be zero');
77614 });
77615
77616 test('creating with utc and no arguments', function (assert) {
77617 var startOfTest = new Date().valueOf(),
77618 momentDefaultUtcTime = moment.utc().valueOf(),
77619 afterMomentCreationTime = new Date().valueOf();
77620
77621 assert.ok(startOfTest <= momentDefaultUtcTime, 'moment UTC default time should be now, not in the past');
77622 assert.ok(momentDefaultUtcTime <= afterMomentCreationTime, 'moment UTC default time should be now, not in the future');
77623 });
77624
77625 test('creating with utc and a date parameter array', function (assert) {
77626 var m = moment.utc([2011, 1, 2, 3, 4, 5, 6]);
77627 assert.equal(m.date(), 2, 'the day should be correct for utc array');
77628 assert.equal(m.hours(), 3, 'the hours should be correct for utc array');
77629
77630 m = moment.utc('2011-02-02 3:04:05', 'YYYY-MM-DD HH:mm:ss');
77631 assert.equal(m.date(), 2, 'the day should be correct for utc parsing format');
77632 assert.equal(m.hours(), 3, 'the hours should be correct for utc parsing format');
77633
77634 m = moment.utc('2011-02-02T03:04:05+00:00');
77635 assert.equal(m.date(), 2, 'the day should be correct for utc parsing iso');
77636 assert.equal(m.hours(), 3, 'the hours should be correct for utc parsing iso');
77637 });
77638
77639 test('creating with utc without timezone', function (assert) {
77640 var m = moment.utc('2012-01-02T08:20:00');
77641 assert.equal(m.date(), 2, 'the day should be correct for utc parse without timezone');
77642 assert.equal(m.hours(), 8, 'the hours should be correct for utc parse without timezone');
77643
77644 m = moment.utc('2012-01-02T08:20:00+09:00');
77645 assert.equal(m.date(), 1, 'the day should be correct for utc parse with timezone');
77646 assert.equal(m.hours(), 23, 'the hours should be correct for utc parse with timezone');
77647 });
77648
77649 test('cloning with utc offset', function (assert) {
77650 var m = moment.utc('2012-01-02T08:20:00');
77651 assert.equal(moment.utc(m)._isUTC, true, 'the local offset should be converted to UTC');
77652 assert.equal(moment.utc(m.clone().utc())._isUTC, true, 'the local offset should stay in UTC');
77653
77654 m.utcOffset(120);
77655 assert.equal(moment.utc(m)._isUTC, true, 'the explicit utc offset should stay in UTC');
77656 assert.equal(moment.utc(m).utcOffset(), 0, 'the explicit utc offset should have an offset of 0');
77657 });
77658
77659 test('weekday with utc', function (assert) {
77660 assert.equal(
77661 moment('2013-09-15T00:00:00Z').utc().weekday(), // first minute of the day
77662 moment('2013-09-15T23:59:00Z').utc().weekday(), // last minute of the day
77663 'a UTC-moment\'s .weekday() should not be affected by the local timezone'
77664 );
77665 });
d6651c21 77666
73f3c911 77667})));
d6651c21 77668
d6651c21 77669
73f3c911
IC
77670;(function (global, factory) {
77671 typeof exports === 'object' && typeof module !== 'undefined'
77672 && typeof require === 'function' ? factory(require('../../moment')) :
77673 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
77674 factory(global.moment)
77675}(this, (function (moment) { 'use strict';
77676
db71a655
KM
77677 function each(array, callback) {
77678 var i;
77679 for (i = 0; i < array.length; i++) {
77680 callback(array[i], i, array);
77681 }
73f3c911 77682 }
73f3c911 77683
db71a655
KM
77684 function setupDeprecationHandler(test, moment$$1, scope) {
77685 test._expectedDeprecations = null;
77686 test._observedDeprecations = null;
77687 test._oldSupress = moment$$1.suppressDeprecationWarnings;
77688 moment$$1.suppressDeprecationWarnings = true;
77689 test.expectedDeprecations = function () {
77690 test._expectedDeprecations = arguments;
77691 test._observedDeprecations = [];
77692 };
77693 moment$$1.deprecationHandler = function (name, msg) {
77694 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
77695 if (deprecationId === -1) {
77696 throw new Error('Unexpected deprecation thrown name=' +
77697 name + ' msg=' + msg);
77698 }
77699 test._observedDeprecations[deprecationId] = 1;
77700 };
77701 }
b135bf1a 77702
db71a655
KM
77703 function teardownDeprecationHandler(test, moment$$1, scope) {
77704 moment$$1.suppressDeprecationWarnings = test._oldSupress;
73f3c911 77705
db71a655
KM
77706 if (test._expectedDeprecations != null) {
77707 var missedDeprecations = [];
77708 each(test._expectedDeprecations, function (deprecationPattern, id) {
77709 if (test._observedDeprecations[id] !== 1) {
77710 missedDeprecations.push(deprecationPattern);
77711 }
77712 });
77713 if (missedDeprecations.length !== 0) {
77714 throw new Error('Expected deprecation warnings did not happen: ' +
77715 missedDeprecations.join(' '));
b135bf1a 77716 }
b135bf1a
IC
77717 }
77718 }
77719
db71a655
KM
77720 function matchedDeprecation(name, msg, deprecations) {
77721 if (deprecations == null) {
77722 return -1;
b135bf1a 77723 }
db71a655
KM
77724 for (var i = 0; i < deprecations.length; ++i) {
77725 if (name != null && name === deprecations[i]) {
77726 return i;
77727 }
77728 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
77729 return i;
77730 }
b135bf1a 77731 }
db71a655 77732 return -1;
b135bf1a
IC
77733 }
77734
db71a655 77735 /*global QUnit:false*/
b135bf1a 77736
db71a655 77737 var test = QUnit.test;
b135bf1a 77738
db71a655
KM
77739 function module$1 (name, lifecycle) {
77740 QUnit.module(name, {
c58511b9 77741 beforeEach : function () {
db71a655
KM
77742 moment.locale('en');
77743 moment.createFromInputFallback = function (config) {
77744 throw new Error('input not handled by moment: ' + config._i);
77745 };
77746 setupDeprecationHandler(test, moment, 'core');
77747 if (lifecycle && lifecycle.setup) {
77748 lifecycle.setup();
77749 }
77750 },
c58511b9 77751 afterEach : function () {
db71a655
KM
77752 teardownDeprecationHandler(test, moment, 'core');
77753 if (lifecycle && lifecycle.teardown) {
77754 lifecycle.teardown();
77755 }
73f3c911 77756 }
db71a655
KM
77757 });
77758 }
b135bf1a 77759
db71a655 77760 module$1('utc offset');
d6651c21 77761
db71a655
KM
77762 test('setter / getter blackbox', function (assert) {
77763 var m = moment([2010]);
d6651c21 77764
db71a655 77765 assert.equal(m.clone().utcOffset(0).utcOffset(), 0, 'utcOffset 0');
d6651c21 77766
db71a655
KM
77767 assert.equal(m.clone().utcOffset(1).utcOffset(), 60, 'utcOffset 1 is 60');
77768 assert.equal(m.clone().utcOffset(60).utcOffset(), 60, 'utcOffset 60');
77769 assert.equal(m.clone().utcOffset('+01:00').utcOffset(), 60, 'utcOffset +01:00 is 60');
77770 assert.equal(m.clone().utcOffset('+0100').utcOffset(), 60, 'utcOffset +0100 is 60');
73f3c911 77771
db71a655
KM
77772 assert.equal(m.clone().utcOffset(-1).utcOffset(), -60, 'utcOffset -1 is -60');
77773 assert.equal(m.clone().utcOffset(-60).utcOffset(), -60, 'utcOffset -60');
77774 assert.equal(m.clone().utcOffset('-01:00').utcOffset(), -60, 'utcOffset -01:00 is -60');
77775 assert.equal(m.clone().utcOffset('-0100').utcOffset(), -60, 'utcOffset -0100 is -60');
d6651c21 77776
db71a655
KM
77777 assert.equal(m.clone().utcOffset(1.5).utcOffset(), 90, 'utcOffset 1.5 is 90');
77778 assert.equal(m.clone().utcOffset(90).utcOffset(), 90, 'utcOffset 1.5 is 90');
77779 assert.equal(m.clone().utcOffset('+01:30').utcOffset(), 90, 'utcOffset +01:30 is 90');
77780 assert.equal(m.clone().utcOffset('+0130').utcOffset(), 90, 'utcOffset +0130 is 90');
d6651c21 77781
db71a655
KM
77782 assert.equal(m.clone().utcOffset(-1.5).utcOffset(), -90, 'utcOffset -1.5');
77783 assert.equal(m.clone().utcOffset(-90).utcOffset(), -90, 'utcOffset -90');
77784 assert.equal(m.clone().utcOffset('-01:30').utcOffset(), -90, 'utcOffset +01:30 is 90');
77785 assert.equal(m.clone().utcOffset('-0130').utcOffset(), -90, 'utcOffset +0130 is 90');
77786 assert.equal(m.clone().utcOffset('+00:10').utcOffset(), 10, 'utcOffset +00:10 is 10');
77787 assert.equal(m.clone().utcOffset('-00:10').utcOffset(), -10, 'utcOffset +00:10 is 10');
77788 assert.equal(m.clone().utcOffset('+0010').utcOffset(), 10, 'utcOffset +0010 is 10');
77789 assert.equal(m.clone().utcOffset('-0010').utcOffset(), -10, 'utcOffset +0010 is 10');
77790 });
d6651c21 77791
db71a655
KM
77792 test('utcOffset shorthand hours -> minutes', function (assert) {
77793 var i;
77794 for (i = -15; i <= 15; ++i) {
77795 assert.equal(moment().utcOffset(i).utcOffset(), i * 60,
77796 '' + i + ' -> ' + i * 60);
77797 }
77798 assert.equal(moment().utcOffset(-16).utcOffset(), -16, '-16 -> -16');
77799 assert.equal(moment().utcOffset(16).utcOffset(), 16, '16 -> 16');
77800 });
b135bf1a 77801
db71a655
KM
77802 test('isLocal, isUtc, isUtcOffset', function (assert) {
77803 assert.ok(moment().isLocal(), 'moment() creates objects in local time');
77804 assert.ok(!moment.utc().isLocal(), 'moment.utc creates objects NOT in local time');
77805 assert.ok(moment.utc().local().isLocal(), 'moment.fn.local() converts to local time');
77806 assert.ok(!moment().utcOffset(5).isLocal(), 'moment.fn.utcOffset(N) puts objects NOT in local time');
77807 assert.ok(moment().utcOffset(5).local().isLocal(), 'moment.fn.local() converts to local time');
516f5f67 77808
db71a655
KM
77809 assert.ok(moment.utc().isUtc(), 'moment.utc() creates objects in utc time');
77810 assert.ok(moment().utcOffset(0).isUtc(), 'utcOffset(0) is equivalent to utc mode');
77811 assert.ok(!moment().utcOffset(1).isUtc(), 'utcOffset(1) is NOT equivalent to utc mode');
516f5f67 77812
db71a655
KM
77813 assert.ok(!moment().isUtcOffset(), 'moment() creates objects NOT in utc-offset mode');
77814 assert.ok(moment.utc().isUtcOffset(), 'moment.utc() creates objects in utc-offset mode');
77815 assert.ok(moment().utcOffset(3).isUtcOffset(), 'utcOffset(N != 0) creates objects in utc-offset mode');
77816 assert.ok(moment().utcOffset(0).isUtcOffset(), 'utcOffset(0) creates objects in utc-offset mode');
77817 });
c74a101d 77818
db71a655
KM
77819 test('isUTC', function (assert) {
77820 assert.ok(moment.utc().isUTC(), 'moment.utc() creates objects in utc time');
77821 assert.ok(moment().utcOffset(0).isUTC(), 'utcOffset(0) is equivalent to utc mode');
77822 assert.ok(!moment().utcOffset(1).isUTC(), 'utcOffset(1) is NOT equivalent to utc mode');
77823 });
516f5f67 77824
db71a655
KM
77825 test('change hours when changing the utc offset', function (assert) {
77826 var m = moment.utc([2000, 0, 1, 6]);
77827 assert.equal(m.hour(), 6, 'UTC 6AM should be 6AM at +0000');
d6651c21 77828
db71a655
KM
77829 // sanity check
77830 m.utcOffset(0);
77831 assert.equal(m.hour(), 6, 'UTC 6AM should be 6AM at +0000');
516f5f67 77832
db71a655
KM
77833 m.utcOffset(-60);
77834 assert.equal(m.hour(), 5, 'UTC 6AM should be 5AM at -0100');
9483e2a4 77835
db71a655
KM
77836 m.utcOffset(60);
77837 assert.equal(m.hour(), 7, 'UTC 6AM should be 7AM at +0100');
77838 });
516f5f67 77839
db71a655
KM
77840 test('change minutes when changing the utc offset', function (assert) {
77841 var m = moment.utc([2000, 0, 1, 6, 31]);
9483e2a4 77842
db71a655
KM
77843 m.utcOffset(0);
77844 assert.equal(m.format('HH:mm'), '06:31', 'UTC 6:31AM should be 6:31AM at +0000');
b135bf1a 77845
db71a655
KM
77846 m.utcOffset(-30);
77847 assert.equal(m.format('HH:mm'), '06:01', 'UTC 6:31AM should be 6:01AM at -0030');
73f3c911 77848
db71a655
KM
77849 m.utcOffset(30);
77850 assert.equal(m.format('HH:mm'), '07:01', 'UTC 6:31AM should be 7:01AM at +0030');
b135bf1a 77851
db71a655
KM
77852 m.utcOffset(-1380);
77853 assert.equal(m.format('HH:mm'), '07:31', 'UTC 6:31AM should be 7:31AM at +1380');
77854 });
b135bf1a 77855
db71a655
KM
77856 test('distance from the unix epoch', function (assert) {
77857 var zoneA = moment(),
77858 zoneB = moment(zoneA),
77859 zoneC = moment(zoneA),
77860 zoneD = moment(zoneA),
77861 zoneE = moment(zoneA);
b135bf1a 77862
db71a655
KM
77863 zoneB.utc();
77864 assert.equal(+zoneA, +zoneB, 'moment should equal moment.utc');
b135bf1a 77865
db71a655
KM
77866 zoneC.utcOffset(60);
77867 assert.equal(+zoneA, +zoneC, 'moment should equal moment.utcOffset(60)');
b135bf1a 77868
db71a655
KM
77869 zoneD.utcOffset(-480);
77870 assert.equal(+zoneA, +zoneD,
77871 'moment should equal moment.utcOffset(-480)');
77872
77873 zoneE.utcOffset(-1000);
77874 assert.equal(+zoneA, +zoneE,
77875 'moment should equal moment.utcOffset(-1000)');
77876 });
77877
77878 test('update offset after changing any values', function (assert) {
77879 var oldOffset = moment.updateOffset,
77880 m = moment.utc([2000, 6, 1]);
77881
77882 moment.updateOffset = function (mom, keepTime) {
77883 if (mom.__doChange) {
77884 if (+mom > 962409600000) {
77885 mom.utcOffset(-120, keepTime);
77886 } else {
77887 mom.utcOffset(-60, keepTime);
77888 }
b135bf1a 77889 }
db71a655 77890 };
9483e2a4 77891
db71a655
KM
77892 assert.equal(m.format('ZZ'), '+0000', 'should be at +0000');
77893 assert.equal(m.format('HH:mm'), '00:00', 'should start 12AM at +0000 timezone');
b135bf1a 77894
db71a655
KM
77895 m.__doChange = true;
77896 m.add(1, 'h');
d6651c21 77897
db71a655
KM
77898 assert.equal(m.format('ZZ'), '-0200', 'should be at -0200');
77899 assert.equal(m.format('HH:mm'), '23:00', '1AM at +0000 should be 11PM at -0200 timezone');
d6651c21 77900
db71a655 77901 m.subtract(1, 'h');
d6651c21 77902
db71a655
KM
77903 assert.equal(m.format('ZZ'), '-0100', 'should be at -0100');
77904 assert.equal(m.format('HH:mm'), '23:00', '12AM at +0000 should be 11PM at -0100 timezone');
d6651c21 77905
db71a655
KM
77906 moment.updateOffset = oldOffset;
77907 });
b135bf1a 77908
db71a655
KM
77909 //////////////////
77910 test('getters and setters', function (assert) {
77911 var a = moment([2011, 5, 20]);
73f3c911 77912
db71a655
KM
77913 assert.equal(a.clone().utcOffset(-120).year(2012).year(), 2012, 'should get and set year correctly');
77914 assert.equal(a.clone().utcOffset(-120).month(1).month(), 1, 'should get and set month correctly');
77915 assert.equal(a.clone().utcOffset(-120).date(2).date(), 2, 'should get and set date correctly');
77916 assert.equal(a.clone().utcOffset(-120).day(1).day(), 1, 'should get and set day correctly');
77917 assert.equal(a.clone().utcOffset(-120).hour(1).hour(), 1, 'should get and set hour correctly');
77918 assert.equal(a.clone().utcOffset(-120).minute(1).minute(), 1, 'should get and set minute correctly');
77919 });
b135bf1a 77920
db71a655
KM
77921 test('getters', function (assert) {
77922 var a = moment.utc([2012, 0, 1, 0, 0, 0]);
b135bf1a 77923
db71a655
KM
77924 assert.equal(a.clone().utcOffset(-120).year(), 2011, 'should get year correctly');
77925 assert.equal(a.clone().utcOffset(-120).month(), 11, 'should get month correctly');
77926 assert.equal(a.clone().utcOffset(-120).date(), 31, 'should get date correctly');
77927 assert.equal(a.clone().utcOffset(-120).hour(), 22, 'should get hour correctly');
77928 assert.equal(a.clone().utcOffset(-120).minute(), 0, 'should get minute correctly');
b135bf1a 77929
db71a655
KM
77930 assert.equal(a.clone().utcOffset(120).year(), 2012, 'should get year correctly');
77931 assert.equal(a.clone().utcOffset(120).month(), 0, 'should get month correctly');
77932 assert.equal(a.clone().utcOffset(120).date(), 1, 'should get date correctly');
77933 assert.equal(a.clone().utcOffset(120).hour(), 2, 'should get hour correctly');
77934 assert.equal(a.clone().utcOffset(120).minute(), 0, 'should get minute correctly');
b135bf1a 77935
db71a655
KM
77936 assert.equal(a.clone().utcOffset(90).year(), 2012, 'should get year correctly');
77937 assert.equal(a.clone().utcOffset(90).month(), 0, 'should get month correctly');
77938 assert.equal(a.clone().utcOffset(90).date(), 1, 'should get date correctly');
77939 assert.equal(a.clone().utcOffset(90).hour(), 1, 'should get hour correctly');
77940 assert.equal(a.clone().utcOffset(90).minute(), 30, 'should get minute correctly');
77941 });
b135bf1a 77942
db71a655
KM
77943 test('from', function (assert) {
77944 var zoneA = moment(),
77945 zoneB = moment(zoneA).utcOffset(-720),
77946 zoneC = moment(zoneA).utcOffset(-360),
77947 zoneD = moment(zoneA).utcOffset(690),
77948 other = moment(zoneA).add(35, 'm');
73f3c911 77949
db71a655
KM
77950 assert.equal(zoneA.from(other), zoneB.from(other), 'moment#from should be the same in all zones');
77951 assert.equal(zoneA.from(other), zoneC.from(other), 'moment#from should be the same in all zones');
77952 assert.equal(zoneA.from(other), zoneD.from(other), 'moment#from should be the same in all zones');
77953 });
d6651c21 77954
db71a655
KM
77955 test('diff', function (assert) {
77956 var zoneA = moment(),
77957 zoneB = moment(zoneA).utcOffset(-720),
77958 zoneC = moment(zoneA).utcOffset(-360),
77959 zoneD = moment(zoneA).utcOffset(690),
77960 other = moment(zoneA).add(35, 'm');
d6651c21 77961
db71a655
KM
77962 assert.equal(zoneA.diff(other), zoneB.diff(other), 'moment#diff should be the same in all zones');
77963 assert.equal(zoneA.diff(other), zoneC.diff(other), 'moment#diff should be the same in all zones');
77964 assert.equal(zoneA.diff(other), zoneD.diff(other), 'moment#diff should be the same in all zones');
d6651c21 77965
db71a655
KM
77966 assert.equal(zoneA.diff(other, 'minute', true), zoneB.diff(other, 'minute', true), 'moment#diff should be the same in all zones');
77967 assert.equal(zoneA.diff(other, 'minute', true), zoneC.diff(other, 'minute', true), 'moment#diff should be the same in all zones');
77968 assert.equal(zoneA.diff(other, 'minute', true), zoneD.diff(other, 'minute', true), 'moment#diff should be the same in all zones');
d6651c21 77969
db71a655
KM
77970 assert.equal(zoneA.diff(other, 'hour', true), zoneB.diff(other, 'hour', true), 'moment#diff should be the same in all zones');
77971 assert.equal(zoneA.diff(other, 'hour', true), zoneC.diff(other, 'hour', true), 'moment#diff should be the same in all zones');
77972 assert.equal(zoneA.diff(other, 'hour', true), zoneD.diff(other, 'hour', true), 'moment#diff should be the same in all zones');
77973 });
d6651c21 77974
db71a655
KM
77975 test('unix offset and timestamp', function (assert) {
77976 var zoneA = moment(),
77977 zoneB = moment(zoneA).utcOffset(-720),
77978 zoneC = moment(zoneA).utcOffset(-360),
77979 zoneD = moment(zoneA).utcOffset(690);
b135bf1a 77980
db71a655
KM
77981 assert.equal(zoneA.unix(), zoneB.unix(), 'moment#unix should be the same in all zones');
77982 assert.equal(zoneA.unix(), zoneC.unix(), 'moment#unix should be the same in all zones');
77983 assert.equal(zoneA.unix(), zoneD.unix(), 'moment#unix should be the same in all zones');
1d986a17 77984
db71a655
KM
77985 assert.equal(+zoneA, +zoneB, 'moment#valueOf should be the same in all zones');
77986 assert.equal(+zoneA, +zoneC, 'moment#valueOf should be the same in all zones');
77987 assert.equal(+zoneA, +zoneD, 'moment#valueOf should be the same in all zones');
77988 });
1d986a17 77989
db71a655
KM
77990 test('cloning', function (assert) {
77991 assert.equal(moment().utcOffset(-120).clone().utcOffset(), -120,
77992 'explicit cloning should retain the offset');
77993 assert.equal(moment().utcOffset(120).clone().utcOffset(), 120,
77994 'explicit cloning should retain the offset');
77995 assert.equal(moment(moment().utcOffset(-120)).utcOffset(), -120,
77996 'implicit cloning should retain the offset');
77997 assert.equal(moment(moment().utcOffset(120)).utcOffset(), 120,
77998 'implicit cloning should retain the offset');
77999 });
c74a101d 78000
db71a655
KM
78001 test('start of / end of', function (assert) {
78002 var a = moment.utc([2010, 1, 2, 0, 0, 0]).utcOffset(-450);
73f3c911 78003
db71a655
KM
78004 assert.equal(a.clone().startOf('day').hour(), 0,
78005 'start of day should work on moments with utc offset');
78006 assert.equal(a.clone().startOf('day').minute(), 0,
78007 'start of day should work on moments with utc offset');
78008 assert.equal(a.clone().startOf('hour').minute(), 0,
78009 'start of hour should work on moments with utc offset');
1d986a17 78010
db71a655
KM
78011 assert.equal(a.clone().endOf('day').hour(), 23,
78012 'end of day should work on moments with utc offset');
78013 assert.equal(a.clone().endOf('day').minute(), 59,
78014 'end of day should work on moments with utc offset');
78015 assert.equal(a.clone().endOf('hour').minute(), 59,
78016 'end of hour should work on moments with utc offset');
78017 });
1d986a17 78018
db71a655
KM
78019 test('reset offset with moment#utc', function (assert) {
78020 var a = moment.utc([2012]).utcOffset(-480);
b135bf1a 78021
db71a655
KM
78022 assert.equal(a.clone().hour(), 16, 'different utc offset should have different hour');
78023 assert.equal(a.clone().utc().hour(), 0, 'calling moment#utc should reset the offset');
78024 });
73f3c911 78025
db71a655
KM
78026 test('reset offset with moment#local', function (assert) {
78027 var a = moment([2012]).utcOffset(-480);
b135bf1a 78028
db71a655
KM
78029 assert.equal(a.clone().local().hour(), 0, 'calling moment#local should reset the offset');
78030 });
b135bf1a 78031
db71a655
KM
78032 test('toDate', function (assert) {
78033 var zoneA = new Date(),
78034 zoneB = moment(zoneA).utcOffset(-720).toDate(),
78035 zoneC = moment(zoneA).utcOffset(-360).toDate(),
78036 zoneD = moment(zoneA).utcOffset(690).toDate();
b135bf1a 78037
db71a655
KM
78038 assert.equal(+zoneA, +zoneB, 'moment#toDate should output a date with the right unix timestamp');
78039 assert.equal(+zoneA, +zoneC, 'moment#toDate should output a date with the right unix timestamp');
78040 assert.equal(+zoneA, +zoneD, 'moment#toDate should output a date with the right unix timestamp');
78041 });
b135bf1a 78042
db71a655
KM
78043 test('same / before / after', function (assert) {
78044 var zoneA = moment().utc(),
78045 zoneB = moment(zoneA).utcOffset(-120),
78046 zoneC = moment(zoneA).utcOffset(120);
b135bf1a 78047
db71a655
KM
78048 assert.ok(zoneA.isSame(zoneB), 'two moments with different offsets should be the same');
78049 assert.ok(zoneA.isSame(zoneC), 'two moments with different offsets should be the same');
73f3c911 78050
db71a655
KM
78051 assert.ok(zoneA.isSame(zoneB, 'hour'), 'two moments with different offsets should be the same hour');
78052 assert.ok(zoneA.isSame(zoneC, 'hour'), 'two moments with different offsets should be the same hour');
b135bf1a 78053
db71a655 78054 zoneA.add(1, 'hour');
d6651c21 78055
db71a655
KM
78056 assert.ok(zoneA.isAfter(zoneB), 'isAfter should work with two moments with different offsets');
78057 assert.ok(zoneA.isAfter(zoneC), 'isAfter should work with two moments with different offsets');
d6651c21 78058
db71a655
KM
78059 assert.ok(zoneA.isAfter(zoneB, 'hour'), 'isAfter:hour should work with two moments with different offsets');
78060 assert.ok(zoneA.isAfter(zoneC, 'hour'), 'isAfter:hour should work with two moments with different offsets');
d6651c21 78061
db71a655 78062 zoneA.subtract(2, 'hour');
d6651c21 78063
db71a655
KM
78064 assert.ok(zoneA.isBefore(zoneB), 'isBefore should work with two moments with different offsets');
78065 assert.ok(zoneA.isBefore(zoneC), 'isBefore should work with two moments with different offsets');
516f5f67 78066
db71a655
KM
78067 assert.ok(zoneA.isBefore(zoneB, 'hour'), 'isBefore:hour should work with two moments with different offsets');
78068 assert.ok(zoneA.isBefore(zoneC, 'hour'), 'isBefore:hour should work with two moments with different offsets');
78069 });
516f5f67 78070
db71a655
KM
78071 test('add / subtract over dst', function (assert) {
78072 var oldOffset = moment.updateOffset,
78073 m = moment.utc([2000, 2, 31, 3]);
516f5f67 78074
db71a655
KM
78075 moment.updateOffset = function (mom, keepTime) {
78076 if (mom.clone().utc().month() > 2) {
78077 mom.utcOffset(60, keepTime);
78078 } else {
78079 mom.utcOffset(0, keepTime);
78080 }
78081 };
516f5f67 78082
db71a655 78083 assert.equal(m.hour(), 3, 'should start at 00:00');
516f5f67 78084
db71a655 78085 m.add(24, 'hour');
516f5f67 78086
db71a655 78087 assert.equal(m.hour(), 4, 'adding 24 hours should disregard dst');
516f5f67 78088
db71a655 78089 m.subtract(24, 'hour');
73f3c911 78090
db71a655 78091 assert.equal(m.hour(), 3, 'subtracting 24 hours should disregard dst');
73f3c911 78092
db71a655 78093 m.add(1, 'day');
73f3c911 78094
db71a655 78095 assert.equal(m.hour(), 3, 'adding 1 day should have the same hour');
73f3c911 78096
db71a655 78097 m.subtract(1, 'day');
73f3c911 78098
db71a655 78099 assert.equal(m.hour(), 3, 'subtracting 1 day should have the same hour');
73f3c911 78100
db71a655 78101 m.add(1, 'month');
73f3c911 78102
db71a655 78103 assert.equal(m.hour(), 3, 'adding 1 month should have the same hour');
516f5f67 78104
db71a655 78105 m.subtract(1, 'month');
516f5f67 78106
db71a655 78107 assert.equal(m.hour(), 3, 'subtracting 1 month should have the same hour');
516f5f67 78108
db71a655
KM
78109 moment.updateOffset = oldOffset;
78110 });
b135bf1a 78111
db71a655
KM
78112 test('isDST', function (assert) {
78113 var oldOffset = moment.updateOffset;
b135bf1a 78114
db71a655
KM
78115 moment.updateOffset = function (mom, keepTime) {
78116 if (mom.month() > 2 && mom.month() < 9) {
78117 mom.utcOffset(60, keepTime);
78118 } else {
78119 mom.utcOffset(0, keepTime);
78120 }
78121 };
516f5f67 78122
db71a655
KM
78123 assert.ok(!moment().month(0).isDST(), 'Jan should not be summer dst');
78124 assert.ok(moment().month(6).isDST(), 'Jul should be summer dst');
78125 assert.ok(!moment().month(11).isDST(), 'Dec should not be summer dst');
c74a101d 78126
db71a655
KM
78127 moment.updateOffset = function (mom) {
78128 if (mom.month() > 2 && mom.month() < 9) {
78129 mom.utcOffset(0);
78130 } else {
78131 mom.utcOffset(60);
516f5f67 78132 }
db71a655 78133 };
516f5f67 78134
db71a655
KM
78135 assert.ok(moment().month(0).isDST(), 'Jan should be winter dst');
78136 assert.ok(!moment().month(6).isDST(), 'Jul should not be winter dst');
78137 assert.ok(moment().month(11).isDST(), 'Dec should be winter dst');
516f5f67 78138
db71a655
KM
78139 moment.updateOffset = oldOffset;
78140 });
516f5f67 78141
db71a655
KM
78142 test('zone names', function (assert) {
78143 assert.equal(moment().zoneAbbr(), '', 'Local zone abbr should be empty');
78144 assert.equal(moment().format('z'), '', 'Local zone formatted abbr should be empty');
78145 assert.equal(moment().zoneName(), '', 'Local zone name should be empty');
78146 assert.equal(moment().format('zz'), '', 'Local zone formatted name should be empty');
516f5f67 78147
db71a655
KM
78148 assert.equal(moment.utc().zoneAbbr(), 'UTC', 'UTC zone abbr should be UTC');
78149 assert.equal(moment.utc().format('z'), 'UTC', 'UTC zone formatted abbr should be UTC');
78150 assert.equal(moment.utc().zoneName(), 'Coordinated Universal Time', 'UTC zone abbr should be Coordinated Universal Time');
78151 assert.equal(moment.utc().format('zz'), 'Coordinated Universal Time', 'UTC zone formatted abbr should be Coordinated Universal Time');
78152 });
516f5f67 78153
db71a655
KM
78154 test('hours alignment with UTC', function (assert) {
78155 assert.equal(moment().utcOffset(-120).hasAlignedHourOffset(), true);
78156 assert.equal(moment().utcOffset(180).hasAlignedHourOffset(), true);
78157 assert.equal(moment().utcOffset(-90).hasAlignedHourOffset(), false);
78158 assert.equal(moment().utcOffset(90).hasAlignedHourOffset(), false);
78159 });
516f5f67 78160
db71a655
KM
78161 test('hours alignment with other zone', function (assert) {
78162 var m = moment().utcOffset(-120);
516f5f67 78163
db71a655
KM
78164 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(-180)), true);
78165 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(180)), true);
78166 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(-90)), false);
78167 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(90)), false);
516f5f67 78168
db71a655 78169 m = moment().utcOffset(-90);
516f5f67 78170
db71a655
KM
78171 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(-180)), false);
78172 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(180)), false);
78173 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(-30)), true);
78174 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(30)), true);
516f5f67 78175
db71a655 78176 m = moment().utcOffset(60);
516f5f67 78177
db71a655
KM
78178 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(-180)), true);
78179 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(180)), true);
78180 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(-90)), false);
78181 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(90)), false);
516f5f67 78182
db71a655 78183 m = moment().utcOffset(-25);
516f5f67 78184
db71a655
KM
78185 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(35)), true);
78186 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(-85)), true);
516f5f67 78187
db71a655
KM
78188 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(-35)), false);
78189 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(85)), false);
78190 });
78191
78192 test('parse zone', function (assert) {
78193 var m = moment('2013-01-01T00:00:00-13:00').parseZone();
78194 assert.equal(m.utcOffset(), -13 * 60);
78195 assert.equal(m.hours(), 0);
78196 });
78197
78198 test('parse UTC zone', function (assert) {
78199 var m = moment('2013-01-01T05:00:00+00:00').parseZone();
78200 assert.equal(m.utcOffset(), 0);
78201 assert.equal(m.hours(), 5);
78202 });
78203
78204 test('parse zone static', function (assert) {
78205 var m = moment.parseZone('2013-01-01T00:00:00-13:00');
78206 assert.equal(m.utcOffset(), -13 * 60);
78207 assert.equal(m.hours(), 0);
78208 });
516f5f67 78209
db71a655
KM
78210 test('parse zone with more arguments', function (assert) {
78211 var m;
78212 m = moment.parseZone('2013 01 01 05 -13:00', 'YYYY MM DD HH ZZ');
78213 assert.equal(m.format(), '2013-01-01T05:00:00-13:00', 'accept input and format');
78214 m = moment.parseZone('2013-01-01-13:00', 'YYYY MM DD ZZ', true);
78215 assert.equal(m.isValid(), false, 'accept input, format and strict flag');
78216 m = moment.parseZone('2013-01-01-13:00', ['DD MM YYYY ZZ', 'YYYY MM DD ZZ']);
78217 assert.equal(m.format(), '2013-01-01T00:00:00-13:00', 'accept input and array of formats');
78218 });
516f5f67 78219
db71a655
KM
78220 test('parse zone with a timezone from the format string', function (assert) {
78221 var m = moment('11-12-2013 -0400 +1100', 'DD-MM-YYYY ZZ #####').parseZone();
516f5f67 78222
db71a655
KM
78223 assert.equal(m.utcOffset(), -4 * 60);
78224 });
516f5f67 78225
db71a655
KM
78226 test('parse zone without a timezone included in the format string', function (assert) {
78227 var m = moment('11-12-2013 -0400 +1100', 'DD-MM-YYYY').parseZone();
516f5f67 78228
db71a655
KM
78229 assert.equal(m.utcOffset(), 11 * 60);
78230 });
516f5f67 78231
db71a655
KM
78232 test('timezone format', function (assert) {
78233 assert.equal(moment().utcOffset(60).format('ZZ'), '+0100', '-60 -> +0100');
78234 assert.equal(moment().utcOffset(90).format('ZZ'), '+0130', '-90 -> +0130');
78235 assert.equal(moment().utcOffset(120).format('ZZ'), '+0200', '-120 -> +0200');
516f5f67 78236
db71a655
KM
78237 assert.equal(moment().utcOffset(-60).format('ZZ'), '-0100', '+60 -> -0100');
78238 assert.equal(moment().utcOffset(-90).format('ZZ'), '-0130', '+90 -> -0130');
78239 assert.equal(moment().utcOffset(-120).format('ZZ'), '-0200', '+120 -> -0200');
78240 });
f2af24d5 78241
9483e2a4 78242})));
f2af24d5 78243
9483e2a4
IC
78244
78245;(function (global, factory) {
78246 typeof exports === 'object' && typeof module !== 'undefined'
78247 && typeof require === 'function' ? factory(require('../../moment')) :
78248 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
78249 factory(global.moment)
78250}(this, (function (moment) { 'use strict';
78251
db71a655
KM
78252 function each(array, callback) {
78253 var i;
78254 for (i = 0; i < array.length; i++) {
78255 callback(array[i], i, array);
78256 }
9483e2a4 78257 }
f2af24d5 78258
db71a655
KM
78259 function setupDeprecationHandler(test, moment$$1, scope) {
78260 test._expectedDeprecations = null;
78261 test._observedDeprecations = null;
78262 test._oldSupress = moment$$1.suppressDeprecationWarnings;
78263 moment$$1.suppressDeprecationWarnings = true;
78264 test.expectedDeprecations = function () {
78265 test._expectedDeprecations = arguments;
78266 test._observedDeprecations = [];
78267 };
78268 moment$$1.deprecationHandler = function (name, msg) {
78269 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
78270 if (deprecationId === -1) {
78271 throw new Error('Unexpected deprecation thrown name=' +
78272 name + ' msg=' + msg);
78273 }
78274 test._observedDeprecations[deprecationId] = 1;
78275 };
78276 }
f2af24d5 78277
db71a655
KM
78278 function teardownDeprecationHandler(test, moment$$1, scope) {
78279 moment$$1.suppressDeprecationWarnings = test._oldSupress;
f2af24d5 78280
db71a655
KM
78281 if (test._expectedDeprecations != null) {
78282 var missedDeprecations = [];
78283 each(test._expectedDeprecations, function (deprecationPattern, id) {
78284 if (test._observedDeprecations[id] !== 1) {
78285 missedDeprecations.push(deprecationPattern);
78286 }
78287 });
78288 if (missedDeprecations.length !== 0) {
78289 throw new Error('Expected deprecation warnings did not happen: ' +
78290 missedDeprecations.join(' '));
f2af24d5 78291 }
f2af24d5
IC
78292 }
78293 }
f2af24d5 78294
db71a655
KM
78295 function matchedDeprecation(name, msg, deprecations) {
78296 if (deprecations == null) {
78297 return -1;
f2af24d5 78298 }
db71a655
KM
78299 for (var i = 0; i < deprecations.length; ++i) {
78300 if (name != null && name === deprecations[i]) {
78301 return i;
78302 }
78303 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
78304 return i;
78305 }
f2af24d5 78306 }
db71a655 78307 return -1;
f2af24d5 78308 }
f2af24d5 78309
db71a655 78310 /*global QUnit:false*/
f2af24d5 78311
db71a655 78312 var test = QUnit.test;
f2af24d5 78313
db71a655
KM
78314 function module$1 (name, lifecycle) {
78315 QUnit.module(name, {
c58511b9 78316 beforeEach : function () {
db71a655
KM
78317 moment.locale('en');
78318 moment.createFromInputFallback = function (config) {
78319 throw new Error('input not handled by moment: ' + config._i);
78320 };
78321 setupDeprecationHandler(test, moment, 'core');
78322 if (lifecycle && lifecycle.setup) {
78323 lifecycle.setup();
78324 }
78325 },
c58511b9 78326 afterEach : function () {
db71a655
KM
78327 teardownDeprecationHandler(test, moment, 'core');
78328 if (lifecycle && lifecycle.teardown) {
78329 lifecycle.teardown();
78330 }
f2af24d5 78331 }
db71a655
KM
78332 });
78333 }
78334
78335 module$1('week year');
78336
78337 test('iso week year', function (assert) {
78338 // Some examples taken from https://en.wikipedia.org/wiki/ISO_week
78339 assert.equal(moment([2005, 0, 1]).isoWeekYear(), 2004);
78340 assert.equal(moment([2005, 0, 2]).isoWeekYear(), 2004);
78341 assert.equal(moment([2005, 0, 3]).isoWeekYear(), 2005);
78342 assert.equal(moment([2005, 11, 31]).isoWeekYear(), 2005);
78343 assert.equal(moment([2006, 0, 1]).isoWeekYear(), 2005);
78344 assert.equal(moment([2006, 0, 2]).isoWeekYear(), 2006);
78345 assert.equal(moment([2007, 0, 1]).isoWeekYear(), 2007);
78346 assert.equal(moment([2007, 11, 30]).isoWeekYear(), 2007);
78347 assert.equal(moment([2007, 11, 31]).isoWeekYear(), 2008);
78348 assert.equal(moment([2008, 0, 1]).isoWeekYear(), 2008);
78349 assert.equal(moment([2008, 11, 28]).isoWeekYear(), 2008);
78350 assert.equal(moment([2008, 11, 29]).isoWeekYear(), 2009);
78351 assert.equal(moment([2008, 11, 30]).isoWeekYear(), 2009);
78352 assert.equal(moment([2008, 11, 31]).isoWeekYear(), 2009);
78353 assert.equal(moment([2009, 0, 1]).isoWeekYear(), 2009);
78354 assert.equal(moment([2010, 0, 1]).isoWeekYear(), 2009);
78355 assert.equal(moment([2010, 0, 2]).isoWeekYear(), 2009);
78356 assert.equal(moment([2010, 0, 3]).isoWeekYear(), 2009);
78357 assert.equal(moment([2010, 0, 4]).isoWeekYear(), 2010);
78358 });
78359
78360 test('week year', function (assert) {
78361 // Some examples taken from https://en.wikipedia.org/wiki/ISO_week
78362 moment.locale('dow: 1,doy: 4', {week: {dow: 1, doy: 4}}); // like iso
78363 assert.equal(moment([2005, 0, 1]).weekYear(), 2004);
78364 assert.equal(moment([2005, 0, 2]).weekYear(), 2004);
78365 assert.equal(moment([2005, 0, 3]).weekYear(), 2005);
78366 assert.equal(moment([2005, 11, 31]).weekYear(), 2005);
78367 assert.equal(moment([2006, 0, 1]).weekYear(), 2005);
78368 assert.equal(moment([2006, 0, 2]).weekYear(), 2006);
78369 assert.equal(moment([2007, 0, 1]).weekYear(), 2007);
78370 assert.equal(moment([2007, 11, 30]).weekYear(), 2007);
78371 assert.equal(moment([2007, 11, 31]).weekYear(), 2008);
78372 assert.equal(moment([2008, 0, 1]).weekYear(), 2008);
78373 assert.equal(moment([2008, 11, 28]).weekYear(), 2008);
78374 assert.equal(moment([2008, 11, 29]).weekYear(), 2009);
78375 assert.equal(moment([2008, 11, 30]).weekYear(), 2009);
78376 assert.equal(moment([2008, 11, 31]).weekYear(), 2009);
78377 assert.equal(moment([2009, 0, 1]).weekYear(), 2009);
78378 assert.equal(moment([2010, 0, 1]).weekYear(), 2009);
78379 assert.equal(moment([2010, 0, 2]).weekYear(), 2009);
78380 assert.equal(moment([2010, 0, 3]).weekYear(), 2009);
78381 assert.equal(moment([2010, 0, 4]).weekYear(), 2010);
78382
78383 moment.locale('dow: 1,doy: 7', {week: {dow: 1, doy: 7}});
78384 assert.equal(moment([2004, 11, 26]).weekYear(), 2004);
78385 assert.equal(moment([2004, 11, 27]).weekYear(), 2005);
78386 assert.equal(moment([2005, 11, 25]).weekYear(), 2005);
78387 assert.equal(moment([2005, 11, 26]).weekYear(), 2006);
78388 assert.equal(moment([2006, 11, 31]).weekYear(), 2006);
78389 assert.equal(moment([2007, 0, 1]).weekYear(), 2007);
78390 assert.equal(moment([2007, 11, 30]).weekYear(), 2007);
78391 assert.equal(moment([2007, 11, 31]).weekYear(), 2008);
78392 assert.equal(moment([2008, 11, 28]).weekYear(), 2008);
78393 assert.equal(moment([2008, 11, 29]).weekYear(), 2009);
78394 assert.equal(moment([2009, 11, 27]).weekYear(), 2009);
78395 assert.equal(moment([2009, 11, 28]).weekYear(), 2010);
78396 });
78397
78398 // Verifies that the week number, week day computation is correct for all dow, doy combinations
78399 test('week year roundtrip', function (assert) {
78400 var dow, doy, wd, m, localeName;
78401 for (dow = 0; dow < 7; ++dow) {
78402 for (doy = dow; doy < dow + 7; ++doy) {
78403 for (wd = 0; wd < 7; ++wd) {
78404 localeName = 'dow: ' + dow + ', doy: ' + doy;
78405 moment.locale(localeName, {week: {dow: dow, doy: doy}});
78406 // We use the 10th week as the 1st one can spill to the previous year
78407 m = moment('2015 10 ' + wd, 'gggg w d', true);
78408 assert.equal(m.format('gggg w d'), '2015 10 ' + wd, 'dow: ' + dow + ' doy: ' + doy + ' wd: ' + wd);
78409 m = moment('2015 10 ' + wd, 'gggg w e', true);
78410 assert.equal(m.format('gggg w e'), '2015 10 ' + wd, 'dow: ' + dow + ' doy: ' + doy + ' wd: ' + wd);
78411 moment.defineLocale(localeName, null);
78412 }
f2af24d5
IC
78413 }
78414 }
78415 });
f2af24d5 78416
db71a655
KM
78417 test('week numbers 2012/2013', function (assert) {
78418 moment.locale('dow: 6, doy: 12', {week: {dow: 6, doy: 12}});
78419 assert.equal(52, moment('2012-12-28', 'YYYY-MM-DD').week(), '2012-12-28 is week 52'); // 51 -- should be 52?
78420 assert.equal(1, moment('2012-12-29', 'YYYY-MM-DD').week(), '2012-12-29 is week 1'); // 52 -- should be 1
78421 assert.equal(1, moment('2013-01-01', 'YYYY-MM-DD').week(), '2013-01-01 is week 1'); // 52 -- should be 1
78422 assert.equal(2, moment('2013-01-08', 'YYYY-MM-DD').week(), '2013-01-08 is week 2'); // 53 -- should be 2
78423 assert.equal(2, moment('2013-01-11', 'YYYY-MM-DD').week(), '2013-01-11 is week 2'); // 53 -- should be 2
78424 assert.equal(3, moment('2013-01-12', 'YYYY-MM-DD').week(), '2013-01-12 is week 3'); // 1 -- should be 3
78425 assert.equal(52, moment('2012-01-01', 'YYYY-MM-DD').weeksInYear(), 'weeks in 2012 are 52'); // 52
78426 moment.defineLocale('dow: 6, doy: 12', null);
78427 });
78428
78429 test('weeks numbers dow:1 doy:4', function (assert) {
78430 moment.locale('dow: 1, doy: 4', {week: {dow: 1, doy: 4}});
78431 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52');
78432 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1');
78433 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1');
78434 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2');
78435 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2');
78436 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
78437 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
78438 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
78439 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
78440 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
78441 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
78442 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
78443 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
78444 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
78445 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
78446 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
78447 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
78448 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
78449 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
78450 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
78451 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
78452 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
78453 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
78454 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
78455 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
78456 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
78457 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
78458 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3');
78459 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53');
78460 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53');
78461 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53');
78462 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1');
78463 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1');
78464 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2');
78465 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52');
78466 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52');
78467 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52');
78468 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1');
78469 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1');
78470 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2');
78471 moment.defineLocale('dow: 1, doy: 4', null);
78472 });
78473
78474 test('weeks numbers dow:6 doy:12', function (assert) {
78475 moment.locale('dow: 6, doy: 12', {week: {dow: 6, doy: 12}});
78476 assert.equal(moment([2011, 11, 31]).week(), 1, 'Dec 31 2011 should be week 1');
78477 assert.equal(moment([2012, 0, 6]).week(), 1, 'Jan 6 2012 should be week 1');
78478 assert.equal(moment([2012, 0, 7]).week(), 2, 'Jan 7 2012 should be week 2');
78479 assert.equal(moment([2012, 0, 13]).week(), 2, 'Jan 13 2012 should be week 2');
78480 assert.equal(moment([2012, 0, 14]).week(), 3, 'Jan 14 2012 should be week 3');
78481 assert.equal(moment([2006, 11, 30]).week(), 1, 'Dec 30 2006 should be week 1');
78482 assert.equal(moment([2007, 0, 5]).week(), 1, 'Jan 5 2007 should be week 1');
78483 assert.equal(moment([2007, 0, 6]).week(), 2, 'Jan 6 2007 should be week 2');
78484 assert.equal(moment([2007, 0, 12]).week(), 2, 'Jan 12 2007 should be week 2');
78485 assert.equal(moment([2007, 0, 13]).week(), 3, 'Jan 13 2007 should be week 3');
78486 assert.equal(moment([2007, 11, 29]).week(), 1, 'Dec 29 2007 should be week 1');
78487 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
78488 assert.equal(moment([2008, 0, 4]).week(), 1, 'Jan 4 2008 should be week 1');
78489 assert.equal(moment([2008, 0, 5]).week(), 2, 'Jan 5 2008 should be week 2');
78490 assert.equal(moment([2008, 0, 11]).week(), 2, 'Jan 11 2008 should be week 2');
78491 assert.equal(moment([2008, 0, 12]).week(), 3, 'Jan 12 2008 should be week 3');
78492 assert.equal(moment([2002, 11, 28]).week(), 1, 'Dec 28 2002 should be week 1');
78493 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
78494 assert.equal(moment([2003, 0, 3]).week(), 1, 'Jan 3 2003 should be week 1');
78495 assert.equal(moment([2003, 0, 4]).week(), 2, 'Jan 4 2003 should be week 2');
78496 assert.equal(moment([2003, 0, 10]).week(), 2, 'Jan 10 2003 should be week 2');
78497 assert.equal(moment([2003, 0, 11]).week(), 3, 'Jan 11 2003 should be week 3');
78498 assert.equal(moment([2008, 11, 27]).week(), 1, 'Dec 27 2008 should be week 1');
78499 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
78500 assert.equal(moment([2009, 0, 2]).week(), 1, 'Jan 2 2009 should be week 1');
78501 assert.equal(moment([2009, 0, 3]).week(), 2, 'Jan 3 2009 should be week 2');
78502 assert.equal(moment([2009, 0, 9]).week(), 2, 'Jan 9 2009 should be week 2');
78503 assert.equal(moment([2009, 0, 10]).week(), 3, 'Jan 10 2009 should be week 3');
78504 assert.equal(moment([2009, 11, 26]).week(), 1, 'Dec 26 2009 should be week 1');
78505 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
78506 assert.equal(moment([2010, 0, 2]).week(), 2, 'Jan 2 2010 should be week 2');
78507 assert.equal(moment([2010, 0, 8]).week(), 2, 'Jan 8 2010 should be week 2');
78508 assert.equal(moment([2010, 0, 9]).week(), 3, 'Jan 9 2010 should be week 3');
78509 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
78510 assert.equal(moment([2011, 0, 7]).week(), 1, 'Jan 7 2011 should be week 1');
78511 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
78512 assert.equal(moment([2011, 0, 14]).week(), 2, 'Jan 14 2011 should be week 2');
78513 assert.equal(moment([2011, 0, 15]).week(), 3, 'Jan 15 2011 should be week 3');
78514 moment.defineLocale('dow: 6, doy: 12', null);
78515 });
78516
78517 test('weeks numbers dow:1 doy:7', function (assert) {
78518 moment.locale('dow: 1, doy: 7', {week: {dow: 1, doy: 7}});
78519 assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1');
78520 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
78521 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2');
78522 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
78523 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3');
78524 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
78525 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1');
78526 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2');
78527 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2');
78528 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3');
78529 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1');
78530 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
78531 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1');
78532 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2');
78533 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2');
78534 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3');
78535 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1');
78536 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
78537 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1');
78538 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2');
78539 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2');
78540 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3');
78541 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1');
78542 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
78543 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1');
78544 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2');
78545 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2');
78546 assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3');
78547 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1');
78548 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
78549 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1');
78550 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2');
78551 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2');
78552 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3');
78553 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1');
78554 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
78555 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1');
78556 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2');
78557 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2');
78558 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3');
78559 moment.defineLocale('dow: 1, doy: 7', null);
78560 });
78561
78562 test('weeks numbers dow:0 doy:6', function (assert) {
78563 moment.locale('dow: 0, doy: 6', {week: {dow: 0, doy: 6}});
78564 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1');
78565 assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1');
78566 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2');
78567 assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2');
78568 assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3');
78569 assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1');
78570 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1');
78571 assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1');
78572 assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2');
78573 assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2');
78574 assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3');
78575 assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52');
78576 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1');
78577 assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1');
78578 assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2');
78579 assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2');
78580 assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3');
78581 assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1');
78582 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1');
78583 assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1');
78584 assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2');
78585 assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2');
78586 assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3');
78587 assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1');
78588 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1');
78589 assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1');
78590 assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2');
78591 assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2');
78592 assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3');
78593 assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1');
78594 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1');
78595 assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1');
78596 assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2');
78597 assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2');
78598 assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3');
78599 assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1');
78600 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1');
78601 assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2');
78602 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2');
78603 assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3');
78604 moment.defineLocale('dow: 0, doy: 6', null);
78605 });
78606
78607 test('week year overflows', function (assert) {
78608 assert.equal('2005-01-01', moment.utc('2004-W53-6', moment.ISO_8601, true).format('YYYY-MM-DD'), '2004-W53-6 is 1st Jan 2005');
78609 assert.equal('2007-12-31', moment.utc('2008-W01-1', moment.ISO_8601, true).format('YYYY-MM-DD'), '2008-W01-1 is 31st Dec 2007');
78610 });
78611
78612 test('weeks overflow', function (assert) {
78613 assert.equal(7, moment.utc('2004-W54-1', moment.ISO_8601, true).parsingFlags().overflow, '2004 has only 53 weeks');
78614 assert.equal(7, moment.utc('2004-W00-1', moment.ISO_8601, true).parsingFlags().overflow, 'there is no 0th week');
78615 });
78616
78617 test('weekday overflow', function (assert) {
78618 assert.equal(8, moment.utc('2004-W30-0', moment.ISO_8601, true).parsingFlags().overflow, 'there is no 0 iso weekday');
78619 assert.equal(8, moment.utc('2004-W30-8', moment.ISO_8601, true).parsingFlags().overflow, 'there is no 8 iso weekday');
78620 assert.equal(8, moment.utc('2004-w30-7', 'gggg-[w]ww-e', true).parsingFlags().overflow, 'there is no 7 \'e\' weekday');
78621 assert.equal(8, moment.utc('2004-w30-7', 'gggg-[w]ww-d', true).parsingFlags().overflow, 'there is no 7 \'d\' weekday');
78622 });
78623
78624 test('week year setter works', function (assert) {
78625 for (var year = 2000; year <= 2020; year += 1) {
78626 assert.equal(moment.utc('2012-12-31T00:00:00.000Z').isoWeekYear(year).isoWeekYear(), year, 'setting iso-week-year to ' + year);
78627 assert.equal(moment.utc('2012-12-31T00:00:00.000Z').weekYear(year).weekYear(), year, 'setting week-year to ' + year);
78628 }
78629
78630 assert.equal(moment.utc('2004-W53-1', moment.ISO_8601, true).isoWeekYear(2013).format('GGGG-[W]WW-E'), '2013-W52-1', '2004-W53-1 to 2013');
78631 assert.equal(moment.utc('2004-W53-1', moment.ISO_8601, true).isoWeekYear(2020).format('GGGG-[W]WW-E'), '2020-W53-1', '2004-W53-1 to 2020');
78632 assert.equal(moment.utc('2005-W52-1', moment.ISO_8601, true).isoWeekYear(2004).format('GGGG-[W]WW-E'), '2004-W52-1', '2005-W52-1 to 2004');
78633 assert.equal(moment.utc('2013-W30-4', moment.ISO_8601, true).isoWeekYear(2015).format('GGGG-[W]WW-E'), '2015-W30-4', '2013-W30-4 to 2015');
78634
78635 assert.equal(moment.utc('2005-w53-0', 'gggg-[w]ww-e', true).weekYear(2013).format('gggg-[w]ww-e'), '2013-w52-0', '2005-w53-0 to 2013');
78636 assert.equal(moment.utc('2005-w53-0', 'gggg-[w]ww-e', true).weekYear(2016).format('gggg-[w]ww-e'), '2016-w53-0', '2005-w53-0 to 2016');
78637 assert.equal(moment.utc('2004-w52-0', 'gggg-[w]ww-e', true).weekYear(2005).format('gggg-[w]ww-e'), '2005-w52-0', '2004-w52-0 to 2005');
78638 assert.equal(moment.utc('2013-w30-4', 'gggg-[w]ww-e', true).weekYear(2015).format('gggg-[w]ww-e'), '2015-w30-4', '2013-w30-4 to 2015');
78639 });
f2af24d5
IC
78640
78641})));
78642
78643
78644;(function (global, factory) {
78645 typeof exports === 'object' && typeof module !== 'undefined'
78646 && typeof require === 'function' ? factory(require('../../moment')) :
78647 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
78648 factory(global.moment)
78649}(this, (function (moment) { 'use strict';
78650
db71a655
KM
78651 function each(array, callback) {
78652 var i;
78653 for (i = 0; i < array.length; i++) {
78654 callback(array[i], i, array);
78655 }
f2af24d5 78656 }
f2af24d5 78657
db71a655
KM
78658 function setupDeprecationHandler(test, moment$$1, scope) {
78659 test._expectedDeprecations = null;
78660 test._observedDeprecations = null;
78661 test._oldSupress = moment$$1.suppressDeprecationWarnings;
78662 moment$$1.suppressDeprecationWarnings = true;
78663 test.expectedDeprecations = function () {
78664 test._expectedDeprecations = arguments;
78665 test._observedDeprecations = [];
78666 };
78667 moment$$1.deprecationHandler = function (name, msg) {
78668 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
78669 if (deprecationId === -1) {
78670 throw new Error('Unexpected deprecation thrown name=' +
78671 name + ' msg=' + msg);
78672 }
78673 test._observedDeprecations[deprecationId] = 1;
78674 };
78675 }
516f5f67 78676
db71a655
KM
78677 function teardownDeprecationHandler(test, moment$$1, scope) {
78678 moment$$1.suppressDeprecationWarnings = test._oldSupress;
516f5f67 78679
db71a655
KM
78680 if (test._expectedDeprecations != null) {
78681 var missedDeprecations = [];
78682 each(test._expectedDeprecations, function (deprecationPattern, id) {
78683 if (test._observedDeprecations[id] !== 1) {
78684 missedDeprecations.push(deprecationPattern);
78685 }
78686 });
78687 if (missedDeprecations.length !== 0) {
78688 throw new Error('Expected deprecation warnings did not happen: ' +
78689 missedDeprecations.join(' '));
73f3c911 78690 }
73f3c911
IC
78691 }
78692 }
516f5f67 78693
db71a655
KM
78694 function matchedDeprecation(name, msg, deprecations) {
78695 if (deprecations == null) {
78696 return -1;
73f3c911 78697 }
db71a655
KM
78698 for (var i = 0; i < deprecations.length; ++i) {
78699 if (name != null && name === deprecations[i]) {
78700 return i;
78701 }
78702 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
78703 return i;
78704 }
73f3c911 78705 }
db71a655 78706 return -1;
73f3c911 78707 }
516f5f67 78708
db71a655 78709 /*global QUnit:false*/
516f5f67 78710
db71a655 78711 var test = QUnit.test;
516f5f67 78712
db71a655
KM
78713 function module$1 (name, lifecycle) {
78714 QUnit.module(name, {
c58511b9 78715 beforeEach : function () {
db71a655
KM
78716 moment.locale('en');
78717 moment.createFromInputFallback = function (config) {
78718 throw new Error('input not handled by moment: ' + config._i);
78719 };
78720 setupDeprecationHandler(test, moment, 'core');
78721 if (lifecycle && lifecycle.setup) {
78722 lifecycle.setup();
78723 }
78724 },
c58511b9 78725 afterEach : function () {
db71a655
KM
78726 teardownDeprecationHandler(test, moment, 'core');
78727 if (lifecycle && lifecycle.teardown) {
78728 lifecycle.teardown();
78729 }
73f3c911 78730 }
db71a655
KM
78731 });
78732 }
73f3c911 78733
db71a655 78734 module$1('week day');
73f3c911 78735
db71a655
KM
78736 test('iso weekday', function (assert) {
78737 var i;
73f3c911 78738
db71a655
KM
78739 for (i = 0; i < 7; ++i) {
78740 moment.locale('dow:' + i + ',doy: 6', {week: {dow: i, doy: 6}});
78741 assert.equal(moment([1985, 1, 4]).isoWeekday(), 1, 'Feb 4 1985 is Monday -- 1st day');
78742 assert.equal(moment([2029, 8, 18]).isoWeekday(), 2, 'Sep 18 2029 is Tuesday -- 2nd day');
78743 assert.equal(moment([2013, 3, 24]).isoWeekday(), 3, 'Apr 24 2013 is Wednesday -- 3rd day');
78744 assert.equal(moment([2015, 2, 5]).isoWeekday(), 4, 'Mar 5 2015 is Thursday -- 4th day');
78745 assert.equal(moment([1970, 0, 2]).isoWeekday(), 5, 'Jan 2 1970 is Friday -- 5th day');
78746 assert.equal(moment([2001, 4, 12]).isoWeekday(), 6, 'May 12 2001 is Saturday -- 6th day');
78747 assert.equal(moment([2000, 0, 2]).isoWeekday(), 7, 'Jan 2 2000 is Sunday -- 7th day');
78748 }
78749 });
78750
78751 test('iso weekday setter', function (assert) {
78752 var a = moment([2011, 0, 10]);
78753 assert.equal(moment(a).isoWeekday(1).date(), 10, 'set from mon to mon');
78754 assert.equal(moment(a).isoWeekday(4).date(), 13, 'set from mon to thu');
78755 assert.equal(moment(a).isoWeekday(7).date(), 16, 'set from mon to sun');
78756 assert.equal(moment(a).isoWeekday(-6).date(), 3, 'set from mon to last mon');
78757 assert.equal(moment(a).isoWeekday(-3).date(), 6, 'set from mon to last thu');
78758 assert.equal(moment(a).isoWeekday(0).date(), 9, 'set from mon to last sun');
78759 assert.equal(moment(a).isoWeekday(8).date(), 17, 'set from mon to next mon');
78760 assert.equal(moment(a).isoWeekday(11).date(), 20, 'set from mon to next thu');
78761 assert.equal(moment(a).isoWeekday(14).date(), 23, 'set from mon to next sun');
78762
78763 a = moment([2011, 0, 13]);
78764 assert.equal(moment(a).isoWeekday(1).date(), 10, 'set from thu to mon');
78765 assert.equal(moment(a).isoWeekday(4).date(), 13, 'set from thu to thu');
78766 assert.equal(moment(a).isoWeekday(7).date(), 16, 'set from thu to sun');
78767 assert.equal(moment(a).isoWeekday(-6).date(), 3, 'set from thu to last mon');
78768 assert.equal(moment(a).isoWeekday(-3).date(), 6, 'set from thu to last thu');
78769 assert.equal(moment(a).isoWeekday(0).date(), 9, 'set from thu to last sun');
78770 assert.equal(moment(a).isoWeekday(8).date(), 17, 'set from thu to next mon');
78771 assert.equal(moment(a).isoWeekday(11).date(), 20, 'set from thu to next thu');
78772 assert.equal(moment(a).isoWeekday(14).date(), 23, 'set from thu to next sun');
78773
78774 a = moment([2011, 0, 16]);
78775 assert.equal(moment(a).isoWeekday(1).date(), 10, 'set from sun to mon');
78776 assert.equal(moment(a).isoWeekday(4).date(), 13, 'set from sun to thu');
78777 assert.equal(moment(a).isoWeekday(7).date(), 16, 'set from sun to sun');
78778 assert.equal(moment(a).isoWeekday(-6).date(), 3, 'set from sun to last mon');
78779 assert.equal(moment(a).isoWeekday(-3).date(), 6, 'set from sun to last thu');
78780 assert.equal(moment(a).isoWeekday(0).date(), 9, 'set from sun to last sun');
78781 assert.equal(moment(a).isoWeekday(8).date(), 17, 'set from sun to next mon');
78782 assert.equal(moment(a).isoWeekday(11).date(), 20, 'set from sun to next thu');
78783 assert.equal(moment(a).isoWeekday(14).date(), 23, 'set from sun to next sun');
78784 });
78785
78786 test('iso weekday setter with day name', function (assert) {
78787 moment.locale('en');
78788
78789 var a = moment([2011, 0, 10]);
78790 assert.equal(moment(a).isoWeekday('Monday').date(), 10, 'set from mon to mon');
78791 assert.equal(moment(a).isoWeekday('Thursday').date(), 13, 'set from mon to thu');
78792 assert.equal(moment(a).isoWeekday('Sunday').date(), 16, 'set from mon to sun');
78793
78794 a = moment([2011, 0, 13]);
78795 assert.equal(moment(a).isoWeekday('Monday').date(), 10, 'set from thu to mon');
78796 assert.equal(moment(a).isoWeekday('Thursday').date(), 13, 'set from thu to thu');
78797 assert.equal(moment(a).isoWeekday('Sunday').date(), 16, 'set from thu to sun');
78798
78799 a = moment([2011, 0, 16]);
78800 assert.equal(moment(a).isoWeekday('Monday').date(), 10, 'set from sun to mon');
78801 assert.equal(moment(a).isoWeekday('Thursday').date(), 13, 'set from sun to thu');
78802 assert.equal(moment(a).isoWeekday('Sunday').date(), 16, 'set from sun to sun');
78803 });
78804
78805 test('weekday first day of week Sunday (dow 0)', function (assert) {
78806 moment.locale('dow: 0,doy: 6', {week: {dow: 0, doy: 6}});
78807 assert.equal(moment([1985, 1, 3]).weekday(), 0, 'Feb 3 1985 is Sunday -- 0th day');
78808 assert.equal(moment([2029, 8, 17]).weekday(), 1, 'Sep 17 2029 is Monday -- 1st day');
78809 assert.equal(moment([2013, 3, 23]).weekday(), 2, 'Apr 23 2013 is Tuesday -- 2nd day');
78810 assert.equal(moment([2015, 2, 4]).weekday(), 3, 'Mar 4 2015 is Wednesday -- 3nd day');
78811 assert.equal(moment([1970, 0, 1]).weekday(), 4, 'Jan 1 1970 is Thursday -- 4th day');
78812 assert.equal(moment([2001, 4, 11]).weekday(), 5, 'May 11 2001 is Friday -- 5th day');
78813 assert.equal(moment([2000, 0, 1]).weekday(), 6, 'Jan 1 2000 is Saturday -- 6th day');
78814 });
78815
78816 test('weekday first day of week Monday (dow 1)', function (assert) {
78817 moment.locale('dow: 1,doy: 6', {week: {dow: 1, doy: 6}});
78818 assert.equal(moment([1985, 1, 4]).weekday(), 0, 'Feb 4 1985 is Monday -- 0th day');
78819 assert.equal(moment([2029, 8, 18]).weekday(), 1, 'Sep 18 2029 is Tuesday -- 1st day');
78820 assert.equal(moment([2013, 3, 24]).weekday(), 2, 'Apr 24 2013 is Wednesday -- 2nd day');
78821 assert.equal(moment([2015, 2, 5]).weekday(), 3, 'Mar 5 2015 is Thursday -- 3nd day');
78822 assert.equal(moment([1970, 0, 2]).weekday(), 4, 'Jan 2 1970 is Friday -- 4th day');
78823 assert.equal(moment([2001, 4, 12]).weekday(), 5, 'May 12 2001 is Saturday -- 5th day');
78824 assert.equal(moment([2000, 0, 2]).weekday(), 6, 'Jan 2 2000 is Sunday -- 6th day');
78825 });
78826
78827 test('weekday first day of week Tuesday (dow 2)', function (assert) {
78828 moment.locale('dow: 2,doy: 6', {week: {dow: 2, doy: 6}});
78829 assert.equal(moment([1985, 1, 5]).weekday(), 0, 'Feb 5 1985 is Tuesday -- 0th day');
78830 assert.equal(moment([2029, 8, 19]).weekday(), 1, 'Sep 19 2029 is Wednesday -- 1st day');
78831 assert.equal(moment([2013, 3, 25]).weekday(), 2, 'Apr 25 2013 is Thursday -- 2nd day');
78832 assert.equal(moment([2015, 2, 6]).weekday(), 3, 'Mar 6 2015 is Friday -- 3nd day');
78833 assert.equal(moment([1970, 0, 3]).weekday(), 4, 'Jan 3 1970 is Staturday -- 4th day');
78834 assert.equal(moment([2001, 4, 13]).weekday(), 5, 'May 13 2001 is Sunday -- 5th day');
78835 assert.equal(moment([2000, 0, 3]).weekday(), 6, 'Jan 3 2000 is Monday -- 6th day');
78836 });
78837
78838 test('weekday first day of week Wednesday (dow 3)', function (assert) {
78839 moment.locale('dow: 3,doy: 6', {week: {dow: 3, doy: 6}});
78840 assert.equal(moment([1985, 1, 6]).weekday(), 0, 'Feb 6 1985 is Wednesday -- 0th day');
78841 assert.equal(moment([2029, 8, 20]).weekday(), 1, 'Sep 20 2029 is Thursday -- 1st day');
78842 assert.equal(moment([2013, 3, 26]).weekday(), 2, 'Apr 26 2013 is Friday -- 2nd day');
78843 assert.equal(moment([2015, 2, 7]).weekday(), 3, 'Mar 7 2015 is Saturday -- 3nd day');
78844 assert.equal(moment([1970, 0, 4]).weekday(), 4, 'Jan 4 1970 is Sunday -- 4th day');
78845 assert.equal(moment([2001, 4, 14]).weekday(), 5, 'May 14 2001 is Monday -- 5th day');
78846 assert.equal(moment([2000, 0, 4]).weekday(), 6, 'Jan 4 2000 is Tuesday -- 6th day');
78847 moment.locale('dow:3,doy:6', null);
78848 });
78849
78850 test('weekday first day of week Thursday (dow 4)', function (assert) {
78851 moment.locale('dow: 4,doy: 6', {week: {dow: 4, doy: 6}});
78852 assert.equal(moment([1985, 1, 7]).weekday(), 0, 'Feb 7 1985 is Thursday -- 0th day');
78853 assert.equal(moment([2029, 8, 21]).weekday(), 1, 'Sep 21 2029 is Friday -- 1st day');
78854 assert.equal(moment([2013, 3, 27]).weekday(), 2, 'Apr 27 2013 is Saturday -- 2nd day');
78855 assert.equal(moment([2015, 2, 8]).weekday(), 3, 'Mar 8 2015 is Sunday -- 3nd day');
78856 assert.equal(moment([1970, 0, 5]).weekday(), 4, 'Jan 5 1970 is Monday -- 4th day');
78857 assert.equal(moment([2001, 4, 15]).weekday(), 5, 'May 15 2001 is Tuesday -- 5th day');
78858 assert.equal(moment([2000, 0, 5]).weekday(), 6, 'Jan 5 2000 is Wednesday -- 6th day');
78859 });
78860
78861 test('weekday first day of week Friday (dow 5)', function (assert) {
78862 moment.locale('dow: 5,doy: 6', {week: {dow: 5, doy: 6}});
78863 assert.equal(moment([1985, 1, 8]).weekday(), 0, 'Feb 8 1985 is Friday -- 0th day');
78864 assert.equal(moment([2029, 8, 22]).weekday(), 1, 'Sep 22 2029 is Staturday -- 1st day');
78865 assert.equal(moment([2013, 3, 28]).weekday(), 2, 'Apr 28 2013 is Sunday -- 2nd day');
78866 assert.equal(moment([2015, 2, 9]).weekday(), 3, 'Mar 9 2015 is Monday -- 3nd day');
78867 assert.equal(moment([1970, 0, 6]).weekday(), 4, 'Jan 6 1970 is Tuesday -- 4th day');
78868 assert.equal(moment([2001, 4, 16]).weekday(), 5, 'May 16 2001 is Wednesday -- 5th day');
78869 assert.equal(moment([2000, 0, 6]).weekday(), 6, 'Jan 6 2000 is Thursday -- 6th day');
78870 });
78871
78872 test('weekday first day of week Saturday (dow 6)', function (assert) {
78873 moment.locale('dow: 6,doy: 6', {week: {dow: 6, doy: 6}});
78874 assert.equal(moment([1985, 1, 9]).weekday(), 0, 'Feb 9 1985 is Staturday -- 0th day');
78875 assert.equal(moment([2029, 8, 23]).weekday(), 1, 'Sep 23 2029 is Sunday -- 1st day');
78876 assert.equal(moment([2013, 3, 29]).weekday(), 2, 'Apr 29 2013 is Monday -- 2nd day');
78877 assert.equal(moment([2015, 2, 10]).weekday(), 3, 'Mar 10 2015 is Tuesday -- 3nd day');
78878 assert.equal(moment([1970, 0, 7]).weekday(), 4, 'Jan 7 1970 is Wednesday -- 4th day');
78879 assert.equal(moment([2001, 4, 17]).weekday(), 5, 'May 17 2001 is Thursday -- 5th day');
78880 assert.equal(moment([2000, 0, 7]).weekday(), 6, 'Jan 7 2000 is Friday -- 6th day');
78881 });
516f5f67 78882
73f3c911 78883})));
516f5f67 78884
73f3c911
IC
78885
78886;(function (global, factory) {
78887 typeof exports === 'object' && typeof module !== 'undefined'
78888 && typeof require === 'function' ? factory(require('../../moment')) :
78889 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
78890 factory(global.moment)
78891}(this, (function (moment) { 'use strict';
78892
db71a655
KM
78893 function each(array, callback) {
78894 var i;
78895 for (i = 0; i < array.length; i++) {
78896 callback(array[i], i, array);
78897 }
73f3c911 78898 }
73f3c911 78899
db71a655
KM
78900 function setupDeprecationHandler(test, moment$$1, scope) {
78901 test._expectedDeprecations = null;
78902 test._observedDeprecations = null;
78903 test._oldSupress = moment$$1.suppressDeprecationWarnings;
78904 moment$$1.suppressDeprecationWarnings = true;
78905 test.expectedDeprecations = function () {
78906 test._expectedDeprecations = arguments;
78907 test._observedDeprecations = [];
78908 };
78909 moment$$1.deprecationHandler = function (name, msg) {
78910 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
78911 if (deprecationId === -1) {
78912 throw new Error('Unexpected deprecation thrown name=' +
78913 name + ' msg=' + msg);
78914 }
78915 test._observedDeprecations[deprecationId] = 1;
78916 };
78917 }
516f5f67 78918
db71a655
KM
78919 function teardownDeprecationHandler(test, moment$$1, scope) {
78920 moment$$1.suppressDeprecationWarnings = test._oldSupress;
516f5f67 78921
db71a655
KM
78922 if (test._expectedDeprecations != null) {
78923 var missedDeprecations = [];
78924 each(test._expectedDeprecations, function (deprecationPattern, id) {
78925 if (test._observedDeprecations[id] !== 1) {
78926 missedDeprecations.push(deprecationPattern);
78927 }
78928 });
78929 if (missedDeprecations.length !== 0) {
78930 throw new Error('Expected deprecation warnings did not happen: ' +
78931 missedDeprecations.join(' '));
73f3c911 78932 }
73f3c911
IC
78933 }
78934 }
73f3c911 78935
db71a655
KM
78936 function matchedDeprecation(name, msg, deprecations) {
78937 if (deprecations == null) {
78938 return -1;
73f3c911 78939 }
db71a655
KM
78940 for (var i = 0; i < deprecations.length; ++i) {
78941 if (name != null && name === deprecations[i]) {
78942 return i;
78943 }
78944 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
78945 return i;
78946 }
73f3c911 78947 }
db71a655 78948 return -1;
73f3c911 78949 }
516f5f67 78950
db71a655 78951 /*global QUnit:false*/
516f5f67 78952
db71a655 78953 var test = QUnit.test;
516f5f67 78954
db71a655
KM
78955 function module$1 (name, lifecycle) {
78956 QUnit.module(name, {
c58511b9 78957 beforeEach : function () {
db71a655
KM
78958 moment.locale('en');
78959 moment.createFromInputFallback = function (config) {
78960 throw new Error('input not handled by moment: ' + config._i);
78961 };
78962 setupDeprecationHandler(test, moment, 'core');
78963 if (lifecycle && lifecycle.setup) {
78964 lifecycle.setup();
78965 }
78966 },
c58511b9 78967 afterEach : function () {
db71a655
KM
78968 teardownDeprecationHandler(test, moment, 'core');
78969 if (lifecycle && lifecycle.teardown) {
78970 lifecycle.teardown();
78971 }
73f3c911 78972 }
db71a655
KM
78973 });
78974 }
73f3c911 78975
db71a655
KM
78976 module$1('weeks');
78977
78978 test('day of year', function (assert) {
78979 assert.equal(moment([2000, 0, 1]).dayOfYear(), 1, 'Jan 1 2000 should be day 1 of the year');
78980 assert.equal(moment([2000, 1, 28]).dayOfYear(), 59, 'Feb 28 2000 should be day 59 of the year');
2e2a5b35 78981 assert.equal(moment([2000, 1, 29]).dayOfYear(), 60, 'Feb 29 2000 should be day 60 of the year');
db71a655
KM
78982 assert.equal(moment([2000, 11, 31]).dayOfYear(), 366, 'Dec 31 2000 should be day 366 of the year');
78983 assert.equal(moment([2001, 0, 1]).dayOfYear(), 1, 'Jan 1 2001 should be day 1 of the year');
78984 assert.equal(moment([2001, 1, 28]).dayOfYear(), 59, 'Feb 28 2001 should be day 59 of the year');
78985 assert.equal(moment([2001, 2, 1]).dayOfYear(), 60, 'Mar 1 2001 should be day 60 of the year');
78986 assert.equal(moment([2001, 11, 31]).dayOfYear(), 365, 'Dec 31 2001 should be day 365 of the year');
78987 });
78988
78989 test('day of year setters', function (assert) {
78990 assert.equal(moment([2000, 0, 1]).dayOfYear(200).dayOfYear(), 200, 'Setting Jan 1 2000 day of the year to 200 should work');
78991 assert.equal(moment([2000, 1, 28]).dayOfYear(200).dayOfYear(), 200, 'Setting Feb 28 2000 day of the year to 200 should work');
2e2a5b35 78992 assert.equal(moment([2000, 1, 29]).dayOfYear(200).dayOfYear(), 200, 'Setting Feb 29 2000 day of the year to 200 should work');
db71a655
KM
78993 assert.equal(moment([2000, 11, 31]).dayOfYear(200).dayOfYear(), 200, 'Setting Dec 31 2000 day of the year to 200 should work');
78994 assert.equal(moment().dayOfYear(1).dayOfYear(), 1, 'Setting day of the year to 1 should work');
78995 assert.equal(moment().dayOfYear(59).dayOfYear(), 59, 'Setting day of the year to 59 should work');
78996 assert.equal(moment().dayOfYear(60).dayOfYear(), 60, 'Setting day of the year to 60 should work');
78997 assert.equal(moment().dayOfYear(365).dayOfYear(), 365, 'Setting day of the year to 365 should work');
78998 });
78999
79000 test('iso weeks year starting sunday', function (assert) {
79001 assert.equal(moment([2012, 0, 1]).isoWeek(), 52, 'Jan 1 2012 should be iso week 52');
79002 assert.equal(moment([2012, 0, 2]).isoWeek(), 1, 'Jan 2 2012 should be iso week 1');
79003 assert.equal(moment([2012, 0, 8]).isoWeek(), 1, 'Jan 8 2012 should be iso week 1');
79004 assert.equal(moment([2012, 0, 9]).isoWeek(), 2, 'Jan 9 2012 should be iso week 2');
79005 assert.equal(moment([2012, 0, 15]).isoWeek(), 2, 'Jan 15 2012 should be iso week 2');
79006 });
79007
79008 test('iso weeks year starting monday', function (assert) {
79009 assert.equal(moment([2007, 0, 1]).isoWeek(), 1, 'Jan 1 2007 should be iso week 1');
79010 assert.equal(moment([2007, 0, 7]).isoWeek(), 1, 'Jan 7 2007 should be iso week 1');
79011 assert.equal(moment([2007, 0, 8]).isoWeek(), 2, 'Jan 8 2007 should be iso week 2');
79012 assert.equal(moment([2007, 0, 14]).isoWeek(), 2, 'Jan 14 2007 should be iso week 2');
79013 assert.equal(moment([2007, 0, 15]).isoWeek(), 3, 'Jan 15 2007 should be iso week 3');
79014 });
79015
79016 test('iso weeks year starting tuesday', function (assert) {
79017 assert.equal(moment([2007, 11, 31]).isoWeek(), 1, 'Dec 31 2007 should be iso week 1');
79018 assert.equal(moment([2008, 0, 1]).isoWeek(), 1, 'Jan 1 2008 should be iso week 1');
79019 assert.equal(moment([2008, 0, 6]).isoWeek(), 1, 'Jan 6 2008 should be iso week 1');
79020 assert.equal(moment([2008, 0, 7]).isoWeek(), 2, 'Jan 7 2008 should be iso week 2');
79021 assert.equal(moment([2008, 0, 13]).isoWeek(), 2, 'Jan 13 2008 should be iso week 2');
79022 assert.equal(moment([2008, 0, 14]).isoWeek(), 3, 'Jan 14 2008 should be iso week 3');
79023 });
79024
79025 test('iso weeks year starting wednesday', function (assert) {
79026 assert.equal(moment([2002, 11, 30]).isoWeek(), 1, 'Dec 30 2002 should be iso week 1');
79027 assert.equal(moment([2003, 0, 1]).isoWeek(), 1, 'Jan 1 2003 should be iso week 1');
79028 assert.equal(moment([2003, 0, 5]).isoWeek(), 1, 'Jan 5 2003 should be iso week 1');
79029 assert.equal(moment([2003, 0, 6]).isoWeek(), 2, 'Jan 6 2003 should be iso week 2');
79030 assert.equal(moment([2003, 0, 12]).isoWeek(), 2, 'Jan 12 2003 should be iso week 2');
79031 assert.equal(moment([2003, 0, 13]).isoWeek(), 3, 'Jan 13 2003 should be iso week 3');
79032 });
79033
79034 test('iso weeks year starting thursday', function (assert) {
79035 assert.equal(moment([2008, 11, 29]).isoWeek(), 1, 'Dec 29 2008 should be iso week 1');
79036 assert.equal(moment([2009, 0, 1]).isoWeek(), 1, 'Jan 1 2009 should be iso week 1');
79037 assert.equal(moment([2009, 0, 4]).isoWeek(), 1, 'Jan 4 2009 should be iso week 1');
79038 assert.equal(moment([2009, 0, 5]).isoWeek(), 2, 'Jan 5 2009 should be iso week 2');
79039 assert.equal(moment([2009, 0, 11]).isoWeek(), 2, 'Jan 11 2009 should be iso week 2');
79040 assert.equal(moment([2009, 0, 13]).isoWeek(), 3, 'Jan 12 2009 should be iso week 3');
79041 });
79042
79043 test('iso weeks year starting friday', function (assert) {
79044 assert.equal(moment([2009, 11, 28]).isoWeek(), 53, 'Dec 28 2009 should be iso week 53');
79045 assert.equal(moment([2010, 0, 1]).isoWeek(), 53, 'Jan 1 2010 should be iso week 53');
79046 assert.equal(moment([2010, 0, 3]).isoWeek(), 53, 'Jan 3 2010 should be iso week 53');
79047 assert.equal(moment([2010, 0, 4]).isoWeek(), 1, 'Jan 4 2010 should be iso week 1');
79048 assert.equal(moment([2010, 0, 10]).isoWeek(), 1, 'Jan 10 2010 should be iso week 1');
79049 assert.equal(moment([2010, 0, 11]).isoWeek(), 2, 'Jan 11 2010 should be iso week 2');
79050 });
79051
79052 test('iso weeks year starting saturday', function (assert) {
79053 assert.equal(moment([2010, 11, 27]).isoWeek(), 52, 'Dec 27 2010 should be iso week 52');
79054 assert.equal(moment([2011, 0, 1]).isoWeek(), 52, 'Jan 1 2011 should be iso week 52');
79055 assert.equal(moment([2011, 0, 2]).isoWeek(), 52, 'Jan 2 2011 should be iso week 52');
79056 assert.equal(moment([2011, 0, 3]).isoWeek(), 1, 'Jan 3 2011 should be iso week 1');
79057 assert.equal(moment([2011, 0, 9]).isoWeek(), 1, 'Jan 9 2011 should be iso week 1');
79058 assert.equal(moment([2011, 0, 10]).isoWeek(), 2, 'Jan 10 2011 should be iso week 2');
79059 });
79060
79061 test('iso weeks year starting sunday formatted', function (assert) {
79062 assert.equal(moment([2012, 0, 1]).format('W WW Wo'), '52 52 52nd', 'Jan 1 2012 should be iso week 52');
79063 assert.equal(moment([2012, 0, 2]).format('W WW Wo'), '1 01 1st', 'Jan 2 2012 should be iso week 1');
79064 assert.equal(moment([2012, 0, 8]).format('W WW Wo'), '1 01 1st', 'Jan 8 2012 should be iso week 1');
79065 assert.equal(moment([2012, 0, 9]).format('W WW Wo'), '2 02 2nd', 'Jan 9 2012 should be iso week 2');
79066 assert.equal(moment([2012, 0, 15]).format('W WW Wo'), '2 02 2nd', 'Jan 15 2012 should be iso week 2');
79067 });
79068
79069 test('weeks plural year starting sunday', function (assert) {
79070 assert.equal(moment([2012, 0, 1]).weeks(), 1, 'Jan 1 2012 should be week 1');
79071 assert.equal(moment([2012, 0, 7]).weeks(), 1, 'Jan 7 2012 should be week 1');
79072 assert.equal(moment([2012, 0, 8]).weeks(), 2, 'Jan 8 2012 should be week 2');
79073 assert.equal(moment([2012, 0, 14]).weeks(), 2, 'Jan 14 2012 should be week 2');
79074 assert.equal(moment([2012, 0, 15]).weeks(), 3, 'Jan 15 2012 should be week 3');
79075 });
79076
79077 test('iso weeks plural year starting sunday', function (assert) {
79078 assert.equal(moment([2012, 0, 1]).isoWeeks(), 52, 'Jan 1 2012 should be iso week 52');
79079 assert.equal(moment([2012, 0, 2]).isoWeeks(), 1, 'Jan 2 2012 should be iso week 1');
79080 assert.equal(moment([2012, 0, 8]).isoWeeks(), 1, 'Jan 8 2012 should be iso week 1');
79081 assert.equal(moment([2012, 0, 9]).isoWeeks(), 2, 'Jan 9 2012 should be iso week 2');
79082 assert.equal(moment([2012, 0, 15]).isoWeeks(), 2, 'Jan 15 2012 should be iso week 2');
79083 });
79084
79085 test('weeks setter', function (assert) {
79086 assert.equal(moment([2012, 0, 1]).week(30).week(), 30, 'Setting Jan 1 2012 to week 30 should work');
79087 assert.equal(moment([2012, 0, 7]).week(30).week(), 30, 'Setting Jan 7 2012 to week 30 should work');
79088 assert.equal(moment([2012, 0, 8]).week(30).week(), 30, 'Setting Jan 8 2012 to week 30 should work');
79089 assert.equal(moment([2012, 0, 14]).week(30).week(), 30, 'Setting Jan 14 2012 to week 30 should work');
79090 assert.equal(moment([2012, 0, 15]).week(30).week(), 30, 'Setting Jan 15 2012 to week 30 should work');
79091 });
79092
79093 test('iso weeks setter', function (assert) {
79094 assert.equal(moment([2012, 0, 1]).isoWeeks(25).isoWeeks(), 25, 'Setting Jan 1 2012 to week 25 should work');
79095 assert.equal(moment([2012, 0, 2]).isoWeeks(24).isoWeeks(), 24, 'Setting Jan 2 2012 to week 24 should work');
79096 assert.equal(moment([2012, 0, 8]).isoWeeks(23).isoWeeks(), 23, 'Setting Jan 8 2012 to week 23 should work');
79097 assert.equal(moment([2012, 0, 9]).isoWeeks(22).isoWeeks(), 22, 'Setting Jan 9 2012 to week 22 should work');
79098 assert.equal(moment([2012, 0, 15]).isoWeeks(21).isoWeeks(), 21, 'Setting Jan 15 2012 to week 21 should work');
79099 });
79100
79101 test('iso weeks setter day of year', function (assert) {
79102 assert.equal(moment([2012, 0, 1]).isoWeek(1).dayOfYear(), 9, 'Setting Jan 1 2012 to week 1 should be day of year 8');
79103 assert.equal(moment([2012, 0, 1]).isoWeek(1).year(), 2011, 'Setting Jan 1 2012 to week 1 should be year 2011');
79104 assert.equal(moment([2012, 0, 2]).isoWeek(1).dayOfYear(), 2, 'Setting Jan 2 2012 to week 1 should be day of year 2');
79105 assert.equal(moment([2012, 0, 8]).isoWeek(1).dayOfYear(), 8, 'Setting Jan 8 2012 to week 1 should be day of year 8');
79106 assert.equal(moment([2012, 0, 9]).isoWeek(1).dayOfYear(), 2, 'Setting Jan 9 2012 to week 1 should be day of year 2');
79107 assert.equal(moment([2012, 0, 15]).isoWeek(1).dayOfYear(), 8, 'Setting Jan 15 2012 to week 1 should be day of year 8');
79108 });
79109
79110 test('years with iso week 53', function (assert) {
79111 // Based on a table taken from https://en.wikipedia.org/wiki/ISO_week_date
79112 // (as downloaded on 2014-01-06) listing the 71 years in a 400-year cycle
79113 // that have 53 weeks; in this case reflecting the 2000 based cycle
79114 assert.equal(moment([2004, 11, 31]).isoWeek(), 53, 'Dec 31 2004 should be iso week 53');
79115 assert.equal(moment([2009, 11, 31]).isoWeek(), 53, 'Dec 31 2009 should be iso week 53');
79116 assert.equal(moment([2015, 11, 31]).isoWeek(), 53, 'Dec 31 2015 should be iso week 53');
79117 assert.equal(moment([2020, 11, 31]).isoWeek(), 53, 'Dec 31 2020 should be iso week 53');
79118 assert.equal(moment([2026, 11, 31]).isoWeek(), 53, 'Dec 31 2026 should be iso week 53');
79119 assert.equal(moment([2032, 11, 31]).isoWeek(), 53, 'Dec 31 2032 should be iso week 53');
79120 assert.equal(moment([2037, 11, 31]).isoWeek(), 53, 'Dec 31 2037 should be iso week 53');
79121 assert.equal(moment([2043, 11, 31]).isoWeek(), 53, 'Dec 31 2043 should be iso week 53');
79122 assert.equal(moment([2048, 11, 31]).isoWeek(), 53, 'Dec 31 2048 should be iso week 53');
79123 assert.equal(moment([2054, 11, 31]).isoWeek(), 53, 'Dec 31 2054 should be iso week 53');
79124 assert.equal(moment([2060, 11, 31]).isoWeek(), 53, 'Dec 31 2060 should be iso week 53');
79125 assert.equal(moment([2065, 11, 31]).isoWeek(), 53, 'Dec 31 2065 should be iso week 53');
79126 assert.equal(moment([2071, 11, 31]).isoWeek(), 53, 'Dec 31 2071 should be iso week 53');
79127 assert.equal(moment([2076, 11, 31]).isoWeek(), 53, 'Dec 31 2076 should be iso week 53');
79128 assert.equal(moment([2082, 11, 31]).isoWeek(), 53, 'Dec 31 2082 should be iso week 53');
79129 assert.equal(moment([2088, 11, 31]).isoWeek(), 53, 'Dec 31 2088 should be iso week 53');
79130 assert.equal(moment([2093, 11, 31]).isoWeek(), 53, 'Dec 31 2093 should be iso week 53');
79131 assert.equal(moment([2099, 11, 31]).isoWeek(), 53, 'Dec 31 2099 should be iso week 53');
79132 assert.equal(moment([2105, 11, 31]).isoWeek(), 53, 'Dec 31 2105 should be iso week 53');
79133 assert.equal(moment([2111, 11, 31]).isoWeek(), 53, 'Dec 31 2111 should be iso week 53');
79134 assert.equal(moment([2116, 11, 31]).isoWeek(), 53, 'Dec 31 2116 should be iso week 53');
79135 assert.equal(moment([2122, 11, 31]).isoWeek(), 53, 'Dec 31 2122 should be iso week 53');
79136 assert.equal(moment([2128, 11, 31]).isoWeek(), 53, 'Dec 31 2128 should be iso week 53');
79137 assert.equal(moment([2133, 11, 31]).isoWeek(), 53, 'Dec 31 2133 should be iso week 53');
79138 assert.equal(moment([2139, 11, 31]).isoWeek(), 53, 'Dec 31 2139 should be iso week 53');
79139 assert.equal(moment([2144, 11, 31]).isoWeek(), 53, 'Dec 31 2144 should be iso week 53');
79140 assert.equal(moment([2150, 11, 31]).isoWeek(), 53, 'Dec 31 2150 should be iso week 53');
79141 assert.equal(moment([2156, 11, 31]).isoWeek(), 53, 'Dec 31 2156 should be iso week 53');
79142 assert.equal(moment([2161, 11, 31]).isoWeek(), 53, 'Dec 31 2161 should be iso week 53');
79143 assert.equal(moment([2167, 11, 31]).isoWeek(), 53, 'Dec 31 2167 should be iso week 53');
79144 assert.equal(moment([2172, 11, 31]).isoWeek(), 53, 'Dec 31 2172 should be iso week 53');
79145 assert.equal(moment([2178, 11, 31]).isoWeek(), 53, 'Dec 31 2178 should be iso week 53');
79146 assert.equal(moment([2184, 11, 31]).isoWeek(), 53, 'Dec 31 2184 should be iso week 53');
79147 assert.equal(moment([2189, 11, 31]).isoWeek(), 53, 'Dec 31 2189 should be iso week 53');
79148 assert.equal(moment([2195, 11, 31]).isoWeek(), 53, 'Dec 31 2195 should be iso week 53');
79149 assert.equal(moment([2201, 11, 31]).isoWeek(), 53, 'Dec 31 2201 should be iso week 53');
79150 assert.equal(moment([2207, 11, 31]).isoWeek(), 53, 'Dec 31 2207 should be iso week 53');
79151 assert.equal(moment([2212, 11, 31]).isoWeek(), 53, 'Dec 31 2212 should be iso week 53');
79152 assert.equal(moment([2218, 11, 31]).isoWeek(), 53, 'Dec 31 2218 should be iso week 53');
79153 assert.equal(moment([2224, 11, 31]).isoWeek(), 53, 'Dec 31 2224 should be iso week 53');
79154 assert.equal(moment([2229, 11, 31]).isoWeek(), 53, 'Dec 31 2229 should be iso week 53');
79155 assert.equal(moment([2235, 11, 31]).isoWeek(), 53, 'Dec 31 2235 should be iso week 53');
79156 assert.equal(moment([2240, 11, 31]).isoWeek(), 53, 'Dec 31 2240 should be iso week 53');
79157 assert.equal(moment([2246, 11, 31]).isoWeek(), 53, 'Dec 31 2246 should be iso week 53');
79158 assert.equal(moment([2252, 11, 31]).isoWeek(), 53, 'Dec 31 2252 should be iso week 53');
79159 assert.equal(moment([2257, 11, 31]).isoWeek(), 53, 'Dec 31 2257 should be iso week 53');
79160 assert.equal(moment([2263, 11, 31]).isoWeek(), 53, 'Dec 31 2263 should be iso week 53');
79161 assert.equal(moment([2268, 11, 31]).isoWeek(), 53, 'Dec 31 2268 should be iso week 53');
79162 assert.equal(moment([2274, 11, 31]).isoWeek(), 53, 'Dec 31 2274 should be iso week 53');
79163 assert.equal(moment([2280, 11, 31]).isoWeek(), 53, 'Dec 31 2280 should be iso week 53');
79164 assert.equal(moment([2285, 11, 31]).isoWeek(), 53, 'Dec 31 2285 should be iso week 53');
79165 assert.equal(moment([2291, 11, 31]).isoWeek(), 53, 'Dec 31 2291 should be iso week 53');
79166 assert.equal(moment([2296, 11, 31]).isoWeek(), 53, 'Dec 31 2296 should be iso week 53');
79167 assert.equal(moment([2303, 11, 31]).isoWeek(), 53, 'Dec 31 2303 should be iso week 53');
79168 assert.equal(moment([2308, 11, 31]).isoWeek(), 53, 'Dec 31 2308 should be iso week 53');
79169 assert.equal(moment([2314, 11, 31]).isoWeek(), 53, 'Dec 31 2314 should be iso week 53');
79170 assert.equal(moment([2320, 11, 31]).isoWeek(), 53, 'Dec 31 2320 should be iso week 53');
79171 assert.equal(moment([2325, 11, 31]).isoWeek(), 53, 'Dec 31 2325 should be iso week 53');
79172 assert.equal(moment([2331, 11, 31]).isoWeek(), 53, 'Dec 31 2331 should be iso week 53');
79173 assert.equal(moment([2336, 11, 31]).isoWeek(), 53, 'Dec 31 2336 should be iso week 53');
79174 assert.equal(moment([2342, 11, 31]).isoWeek(), 53, 'Dec 31 2342 should be iso week 53');
79175 assert.equal(moment([2348, 11, 31]).isoWeek(), 53, 'Dec 31 2348 should be iso week 53');
79176 assert.equal(moment([2353, 11, 31]).isoWeek(), 53, 'Dec 31 2353 should be iso week 53');
79177 assert.equal(moment([2359, 11, 31]).isoWeek(), 53, 'Dec 31 2359 should be iso week 53');
79178 assert.equal(moment([2364, 11, 31]).isoWeek(), 53, 'Dec 31 2364 should be iso week 53');
79179 assert.equal(moment([2370, 11, 31]).isoWeek(), 53, 'Dec 31 2370 should be iso week 53');
79180 assert.equal(moment([2376, 11, 31]).isoWeek(), 53, 'Dec 31 2376 should be iso week 53');
79181 assert.equal(moment([2381, 11, 31]).isoWeek(), 53, 'Dec 31 2381 should be iso week 53');
79182 assert.equal(moment([2387, 11, 31]).isoWeek(), 53, 'Dec 31 2387 should be iso week 53');
79183 assert.equal(moment([2392, 11, 31]).isoWeek(), 53, 'Dec 31 2392 should be iso week 53');
79184 assert.equal(moment([2398, 11, 31]).isoWeek(), 53, 'Dec 31 2398 should be iso week 53');
79185 });
79186
79187 test('count years with iso week 53', function (assert) {
79188 // Based on https://en.wikipedia.org/wiki/ISO_week_date (as seen on 2014-01-06)
79189 // stating that there are 71 years in a 400-year cycle that have 53 weeks;
79190 // in this case reflecting the 2000 based cycle
79191 var count = 0, i;
79192 for (i = 0; i < 400; i++) {
79193 count += (moment([2000 + i, 11, 31]).isoWeek() === 53) ? 1 : 0;
79194 }
79195 assert.equal(count, 71, 'Should have 71 years in 400-year cycle with iso week 53');
79196 });
73f3c911
IC
79197
79198})));
516f5f67 79199
516f5f67 79200
c74a101d
IC
79201;(function (global, factory) {
79202 typeof exports === 'object' && typeof module !== 'undefined'
79203 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
79204 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
79205 factory(global.moment)
73f3c911 79206}(this, (function (moment) { 'use strict';
516f5f67 79207
db71a655
KM
79208 function each(array, callback) {
79209 var i;
79210 for (i = 0; i < array.length; i++) {
79211 callback(array[i], i, array);
79212 }
b135bf1a
IC
79213 }
79214
db71a655
KM
79215 function setupDeprecationHandler(test, moment$$1, scope) {
79216 test._expectedDeprecations = null;
79217 test._observedDeprecations = null;
79218 test._oldSupress = moment$$1.suppressDeprecationWarnings;
79219 moment$$1.suppressDeprecationWarnings = true;
79220 test.expectedDeprecations = function () {
79221 test._expectedDeprecations = arguments;
79222 test._observedDeprecations = [];
79223 };
79224 moment$$1.deprecationHandler = function (name, msg) {
79225 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
79226 if (deprecationId === -1) {
79227 throw new Error('Unexpected deprecation thrown name=' +
79228 name + ' msg=' + msg);
79229 }
79230 test._observedDeprecations[deprecationId] = 1;
79231 };
79232 }
b135bf1a 79233
db71a655
KM
79234 function teardownDeprecationHandler(test, moment$$1, scope) {
79235 moment$$1.suppressDeprecationWarnings = test._oldSupress;
73f3c911 79236
db71a655
KM
79237 if (test._expectedDeprecations != null) {
79238 var missedDeprecations = [];
79239 each(test._expectedDeprecations, function (deprecationPattern, id) {
79240 if (test._observedDeprecations[id] !== 1) {
79241 missedDeprecations.push(deprecationPattern);
79242 }
79243 });
79244 if (missedDeprecations.length !== 0) {
79245 throw new Error('Expected deprecation warnings did not happen: ' +
79246 missedDeprecations.join(' '));
b135bf1a 79247 }
b135bf1a
IC
79248 }
79249 }
79250
db71a655
KM
79251 function matchedDeprecation(name, msg, deprecations) {
79252 if (deprecations == null) {
79253 return -1;
b135bf1a 79254 }
db71a655
KM
79255 for (var i = 0; i < deprecations.length; ++i) {
79256 if (name != null && name === deprecations[i]) {
79257 return i;
79258 }
79259 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
79260 return i;
79261 }
b135bf1a 79262 }
db71a655 79263 return -1;
b135bf1a
IC
79264 }
79265
db71a655 79266 /*global QUnit:false*/
b135bf1a 79267
db71a655 79268 var test = QUnit.test;
b135bf1a 79269
db71a655
KM
79270 function module$1 (name, lifecycle) {
79271 QUnit.module(name, {
c58511b9 79272 beforeEach : function () {
db71a655
KM
79273 moment.locale('en');
79274 moment.createFromInputFallback = function (config) {
79275 throw new Error('input not handled by moment: ' + config._i);
79276 };
79277 setupDeprecationHandler(test, moment, 'core');
79278 if (lifecycle && lifecycle.setup) {
79279 lifecycle.setup();
79280 }
79281 },
c58511b9 79282 afterEach : function () {
db71a655
KM
79283 teardownDeprecationHandler(test, moment, 'core');
79284 if (lifecycle && lifecycle.teardown) {
79285 lifecycle.teardown();
79286 }
73f3c911 79287 }
db71a655
KM
79288 });
79289 }
79290
79291 module$1('weeks in year');
79292
79293 test('isoWeeksInYear', function (assert) {
79294 assert.equal(moment([2004]).isoWeeksInYear(), 53, '2004 has 53 iso weeks');
79295 assert.equal(moment([2005]).isoWeeksInYear(), 52, '2005 has 53 iso weeks');
79296 assert.equal(moment([2006]).isoWeeksInYear(), 52, '2006 has 53 iso weeks');
79297 assert.equal(moment([2007]).isoWeeksInYear(), 52, '2007 has 52 iso weeks');
79298 assert.equal(moment([2008]).isoWeeksInYear(), 52, '2008 has 53 iso weeks');
79299 assert.equal(moment([2009]).isoWeeksInYear(), 53, '2009 has 53 iso weeks');
79300 assert.equal(moment([2010]).isoWeeksInYear(), 52, '2010 has 52 iso weeks');
79301 assert.equal(moment([2011]).isoWeeksInYear(), 52, '2011 has 52 iso weeks');
79302 assert.equal(moment([2012]).isoWeeksInYear(), 52, '2012 has 52 iso weeks');
79303 assert.equal(moment([2013]).isoWeeksInYear(), 52, '2013 has 52 iso weeks');
79304 assert.equal(moment([2014]).isoWeeksInYear(), 52, '2014 has 52 iso weeks');
79305 assert.equal(moment([2015]).isoWeeksInYear(), 53, '2015 has 53 iso weeks');
79306 });
79307
79308 test('weeksInYear doy/dow = 1/4', function (assert) {
79309 moment.locale('1/4', {week: {dow: 1, doy: 4}});
79310
79311 assert.equal(moment([2004]).weeksInYear(), 53, '2004 has 53 weeks');
79312 assert.equal(moment([2005]).weeksInYear(), 52, '2005 has 53 weeks');
79313 assert.equal(moment([2006]).weeksInYear(), 52, '2006 has 53 weeks');
79314 assert.equal(moment([2007]).weeksInYear(), 52, '2007 has 52 weeks');
79315 assert.equal(moment([2008]).weeksInYear(), 52, '2008 has 53 weeks');
79316 assert.equal(moment([2009]).weeksInYear(), 53, '2009 has 53 weeks');
79317 assert.equal(moment([2010]).weeksInYear(), 52, '2010 has 52 weeks');
79318 assert.equal(moment([2011]).weeksInYear(), 52, '2011 has 52 weeks');
79319 assert.equal(moment([2012]).weeksInYear(), 52, '2012 has 52 weeks');
79320 assert.equal(moment([2013]).weeksInYear(), 52, '2013 has 52 weeks');
79321 assert.equal(moment([2014]).weeksInYear(), 52, '2014 has 52 weeks');
79322 assert.equal(moment([2015]).weeksInYear(), 53, '2015 has 53 weeks');
79323 });
79324
79325 test('weeksInYear doy/dow = 6/12', function (assert) {
79326 moment.locale('6/12', {week: {dow: 6, doy: 12}});
79327
79328 assert.equal(moment([2004]).weeksInYear(), 53, '2004 has 53 weeks');
79329 assert.equal(moment([2005]).weeksInYear(), 52, '2005 has 53 weeks');
79330 assert.equal(moment([2006]).weeksInYear(), 52, '2006 has 53 weeks');
79331 assert.equal(moment([2007]).weeksInYear(), 52, '2007 has 52 weeks');
79332 assert.equal(moment([2008]).weeksInYear(), 52, '2008 has 53 weeks');
79333 assert.equal(moment([2009]).weeksInYear(), 52, '2009 has 53 weeks');
79334 assert.equal(moment([2010]).weeksInYear(), 53, '2010 has 52 weeks');
79335 assert.equal(moment([2011]).weeksInYear(), 52, '2011 has 52 weeks');
79336 assert.equal(moment([2012]).weeksInYear(), 52, '2012 has 52 weeks');
79337 assert.equal(moment([2013]).weeksInYear(), 52, '2013 has 52 weeks');
79338 assert.equal(moment([2014]).weeksInYear(), 52, '2014 has 52 weeks');
79339 assert.equal(moment([2015]).weeksInYear(), 52, '2015 has 53 weeks');
79340 });
79341
79342 test('weeksInYear doy/dow = 1/7', function (assert) {
79343 moment.locale('1/7', {week: {dow: 1, doy: 7}});
79344
79345 assert.equal(moment([2004]).weeksInYear(), 52, '2004 has 53 weeks');
79346 assert.equal(moment([2005]).weeksInYear(), 52, '2005 has 53 weeks');
79347 assert.equal(moment([2006]).weeksInYear(), 53, '2006 has 53 weeks');
79348 assert.equal(moment([2007]).weeksInYear(), 52, '2007 has 52 weeks');
79349 assert.equal(moment([2008]).weeksInYear(), 52, '2008 has 53 weeks');
79350 assert.equal(moment([2009]).weeksInYear(), 52, '2009 has 53 weeks');
79351 assert.equal(moment([2010]).weeksInYear(), 52, '2010 has 52 weeks');
79352 assert.equal(moment([2011]).weeksInYear(), 52, '2011 has 52 weeks');
79353 assert.equal(moment([2012]).weeksInYear(), 53, '2012 has 52 weeks');
79354 assert.equal(moment([2013]).weeksInYear(), 52, '2013 has 52 weeks');
79355 assert.equal(moment([2014]).weeksInYear(), 52, '2014 has 52 weeks');
79356 assert.equal(moment([2015]).weeksInYear(), 52, '2015 has 53 weeks');
79357 });
79358
79359 test('weeksInYear doy/dow = 0/6', function (assert) {
79360 moment.locale('0/6', {week: {dow: 0, doy: 6}});
79361
79362 assert.equal(moment([2004]).weeksInYear(), 52, '2004 has 53 weeks');
79363 assert.equal(moment([2005]).weeksInYear(), 53, '2005 has 53 weeks');
79364 assert.equal(moment([2006]).weeksInYear(), 52, '2006 has 53 weeks');
79365 assert.equal(moment([2007]).weeksInYear(), 52, '2007 has 52 weeks');
79366 assert.equal(moment([2008]).weeksInYear(), 52, '2008 has 53 weeks');
79367 assert.equal(moment([2009]).weeksInYear(), 52, '2009 has 53 weeks');
79368 assert.equal(moment([2010]).weeksInYear(), 52, '2010 has 52 weeks');
79369 assert.equal(moment([2011]).weeksInYear(), 53, '2011 has 52 weeks');
79370 assert.equal(moment([2012]).weeksInYear(), 52, '2012 has 52 weeks');
79371 assert.equal(moment([2013]).weeksInYear(), 52, '2013 has 52 weeks');
79372 assert.equal(moment([2014]).weeksInYear(), 52, '2014 has 52 weeks');
79373 assert.equal(moment([2015]).weeksInYear(), 52, '2015 has 53 weeks');
73f3c911 79374 });
b135bf1a 79375
db71a655 79376})));
d6651c21 79377
73f3c911 79378
db71a655
KM
79379;(function (global, factory) {
79380 typeof exports === 'object' && typeof module !== 'undefined'
79381 && typeof require === 'function' ? factory(require('../../moment')) :
79382 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
79383 factory(global.moment)
79384}(this, (function (moment) { 'use strict';
d6651c21 79385
db71a655
KM
79386 function each(array, callback) {
79387 var i;
79388 for (i = 0; i < array.length; i++) {
79389 callback(array[i], i, array);
79390 }
79391 }
d6651c21 79392
db71a655
KM
79393 function setupDeprecationHandler(test, moment$$1, scope) {
79394 test._expectedDeprecations = null;
79395 test._observedDeprecations = null;
79396 test._oldSupress = moment$$1.suppressDeprecationWarnings;
79397 moment$$1.suppressDeprecationWarnings = true;
79398 test.expectedDeprecations = function () {
79399 test._expectedDeprecations = arguments;
79400 test._observedDeprecations = [];
79401 };
79402 moment$$1.deprecationHandler = function (name, msg) {
79403 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
79404 if (deprecationId === -1) {
79405 throw new Error('Unexpected deprecation thrown name=' +
79406 name + ' msg=' + msg);
79407 }
79408 test._observedDeprecations[deprecationId] = 1;
79409 };
79410 }
d6651c21 79411
db71a655
KM
79412 function teardownDeprecationHandler(test, moment$$1, scope) {
79413 moment$$1.suppressDeprecationWarnings = test._oldSupress;
d6651c21 79414
db71a655
KM
79415 if (test._expectedDeprecations != null) {
79416 var missedDeprecations = [];
79417 each(test._expectedDeprecations, function (deprecationPattern, id) {
79418 if (test._observedDeprecations[id] !== 1) {
79419 missedDeprecations.push(deprecationPattern);
79420 }
79421 });
79422 if (missedDeprecations.length !== 0) {
79423 throw new Error('Expected deprecation warnings did not happen: ' +
79424 missedDeprecations.join(' '));
79425 }
79426 }
79427 }
b135bf1a 79428
db71a655
KM
79429 function matchedDeprecation(name, msg, deprecations) {
79430 if (deprecations == null) {
79431 return -1;
79432 }
79433 for (var i = 0; i < deprecations.length; ++i) {
79434 if (name != null && name === deprecations[i]) {
79435 return i;
79436 }
79437 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
79438 return i;
79439 }
79440 }
79441 return -1;
79442 }
516f5f67 79443
db71a655 79444 /*global QUnit:false*/
516f5f67 79445
db71a655 79446 var test = QUnit.test;
c74a101d 79447
db71a655
KM
79448 function module$1 (name, lifecycle) {
79449 QUnit.module(name, {
c58511b9 79450 beforeEach : function () {
db71a655
KM
79451 moment.locale('en');
79452 moment.createFromInputFallback = function (config) {
79453 throw new Error('input not handled by moment: ' + config._i);
79454 };
79455 setupDeprecationHandler(test, moment, 'core');
79456 if (lifecycle && lifecycle.setup) {
79457 lifecycle.setup();
79458 }
79459 },
c58511b9 79460 afterEach : function () {
db71a655
KM
79461 teardownDeprecationHandler(test, moment, 'core');
79462 if (lifecycle && lifecycle.teardown) {
79463 lifecycle.teardown();
79464 }
79465 }
79466 });
79467 }
516f5f67 79468
db71a655
KM
79469 function isNearSpringDST() {
79470 return moment().subtract(1, 'day').utcOffset() !== moment().add(1, 'day').utcOffset();
79471 }
516f5f67 79472
db71a655 79473 module$1('zone switching');
516f5f67 79474
db71a655
KM
79475 test('local to utc, keepLocalTime = true', function (assert) {
79476 var m = moment(),
79477 fmt = 'YYYY-DD-MM HH:mm:ss';
79478 assert.equal(m.clone().utc(true).format(fmt), m.format(fmt), 'local to utc failed to keep local time');
79479 });
d40760af 79480
db71a655
KM
79481 test('local to utc, keepLocalTime = false', function (assert) {
79482 var m = moment();
79483 assert.equal(m.clone().utc().valueOf(), m.valueOf(), 'local to utc failed to keep utc time (implicit)');
79484 assert.equal(m.clone().utc(false).valueOf(), m.valueOf(), 'local to utc failed to keep utc time (explicit)');
79485 });
516f5f67 79486
db71a655
KM
79487 test('local to zone, keepLocalTime = true', function (assert) {
79488 test.expectedDeprecations('moment().zone');
79489 var m = moment(),
79490 fmt = 'YYYY-DD-MM HH:mm:ss',
79491 z;
516f5f67 79492
db71a655
KM
79493 // Apparently there is -12:00 and +14:00
79494 // https://en.wikipedia.org/wiki/UTC+14:00
79495 // https://en.wikipedia.org/wiki/UTC-12:00
79496 for (z = -12; z <= 14; ++z) {
79497 assert.equal(m.clone().zone(z * 60, true).format(fmt), m.format(fmt),
79498 'local to zone(' + z + ':00) failed to keep local time');
b135bf1a 79499 }
db71a655 79500 });
b135bf1a 79501
db71a655
KM
79502 test('local to zone, keepLocalTime = false', function (assert) {
79503 test.expectedDeprecations('moment().zone');
79504 var m = moment(),
79505 z;
73f3c911 79506
db71a655
KM
79507 // Apparently there is -12:00 and +14:00
79508 // https://en.wikipedia.org/wiki/UTC+14:00
79509 // https://en.wikipedia.org/wiki/UTC-12:00
79510 for (z = -12; z <= 14; ++z) {
79511 assert.equal(m.clone().zone(z * 60).valueOf(), m.valueOf(),
79512 'local to zone(' + z + ':00) failed to keep utc time (implicit)');
79513 assert.equal(m.clone().zone(z * 60, false).valueOf(), m.valueOf(),
79514 'local to zone(' + z + ':00) failed to keep utc time (explicit)');
73f3c911 79515 }
db71a655 79516 });
516f5f67 79517
db71a655
KM
79518 test('utc to local, keepLocalTime = true', function (assert) {
79519 // Don't test near the spring DST transition
79520 if (isNearSpringDST()) {
c58511b9 79521 assert.expect(0);
db71a655
KM
79522 return;
79523 }
516f5f67 79524
db71a655
KM
79525 var um = moment.utc(),
79526 fmt = 'YYYY-DD-MM HH:mm:ss';
516f5f67 79527
db71a655
KM
79528 assert.equal(um.clone().local(true).format(fmt), um.format(fmt), 'utc to local failed to keep local time');
79529 });
b135bf1a 79530
db71a655
KM
79531 test('utc to local, keepLocalTime = false', function (assert) {
79532 var um = moment.utc();
79533 assert.equal(um.clone().local().valueOf(), um.valueOf(), 'utc to local failed to keep utc time (implicit)');
79534 assert.equal(um.clone().local(false).valueOf(), um.valueOf(), 'utc to local failed to keep utc time (explicit)');
79535 });
73f3c911 79536
db71a655
KM
79537 test('zone to local, keepLocalTime = true', function (assert) {
79538 // Don't test near the spring DST transition
79539 if (isNearSpringDST()) {
c58511b9 79540 assert.expect(0);
db71a655 79541 return;
d6651c21 79542 }
73f3c911 79543
db71a655 79544 test.expectedDeprecations('moment().zone');
73f3c911 79545
db71a655
KM
79546 var m = moment(),
79547 fmt = 'YYYY-DD-MM HH:mm:ss',
79548 z;
73f3c911 79549
db71a655
KM
79550 // Apparently there is -12:00 and +14:00
79551 // https://en.wikipedia.org/wiki/UTC+14:00
79552 // https://en.wikipedia.org/wiki/UTC-12:00
79553 for (z = -12; z <= 14; ++z) {
79554 m.zone(z * 60);
b135bf1a 79555
db71a655
KM
79556 assert.equal(m.clone().local(true).format(fmt), m.format(fmt),
79557 'zone(' + z + ':00) to local failed to keep local time');
79558 }
79559 });
516f5f67 79560
db71a655
KM
79561 test('zone to local, keepLocalTime = false', function (assert) {
79562 test.expectedDeprecations('moment().zone');
79563 var m = moment(),
79564 z;
516f5f67 79565
db71a655
KM
79566 // Apparently there is -12:00 and +14:00
79567 // https://en.wikipedia.org/wiki/UTC+14:00
79568 // https://en.wikipedia.org/wiki/UTC-12:00
79569 for (z = -12; z <= 14; ++z) {
79570 m.zone(z * 60);
c74a101d 79571
db71a655
KM
79572 assert.equal(m.clone().local(false).valueOf(), m.valueOf(),
79573 'zone(' + z + ':00) to local failed to keep utc time (explicit)');
79574 assert.equal(m.clone().local().valueOf(), m.valueOf(),
79575 'zone(' + z + ':00) to local failed to keep utc time (implicit)');
79576 }
79577 });
73f3c911
IC
79578
79579})));
516f5f67 79580
516f5f67 79581
c74a101d
IC
79582;(function (global, factory) {
79583 typeof exports === 'object' && typeof module !== 'undefined'
79584 && typeof require === 'function' ? factory(require('../../moment')) :
516f5f67
IC
79585 typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
79586 factory(global.moment)
73f3c911 79587}(this, (function (moment) { 'use strict';
516f5f67 79588
db71a655
KM
79589 function each(array, callback) {
79590 var i;
79591 for (i = 0; i < array.length; i++) {
79592 callback(array[i], i, array);
79593 }
b135bf1a
IC
79594 }
79595
db71a655
KM
79596 function setupDeprecationHandler(test, moment$$1, scope) {
79597 test._expectedDeprecations = null;
79598 test._observedDeprecations = null;
79599 test._oldSupress = moment$$1.suppressDeprecationWarnings;
79600 moment$$1.suppressDeprecationWarnings = true;
79601 test.expectedDeprecations = function () {
79602 test._expectedDeprecations = arguments;
79603 test._observedDeprecations = [];
79604 };
79605 moment$$1.deprecationHandler = function (name, msg) {
79606 var deprecationId = matchedDeprecation(name, msg, test._expectedDeprecations);
79607 if (deprecationId === -1) {
79608 throw new Error('Unexpected deprecation thrown name=' +
79609 name + ' msg=' + msg);
79610 }
79611 test._observedDeprecations[deprecationId] = 1;
79612 };
79613 }
73f3c911 79614
db71a655
KM
79615 function teardownDeprecationHandler(test, moment$$1, scope) {
79616 moment$$1.suppressDeprecationWarnings = test._oldSupress;
73f3c911 79617
db71a655
KM
79618 if (test._expectedDeprecations != null) {
79619 var missedDeprecations = [];
79620 each(test._expectedDeprecations, function (deprecationPattern, id) {
79621 if (test._observedDeprecations[id] !== 1) {
79622 missedDeprecations.push(deprecationPattern);
79623 }
79624 });
79625 if (missedDeprecations.length !== 0) {
79626 throw new Error('Expected deprecation warnings did not happen: ' +
79627 missedDeprecations.join(' '));
d6651c21
IC
79628 }
79629 }
73f3c911 79630 }
73f3c911 79631
db71a655
KM
79632 function matchedDeprecation(name, msg, deprecations) {
79633 if (deprecations == null) {
79634 return -1;
73f3c911 79635 }
db71a655
KM
79636 for (var i = 0; i < deprecations.length; ++i) {
79637 if (name != null && name === deprecations[i]) {
79638 return i;
79639 }
79640 if (msg != null && msg.substring(0, deprecations[i].length) === deprecations[i]) {
79641 return i;
79642 }
73f3c911 79643 }
db71a655 79644 return -1;
73f3c911 79645 }
b135bf1a 79646
db71a655 79647 /*global QUnit:false*/
516f5f67 79648
db71a655 79649 var test = QUnit.test;
516f5f67 79650
db71a655
KM
79651 function module$1 (name, lifecycle) {
79652 QUnit.module(name, {
c58511b9 79653 beforeEach : function () {
db71a655
KM
79654 moment.locale('en');
79655 moment.createFromInputFallback = function (config) {
79656 throw new Error('input not handled by moment: ' + config._i);
79657 };
79658 setupDeprecationHandler(test, moment, 'core');
79659 if (lifecycle && lifecycle.setup) {
79660 lifecycle.setup();
79661 }
79662 },
c58511b9 79663 afterEach : function () {
db71a655
KM
79664 teardownDeprecationHandler(test, moment, 'core');
79665 if (lifecycle && lifecycle.teardown) {
79666 lifecycle.teardown();
79667 }
516f5f67 79668 }
db71a655
KM
79669 });
79670 }
516f5f67 79671
db71a655
KM
79672 module$1('zones', {
79673 'setup': function () {
79674 test.expectedDeprecations('moment().zone');
79675 }
79676 });
f2af24d5 79677
db71a655
KM
79678 test('set zone', function (assert) {
79679 var zone = moment();
9483e2a4 79680
db71a655
KM
79681 zone.zone(0);
79682 assert.equal(zone.zone(), 0, 'should be able to set the zone to 0');
9483e2a4 79683
db71a655
KM
79684 zone.zone(60);
79685 assert.equal(zone.zone(), 60, 'should be able to set the zone to 60');
516f5f67 79686
db71a655
KM
79687 zone.zone(-60);
79688 assert.equal(zone.zone(), -60, 'should be able to set the zone to -60');
79689 });
9483e2a4 79690
db71a655
KM
79691 test('set zone shorthand', function (assert) {
79692 var zone = moment();
73f3c911 79693
db71a655
KM
79694 zone.zone(1);
79695 assert.equal(zone.zone(), 60, 'setting the zone to 1 should imply hours and convert to 60');
516f5f67 79696
db71a655
KM
79697 zone.zone(-1);
79698 assert.equal(zone.zone(), -60, 'setting the zone to -1 should imply hours and convert to -60');
516f5f67 79699
db71a655
KM
79700 zone.zone(15);
79701 assert.equal(zone.zone(), 900, 'setting the zone to 15 should imply hours and convert to 900');
73f3c911 79702
db71a655
KM
79703 zone.zone(-15);
79704 assert.equal(zone.zone(), -900, 'setting the zone to -15 should imply hours and convert to -900');
73f3c911 79705
db71a655
KM
79706 zone.zone(16);
79707 assert.equal(zone.zone(), 16, 'setting the zone to 16 should imply minutes');
73f3c911 79708
db71a655
KM
79709 zone.zone(-16);
79710 assert.equal(zone.zone(), -16, 'setting the zone to -16 should imply minutes');
79711 });
73f3c911 79712
db71a655
KM
79713 test('set zone with string', function (assert) {
79714 var zone = moment();
73f3c911 79715
db71a655
KM
79716 zone.zone('+00:00');
79717 assert.equal(zone.zone(), 0, 'set the zone with a timezone string');
516f5f67 79718
db71a655
KM
79719 zone.zone('2013-03-07T07:00:00-08:00');
79720 assert.equal(zone.zone(), 480, 'set the zone with a string that does not begin with the timezone');
516f5f67 79721
db71a655
KM
79722 zone.zone('2013-03-07T07:00:00+0100');
79723 assert.equal(zone.zone(), -60, 'set the zone with a string that uses the +0000 syntax');
516f5f67 79724
db71a655
KM
79725 zone.zone('2013-03-07T07:00:00+02');
79726 assert.equal(zone.zone(), -120, 'set the zone with a string that uses the +00 syntax');
b135bf1a 79727
db71a655
KM
79728 zone.zone('03-07-2013T07:00:00-08:00');
79729 assert.equal(zone.zone(), 480, 'set the zone with a string with a non-ISO 8601 date');
79730 });
73f3c911 79731
db71a655
KM
79732 test('change hours when changing the zone', function (assert) {
79733 var zone = moment.utc([2000, 0, 1, 6]);
d6651c21 79734
db71a655
KM
79735 zone.zone(0);
79736 assert.equal(zone.hour(), 6, 'UTC 6AM should be 6AM at +0000');
d6651c21 79737
db71a655
KM
79738 zone.zone(60);
79739 assert.equal(zone.hour(), 5, 'UTC 6AM should be 5AM at -0100');
d6651c21 79740
db71a655
KM
79741 zone.zone(-60);
79742 assert.equal(zone.hour(), 7, 'UTC 6AM should be 7AM at +0100');
79743 });
b135bf1a 79744
db71a655
KM
79745 test('change minutes when changing the zone', function (assert) {
79746 var zone = moment.utc([2000, 0, 1, 6, 31]);
516f5f67 79747
db71a655
KM
79748 zone.zone(0);
79749 assert.equal(zone.format('HH:mm'), '06:31', 'UTC 6:31AM should be 6:31AM at +0000');
516f5f67 79750
db71a655
KM
79751 zone.zone(30);
79752 assert.equal(zone.format('HH:mm'), '06:01', 'UTC 6:31AM should be 6:01AM at -0030');
c74a101d 79753
db71a655
KM
79754 zone.zone(-30);
79755 assert.equal(zone.format('HH:mm'), '07:01', 'UTC 6:31AM should be 7:01AM at +0030');
73f3c911 79756
db71a655
KM
79757 zone.zone(1380);
79758 assert.equal(zone.format('HH:mm'), '07:31', 'UTC 6:31AM should be 7:31AM at +1380');
79759 });
73f3c911 79760
db71a655
KM
79761 test('distance from the unix epoch', function (assert) {
79762 var zoneA = moment(),
79763 zoneB = moment(zoneA),
79764 zoneC = moment(zoneA),
79765 zoneD = moment(zoneA),
79766 zoneE = moment(zoneA);
73f3c911 79767
db71a655
KM
79768 zoneB.utc();
79769 assert.equal(+zoneA, +zoneB, 'moment should equal moment.utc');
73f3c911 79770
db71a655
KM
79771 zoneC.zone(-60);
79772 assert.equal(+zoneA, +zoneC, 'moment should equal moment.zone(-60)');
516f5f67 79773
db71a655
KM
79774 zoneD.zone(480);
79775 assert.equal(+zoneA, +zoneD, 'moment should equal moment.zone(480)');
73f3c911 79776
db71a655
KM
79777 zoneE.zone(1000);
79778 assert.equal(+zoneA, +zoneE, 'moment should equal moment.zone(1000)');
79779 });
516f5f67 79780
db71a655
KM
79781 test('update offset after changing any values', function (assert) {
79782 var oldOffset = moment.updateOffset,
79783 m = moment.utc([2000, 6, 1]);
516f5f67 79784
db71a655
KM
79785 moment.updateOffset = function (mom, keepTime) {
79786 if (mom.__doChange) {
79787 if (+mom > 962409600000) {
79788 mom.zone(120, keepTime);
79789 } else {
79790 mom.zone(60, keepTime);
79791 }
73f3c911 79792 }
db71a655 79793 };
c74a101d 79794
db71a655
KM
79795 assert.equal(m.format('ZZ'), '+0000', 'should be at +0000');
79796 assert.equal(m.format('HH:mm'), '00:00', 'should start 12AM at +0000 timezone');
516f5f67 79797
db71a655
KM
79798 m.__doChange = true;
79799 m.add(1, 'h');
516f5f67 79800
db71a655
KM
79801 assert.equal(m.format('ZZ'), '-0200', 'should be at -0200');
79802 assert.equal(m.format('HH:mm'), '23:00', '1AM at +0000 should be 11PM at -0200 timezone');
516f5f67 79803
db71a655 79804 m.subtract(1, 'h');
516f5f67 79805
db71a655
KM
79806 assert.equal(m.format('ZZ'), '-0100', 'should be at -0100');
79807 assert.equal(m.format('HH:mm'), '23:00', '12AM at +0000 should be 11PM at -0100 timezone');
516f5f67 79808
db71a655
KM
79809 moment.updateOffset = oldOffset;
79810 });
516f5f67 79811
db71a655
KM
79812 test('getters and setters', function (assert) {
79813 var a = moment([2011, 5, 20]);
516f5f67 79814
db71a655
KM
79815 assert.equal(a.clone().zone(120).year(2012).year(), 2012, 'should get and set year correctly');
79816 assert.equal(a.clone().zone(120).month(1).month(), 1, 'should get and set month correctly');
79817 assert.equal(a.clone().zone(120).date(2).date(), 2, 'should get and set date correctly');
79818 assert.equal(a.clone().zone(120).day(1).day(), 1, 'should get and set day correctly');
79819 assert.equal(a.clone().zone(120).hour(1).hour(), 1, 'should get and set hour correctly');
79820 assert.equal(a.clone().zone(120).minute(1).minute(), 1, 'should get and set minute correctly');
79821 });
516f5f67 79822
db71a655
KM
79823 test('getters', function (assert) {
79824 var a = moment.utc([2012, 0, 1, 0, 0, 0]);
516f5f67 79825
db71a655
KM
79826 assert.equal(a.clone().zone(120).year(), 2011, 'should get year correctly');
79827 assert.equal(a.clone().zone(120).month(), 11, 'should get month correctly');
79828 assert.equal(a.clone().zone(120).date(), 31, 'should get date correctly');
79829 assert.equal(a.clone().zone(120).hour(), 22, 'should get hour correctly');
79830 assert.equal(a.clone().zone(120).minute(), 0, 'should get minute correctly');
516f5f67 79831
db71a655
KM
79832 assert.equal(a.clone().zone(-120).year(), 2012, 'should get year correctly');
79833 assert.equal(a.clone().zone(-120).month(), 0, 'should get month correctly');
79834 assert.equal(a.clone().zone(-120).date(), 1, 'should get date correctly');
79835 assert.equal(a.clone().zone(-120).hour(), 2, 'should get hour correctly');
79836 assert.equal(a.clone().zone(-120).minute(), 0, 'should get minute correctly');
516f5f67 79837
db71a655
KM
79838 assert.equal(a.clone().zone(-90).year(), 2012, 'should get year correctly');
79839 assert.equal(a.clone().zone(-90).month(), 0, 'should get month correctly');
79840 assert.equal(a.clone().zone(-90).date(), 1, 'should get date correctly');
79841 assert.equal(a.clone().zone(-90).hour(), 1, 'should get hour correctly');
79842 assert.equal(a.clone().zone(-90).minute(), 30, 'should get minute correctly');
79843 });
516f5f67 79844
db71a655
KM
79845 test('from', function (assert) {
79846 var zoneA = moment(),
79847 zoneB = moment(zoneA).zone(720),
79848 zoneC = moment(zoneA).zone(360),
79849 zoneD = moment(zoneA).zone(-690),
79850 other = moment(zoneA).add(35, 'm');
516f5f67 79851
db71a655
KM
79852 assert.equal(zoneA.from(other), zoneB.from(other), 'moment#from should be the same in all zones');
79853 assert.equal(zoneA.from(other), zoneC.from(other), 'moment#from should be the same in all zones');
79854 assert.equal(zoneA.from(other), zoneD.from(other), 'moment#from should be the same in all zones');
79855 });
516f5f67 79856
db71a655
KM
79857 test('diff', function (assert) {
79858 var zoneA = moment(),
79859 zoneB = moment(zoneA).zone(720),
79860 zoneC = moment(zoneA).zone(360),
79861 zoneD = moment(zoneA).zone(-690),
79862 other = moment(zoneA).add(35, 'm');
516f5f67 79863
db71a655
KM
79864 assert.equal(zoneA.diff(other), zoneB.diff(other), 'moment#diff should be the same in all zones');
79865 assert.equal(zoneA.diff(other), zoneC.diff(other), 'moment#diff should be the same in all zones');
79866 assert.equal(zoneA.diff(other), zoneD.diff(other), 'moment#diff should be the same in all zones');
516f5f67 79867
db71a655
KM
79868 assert.equal(zoneA.diff(other, 'minute', true), zoneB.diff(other, 'minute', true), 'moment#diff should be the same in all zones');
79869 assert.equal(zoneA.diff(other, 'minute', true), zoneC.diff(other, 'minute', true), 'moment#diff should be the same in all zones');
79870 assert.equal(zoneA.diff(other, 'minute', true), zoneD.diff(other, 'minute', true), 'moment#diff should be the same in all zones');
516f5f67 79871
db71a655
KM
79872 assert.equal(zoneA.diff(other, 'hour', true), zoneB.diff(other, 'hour', true), 'moment#diff should be the same in all zones');
79873 assert.equal(zoneA.diff(other, 'hour', true), zoneC.diff(other, 'hour', true), 'moment#diff should be the same in all zones');
79874 assert.equal(zoneA.diff(other, 'hour', true), zoneD.diff(other, 'hour', true), 'moment#diff should be the same in all zones');
79875 });
516f5f67 79876
db71a655
KM
79877 test('unix offset and timestamp', function (assert) {
79878 var zoneA = moment(),
79879 zoneB = moment(zoneA).zone(720),
79880 zoneC = moment(zoneA).zone(360),
79881 zoneD = moment(zoneA).zone(-690);
516f5f67 79882
db71a655
KM
79883 assert.equal(zoneA.unix(), zoneB.unix(), 'moment#unix should be the same in all zones');
79884 assert.equal(zoneA.unix(), zoneC.unix(), 'moment#unix should be the same in all zones');
79885 assert.equal(zoneA.unix(), zoneD.unix(), 'moment#unix should be the same in all zones');
516f5f67 79886
db71a655
KM
79887 assert.equal(+zoneA, +zoneB, 'moment#valueOf should be the same in all zones');
79888 assert.equal(+zoneA, +zoneC, 'moment#valueOf should be the same in all zones');
79889 assert.equal(+zoneA, +zoneD, 'moment#valueOf should be the same in all zones');
79890 });
516f5f67 79891
db71a655
KM
79892 test('cloning', function (assert) {
79893 assert.equal(moment().zone(120).clone().zone(), 120, 'explicit cloning should retain the zone');
79894 assert.equal(moment().zone(-120).clone().zone(), -120, 'explicit cloning should retain the zone');
79895 assert.equal(moment(moment().zone(120)).zone(), 120, 'implicit cloning should retain the zone');
79896 assert.equal(moment(moment().zone(-120)).zone(), -120, 'implicit cloning should retain the zone');
79897 });
516f5f67 79898
db71a655
KM
79899 test('start of / end of', function (assert) {
79900 var a = moment.utc([2010, 1, 2, 0, 0, 0]).zone(450);
516f5f67 79901
db71a655
KM
79902 assert.equal(a.clone().startOf('day').hour(), 0, 'start of day should work on moments with a zone');
79903 assert.equal(a.clone().startOf('day').minute(), 0, 'start of day should work on moments with a zone');
79904 assert.equal(a.clone().startOf('hour').minute(), 0, 'start of hour should work on moments with a zone');
516f5f67 79905
db71a655
KM
79906 assert.equal(a.clone().endOf('day').hour(), 23, 'end of day should work on moments with a zone');
79907 assert.equal(a.clone().endOf('day').minute(), 59, 'end of day should work on moments with a zone');
79908 assert.equal(a.clone().endOf('hour').minute(), 59, 'end of hour should work on moments with a zone');
79909 });
516f5f67 79910
db71a655
KM
79911 test('reset zone with moment#utc', function (assert) {
79912 var a = moment.utc([2012]).zone(480);
516f5f67 79913
db71a655
KM
79914 assert.equal(a.clone().hour(), 16, 'different zone should have different hour');
79915 assert.equal(a.clone().utc().hour(), 0, 'calling moment#utc should reset the offset');
79916 });
516f5f67 79917
db71a655
KM
79918 test('reset zone with moment#local', function (assert) {
79919 var a = moment([2012]).zone(480);
516f5f67 79920
db71a655 79921 assert.equal(a.clone().local().hour(), 0, 'calling moment#local should reset the offset');
516f5f67 79922 });
73f3c911 79923
db71a655
KM
79924 test('toDate', function (assert) {
79925 var zoneA = new Date(),
79926 zoneB = moment(zoneA).zone(720).toDate(),
79927 zoneC = moment(zoneA).zone(360).toDate(),
79928 zoneD = moment(zoneA).zone(-690).toDate();
516f5f67 79929
db71a655
KM
79930 assert.equal(+zoneA, +zoneB, 'moment#toDate should output a date with the right unix timestamp');
79931 assert.equal(+zoneA, +zoneC, 'moment#toDate should output a date with the right unix timestamp');
79932 assert.equal(+zoneA, +zoneD, 'moment#toDate should output a date with the right unix timestamp');
79933 });
516f5f67 79934
db71a655
KM
79935 test('same / before / after', function (assert) {
79936 var zoneA = moment().utc(),
79937 zoneB = moment(zoneA).zone(120),
79938 zoneC = moment(zoneA).zone(-120);
516f5f67 79939
db71a655
KM
79940 assert.ok(zoneA.isSame(zoneB), 'two moments with different offsets should be the same');
79941 assert.ok(zoneA.isSame(zoneC), 'two moments with different offsets should be the same');
516f5f67 79942
db71a655
KM
79943 assert.ok(zoneA.isSame(zoneB, 'hour'), 'two moments with different offsets should be the same hour');
79944 assert.ok(zoneA.isSame(zoneC, 'hour'), 'two moments with different offsets should be the same hour');
516f5f67 79945
db71a655 79946 zoneA.add(1, 'hour');
516f5f67 79947
db71a655
KM
79948 assert.ok(zoneA.isAfter(zoneB), 'isAfter should work with two moments with different offsets');
79949 assert.ok(zoneA.isAfter(zoneC), 'isAfter should work with two moments with different offsets');
516f5f67 79950
db71a655
KM
79951 assert.ok(zoneA.isAfter(zoneB, 'hour'), 'isAfter:hour should work with two moments with different offsets');
79952 assert.ok(zoneA.isAfter(zoneC, 'hour'), 'isAfter:hour should work with two moments with different offsets');
516f5f67 79953
db71a655 79954 zoneA.subtract(2, 'hour');
516f5f67 79955
db71a655
KM
79956 assert.ok(zoneA.isBefore(zoneB), 'isBefore should work with two moments with different offsets');
79957 assert.ok(zoneA.isBefore(zoneC), 'isBefore should work with two moments with different offsets');
516f5f67 79958
db71a655
KM
79959 assert.ok(zoneA.isBefore(zoneB, 'hour'), 'isBefore:hour should work with two moments with different offsets');
79960 assert.ok(zoneA.isBefore(zoneC, 'hour'), 'isBefore:hour should work with two moments with different offsets');
79961 });
516f5f67 79962
db71a655
KM
79963 test('add / subtract over dst', function (assert) {
79964 var oldOffset = moment.updateOffset,
79965 m = moment.utc([2000, 2, 31, 3]);
516f5f67 79966
db71a655
KM
79967 moment.updateOffset = function (mom, keepTime) {
79968 if (mom.clone().utc().month() > 2) {
79969 mom.zone(-60, keepTime);
79970 } else {
79971 mom.zone(0, keepTime);
79972 }
79973 };
516f5f67 79974
db71a655 79975 assert.equal(m.hour(), 3, 'should start at 00:00');
516f5f67 79976
db71a655 79977 m.add(24, 'hour');
516f5f67 79978
db71a655 79979 assert.equal(m.hour(), 4, 'adding 24 hours should disregard dst');
516f5f67 79980
db71a655 79981 m.subtract(24, 'hour');
516f5f67 79982
db71a655 79983 assert.equal(m.hour(), 3, 'subtracting 24 hours should disregard dst');
516f5f67 79984
db71a655 79985 m.add(1, 'day');
516f5f67 79986
db71a655 79987 assert.equal(m.hour(), 3, 'adding 1 day should have the same hour');
516f5f67 79988
db71a655 79989 m.subtract(1, 'day');
516f5f67 79990
db71a655 79991 assert.equal(m.hour(), 3, 'subtracting 1 day should have the same hour');
516f5f67 79992
db71a655 79993 m.add(1, 'month');
516f5f67 79994
db71a655 79995 assert.equal(m.hour(), 3, 'adding 1 month should have the same hour');
516f5f67 79996
db71a655 79997 m.subtract(1, 'month');
516f5f67 79998
db71a655 79999 assert.equal(m.hour(), 3, 'subtracting 1 month should have the same hour');
516f5f67 80000
db71a655
KM
80001 moment.updateOffset = oldOffset;
80002 });
516f5f67 80003
db71a655
KM
80004 test('isDST', function (assert) {
80005 var oldOffset = moment.updateOffset;
516f5f67 80006
db71a655
KM
80007 moment.updateOffset = function (mom, keepTime) {
80008 if (mom.month() > 2 && mom.month() < 9) {
80009 mom.zone(-60, keepTime);
80010 } else {
80011 mom.zone(0, keepTime);
80012 }
80013 };
516f5f67 80014
db71a655
KM
80015 assert.ok(!moment().month(0).isDST(), 'Jan should not be summer dst');
80016 assert.ok(moment().month(6).isDST(), 'Jul should be summer dst');
80017 assert.ok(!moment().month(11).isDST(), 'Dec should not be summer dst');
516f5f67 80018
db71a655
KM
80019 moment.updateOffset = function (mom) {
80020 if (mom.month() > 2 && mom.month() < 9) {
80021 mom.zone(0);
80022 } else {
80023 mom.zone(-60);
80024 }
80025 };
516f5f67 80026
db71a655
KM
80027 assert.ok(moment().month(0).isDST(), 'Jan should be winter dst');
80028 assert.ok(!moment().month(6).isDST(), 'Jul should not be winter dst');
80029 assert.ok(moment().month(11).isDST(), 'Dec should be winter dst');
516f5f67 80030
db71a655
KM
80031 moment.updateOffset = oldOffset;
80032 });
516f5f67 80033
db71a655
KM
80034 test('zone names', function (assert) {
80035 test.expectedDeprecations();
80036 assert.equal(moment().zoneAbbr(), '', 'Local zone abbr should be empty');
80037 assert.equal(moment().format('z'), '', 'Local zone formatted abbr should be empty');
80038 assert.equal(moment().zoneName(), '', 'Local zone name should be empty');
80039 assert.equal(moment().format('zz'), '', 'Local zone formatted name should be empty');
73f3c911 80040
db71a655
KM
80041 assert.equal(moment.utc().zoneAbbr(), 'UTC', 'UTC zone abbr should be UTC');
80042 assert.equal(moment.utc().format('z'), 'UTC', 'UTC zone formatted abbr should be UTC');
80043 assert.equal(moment.utc().zoneName(), 'Coordinated Universal Time', 'UTC zone abbr should be Coordinated Universal Time');
80044 assert.equal(moment.utc().format('zz'), 'Coordinated Universal Time', 'UTC zone formatted abbr should be Coordinated Universal Time');
80045 });
516f5f67 80046
db71a655
KM
80047 test('hours alignment with UTC', function (assert) {
80048 assert.equal(moment().zone(120).hasAlignedHourOffset(), true);
80049 assert.equal(moment().zone(-180).hasAlignedHourOffset(), true);
80050 assert.equal(moment().zone(90).hasAlignedHourOffset(), false);
80051 assert.equal(moment().zone(-90).hasAlignedHourOffset(), false);
80052 });
516f5f67 80053
db71a655
KM
80054 test('hours alignment with other zone', function (assert) {
80055 var m = moment().zone(120);
516f5f67 80056
db71a655
KM
80057 assert.equal(m.hasAlignedHourOffset(moment().zone(180)), true);
80058 assert.equal(m.hasAlignedHourOffset(moment().zone(-180)), true);
80059 assert.equal(m.hasAlignedHourOffset(moment().zone(90)), false);
80060 assert.equal(m.hasAlignedHourOffset(moment().zone(-90)), false);
516f5f67 80061
db71a655 80062 m = moment().zone(90);
516f5f67 80063
db71a655
KM
80064 assert.equal(m.hasAlignedHourOffset(moment().zone(180)), false);
80065 assert.equal(m.hasAlignedHourOffset(moment().zone(-180)), false);
80066 assert.equal(m.hasAlignedHourOffset(moment().zone(30)), true);
80067 assert.equal(m.hasAlignedHourOffset(moment().zone(-30)), true);
516f5f67 80068
db71a655 80069 m = moment().zone(-60);
516f5f67 80070
db71a655
KM
80071 assert.equal(m.hasAlignedHourOffset(moment().zone(180)), true);
80072 assert.equal(m.hasAlignedHourOffset(moment().zone(-180)), true);
80073 assert.equal(m.hasAlignedHourOffset(moment().zone(90)), false);
80074 assert.equal(m.hasAlignedHourOffset(moment().zone(-90)), false);
516f5f67 80075
db71a655 80076 m = moment().zone(25);
516f5f67 80077
db71a655
KM
80078 assert.equal(m.hasAlignedHourOffset(moment().zone(-35)), true);
80079 assert.equal(m.hasAlignedHourOffset(moment().zone(85)), true);
516f5f67 80080
db71a655
KM
80081 assert.equal(m.hasAlignedHourOffset(moment().zone(35)), false);
80082 assert.equal(m.hasAlignedHourOffset(moment().zone(-85)), false);
80083 });
516f5f67 80084
db71a655
KM
80085 test('parse zone', function (assert) {
80086 var m = moment('2013-01-01T00:00:00-13:00').parseZone();
80087 assert.equal(m.zone(), 13 * 60);
80088 assert.equal(m.hours(), 0);
80089 });
516f5f67 80090
db71a655
KM
80091 test('parse zone static', function (assert) {
80092 var m = moment.parseZone('2013-01-01T00:00:00-13:00');
80093 assert.equal(m.zone(), 13 * 60);
80094 assert.equal(m.hours(), 0);
80095 });
516f5f67 80096
db71a655
KM
80097 test('parse zone with more arguments', function (assert) {
80098 test.expectedDeprecations();
80099 var m;
80100 m = moment.parseZone('2013 01 01 05 -13:00', 'YYYY MM DD HH ZZ');
80101 assert.equal(m.format(), '2013-01-01T05:00:00-13:00', 'accept input and format');
80102 m = moment.parseZone('2013-01-01-13:00', 'YYYY MM DD ZZ', true);
80103 assert.equal(m.isValid(), false, 'accept input, format and strict flag');
80104 m = moment.parseZone('2013-01-01-13:00', ['DD MM YYYY ZZ', 'YYYY MM DD ZZ']);
80105 assert.equal(m.format(), '2013-01-01T00:00:00-13:00', 'accept input and array of formats');
80106 });
516f5f67 80107
db71a655
KM
80108 test('parse zone with a timezone from the format string', function (assert) {
80109 var m = moment('11-12-2013 -0400 +1100', 'DD-MM-YYYY ZZ #####').parseZone();
516f5f67 80110
db71a655
KM
80111 assert.equal(m.zone(), 4 * 60);
80112 });
516f5f67 80113
db71a655
KM
80114 test('parse zone without a timezone included in the format string', function (assert) {
80115 var m = moment('11-12-2013 -0400 +1100', 'DD-MM-YYYY').parseZone();
516f5f67 80116
db71a655
KM
80117 assert.equal(m.zone(), -11 * 60);
80118 });
516f5f67 80119
db71a655
KM
80120 test('timezone format', function (assert) {
80121 assert.equal(moment().zone(-60).format('ZZ'), '+0100', '-60 -> +0100');
80122 assert.equal(moment().zone(-90).format('ZZ'), '+0130', '-90 -> +0130');
80123 assert.equal(moment().zone(-120).format('ZZ'), '+0200', '-120 -> +0200');
516f5f67 80124
db71a655
KM
80125 assert.equal(moment().zone(+60).format('ZZ'), '-0100', '+60 -> -0100');
80126 assert.equal(moment().zone(+90).format('ZZ'), '-0130', '+90 -> -0130');
80127 assert.equal(moment().zone(+120).format('ZZ'), '-0200', '+120 -> -0200');
80128 });
516f5f67 80129
db71a655
KM
80130 test('parse zone without a timezone', function (assert) {
80131 test.expectedDeprecations();
80132 var m1 = moment.parseZone('2016-02-01T00:00:00');
80133 var m2 = moment.parseZone('2016-02-01T00:00:00Z');
80134 var m3 = moment.parseZone('2016-02-01T00:00:00+00:00'); //Someone might argue this is not necessary, you could even argue that is wrong being here.
80135 var m4 = moment.parseZone('2016-02-01T00:00:00+0000'); //Someone might argue this is not necessary, you could even argue that is wrong being here.
80136 assert.equal(
80137 m1.format('M D YYYY HH:mm:ss ZZ'),
80138 '2 1 2016 00:00:00 +0000',
80139 'Not providing a timezone should keep the time and change the zone to 0'
80140 );
80141 assert.equal(
80142 m2.format('M D YYYY HH:mm:ss ZZ'),
80143 '2 1 2016 00:00:00 +0000',
80144 'Not providing a timezone should keep the time and change the zone to 0'
80145 );
80146 assert.equal(
80147 m3.format('M D YYYY HH:mm:ss ZZ'),
80148 '2 1 2016 00:00:00 +0000',
80149 'Not providing a timezone should keep the time and change the zone to 0'
80150 );
80151 assert.equal(
80152 m4.format('M D YYYY HH:mm:ss ZZ'),
80153 '2 1 2016 00:00:00 +0000',
80154 'Not providing a timezone should keep the time and change the zone to 0'
80155 );
80156 });
c587bf00 80157
db71a655
KM
80158 test('parse zone with a minutes unit abs less than 16 should retain minutes', function (assert) {
80159 //ensure when minutes are explicitly parsed, they are retained
80160 //instead of converted to hours, even if less than 16
80161 var n = moment.parseZone('2013-01-01T00:00:00-00:15');
80162 assert.equal(n.utcOffset(), -15);
80163 assert.equal(n.zone(), 15);
80164 assert.equal(n.hour(), 0);
80165 var o = moment.parseZone('2013-01-01T00:00:00+00:15');
80166 assert.equal(o.utcOffset(), 15);
80167 assert.equal(o.zone(), -15);
80168 assert.equal(o.hour(), 0);
80169 });
73f3c911 80170
db71a655
KM
80171 test('parse zone with weekday on verifies day acccording to the offset', function (assert) {
80172 test.expectedDeprecations();
80173 assert.ok(moment.parseZone('Mon 03:59 +12:00', 'ddd HH:mm Z', true).isValid(), 'Monday 03:59');
80174 });
fea48bb6 80175
73f3c911 80176})));