Mercurial > hg > NetworkVis
comparison query_builder/moment/min/tests.js @ 26:22be4ea663a7
Trying to work out having json request from neo4j display properly in drop down selectize box
author | arussell |
---|---|
date | Tue, 01 Dec 2015 02:07:13 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
25:f82512502b31 | 26:22be4ea663a7 |
---|---|
1 | |
2 (function (global, factory) { | |
3 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
4 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
5 factory(global.moment) | |
6 }(this, function (moment) { 'use strict'; | |
7 | |
8 /*global QUnit:false*/ | |
9 | |
10 var test = QUnit.test; | |
11 | |
12 function module (name, lifecycle) { | |
13 QUnit.module(name, { | |
14 setup : function () { | |
15 moment.locale('en'); | |
16 moment.createFromInputFallback = function () { | |
17 throw new Error('input not handled by moment'); | |
18 }; | |
19 if (lifecycle && lifecycle.setup) { | |
20 lifecycle.setup(); | |
21 } | |
22 }, | |
23 teardown : function () { | |
24 if (lifecycle && lifecycle.teardown) { | |
25 lifecycle.teardown(); | |
26 } | |
27 } | |
28 }); | |
29 } | |
30 | |
31 function localeModule (name, lifecycle) { | |
32 QUnit.module('locale:' + name, { | |
33 setup : function () { | |
34 moment.locale(name); | |
35 moment.createFromInputFallback = function () { | |
36 throw new Error('input not handled by moment'); | |
37 }; | |
38 if (lifecycle && lifecycle.setup) { | |
39 lifecycle.setup(); | |
40 } | |
41 }, | |
42 teardown : function () { | |
43 moment.locale('en'); | |
44 if (lifecycle && lifecycle.teardown) { | |
45 lifecycle.teardown(); | |
46 } | |
47 } | |
48 }); | |
49 } | |
50 | |
51 localeModule('af'); | |
52 | |
53 test('parse', function (assert) { | |
54 var tests = 'Januarie Jan_Februarie Feb_Maart Mar_April Apr_Mei Mei_Junie Jun_Julie Jul_Augustus Aug_September Sep_Oktober Okt_November Nov_Desember Des'.split('_'), i; | |
55 function equalTest(input, mmm, i) { | |
56 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
57 } | |
58 for (i = 0; i < 12; i++) { | |
59 tests[i] = tests[i].split(' '); | |
60 equalTest(tests[i][0], 'MMM', i); | |
61 equalTest(tests[i][1], 'MMM', i); | |
62 equalTest(tests[i][0], 'MMMM', i); | |
63 equalTest(tests[i][1], 'MMMM', i); | |
64 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
65 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
66 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
67 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
68 } | |
69 }); | |
70 | |
71 test('format', function (assert) { | |
72 var a = [ | |
73 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Sondag, Februarie 14de 2010, 3:25:50 nm'], | |
74 ['ddd, hA', 'Son, 3NM'], | |
75 ['M Mo MM MMMM MMM', '2 2de 02 Februarie Feb'], | |
76 ['YYYY YY', '2010 10'], | |
77 ['D Do DD', '14 14de 14'], | |
78 ['d do dddd ddd dd', '0 0de Sondag Son So'], | |
79 ['DDD DDDo DDDD', '45 45ste 045'], | |
80 ['w wo ww', '6 6de 06'], | |
81 ['h hh', '3 03'], | |
82 ['H HH', '15 15'], | |
83 ['m mm', '25 25'], | |
84 ['s ss', '50 50'], | |
85 ['a A', 'nm NM'], | |
86 ['[the] DDDo [day of the year]', 'the 45ste day of the year'], | |
87 ['LT', '15:25'], | |
88 ['LTS', '15:25:50'], | |
89 ['L', '14/02/2010'], | |
90 ['LL', '14 Februarie 2010'], | |
91 ['LLL', '14 Februarie 2010 15:25'], | |
92 ['LLLL', 'Sondag, 14 Februarie 2010 15:25'], | |
93 ['l', '14/2/2010'], | |
94 ['ll', '14 Feb 2010'], | |
95 ['lll', '14 Feb 2010 15:25'], | |
96 ['llll', 'Son, 14 Feb 2010 15:25'] | |
97 ], | |
98 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
99 i; | |
100 for (i = 0; i < a.length; i++) { | |
101 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
102 } | |
103 }); | |
104 | |
105 test('format ordinal', function (assert) { | |
106 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1ste', '1ste'); | |
107 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2de', '2de'); | |
108 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3de', '3de'); | |
109 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4de', '4de'); | |
110 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5de', '5de'); | |
111 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6de', '6de'); | |
112 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7de', '7de'); | |
113 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8ste', '8ste'); | |
114 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9de', '9de'); | |
115 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10de', '10de'); | |
116 | |
117 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11de', '11de'); | |
118 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12de', '12de'); | |
119 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13de', '13de'); | |
120 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14de', '14de'); | |
121 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15de', '15de'); | |
122 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16de', '16de'); | |
123 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17de', '17de'); | |
124 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18de', '18de'); | |
125 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19de', '19de'); | |
126 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20ste', '20ste'); | |
127 | |
128 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21ste', '21ste'); | |
129 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22ste', '22ste'); | |
130 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23ste', '23ste'); | |
131 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24ste', '24ste'); | |
132 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25ste', '25ste'); | |
133 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26ste', '26ste'); | |
134 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27ste', '27ste'); | |
135 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28ste', '28ste'); | |
136 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29ste', '29ste'); | |
137 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30ste', '30ste'); | |
138 | |
139 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31ste', '31ste'); | |
140 }); | |
141 | |
142 test('format month', function (assert) { | |
143 var expected = 'Januarie Jan_Februarie Feb_Maart Mar_April Apr_Mei Mei_Junie Jun_Julie Jul_Augustus Aug_September Sep_Oktober Okt_November Nov_Desember Des'.split('_'), i; | |
144 for (i = 0; i < expected.length; i++) { | |
145 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
146 } | |
147 }); | |
148 | |
149 test('format week', function (assert) { | |
150 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; | |
151 for (i = 0; i < expected.length; i++) { | |
152 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
153 } | |
154 }); | |
155 | |
156 test('from', function (assert) { | |
157 var start = moment([2007, 1, 28]); | |
158 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), '\'n paar sekondes', '44 seconds = a few seconds'); | |
159 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '\'n minuut', '45 seconds = a minute'); | |
160 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '\'n minuut', '89 seconds = a minute'); | |
161 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minute', '90 seconds = 2 minutes'); | |
162 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minute', '44 minutes = 44 minutes'); | |
163 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '\'n uur', '45 minutes = an hour'); | |
164 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '\'n uur', '89 minutes = an hour'); | |
165 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ure', '90 minutes = 2 hours'); | |
166 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ure', '5 hours = 5 hours'); | |
167 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ure', '21 hours = 21 hours'); | |
168 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '\'n dag', '22 hours = a day'); | |
169 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '\'n dag', '35 hours = a day'); | |
170 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dae', '36 hours = 2 days'); | |
171 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '\'n dag', '1 day = a day'); | |
172 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dae', '5 days = 5 days'); | |
173 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dae', '25 days = 25 days'); | |
174 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '\'n maand', '26 days = a month'); | |
175 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '\'n maand', '30 days = a month'); | |
176 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '\'n maand', '43 days = a month'); | |
177 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 maande', '46 days = 2 months'); | |
178 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 maande', '75 days = 2 months'); | |
179 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 maande', '76 days = 3 months'); | |
180 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '\'n maand', '1 month = a month'); | |
181 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 maande', '5 months = 5 months'); | |
182 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '\'n jaar', '345 days = a year'); | |
183 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 jaar', '548 days = 2 years'); | |
184 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '\'n jaar', '1 year = a year'); | |
185 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 jaar', '5 years = 5 years'); | |
186 }); | |
187 | |
188 test('suffix', function (assert) { | |
189 assert.equal(moment(30000).from(0), 'oor \'n paar sekondes', 'prefix'); | |
190 assert.equal(moment(0).from(30000), '\'n paar sekondes gelede', 'suffix'); | |
191 }); | |
192 | |
193 test('now from now', function (assert) { | |
194 assert.equal(moment().fromNow(), '\'n paar sekondes gelede', 'now from now should display as in the past'); | |
195 }); | |
196 | |
197 test('fromNow', function (assert) { | |
198 assert.equal(moment().add({s: 30}).fromNow(), 'oor \'n paar sekondes', 'in a few seconds'); | |
199 assert.equal(moment().add({d: 5}).fromNow(), 'oor 5 dae', 'in 5 days'); | |
200 }); | |
201 | |
202 test('calendar day', function (assert) { | |
203 var a = moment().hours(2).minutes(0).seconds(0); | |
204 | |
205 assert.equal(moment(a).calendar(), 'Vandag om 02:00', 'today at the same time'); | |
206 assert.equal(moment(a).add({m: 25}).calendar(), 'Vandag om 02:25', 'Now plus 25 min'); | |
207 assert.equal(moment(a).add({h: 1}).calendar(), 'Vandag om 03:00', 'Now plus 1 hour'); | |
208 assert.equal(moment(a).add({d: 1}).calendar(), 'Môre om 02:00', 'tomorrow at the same time'); | |
209 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Vandag om 01:00', 'Now minus 1 hour'); | |
210 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Gister om 02:00', 'yesterday at the same time'); | |
211 }); | |
212 | |
213 test('calendar next week', function (assert) { | |
214 var i, m; | |
215 for (i = 2; i < 7; i++) { | |
216 m = moment().add({d: i}); | |
217 assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days current time'); | |
218 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
219 assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days beginning of day'); | |
220 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
221 assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days end of day'); | |
222 } | |
223 }); | |
224 | |
225 test('calendar last week', function (assert) { | |
226 var i, m; | |
227 for (i = 2; i < 7; i++) { | |
228 m = moment().subtract({d: i}); | |
229 assert.equal(m.calendar(), m.format('[Laas] dddd [om] LT'), 'Today - ' + i + ' days current time'); | |
230 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
231 assert.equal(m.calendar(), m.format('[Laas] dddd [om] LT'), 'Today - ' + i + ' days beginning of day'); | |
232 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
233 assert.equal(m.calendar(), m.format('[Laas] dddd [om] LT'), 'Today - ' + i + ' days end of day'); | |
234 } | |
235 }); | |
236 | |
237 test('calendar all else', function (assert) { | |
238 var weeksAgo = moment().subtract({w: 1}), | |
239 weeksFromNow = moment().add({w: 1}); | |
240 | |
241 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
242 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
243 | |
244 weeksAgo = moment().subtract({w: 2}); | |
245 weeksFromNow = moment().add({w: 2}); | |
246 | |
247 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
248 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
249 }); | |
250 | |
251 test('weeks year starting sunday', function (assert) { | |
252 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
253 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
254 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
255 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
256 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
257 }); | |
258 | |
259 test('weeks year starting monday', function (assert) { | |
260 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
261 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
262 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
263 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
264 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
265 }); | |
266 | |
267 test('weeks year starting tuesday', function (assert) { | |
268 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
269 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
270 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
271 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
272 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
273 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
274 }); | |
275 | |
276 test('weeks year starting wednesday', function (assert) { | |
277 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
278 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
279 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
280 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
281 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
282 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
283 }); | |
284 | |
285 test('weeks year starting thursday', function (assert) { | |
286 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
287 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
288 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
289 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
290 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
291 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
292 }); | |
293 | |
294 test('weeks year starting friday', function (assert) { | |
295 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
296 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
297 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
298 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
299 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
300 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
301 }); | |
302 | |
303 test('weeks year starting saturday', function (assert) { | |
304 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
305 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
306 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
307 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
308 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
309 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
310 }); | |
311 | |
312 test('weeks year starting sunday formatted', function (assert) { | |
313 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52ste', 'Jan 1 2012 should be week 52'); | |
314 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1ste', 'Jan 2 2012 should be week 1'); | |
315 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1ste', 'Jan 8 2012 should be week 1'); | |
316 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2de', 'Jan 9 2012 should be week 2'); | |
317 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2de', 'Jan 15 2012 should be week 2'); | |
318 }); | |
319 | |
320 test('lenient ordinal parsing', function (assert) { | |
321 var i, ordinalStr, testMoment; | |
322 for (i = 1; i <= 31; ++i) { | |
323 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
324 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
325 assert.equal(testMoment.year(), 2014, | |
326 'lenient ordinal parsing ' + i + ' year check'); | |
327 assert.equal(testMoment.month(), 0, | |
328 'lenient ordinal parsing ' + i + ' month check'); | |
329 assert.equal(testMoment.date(), i, | |
330 'lenient ordinal parsing ' + i + ' date check'); | |
331 } | |
332 }); | |
333 | |
334 test('lenient ordinal parsing of number', function (assert) { | |
335 var i, testMoment; | |
336 for (i = 1; i <= 31; ++i) { | |
337 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
338 assert.equal(testMoment.year(), 2014, | |
339 'lenient ordinal parsing of number ' + i + ' year check'); | |
340 assert.equal(testMoment.month(), 0, | |
341 'lenient ordinal parsing of number ' + i + ' month check'); | |
342 assert.equal(testMoment.date(), i, | |
343 'lenient ordinal parsing of number ' + i + ' date check'); | |
344 } | |
345 }); | |
346 | |
347 test('strict ordinal parsing', function (assert) { | |
348 var i, ordinalStr, testMoment; | |
349 for (i = 1; i <= 31; ++i) { | |
350 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
351 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
352 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
353 } | |
354 }); | |
355 | |
356 })); | |
357 | |
358 (function (global, factory) { | |
359 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
360 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
361 factory(global.moment) | |
362 }(this, function (moment) { 'use strict'; | |
363 | |
364 /*global QUnit:false*/ | |
365 | |
366 var test = QUnit.test; | |
367 | |
368 function module (name, lifecycle) { | |
369 QUnit.module(name, { | |
370 setup : function () { | |
371 moment.locale('en'); | |
372 moment.createFromInputFallback = function () { | |
373 throw new Error('input not handled by moment'); | |
374 }; | |
375 if (lifecycle && lifecycle.setup) { | |
376 lifecycle.setup(); | |
377 } | |
378 }, | |
379 teardown : function () { | |
380 if (lifecycle && lifecycle.teardown) { | |
381 lifecycle.teardown(); | |
382 } | |
383 } | |
384 }); | |
385 } | |
386 | |
387 function localeModule (name, lifecycle) { | |
388 QUnit.module('locale:' + name, { | |
389 setup : function () { | |
390 moment.locale(name); | |
391 moment.createFromInputFallback = function () { | |
392 throw new Error('input not handled by moment'); | |
393 }; | |
394 if (lifecycle && lifecycle.setup) { | |
395 lifecycle.setup(); | |
396 } | |
397 }, | |
398 teardown : function () { | |
399 moment.locale('en'); | |
400 if (lifecycle && lifecycle.teardown) { | |
401 lifecycle.teardown(); | |
402 } | |
403 } | |
404 }); | |
405 } | |
406 | |
407 localeModule('ar-ma'); | |
408 | |
409 test('parse', function (assert) { | |
410 var tests = 'يناير:يناير_فبراير:فبراير_مارس:مارس_أبريل:أبريل_ماي:ماي_يونيو:يونيو_يوليوز:يوليوز_غشت:غشت_شتنبر:شتنبر_أكتوبر:أكتوبر_نونبر:نونبر_دجنبر:دجنبر'.split('_'), i; | |
411 function equalTest(input, mmm, i) { | |
412 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
413 } | |
414 for (i = 0; i < 12; i++) { | |
415 tests[i] = tests[i].split(':'); | |
416 equalTest(tests[i][0], 'MMM', i); | |
417 equalTest(tests[i][1], 'MMM', i); | |
418 equalTest(tests[i][0], 'MMMM', i); | |
419 equalTest(tests[i][1], 'MMMM', i); | |
420 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
421 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
422 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
423 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
424 } | |
425 }); | |
426 | |
427 test('format', function (assert) { | |
428 var a = [ | |
429 ['dddd, MMMM Do YYYY, h:mm:ss a', 'الأحد, فبراير 14 2010, 3:25:50 pm'], | |
430 ['ddd, hA', 'احد, 3PM'], | |
431 ['M Mo MM MMMM MMM', '2 2 02 فبراير فبراير'], | |
432 ['YYYY YY', '2010 10'], | |
433 ['D Do DD', '14 14 14'], | |
434 ['d do dddd ddd dd', '0 0 الأحد احد ح'], | |
435 ['DDD DDDo DDDD', '45 45 045'], | |
436 ['w wo ww', '8 8 08'], | |
437 ['h hh', '3 03'], | |
438 ['H HH', '15 15'], | |
439 ['m mm', '25 25'], | |
440 ['s ss', '50 50'], | |
441 ['a A', 'pm PM'], | |
442 ['[the] DDDo [day of the year]', 'the 45 day of the year'], | |
443 ['LT', '15:25'], | |
444 ['LTS', '15:25:50'], | |
445 ['L', '14/02/2010'], | |
446 ['LL', '14 فبراير 2010'], | |
447 ['LLL', '14 فبراير 2010 15:25'], | |
448 ['LLLL', 'الأحد 14 فبراير 2010 15:25'], | |
449 ['l', '14/2/2010'], | |
450 ['ll', '14 فبراير 2010'], | |
451 ['lll', '14 فبراير 2010 15:25'], | |
452 ['llll', 'احد 14 فبراير 2010 15:25'] | |
453 ], | |
454 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
455 i; | |
456 for (i = 0; i < a.length; i++) { | |
457 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
458 } | |
459 }); | |
460 | |
461 test('format ordinal', function (assert) { | |
462 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1'); | |
463 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2'); | |
464 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3'); | |
465 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4'); | |
466 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5'); | |
467 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6'); | |
468 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7'); | |
469 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8'); | |
470 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9'); | |
471 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10'); | |
472 | |
473 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11'); | |
474 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12'); | |
475 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13'); | |
476 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14'); | |
477 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15'); | |
478 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16'); | |
479 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17'); | |
480 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18'); | |
481 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19'); | |
482 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20'); | |
483 | |
484 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21'); | |
485 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22'); | |
486 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23'); | |
487 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24'); | |
488 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25'); | |
489 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26'); | |
490 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27'); | |
491 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28'); | |
492 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29'); | |
493 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30'); | |
494 | |
495 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31'); | |
496 }); | |
497 | |
498 test('format month', function (assert) { | |
499 var expected = 'يناير يناير_فبراير فبراير_مارس مارس_أبريل أبريل_ماي ماي_يونيو يونيو_يوليوز يوليوز_غشت غشت_شتنبر شتنبر_أكتوبر أكتوبر_نونبر نونبر_دجنبر دجنبر'.split('_'), i; | |
500 for (i = 0; i < expected.length; i++) { | |
501 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
502 } | |
503 }); | |
504 | |
505 test('format week', function (assert) { | |
506 var expected = 'الأحد احد ح_الإتنين اتنين ن_الثلاثاء ثلاثاء ث_الأربعاء اربعاء ر_الخميس خميس خ_الجمعة جمعة ج_السبت سبت س'.split('_'), i; | |
507 for (i = 0; i < expected.length; i++) { | |
508 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
509 } | |
510 }); | |
511 | |
512 test('from', function (assert) { | |
513 var start = moment([2007, 1, 28]); | |
514 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ثوان', '44 seconds = a few seconds'); | |
515 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'دقيقة', '45 seconds = a minute'); | |
516 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'دقيقة', '89 seconds = a minute'); | |
517 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 دقائق', '90 seconds = 2 minutes'); | |
518 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 دقائق', '44 minutes = 44 minutes'); | |
519 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ساعة', '45 minutes = an hour'); | |
520 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ساعة', '89 minutes = an hour'); | |
521 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ساعات', '90 minutes = 2 hours'); | |
522 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ساعات', '5 hours = 5 hours'); | |
523 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ساعات', '21 hours = 21 hours'); | |
524 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'يوم', '22 hours = a day'); | |
525 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'يوم', '35 hours = a day'); | |
526 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 أيام', '36 hours = 2 days'); | |
527 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'يوم', '1 day = a day'); | |
528 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 أيام', '5 days = 5 days'); | |
529 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 أيام', '25 days = 25 days'); | |
530 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'شهر', '26 days = a month'); | |
531 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'شهر', '30 days = a month'); | |
532 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'شهر', '43 days = a month'); | |
533 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 أشهر', '46 days = 2 months'); | |
534 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 أشهر', '75 days = 2 months'); | |
535 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 أشهر', '76 days = 3 months'); | |
536 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'شهر', '1 month = a month'); | |
537 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 أشهر', '5 months = 5 months'); | |
538 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'سنة', '345 days = a year'); | |
539 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 سنوات', '548 days = 2 years'); | |
540 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'سنة', '1 year = a year'); | |
541 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 سنوات', '5 years = 5 years'); | |
542 }); | |
543 | |
544 test('suffix', function (assert) { | |
545 assert.equal(moment(30000).from(0), 'في ثوان', 'prefix'); | |
546 assert.equal(moment(0).from(30000), 'منذ ثوان', 'suffix'); | |
547 }); | |
548 | |
549 test('now from now', function (assert) { | |
550 assert.equal(moment().fromNow(), 'منذ ثوان', 'now from now should display as in the past'); | |
551 }); | |
552 | |
553 test('fromNow', function (assert) { | |
554 assert.equal(moment().add({s: 30}).fromNow(), 'في ثوان', 'in a few seconds'); | |
555 assert.equal(moment().add({d: 5}).fromNow(), 'في 5 أيام', 'in 5 days'); | |
556 }); | |
557 | |
558 test('calendar day', function (assert) { | |
559 var a = moment().hours(2).minutes(0).seconds(0); | |
560 | |
561 assert.equal(moment(a).calendar(), 'اليوم على الساعة 02:00', 'today at the same time'); | |
562 assert.equal(moment(a).add({m: 25}).calendar(), 'اليوم على الساعة 02:25', 'Now plus 25 min'); | |
563 assert.equal(moment(a).add({h: 1}).calendar(), 'اليوم على الساعة 03:00', 'Now plus 1 hour'); | |
564 assert.equal(moment(a).add({d: 1}).calendar(), 'غدا على الساعة 02:00', 'tomorrow at the same time'); | |
565 assert.equal(moment(a).subtract({h: 1}).calendar(), 'اليوم على الساعة 01:00', 'Now minus 1 hour'); | |
566 assert.equal(moment(a).subtract({d: 1}).calendar(), 'أمس على الساعة 02:00', 'yesterday at the same time'); | |
567 }); | |
568 | |
569 test('calendar next week', function (assert) { | |
570 var i, m; | |
571 for (i = 2; i < 7; i++) { | |
572 m = moment().add({d: i}); | |
573 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days current time'); | |
574 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
575 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days beginning of day'); | |
576 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
577 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days end of day'); | |
578 } | |
579 }); | |
580 | |
581 test('calendar last week', function (assert) { | |
582 var i, m; | |
583 for (i = 2; i < 7; i++) { | |
584 m = moment().subtract({d: i}); | |
585 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days current time'); | |
586 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
587 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days beginning of day'); | |
588 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
589 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days end of day'); | |
590 } | |
591 }); | |
592 | |
593 test('calendar all else', function (assert) { | |
594 var weeksAgo = moment().subtract({w: 1}), | |
595 weeksFromNow = moment().add({w: 1}); | |
596 | |
597 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
598 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
599 | |
600 weeksAgo = moment().subtract({w: 2}); | |
601 weeksFromNow = moment().add({w: 2}); | |
602 | |
603 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
604 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
605 }); | |
606 | |
607 test('weeks year starting sunday', function (assert) { | |
608 assert.equal(moment([2011, 11, 31]).week(), 1, 'Dec 31 2011 should be week 1'); | |
609 assert.equal(moment([2012, 0, 6]).week(), 1, 'Jan 6 2012 should be week 1'); | |
610 assert.equal(moment([2012, 0, 7]).week(), 2, 'Jan 7 2012 should be week 2'); | |
611 assert.equal(moment([2012, 0, 13]).week(), 2, 'Jan 13 2012 should be week 2'); | |
612 assert.equal(moment([2012, 0, 14]).week(), 3, 'Jan 14 2012 should be week 3'); | |
613 }); | |
614 | |
615 test('weeks year starting monday', function (assert) { | |
616 assert.equal(moment([2006, 11, 30]).week(), 1, 'Dec 30 2006 should be week 1'); | |
617 assert.equal(moment([2007, 0, 5]).week(), 1, 'Jan 5 2007 should be week 1'); | |
618 assert.equal(moment([2007, 0, 6]).week(), 2, 'Jan 6 2007 should be week 2'); | |
619 assert.equal(moment([2007, 0, 12]).week(), 2, 'Jan 12 2007 should be week 2'); | |
620 assert.equal(moment([2007, 0, 13]).week(), 3, 'Jan 13 2007 should be week 3'); | |
621 }); | |
622 | |
623 test('weeks year starting tuesday', function (assert) { | |
624 assert.equal(moment([2007, 11, 29]).week(), 1, 'Dec 29 2007 should be week 1'); | |
625 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
626 assert.equal(moment([2008, 0, 4]).week(), 1, 'Jan 4 2008 should be week 1'); | |
627 assert.equal(moment([2008, 0, 5]).week(), 2, 'Jan 5 2008 should be week 2'); | |
628 assert.equal(moment([2008, 0, 11]).week(), 2, 'Jan 11 2008 should be week 2'); | |
629 assert.equal(moment([2008, 0, 12]).week(), 3, 'Jan 12 2008 should be week 3'); | |
630 }); | |
631 | |
632 test('weeks year starting wednesday', function (assert) { | |
633 assert.equal(moment([2002, 11, 28]).week(), 1, 'Dec 28 2002 should be week 1'); | |
634 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
635 assert.equal(moment([2003, 0, 3]).week(), 1, 'Jan 3 2003 should be week 1'); | |
636 assert.equal(moment([2003, 0, 4]).week(), 2, 'Jan 4 2003 should be week 2'); | |
637 assert.equal(moment([2003, 0, 10]).week(), 2, 'Jan 10 2003 should be week 2'); | |
638 assert.equal(moment([2003, 0, 11]).week(), 3, 'Jan 11 2003 should be week 3'); | |
639 }); | |
640 | |
641 test('weeks year starting thursday', function (assert) { | |
642 assert.equal(moment([2008, 11, 27]).week(), 1, 'Dec 27 2008 should be week 1'); | |
643 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
644 assert.equal(moment([2009, 0, 2]).week(), 1, 'Jan 2 2009 should be week 1'); | |
645 assert.equal(moment([2009, 0, 3]).week(), 2, 'Jan 3 2009 should be week 2'); | |
646 assert.equal(moment([2009, 0, 9]).week(), 2, 'Jan 9 2009 should be week 2'); | |
647 assert.equal(moment([2009, 0, 10]).week(), 3, 'Jan 10 2009 should be week 3'); | |
648 }); | |
649 | |
650 test('weeks year starting friday', function (assert) { | |
651 assert.equal(moment([2009, 11, 26]).week(), 1, 'Dec 26 2009 should be week 1'); | |
652 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
653 assert.equal(moment([2010, 0, 2]).week(), 2, 'Jan 2 2010 should be week 2'); | |
654 assert.equal(moment([2010, 0, 8]).week(), 2, 'Jan 8 2010 should be week 2'); | |
655 assert.equal(moment([2010, 0, 9]).week(), 3, 'Jan 9 2010 should be week 3'); | |
656 }); | |
657 | |
658 test('weeks year starting saturday', function (assert) { | |
659 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
660 assert.equal(moment([2011, 0, 7]).week(), 1, 'Jan 7 2011 should be week 1'); | |
661 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2'); | |
662 assert.equal(moment([2011, 0, 14]).week(), 2, 'Jan 14 2011 should be week 2'); | |
663 assert.equal(moment([2011, 0, 15]).week(), 3, 'Jan 15 2011 should be week 3'); | |
664 }); | |
665 | |
666 test('weeks year starting sunday formatted', function (assert) { | |
667 assert.equal(moment([2011, 11, 31]).format('w ww wo'), '1 01 1', 'Dec 31 2011 should be week 1'); | |
668 assert.equal(moment([2012, 0, 6]).format('w ww wo'), '1 01 1', 'Jan 6 2012 should be week 1'); | |
669 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '2 02 2', 'Jan 7 2012 should be week 2'); | |
670 assert.equal(moment([2012, 0, 13]).format('w ww wo'), '2 02 2', 'Jan 13 2012 should be week 2'); | |
671 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '3 03 3', 'Jan 14 2012 should be week 3'); | |
672 }); | |
673 | |
674 test('lenient ordinal parsing', function (assert) { | |
675 var i, ordinalStr, testMoment; | |
676 for (i = 1; i <= 31; ++i) { | |
677 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
678 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
679 assert.equal(testMoment.year(), 2014, | |
680 'lenient ordinal parsing ' + i + ' year check'); | |
681 assert.equal(testMoment.month(), 0, | |
682 'lenient ordinal parsing ' + i + ' month check'); | |
683 assert.equal(testMoment.date(), i, | |
684 'lenient ordinal parsing ' + i + ' date check'); | |
685 } | |
686 }); | |
687 | |
688 test('lenient ordinal parsing of number', function (assert) { | |
689 var i, testMoment; | |
690 for (i = 1; i <= 31; ++i) { | |
691 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
692 assert.equal(testMoment.year(), 2014, | |
693 'lenient ordinal parsing of number ' + i + ' year check'); | |
694 assert.equal(testMoment.month(), 0, | |
695 'lenient ordinal parsing of number ' + i + ' month check'); | |
696 assert.equal(testMoment.date(), i, | |
697 'lenient ordinal parsing of number ' + i + ' date check'); | |
698 } | |
699 }); | |
700 | |
701 test('strict ordinal parsing', function (assert) { | |
702 var i, ordinalStr, testMoment; | |
703 for (i = 1; i <= 31; ++i) { | |
704 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
705 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
706 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
707 } | |
708 }); | |
709 | |
710 })); | |
711 | |
712 (function (global, factory) { | |
713 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
714 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
715 factory(global.moment) | |
716 }(this, function (moment) { 'use strict'; | |
717 | |
718 /*global QUnit:false*/ | |
719 | |
720 var test = QUnit.test; | |
721 | |
722 function module (name, lifecycle) { | |
723 QUnit.module(name, { | |
724 setup : function () { | |
725 moment.locale('en'); | |
726 moment.createFromInputFallback = function () { | |
727 throw new Error('input not handled by moment'); | |
728 }; | |
729 if (lifecycle && lifecycle.setup) { | |
730 lifecycle.setup(); | |
731 } | |
732 }, | |
733 teardown : function () { | |
734 if (lifecycle && lifecycle.teardown) { | |
735 lifecycle.teardown(); | |
736 } | |
737 } | |
738 }); | |
739 } | |
740 | |
741 function localeModule (name, lifecycle) { | |
742 QUnit.module('locale:' + name, { | |
743 setup : function () { | |
744 moment.locale(name); | |
745 moment.createFromInputFallback = function () { | |
746 throw new Error('input not handled by moment'); | |
747 }; | |
748 if (lifecycle && lifecycle.setup) { | |
749 lifecycle.setup(); | |
750 } | |
751 }, | |
752 teardown : function () { | |
753 moment.locale('en'); | |
754 if (lifecycle && lifecycle.teardown) { | |
755 lifecycle.teardown(); | |
756 } | |
757 } | |
758 }); | |
759 } | |
760 | |
761 localeModule('ar-sa'); | |
762 | |
763 test('parse', function (assert) { | |
764 var tests = 'يناير:يناير_فبراير:فبراير_مارس:مارس_أبريل:أبريل_مايو:مايو_يونيو:يونيو_يوليو:يوليو_أغسطس:أغسطس_سبتمبر:سبتمبر_أكتوبر:أكتوبر_نوفمبر:نوفمبر_ديسمبر:ديسمبر'.split('_'), i; | |
765 function equalTest(input, mmm, i) { | |
766 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1) + ' instead is month ' + moment(input, mmm).month()); | |
767 } | |
768 for (i = 0; i < 12; i++) { | |
769 tests[i] = tests[i].split(':'); | |
770 equalTest(tests[i][0], 'MMM', i); | |
771 equalTest(tests[i][1], 'MMM', i); | |
772 equalTest(tests[i][0], 'MMMM', i); | |
773 equalTest(tests[i][1], 'MMMM', i); | |
774 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
775 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
776 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
777 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
778 } | |
779 }); | |
780 | |
781 test('format', function (assert) { | |
782 var a = [ | |
783 ['dddd, MMMM Do YYYY, h:mm:ss a', 'الأحد، فبراير ١٤ ٢٠١٠، ٣:٢٥:٥٠ م'], | |
784 ['ddd, hA', 'أحد، ٣م'], | |
785 ['M Mo MM MMMM MMM', '٢ ٢ ٠٢ فبراير فبراير'], | |
786 ['YYYY YY', '٢٠١٠ ١٠'], | |
787 ['D Do DD', '١٤ ١٤ ١٤'], | |
788 ['d do dddd ddd dd', '٠ ٠ الأحد أحد ح'], | |
789 ['DDD DDDo DDDD', '٤٥ ٤٥ ٠٤٥'], | |
790 ['w wo ww', '٨ ٨ ٠٨'], | |
791 ['h hh', '٣ ٠٣'], | |
792 ['H HH', '١٥ ١٥'], | |
793 ['m mm', '٢٥ ٢٥'], | |
794 ['s ss', '٥٠ ٥٠'], | |
795 ['a A', 'م م'], | |
796 ['[the] DDDo [day of the year]', 'the ٤٥ day of the year'], | |
797 ['LT', '١٥:٢٥'], | |
798 ['LTS', '١٥:٢٥:٥٠'], | |
799 ['L', '١٤/٠٢/٢٠١٠'], | |
800 ['LL', '١٤ فبراير ٢٠١٠'], | |
801 ['LLL', '١٤ فبراير ٢٠١٠ ١٥:٢٥'], | |
802 ['LLLL', 'الأحد ١٤ فبراير ٢٠١٠ ١٥:٢٥'], | |
803 ['l', '١٤/٢/٢٠١٠'], | |
804 ['ll', '١٤ فبراير ٢٠١٠'], | |
805 ['lll', '١٤ فبراير ٢٠١٠ ١٥:٢٥'], | |
806 ['llll', 'أحد ١٤ فبراير ٢٠١٠ ١٥:٢٥'] | |
807 ], | |
808 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
809 i; | |
810 for (i = 0; i < a.length; i++) { | |
811 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
812 } | |
813 }); | |
814 | |
815 test('format ordinal', function (assert) { | |
816 assert.equal(moment([2011, 0, 1]).format('DDDo'), '١', '1'); | |
817 assert.equal(moment([2011, 0, 2]).format('DDDo'), '٢', '2'); | |
818 assert.equal(moment([2011, 0, 3]).format('DDDo'), '٣', '3'); | |
819 assert.equal(moment([2011, 0, 4]).format('DDDo'), '٤', '4'); | |
820 assert.equal(moment([2011, 0, 5]).format('DDDo'), '٥', '5'); | |
821 assert.equal(moment([2011, 0, 6]).format('DDDo'), '٦', '6'); | |
822 assert.equal(moment([2011, 0, 7]).format('DDDo'), '٧', '7'); | |
823 assert.equal(moment([2011, 0, 8]).format('DDDo'), '٨', '8'); | |
824 assert.equal(moment([2011, 0, 9]).format('DDDo'), '٩', '9'); | |
825 assert.equal(moment([2011, 0, 10]).format('DDDo'), '١٠', '10'); | |
826 | |
827 assert.equal(moment([2011, 0, 11]).format('DDDo'), '١١', '11'); | |
828 assert.equal(moment([2011, 0, 12]).format('DDDo'), '١٢', '12'); | |
829 assert.equal(moment([2011, 0, 13]).format('DDDo'), '١٣', '13'); | |
830 assert.equal(moment([2011, 0, 14]).format('DDDo'), '١٤', '14'); | |
831 assert.equal(moment([2011, 0, 15]).format('DDDo'), '١٥', '15'); | |
832 assert.equal(moment([2011, 0, 16]).format('DDDo'), '١٦', '16'); | |
833 assert.equal(moment([2011, 0, 17]).format('DDDo'), '١٧', '17'); | |
834 assert.equal(moment([2011, 0, 18]).format('DDDo'), '١٨', '18'); | |
835 assert.equal(moment([2011, 0, 19]).format('DDDo'), '١٩', '19'); | |
836 assert.equal(moment([2011, 0, 20]).format('DDDo'), '٢٠', '20'); | |
837 | |
838 assert.equal(moment([2011, 0, 21]).format('DDDo'), '٢١', '21'); | |
839 assert.equal(moment([2011, 0, 22]).format('DDDo'), '٢٢', '22'); | |
840 assert.equal(moment([2011, 0, 23]).format('DDDo'), '٢٣', '23'); | |
841 assert.equal(moment([2011, 0, 24]).format('DDDo'), '٢٤', '24'); | |
842 assert.equal(moment([2011, 0, 25]).format('DDDo'), '٢٥', '25'); | |
843 assert.equal(moment([2011, 0, 26]).format('DDDo'), '٢٦', '26'); | |
844 assert.equal(moment([2011, 0, 27]).format('DDDo'), '٢٧', '27'); | |
845 assert.equal(moment([2011, 0, 28]).format('DDDo'), '٢٨', '28'); | |
846 assert.equal(moment([2011, 0, 29]).format('DDDo'), '٢٩', '29'); | |
847 assert.equal(moment([2011, 0, 30]).format('DDDo'), '٣٠', '30'); | |
848 | |
849 assert.equal(moment([2011, 0, 31]).format('DDDo'), '٣١', '31'); | |
850 }); | |
851 | |
852 test('format month', function (assert) { | |
853 var expected = 'يناير يناير_فبراير فبراير_مارس مارس_أبريل أبريل_مايو مايو_يونيو يونيو_يوليو يوليو_أغسطس أغسطس_سبتمبر سبتمبر_أكتوبر أكتوبر_نوفمبر نوفمبر_ديسمبر ديسمبر'.split('_'), i; | |
854 for (i = 0; i < expected.length; i++) { | |
855 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
856 } | |
857 }); | |
858 | |
859 test('format week', function (assert) { | |
860 var expected = 'الأحد أحد ح_الإثنين إثنين ن_الثلاثاء ثلاثاء ث_الأربعاء أربعاء ر_الخميس خميس خ_الجمعة جمعة ج_السبت سبت س'.split('_'), i; | |
861 for (i = 0; i < expected.length; i++) { | |
862 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
863 } | |
864 }); | |
865 | |
866 test('from', function (assert) { | |
867 var start = moment([2007, 1, 28]); | |
868 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ثوان', '44 seconds = a few seconds'); | |
869 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'دقيقة', '45 seconds = a minute'); | |
870 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'دقيقة', '89 seconds = a minute'); | |
871 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '٢ دقائق', '90 seconds = 2 minutes'); | |
872 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '٤٤ دقائق', '44 minutes = 44 minutes'); | |
873 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ساعة', '45 minutes = an hour'); | |
874 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ساعة', '89 minutes = an hour'); | |
875 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '٢ ساعات', '90 minutes = 2 hours'); | |
876 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '٥ ساعات', '5 hours = 5 hours'); | |
877 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '٢١ ساعات', '21 hours = 21 hours'); | |
878 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'يوم', '22 hours = a day'); | |
879 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'يوم', '35 hours = a day'); | |
880 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '٢ أيام', '36 hours = 2 days'); | |
881 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'يوم', '1 day = a day'); | |
882 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '٥ أيام', '5 days = 5 days'); | |
883 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '٢٥ أيام', '25 days = 25 days'); | |
884 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'شهر', '26 days = a month'); | |
885 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'شهر', '30 days = a month'); | |
886 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'شهر', '43 days = a month'); | |
887 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '٢ أشهر', '46 days = 2 months'); | |
888 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '٢ أشهر', '75 days = 2 months'); | |
889 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '٣ أشهر', '76 days = 3 months'); | |
890 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'شهر', '1 month = a month'); | |
891 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '٥ أشهر', '5 months = 5 months'); | |
892 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'سنة', '345 days = a year'); | |
893 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '٢ سنوات', '548 days = 2 years'); | |
894 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'سنة', '1 year = a year'); | |
895 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '٥ سنوات', '5 years = 5 years'); | |
896 }); | |
897 | |
898 test('suffix', function (assert) { | |
899 assert.equal(moment(30000).from(0), 'في ثوان', 'prefix'); | |
900 assert.equal(moment(0).from(30000), 'منذ ثوان', 'suffix'); | |
901 }); | |
902 | |
903 test('now from now', function (assert) { | |
904 assert.equal(moment().fromNow(), 'منذ ثوان', 'now from now should display as in the past'); | |
905 }); | |
906 | |
907 test('fromNow', function (assert) { | |
908 assert.equal(moment().add({s: 30}).fromNow(), 'في ثوان', 'in a few seconds'); | |
909 assert.equal(moment().add({d: 5}).fromNow(), 'في ٥ أيام', 'in 5 days'); | |
910 }); | |
911 | |
912 test('calendar day', function (assert) { | |
913 var a = moment().hours(2).minutes(0).seconds(0); | |
914 | |
915 assert.equal(moment(a).calendar(), 'اليوم على الساعة ٠٢:٠٠', 'today at the same time'); | |
916 assert.equal(moment(a).add({m: 25}).calendar(), 'اليوم على الساعة ٠٢:٢٥', 'Now plus 25 min'); | |
917 assert.equal(moment(a).add({h: 1}).calendar(), 'اليوم على الساعة ٠٣:٠٠', 'Now plus 1 hour'); | |
918 assert.equal(moment(a).add({d: 1}).calendar(), 'غدا على الساعة ٠٢:٠٠', 'tomorrow at the same time'); | |
919 assert.equal(moment(a).subtract({h: 1}).calendar(), 'اليوم على الساعة ٠١:٠٠', 'Now minus 1 hour'); | |
920 assert.equal(moment(a).subtract({d: 1}).calendar(), 'أمس على الساعة ٠٢:٠٠', 'yesterday at the same time'); | |
921 }); | |
922 | |
923 test('calendar next week', function (assert) { | |
924 var i, m; | |
925 for (i = 2; i < 7; i++) { | |
926 m = moment().add({d: i}); | |
927 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days current time'); | |
928 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
929 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days beginning of day'); | |
930 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
931 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days end of day'); | |
932 } | |
933 }); | |
934 | |
935 test('calendar last week', function (assert) { | |
936 var i, m; | |
937 for (i = 2; i < 7; i++) { | |
938 m = moment().subtract({d: i}); | |
939 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days current time'); | |
940 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
941 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days beginning of day'); | |
942 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
943 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days end of day'); | |
944 } | |
945 }); | |
946 | |
947 test('calendar all else', function (assert) { | |
948 var weeksAgo = moment().subtract({w: 1}), | |
949 weeksFromNow = moment().add({w: 1}); | |
950 | |
951 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
952 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
953 | |
954 weeksAgo = moment().subtract({w: 2}); | |
955 weeksFromNow = moment().add({w: 2}); | |
956 | |
957 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
958 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
959 }); | |
960 | |
961 test('weeks year starting sunday', function (assert) { | |
962 assert.equal(moment([2011, 11, 31]).week(), 1, 'Dec 31 2011 should be week 1'); | |
963 assert.equal(moment([2012, 0, 6]).week(), 1, 'Jan 6 2012 should be week 1'); | |
964 assert.equal(moment([2012, 0, 7]).week(), 2, 'Jan 7 2012 should be week 2'); | |
965 assert.equal(moment([2012, 0, 13]).week(), 2, 'Jan 13 2012 should be week 2'); | |
966 assert.equal(moment([2012, 0, 14]).week(), 3, 'Jan 14 2012 should be week 3'); | |
967 }); | |
968 | |
969 test('weeks year starting monday', function (assert) { | |
970 assert.equal(moment([2006, 11, 30]).week(), 1, 'Dec 30 2006 should be week 1'); | |
971 assert.equal(moment([2007, 0, 5]).week(), 1, 'Jan 5 2007 should be week 1'); | |
972 assert.equal(moment([2007, 0, 6]).week(), 2, 'Jan 6 2007 should be week 2'); | |
973 assert.equal(moment([2007, 0, 12]).week(), 2, 'Jan 12 2007 should be week 2'); | |
974 assert.equal(moment([2007, 0, 13]).week(), 3, 'Jan 13 2007 should be week 3'); | |
975 }); | |
976 | |
977 test('weeks year starting tuesday', function (assert) { | |
978 assert.equal(moment([2007, 11, 29]).week(), 1, 'Dec 29 2007 should be week 1'); | |
979 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
980 assert.equal(moment([2008, 0, 4]).week(), 1, 'Jan 4 2008 should be week 1'); | |
981 assert.equal(moment([2008, 0, 5]).week(), 2, 'Jan 5 2008 should be week 2'); | |
982 assert.equal(moment([2008, 0, 11]).week(), 2, 'Jan 11 2008 should be week 2'); | |
983 assert.equal(moment([2008, 0, 12]).week(), 3, 'Jan 12 2008 should be week 3'); | |
984 }); | |
985 | |
986 test('weeks year starting wednesday', function (assert) { | |
987 assert.equal(moment([2002, 11, 28]).week(), 1, 'Dec 28 2002 should be week 1'); | |
988 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
989 assert.equal(moment([2003, 0, 3]).week(), 1, 'Jan 3 2003 should be week 1'); | |
990 assert.equal(moment([2003, 0, 4]).week(), 2, 'Jan 4 2003 should be week 2'); | |
991 assert.equal(moment([2003, 0, 10]).week(), 2, 'Jan 10 2003 should be week 2'); | |
992 assert.equal(moment([2003, 0, 11]).week(), 3, 'Jan 11 2003 should be week 3'); | |
993 | |
994 assert.equal(moment('2003 1 6', 'gggg w d').format('YYYY-MM-DD'), '٢٠٠٢-١٢-٢٨', 'Week 1 of 2003 should be Dec 28 2002'); | |
995 assert.equal(moment('2003 1 0', 'gggg w e').format('YYYY-MM-DD'), '٢٠٠٢-١٢-٢٨', 'Week 1 of 2003 should be Dec 28 2002'); | |
996 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'); | |
997 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'); | |
998 }); | |
999 | |
1000 test('weeks year starting thursday', function (assert) { | |
1001 assert.equal(moment([2008, 11, 27]).week(), 1, 'Dec 27 2008 should be week 1'); | |
1002 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
1003 assert.equal(moment([2009, 0, 2]).week(), 1, 'Jan 2 2009 should be week 1'); | |
1004 assert.equal(moment([2009, 0, 3]).week(), 2, 'Jan 3 2009 should be week 2'); | |
1005 assert.equal(moment([2009, 0, 9]).week(), 2, 'Jan 9 2009 should be week 2'); | |
1006 assert.equal(moment([2009, 0, 10]).week(), 3, 'Jan 10 2009 should be week 3'); | |
1007 }); | |
1008 | |
1009 test('weeks year starting friday', function (assert) { | |
1010 assert.equal(moment([2009, 11, 26]).week(), 1, 'Dec 26 2009 should be week 1'); | |
1011 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
1012 assert.equal(moment([2010, 0, 2]).week(), 2, 'Jan 2 2010 should be week 2'); | |
1013 assert.equal(moment([2010, 0, 8]).week(), 2, 'Jan 8 2010 should be week 2'); | |
1014 assert.equal(moment([2010, 0, 9]).week(), 3, 'Jan 9 2010 should be week 3'); | |
1015 }); | |
1016 | |
1017 test('weeks year starting saturday', function (assert) { | |
1018 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
1019 assert.equal(moment([2011, 0, 7]).week(), 1, 'Jan 7 2011 should be week 1'); | |
1020 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2'); | |
1021 assert.equal(moment([2011, 0, 14]).week(), 2, 'Jan 14 2011 should be week 2'); | |
1022 assert.equal(moment([2011, 0, 15]).week(), 3, 'Jan 15 2011 should be week 3'); | |
1023 }); | |
1024 | |
1025 test('weeks year starting sunday formatted', function (assert) { | |
1026 assert.equal(moment([2011, 11, 31]).format('w ww wo'), '١ ٠١ ١', 'Dec 31 2011 should be week 1'); | |
1027 assert.equal(moment([2012, 0, 6]).format('w ww wo'), '١ ٠١ ١', 'Jan 6 2012 should be week 1'); | |
1028 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '٢ ٠٢ ٢', 'Jan 7 2012 should be week 2'); | |
1029 assert.equal(moment([2012, 0, 13]).format('w ww wo'), '٢ ٠٢ ٢', 'Jan 13 2012 should be week 2'); | |
1030 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '٣ ٠٣ ٣', 'Jan 14 2012 should be week 3'); | |
1031 }); | |
1032 | |
1033 test('lenient ordinal parsing', function (assert) { | |
1034 var i, ordinalStr, testMoment; | |
1035 for (i = 1; i <= 31; ++i) { | |
1036 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
1037 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
1038 assert.equal(testMoment.year(), 2014, | |
1039 'lenient ordinal parsing ' + i + ' year check'); | |
1040 assert.equal(testMoment.month(), 0, | |
1041 'lenient ordinal parsing ' + i + ' month check'); | |
1042 assert.equal(testMoment.date(), i, | |
1043 'lenient ordinal parsing ' + i + ' date check'); | |
1044 } | |
1045 }); | |
1046 | |
1047 test('lenient ordinal parsing of number', function (assert) { | |
1048 var i, testMoment; | |
1049 for (i = 1; i <= 31; ++i) { | |
1050 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
1051 assert.equal(testMoment.year(), 2014, | |
1052 'lenient ordinal parsing of number ' + i + ' year check'); | |
1053 assert.equal(testMoment.month(), 0, | |
1054 'lenient ordinal parsing of number ' + i + ' month check'); | |
1055 assert.equal(testMoment.date(), i, | |
1056 'lenient ordinal parsing of number ' + i + ' date check'); | |
1057 } | |
1058 }); | |
1059 | |
1060 test('strict ordinal parsing', function (assert) { | |
1061 var i, ordinalStr, testMoment; | |
1062 for (i = 1; i <= 31; ++i) { | |
1063 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
1064 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
1065 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
1066 } | |
1067 }); | |
1068 | |
1069 })); | |
1070 | |
1071 (function (global, factory) { | |
1072 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
1073 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
1074 factory(global.moment) | |
1075 }(this, function (moment) { 'use strict'; | |
1076 | |
1077 /*global QUnit:false*/ | |
1078 | |
1079 var test = QUnit.test; | |
1080 | |
1081 function module (name, lifecycle) { | |
1082 QUnit.module(name, { | |
1083 setup : function () { | |
1084 moment.locale('en'); | |
1085 moment.createFromInputFallback = function () { | |
1086 throw new Error('input not handled by moment'); | |
1087 }; | |
1088 if (lifecycle && lifecycle.setup) { | |
1089 lifecycle.setup(); | |
1090 } | |
1091 }, | |
1092 teardown : function () { | |
1093 if (lifecycle && lifecycle.teardown) { | |
1094 lifecycle.teardown(); | |
1095 } | |
1096 } | |
1097 }); | |
1098 } | |
1099 | |
1100 function localeModule (name, lifecycle) { | |
1101 QUnit.module('locale:' + name, { | |
1102 setup : function () { | |
1103 moment.locale(name); | |
1104 moment.createFromInputFallback = function () { | |
1105 throw new Error('input not handled by moment'); | |
1106 }; | |
1107 if (lifecycle && lifecycle.setup) { | |
1108 lifecycle.setup(); | |
1109 } | |
1110 }, | |
1111 teardown : function () { | |
1112 moment.locale('en'); | |
1113 if (lifecycle && lifecycle.teardown) { | |
1114 lifecycle.teardown(); | |
1115 } | |
1116 } | |
1117 }); | |
1118 } | |
1119 | |
1120 localeModule('ar-tn'); | |
1121 | |
1122 test('parse', function (assert) { | |
1123 var tests = 'جانفي:جانفي_فيفري:فيفري_مارس:مارس_أفريل:أفريل_ماي:ماي_جوان:جوان_جويلية:جويلية_أوت:أوت_سبتمبر:سبتمبر_أكتوبر:أكتوبر_نوفمبر:نوفمبر_ديسمبر:ديسمبر'.split('_'), | |
1124 i; | |
1125 | |
1126 function equalTest(input, mmm, i) { | |
1127 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
1128 } | |
1129 for (i = 0; i < 12; i++) { | |
1130 tests[i] = tests[i].split(':'); | |
1131 equalTest(tests[i][0], 'MMM', i); | |
1132 equalTest(tests[i][1], 'MMM', i); | |
1133 equalTest(tests[i][0], 'MMMM', i); | |
1134 equalTest(tests[i][1], 'MMMM', i); | |
1135 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
1136 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
1137 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
1138 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
1139 } | |
1140 }); | |
1141 | |
1142 test('format', function (assert) { | |
1143 var a = [ | |
1144 ['dddd, MMMM Do YYYY, h:mm:ss a', 'الأحد, فيفري 14 2010, 3:25:50 pm'], | |
1145 ['ddd, hA', 'أحد, 3PM'], | |
1146 ['M Mo MM MMMM MMM', '2 2 02 فيفري فيفري'], | |
1147 ['YYYY YY', '2010 10'], | |
1148 ['D Do DD', '14 14 14'], | |
1149 ['d do dddd ddd dd', '0 0 الأحد أحد ح'], | |
1150 ['DDD DDDo DDDD', '45 45 045'], | |
1151 ['w wo ww', '6 6 06'], | |
1152 ['h hh', '3 03'], | |
1153 ['H HH', '15 15'], | |
1154 ['m mm', '25 25'], | |
1155 ['s ss', '50 50'], | |
1156 ['a A', 'pm PM'], | |
1157 ['[the] DDDo [day of the year]', 'the 45 day of the year'], | |
1158 ['LT', '15:25'], | |
1159 ['LTS', '15:25:50'], | |
1160 ['L', '14/02/2010'], | |
1161 ['LL', '14 فيفري 2010'], | |
1162 ['LLL', '14 فيفري 2010 15:25'], | |
1163 ['LLLL', 'الأحد 14 فيفري 2010 15:25'], | |
1164 ['l', '14/2/2010'], | |
1165 ['ll', '14 فيفري 2010'], | |
1166 ['lll', '14 فيفري 2010 15:25'], | |
1167 ['llll', 'أحد 14 فيفري 2010 15:25'] | |
1168 ], | |
1169 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
1170 i; | |
1171 for (i = 0; i < a.length; i++) { | |
1172 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
1173 } | |
1174 }); | |
1175 | |
1176 test('format ordinal', function (assert) { | |
1177 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1'); | |
1178 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2'); | |
1179 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3'); | |
1180 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4'); | |
1181 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5'); | |
1182 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6'); | |
1183 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7'); | |
1184 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8'); | |
1185 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9'); | |
1186 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10'); | |
1187 | |
1188 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11'); | |
1189 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12'); | |
1190 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13'); | |
1191 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14'); | |
1192 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15'); | |
1193 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16'); | |
1194 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17'); | |
1195 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18'); | |
1196 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19'); | |
1197 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20'); | |
1198 | |
1199 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21'); | |
1200 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22'); | |
1201 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23'); | |
1202 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24'); | |
1203 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25'); | |
1204 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26'); | |
1205 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27'); | |
1206 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28'); | |
1207 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29'); | |
1208 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30'); | |
1209 | |
1210 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31'); | |
1211 }); | |
1212 | |
1213 test('format month', function (assert) { | |
1214 var expected = 'جانفي جانفي_فيفري فيفري_مارس مارس_أفريل أفريل_ماي ماي_جوان جوان_جويلية جويلية_أوت أوت_سبتمبر سبتمبر_أكتوبر أكتوبر_نوفمبر نوفمبر_ديسمبر ديسمبر'.split('_'), | |
1215 i; | |
1216 for (i = 0; i < expected.length; i++) { | |
1217 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
1218 } | |
1219 }); | |
1220 | |
1221 test('format week', function (assert) { | |
1222 var expected = 'الأحد أحد ح_الإثنين إثنين ن_الثلاثاء ثلاثاء ث_الأربعاء أربعاء ر_الخميس خميس خ_الجمعة جمعة ج_السبت سبت س'.split('_'), | |
1223 i; | |
1224 for (i = 0; i < expected.length; i++) { | |
1225 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
1226 } | |
1227 }); | |
1228 | |
1229 test('from', function (assert) { | |
1230 var start = moment([2007, 1, 28]); | |
1231 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1232 s: 44 | |
1233 }), true), 'ثوان', '44 seconds = a few seconds'); | |
1234 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1235 s: 45 | |
1236 }), true), 'دقيقة', '45 seconds = a minute'); | |
1237 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1238 s: 89 | |
1239 }), true), 'دقيقة', '89 seconds = a minute'); | |
1240 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1241 s: 90 | |
1242 }), true), '2 دقائق', '90 seconds = 2 minutes'); | |
1243 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1244 m: 44 | |
1245 }), true), '44 دقائق', '44 minutes = 44 minutes'); | |
1246 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1247 m: 45 | |
1248 }), true), 'ساعة', '45 minutes = an hour'); | |
1249 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1250 m: 89 | |
1251 }), true), 'ساعة', '89 minutes = an hour'); | |
1252 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1253 m: 90 | |
1254 }), true), '2 ساعات', '90 minutes = 2 hours'); | |
1255 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1256 h: 5 | |
1257 }), true), '5 ساعات', '5 hours = 5 hours'); | |
1258 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1259 h: 21 | |
1260 }), true), '21 ساعات', '21 hours = 21 hours'); | |
1261 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1262 h: 22 | |
1263 }), true), 'يوم', '22 hours = a day'); | |
1264 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1265 h: 35 | |
1266 }), true), 'يوم', '35 hours = a day'); | |
1267 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1268 h: 36 | |
1269 }), true), '2 أيام', '36 hours = 2 days'); | |
1270 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1271 d: 1 | |
1272 }), true), 'يوم', '1 day = a day'); | |
1273 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1274 d: 5 | |
1275 }), true), '5 أيام', '5 days = 5 days'); | |
1276 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1277 d: 25 | |
1278 }), true), '25 أيام', '25 days = 25 days'); | |
1279 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1280 d: 26 | |
1281 }), true), 'شهر', '26 days = a month'); | |
1282 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1283 d: 30 | |
1284 }), true), 'شهر', '30 days = a month'); | |
1285 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1286 d: 43 | |
1287 }), true), 'شهر', '43 days = a month'); | |
1288 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1289 d: 46 | |
1290 }), true), '2 أشهر', '46 days = 2 months'); | |
1291 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1292 d: 74 | |
1293 }), true), '2 أشهر', '75 days = 2 months'); | |
1294 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1295 d: 76 | |
1296 }), true), '3 أشهر', '76 days = 3 months'); | |
1297 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1298 M: 1 | |
1299 }), true), 'شهر', '1 month = a month'); | |
1300 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1301 M: 5 | |
1302 }), true), '5 أشهر', '5 months = 5 months'); | |
1303 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1304 d: 345 | |
1305 }), true), 'سنة', '345 days = a year'); | |
1306 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1307 d: 548 | |
1308 }), true), '2 سنوات', '548 days = 2 years'); | |
1309 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1310 y: 1 | |
1311 }), true), 'سنة', '1 year = a year'); | |
1312 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
1313 y: 5 | |
1314 }), true), '5 سنوات', '5 years = 5 years'); | |
1315 }); | |
1316 | |
1317 test('suffix', function (assert) { | |
1318 assert.equal(moment(30000).from(0), 'في ثوان', 'prefix'); | |
1319 assert.equal(moment(0).from(30000), 'منذ ثوان', 'suffix'); | |
1320 }); | |
1321 | |
1322 test('now from now', function (assert) { | |
1323 assert.equal(moment().fromNow(), 'منذ ثوان', 'now from now should display as in the past'); | |
1324 }); | |
1325 | |
1326 test('fromNow', function (assert) { | |
1327 assert.equal(moment().add({ | |
1328 s: 30 | |
1329 }).fromNow(), 'في ثوان', 'in a few seconds'); | |
1330 assert.equal(moment().add({ | |
1331 d: 5 | |
1332 }).fromNow(), 'في 5 أيام', 'in 5 days'); | |
1333 }); | |
1334 | |
1335 test('calendar day', function (assert) { | |
1336 var a = moment().hours(2).minutes(0).seconds(0); | |
1337 | |
1338 assert.equal(moment(a).calendar(), 'اليوم على الساعة 02:00', 'today at the same time'); | |
1339 assert.equal(moment(a).add({ | |
1340 m: 25 | |
1341 }).calendar(), 'اليوم على الساعة 02:25', 'Now plus 25 min'); | |
1342 assert.equal(moment(a).add({ | |
1343 h: 1 | |
1344 }).calendar(), 'اليوم على الساعة 03:00', 'Now plus 1 hour'); | |
1345 assert.equal(moment(a).add({ | |
1346 d: 1 | |
1347 }).calendar(), 'غدا على الساعة 02:00', 'tomorrow at the same time'); | |
1348 assert.equal(moment(a).subtract({ | |
1349 h: 1 | |
1350 }).calendar(), 'اليوم على الساعة 01:00', 'Now minus 1 hour'); | |
1351 assert.equal(moment(a).subtract({ | |
1352 d: 1 | |
1353 }).calendar(), 'أمس على الساعة 02:00', 'yesterday at the same time'); | |
1354 }); | |
1355 | |
1356 test('calendar next week', function (assert) { | |
1357 var i, m; | |
1358 for (i = 2; i < 7; i++) { | |
1359 m = moment().add({ | |
1360 d: i | |
1361 }); | |
1362 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days current time'); | |
1363 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
1364 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days beginning of day'); | |
1365 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
1366 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today + ' + i + ' days end of day'); | |
1367 } | |
1368 }); | |
1369 | |
1370 test('calendar last week', function (assert) { | |
1371 var i, m; | |
1372 for (i = 2; i < 7; i++) { | |
1373 m = moment().subtract({ | |
1374 d: i | |
1375 }); | |
1376 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days current time'); | |
1377 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
1378 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days beginning of day'); | |
1379 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
1380 assert.equal(m.calendar(), m.format('dddd [على الساعة] LT'), 'Today - ' + i + ' days end of day'); | |
1381 } | |
1382 }); | |
1383 | |
1384 test('calendar all else', function (assert) { | |
1385 var weeksAgo = moment().subtract({ | |
1386 w: 1 | |
1387 }), | |
1388 weeksFromNow = moment().add({ | |
1389 w: 1 | |
1390 }); | |
1391 | |
1392 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
1393 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
1394 | |
1395 weeksAgo = moment().subtract({ | |
1396 w: 2 | |
1397 }); | |
1398 weeksFromNow = moment().add({ | |
1399 w: 2 | |
1400 }); | |
1401 | |
1402 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
1403 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
1404 }); | |
1405 | |
1406 test('weeks year starting sunday', function (assert) { | |
1407 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
1408 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
1409 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
1410 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
1411 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
1412 }); | |
1413 | |
1414 test('weeks year starting monday', function (assert) { | |
1415 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
1416 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
1417 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
1418 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
1419 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
1420 }); | |
1421 | |
1422 test('weeks year starting tuesday', function (assert) { | |
1423 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
1424 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
1425 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
1426 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
1427 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
1428 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
1429 }); | |
1430 | |
1431 test('weeks year starting wednesday', function (assert) { | |
1432 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
1433 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
1434 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
1435 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
1436 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
1437 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
1438 }); | |
1439 | |
1440 test('weeks year starting thursday', function (assert) { | |
1441 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
1442 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
1443 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
1444 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
1445 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
1446 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
1447 }); | |
1448 | |
1449 test('weeks year starting friday', function (assert) { | |
1450 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
1451 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
1452 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
1453 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
1454 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
1455 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
1456 }); | |
1457 | |
1458 test('weeks year starting saturday', function (assert) { | |
1459 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
1460 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
1461 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
1462 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
1463 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
1464 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
1465 }); | |
1466 | |
1467 test('weeks year starting sunday formatted', function (assert) { | |
1468 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52', 'Jan 1 2012 should be week 52'); | |
1469 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1', 'Jan 2 2012 should be week 1'); | |
1470 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1', 'Jan 8 2012 should be week 1'); | |
1471 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2', 'Jan 9 2012 should be week 2'); | |
1472 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2', 'Jan 15 2012 should be week 2'); | |
1473 }); | |
1474 | |
1475 test('lenient ordinal parsing', function (assert) { | |
1476 var i, ordinalStr, testMoment; | |
1477 for (i = 1; i <= 31; ++i) { | |
1478 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
1479 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
1480 assert.equal(testMoment.year(), 2014, | |
1481 'lenient ordinal parsing ' + i + ' year check'); | |
1482 assert.equal(testMoment.month(), 0, | |
1483 'lenient ordinal parsing ' + i + ' month check'); | |
1484 assert.equal(testMoment.date(), i, | |
1485 'lenient ordinal parsing ' + i + ' date check'); | |
1486 } | |
1487 }); | |
1488 | |
1489 test('lenient ordinal parsing of number', function (assert) { | |
1490 var i, testMoment; | |
1491 for (i = 1; i <= 31; ++i) { | |
1492 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
1493 assert.equal(testMoment.year(), 2014, | |
1494 'lenient ordinal parsing of number ' + i + ' year check'); | |
1495 assert.equal(testMoment.month(), 0, | |
1496 'lenient ordinal parsing of number ' + i + ' month check'); | |
1497 assert.equal(testMoment.date(), i, | |
1498 'lenient ordinal parsing of number ' + i + ' date check'); | |
1499 } | |
1500 }); | |
1501 | |
1502 test('strict ordinal parsing', function (assert) { | |
1503 var i, ordinalStr, testMoment; | |
1504 for (i = 1; i <= 31; ++i) { | |
1505 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
1506 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
1507 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
1508 } | |
1509 }); | |
1510 | |
1511 })); | |
1512 | |
1513 (function (global, factory) { | |
1514 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
1515 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
1516 factory(global.moment) | |
1517 }(this, function (moment) { 'use strict'; | |
1518 | |
1519 /*global QUnit:false*/ | |
1520 | |
1521 var test = QUnit.test; | |
1522 | |
1523 function module (name, lifecycle) { | |
1524 QUnit.module(name, { | |
1525 setup : function () { | |
1526 moment.locale('en'); | |
1527 moment.createFromInputFallback = function () { | |
1528 throw new Error('input not handled by moment'); | |
1529 }; | |
1530 if (lifecycle && lifecycle.setup) { | |
1531 lifecycle.setup(); | |
1532 } | |
1533 }, | |
1534 teardown : function () { | |
1535 if (lifecycle && lifecycle.teardown) { | |
1536 lifecycle.teardown(); | |
1537 } | |
1538 } | |
1539 }); | |
1540 } | |
1541 | |
1542 function localeModule (name, lifecycle) { | |
1543 QUnit.module('locale:' + name, { | |
1544 setup : function () { | |
1545 moment.locale(name); | |
1546 moment.createFromInputFallback = function () { | |
1547 throw new Error('input not handled by moment'); | |
1548 }; | |
1549 if (lifecycle && lifecycle.setup) { | |
1550 lifecycle.setup(); | |
1551 } | |
1552 }, | |
1553 teardown : function () { | |
1554 moment.locale('en'); | |
1555 if (lifecycle && lifecycle.teardown) { | |
1556 lifecycle.teardown(); | |
1557 } | |
1558 } | |
1559 }); | |
1560 } | |
1561 | |
1562 localeModule('ar'); | |
1563 | |
1564 var months = [ | |
1565 'كانون الثاني يناير', | |
1566 'شباط فبراير', | |
1567 'آذار مارس', | |
1568 'نيسان أبريل', | |
1569 'أيار مايو', | |
1570 'حزيران يونيو', | |
1571 'تموز يوليو', | |
1572 'آب أغسطس', | |
1573 'أيلول سبتمبر', | |
1574 'تشرين الأول أكتوبر', | |
1575 'تشرين الثاني نوفمبر', | |
1576 'كانون الأول ديسمبر' | |
1577 ]; | |
1578 | |
1579 test('parse', function (assert) { | |
1580 var tests = months, i; | |
1581 function equalTest(input, mmm, i) { | |
1582 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1) + ' instead is month ' + moment(input, mmm).month()); | |
1583 } | |
1584 for (i = 0; i < 12; i++) { | |
1585 equalTest(tests[i], 'MMM', i); | |
1586 equalTest(tests[i], 'MMM', i); | |
1587 equalTest(tests[i], 'MMMM', i); | |
1588 equalTest(tests[i], 'MMMM', i); | |
1589 equalTest(tests[i].toLocaleLowerCase(), 'MMMM', i); | |
1590 equalTest(tests[i].toLocaleLowerCase(), 'MMMM', i); | |
1591 equalTest(tests[i].toLocaleUpperCase(), 'MMMM', i); | |
1592 equalTest(tests[i].toLocaleUpperCase(), 'MMMM', i); | |
1593 } | |
1594 }); | |
1595 | |
1596 test('format', function (assert) { | |
1597 var a = [ | |
1598 ['dddd, MMMM Do YYYY, h:mm:ss a', 'الأحد، شباط فبراير ١٤ ٢٠١٠، ٣:٢٥:٥٠ م'], | |
1599 ['ddd, hA', 'أحد، ٣م'], | |
1600 ['M Mo MM MMMM MMM', '٢ ٢ ٠٢ شباط فبراير شباط فبراير'], | |
1601 ['YYYY YY', '٢٠١٠ ١٠'], | |
1602 ['D Do DD', '١٤ ١٤ ١٤'], | |
1603 ['d do dddd ddd dd', '٠ ٠ الأحد أحد ح'], | |
1604 ['DDD DDDo DDDD', '٤٥ ٤٥ ٠٤٥'], | |
1605 ['w wo ww', '٨ ٨ ٠٨'], | |
1606 ['h hh', '٣ ٠٣'], | |
1607 ['H HH', '١٥ ١٥'], | |
1608 ['m mm', '٢٥ ٢٥'], | |
1609 ['s ss', '٥٠ ٥٠'], | |
1610 ['a A', 'م م'], | |
1611 ['[the] DDDo [day of the year]', 'the ٤٥ day of the year'], | |
1612 ['LT', '١٥:٢٥'], | |
1613 ['LTS', '١٥:٢٥:٥٠'], | |
1614 ['L', '١٤/\u200f٢/\u200f٢٠١٠'], | |
1615 ['LL', '١٤ شباط فبراير ٢٠١٠'], | |
1616 ['LLL', '١٤ شباط فبراير ٢٠١٠ ١٥:٢٥'], | |
1617 ['LLLL', 'الأحد ١٤ شباط فبراير ٢٠١٠ ١٥:٢٥'], | |
1618 ['l', '١٤/\u200f٢/\u200f٢٠١٠'], | |
1619 ['ll', '١٤ شباط فبراير ٢٠١٠'], | |
1620 ['lll', '١٤ شباط فبراير ٢٠١٠ ١٥:٢٥'], | |
1621 ['llll', 'أحد ١٤ شباط فبراير ٢٠١٠ ١٥:٢٥'] | |
1622 ], | |
1623 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
1624 i; | |
1625 for (i = 0; i < a.length; i++) { | |
1626 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
1627 } | |
1628 }); | |
1629 | |
1630 test('format ordinal', function (assert) { | |
1631 assert.equal(moment([2011, 0, 1]).format('DDDo'), '١', '1'); | |
1632 assert.equal(moment([2011, 0, 2]).format('DDDo'), '٢', '2'); | |
1633 assert.equal(moment([2011, 0, 3]).format('DDDo'), '٣', '3'); | |
1634 assert.equal(moment([2011, 0, 4]).format('DDDo'), '٤', '4'); | |
1635 assert.equal(moment([2011, 0, 5]).format('DDDo'), '٥', '5'); | |
1636 assert.equal(moment([2011, 0, 6]).format('DDDo'), '٦', '6'); | |
1637 assert.equal(moment([2011, 0, 7]).format('DDDo'), '٧', '7'); | |
1638 assert.equal(moment([2011, 0, 8]).format('DDDo'), '٨', '8'); | |
1639 assert.equal(moment([2011, 0, 9]).format('DDDo'), '٩', '9'); | |
1640 assert.equal(moment([2011, 0, 10]).format('DDDo'), '١٠', '10'); | |
1641 | |
1642 assert.equal(moment([2011, 0, 11]).format('DDDo'), '١١', '11'); | |
1643 assert.equal(moment([2011, 0, 12]).format('DDDo'), '١٢', '12'); | |
1644 assert.equal(moment([2011, 0, 13]).format('DDDo'), '١٣', '13'); | |
1645 assert.equal(moment([2011, 0, 14]).format('DDDo'), '١٤', '14'); | |
1646 assert.equal(moment([2011, 0, 15]).format('DDDo'), '١٥', '15'); | |
1647 assert.equal(moment([2011, 0, 16]).format('DDDo'), '١٦', '16'); | |
1648 assert.equal(moment([2011, 0, 17]).format('DDDo'), '١٧', '17'); | |
1649 assert.equal(moment([2011, 0, 18]).format('DDDo'), '١٨', '18'); | |
1650 assert.equal(moment([2011, 0, 19]).format('DDDo'), '١٩', '19'); | |
1651 assert.equal(moment([2011, 0, 20]).format('DDDo'), '٢٠', '20'); | |
1652 | |
1653 assert.equal(moment([2011, 0, 21]).format('DDDo'), '٢١', '21'); | |
1654 assert.equal(moment([2011, 0, 22]).format('DDDo'), '٢٢', '22'); | |
1655 assert.equal(moment([2011, 0, 23]).format('DDDo'), '٢٣', '23'); | |
1656 assert.equal(moment([2011, 0, 24]).format('DDDo'), '٢٤', '24'); | |
1657 assert.equal(moment([2011, 0, 25]).format('DDDo'), '٢٥', '25'); | |
1658 assert.equal(moment([2011, 0, 26]).format('DDDo'), '٢٦', '26'); | |
1659 assert.equal(moment([2011, 0, 27]).format('DDDo'), '٢٧', '27'); | |
1660 assert.equal(moment([2011, 0, 28]).format('DDDo'), '٢٨', '28'); | |
1661 assert.equal(moment([2011, 0, 29]).format('DDDo'), '٢٩', '29'); | |
1662 assert.equal(moment([2011, 0, 30]).format('DDDo'), '٣٠', '30'); | |
1663 | |
1664 assert.equal(moment([2011, 0, 31]).format('DDDo'), '٣١', '31'); | |
1665 }); | |
1666 | |
1667 test('format month', function (assert) { | |
1668 var expected = months, i; | |
1669 for (i = 0; i < expected.length; i++) { | |
1670 assert.equal(moment([2011, i, 1]).format('MMMM'), expected[i], expected[i]); | |
1671 assert.equal(moment([2011, i, 1]).format('MMM'), expected[i], expected[i]); | |
1672 } | |
1673 }); | |
1674 | |
1675 test('format week', function (assert) { | |
1676 var expected = 'الأحد أحد ح_الإثنين إثنين ن_الثلاثاء ثلاثاء ث_الأربعاء أربعاء ر_الخميس خميس خ_الجمعة جمعة ج_السبت سبت س'.split('_'), i; | |
1677 for (i = 0; i < expected.length; i++) { | |
1678 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
1679 } | |
1680 }); | |
1681 | |
1682 test('from', function (assert) { | |
1683 var start = moment([2007, 1, 28]); | |
1684 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), '٤٤ ثانية', '44 seconds = a few seconds'); | |
1685 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'دقيقة واحدة', '45 seconds = a minute'); | |
1686 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'دقيقة واحدة', '89 seconds = a minute'); | |
1687 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), 'دقيقتان', '90 seconds = 2 minutes'); | |
1688 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '٤٤ دقيقة', '44 minutes = 44 minutes'); | |
1689 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ساعة واحدة', '45 minutes = an hour'); | |
1690 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ساعة واحدة', '89 minutes = an hour'); | |
1691 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), 'ساعتان', '90 minutes = 2 hours'); | |
1692 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '٥ ساعات', '5 hours = 5 hours'); | |
1693 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '٢١ ساعة', '21 hours = 21 hours'); | |
1694 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'يوم واحد', '22 hours = a day'); | |
1695 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'يوم واحد', '35 hours = a day'); | |
1696 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), 'يومان', '36 hours = 2 days'); | |
1697 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'يوم واحد', '1 day = a day'); | |
1698 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '٥ أيام', '5 days = 5 days'); | |
1699 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '٢٥ يومًا', '25 days = 25 days'); | |
1700 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'شهر واحد', '26 days = a month'); | |
1701 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'شهر واحد', '30 days = a month'); | |
1702 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'شهر واحد', '43 days = a month'); | |
1703 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), 'شهران', '46 days = 2 months'); | |
1704 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), 'شهران', '75 days = 2 months'); | |
1705 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '٣ أشهر', '76 days = 3 months'); | |
1706 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'شهر واحد', '1 month = a month'); | |
1707 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '٥ أشهر', '5 months = 5 months'); | |
1708 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'عام واحد', '345 days = a year'); | |
1709 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), 'عامان', '548 days = 2 years'); | |
1710 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'عام واحد', '1 year = a year'); | |
1711 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '٥ أعوام', '5 years = 5 years'); | |
1712 }); | |
1713 | |
1714 test('suffix', function (assert) { | |
1715 assert.equal(moment(30000).from(0), 'بعد ٣٠ ثانية', 'prefix'); | |
1716 assert.equal(moment(0).from(30000), 'منذ ٣٠ ثانية', 'suffix'); | |
1717 }); | |
1718 | |
1719 test('now from now', function (assert) { | |
1720 assert.equal(moment().fromNow(), 'منذ ثانية واحدة', 'now from now should display as in the past'); | |
1721 }); | |
1722 | |
1723 test('fromNow', function (assert) { | |
1724 assert.equal(moment().add({s: 30}).fromNow(), 'بعد ٣٠ ثانية', 'in a few seconds'); | |
1725 assert.equal(moment().add({d: 5}).fromNow(), 'بعد ٥ أيام', 'in 5 days'); | |
1726 }); | |
1727 | |
1728 test('calendar day', function (assert) { | |
1729 var a = moment().hours(2).minutes(0).seconds(0); | |
1730 | |
1731 assert.equal(moment(a).calendar(), 'اليوم عند الساعة ٠٢:٠٠', 'today at the same time'); | |
1732 assert.equal(moment(a).add({m: 25}).calendar(), 'اليوم عند الساعة ٠٢:٢٥', 'Now plus 25 min'); | |
1733 assert.equal(moment(a).add({h: 1}).calendar(), 'اليوم عند الساعة ٠٣:٠٠', 'Now plus 1 hour'); | |
1734 assert.equal(moment(a).add({d: 1}).calendar(), 'غدًا عند الساعة ٠٢:٠٠', 'tomorrow at the same time'); | |
1735 assert.equal(moment(a).subtract({h: 1}).calendar(), 'اليوم عند الساعة ٠١:٠٠', 'Now minus 1 hour'); | |
1736 assert.equal(moment(a).subtract({d: 1}).calendar(), 'أمس عند الساعة ٠٢:٠٠', 'yesterday at the same time'); | |
1737 }); | |
1738 | |
1739 test('calendar next week', function (assert) { | |
1740 var i, m; | |
1741 for (i = 2; i < 7; i++) { | |
1742 m = moment().add({d: i}); | |
1743 assert.equal(m.calendar(), m.format('dddd [عند الساعة] LT'), 'Today + ' + i + ' days current time'); | |
1744 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
1745 assert.equal(m.calendar(), m.format('dddd [عند الساعة] LT'), 'Today + ' + i + ' days beginning of day'); | |
1746 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
1747 assert.equal(m.calendar(), m.format('dddd [عند الساعة] LT'), 'Today + ' + i + ' days end of day'); | |
1748 } | |
1749 }); | |
1750 | |
1751 test('calendar last week', function (assert) { | |
1752 var i, m; | |
1753 for (i = 2; i < 7; i++) { | |
1754 m = moment().subtract({d: i}); | |
1755 assert.equal(m.calendar(), m.format('dddd [عند الساعة] LT'), 'Today - ' + i + ' days current time'); | |
1756 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
1757 assert.equal(m.calendar(), m.format('dddd [عند الساعة] LT'), 'Today - ' + i + ' days beginning of day'); | |
1758 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
1759 assert.equal(m.calendar(), m.format('dddd [عند الساعة] LT'), 'Today - ' + i + ' days end of day'); | |
1760 } | |
1761 }); | |
1762 | |
1763 test('calendar all else', function (assert) { | |
1764 var weeksAgo = moment().subtract({w: 1}), | |
1765 weeksFromNow = moment().add({w: 1}); | |
1766 | |
1767 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
1768 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
1769 | |
1770 weeksAgo = moment().subtract({w: 2}); | |
1771 weeksFromNow = moment().add({w: 2}); | |
1772 | |
1773 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
1774 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
1775 }); | |
1776 | |
1777 test('weeks year starting sunday', function (assert) { | |
1778 assert.equal(moment([2011, 11, 31]).week(), 1, 'Dec 31 2011 should be week 1'); | |
1779 assert.equal(moment([2012, 0, 6]).week(), 1, 'Jan 6 2012 should be week 1'); | |
1780 assert.equal(moment([2012, 0, 7]).week(), 2, 'Jan 7 2012 should be week 2'); | |
1781 assert.equal(moment([2012, 0, 13]).week(), 2, 'Jan 13 2012 should be week 2'); | |
1782 assert.equal(moment([2012, 0, 14]).week(), 3, 'Jan 14 2012 should be week 3'); | |
1783 }); | |
1784 | |
1785 test('weeks year starting monday', function (assert) { | |
1786 assert.equal(moment([2006, 11, 30]).week(), 1, 'Dec 30 2006 should be week 1'); | |
1787 assert.equal(moment([2007, 0, 5]).week(), 1, 'Jan 5 2007 should be week 1'); | |
1788 assert.equal(moment([2007, 0, 6]).week(), 2, 'Jan 6 2007 should be week 2'); | |
1789 assert.equal(moment([2007, 0, 12]).week(), 2, 'Jan 12 2007 should be week 2'); | |
1790 assert.equal(moment([2007, 0, 13]).week(), 3, 'Jan 13 2007 should be week 3'); | |
1791 }); | |
1792 | |
1793 test('weeks year starting tuesday', function (assert) { | |
1794 assert.equal(moment([2007, 11, 29]).week(), 1, 'Dec 29 2007 should be week 1'); | |
1795 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
1796 assert.equal(moment([2008, 0, 4]).week(), 1, 'Jan 4 2008 should be week 1'); | |
1797 assert.equal(moment([2008, 0, 5]).week(), 2, 'Jan 5 2008 should be week 2'); | |
1798 assert.equal(moment([2008, 0, 11]).week(), 2, 'Jan 11 2008 should be week 2'); | |
1799 assert.equal(moment([2008, 0, 12]).week(), 3, 'Jan 12 2008 should be week 3'); | |
1800 }); | |
1801 | |
1802 test('weeks year starting wednesday', function (assert) { | |
1803 assert.equal(moment([2002, 11, 28]).week(), 1, 'Dec 28 2002 should be week 1'); | |
1804 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
1805 assert.equal(moment([2003, 0, 3]).week(), 1, 'Jan 3 2003 should be week 1'); | |
1806 assert.equal(moment([2003, 0, 4]).week(), 2, 'Jan 4 2003 should be week 2'); | |
1807 assert.equal(moment([2003, 0, 10]).week(), 2, 'Jan 10 2003 should be week 2'); | |
1808 assert.equal(moment([2003, 0, 11]).week(), 3, 'Jan 11 2003 should be week 3'); | |
1809 | |
1810 assert.equal(moment('2003 1 6', 'gggg w d').format('YYYY-MM-DD'), '٢٠٠٢-١٢-٢٨', 'Week 1 of 2003 should be Dec 28 2002'); | |
1811 assert.equal(moment('2003 1 0', 'gggg w e').format('YYYY-MM-DD'), '٢٠٠٢-١٢-٢٨', 'Week 1 of 2003 should be Dec 28 2002'); | |
1812 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'); | |
1813 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'); | |
1814 }); | |
1815 | |
1816 test('weeks year starting thursday', function (assert) { | |
1817 assert.equal(moment([2008, 11, 27]).week(), 1, 'Dec 27 2008 should be week 1'); | |
1818 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
1819 assert.equal(moment([2009, 0, 2]).week(), 1, 'Jan 2 2009 should be week 1'); | |
1820 assert.equal(moment([2009, 0, 3]).week(), 2, 'Jan 3 2009 should be week 2'); | |
1821 assert.equal(moment([2009, 0, 9]).week(), 2, 'Jan 9 2009 should be week 2'); | |
1822 assert.equal(moment([2009, 0, 10]).week(), 3, 'Jan 10 2009 should be week 3'); | |
1823 }); | |
1824 | |
1825 test('weeks year starting friday', function (assert) { | |
1826 assert.equal(moment([2009, 11, 26]).week(), 1, 'Dec 26 2009 should be week 1'); | |
1827 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
1828 assert.equal(moment([2010, 0, 2]).week(), 2, 'Jan 2 2010 should be week 2'); | |
1829 assert.equal(moment([2010, 0, 8]).week(), 2, 'Jan 8 2010 should be week 2'); | |
1830 assert.equal(moment([2010, 0, 9]).week(), 3, 'Jan 9 2010 should be week 3'); | |
1831 }); | |
1832 | |
1833 test('weeks year starting saturday', function (assert) { | |
1834 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
1835 assert.equal(moment([2011, 0, 7]).week(), 1, 'Jan 7 2011 should be week 1'); | |
1836 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2'); | |
1837 assert.equal(moment([2011, 0, 14]).week(), 2, 'Jan 14 2011 should be week 2'); | |
1838 assert.equal(moment([2011, 0, 15]).week(), 3, 'Jan 15 2011 should be week 3'); | |
1839 }); | |
1840 | |
1841 test('weeks year starting sunday formatted', function (assert) { | |
1842 assert.equal(moment([2011, 11, 31]).format('w ww wo'), '١ ٠١ ١', 'Dec 31 2011 should be week 1'); | |
1843 assert.equal(moment([2012, 0, 6]).format('w ww wo'), '١ ٠١ ١', 'Jan 6 2012 should be week 1'); | |
1844 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '٢ ٠٢ ٢', 'Jan 7 2012 should be week 2'); | |
1845 assert.equal(moment([2012, 0, 13]).format('w ww wo'), '٢ ٠٢ ٢', 'Jan 13 2012 should be week 2'); | |
1846 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '٣ ٠٣ ٣', 'Jan 14 2012 should be week 3'); | |
1847 }); | |
1848 | |
1849 test('lenient ordinal parsing', function (assert) { | |
1850 var i, ordinalStr, testMoment; | |
1851 for (i = 1; i <= 31; ++i) { | |
1852 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
1853 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
1854 assert.equal(testMoment.year(), 2014, | |
1855 'lenient ordinal parsing ' + i + ' year check'); | |
1856 assert.equal(testMoment.month(), 0, | |
1857 'lenient ordinal parsing ' + i + ' month check'); | |
1858 assert.equal(testMoment.date(), i, | |
1859 'lenient ordinal parsing ' + i + ' date check'); | |
1860 } | |
1861 }); | |
1862 | |
1863 test('lenient ordinal parsing of number', function (assert) { | |
1864 var i, testMoment; | |
1865 for (i = 1; i <= 31; ++i) { | |
1866 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
1867 assert.equal(testMoment.year(), 2014, | |
1868 'lenient ordinal parsing of number ' + i + ' year check'); | |
1869 assert.equal(testMoment.month(), 0, | |
1870 'lenient ordinal parsing of number ' + i + ' month check'); | |
1871 assert.equal(testMoment.date(), i, | |
1872 'lenient ordinal parsing of number ' + i + ' date check'); | |
1873 } | |
1874 }); | |
1875 | |
1876 test('strict ordinal parsing', function (assert) { | |
1877 var i, ordinalStr, testMoment; | |
1878 for (i = 1; i <= 31; ++i) { | |
1879 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
1880 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
1881 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
1882 } | |
1883 }); | |
1884 | |
1885 test('no leading zeros in long date formats', function (assert) { | |
1886 var i, j, longDateStr, shortDateStr; | |
1887 for (i = 1; i <= 9; ++i) { | |
1888 for (j = 1; j <= 9; ++j) { | |
1889 longDateStr = moment([2014, i, j]).format('L'); | |
1890 shortDateStr = moment([2014, i, j]).format('l'); | |
1891 assert.equal(longDateStr, shortDateStr, 'should not have leading zeros in month or day'); | |
1892 } | |
1893 } | |
1894 }); | |
1895 | |
1896 })); | |
1897 | |
1898 (function (global, factory) { | |
1899 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
1900 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
1901 factory(global.moment) | |
1902 }(this, function (moment) { 'use strict'; | |
1903 | |
1904 /*global QUnit:false*/ | |
1905 | |
1906 var test = QUnit.test; | |
1907 | |
1908 function module (name, lifecycle) { | |
1909 QUnit.module(name, { | |
1910 setup : function () { | |
1911 moment.locale('en'); | |
1912 moment.createFromInputFallback = function () { | |
1913 throw new Error('input not handled by moment'); | |
1914 }; | |
1915 if (lifecycle && lifecycle.setup) { | |
1916 lifecycle.setup(); | |
1917 } | |
1918 }, | |
1919 teardown : function () { | |
1920 if (lifecycle && lifecycle.teardown) { | |
1921 lifecycle.teardown(); | |
1922 } | |
1923 } | |
1924 }); | |
1925 } | |
1926 | |
1927 function localeModule (name, lifecycle) { | |
1928 QUnit.module('locale:' + name, { | |
1929 setup : function () { | |
1930 moment.locale(name); | |
1931 moment.createFromInputFallback = function () { | |
1932 throw new Error('input not handled by moment'); | |
1933 }; | |
1934 if (lifecycle && lifecycle.setup) { | |
1935 lifecycle.setup(); | |
1936 } | |
1937 }, | |
1938 teardown : function () { | |
1939 moment.locale('en'); | |
1940 if (lifecycle && lifecycle.teardown) { | |
1941 lifecycle.teardown(); | |
1942 } | |
1943 } | |
1944 }); | |
1945 } | |
1946 | |
1947 localeModule('az'); | |
1948 | |
1949 test('parse', function (assert) { | |
1950 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; | |
1951 function equalTest(input, mmm, i) { | |
1952 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
1953 } | |
1954 for (i = 0; i < 12; i++) { | |
1955 tests[i] = tests[i].split(' '); | |
1956 equalTest(tests[i][0], 'MMM', i); | |
1957 equalTest(tests[i][1], 'MMM', i); | |
1958 equalTest(tests[i][0], 'MMMM', i); | |
1959 equalTest(tests[i][1], 'MMMM', i); | |
1960 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
1961 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
1962 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
1963 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
1964 } | |
1965 }); | |
1966 | |
1967 test('format', function (assert) { | |
1968 var a = [ | |
1969 ['dddd, D MMMM YYYY, HH:mm:ss', 'Bazar, 14 fevral 2010, 15:25:50'], | |
1970 ['ddd, A h', 'Baz, gündüz 3'], | |
1971 ['M Mo MM MMMM MMM', '2 2-nci 02 fevral fev'], | |
1972 ['YYYY YY', '2010 10'], | |
1973 ['D Do DD', '14 14-üncü 14'], | |
1974 ['d do dddd ddd dd', '0 0-ıncı Bazar Baz Bz'], | |
1975 ['DDD DDDo DDDD', '45 45-inci 045'], | |
1976 ['w wo ww', '7 7-nci 07'], | |
1977 ['h hh', '3 03'], | |
1978 ['H HH', '15 15'], | |
1979 ['m mm', '25 25'], | |
1980 ['s ss', '50 50'], | |
1981 ['a A', 'gündüz gündüz'], | |
1982 ['[ilin] DDDo [günü]', 'ilin 45-inci günü'], | |
1983 ['LT', '15:25'], | |
1984 ['LTS', '15:25:50'], | |
1985 ['L', '14.02.2010'], | |
1986 ['LL', '14 fevral 2010'], | |
1987 ['LLL', '14 fevral 2010 15:25'], | |
1988 ['LLLL', 'Bazar, 14 fevral 2010 15:25'], | |
1989 ['l', '14.2.2010'], | |
1990 ['ll', '14 fev 2010'], | |
1991 ['lll', '14 fev 2010 15:25'], | |
1992 ['llll', 'Baz, 14 fev 2010 15:25'] | |
1993 ], | |
1994 DDDo = [ | |
1995 [359, '360-ıncı'], | |
1996 [199, '200-üncü'], | |
1997 [149, '150-nci'] | |
1998 ], | |
1999 dt = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
2000 DDDoDt, | |
2001 i; | |
2002 | |
2003 for (i = 0; i < a.length; i++) { | |
2004 assert.equal(dt.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
2005 } | |
2006 for (i = 0; i < DDDo.length; i++) { | |
2007 DDDoDt = moment([2010]); | |
2008 assert.equal(DDDoDt.add(DDDo[i][0], 'days').format('DDDo'), DDDo[i][1], DDDo[i][0] + ' ---> ' + DDDo[i][1]); | |
2009 } | |
2010 }); | |
2011 | |
2012 test('format ordinal', function (assert) { | |
2013 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-inci', '1st'); | |
2014 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-nci', '2nd'); | |
2015 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-üncü', '3rd'); | |
2016 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-üncü', '4th'); | |
2017 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-inci', '5th'); | |
2018 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-ncı', '6th'); | |
2019 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-nci', '7th'); | |
2020 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-inci', '8th'); | |
2021 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-uncu', '9th'); | |
2022 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-uncu', '10th'); | |
2023 | |
2024 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-inci', '11th'); | |
2025 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-nci', '12th'); | |
2026 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-üncü', '13th'); | |
2027 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-üncü', '14th'); | |
2028 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-inci', '15th'); | |
2029 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-ncı', '16th'); | |
2030 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-nci', '17th'); | |
2031 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-inci', '18th'); | |
2032 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-uncu', '19th'); | |
2033 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-nci', '20th'); | |
2034 | |
2035 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-inci', '21th'); | |
2036 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-nci', '22th'); | |
2037 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-üncü', '23th'); | |
2038 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-üncü', '24th'); | |
2039 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-inci', '25th'); | |
2040 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-ncı', '26th'); | |
2041 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-nci', '27th'); | |
2042 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-inci', '28th'); | |
2043 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-uncu', '29th'); | |
2044 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-uncu', '30th'); | |
2045 | |
2046 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-inci', '31st'); | |
2047 }); | |
2048 | |
2049 test('format month', function (assert) { | |
2050 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; | |
2051 for (i = 0; i < expected.length; i++) { | |
2052 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
2053 } | |
2054 }); | |
2055 | |
2056 test('format week', function (assert) { | |
2057 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; | |
2058 for (i = 0; i < expected.length; i++) { | |
2059 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
2060 } | |
2061 }); | |
2062 | |
2063 test('from', function (assert) { | |
2064 var start = moment([2007, 1, 28]); | |
2065 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'birneçə saniyyə', '44 seconds = a few seconds'); | |
2066 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'bir dəqiqə', '45 seconds = a minute'); | |
2067 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'bir dəqiqə', '89 seconds = a minute'); | |
2068 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 dəqiqə', '90 seconds = 2 minutes'); | |
2069 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 dəqiqə', '44 minutes = 44 minutes'); | |
2070 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'bir saat', '45 minutes = an hour'); | |
2071 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'bir saat', '89 minutes = an hour'); | |
2072 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 saat', '90 minutes = 2 hours'); | |
2073 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 saat', '5 hours = 5 hours'); | |
2074 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 saat', '21 hours = 21 hours'); | |
2075 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'bir gün', '22 hours = a day'); | |
2076 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'bir gün', '35 hours = a day'); | |
2077 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 gün', '36 hours = 2 days'); | |
2078 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'bir gün', '1 day = a day'); | |
2079 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 gün', '5 days = 5 days'); | |
2080 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 gün', '25 days = 25 days'); | |
2081 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'bir ay', '26 days = a month'); | |
2082 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'bir ay', '30 days = a month'); | |
2083 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 ay', '46 days = 2 months'); | |
2084 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 ay', '75 days = 2 months'); | |
2085 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 ay', '76 days = 3 months'); | |
2086 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'bir ay', '1 month = a month'); | |
2087 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 ay', '5 months = 5 months'); | |
2088 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'bir il', '345 days = a year'); | |
2089 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 il', '548 days = 2 years'); | |
2090 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'bir il', '1 year = a year'); | |
2091 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 il', '5 years = 5 years'); | |
2092 }); | |
2093 | |
2094 test('suffix', function (assert) { | |
2095 assert.equal(moment(30000).from(0), 'birneçə saniyyə sonra', 'prefix'); | |
2096 assert.equal(moment(0).from(30000), 'birneçə saniyyə əvvəl', 'suffix'); | |
2097 }); | |
2098 | |
2099 test('now from now', function (assert) { | |
2100 assert.equal(moment().fromNow(), 'birneçə saniyyə əvvəl', 'now from now should display as in the past'); | |
2101 }); | |
2102 | |
2103 test('fromNow', function (assert) { | |
2104 assert.equal(moment().add({s: 30}).fromNow(), 'birneçə saniyyə sonra', 'in a few seconds'); | |
2105 assert.equal(moment().add({d: 5}).fromNow(), '5 gün sonra', 'in 5 days'); | |
2106 }); | |
2107 | |
2108 test('calendar day', function (assert) { | |
2109 var a = moment().hours(2).minutes(0).seconds(0); | |
2110 | |
2111 assert.equal(moment(a).calendar(), 'bugün saat 02:00', 'today at the same time'); | |
2112 assert.equal(moment(a).add({m: 25}).calendar(), 'bugün saat 02:25', 'Now plus 25 min'); | |
2113 assert.equal(moment(a).add({h: 1}).calendar(), 'bugün saat 03:00', 'Now plus 1 hour'); | |
2114 assert.equal(moment(a).add({d: 1}).calendar(), 'sabah saat 02:00', 'tomorrow at the same time'); | |
2115 assert.equal(moment(a).subtract({h: 1}).calendar(), 'bugün saat 01:00', 'Now minus 1 hour'); | |
2116 assert.equal(moment(a).subtract({d: 1}).calendar(), 'dünən 02:00', 'yesterday at the same time'); | |
2117 }); | |
2118 | |
2119 test('calendar next week', function (assert) { | |
2120 var i, m; | |
2121 for (i = 2; i < 7; i++) { | |
2122 m = moment().add({d: i}); | |
2123 assert.equal(m.calendar(), m.format('[gələn həftə] dddd [saat] LT'), 'Today + ' + i + ' days current time'); | |
2124 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
2125 assert.equal(m.calendar(), m.format('[gələn həftə] dddd [saat] LT'), 'Today + ' + i + ' days beginning of day'); | |
2126 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
2127 assert.equal(m.calendar(), m.format('[gələn həftə] dddd [saat] LT'), 'Today + ' + i + ' days end of day'); | |
2128 } | |
2129 }); | |
2130 | |
2131 test('calendar last week', function (assert) { | |
2132 var i, m; | |
2133 for (i = 2; i < 7; i++) { | |
2134 m = moment().subtract({d: i}); | |
2135 assert.equal(m.calendar(), m.format('[keçən həftə] dddd [saat] LT'), 'Today - ' + i + ' days current time'); | |
2136 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
2137 assert.equal(m.calendar(), m.format('[keçən həftə] dddd [saat] LT'), 'Today - ' + i + ' days beginning of day'); | |
2138 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
2139 assert.equal(m.calendar(), m.format('[keçən həftə] dddd [saat] LT'), 'Today - ' + i + ' days end of day'); | |
2140 } | |
2141 }); | |
2142 | |
2143 test('calendar all else', function (assert) { | |
2144 var weeksAgo = moment().subtract({w: 1}), | |
2145 weeksFromNow = moment().add({w: 1}); | |
2146 | |
2147 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
2148 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
2149 | |
2150 weeksAgo = moment().subtract({w: 2}); | |
2151 weeksFromNow = moment().add({w: 2}); | |
2152 | |
2153 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
2154 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
2155 }); | |
2156 | |
2157 test('weeks year starting sunday', function (assert) { | |
2158 assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1'); | |
2159 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
2160 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2'); | |
2161 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
2162 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3'); | |
2163 }); | |
2164 | |
2165 test('weeks year starting monday', function (assert) { | |
2166 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
2167 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
2168 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
2169 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
2170 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
2171 }); | |
2172 | |
2173 test('weeks year starting tuesday', function (assert) { | |
2174 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
2175 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
2176 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
2177 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
2178 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
2179 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
2180 }); | |
2181 | |
2182 test('weeks year starting wednesday', function (assert) { | |
2183 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
2184 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
2185 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
2186 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
2187 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
2188 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
2189 }); | |
2190 | |
2191 test('weeks year starting thursday', function (assert) { | |
2192 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
2193 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
2194 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
2195 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
2196 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
2197 assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3'); | |
2198 }); | |
2199 | |
2200 test('weeks year starting friday', function (assert) { | |
2201 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1'); | |
2202 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
2203 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1'); | |
2204 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2'); | |
2205 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2'); | |
2206 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3'); | |
2207 }); | |
2208 | |
2209 test('weeks year starting saturday', function (assert) { | |
2210 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1'); | |
2211 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
2212 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1'); | |
2213 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2'); | |
2214 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2'); | |
2215 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3'); | |
2216 }); | |
2217 | |
2218 test('weeks year starting sunday formatted', function (assert) { | |
2219 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-inci', 'Dec 26 2011 should be week 1'); | |
2220 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-inci', 'Jan 1 2012 should be week 1'); | |
2221 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-nci', 'Jan 2 2012 should be week 2'); | |
2222 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-nci', 'Jan 8 2012 should be week 2'); | |
2223 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-üncü', 'Jan 9 2012 should be week 3'); | |
2224 }); | |
2225 | |
2226 test('lenient ordinal parsing', function (assert) { | |
2227 var i, ordinalStr, testMoment; | |
2228 for (i = 1; i <= 31; ++i) { | |
2229 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
2230 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
2231 assert.equal(testMoment.year(), 2014, | |
2232 'lenient ordinal parsing ' + i + ' year check'); | |
2233 assert.equal(testMoment.month(), 0, | |
2234 'lenient ordinal parsing ' + i + ' month check'); | |
2235 assert.equal(testMoment.date(), i, | |
2236 'lenient ordinal parsing ' + i + ' date check'); | |
2237 } | |
2238 }); | |
2239 | |
2240 test('lenient ordinal parsing of number', function (assert) { | |
2241 var i, testMoment; | |
2242 for (i = 1; i <= 31; ++i) { | |
2243 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
2244 assert.equal(testMoment.year(), 2014, | |
2245 'lenient ordinal parsing of number ' + i + ' year check'); | |
2246 assert.equal(testMoment.month(), 0, | |
2247 'lenient ordinal parsing of number ' + i + ' month check'); | |
2248 assert.equal(testMoment.date(), i, | |
2249 'lenient ordinal parsing of number ' + i + ' date check'); | |
2250 } | |
2251 }); | |
2252 | |
2253 test('strict ordinal parsing', function (assert) { | |
2254 var i, ordinalStr, testMoment; | |
2255 for (i = 1; i <= 31; ++i) { | |
2256 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
2257 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
2258 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
2259 } | |
2260 }); | |
2261 | |
2262 })); | |
2263 | |
2264 (function (global, factory) { | |
2265 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
2266 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
2267 factory(global.moment) | |
2268 }(this, function (moment) { 'use strict'; | |
2269 | |
2270 /*global QUnit:false*/ | |
2271 | |
2272 var test = QUnit.test; | |
2273 | |
2274 function module (name, lifecycle) { | |
2275 QUnit.module(name, { | |
2276 setup : function () { | |
2277 moment.locale('en'); | |
2278 moment.createFromInputFallback = function () { | |
2279 throw new Error('input not handled by moment'); | |
2280 }; | |
2281 if (lifecycle && lifecycle.setup) { | |
2282 lifecycle.setup(); | |
2283 } | |
2284 }, | |
2285 teardown : function () { | |
2286 if (lifecycle && lifecycle.teardown) { | |
2287 lifecycle.teardown(); | |
2288 } | |
2289 } | |
2290 }); | |
2291 } | |
2292 | |
2293 function localeModule (name, lifecycle) { | |
2294 QUnit.module('locale:' + name, { | |
2295 setup : function () { | |
2296 moment.locale(name); | |
2297 moment.createFromInputFallback = function () { | |
2298 throw new Error('input not handled by moment'); | |
2299 }; | |
2300 if (lifecycle && lifecycle.setup) { | |
2301 lifecycle.setup(); | |
2302 } | |
2303 }, | |
2304 teardown : function () { | |
2305 moment.locale('en'); | |
2306 if (lifecycle && lifecycle.teardown) { | |
2307 lifecycle.teardown(); | |
2308 } | |
2309 } | |
2310 }); | |
2311 } | |
2312 | |
2313 localeModule('be'); | |
2314 | |
2315 test('parse', function (assert) { | |
2316 var tests = 'студзень студ_люты лют_сакавік сак_красавік крас_травень трав_чэрвень чэрв_ліпень ліп_жнівень жнів_верасень вер_кастрычнік каст_лістапад ліст_снежань снеж'.split('_'), i; | |
2317 function equalTest(input, mmm, i) { | |
2318 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
2319 } | |
2320 for (i = 0; i < 12; i++) { | |
2321 tests[i] = tests[i].split(' '); | |
2322 equalTest(tests[i][0], 'MMM', i); | |
2323 equalTest(tests[i][1], 'MMM', i); | |
2324 equalTest(tests[i][0], 'MMMM', i); | |
2325 equalTest(tests[i][1], 'MMMM', i); | |
2326 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
2327 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
2328 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
2329 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
2330 } | |
2331 }); | |
2332 | |
2333 test('format', function (assert) { | |
2334 var a = [ | |
2335 ['dddd, Do MMMM YYYY, HH:mm:ss', 'нядзеля, 14-га лютага 2010, 15:25:50'], | |
2336 ['ddd, h A', 'нд, 3 дня'], | |
2337 ['M Mo MM MMMM MMM', '2 2-і 02 люты лют'], | |
2338 ['YYYY YY', '2010 10'], | |
2339 ['D Do DD', '14 14-га 14'], | |
2340 ['d do dddd ddd dd', '0 0-ы нядзеля нд нд'], | |
2341 ['DDD DDDo DDDD', '45 45-ы 045'], | |
2342 ['w wo ww', '7 7-ы 07'], | |
2343 ['h hh', '3 03'], | |
2344 ['H HH', '15 15'], | |
2345 ['m mm', '25 25'], | |
2346 ['s ss', '50 50'], | |
2347 ['a A', 'дня дня'], | |
2348 ['DDDo [дзень года]', '45-ы дзень года'], | |
2349 ['LT', '15:25'], | |
2350 ['LTS', '15:25:50'], | |
2351 ['L', '14.02.2010'], | |
2352 ['LL', '14 лютага 2010 г.'], | |
2353 ['LLL', '14 лютага 2010 г., 15:25'], | |
2354 ['LLLL', 'нядзеля, 14 лютага 2010 г., 15:25'], | |
2355 ['l', '14.2.2010'], | |
2356 ['ll', '14 лют 2010 г.'], | |
2357 ['lll', '14 лют 2010 г., 15:25'], | |
2358 ['llll', 'нд, 14 лют 2010 г., 15:25'] | |
2359 ], | |
2360 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
2361 i; | |
2362 for (i = 0; i < a.length; i++) { | |
2363 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
2364 } | |
2365 }); | |
2366 | |
2367 test('format meridiem', function (assert) { | |
2368 assert.equal(moment([2012, 11, 28, 0, 0]).format('A'), 'ночы', 'night'); | |
2369 assert.equal(moment([2012, 11, 28, 3, 59]).format('A'), 'ночы', 'night'); | |
2370 assert.equal(moment([2012, 11, 28, 4, 0]).format('A'), 'раніцы', 'morning'); | |
2371 assert.equal(moment([2012, 11, 28, 11, 59]).format('A'), 'раніцы', 'morning'); | |
2372 assert.equal(moment([2012, 11, 28, 12, 0]).format('A'), 'дня', 'afternoon'); | |
2373 assert.equal(moment([2012, 11, 28, 16, 59]).format('A'), 'дня', 'afternoon'); | |
2374 assert.equal(moment([2012, 11, 28, 17, 0]).format('A'), 'вечара', 'evening'); | |
2375 assert.equal(moment([2012, 11, 28, 23, 59]).format('A'), 'вечара', 'evening'); | |
2376 }); | |
2377 | |
2378 test('format ordinal', function (assert) { | |
2379 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-ы', '1-ы'); | |
2380 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-і', '2-і'); | |
2381 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-і', '3-і'); | |
2382 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-ы', '4-ы'); | |
2383 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-ы', '5-ы'); | |
2384 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-ы', '6-ы'); | |
2385 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-ы', '7-ы'); | |
2386 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-ы', '8-ы'); | |
2387 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-ы', '9-ы'); | |
2388 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-ы', '10-ы'); | |
2389 | |
2390 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-ы', '11-ы'); | |
2391 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-ы', '12-ы'); | |
2392 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-ы', '13-ы'); | |
2393 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-ы', '14-ы'); | |
2394 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-ы', '15-ы'); | |
2395 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-ы', '16-ы'); | |
2396 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-ы', '17-ы'); | |
2397 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-ы', '18-ы'); | |
2398 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-ы', '19-ы'); | |
2399 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-ы', '20-ы'); | |
2400 | |
2401 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-ы', '21-ы'); | |
2402 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-і', '22-і'); | |
2403 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-і', '23-і'); | |
2404 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-ы', '24-ы'); | |
2405 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-ы', '25-ы'); | |
2406 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-ы', '26-ы'); | |
2407 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-ы', '27-ы'); | |
2408 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-ы', '28-ы'); | |
2409 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-ы', '29-ы'); | |
2410 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-ы', '30-ы'); | |
2411 | |
2412 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-ы', '31-ы'); | |
2413 }); | |
2414 | |
2415 test('format month', function (assert) { | |
2416 var expected = 'студзень студ_люты лют_сакавік сак_красавік крас_травень трав_чэрвень чэрв_ліпень ліп_жнівень жнів_верасень вер_кастрычнік каст_лістапад ліст_снежань снеж'.split('_'), i; | |
2417 for (i = 0; i < expected.length; i++) { | |
2418 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
2419 } | |
2420 }); | |
2421 | |
2422 test('format month case', function (assert) { | |
2423 var months = { | |
2424 'nominative': 'студзень_люты_сакавік_красавік_травень_чэрвень_ліпень_жнівень_верасень_кастрычнік_лістапад_снежань'.split('_'), | |
2425 'accusative': 'студзеня_лютага_сакавіка_красавіка_траўня_чэрвеня_ліпеня_жніўня_верасня_кастрычніка_лістапада_снежня'.split('_') | |
2426 }, i; | |
2427 for (i = 0; i < 12; i++) { | |
2428 assert.equal(moment([2011, i, 1]).format('D MMMM'), '1 ' + months.accusative[i], '1 ' + months.accusative[i]); | |
2429 assert.equal(moment([2011, i, 1]).format('MMMM'), months.nominative[i], '1 ' + months.nominative[i]); | |
2430 } | |
2431 }); | |
2432 | |
2433 test('format month case with escaped symbols', function (assert) { | |
2434 var months = { | |
2435 'nominative': 'студзень_люты_сакавік_красавік_травень_чэрвень_ліпень_жнівень_верасень_кастрычнік_лістапад_снежань'.split('_'), | |
2436 'accusative': 'студзеня_лютага_сакавіка_красавіка_траўня_чэрвеня_ліпеня_жніўня_верасня_кастрычніка_лістапада_снежня'.split('_') | |
2437 }, i; | |
2438 for (i = 0; i < 12; i++) { | |
2439 assert.equal(moment([2013, i, 1]).format('D[] MMMM'), '1 ' + months.accusative[i], '1 ' + months.accusative[i]); | |
2440 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>'); | |
2441 assert.equal(moment([2013, i, 1]).format('D[-ы дзень] MMMM'), '1-ы дзень ' + months.accusative[i], '1-ы дзень ' + months.accusative[i]); | |
2442 assert.equal(moment([2013, i, 1]).format('D, MMMM'), '1, ' + months.nominative[i], '1, ' + months.nominative[i]); | |
2443 } | |
2444 }); | |
2445 | |
2446 test('format week', function (assert) { | |
2447 var expected = 'нядзеля нд нд_панядзелак пн пн_аўторак ат ат_серада ср ср_чацвер чц чц_пятніца пт пт_субота сб сб'.split('_'), i; | |
2448 for (i = 0; i < expected.length; i++) { | |
2449 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
2450 } | |
2451 }); | |
2452 | |
2453 test('from', function (assert) { | |
2454 var start = moment([2007, 1, 28]); | |
2455 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'некалькі секунд', '44 seconds = a few seconds'); | |
2456 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'хвіліна', '45 seconds = a minute'); | |
2457 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'хвіліна', '89 seconds = a minute'); | |
2458 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 хвіліны', '90 seconds = 2 minutes'); | |
2459 assert.equal(start.from(moment([2007, 1, 28]).add({m: 31}), true), '31 хвіліна', '31 minutes = 31 minutes'); | |
2460 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 хвіліны', '44 minutes = 44 minutes'); | |
2461 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'гадзіна', '45 minutes = an hour'); | |
2462 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'гадзіна', '89 minutes = an hour'); | |
2463 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 гадзіны', '90 minutes = 2 hours'); | |
2464 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 гадзін', '5 hours = 5 hours'); | |
2465 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 гадзіна', '21 hours = 21 hours'); | |
2466 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'дзень', '22 hours = a day'); | |
2467 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'дзень', '35 hours = a day'); | |
2468 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 дні', '36 hours = 2 days'); | |
2469 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'дзень', '1 day = a day'); | |
2470 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 дзён', '5 days = 5 days'); | |
2471 assert.equal(start.from(moment([2007, 1, 28]).add({d: 11}), true), '11 дзён', '11 days = 11 days'); | |
2472 assert.equal(start.from(moment([2007, 1, 28]).add({d: 21}), true), '21 дзень', '21 days = 21 days'); | |
2473 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 дзён', '25 days = 25 days'); | |
2474 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'месяц', '26 days = a month'); | |
2475 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'месяц', '30 days = a month'); | |
2476 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'месяц', '43 days = a month'); | |
2477 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 месяцы', '46 days = 2 months'); | |
2478 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 месяцы', '75 days = 2 months'); | |
2479 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 месяцы', '76 days = 3 months'); | |
2480 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'месяц', '1 month = a month'); | |
2481 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 месяцаў', '5 months = 5 months'); | |
2482 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'год', '345 days = a year'); | |
2483 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 гады', '548 days = 2 years'); | |
2484 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'год', '1 year = a year'); | |
2485 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 гадоў', '5 years = 5 years'); | |
2486 }); | |
2487 | |
2488 test('suffix', function (assert) { | |
2489 assert.equal(moment(30000).from(0), 'праз некалькі секунд', 'prefix'); | |
2490 assert.equal(moment(0).from(30000), 'некалькі секунд таму', 'suffix'); | |
2491 }); | |
2492 | |
2493 test('fromNow', function (assert) { | |
2494 assert.equal(moment().add({s: 30}).fromNow(), 'праз некалькі секунд', 'in a few seconds'); | |
2495 assert.equal(moment().add({d: 5}).fromNow(), 'праз 5 дзён', 'in 5 days'); | |
2496 assert.equal(moment().add({m: 31}).fromNow(), 'праз 31 хвіліну', 'in 31 minutes = in 31 minutes'); | |
2497 assert.equal(moment().subtract({m: 31}).fromNow(), '31 хвіліну таму', '31 minutes ago = 31 minutes ago'); | |
2498 }); | |
2499 | |
2500 test('calendar day', function (assert) { | |
2501 var a = moment().hours(2).minutes(0).seconds(0); | |
2502 | |
2503 assert.equal(moment(a).calendar(), 'Сёння ў 02:00', 'today at the same time'); | |
2504 assert.equal(moment(a).add({m: 25}).calendar(), 'Сёння ў 02:25', 'Now plus 25 min'); | |
2505 assert.equal(moment(a).add({h: 1}).calendar(), 'Сёння ў 03:00', 'Now plus 1 hour'); | |
2506 assert.equal(moment(a).add({d: 1}).calendar(), 'Заўтра ў 02:00', 'tomorrow at the same time'); | |
2507 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Сёння ў 01:00', 'Now minus 1 hour'); | |
2508 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Учора ў 02:00', 'yesterday at the same time'); | |
2509 }); | |
2510 | |
2511 test('calendar next week', function (assert) { | |
2512 var i, m; | |
2513 function makeFormat(d) { | |
2514 return '[У] dddd [ў] LT'; | |
2515 } | |
2516 | |
2517 for (i = 2; i < 7; i++) { | |
2518 m = moment().add({d: i}); | |
2519 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time'); | |
2520 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
2521 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day'); | |
2522 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
2523 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day'); | |
2524 } | |
2525 }); | |
2526 | |
2527 test('calendar last week', function (assert) { | |
2528 var i, m; | |
2529 | |
2530 function makeFormat(d) { | |
2531 switch (d.day()) { | |
2532 case 0: | |
2533 case 3: | |
2534 case 5: | |
2535 case 6: | |
2536 return '[У мінулую] dddd [ў] LT'; | |
2537 case 1: | |
2538 case 2: | |
2539 case 4: | |
2540 return '[У мінулы] dddd [ў] LT'; | |
2541 } | |
2542 } | |
2543 | |
2544 for (i = 2; i < 7; i++) { | |
2545 m = moment().subtract({d: i}); | |
2546 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time'); | |
2547 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
2548 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day'); | |
2549 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
2550 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day'); | |
2551 } | |
2552 }); | |
2553 | |
2554 test('calendar all else', function (assert) { | |
2555 var weeksAgo = moment().subtract({w: 1}), | |
2556 weeksFromNow = moment().add({w: 1}); | |
2557 | |
2558 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
2559 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
2560 | |
2561 weeksAgo = moment().subtract({w: 2}); | |
2562 weeksFromNow = moment().add({w: 2}); | |
2563 | |
2564 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
2565 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
2566 }); | |
2567 | |
2568 test('weeks year starting sunday', function (assert) { | |
2569 assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1'); | |
2570 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
2571 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2'); | |
2572 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
2573 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3'); | |
2574 }); | |
2575 | |
2576 test('weeks year starting monday', function (assert) { | |
2577 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
2578 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
2579 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
2580 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
2581 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
2582 }); | |
2583 | |
2584 test('weeks year starting tuesday', function (assert) { | |
2585 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
2586 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
2587 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
2588 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
2589 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
2590 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
2591 }); | |
2592 | |
2593 test('weeks year starting wednesday', function (assert) { | |
2594 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
2595 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
2596 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
2597 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
2598 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
2599 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
2600 }); | |
2601 | |
2602 test('weeks year starting thursday', function (assert) { | |
2603 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
2604 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
2605 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
2606 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
2607 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
2608 assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3'); | |
2609 }); | |
2610 | |
2611 test('weeks year starting friday', function (assert) { | |
2612 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1'); | |
2613 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
2614 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1'); | |
2615 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2'); | |
2616 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2'); | |
2617 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3'); | |
2618 }); | |
2619 | |
2620 test('weeks year starting saturday', function (assert) { | |
2621 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1'); | |
2622 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
2623 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1'); | |
2624 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2'); | |
2625 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2'); | |
2626 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3'); | |
2627 }); | |
2628 | |
2629 test('weeks year starting sunday formatted', function (assert) { | |
2630 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-ы', 'Dec 26 2011 should be week 1'); | |
2631 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-ы', 'Jan 1 2012 should be week 1'); | |
2632 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-і', 'Jan 2 2012 should be week 2'); | |
2633 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-і', 'Jan 8 2012 should be week 2'); | |
2634 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-і', 'Jan 9 2012 should be week 3'); | |
2635 }); | |
2636 | |
2637 test('lenient ordinal parsing', function (assert) { | |
2638 var i, ordinalStr, testMoment; | |
2639 for (i = 1; i <= 31; ++i) { | |
2640 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
2641 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
2642 assert.equal(testMoment.year(), 2014, | |
2643 'lenient ordinal parsing ' + i + ' year check'); | |
2644 assert.equal(testMoment.month(), 0, | |
2645 'lenient ordinal parsing ' + i + ' month check'); | |
2646 assert.equal(testMoment.date(), i, | |
2647 'lenient ordinal parsing ' + i + ' date check'); | |
2648 } | |
2649 }); | |
2650 | |
2651 test('lenient ordinal parsing of number', function (assert) { | |
2652 var i, testMoment; | |
2653 for (i = 1; i <= 31; ++i) { | |
2654 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
2655 assert.equal(testMoment.year(), 2014, | |
2656 'lenient ordinal parsing of number ' + i + ' year check'); | |
2657 assert.equal(testMoment.month(), 0, | |
2658 'lenient ordinal parsing of number ' + i + ' month check'); | |
2659 assert.equal(testMoment.date(), i, | |
2660 'lenient ordinal parsing of number ' + i + ' date check'); | |
2661 } | |
2662 }); | |
2663 | |
2664 test('strict ordinal parsing', function (assert) { | |
2665 var i, ordinalStr, testMoment; | |
2666 for (i = 1; i <= 31; ++i) { | |
2667 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
2668 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
2669 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
2670 } | |
2671 }); | |
2672 | |
2673 })); | |
2674 | |
2675 (function (global, factory) { | |
2676 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
2677 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
2678 factory(global.moment) | |
2679 }(this, function (moment) { 'use strict'; | |
2680 | |
2681 /*global QUnit:false*/ | |
2682 | |
2683 var test = QUnit.test; | |
2684 | |
2685 function module (name, lifecycle) { | |
2686 QUnit.module(name, { | |
2687 setup : function () { | |
2688 moment.locale('en'); | |
2689 moment.createFromInputFallback = function () { | |
2690 throw new Error('input not handled by moment'); | |
2691 }; | |
2692 if (lifecycle && lifecycle.setup) { | |
2693 lifecycle.setup(); | |
2694 } | |
2695 }, | |
2696 teardown : function () { | |
2697 if (lifecycle && lifecycle.teardown) { | |
2698 lifecycle.teardown(); | |
2699 } | |
2700 } | |
2701 }); | |
2702 } | |
2703 | |
2704 function localeModule (name, lifecycle) { | |
2705 QUnit.module('locale:' + name, { | |
2706 setup : function () { | |
2707 moment.locale(name); | |
2708 moment.createFromInputFallback = function () { | |
2709 throw new Error('input not handled by moment'); | |
2710 }; | |
2711 if (lifecycle && lifecycle.setup) { | |
2712 lifecycle.setup(); | |
2713 } | |
2714 }, | |
2715 teardown : function () { | |
2716 moment.locale('en'); | |
2717 if (lifecycle && lifecycle.teardown) { | |
2718 lifecycle.teardown(); | |
2719 } | |
2720 } | |
2721 }); | |
2722 } | |
2723 | |
2724 localeModule('bg'); | |
2725 | |
2726 test('parse', function (assert) { | |
2727 var tests = 'януари янр_февруари фев_март мар_април апр_май май_юни юни_юли юли_август авг_септември сеп_октомври окт_ноември ное_декември дек'.split('_'), i; | |
2728 function equalTest(input, mmm, i) { | |
2729 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
2730 } | |
2731 for (i = 0; i < 12; i++) { | |
2732 tests[i] = tests[i].split(' '); | |
2733 equalTest(tests[i][0], 'MMM', i); | |
2734 equalTest(tests[i][1], 'MMM', i); | |
2735 equalTest(tests[i][0], 'MMMM', i); | |
2736 equalTest(tests[i][1], 'MMMM', i); | |
2737 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
2738 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
2739 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
2740 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
2741 } | |
2742 }); | |
2743 | |
2744 test('format', function (assert) { | |
2745 var a = [ | |
2746 ['dddd, MMMM Do YYYY, H:mm:ss', 'неделя, февруари 14-ти 2010, 15:25:50'], | |
2747 ['ddd, hA', 'нед, 3PM'], | |
2748 ['M Mo MM MMMM MMM', '2 2-ри 02 февруари фев'], | |
2749 ['YYYY YY', '2010 10'], | |
2750 ['D Do DD', '14 14-ти 14'], | |
2751 ['d do dddd ddd dd', '0 0-ев неделя нед нд'], | |
2752 ['DDD DDDo DDDD', '45 45-ти 045'], | |
2753 ['w wo ww', '7 7-ми 07'], | |
2754 ['h hh', '3 03'], | |
2755 ['H HH', '15 15'], | |
2756 ['m mm', '25 25'], | |
2757 ['s ss', '50 50'], | |
2758 ['a A', 'pm PM'], | |
2759 ['[the] DDDo [day of the year]', 'the 45-ти day of the year'], | |
2760 ['LT', '15:25'], | |
2761 ['LTS', '15:25:50'], | |
2762 ['L', '14.02.2010'], | |
2763 ['LL', '14 февруари 2010'], | |
2764 ['LLL', '14 февруари 2010 15:25'], | |
2765 ['LLLL', 'неделя, 14 февруари 2010 15:25'], | |
2766 ['l', '14.2.2010'], | |
2767 ['ll', '14 фев 2010'], | |
2768 ['lll', '14 фев 2010 15:25'], | |
2769 ['llll', 'нед, 14 фев 2010 15:25'] | |
2770 ], | |
2771 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
2772 i; | |
2773 for (i = 0; i < a.length; i++) { | |
2774 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
2775 } | |
2776 }); | |
2777 | |
2778 test('format ordinal', function (assert) { | |
2779 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-ви', '1-ви'); | |
2780 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-ри', '2-ри'); | |
2781 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-ти', '3-ти'); | |
2782 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-ти', '4-ти'); | |
2783 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-ти', '5-ти'); | |
2784 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-ти', '6-ти'); | |
2785 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-ми', '7-ми'); | |
2786 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-ми', '8-ми'); | |
2787 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-ти', '9-ти'); | |
2788 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-ти', '10-ти'); | |
2789 | |
2790 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-ти', '11-ти'); | |
2791 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-ти', '12-ти'); | |
2792 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-ти', '13-ти'); | |
2793 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-ти', '14-ти'); | |
2794 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-ти', '15-ти'); | |
2795 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-ти', '16-ти'); | |
2796 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-ти', '17-ти'); | |
2797 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-ти', '18-ти'); | |
2798 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-ти', '19-ти'); | |
2799 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-ти', '20-ти'); | |
2800 | |
2801 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-ви', '21-ви'); | |
2802 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-ри', '22-ри'); | |
2803 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-ти', '23-ти'); | |
2804 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-ти', '24-ти'); | |
2805 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-ти', '25-ти'); | |
2806 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-ти', '26-ти'); | |
2807 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-ми', '27-ми'); | |
2808 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-ми', '28-ми'); | |
2809 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-ти', '29-ти'); | |
2810 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-ти', '30-ти'); | |
2811 | |
2812 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-ви', '31-ви'); | |
2813 }); | |
2814 | |
2815 test('format month', function (assert) { | |
2816 var expected = 'януари янр_февруари фев_март мар_април апр_май май_юни юни_юли юли_август авг_септември сеп_октомври окт_ноември ное_декември дек'.split('_'), i; | |
2817 for (i = 0; i < expected.length; i++) { | |
2818 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
2819 } | |
2820 }); | |
2821 | |
2822 test('format week', function (assert) { | |
2823 var expected = 'неделя нед нд_понеделник пон пн_вторник вто вт_сряда сря ср_четвъртък чет чт_петък пет пт_събота съб сб'.split('_'), i; | |
2824 for (i = 0; i < expected.length; i++) { | |
2825 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
2826 } | |
2827 }); | |
2828 | |
2829 test('from', function (assert) { | |
2830 var start = moment([2007, 1, 28]); | |
2831 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'няколко секунди', '44 seconds = a few seconds'); | |
2832 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'минута', '45 seconds = a minute'); | |
2833 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'минута', '89 seconds = a minute'); | |
2834 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 минути', '90 seconds = 2 minutes'); | |
2835 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 минути', '44 minutes = 44 minutes'); | |
2836 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'час', '45 minutes = an hour'); | |
2837 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'час', '89 minutes = an hour'); | |
2838 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 часа', '90 minutes = 2 hours'); | |
2839 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 часа', '5 hours = 5 hours'); | |
2840 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 часа', '21 hours = 21 hours'); | |
2841 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ден', '22 hours = a day'); | |
2842 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ден', '35 hours = a day'); | |
2843 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 дни', '36 hours = 2 days'); | |
2844 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ден', '1 day = a day'); | |
2845 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 дни', '5 days = 5 days'); | |
2846 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 дни', '25 days = 25 days'); | |
2847 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'месец', '26 days = a month'); | |
2848 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'месец', '30 days = a month'); | |
2849 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'месец', '43 days = a month'); | |
2850 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 месеца', '46 days = 2 months'); | |
2851 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 месеца', '75 days = 2 months'); | |
2852 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 месеца', '76 days = 3 months'); | |
2853 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'месец', '1 month = a month'); | |
2854 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 месеца', '5 months = 5 months'); | |
2855 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'година', '345 days = a year'); | |
2856 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 години', '548 days = 2 years'); | |
2857 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'година', '1 year = a year'); | |
2858 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 години', '5 years = 5 years'); | |
2859 }); | |
2860 | |
2861 test('suffix', function (assert) { | |
2862 assert.equal(moment(30000).from(0), 'след няколко секунди', 'prefix'); | |
2863 assert.equal(moment(0).from(30000), 'преди няколко секунди', 'suffix'); | |
2864 }); | |
2865 | |
2866 test('now from now', function (assert) { | |
2867 assert.equal(moment().fromNow(), 'преди няколко секунди', 'now from now should display as in the past'); | |
2868 }); | |
2869 | |
2870 test('fromNow', function (assert) { | |
2871 assert.equal(moment().add({s: 30}).fromNow(), 'след няколко секунди', 'in a few seconds'); | |
2872 assert.equal(moment().add({d: 5}).fromNow(), 'след 5 дни', 'in 5 days'); | |
2873 }); | |
2874 | |
2875 test('calendar day', function (assert) { | |
2876 var a = moment().hours(2).minutes(0).seconds(0); | |
2877 | |
2878 assert.equal(moment(a).calendar(), 'Днес в 2:00', 'today at the same time'); | |
2879 assert.equal(moment(a).add({m: 25}).calendar(), 'Днес в 2:25', 'Now plus 25 min'); | |
2880 assert.equal(moment(a).add({h: 1}).calendar(), 'Днес в 3:00', 'Now plus 1 hour'); | |
2881 assert.equal(moment(a).add({d: 1}).calendar(), 'Утре в 2:00', 'tomorrow at the same time'); | |
2882 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Днес в 1:00', 'Now minus 1 hour'); | |
2883 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Вчера в 2:00', 'yesterday at the same time'); | |
2884 }); | |
2885 | |
2886 test('calendar next week', function (assert) { | |
2887 var i, m; | |
2888 for (i = 2; i < 7; i++) { | |
2889 m = moment().add({d: i}); | |
2890 assert.equal(m.calendar(), m.format('dddd [в] LT'), 'Today + ' + i + ' days current time'); | |
2891 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
2892 assert.equal(m.calendar(), m.format('dddd [в] LT'), 'Today + ' + i + ' days beginning of day'); | |
2893 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
2894 assert.equal(m.calendar(), m.format('dddd [в] LT'), 'Today + ' + i + ' days end of day'); | |
2895 } | |
2896 }); | |
2897 | |
2898 test('calendar last week', function (assert) { | |
2899 var i, m; | |
2900 | |
2901 function makeFormat(d) { | |
2902 switch (d.day()) { | |
2903 case 0: | |
2904 case 3: | |
2905 case 6: | |
2906 return '[В изминалата] dddd [в] LT'; | |
2907 case 1: | |
2908 case 2: | |
2909 case 4: | |
2910 case 5: | |
2911 return '[В изминалия] dddd [в] LT'; | |
2912 } | |
2913 } | |
2914 | |
2915 for (i = 2; i < 7; i++) { | |
2916 m = moment().subtract({d: i}); | |
2917 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time'); | |
2918 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
2919 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day'); | |
2920 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
2921 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day'); | |
2922 } | |
2923 }); | |
2924 | |
2925 test('calendar all else', function (assert) { | |
2926 var weeksAgo = moment().subtract({w: 1}), | |
2927 weeksFromNow = moment().add({w: 1}); | |
2928 | |
2929 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
2930 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
2931 | |
2932 weeksAgo = moment().subtract({w: 2}); | |
2933 weeksFromNow = moment().add({w: 2}); | |
2934 | |
2935 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
2936 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
2937 }); | |
2938 | |
2939 test('weeks year starting sunday', function (assert) { | |
2940 assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1'); | |
2941 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
2942 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2'); | |
2943 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
2944 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3'); | |
2945 }); | |
2946 | |
2947 test('weeks year starting monday', function (assert) { | |
2948 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
2949 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
2950 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
2951 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
2952 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
2953 }); | |
2954 | |
2955 test('weeks year starting tuesday', function (assert) { | |
2956 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
2957 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
2958 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
2959 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
2960 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
2961 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
2962 }); | |
2963 | |
2964 test('weeks year starting wednesday', function (assert) { | |
2965 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
2966 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
2967 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
2968 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
2969 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
2970 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
2971 }); | |
2972 | |
2973 test('weeks year starting thursday', function (assert) { | |
2974 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
2975 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
2976 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
2977 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
2978 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
2979 assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3'); | |
2980 }); | |
2981 | |
2982 test('weeks year starting friday', function (assert) { | |
2983 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1'); | |
2984 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
2985 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1'); | |
2986 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2'); | |
2987 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2'); | |
2988 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3'); | |
2989 }); | |
2990 | |
2991 test('weeks year starting saturday', function (assert) { | |
2992 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1'); | |
2993 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
2994 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1'); | |
2995 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2'); | |
2996 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2'); | |
2997 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3'); | |
2998 }); | |
2999 | |
3000 test('weeks year starting sunday formatted', function (assert) { | |
3001 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-ви', 'Dec 26 2011 should be week 1'); | |
3002 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-ви', 'Jan 1 2012 should be week 1'); | |
3003 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-ри', 'Jan 2 2012 should be week 2'); | |
3004 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-ри', 'Jan 8 2012 should be week 2'); | |
3005 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-ти', 'Jan 9 2012 should be week 3'); | |
3006 }); | |
3007 | |
3008 test('lenient ordinal parsing', function (assert) { | |
3009 var i, ordinalStr, testMoment; | |
3010 for (i = 1; i <= 31; ++i) { | |
3011 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
3012 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
3013 assert.equal(testMoment.year(), 2014, | |
3014 'lenient ordinal parsing ' + i + ' year check'); | |
3015 assert.equal(testMoment.month(), 0, | |
3016 'lenient ordinal parsing ' + i + ' month check'); | |
3017 assert.equal(testMoment.date(), i, | |
3018 'lenient ordinal parsing ' + i + ' date check'); | |
3019 } | |
3020 }); | |
3021 | |
3022 test('lenient ordinal parsing of number', function (assert) { | |
3023 var i, testMoment; | |
3024 for (i = 1; i <= 31; ++i) { | |
3025 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
3026 assert.equal(testMoment.year(), 2014, | |
3027 'lenient ordinal parsing of number ' + i + ' year check'); | |
3028 assert.equal(testMoment.month(), 0, | |
3029 'lenient ordinal parsing of number ' + i + ' month check'); | |
3030 assert.equal(testMoment.date(), i, | |
3031 'lenient ordinal parsing of number ' + i + ' date check'); | |
3032 } | |
3033 }); | |
3034 | |
3035 test('strict ordinal parsing', function (assert) { | |
3036 var i, ordinalStr, testMoment; | |
3037 for (i = 1; i <= 31; ++i) { | |
3038 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
3039 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
3040 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
3041 } | |
3042 }); | |
3043 | |
3044 })); | |
3045 | |
3046 (function (global, factory) { | |
3047 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
3048 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
3049 factory(global.moment) | |
3050 }(this, function (moment) { 'use strict'; | |
3051 | |
3052 /*global QUnit:false*/ | |
3053 | |
3054 var test = QUnit.test; | |
3055 | |
3056 function module (name, lifecycle) { | |
3057 QUnit.module(name, { | |
3058 setup : function () { | |
3059 moment.locale('en'); | |
3060 moment.createFromInputFallback = function () { | |
3061 throw new Error('input not handled by moment'); | |
3062 }; | |
3063 if (lifecycle && lifecycle.setup) { | |
3064 lifecycle.setup(); | |
3065 } | |
3066 }, | |
3067 teardown : function () { | |
3068 if (lifecycle && lifecycle.teardown) { | |
3069 lifecycle.teardown(); | |
3070 } | |
3071 } | |
3072 }); | |
3073 } | |
3074 | |
3075 function localeModule (name, lifecycle) { | |
3076 QUnit.module('locale:' + name, { | |
3077 setup : function () { | |
3078 moment.locale(name); | |
3079 moment.createFromInputFallback = function () { | |
3080 throw new Error('input not handled by moment'); | |
3081 }; | |
3082 if (lifecycle && lifecycle.setup) { | |
3083 lifecycle.setup(); | |
3084 } | |
3085 }, | |
3086 teardown : function () { | |
3087 moment.locale('en'); | |
3088 if (lifecycle && lifecycle.teardown) { | |
3089 lifecycle.teardown(); | |
3090 } | |
3091 } | |
3092 }); | |
3093 } | |
3094 | |
3095 localeModule('bn'); | |
3096 | |
3097 test('parse', function (assert) { | |
3098 var tests = 'জানুয়ারী জানু_ফেবুয়ারী ফেব_মার্চ মার্চ_এপ্রিল এপর_মে মে_জুন জুন_জুলাই জুল_অগাস্ট অগ_সেপ্টেম্বর সেপ্ট_অক্টোবর অক্টো_নভেম্বর নভ_ডিসেম্বর ডিসেম্'.split('_'), i; | |
3099 function equalTest(input, mmm, i) { | |
3100 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
3101 } | |
3102 for (i = 0; i < 12; i++) { | |
3103 tests[i] = tests[i].split(' '); | |
3104 equalTest(tests[i][0], 'MMM', i); | |
3105 equalTest(tests[i][1], 'MMM', i); | |
3106 equalTest(tests[i][0], 'MMMM', i); | |
3107 equalTest(tests[i][1], 'MMMM', i); | |
3108 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
3109 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
3110 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
3111 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
3112 } | |
3113 }); | |
3114 | |
3115 test('format', function (assert) { | |
3116 var a = [ | |
3117 ['dddd, Do MMMM YYYY, a h:mm:ss সময়', 'রবিবার, ১৪ ফেবুয়ারী ২০১০, দুপুর ৩:২৫:৫০ সময়'], | |
3118 ['ddd, a h সময়', 'রবি, দুপুর ৩ সময়'], | |
3119 ['M Mo MM MMMM MMM', '২ ২ ০২ ফেবুয়ারী ফেব'], | |
3120 ['YYYY YY', '২০১০ ১০'], | |
3121 ['D Do DD', '১৪ ১৪ ১৪'], | |
3122 ['d do dddd ddd dd', '০ ০ রবিবার রবি রব'], | |
3123 ['DDD DDDo DDDD', '৪৫ ৪৫ ০৪৫'], | |
3124 ['w wo ww', '৮ ৮ ০৮'], | |
3125 ['h hh', '৩ ০৩'], | |
3126 ['H HH', '১৫ ১৫'], | |
3127 ['m mm', '২৫ ২৫'], | |
3128 ['s ss', '৫০ ৫০'], | |
3129 ['a A', 'দুপুর দুপুর'], | |
3130 ['LT', 'দুপুর ৩:২৫ সময়'], | |
3131 ['LTS', 'দুপুর ৩:২৫:৫০ সময়'], | |
3132 ['L', '১৪/০২/২০১০'], | |
3133 ['LL', '১৪ ফেবুয়ারী ২০১০'], | |
3134 ['LLL', '১৪ ফেবুয়ারী ২০১০, দুপুর ৩:২৫ সময়'], | |
3135 ['LLLL', 'রবিবার, ১৪ ফেবুয়ারী ২০১০, দুপুর ৩:২৫ সময়'], | |
3136 ['l', '১৪/২/২০১০'], | |
3137 ['ll', '১৪ ফেব ২০১০'], | |
3138 ['lll', '১৪ ফেব ২০১০, দুপুর ৩:২৫ সময়'], | |
3139 ['llll', 'রবি, ১৪ ফেব ২০১০, দুপুর ৩:২৫ সময়'] | |
3140 ], | |
3141 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
3142 i; | |
3143 for (i = 0; i < a.length; i++) { | |
3144 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
3145 } | |
3146 }); | |
3147 | |
3148 test('format ordinal', function (assert) { | |
3149 assert.equal(moment([2011, 0, 1]).format('DDDo'), '১', '১'); | |
3150 assert.equal(moment([2011, 0, 2]).format('DDDo'), '২', '২'); | |
3151 assert.equal(moment([2011, 0, 3]).format('DDDo'), '৩', '৩'); | |
3152 assert.equal(moment([2011, 0, 4]).format('DDDo'), '৪', '৪'); | |
3153 assert.equal(moment([2011, 0, 5]).format('DDDo'), '৫', '৫'); | |
3154 assert.equal(moment([2011, 0, 6]).format('DDDo'), '৬', '৬'); | |
3155 assert.equal(moment([2011, 0, 7]).format('DDDo'), '৭', '৭'); | |
3156 assert.equal(moment([2011, 0, 8]).format('DDDo'), '৮', '৮'); | |
3157 assert.equal(moment([2011, 0, 9]).format('DDDo'), '৯', '৯'); | |
3158 assert.equal(moment([2011, 0, 10]).format('DDDo'), '১০', '১০'); | |
3159 | |
3160 assert.equal(moment([2011, 0, 11]).format('DDDo'), '১১', '১১'); | |
3161 assert.equal(moment([2011, 0, 12]).format('DDDo'), '১২', '১২'); | |
3162 assert.equal(moment([2011, 0, 13]).format('DDDo'), '১৩', '১৩'); | |
3163 assert.equal(moment([2011, 0, 14]).format('DDDo'), '১৪', '১৪'); | |
3164 assert.equal(moment([2011, 0, 15]).format('DDDo'), '১৫', '১৫'); | |
3165 assert.equal(moment([2011, 0, 16]).format('DDDo'), '১৬', '১৬'); | |
3166 assert.equal(moment([2011, 0, 17]).format('DDDo'), '১৭', '১৭'); | |
3167 assert.equal(moment([2011, 0, 18]).format('DDDo'), '১৮', '১৮'); | |
3168 assert.equal(moment([2011, 0, 19]).format('DDDo'), '১৯', '১৯'); | |
3169 assert.equal(moment([2011, 0, 20]).format('DDDo'), '২০', '২০'); | |
3170 | |
3171 assert.equal(moment([2011, 0, 21]).format('DDDo'), '২১', '২১'); | |
3172 assert.equal(moment([2011, 0, 22]).format('DDDo'), '২২', '২২'); | |
3173 assert.equal(moment([2011, 0, 23]).format('DDDo'), '২৩', '২৩'); | |
3174 assert.equal(moment([2011, 0, 24]).format('DDDo'), '২৪', '২৪'); | |
3175 assert.equal(moment([2011, 0, 25]).format('DDDo'), '২৫', '২৫'); | |
3176 assert.equal(moment([2011, 0, 26]).format('DDDo'), '২৬', '২৬'); | |
3177 assert.equal(moment([2011, 0, 27]).format('DDDo'), '২৭', '২৭'); | |
3178 assert.equal(moment([2011, 0, 28]).format('DDDo'), '২৮', '२৮'); | |
3179 assert.equal(moment([2011, 0, 29]).format('DDDo'), '২৯', '২৯'); | |
3180 assert.equal(moment([2011, 0, 30]).format('DDDo'), '৩০', '৩০'); | |
3181 | |
3182 assert.equal(moment([2011, 0, 31]).format('DDDo'), '৩১', '৩১'); | |
3183 }); | |
3184 | |
3185 test('format month', function (assert) { | |
3186 var expected = 'জানুয়ারী জানু_ফেবুয়ারী ফেব_মার্চ মার্চ_এপ্রিল এপর_মে মে_জুন জুন_জুলাই জুল_অগাস্ট অগ_সেপ্টেম্বর সেপ্ট_অক্টোবর অক্টো_নভেম্বর নভ_ডিসেম্বর ডিসেম্'.split('_'), i; | |
3187 for (i = 0; i < expected.length; i++) { | |
3188 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
3189 } | |
3190 }); | |
3191 | |
3192 test('format week', function (assert) { | |
3193 var expected = 'রবিবার রবি রব_সোমবার সোম সম_মঙ্গলবার মঙ্গল মঙ্গ_বুধবার বুধ বু_বৃহস্পত্তিবার বৃহস্পত্তি ব্রিহ_শুক্রুবার শুক্রু শু_শনিবার শনি শনি'.split('_'), i; | |
3194 for (i = 0; i < expected.length; i++) { | |
3195 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
3196 } | |
3197 }); | |
3198 | |
3199 test('from', function (assert) { | |
3200 var start = moment([2007, 1, 28]); | |
3201 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'কএক সেকেন্ড', '44 seconds = a few seconds'); | |
3202 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'এক মিনিট', '45 seconds = a minute'); | |
3203 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'এক মিনিট', '89 seconds = a minute'); | |
3204 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '২ মিনিট', '90 seconds = 2 minutes'); | |
3205 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '৪৪ মিনিট', '44 minutes = 44 minutes'); | |
3206 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'এক ঘন্টা', '45 minutes = an hour'); | |
3207 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'এক ঘন্টা', '89 minutes = an hour'); | |
3208 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '২ ঘন্টা', '90 minutes = 2 hours'); | |
3209 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '৫ ঘন্টা', '5 hours = 5 hours'); | |
3210 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '২১ ঘন্টা', '21 hours = 21 hours'); | |
3211 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'এক দিন', '22 hours = a day'); | |
3212 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'এক দিন', '35 hours = a day'); | |
3213 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '২ দিন', '36 hours = 2 days'); | |
3214 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'এক দিন', '1 day = a day'); | |
3215 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '৫ দিন', '5 days = 5 days'); | |
3216 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '২৫ দিন', '25 days = 25 days'); | |
3217 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'এক মাস', '26 days = a month'); | |
3218 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'এক মাস', '30 days = a month'); | |
3219 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '২ মাস', '46 days = 2 months'); | |
3220 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '২ মাস', '75 days = 2 months'); | |
3221 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '৩ মাস', '76 days = 3 months'); | |
3222 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'এক মাস', '1 month = a month'); | |
3223 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '৫ মাস', '5 months = 5 months'); | |
3224 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'এক বছর', '345 days = a year'); | |
3225 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '২ বছর', '548 days = 2 years'); | |
3226 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'এক বছর', '1 year = a year'); | |
3227 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '৫ বছর', '5 years = 5 years'); | |
3228 }); | |
3229 | |
3230 test('suffix', function (assert) { | |
3231 assert.equal(moment(30000).from(0), 'কএক সেকেন্ড পরে', 'prefix'); | |
3232 assert.equal(moment(0).from(30000), 'কএক সেকেন্ড আগে', 'suffix'); | |
3233 }); | |
3234 | |
3235 test('now from now', function (assert) { | |
3236 assert.equal(moment().fromNow(), 'কএক সেকেন্ড আগে', 'now from now should display as in the past'); | |
3237 }); | |
3238 | |
3239 test('fromNow', function (assert) { | |
3240 assert.equal(moment().add({s: 30}).fromNow(), 'কএক সেকেন্ড পরে', 'কএক সেকেন্ড পরে'); | |
3241 assert.equal(moment().add({d: 5}).fromNow(), '৫ দিন পরে', '৫ দিন পরে'); | |
3242 }); | |
3243 | |
3244 test('calendar day', function (assert) { | |
3245 var a = moment().hours(2).minutes(0).seconds(0); | |
3246 | |
3247 assert.equal(moment(a).calendar(), 'আজ রাত ২:০০ সময়', 'today at the same time'); | |
3248 assert.equal(moment(a).add({m: 25}).calendar(), 'আজ রাত ২:২৫ সময়', 'Now plus 25 min'); | |
3249 assert.equal(moment(a).add({h: 3}).calendar(), 'আজ সকাল ৫:০০ সময়', 'Now plus 3 hour'); | |
3250 assert.equal(moment(a).add({d: 1}).calendar(), 'আগামীকাল রাত ২:০০ সময়', 'tomorrow at the same time'); | |
3251 assert.equal(moment(a).subtract({h: 1}).calendar(), 'আজ রাত ১:০০ সময়', 'Now minus 1 hour'); | |
3252 assert.equal(moment(a).subtract({d: 1}).calendar(), 'গতকাল রাত ২:০০ সময়', 'yesterday at the same time'); | |
3253 }); | |
3254 | |
3255 test('calendar next week', function (assert) { | |
3256 var i, m; | |
3257 for (i = 2; i < 7; i++) { | |
3258 m = moment().add({d: i}); | |
3259 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days current time'); | |
3260 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
3261 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days beginning of day'); | |
3262 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
3263 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days end of day'); | |
3264 } | |
3265 }); | |
3266 | |
3267 test('calendar last week', function (assert) { | |
3268 var i, m; | |
3269 | |
3270 for (i = 2; i < 7; i++) { | |
3271 m = moment().subtract({d: i}); | |
3272 assert.equal(m.calendar(), m.format('[গত] dddd[,] LT'), 'Today - ' + i + ' days current time'); | |
3273 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
3274 assert.equal(m.calendar(), m.format('[গত] dddd[,] LT'), 'Today - ' + i + ' days beginning of day'); | |
3275 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
3276 assert.equal(m.calendar(), m.format('[গত] dddd[,] LT'), 'Today - ' + i + ' days end of day'); | |
3277 } | |
3278 }); | |
3279 | |
3280 test('calendar all else', function (assert) { | |
3281 var weeksAgo = moment().subtract({w: 1}), | |
3282 weeksFromNow = moment().add({w: 1}); | |
3283 | |
3284 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
3285 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
3286 | |
3287 weeksAgo = moment().subtract({w: 2}); | |
3288 weeksFromNow = moment().add({w: 2}); | |
3289 | |
3290 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
3291 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
3292 }); | |
3293 | |
3294 test('meridiem', function (assert) { | |
3295 assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), 'রাত', 'before dawn'); | |
3296 assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), 'সকাল', 'morning'); | |
3297 assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), 'দুপুর', 'during day'); | |
3298 assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), 'বিকেল', 'evening'); | |
3299 assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), 'বিকেল', 'late evening'); | |
3300 assert.equal(moment([2011, 2, 23, 21, 20]).format('a'), 'রাত', 'night'); | |
3301 | |
3302 assert.equal(moment([2011, 2, 23, 2, 30]).format('A'), 'রাত', 'before dawn'); | |
3303 assert.equal(moment([2011, 2, 23, 9, 30]).format('A'), 'সকাল', 'morning'); | |
3304 assert.equal(moment([2011, 2, 23, 14, 30]).format('A'), 'দুপুর', ' during day'); | |
3305 assert.equal(moment([2011, 2, 23, 17, 30]).format('A'), 'বিকেল', 'evening'); | |
3306 assert.equal(moment([2011, 2, 23, 19, 30]).format('A'), 'বিকেল', 'late evening'); | |
3307 assert.equal(moment([2011, 2, 23, 21, 20]).format('A'), 'রাত', 'night'); | |
3308 }); | |
3309 | |
3310 test('weeks year starting sunday', function (assert) { | |
3311 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
3312 assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1'); | |
3313 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
3314 assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2'); | |
3315 assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3'); | |
3316 }); | |
3317 | |
3318 test('weeks year starting monday', function (assert) { | |
3319 assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1'); | |
3320 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
3321 assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1'); | |
3322 assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2'); | |
3323 assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2'); | |
3324 assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3'); | |
3325 }); | |
3326 | |
3327 test('weeks year starting tuesday', function (assert) { | |
3328 assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52'); | |
3329 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
3330 assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1'); | |
3331 assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2'); | |
3332 assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2'); | |
3333 assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3'); | |
3334 }); | |
3335 | |
3336 test('weeks year starting wednesday', function (assert) { | |
3337 assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1'); | |
3338 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
3339 assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1'); | |
3340 assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2'); | |
3341 assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2'); | |
3342 assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3'); | |
3343 }); | |
3344 | |
3345 test('weeks year starting thursday', function (assert) { | |
3346 assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1'); | |
3347 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
3348 assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1'); | |
3349 assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2'); | |
3350 assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2'); | |
3351 assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3'); | |
3352 }); | |
3353 | |
3354 test('weeks year starting friday', function (assert) { | |
3355 assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1'); | |
3356 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
3357 assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1'); | |
3358 assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2'); | |
3359 assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2'); | |
3360 assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3'); | |
3361 }); | |
3362 | |
3363 test('weeks year starting saturday', function (assert) { | |
3364 assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1'); | |
3365 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
3366 assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2'); | |
3367 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2'); | |
3368 assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3'); | |
3369 }); | |
3370 | |
3371 test('weeks year starting sunday formatted', function (assert) { | |
3372 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '১ ০১ ১', 'Jan 1 2012 should be week 1'); | |
3373 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '১ ০১ ১', 'Jan 7 2012 should be week 1'); | |
3374 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '২ ০২ ২', 'Jan 8 2012 should be week 2'); | |
3375 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '২ ০২ ২', 'Jan 14 2012 should be week 2'); | |
3376 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '৩ ০৩ ৩', 'Jan 15 2012 should be week 3'); | |
3377 }); | |
3378 | |
3379 test('lenient ordinal parsing', function (assert) { | |
3380 var i, ordinalStr, testMoment; | |
3381 for (i = 1; i <= 31; ++i) { | |
3382 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
3383 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
3384 assert.equal(testMoment.year(), 2014, | |
3385 'lenient ordinal parsing ' + i + ' year check'); | |
3386 assert.equal(testMoment.month(), 0, | |
3387 'lenient ordinal parsing ' + i + ' month check'); | |
3388 assert.equal(testMoment.date(), i, | |
3389 'lenient ordinal parsing ' + i + ' date check'); | |
3390 } | |
3391 }); | |
3392 | |
3393 test('lenient ordinal parsing of number', function (assert) { | |
3394 var i, testMoment; | |
3395 for (i = 1; i <= 31; ++i) { | |
3396 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
3397 assert.equal(testMoment.year(), 2014, | |
3398 'lenient ordinal parsing of number ' + i + ' year check'); | |
3399 assert.equal(testMoment.month(), 0, | |
3400 'lenient ordinal parsing of number ' + i + ' month check'); | |
3401 assert.equal(testMoment.date(), i, | |
3402 'lenient ordinal parsing of number ' + i + ' date check'); | |
3403 } | |
3404 }); | |
3405 | |
3406 test('strict ordinal parsing', function (assert) { | |
3407 var i, ordinalStr, testMoment; | |
3408 for (i = 1; i <= 31; ++i) { | |
3409 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
3410 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
3411 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
3412 } | |
3413 }); | |
3414 | |
3415 })); | |
3416 | |
3417 (function (global, factory) { | |
3418 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
3419 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
3420 factory(global.moment) | |
3421 }(this, function (moment) { 'use strict'; | |
3422 | |
3423 /*global QUnit:false*/ | |
3424 | |
3425 var test = QUnit.test; | |
3426 | |
3427 function module (name, lifecycle) { | |
3428 QUnit.module(name, { | |
3429 setup : function () { | |
3430 moment.locale('en'); | |
3431 moment.createFromInputFallback = function () { | |
3432 throw new Error('input not handled by moment'); | |
3433 }; | |
3434 if (lifecycle && lifecycle.setup) { | |
3435 lifecycle.setup(); | |
3436 } | |
3437 }, | |
3438 teardown : function () { | |
3439 if (lifecycle && lifecycle.teardown) { | |
3440 lifecycle.teardown(); | |
3441 } | |
3442 } | |
3443 }); | |
3444 } | |
3445 | |
3446 function localeModule (name, lifecycle) { | |
3447 QUnit.module('locale:' + name, { | |
3448 setup : function () { | |
3449 moment.locale(name); | |
3450 moment.createFromInputFallback = function () { | |
3451 throw new Error('input not handled by moment'); | |
3452 }; | |
3453 if (lifecycle && lifecycle.setup) { | |
3454 lifecycle.setup(); | |
3455 } | |
3456 }, | |
3457 teardown : function () { | |
3458 moment.locale('en'); | |
3459 if (lifecycle && lifecycle.teardown) { | |
3460 lifecycle.teardown(); | |
3461 } | |
3462 } | |
3463 }); | |
3464 } | |
3465 | |
3466 localeModule('bo'); | |
3467 | |
3468 test('parse', function (assert) { | |
3469 var tests = 'ཟླ་བ་དང་པོ ཟླ་བ་དང་པོ._ཟླ་བ་གཉིས་པ ཟླ་བ་གཉིས་པ_ཟླ་བ་གསུམ་པ ཟླ་བ་གསུམ་པ_ཟླ་བ་བཞི་པ ཟླ་བ་བཞི་པ_ཟླ་བ་ལྔ་པ ཟླ་བ་ལྔ་པ_ཟླ་བ་དྲུག་པ ཟླ་བ་དྲུག་པ_ཟླ་བ་བདུན་པ ཟླ་བ་བདུན་པ_ཟླ་བ་བརྒྱད་པ ཟླ་བ་བརྒྱད་པ_ཟླ་བ་དགུ་པ ཟླ་བ་དགུ་པ_ཟླ་བ་བཅུ་པ ཟླ་བ་བཅུ་པ_ཟླ་བ་བཅུ་གཅིག་པ ཟླ་བ་བཅུ་གཅིག་པ_ཟླ་བ་བཅུ་གཉིས་པ ཟླ་བ་བཅུ་གཉིས་པ'.split('_'), i; | |
3470 function equalTest(input, mmm, i) { | |
3471 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
3472 } | |
3473 for (i = 0; i < 12; i++) { | |
3474 tests[i] = tests[i].split(' '); | |
3475 equalTest(tests[i][0], 'MMM', i); | |
3476 equalTest(tests[i][1], 'MMM', i); | |
3477 equalTest(tests[i][0], 'MMMM', i); | |
3478 equalTest(tests[i][1], 'MMMM', i); | |
3479 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
3480 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
3481 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
3482 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
3483 } | |
3484 }); | |
3485 | |
3486 test('format', function (assert) { | |
3487 var a = [ | |
3488 ['dddd, Do MMMM YYYY, a h:mm:ss ལ་', 'གཟའ་ཉི་མ་, ༡༤ ཟླ་བ་གཉིས་པ ༢༠༡༠, ཉིན་གུང ༣:༢༥:༥༠ ལ་'], | |
3489 ['ddd, a h ལ་', 'ཉི་མ་, ཉིན་གུང ༣ ལ་'], | |
3490 ['M Mo MM MMMM MMM', '༢ ༢ ༠༢ ཟླ་བ་གཉིས་པ ཟླ་བ་གཉིས་པ'], | |
3491 ['YYYY YY', '༢༠༡༠ ༡༠'], | |
3492 ['D Do DD', '༡༤ ༡༤ ༡༤'], | |
3493 ['d do dddd ddd dd', '༠ ༠ གཟའ་ཉི་མ་ ཉི་མ་ ཉི་མ་'], | |
3494 ['DDD DDDo DDDD', '༤༥ ༤༥ ༠༤༥'], | |
3495 ['w wo ww', '༨ ༨ ༠༨'], | |
3496 ['h hh', '༣ ༠༣'], | |
3497 ['H HH', '༡༥ ༡༥'], | |
3498 ['m mm', '༢༥ ༢༥'], | |
3499 ['s ss', '༥༠ ༥༠'], | |
3500 ['a A', 'ཉིན་གུང ཉིན་གུང'], | |
3501 ['LT', 'ཉིན་གུང ༣:༢༥'], | |
3502 ['LTS', 'ཉིན་གུང ༣:༢༥:༥༠'], | |
3503 ['L', '༡༤/༠༢/༢༠༡༠'], | |
3504 ['LL', '༡༤ ཟླ་བ་གཉིས་པ ༢༠༡༠'], | |
3505 ['LLL', '༡༤ ཟླ་བ་གཉིས་པ ༢༠༡༠, ཉིན་གུང ༣:༢༥'], | |
3506 ['LLLL', 'གཟའ་ཉི་མ་, ༡༤ ཟླ་བ་གཉིས་པ ༢༠༡༠, ཉིན་གུང ༣:༢༥'], | |
3507 ['l', '༡༤/༢/༢༠༡༠'], | |
3508 ['ll', '༡༤ ཟླ་བ་གཉིས་པ ༢༠༡༠'], | |
3509 ['lll', '༡༤ ཟླ་བ་གཉིས་པ ༢༠༡༠, ཉིན་གུང ༣:༢༥'], | |
3510 ['llll', 'ཉི་མ་, ༡༤ ཟླ་བ་གཉིས་པ ༢༠༡༠, ཉིན་གུང ༣:༢༥'] | |
3511 ], | |
3512 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
3513 i; | |
3514 for (i = 0; i < a.length; i++) { | |
3515 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
3516 } | |
3517 }); | |
3518 | |
3519 test('format ordinal', function (assert) { | |
3520 assert.equal(moment([2011, 0, 1]).format('DDDo'), '༡', '༡'); | |
3521 assert.equal(moment([2011, 0, 2]).format('DDDo'), '༢', '༢'); | |
3522 assert.equal(moment([2011, 0, 3]).format('DDDo'), '༣', '༣'); | |
3523 assert.equal(moment([2011, 0, 4]).format('DDDo'), '༤', '༤'); | |
3524 assert.equal(moment([2011, 0, 5]).format('DDDo'), '༥', '༥'); | |
3525 assert.equal(moment([2011, 0, 6]).format('DDDo'), '༦', '༦'); | |
3526 assert.equal(moment([2011, 0, 7]).format('DDDo'), '༧', '༧'); | |
3527 assert.equal(moment([2011, 0, 8]).format('DDDo'), '༨', '༨'); | |
3528 assert.equal(moment([2011, 0, 9]).format('DDDo'), '༩', '༩'); | |
3529 assert.equal(moment([2011, 0, 10]).format('DDDo'), '༡༠', '༡༠'); | |
3530 | |
3531 assert.equal(moment([2011, 0, 11]).format('DDDo'), '༡༡', '༡༡'); | |
3532 assert.equal(moment([2011, 0, 12]).format('DDDo'), '༡༢', '༡༢'); | |
3533 assert.equal(moment([2011, 0, 13]).format('DDDo'), '༡༣', '༡༣'); | |
3534 assert.equal(moment([2011, 0, 14]).format('DDDo'), '༡༤', '༡༤'); | |
3535 assert.equal(moment([2011, 0, 15]).format('DDDo'), '༡༥', '༡༥'); | |
3536 assert.equal(moment([2011, 0, 16]).format('DDDo'), '༡༦', '༡༦'); | |
3537 assert.equal(moment([2011, 0, 17]).format('DDDo'), '༡༧', '༡༧'); | |
3538 assert.equal(moment([2011, 0, 18]).format('DDDo'), '༡༨', '༡༨'); | |
3539 assert.equal(moment([2011, 0, 19]).format('DDDo'), '༡༩', '༡༩'); | |
3540 assert.equal(moment([2011, 0, 20]).format('DDDo'), '༢༠', '༢༠'); | |
3541 | |
3542 assert.equal(moment([2011, 0, 21]).format('DDDo'), '༢༡', '༢༡'); | |
3543 assert.equal(moment([2011, 0, 22]).format('DDDo'), '༢༢', '༢༢'); | |
3544 assert.equal(moment([2011, 0, 23]).format('DDDo'), '༢༣', '༢༣'); | |
3545 assert.equal(moment([2011, 0, 24]).format('DDDo'), '༢༤', '༢༤'); | |
3546 assert.equal(moment([2011, 0, 25]).format('DDDo'), '༢༥', '༢༥'); | |
3547 assert.equal(moment([2011, 0, 26]).format('DDDo'), '༢༦', '༢༦'); | |
3548 assert.equal(moment([2011, 0, 27]).format('DDDo'), '༢༧', '༢༧'); | |
3549 assert.equal(moment([2011, 0, 28]).format('DDDo'), '༢༨', '༢༨'); | |
3550 assert.equal(moment([2011, 0, 29]).format('DDDo'), '༢༩', '༢༩'); | |
3551 assert.equal(moment([2011, 0, 30]).format('DDDo'), '༣༠', '༣༠'); | |
3552 | |
3553 assert.equal(moment([2011, 0, 31]).format('DDDo'), '༣༡', '༣༡'); | |
3554 }); | |
3555 | |
3556 test('format month', function (assert) { | |
3557 var expected = 'ཟླ་བ་དང་པོ ཟླ་བ་དང་པོ_ཟླ་བ་གཉིས་པ ཟླ་བ་གཉིས་པ_ཟླ་བ་གསུམ་པ ཟླ་བ་གསུམ་པ_ཟླ་བ་བཞི་པ ཟླ་བ་བཞི་པ_ཟླ་བ་ལྔ་པ ཟླ་བ་ལྔ་པ_ཟླ་བ་དྲུག་པ ཟླ་བ་དྲུག་པ_ཟླ་བ་བདུན་པ ཟླ་བ་བདུན་པ_ཟླ་བ་བརྒྱད་པ ཟླ་བ་བརྒྱད་པ_ཟླ་བ་དགུ་པ ཟླ་བ་དགུ་པ_ཟླ་བ་བཅུ་པ ཟླ་བ་བཅུ་པ_ཟླ་བ་བཅུ་གཅིག་པ ཟླ་བ་བཅུ་གཅིག་པ_ཟླ་བ་བཅུ་གཉིས་པ ཟླ་བ་བཅུ་གཉིས་པ'.split('_'), i; | |
3558 for (i = 0; i < expected.length; i++) { | |
3559 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
3560 } | |
3561 }); | |
3562 | |
3563 test('format week', function (assert) { | |
3564 var expected = 'གཟའ་ཉི་མ་ ཉི་མ་ ཉི་མ་_གཟའ་ཟླ་བ་ ཟླ་བ་ ཟླ་བ་_གཟའ་མིག་དམར་ མིག་དམར་ མིག་དམར་_གཟའ་ལྷག་པ་ ལྷག་པ་ ལྷག་པ་_གཟའ་ཕུར་བུ ཕུར་བུ ཕུར་བུ_གཟའ་པ་སངས་ པ་སངས་ པ་སངས་_གཟའ་སྤེན་པ་ སྤེན་པ་ སྤེན་པ་'.split('_'), i; | |
3565 for (i = 0; i < expected.length; i++) { | |
3566 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
3567 } | |
3568 }); | |
3569 | |
3570 test('from', function (assert) { | |
3571 var start = moment([2007, 1, 28]); | |
3572 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ལམ་སང', '44 seconds = a few seconds'); | |
3573 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'སྐར་མ་གཅིག', '45 seconds = a minute'); | |
3574 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'སྐར་མ་གཅིག', '89 seconds = a minute'); | |
3575 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '༢ སྐར་མ', '90 seconds = 2 minutes'); | |
3576 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '༤༤ སྐར་མ', '44 minutes = 44 minutes'); | |
3577 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ཆུ་ཚོད་གཅིག', '45 minutes = an hour'); | |
3578 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ཆུ་ཚོད་གཅིག', '89 minutes = an hour'); | |
3579 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '༢ ཆུ་ཚོད', '90 minutes = 2 hours'); | |
3580 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '༥ ཆུ་ཚོད', '5 hours = 5 hours'); | |
3581 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '༢༡ ཆུ་ཚོད', '21 hours = 21 hours'); | |
3582 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ཉིན་གཅིག', '22 hours = a day'); | |
3583 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ཉིན་གཅིག', '35 hours = a day'); | |
3584 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '༢ ཉིན་', '36 hours = 2 days'); | |
3585 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ཉིན་གཅིག', '1 day = a day'); | |
3586 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '༥ ཉིན་', '5 days = 5 days'); | |
3587 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '༢༥ ཉིན་', '25 days = 25 days'); | |
3588 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ཟླ་བ་གཅིག', '26 days = a month'); | |
3589 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ཟླ་བ་གཅིག', '30 days = a month'); | |
3590 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ཟླ་བ་གཅིག', '43 days = a month'); | |
3591 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '༢ ཟླ་བ', '46 days = 2 months'); | |
3592 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '༢ ཟླ་བ', '75 days = 2 months'); | |
3593 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '༣ ཟླ་བ', '76 days = 3 months'); | |
3594 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ཟླ་བ་གཅིག', '1 month = a month'); | |
3595 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '༥ ཟླ་བ', '5 months = 5 months'); | |
3596 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ལོ་གཅིག', '345 days = a year'); | |
3597 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '༢ ལོ', '548 days = 2 years'); | |
3598 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ལོ་གཅིག', '1 year = a year'); | |
3599 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '༥ ལོ', '5 years = 5 years'); | |
3600 }); | |
3601 | |
3602 test('suffix', function (assert) { | |
3603 assert.equal(moment(30000).from(0), 'ལམ་སང ལ་', 'prefix'); | |
3604 assert.equal(moment(0).from(30000), 'ལམ་སང སྔན་ལ', 'suffix'); | |
3605 }); | |
3606 | |
3607 test('now from now', function (assert) { | |
3608 assert.equal(moment().fromNow(), 'ལམ་སང སྔན་ལ', 'now from now should display as in the past'); | |
3609 }); | |
3610 | |
3611 test('fromNow', function (assert) { | |
3612 assert.equal(moment().add({s: 30}).fromNow(), 'ལམ་སང ལ་', 'ལམ་སང ལ་'); | |
3613 assert.equal(moment().add({d: 5}).fromNow(), '༥ ཉིན་ ལ་', '༥ ཉིན་ ལ་'); | |
3614 }); | |
3615 | |
3616 test('calendar day', function (assert) { | |
3617 var a = moment().hours(2).minutes(0).seconds(0); | |
3618 | |
3619 assert.equal(moment(a).calendar(), 'དི་རིང མཚན་མོ ༢:༠༠', 'today at the same time'); | |
3620 assert.equal(moment(a).add({m: 25}).calendar(), 'དི་རིང མཚན་མོ ༢:༢༥', 'Now plus 25 min'); | |
3621 assert.equal(moment(a).add({h: 3}).calendar(), 'དི་རིང ཞོགས་ཀས ༥:༠༠', 'Now plus 3 hour'); | |
3622 assert.equal(moment(a).add({d: 1}).calendar(), 'སང་ཉིན མཚན་མོ ༢:༠༠', 'tomorrow at the same time'); | |
3623 assert.equal(moment(a).subtract({h: 1}).calendar(), 'དི་རིང མཚན་མོ ༡:༠༠', 'Now minus 1 hour'); | |
3624 assert.equal(moment(a).subtract({d: 1}).calendar(), 'ཁ་སང མཚན་མོ ༢:༠༠', 'yesterday at the same time'); | |
3625 }); | |
3626 | |
3627 test('calendar next week', function (assert) { | |
3628 var i, m; | |
3629 for (i = 2; i < 7; i++) { | |
3630 m = moment().add({d: i}); | |
3631 assert.equal(m.calendar(), m.format('[བདུན་ཕྲག་རྗེས་མ][,] LT'), 'Today + ' + i + ' days current time'); | |
3632 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
3633 assert.equal(m.calendar(), m.format('[བདུན་ཕྲག་རྗེས་མ][,] LT'), 'Today + ' + i + ' days beginning of day'); | |
3634 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
3635 assert.equal(m.calendar(), m.format('[བདུན་ཕྲག་རྗེས་མ][,] LT'), 'Today + ' + i + ' days end of day'); | |
3636 } | |
3637 }); | |
3638 | |
3639 test('calendar last week', function (assert) { | |
3640 var i, m; | |
3641 | |
3642 for (i = 2; i < 7; i++) { | |
3643 m = moment().subtract({d: i}); | |
3644 assert.equal(m.calendar(), m.format('[བདུན་ཕྲག་མཐའ་མ] dddd[,] LT'), 'Today - ' + i + ' days current time'); | |
3645 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
3646 assert.equal(m.calendar(), m.format('[བདུན་ཕྲག་མཐའ་མ] dddd[,] LT'), 'Today - ' + i + ' days beginning of day'); | |
3647 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
3648 assert.equal(m.calendar(), m.format('[བདུན་ཕྲག་མཐའ་མ] dddd[,] LT'), 'Today - ' + i + ' days end of day'); | |
3649 } | |
3650 }); | |
3651 | |
3652 test('calendar all else', function (assert) { | |
3653 var weeksAgo = moment().subtract({w: 1}), | |
3654 weeksFromNow = moment().add({w: 1}); | |
3655 | |
3656 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
3657 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
3658 | |
3659 weeksAgo = moment().subtract({w: 2}); | |
3660 weeksFromNow = moment().add({w: 2}); | |
3661 | |
3662 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
3663 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
3664 }); | |
3665 | |
3666 test('meridiem', function (assert) { | |
3667 assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), 'མཚན་མོ', 'before dawn'); | |
3668 assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), 'ཞོགས་ཀས', 'morning'); | |
3669 assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), 'ཉིན་གུང', 'during day'); | |
3670 assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), 'དགོང་དག', 'evening'); | |
3671 assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), 'དགོང་དག', 'late evening'); | |
3672 assert.equal(moment([2011, 2, 23, 21, 20]).format('a'), 'མཚན་མོ', 'night'); | |
3673 | |
3674 assert.equal(moment([2011, 2, 23, 2, 30]).format('A'), 'མཚན་མོ', 'before dawn'); | |
3675 assert.equal(moment([2011, 2, 23, 9, 30]).format('A'), 'ཞོགས་ཀས', 'morning'); | |
3676 assert.equal(moment([2011, 2, 23, 14, 30]).format('A'), 'ཉིན་གུང', ' during day'); | |
3677 assert.equal(moment([2011, 2, 23, 17, 30]).format('A'), 'དགོང་དག', 'evening'); | |
3678 assert.equal(moment([2011, 2, 23, 19, 30]).format('A'), 'དགོང་དག', 'late evening'); | |
3679 assert.equal(moment([2011, 2, 23, 21, 20]).format('A'), 'མཚན་མོ', 'night'); | |
3680 }); | |
3681 | |
3682 test('weeks year starting sunday', function (assert) { | |
3683 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
3684 assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1'); | |
3685 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
3686 assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2'); | |
3687 assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3'); | |
3688 }); | |
3689 | |
3690 test('weeks year starting monday', function (assert) { | |
3691 assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1'); | |
3692 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
3693 assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1'); | |
3694 assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2'); | |
3695 assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2'); | |
3696 assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3'); | |
3697 }); | |
3698 | |
3699 test('weeks year starting tuesday', function (assert) { | |
3700 assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52'); | |
3701 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
3702 assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1'); | |
3703 assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2'); | |
3704 assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2'); | |
3705 assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3'); | |
3706 }); | |
3707 | |
3708 test('weeks year starting wednesday', function (assert) { | |
3709 assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1'); | |
3710 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
3711 assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1'); | |
3712 assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2'); | |
3713 assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2'); | |
3714 assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3'); | |
3715 }); | |
3716 | |
3717 test('weeks year starting thursday', function (assert) { | |
3718 assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1'); | |
3719 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
3720 assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1'); | |
3721 assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2'); | |
3722 assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2'); | |
3723 assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3'); | |
3724 }); | |
3725 | |
3726 test('weeks year starting friday', function (assert) { | |
3727 assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1'); | |
3728 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
3729 assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1'); | |
3730 assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2'); | |
3731 assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2'); | |
3732 assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3'); | |
3733 }); | |
3734 | |
3735 test('weeks year starting saturday', function (assert) { | |
3736 assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1'); | |
3737 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
3738 assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2'); | |
3739 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2'); | |
3740 assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3'); | |
3741 }); | |
3742 | |
3743 test('weeks year starting sunday formatted', function (assert) { | |
3744 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '༡ ༠༡ ༡', 'Jan 1 2012 should be week 1'); | |
3745 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '༡ ༠༡ ༡', 'Jan 7 2012 should be week 1'); | |
3746 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '༢ ༠༢ ༢', 'Jan 8 2012 should be week 2'); | |
3747 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '༢ ༠༢ ༢', 'Jan 14 2012 should be week 2'); | |
3748 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '༣ ༠༣ ༣', 'Jan 15 2012 should be week 3'); | |
3749 }); | |
3750 | |
3751 test('lenient ordinal parsing', function (assert) { | |
3752 var i, ordinalStr, testMoment; | |
3753 for (i = 1; i <= 31; ++i) { | |
3754 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
3755 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
3756 assert.equal(testMoment.year(), 2014, | |
3757 'lenient ordinal parsing ' + i + ' year check'); | |
3758 assert.equal(testMoment.month(), 0, | |
3759 'lenient ordinal parsing ' + i + ' month check'); | |
3760 assert.equal(testMoment.date(), i, | |
3761 'lenient ordinal parsing ' + i + ' date check'); | |
3762 } | |
3763 }); | |
3764 | |
3765 test('lenient ordinal parsing of number', function (assert) { | |
3766 var i, testMoment; | |
3767 for (i = 1; i <= 31; ++i) { | |
3768 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
3769 assert.equal(testMoment.year(), 2014, | |
3770 'lenient ordinal parsing of number ' + i + ' year check'); | |
3771 assert.equal(testMoment.month(), 0, | |
3772 'lenient ordinal parsing of number ' + i + ' month check'); | |
3773 assert.equal(testMoment.date(), i, | |
3774 'lenient ordinal parsing of number ' + i + ' date check'); | |
3775 } | |
3776 }); | |
3777 | |
3778 test('strict ordinal parsing', function (assert) { | |
3779 var i, ordinalStr, testMoment; | |
3780 for (i = 1; i <= 31; ++i) { | |
3781 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
3782 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
3783 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
3784 } | |
3785 }); | |
3786 | |
3787 })); | |
3788 | |
3789 (function (global, factory) { | |
3790 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
3791 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
3792 factory(global.moment) | |
3793 }(this, function (moment) { 'use strict'; | |
3794 | |
3795 /*global QUnit:false*/ | |
3796 | |
3797 var test = QUnit.test; | |
3798 | |
3799 function module (name, lifecycle) { | |
3800 QUnit.module(name, { | |
3801 setup : function () { | |
3802 moment.locale('en'); | |
3803 moment.createFromInputFallback = function () { | |
3804 throw new Error('input not handled by moment'); | |
3805 }; | |
3806 if (lifecycle && lifecycle.setup) { | |
3807 lifecycle.setup(); | |
3808 } | |
3809 }, | |
3810 teardown : function () { | |
3811 if (lifecycle && lifecycle.teardown) { | |
3812 lifecycle.teardown(); | |
3813 } | |
3814 } | |
3815 }); | |
3816 } | |
3817 | |
3818 function localeModule (name, lifecycle) { | |
3819 QUnit.module('locale:' + name, { | |
3820 setup : function () { | |
3821 moment.locale(name); | |
3822 moment.createFromInputFallback = function () { | |
3823 throw new Error('input not handled by moment'); | |
3824 }; | |
3825 if (lifecycle && lifecycle.setup) { | |
3826 lifecycle.setup(); | |
3827 } | |
3828 }, | |
3829 teardown : function () { | |
3830 moment.locale('en'); | |
3831 if (lifecycle && lifecycle.teardown) { | |
3832 lifecycle.teardown(); | |
3833 } | |
3834 } | |
3835 }); | |
3836 } | |
3837 | |
3838 localeModule('br'); | |
3839 | |
3840 test('parse', function (assert) { | |
3841 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; | |
3842 function equalTest(input, mmm, i) { | |
3843 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
3844 } | |
3845 for (i = 0; i < 12; i++) { | |
3846 tests[i] = tests[i].split(' '); | |
3847 equalTest(tests[i][0], 'MMM', i); | |
3848 equalTest(tests[i][1], 'MMM', i); | |
3849 equalTest(tests[i][0], 'MMMM', i); | |
3850 equalTest(tests[i][1], 'MMMM', i); | |
3851 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
3852 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
3853 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
3854 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
3855 } | |
3856 }); | |
3857 | |
3858 test('format', function (assert) { | |
3859 moment.locale('br'); | |
3860 var a = [ | |
3861 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Sul, C\'hwevrer 14vet 2010, 3:25:50 pm'], | |
3862 ['ddd, h A', 'Sul, 3 PM'], | |
3863 ['M Mo MM MMMM MMM', '2 2vet 02 C\'hwevrer C\'hwe'], | |
3864 ['YYYY YY', '2010 10'], | |
3865 ['D Do DD', '14 14vet 14'], | |
3866 ['d do dddd ddd dd', '0 0vet Sul Sul Su'], | |
3867 ['DDD DDDo DDDD', '45 45vet 045'], | |
3868 ['w wo ww', '6 6vet 06'], | |
3869 ['h hh', '3 03'], | |
3870 ['H HH', '15 15'], | |
3871 ['m mm', '25 25'], | |
3872 ['s ss', '50 50'], | |
3873 ['DDDo [devezh] [ar] [vloaz]', '45vet devezh ar vloaz'], | |
3874 ['L', '14/02/2010'], | |
3875 ['LL', '14 a viz C\'hwevrer 2010'], | |
3876 ['LLL', '14 a viz C\'hwevrer 2010 3e25 PM'], | |
3877 ['LLLL', 'Sul, 14 a viz C\'hwevrer 2010 3e25 PM'] | |
3878 ], | |
3879 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
3880 i; | |
3881 for (i = 0; i < a.length; i++) { | |
3882 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
3883 } | |
3884 }); | |
3885 | |
3886 test('format ordinal', function (assert) { | |
3887 moment.locale('br'); | |
3888 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1añ', '1añ'); | |
3889 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2vet', '2vet'); | |
3890 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3vet', '3vet'); | |
3891 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4vet', '4vet'); | |
3892 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5vet', '5vet'); | |
3893 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6vet', '6vet'); | |
3894 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7vet', '7vet'); | |
3895 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8vet', '8vet'); | |
3896 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9vet', '9vet'); | |
3897 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10vet', '10vet'); | |
3898 | |
3899 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11vet', '11vet'); | |
3900 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12vet', '12vet'); | |
3901 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13vet', '13vet'); | |
3902 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14vet', '14vet'); | |
3903 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15vet', '15vet'); | |
3904 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16vet', '16vet'); | |
3905 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17vet', '17vet'); | |
3906 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18vet', '18vet'); | |
3907 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19vet', '19vet'); | |
3908 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20vet', '20vet'); | |
3909 | |
3910 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21vet', '21vet'); | |
3911 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22vet', '22vet'); | |
3912 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23vet', '23vet'); | |
3913 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24vet', '24vet'); | |
3914 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25vet', '25vet'); | |
3915 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26vet', '26vet'); | |
3916 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27vet', '27vet'); | |
3917 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28vet', '28vet'); | |
3918 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29vet', '29vet'); | |
3919 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30vet', '30vet'); | |
3920 | |
3921 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31vet', '31vet'); | |
3922 }); | |
3923 | |
3924 test('format month', function (assert) { | |
3925 moment.locale('br'); | |
3926 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; | |
3927 for (i = 0; i < expected.length; i++) { | |
3928 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
3929 } | |
3930 }); | |
3931 | |
3932 test('format week', function (assert) { | |
3933 moment.locale('br'); | |
3934 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; | |
3935 for (i = 0; i < expected.length; i++) { | |
3936 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
3937 } | |
3938 }); | |
3939 | |
3940 test('from', function (assert) { | |
3941 moment.locale('br'); | |
3942 var start = moment([2007, 1, 28]); | |
3943 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'un nebeud segondennoù', '44 seconds = a few seconds'); | |
3944 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ur vunutenn', '45 seconds = a minute'); | |
3945 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ur vunutenn', '89 seconds = a minute'); | |
3946 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 vunutenn', '90 seconds = 2 minutes'); | |
3947 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 munutenn', '44 minutes = 44 minutes'); | |
3948 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'un eur', '45 minutes = an hour'); | |
3949 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'un eur', '89 minutes = an hour'); | |
3950 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 eur', '90 minutes = 2 hours'); | |
3951 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 eur', '5 hours = 5 hours'); | |
3952 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 eur', '21 hours = 21 hours'); | |
3953 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un devezh', '22 hours = a day'); | |
3954 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un devezh', '35 hours = a day'); | |
3955 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 zevezh', '36 hours = 2 days'); | |
3956 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un devezh', '1 day = a day'); | |
3957 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 devezh', '5 days = 5 days'); | |
3958 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 devezh', '25 days = 25 days'); | |
3959 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ur miz', '26 days = a month'); | |
3960 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ur miz', '30 days = a month'); | |
3961 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ur miz', '43 days = a month'); | |
3962 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 viz', '46 days = 2 months'); | |
3963 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 viz', '75 days = 2 months'); | |
3964 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 miz', '76 days = 3 months'); | |
3965 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ur miz', '1 month = a month'); | |
3966 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 miz', '5 months = 5 months'); | |
3967 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ur bloaz', '345 days = a year'); | |
3968 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 vloaz', '548 days = 2 years'); | |
3969 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ur bloaz', '1 year = a year'); | |
3970 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 bloaz', '5 years = 5 years'); | |
3971 }); | |
3972 | |
3973 test('suffix', function (assert) { | |
3974 moment.locale('br'); | |
3975 assert.equal(moment(30000).from(0), 'a-benn un nebeud segondennoù', 'prefix'); | |
3976 assert.equal(moment(0).from(30000), 'un nebeud segondennoù \'zo', 'suffix'); | |
3977 }); | |
3978 | |
3979 test('now from now', function (assert) { | |
3980 moment.locale('br'); | |
3981 assert.equal(moment().fromNow(), 'un nebeud segondennoù \'zo', 'now from now should display as in the past'); | |
3982 }); | |
3983 | |
3984 test('fromNow', function (assert) { | |
3985 moment.locale('br'); | |
3986 assert.equal(moment().add({s: 30}).fromNow(), 'a-benn un nebeud segondennoù', 'in a few seconds'); | |
3987 assert.equal(moment().add({d: 5}).fromNow(), 'a-benn 5 devezh', 'in 5 days'); | |
3988 }); | |
3989 | |
3990 test('calendar day', function (assert) { | |
3991 moment.locale('br'); | |
3992 | |
3993 var a = moment().hours(2).minutes(0).seconds(0); | |
3994 | |
3995 assert.equal(moment(a).calendar(), 'Hiziv da 2e00 AM', 'today at the same time'); | |
3996 assert.equal(moment(a).add({m: 25}).calendar(), 'Hiziv da 2e25 AM', 'Now plus 25 min'); | |
3997 assert.equal(moment(a).add({h: 1}).calendar(), 'Hiziv da 3e00 AM', 'Now plus 1 hour'); | |
3998 assert.equal(moment(a).add({d: 1}).calendar(), 'Warc\'hoazh da 2e00 AM', 'tomorrow at the same time'); | |
3999 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Hiziv da 1e00 AM', 'Now minus 1 hour'); | |
4000 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Dec\'h da 2e00 AM', 'yesterday at the same time'); | |
4001 }); | |
4002 | |
4003 test('calendar next week', function (assert) { | |
4004 moment.locale('br'); | |
4005 | |
4006 var i, m; | |
4007 for (i = 2; i < 7; i++) { | |
4008 m = moment().add({d: i}); | |
4009 assert.equal(m.calendar(), m.format('dddd [da] LT'), 'Today + ' + i + ' days current time'); | |
4010 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
4011 assert.equal(m.calendar(), m.format('dddd [da] LT'), 'Today + ' + i + ' days beginning of day'); | |
4012 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
4013 assert.equal(m.calendar(), m.format('dddd [da] LT'), 'Today + ' + i + ' days end of day'); | |
4014 } | |
4015 }); | |
4016 | |
4017 test('calendar last week', function (assert) { | |
4018 moment.locale('br'); | |
4019 | |
4020 var i, m; | |
4021 for (i = 2; i < 7; i++) { | |
4022 m = moment().subtract({d: i}); | |
4023 assert.equal(m.calendar(), m.format('dddd [paset da] LT'), 'Today - ' + i + ' days current time'); | |
4024 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
4025 assert.equal(m.calendar(), m.format('dddd [paset da] LT'), 'Today - ' + i + ' days beginning of day'); | |
4026 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
4027 assert.equal(m.calendar(), m.format('dddd [paset da] LT'), 'Today - ' + i + ' days end of day'); | |
4028 } | |
4029 }); | |
4030 | |
4031 test('calendar all else', function (assert) { | |
4032 moment.locale('br'); | |
4033 var weeksAgo = moment().subtract({w: 1}), | |
4034 weeksFromNow = moment().add({w: 1}); | |
4035 | |
4036 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
4037 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
4038 | |
4039 weeksAgo = moment().subtract({w: 2}); | |
4040 weeksFromNow = moment().add({w: 2}); | |
4041 | |
4042 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
4043 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
4044 }); | |
4045 | |
4046 test('special mutations for years', function (assert) { | |
4047 moment.locale('br'); | |
4048 var start = moment([2007, 1, 28]); | |
4049 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ur bloaz', 'mutation 1 year'); | |
4050 assert.equal(start.from(moment([2007, 1, 28]).add({y: 2}), true), '2 vloaz', 'mutation 2 years'); | |
4051 assert.equal(start.from(moment([2007, 1, 28]).add({y: 3}), true), '3 bloaz', 'mutation 3 years'); | |
4052 assert.equal(start.from(moment([2007, 1, 28]).add({y: 4}), true), '4 bloaz', 'mutation 4 years'); | |
4053 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 bloaz', 'mutation 5 years'); | |
4054 assert.equal(start.from(moment([2007, 1, 28]).add({y: 9}), true), '9 bloaz', 'mutation 9 years'); | |
4055 assert.equal(start.from(moment([2007, 1, 28]).add({y: 10}), true), '10 vloaz', 'mutation 10 years'); | |
4056 assert.equal(start.from(moment([2007, 1, 28]).add({y: 21}), true), '21 bloaz', 'mutation 21 years'); | |
4057 assert.equal(start.from(moment([2007, 1, 28]).add({y: 22}), true), '22 vloaz', 'mutation 22 years'); | |
4058 assert.equal(start.from(moment([2007, 1, 28]).add({y: 133}), true), '133 bloaz', 'mutation 133 years'); | |
4059 assert.equal(start.from(moment([2007, 1, 28]).add({y: 148}), true), '148 vloaz', 'mutation 148 years'); | |
4060 assert.equal(start.from(moment([2007, 1, 28]).add({y: 261}), true), '261 bloaz', 'mutation 261 years'); | |
4061 }); | |
4062 | |
4063 test('lenient ordinal parsing', function (assert) { | |
4064 var i, ordinalStr, testMoment; | |
4065 for (i = 1; i <= 31; ++i) { | |
4066 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
4067 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
4068 assert.equal(testMoment.year(), 2014, | |
4069 'lenient ordinal parsing ' + i + ' year check'); | |
4070 assert.equal(testMoment.month(), 0, | |
4071 'lenient ordinal parsing ' + i + ' month check'); | |
4072 assert.equal(testMoment.date(), i, | |
4073 'lenient ordinal parsing ' + i + ' date check'); | |
4074 } | |
4075 }); | |
4076 | |
4077 test('lenient ordinal parsing of number', function (assert) { | |
4078 var i, testMoment; | |
4079 for (i = 1; i <= 31; ++i) { | |
4080 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
4081 assert.equal(testMoment.year(), 2014, | |
4082 'lenient ordinal parsing of number ' + i + ' year check'); | |
4083 assert.equal(testMoment.month(), 0, | |
4084 'lenient ordinal parsing of number ' + i + ' month check'); | |
4085 assert.equal(testMoment.date(), i, | |
4086 'lenient ordinal parsing of number ' + i + ' date check'); | |
4087 } | |
4088 }); | |
4089 | |
4090 test('strict ordinal parsing', function (assert) { | |
4091 var i, ordinalStr, testMoment; | |
4092 for (i = 1; i <= 31; ++i) { | |
4093 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
4094 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
4095 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
4096 } | |
4097 }); | |
4098 | |
4099 })); | |
4100 | |
4101 (function (global, factory) { | |
4102 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
4103 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
4104 factory(global.moment) | |
4105 }(this, function (moment) { 'use strict'; | |
4106 | |
4107 /*global QUnit:false*/ | |
4108 | |
4109 var test = QUnit.test; | |
4110 | |
4111 function module (name, lifecycle) { | |
4112 QUnit.module(name, { | |
4113 setup : function () { | |
4114 moment.locale('en'); | |
4115 moment.createFromInputFallback = function () { | |
4116 throw new Error('input not handled by moment'); | |
4117 }; | |
4118 if (lifecycle && lifecycle.setup) { | |
4119 lifecycle.setup(); | |
4120 } | |
4121 }, | |
4122 teardown : function () { | |
4123 if (lifecycle && lifecycle.teardown) { | |
4124 lifecycle.teardown(); | |
4125 } | |
4126 } | |
4127 }); | |
4128 } | |
4129 | |
4130 function localeModule (name, lifecycle) { | |
4131 QUnit.module('locale:' + name, { | |
4132 setup : function () { | |
4133 moment.locale(name); | |
4134 moment.createFromInputFallback = function () { | |
4135 throw new Error('input not handled by moment'); | |
4136 }; | |
4137 if (lifecycle && lifecycle.setup) { | |
4138 lifecycle.setup(); | |
4139 } | |
4140 }, | |
4141 teardown : function () { | |
4142 moment.locale('en'); | |
4143 if (lifecycle && lifecycle.teardown) { | |
4144 lifecycle.teardown(); | |
4145 } | |
4146 } | |
4147 }); | |
4148 } | |
4149 | |
4150 localeModule('bs'); | |
4151 | |
4152 test('parse', function (assert) { | |
4153 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; | |
4154 function equalTest(input, mmm, i) { | |
4155 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
4156 } | |
4157 for (i = 0; i < 12; i++) { | |
4158 tests[i] = tests[i].split(' '); | |
4159 equalTest(tests[i][0], 'MMM', i); | |
4160 equalTest(tests[i][1], 'MMM', i); | |
4161 equalTest(tests[i][0], 'MMMM', i); | |
4162 equalTest(tests[i][1], 'MMMM', i); | |
4163 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
4164 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
4165 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
4166 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
4167 } | |
4168 }); | |
4169 | |
4170 test('format', function (assert) { | |
4171 var a = [ | |
4172 ['dddd, Do MMMM YYYY, h:mm:ss a', 'nedjelja, 14. februar 2010, 3:25:50 pm'], | |
4173 ['ddd, hA', 'ned., 3PM'], | |
4174 ['M Mo MM MMMM MMM', '2 2. 02 februar feb.'], | |
4175 ['YYYY YY', '2010 10'], | |
4176 ['D Do DD', '14 14. 14'], | |
4177 ['d do dddd ddd dd', '0 0. nedjelja ned. ne'], | |
4178 ['DDD DDDo DDDD', '45 45. 045'], | |
4179 ['w wo ww', '7 7. 07'], | |
4180 ['h hh', '3 03'], | |
4181 ['H HH', '15 15'], | |
4182 ['m mm', '25 25'], | |
4183 ['s ss', '50 50'], | |
4184 ['a A', 'pm PM'], | |
4185 ['[the] DDDo [day of the year]', 'the 45. day of the year'], | |
4186 ['LTS', '15:25:50'], | |
4187 ['L', '14. 02. 2010'], | |
4188 ['LL', '14. februar 2010'], | |
4189 ['LLL', '14. februar 2010 15:25'], | |
4190 ['LLLL', 'nedjelja, 14. februar 2010 15:25'], | |
4191 ['l', '14. 2. 2010'], | |
4192 ['ll', '14. feb. 2010'], | |
4193 ['lll', '14. feb. 2010 15:25'], | |
4194 ['llll', 'ned., 14. feb. 2010 15:25'] | |
4195 ], | |
4196 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
4197 i; | |
4198 for (i = 0; i < a.length; i++) { | |
4199 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
4200 } | |
4201 }); | |
4202 | |
4203 test('format ordinal', function (assert) { | |
4204 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.'); | |
4205 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.'); | |
4206 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.'); | |
4207 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.'); | |
4208 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.'); | |
4209 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.'); | |
4210 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.'); | |
4211 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.'); | |
4212 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.'); | |
4213 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.'); | |
4214 | |
4215 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.'); | |
4216 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.'); | |
4217 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.'); | |
4218 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.'); | |
4219 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.'); | |
4220 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.'); | |
4221 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.'); | |
4222 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.'); | |
4223 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.'); | |
4224 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.'); | |
4225 | |
4226 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.'); | |
4227 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.'); | |
4228 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.'); | |
4229 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.'); | |
4230 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.'); | |
4231 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.'); | |
4232 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.'); | |
4233 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.'); | |
4234 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.'); | |
4235 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.'); | |
4236 | |
4237 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.'); | |
4238 }); | |
4239 | |
4240 test('format month', function (assert) { | |
4241 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; | |
4242 for (i = 0; i < expected.length; i++) { | |
4243 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
4244 } | |
4245 }); | |
4246 | |
4247 test('format week', function (assert) { | |
4248 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; | |
4249 for (i = 0; i < expected.length; i++) { | |
4250 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
4251 } | |
4252 }); | |
4253 | |
4254 test('from', function (assert) { | |
4255 var start = moment([2007, 1, 28]); | |
4256 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'par sekundi', '44 seconds = a few seconds'); | |
4257 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'jedna minuta', '45 seconds = a minute'); | |
4258 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'jedna minuta', '89 seconds = a minute'); | |
4259 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minute', '90 seconds = 2 minutes'); | |
4260 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuta', '44 minutes = 44 minutes'); | |
4261 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'jedan sat', '45 minutes = an hour'); | |
4262 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'jedan sat', '89 minutes = an hour'); | |
4263 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 sata', '90 minutes = 2 hours'); | |
4264 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 sati', '5 hours = 5 hours'); | |
4265 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 sati', '21 hours = 21 hours'); | |
4266 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'dan', '22 hours = a day'); | |
4267 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'dan', '35 hours = a day'); | |
4268 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dana', '36 hours = 2 days'); | |
4269 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'dan', '1 day = a day'); | |
4270 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dana', '5 days = 5 days'); | |
4271 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dana', '25 days = 25 days'); | |
4272 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mjesec', '26 days = a month'); | |
4273 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mjesec', '30 days = a month'); | |
4274 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mjesec', '43 days = a month'); | |
4275 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mjeseca', '46 days = 2 months'); | |
4276 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mjeseca', '75 days = 2 months'); | |
4277 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mjeseca', '76 days = 3 months'); | |
4278 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mjesec', '1 month = a month'); | |
4279 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mjeseci', '5 months = 5 months'); | |
4280 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'godinu', '345 days = a year'); | |
4281 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 godine', '548 days = 2 years'); | |
4282 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'godinu', '1 year = a year'); | |
4283 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 godina', '5 years = 5 years'); | |
4284 }); | |
4285 | |
4286 test('suffix', function (assert) { | |
4287 assert.equal(moment(30000).from(0), 'za par sekundi', 'prefix'); | |
4288 assert.equal(moment(0).from(30000), 'prije par sekundi', 'prefix'); | |
4289 }); | |
4290 | |
4291 test('now from now', function (assert) { | |
4292 assert.equal(moment().fromNow(), 'prije par sekundi', 'now from now should display as in the past'); | |
4293 }); | |
4294 | |
4295 test('fromNow', function (assert) { | |
4296 assert.equal(moment().add({s: 30}).fromNow(), 'za par sekundi', 'in a few seconds'); | |
4297 assert.equal(moment().add({d: 5}).fromNow(), 'za 5 dana', 'in 5 days'); | |
4298 }); | |
4299 | |
4300 test('calendar day', function (assert) { | |
4301 var a = moment().hours(2).minutes(0).seconds(0); | |
4302 | |
4303 assert.equal(moment(a).calendar(), 'danas u 2:00', 'today at the same time'); | |
4304 assert.equal(moment(a).add({m: 25}).calendar(), 'danas u 2:25', 'Now plus 25 min'); | |
4305 assert.equal(moment(a).add({h: 1}).calendar(), 'danas u 3:00', 'Now plus 1 hour'); | |
4306 assert.equal(moment(a).add({d: 1}).calendar(), 'sutra u 2:00', 'tomorrow at the same time'); | |
4307 assert.equal(moment(a).subtract({h: 1}).calendar(), 'danas u 1:00', 'Now minus 1 hour'); | |
4308 assert.equal(moment(a).subtract({d: 1}).calendar(), 'jučer u 2:00', 'yesterday at the same time'); | |
4309 }); | |
4310 | |
4311 test('calendar next week', function (assert) { | |
4312 var i, m; | |
4313 | |
4314 function makeFormat(d) { | |
4315 switch (d.day()) { | |
4316 case 0: | |
4317 return '[u] [nedjelju] [u] LT'; | |
4318 case 3: | |
4319 return '[u] [srijedu] [u] LT'; | |
4320 case 6: | |
4321 return '[u] [subotu] [u] LT'; | |
4322 case 1: | |
4323 case 2: | |
4324 case 4: | |
4325 case 5: | |
4326 return '[u] dddd [u] LT'; | |
4327 } | |
4328 } | |
4329 | |
4330 for (i = 2; i < 7; i++) { | |
4331 m = moment().add({d: i}); | |
4332 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time'); | |
4333 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
4334 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day'); | |
4335 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
4336 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day'); | |
4337 } | |
4338 }); | |
4339 | |
4340 test('calendar last week', function (assert) { | |
4341 var i, m; | |
4342 | |
4343 function makeFormat(d) { | |
4344 switch (d.day()) { | |
4345 case 0: | |
4346 case 3: | |
4347 return '[prošlu] dddd [u] LT'; | |
4348 case 6: | |
4349 return '[prošle] [subote] [u] LT'; | |
4350 case 1: | |
4351 case 2: | |
4352 case 4: | |
4353 case 5: | |
4354 return '[prošli] dddd [u] LT'; | |
4355 } | |
4356 } | |
4357 | |
4358 for (i = 2; i < 7; i++) { | |
4359 m = moment().subtract({d: i}); | |
4360 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time'); | |
4361 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
4362 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day'); | |
4363 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
4364 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day'); | |
4365 } | |
4366 }); | |
4367 | |
4368 test('calendar all else', function (assert) { | |
4369 var weeksAgo = moment().subtract({w: 1}), | |
4370 weeksFromNow = moment().add({w: 1}); | |
4371 | |
4372 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
4373 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
4374 | |
4375 weeksAgo = moment().subtract({w: 2}); | |
4376 weeksFromNow = moment().add({w: 2}); | |
4377 | |
4378 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
4379 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
4380 }); | |
4381 | |
4382 test('weeks year starting sunday', function (assert) { | |
4383 assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1'); | |
4384 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
4385 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2'); | |
4386 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
4387 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3'); | |
4388 }); | |
4389 | |
4390 test('weeks year starting monday', function (assert) { | |
4391 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
4392 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
4393 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
4394 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
4395 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
4396 }); | |
4397 | |
4398 test('weeks year starting tuesday', function (assert) { | |
4399 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
4400 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
4401 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
4402 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
4403 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
4404 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
4405 }); | |
4406 | |
4407 test('weeks year starting wednesday', function (assert) { | |
4408 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
4409 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
4410 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
4411 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
4412 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
4413 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
4414 }); | |
4415 | |
4416 test('weeks year starting thursday', function (assert) { | |
4417 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
4418 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
4419 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
4420 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
4421 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
4422 assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3'); | |
4423 }); | |
4424 | |
4425 test('weeks year starting friday', function (assert) { | |
4426 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1'); | |
4427 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
4428 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1'); | |
4429 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2'); | |
4430 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2'); | |
4431 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3'); | |
4432 }); | |
4433 | |
4434 test('weeks year starting saturday', function (assert) { | |
4435 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1'); | |
4436 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
4437 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1'); | |
4438 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2'); | |
4439 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2'); | |
4440 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3'); | |
4441 }); | |
4442 | |
4443 test('weeks year starting sunday formatted', function (assert) { | |
4444 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', 'Dec 26 2011 should be week 1'); | |
4445 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1.', 'Jan 1 2012 should be week 1'); | |
4446 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2.', 'Jan 2 2012 should be week 2'); | |
4447 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2.', 'Jan 8 2012 should be week 2'); | |
4448 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3.', 'Jan 9 2012 should be week 3'); | |
4449 }); | |
4450 | |
4451 test('lenient ordinal parsing', function (assert) { | |
4452 var i, ordinalStr, testMoment; | |
4453 for (i = 1; i <= 31; ++i) { | |
4454 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
4455 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
4456 assert.equal(testMoment.year(), 2014, | |
4457 'lenient ordinal parsing ' + i + ' year check'); | |
4458 assert.equal(testMoment.month(), 0, | |
4459 'lenient ordinal parsing ' + i + ' month check'); | |
4460 assert.equal(testMoment.date(), i, | |
4461 'lenient ordinal parsing ' + i + ' date check'); | |
4462 } | |
4463 }); | |
4464 | |
4465 test('lenient ordinal parsing of number', function (assert) { | |
4466 var i, testMoment; | |
4467 for (i = 1; i <= 31; ++i) { | |
4468 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
4469 assert.equal(testMoment.year(), 2014, | |
4470 'lenient ordinal parsing of number ' + i + ' year check'); | |
4471 assert.equal(testMoment.month(), 0, | |
4472 'lenient ordinal parsing of number ' + i + ' month check'); | |
4473 assert.equal(testMoment.date(), i, | |
4474 'lenient ordinal parsing of number ' + i + ' date check'); | |
4475 } | |
4476 }); | |
4477 | |
4478 test('strict ordinal parsing', function (assert) { | |
4479 var i, ordinalStr, testMoment; | |
4480 for (i = 1; i <= 31; ++i) { | |
4481 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
4482 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
4483 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
4484 } | |
4485 }); | |
4486 | |
4487 })); | |
4488 | |
4489 (function (global, factory) { | |
4490 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
4491 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
4492 factory(global.moment) | |
4493 }(this, function (moment) { 'use strict'; | |
4494 | |
4495 /*global QUnit:false*/ | |
4496 | |
4497 var test = QUnit.test; | |
4498 | |
4499 function module (name, lifecycle) { | |
4500 QUnit.module(name, { | |
4501 setup : function () { | |
4502 moment.locale('en'); | |
4503 moment.createFromInputFallback = function () { | |
4504 throw new Error('input not handled by moment'); | |
4505 }; | |
4506 if (lifecycle && lifecycle.setup) { | |
4507 lifecycle.setup(); | |
4508 } | |
4509 }, | |
4510 teardown : function () { | |
4511 if (lifecycle && lifecycle.teardown) { | |
4512 lifecycle.teardown(); | |
4513 } | |
4514 } | |
4515 }); | |
4516 } | |
4517 | |
4518 function localeModule (name, lifecycle) { | |
4519 QUnit.module('locale:' + name, { | |
4520 setup : function () { | |
4521 moment.locale(name); | |
4522 moment.createFromInputFallback = function () { | |
4523 throw new Error('input not handled by moment'); | |
4524 }; | |
4525 if (lifecycle && lifecycle.setup) { | |
4526 lifecycle.setup(); | |
4527 } | |
4528 }, | |
4529 teardown : function () { | |
4530 moment.locale('en'); | |
4531 if (lifecycle && lifecycle.teardown) { | |
4532 lifecycle.teardown(); | |
4533 } | |
4534 } | |
4535 }); | |
4536 } | |
4537 | |
4538 localeModule('ca'); | |
4539 | |
4540 test('parse', function (assert) { | |
4541 var tests = 'gener gen._febrer febr._març mar._abril abr._maig mai._juny jun._juliol jul._agost ag._setembre set._octubre oct._novembre nov._desembre des.'.split('_'), i; | |
4542 function equalTest(input, mmm, i) { | |
4543 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
4544 } | |
4545 for (i = 0; i < 12; i++) { | |
4546 tests[i] = tests[i].split(' '); | |
4547 equalTest(tests[i][0], 'MMM', i); | |
4548 equalTest(tests[i][1], 'MMM', i); | |
4549 equalTest(tests[i][0], 'MMMM', i); | |
4550 equalTest(tests[i][1], 'MMMM', i); | |
4551 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
4552 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
4553 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
4554 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
4555 } | |
4556 }); | |
4557 | |
4558 test('format', function (assert) { | |
4559 var a = [ | |
4560 ['dddd, Do MMMM YYYY, h:mm:ss a', 'diumenge, 14è febrer 2010, 3:25:50 pm'], | |
4561 ['ddd, hA', 'dg., 3PM'], | |
4562 ['M Mo MM MMMM MMM', '2 2n 02 febrer febr.'], | |
4563 ['YYYY YY', '2010 10'], | |
4564 ['D Do DD', '14 14è 14'], | |
4565 ['d do dddd ddd dd', '0 0è diumenge dg. Dg'], | |
4566 ['DDD DDDo DDDD', '45 45è 045'], | |
4567 ['w wo ww', '6 6a 06'], | |
4568 ['h hh', '3 03'], | |
4569 ['H HH', '15 15'], | |
4570 ['m mm', '25 25'], | |
4571 ['s ss', '50 50'], | |
4572 ['a A', 'pm PM'], | |
4573 ['[the] DDDo [day of the year]', 'the 45è day of the year'], | |
4574 ['LTS', '15:25:50'], | |
4575 ['L', '14/02/2010'], | |
4576 ['LL', '14 febrer 2010'], | |
4577 ['LLL', '14 febrer 2010 15:25'], | |
4578 ['LLLL', 'diumenge 14 febrer 2010 15:25'], | |
4579 ['l', '14/2/2010'], | |
4580 ['ll', '14 febr. 2010'], | |
4581 ['lll', '14 febr. 2010 15:25'], | |
4582 ['llll', 'dg. 14 febr. 2010 15:25'] | |
4583 ], | |
4584 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
4585 i; | |
4586 for (i = 0; i < a.length; i++) { | |
4587 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
4588 } | |
4589 }); | |
4590 | |
4591 test('format ordinal', function (assert) { | |
4592 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1r', '1r'); | |
4593 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2n', '2n'); | |
4594 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3r', '3r'); | |
4595 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4t', '4t'); | |
4596 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5è', '5è'); | |
4597 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6è', '6è'); | |
4598 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7è', '7è'); | |
4599 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8è', '8è'); | |
4600 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9è', '9è'); | |
4601 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10è', '10è'); | |
4602 | |
4603 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11è', '11è'); | |
4604 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12è', '12è'); | |
4605 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13è', '13è'); | |
4606 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14è', '14è'); | |
4607 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15è', '15è'); | |
4608 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16è', '16è'); | |
4609 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17è', '17è'); | |
4610 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18è', '18è'); | |
4611 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19è', '19è'); | |
4612 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20è', '20è'); | |
4613 | |
4614 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21è', '21è'); | |
4615 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22è', '22è'); | |
4616 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23è', '23è'); | |
4617 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24è', '24è'); | |
4618 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25è', '25è'); | |
4619 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26è', '26è'); | |
4620 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27è', '27è'); | |
4621 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28è', '28è'); | |
4622 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29è', '29è'); | |
4623 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30è', '30è'); | |
4624 | |
4625 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31è', '31è'); | |
4626 }); | |
4627 | |
4628 test('format month', function (assert) { | |
4629 var expected = 'gener gen._febrer febr._març mar._abril abr._maig mai._juny jun._juliol jul._agost ag._setembre set._octubre oct._novembre nov._desembre des.'.split('_'), i; | |
4630 for (i = 0; i < expected.length; i++) { | |
4631 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
4632 } | |
4633 }); | |
4634 | |
4635 test('format week', function (assert) { | |
4636 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; | |
4637 for (i = 0; i < expected.length; i++) { | |
4638 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
4639 } | |
4640 }); | |
4641 | |
4642 test('from', function (assert) { | |
4643 var start = moment([2007, 1, 28]); | |
4644 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'uns segons', '44 seconds = a few seconds'); | |
4645 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'un minut', '45 seconds = a minute'); | |
4646 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'un minut', '89 seconds = a minute'); | |
4647 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuts', '90 seconds = 2 minutes'); | |
4648 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuts', '44 minutes = 44 minutes'); | |
4649 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'una hora', '45 minutes = an hour'); | |
4650 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'una hora', '89 minutes = an hour'); | |
4651 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hores', '90 minutes = 2 hours'); | |
4652 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hores', '5 hours = 5 hours'); | |
4653 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hores', '21 hours = 21 hours'); | |
4654 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un dia', '22 hours = a day'); | |
4655 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un dia', '35 hours = a day'); | |
4656 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dies', '36 hours = 2 days'); | |
4657 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un dia', '1 day = a day'); | |
4658 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dies', '5 days = 5 days'); | |
4659 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dies', '25 days = 25 days'); | |
4660 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'un mes', '26 days = a month'); | |
4661 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'un mes', '30 days = a month'); | |
4662 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'un mes', '43 days = a month'); | |
4663 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mesos', '46 days = 2 months'); | |
4664 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mesos', '75 days = 2 months'); | |
4665 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mesos', '76 days = 3 months'); | |
4666 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'un mes', '1 month = a month'); | |
4667 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mesos', '5 months = 5 months'); | |
4668 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un any', '345 days = a year'); | |
4669 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 anys', '548 days = 2 years'); | |
4670 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un any', '1 year = a year'); | |
4671 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 anys', '5 years = 5 years'); | |
4672 }); | |
4673 | |
4674 test('suffix', function (assert) { | |
4675 assert.equal(moment(30000).from(0), 'en uns segons', 'prefix'); | |
4676 assert.equal(moment(0).from(30000), 'fa uns segons', 'suffix'); | |
4677 }); | |
4678 | |
4679 test('now from now', function (assert) { | |
4680 assert.equal(moment().fromNow(), 'fa uns segons', 'now from now should display as in the past'); | |
4681 }); | |
4682 | |
4683 test('fromNow', function (assert) { | |
4684 assert.equal(moment().add({s: 30}).fromNow(), 'en uns segons', 'en uns segons'); | |
4685 assert.equal(moment().add({d: 5}).fromNow(), 'en 5 dies', 'en 5 dies'); | |
4686 }); | |
4687 | |
4688 test('calendar day', function (assert) { | |
4689 var a = moment().hours(2).minutes(0).seconds(0); | |
4690 | |
4691 assert.equal(moment(a).calendar(), 'avui a les 2:00', 'today at the same time'); | |
4692 assert.equal(moment(a).add({m: 25}).calendar(), 'avui a les 2:25', 'Now plus 25 min'); | |
4693 assert.equal(moment(a).add({h: 1}).calendar(), 'avui a les 3:00', 'Now plus 1 hour'); | |
4694 assert.equal(moment(a).add({d: 1}).calendar(), 'demà a les 2:00', 'tomorrow at the same time'); | |
4695 assert.equal(moment(a).add({d: 1, h : -1}).calendar(), 'demà a la 1:00', 'tomorrow minus 1 hour'); | |
4696 assert.equal(moment(a).subtract({h: 1}).calendar(), 'avui a la 1:00', 'Now minus 1 hour'); | |
4697 assert.equal(moment(a).subtract({d: 1}).calendar(), 'ahir a les 2:00', 'yesterday at the same time'); | |
4698 }); | |
4699 | |
4700 test('calendar next week', function (assert) { | |
4701 var i, m; | |
4702 for (i = 2; i < 7; i++) { | |
4703 m = moment().add({d: i}); | |
4704 assert.equal(m.calendar(), m.format('dddd [a ' + ((m.hours() !== 1) ? 'les' : 'la') + '] LT'), 'Today + ' + i + ' days current time'); | |
4705 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
4706 assert.equal(m.calendar(), m.format('dddd [a ' + ((m.hours() !== 1) ? 'les' : 'la') + '] LT'), 'Today + ' + i + ' days beginning of day'); | |
4707 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
4708 assert.equal(m.calendar(), m.format('dddd [a ' + ((m.hours() !== 1) ? 'les' : 'la') + '] LT'), 'Today + ' + i + ' days end of day'); | |
4709 } | |
4710 }); | |
4711 | |
4712 test('calendar last week', function (assert) { | |
4713 var i, m; | |
4714 for (i = 2; i < 7; i++) { | |
4715 m = moment().subtract({d: i}); | |
4716 assert.equal(m.calendar(), m.format('[el] dddd [passat a ' + ((m.hours() !== 1) ? 'les' : 'la') + '] LT'), 'Today - ' + i + ' days current time'); | |
4717 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
4718 assert.equal(m.calendar(), m.format('[el] dddd [passat a ' + ((m.hours() !== 1) ? 'les' : 'la') + '] LT'), 'Today - ' + i + ' days beginning of day'); | |
4719 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
4720 assert.equal(m.calendar(), m.format('[el] dddd [passat a ' + ((m.hours() !== 1) ? 'les' : 'la') + '] LT'), 'Today - ' + i + ' days end of day'); | |
4721 } | |
4722 }); | |
4723 | |
4724 test('calendar all else', function (assert) { | |
4725 var weeksAgo = moment().subtract({w: 1}), | |
4726 weeksFromNow = moment().add({w: 1}); | |
4727 | |
4728 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
4729 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
4730 | |
4731 weeksAgo = moment().subtract({w: 2}); | |
4732 weeksFromNow = moment().add({w: 2}); | |
4733 | |
4734 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
4735 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
4736 }); | |
4737 | |
4738 test('weeks year starting sunday', function (assert) { | |
4739 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
4740 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
4741 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
4742 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
4743 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
4744 }); | |
4745 | |
4746 test('weeks year starting monday', function (assert) { | |
4747 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
4748 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
4749 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
4750 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
4751 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
4752 }); | |
4753 | |
4754 test('weeks year starting tuesday', function (assert) { | |
4755 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
4756 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
4757 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
4758 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
4759 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
4760 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
4761 }); | |
4762 | |
4763 test('weeks year starting wednesday', function (assert) { | |
4764 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
4765 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
4766 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
4767 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
4768 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
4769 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
4770 }); | |
4771 | |
4772 test('weeks year starting thursday', function (assert) { | |
4773 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
4774 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
4775 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
4776 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
4777 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
4778 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
4779 }); | |
4780 | |
4781 test('weeks year starting friday', function (assert) { | |
4782 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
4783 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
4784 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
4785 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
4786 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
4787 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
4788 }); | |
4789 | |
4790 test('weeks year starting saturday', function (assert) { | |
4791 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
4792 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
4793 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
4794 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
4795 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
4796 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
4797 }); | |
4798 | |
4799 test('weeks year starting sunday formatted', function (assert) { | |
4800 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52a', 'Jan 1 2012 should be week 52'); | |
4801 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1a', 'Jan 2 2012 should be week 1'); | |
4802 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1a', 'Jan 8 2012 should be week 1'); | |
4803 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2a', 'Jan 9 2012 should be week 2'); | |
4804 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2a', 'Jan 15 2012 should be week 2'); | |
4805 }); | |
4806 | |
4807 test('lenient ordinal parsing', function (assert) { | |
4808 var i, ordinalStr, testMoment; | |
4809 for (i = 1; i <= 31; ++i) { | |
4810 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
4811 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
4812 assert.equal(testMoment.year(), 2014, | |
4813 'lenient ordinal parsing ' + i + ' year check'); | |
4814 assert.equal(testMoment.month(), 0, | |
4815 'lenient ordinal parsing ' + i + ' month check'); | |
4816 assert.equal(testMoment.date(), i, | |
4817 'lenient ordinal parsing ' + i + ' date check'); | |
4818 } | |
4819 }); | |
4820 | |
4821 test('lenient ordinal parsing of number', function (assert) { | |
4822 var i, testMoment; | |
4823 for (i = 1; i <= 31; ++i) { | |
4824 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
4825 assert.equal(testMoment.year(), 2014, | |
4826 'lenient ordinal parsing of number ' + i + ' year check'); | |
4827 assert.equal(testMoment.month(), 0, | |
4828 'lenient ordinal parsing of number ' + i + ' month check'); | |
4829 assert.equal(testMoment.date(), i, | |
4830 'lenient ordinal parsing of number ' + i + ' date check'); | |
4831 } | |
4832 }); | |
4833 | |
4834 test('strict ordinal parsing', function (assert) { | |
4835 var i, ordinalStr, testMoment; | |
4836 for (i = 1; i <= 31; ++i) { | |
4837 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
4838 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
4839 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
4840 } | |
4841 }); | |
4842 | |
4843 })); | |
4844 | |
4845 (function (global, factory) { | |
4846 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
4847 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
4848 factory(global.moment) | |
4849 }(this, function (moment) { 'use strict'; | |
4850 | |
4851 /*global QUnit:false*/ | |
4852 | |
4853 var test = QUnit.test; | |
4854 | |
4855 function module (name, lifecycle) { | |
4856 QUnit.module(name, { | |
4857 setup : function () { | |
4858 moment.locale('en'); | |
4859 moment.createFromInputFallback = function () { | |
4860 throw new Error('input not handled by moment'); | |
4861 }; | |
4862 if (lifecycle && lifecycle.setup) { | |
4863 lifecycle.setup(); | |
4864 } | |
4865 }, | |
4866 teardown : function () { | |
4867 if (lifecycle && lifecycle.teardown) { | |
4868 lifecycle.teardown(); | |
4869 } | |
4870 } | |
4871 }); | |
4872 } | |
4873 | |
4874 function localeModule (name, lifecycle) { | |
4875 QUnit.module('locale:' + name, { | |
4876 setup : function () { | |
4877 moment.locale(name); | |
4878 moment.createFromInputFallback = function () { | |
4879 throw new Error('input not handled by moment'); | |
4880 }; | |
4881 if (lifecycle && lifecycle.setup) { | |
4882 lifecycle.setup(); | |
4883 } | |
4884 }, | |
4885 teardown : function () { | |
4886 moment.locale('en'); | |
4887 if (lifecycle && lifecycle.teardown) { | |
4888 lifecycle.teardown(); | |
4889 } | |
4890 } | |
4891 }); | |
4892 } | |
4893 | |
4894 localeModule('cs'); | |
4895 | |
4896 test('parse', function (assert) { | |
4897 var tests = '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; | |
4898 function equalTest(input, mmm, monthIndex) { | |
4899 assert.equal(moment(input, mmm).month(), monthIndex, input + ' should be month ' + (monthIndex + 1)); | |
4900 } | |
4901 for (i = 0; i < 12; i++) { | |
4902 tests[i] = tests[i].split(' '); | |
4903 equalTest(tests[i][0], 'MMM', i); | |
4904 equalTest(tests[i][1], 'MMM', i); | |
4905 equalTest(tests[i][0], 'MMMM', i); | |
4906 equalTest(tests[i][1], 'MMMM', i); | |
4907 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
4908 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
4909 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
4910 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
4911 } | |
4912 }); | |
4913 | |
4914 test('format', function (assert) { | |
4915 var a = [ | |
4916 ['dddd, MMMM Do YYYY, h:mm:ss', 'neděle, únor 14. 2010, 3:25:50'], | |
4917 ['ddd, h', 'ne, 3'], | |
4918 ['M Mo MM MMMM MMM', '2 2. 02 únor úno'], | |
4919 ['YYYY YY', '2010 10'], | |
4920 ['D Do DD', '14 14. 14'], | |
4921 ['d do dddd ddd dd', '0 0. neděle ne ne'], | |
4922 ['DDD DDDo DDDD', '45 45. 045'], | |
4923 ['w wo ww', '6 6. 06'], | |
4924 ['h hh', '3 03'], | |
4925 ['H HH', '15 15'], | |
4926 ['m mm', '25 25'], | |
4927 ['s ss', '50 50'], | |
4928 ['a A', 'pm PM'], | |
4929 ['DDDo [den v roce]', '45. den v roce'], | |
4930 ['LTS', '15:25:50'], | |
4931 ['L', '14.02.2010'], | |
4932 ['LL', '14. únor 2010'], | |
4933 ['LLL', '14. únor 2010 15:25'], | |
4934 ['LLLL', 'neděle 14. únor 2010 15:25'], | |
4935 ['l', '14.2.2010'], | |
4936 ['ll', '14. úno 2010'], | |
4937 ['lll', '14. úno 2010 15:25'], | |
4938 ['llll', 'ne 14. úno 2010 15:25'] | |
4939 ], | |
4940 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
4941 i; | |
4942 for (i = 0; i < a.length; i++) { | |
4943 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
4944 } | |
4945 }); | |
4946 | |
4947 test('format ordinal', function (assert) { | |
4948 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.'); | |
4949 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.'); | |
4950 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.'); | |
4951 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.'); | |
4952 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.'); | |
4953 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.'); | |
4954 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.'); | |
4955 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.'); | |
4956 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.'); | |
4957 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.'); | |
4958 | |
4959 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.'); | |
4960 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.'); | |
4961 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.'); | |
4962 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.'); | |
4963 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.'); | |
4964 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.'); | |
4965 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.'); | |
4966 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.'); | |
4967 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.'); | |
4968 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.'); | |
4969 | |
4970 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.'); | |
4971 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.'); | |
4972 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.'); | |
4973 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.'); | |
4974 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.'); | |
4975 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.'); | |
4976 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.'); | |
4977 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.'); | |
4978 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.'); | |
4979 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.'); | |
4980 | |
4981 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.'); | |
4982 }); | |
4983 | |
4984 test('format month', function (assert) { | |
4985 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; | |
4986 for (i = 0; i < expected.length; i++) { | |
4987 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
4988 } | |
4989 }); | |
4990 | |
4991 test('format week', function (assert) { | |
4992 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; | |
4993 for (i = 0; i < expected.length; i++) { | |
4994 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
4995 } | |
4996 }); | |
4997 | |
4998 test('from', function (assert) { | |
4999 var start = moment([2007, 1, 28]); | |
5000 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'pár sekund', '44 seconds = a few seconds'); | |
5001 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minuta', '45 seconds = a minute'); | |
5002 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minuta', '89 seconds = a minute'); | |
5003 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuty', '90 seconds = 2 minutes'); | |
5004 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minut', '44 minutes = 44 minutes'); | |
5005 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'hodina', '45 minutes = an hour'); | |
5006 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'hodina', '89 minutes = an hour'); | |
5007 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hodiny', '90 minutes = 2 hours'); | |
5008 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hodin', '5 hours = 5 hours'); | |
5009 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hodin', '21 hours = 21 hours'); | |
5010 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'den', '22 hours = a day'); | |
5011 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'den', '35 hours = a day'); | |
5012 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dny', '36 hours = 2 days'); | |
5013 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'den', '1 day = a day'); | |
5014 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dní', '5 days = 5 days'); | |
5015 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dní', '25 days = 25 days'); | |
5016 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'měsíc', '26 days = a month'); | |
5017 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'měsíc', '30 days = a month'); | |
5018 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'měsíc', '43 days = a month'); | |
5019 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 měsíce', '46 days = 2 months'); | |
5020 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 měsíce', '75 days = 2 months'); | |
5021 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 měsíce', '76 days = 3 months'); | |
5022 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'měsíc', '1 month = a month'); | |
5023 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 měsíců', '5 months = 5 months'); | |
5024 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'rok', '345 days = a year'); | |
5025 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 roky', '548 days = 2 years'); | |
5026 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'rok', '1 year = a year'); | |
5027 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 let', '5 years = 5 years'); | |
5028 }); | |
5029 | |
5030 test('suffix', function (assert) { | |
5031 assert.equal(moment(30000).from(0), 'za pár sekund', 'prefix'); | |
5032 assert.equal(moment(0).from(30000), 'před pár sekundami', 'suffix'); | |
5033 }); | |
5034 | |
5035 test('now from now', function (assert) { | |
5036 assert.equal(moment().fromNow(), 'před pár sekundami', 'now from now should display as in the past'); | |
5037 }); | |
5038 | |
5039 test('fromNow (future)', function (assert) { | |
5040 assert.equal(moment().add({s: 30}).fromNow(), 'za pár sekund', 'in a few seconds'); | |
5041 assert.equal(moment().add({m: 1}).fromNow(), 'za minutu', 'in a minute'); | |
5042 assert.equal(moment().add({m: 3}).fromNow(), 'za 3 minuty', 'in 3 minutes'); | |
5043 assert.equal(moment().add({m: 10}).fromNow(), 'za 10 minut', 'in 10 minutes'); | |
5044 assert.equal(moment().add({h: 1}).fromNow(), 'za hodinu', 'in an hour'); | |
5045 assert.equal(moment().add({h: 3}).fromNow(), 'za 3 hodiny', 'in 3 hours'); | |
5046 assert.equal(moment().add({h: 10}).fromNow(), 'za 10 hodin', 'in 10 hours'); | |
5047 assert.equal(moment().add({d: 1}).fromNow(), 'za den', 'in a day'); | |
5048 assert.equal(moment().add({d: 3}).fromNow(), 'za 3 dny', 'in 3 days'); | |
5049 assert.equal(moment().add({d: 10}).fromNow(), 'za 10 dní', 'in 10 days'); | |
5050 assert.equal(moment().add({M: 1}).fromNow(), 'za měsíc', 'in a month'); | |
5051 assert.equal(moment().add({M: 3}).fromNow(), 'za 3 měsíce', 'in 3 months'); | |
5052 assert.equal(moment().add({M: 10}).fromNow(), 'za 10 měsíců', 'in 10 months'); | |
5053 assert.equal(moment().add({y: 1}).fromNow(), 'za rok', 'in a year'); | |
5054 assert.equal(moment().add({y: 3}).fromNow(), 'za 3 roky', 'in 3 years'); | |
5055 assert.equal(moment().add({y: 10}).fromNow(), 'za 10 let', 'in 10 years'); | |
5056 }); | |
5057 | |
5058 test('fromNow (past)', function (assert) { | |
5059 assert.equal(moment().subtract({s: 30}).fromNow(), 'před pár sekundami', 'a few seconds ago'); | |
5060 assert.equal(moment().subtract({m: 1}).fromNow(), 'před minutou', 'a minute ago'); | |
5061 assert.equal(moment().subtract({m: 3}).fromNow(), 'před 3 minutami', '3 minutes ago'); | |
5062 assert.equal(moment().subtract({m: 10}).fromNow(), 'před 10 minutami', '10 minutes ago'); | |
5063 assert.equal(moment().subtract({h: 1}).fromNow(), 'před hodinou', 'an hour ago'); | |
5064 assert.equal(moment().subtract({h: 3}).fromNow(), 'před 3 hodinami', '3 hours ago'); | |
5065 assert.equal(moment().subtract({h: 10}).fromNow(), 'před 10 hodinami', '10 hours ago'); | |
5066 assert.equal(moment().subtract({d: 1}).fromNow(), 'před dnem', 'a day ago'); | |
5067 assert.equal(moment().subtract({d: 3}).fromNow(), 'před 3 dny', '3 days ago'); | |
5068 assert.equal(moment().subtract({d: 10}).fromNow(), 'před 10 dny', '10 days ago'); | |
5069 assert.equal(moment().subtract({M: 1}).fromNow(), 'před měsícem', 'a month ago'); | |
5070 assert.equal(moment().subtract({M: 3}).fromNow(), 'před 3 měsíci', '3 months ago'); | |
5071 assert.equal(moment().subtract({M: 10}).fromNow(), 'před 10 měsíci', '10 months ago'); | |
5072 assert.equal(moment().subtract({y: 1}).fromNow(), 'před rokem', 'a year ago'); | |
5073 assert.equal(moment().subtract({y: 3}).fromNow(), 'před 3 lety', '3 years ago'); | |
5074 assert.equal(moment().subtract({y: 10}).fromNow(), 'před 10 lety', '10 years ago'); | |
5075 }); | |
5076 | |
5077 test('calendar day', function (assert) { | |
5078 var a = moment().hours(2).minutes(0).seconds(0); | |
5079 | |
5080 assert.equal(moment(a).calendar(), 'dnes v 2:00', 'today at the same time'); | |
5081 assert.equal(moment(a).add({m: 25}).calendar(), 'dnes v 2:25', 'Now plus 25 min'); | |
5082 assert.equal(moment(a).add({h: 1}).calendar(), 'dnes v 3:00', 'Now plus 1 hour'); | |
5083 assert.equal(moment(a).add({d: 1}).calendar(), 'zítra v 2:00', 'tomorrow at the same time'); | |
5084 assert.equal(moment(a).subtract({h: 1}).calendar(), 'dnes v 1:00', 'Now minus 1 hour'); | |
5085 assert.equal(moment(a).subtract({d: 1}).calendar(), 'včera v 2:00', 'yesterday at the same time'); | |
5086 }); | |
5087 | |
5088 test('calendar next week', function (assert) { | |
5089 var i, m, nextDay; | |
5090 for (i = 2; i < 7; i++) { | |
5091 m = moment().add({d: i}); | |
5092 nextDay = ''; | |
5093 switch (m.day()) { | |
5094 case 0: | |
5095 nextDay = 'v neděli'; | |
5096 break; | |
5097 case 1: | |
5098 nextDay = 'v pondělí'; | |
5099 break; | |
5100 case 2: | |
5101 nextDay = 'v úterý'; | |
5102 break; | |
5103 case 3: | |
5104 nextDay = 've středu'; | |
5105 break; | |
5106 case 4: | |
5107 nextDay = 've čtvrtek'; | |
5108 break; | |
5109 case 5: | |
5110 nextDay = 'v pátek'; | |
5111 break; | |
5112 case 6: | |
5113 nextDay = 'v sobotu'; | |
5114 break; | |
5115 } | |
5116 assert.equal(m.calendar(), m.format('[' + nextDay + '] [v] LT'), 'Today + ' + i + ' days current time'); | |
5117 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
5118 assert.equal(m.calendar(), m.format('[' + nextDay + '] [v] LT'), 'Today + ' + i + ' days beginning of day'); | |
5119 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
5120 assert.equal(m.calendar(), m.format('[' + nextDay + '] [v] LT'), 'Today + ' + i + ' days end of day'); | |
5121 } | |
5122 }); | |
5123 | |
5124 test('calendar last week', function (assert) { | |
5125 var i, m, lastDay; | |
5126 for (i = 2; i < 7; i++) { | |
5127 m = moment().subtract({d: i}); | |
5128 lastDay = ''; | |
5129 switch (m.day()) { | |
5130 case 0: | |
5131 lastDay = 'minulou neděli'; | |
5132 break; | |
5133 case 1: | |
5134 lastDay = 'minulé pondělí'; | |
5135 break; | |
5136 case 2: | |
5137 lastDay = 'minulé úterý'; | |
5138 break; | |
5139 case 3: | |
5140 lastDay = 'minulou středu'; | |
5141 break; | |
5142 case 4: | |
5143 lastDay = 'minulý čtvrtek'; | |
5144 break; | |
5145 case 5: | |
5146 lastDay = 'minulý pátek'; | |
5147 break; | |
5148 case 6: | |
5149 lastDay = 'minulou sobotu'; | |
5150 break; | |
5151 } | |
5152 assert.equal(m.calendar(), m.format('[' + lastDay + '] [v] LT'), 'Today - ' + i + ' days current time'); | |
5153 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
5154 assert.equal(m.calendar(), m.format('[' + lastDay + '] [v] LT'), 'Today - ' + i + ' days beginning of day'); | |
5155 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
5156 assert.equal(m.calendar(), m.format('[' + lastDay + '] [v] LT'), 'Today - ' + i + ' days end of day'); | |
5157 } | |
5158 }); | |
5159 | |
5160 test('calendar all else', function (assert) { | |
5161 var weeksAgo = moment().subtract({w: 1}), | |
5162 weeksFromNow = moment().add({w: 1}); | |
5163 | |
5164 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
5165 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
5166 | |
5167 weeksAgo = moment().subtract({w: 2}); | |
5168 weeksFromNow = moment().add({w: 2}); | |
5169 | |
5170 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
5171 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
5172 }); | |
5173 | |
5174 test('humanize duration', function (assert) { | |
5175 assert.equal(moment.duration(1, 'minutes').humanize(), 'minuta', 'a minute (future)'); | |
5176 assert.equal(moment.duration(1, 'minutes').humanize(true), 'za minutu', 'in a minute'); | |
5177 assert.equal(moment.duration(-1, 'minutes').humanize(), 'minuta', 'a minute (past)'); | |
5178 assert.equal(moment.duration(-1, 'minutes').humanize(true), 'před minutou', 'a minute ago'); | |
5179 }); | |
5180 | |
5181 test('weeks year starting sunday', function (assert) { | |
5182 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
5183 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
5184 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
5185 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
5186 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
5187 }); | |
5188 | |
5189 test('weeks year starting monday', function (assert) { | |
5190 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
5191 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
5192 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
5193 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
5194 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
5195 }); | |
5196 | |
5197 test('weeks year starting tuesday', function (assert) { | |
5198 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
5199 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
5200 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
5201 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
5202 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
5203 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
5204 }); | |
5205 | |
5206 test('weeks year starting wednesday', function (assert) { | |
5207 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
5208 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
5209 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
5210 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
5211 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
5212 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
5213 }); | |
5214 | |
5215 test('weeks year starting thursday', function (assert) { | |
5216 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
5217 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
5218 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
5219 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
5220 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
5221 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
5222 }); | |
5223 | |
5224 test('weeks year starting friday', function (assert) { | |
5225 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
5226 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
5227 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
5228 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
5229 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
5230 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
5231 }); | |
5232 | |
5233 test('weeks year starting saturday', function (assert) { | |
5234 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
5235 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
5236 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
5237 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
5238 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
5239 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
5240 }); | |
5241 | |
5242 test('weeks year starting sunday formatted', function (assert) { | |
5243 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52'); | |
5244 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1'); | |
5245 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1'); | |
5246 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2'); | |
5247 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2'); | |
5248 }); | |
5249 | |
5250 test('lenient ordinal parsing', function (assert) { | |
5251 var i, ordinalStr, testMoment; | |
5252 for (i = 1; i <= 31; ++i) { | |
5253 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
5254 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
5255 assert.equal(testMoment.year(), 2014, | |
5256 'lenient ordinal parsing ' + i + ' year check'); | |
5257 assert.equal(testMoment.month(), 0, | |
5258 'lenient ordinal parsing ' + i + ' month check'); | |
5259 assert.equal(testMoment.date(), i, | |
5260 'lenient ordinal parsing ' + i + ' date check'); | |
5261 } | |
5262 }); | |
5263 | |
5264 test('lenient ordinal parsing of number', function (assert) { | |
5265 var i, testMoment; | |
5266 for (i = 1; i <= 31; ++i) { | |
5267 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
5268 assert.equal(testMoment.year(), 2014, | |
5269 'lenient ordinal parsing of number ' + i + ' year check'); | |
5270 assert.equal(testMoment.month(), 0, | |
5271 'lenient ordinal parsing of number ' + i + ' month check'); | |
5272 assert.equal(testMoment.date(), i, | |
5273 'lenient ordinal parsing of number ' + i + ' date check'); | |
5274 } | |
5275 }); | |
5276 | |
5277 test('strict ordinal parsing', function (assert) { | |
5278 var i, ordinalStr, testMoment; | |
5279 for (i = 1; i <= 31; ++i) { | |
5280 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
5281 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
5282 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
5283 } | |
5284 }); | |
5285 | |
5286 })); | |
5287 | |
5288 (function (global, factory) { | |
5289 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
5290 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
5291 factory(global.moment) | |
5292 }(this, function (moment) { 'use strict'; | |
5293 | |
5294 /*global QUnit:false*/ | |
5295 | |
5296 var test = QUnit.test; | |
5297 | |
5298 function module (name, lifecycle) { | |
5299 QUnit.module(name, { | |
5300 setup : function () { | |
5301 moment.locale('en'); | |
5302 moment.createFromInputFallback = function () { | |
5303 throw new Error('input not handled by moment'); | |
5304 }; | |
5305 if (lifecycle && lifecycle.setup) { | |
5306 lifecycle.setup(); | |
5307 } | |
5308 }, | |
5309 teardown : function () { | |
5310 if (lifecycle && lifecycle.teardown) { | |
5311 lifecycle.teardown(); | |
5312 } | |
5313 } | |
5314 }); | |
5315 } | |
5316 | |
5317 function localeModule (name, lifecycle) { | |
5318 QUnit.module('locale:' + name, { | |
5319 setup : function () { | |
5320 moment.locale(name); | |
5321 moment.createFromInputFallback = function () { | |
5322 throw new Error('input not handled by moment'); | |
5323 }; | |
5324 if (lifecycle && lifecycle.setup) { | |
5325 lifecycle.setup(); | |
5326 } | |
5327 }, | |
5328 teardown : function () { | |
5329 moment.locale('en'); | |
5330 if (lifecycle && lifecycle.teardown) { | |
5331 lifecycle.teardown(); | |
5332 } | |
5333 } | |
5334 }); | |
5335 } | |
5336 | |
5337 localeModule('cv'); | |
5338 | |
5339 test('parse', function (assert) { | |
5340 var tests = 'кӑрлач кӑр_нарӑс нар_пуш пуш_ака ака_май май_ҫӗртме ҫӗр_утӑ утӑ_ҫурла ҫур_авӑн авн_юпа юпа_чӳк чӳк_раштав раш'.split('_'), i; | |
5341 function equalTest(input, mmm, i) { | |
5342 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
5343 } | |
5344 for (i = 0; i < 12; i++) { | |
5345 tests[i] = tests[i].split(' '); | |
5346 equalTest(tests[i][0], 'MMM', i); | |
5347 equalTest(tests[i][1], 'MMM', i); | |
5348 equalTest(tests[i][0], 'MMMM', i); | |
5349 equalTest(tests[i][1], 'MMMM', i); | |
5350 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
5351 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
5352 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
5353 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
5354 } | |
5355 }); | |
5356 | |
5357 test('format', function (assert) { | |
5358 var a = [ | |
5359 ['dddd, MMMM Do YYYY, h:mm:ss a', 'вырсарникун, нарӑс 14-мӗш 2010, 3:25:50 pm'], | |
5360 ['ddd, hA', 'выр, 3PM'], | |
5361 ['M Mo MM MMMM MMM', '2 2-мӗш 02 нарӑс нар'], | |
5362 ['YYYY YY', '2010 10'], | |
5363 ['D Do DD', '14 14-мӗш 14'], | |
5364 ['d do dddd ddd dd', '0 0-мӗш вырсарникун выр вр'], | |
5365 ['DDD DDDo DDDD', '45 45-мӗш 045'], | |
5366 ['w wo ww', '7 7-мӗш 07'], | |
5367 ['h hh', '3 03'], | |
5368 ['H HH', '15 15'], | |
5369 ['m mm', '25 25'], | |
5370 ['s ss', '50 50'], | |
5371 ['a A', 'pm PM'], | |
5372 ['Ҫулӑн DDDo кунӗ', 'Ҫулӑн 45-мӗш кунӗ'], | |
5373 ['LTS', '15:25:50'], | |
5374 ['L', '14-02-2010'], | |
5375 ['LL', '2010 ҫулхи нарӑс уйӑхӗн 14-мӗшӗ'], | |
5376 ['LLL', '2010 ҫулхи нарӑс уйӑхӗн 14-мӗшӗ, 15:25'], | |
5377 ['LLLL', 'вырсарникун, 2010 ҫулхи нарӑс уйӑхӗн 14-мӗшӗ, 15:25'], | |
5378 ['l', '14-2-2010'], | |
5379 ['ll', '2010 ҫулхи нар уйӑхӗн 14-мӗшӗ'], | |
5380 ['lll', '2010 ҫулхи нар уйӑхӗн 14-мӗшӗ, 15:25'], | |
5381 ['llll', 'выр, 2010 ҫулхи нар уйӑхӗн 14-мӗшӗ, 15:25'] | |
5382 ], | |
5383 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
5384 i; | |
5385 for (i = 0; i < a.length; i++) { | |
5386 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
5387 } | |
5388 }); | |
5389 | |
5390 test('format ordinal', function (assert) { | |
5391 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-мӗш', '1-мӗш'); | |
5392 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-мӗш', '2-мӗш'); | |
5393 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-мӗш', '3-мӗш'); | |
5394 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-мӗш', '4-мӗш'); | |
5395 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-мӗш', '5-мӗш'); | |
5396 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-мӗш', '6-мӗш'); | |
5397 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-мӗш', '7-мӗш'); | |
5398 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-мӗш', '8-мӗш'); | |
5399 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-мӗш', '9-мӗш'); | |
5400 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-мӗш', '10-мӗш'); | |
5401 | |
5402 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-мӗш', '11-мӗш'); | |
5403 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-мӗш', '12-мӗш'); | |
5404 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-мӗш', '13-мӗш'); | |
5405 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-мӗш', '14-мӗш'); | |
5406 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-мӗш', '15-мӗш'); | |
5407 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-мӗш', '16-мӗш'); | |
5408 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-мӗш', '17-мӗш'); | |
5409 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-мӗш', '18-мӗш'); | |
5410 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-мӗш', '19-мӗш'); | |
5411 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-мӗш', '20-мӗш'); | |
5412 | |
5413 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-мӗш', '21-мӗш'); | |
5414 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-мӗш', '22-мӗш'); | |
5415 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-мӗш', '23-мӗш'); | |
5416 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-мӗш', '24-мӗш'); | |
5417 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-мӗш', '25-мӗш'); | |
5418 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-мӗш', '26-мӗш'); | |
5419 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-мӗш', '27-мӗш'); | |
5420 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-мӗш', '28-мӗш'); | |
5421 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-мӗш', '29-мӗш'); | |
5422 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-мӗш', '30-мӗш'); | |
5423 | |
5424 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-мӗш', '31-мӗш'); | |
5425 }); | |
5426 | |
5427 test('format month', function (assert) { | |
5428 var expected = 'кӑрлач кӑр_нарӑс нар_пуш пуш_ака ака_май май_ҫӗртме ҫӗр_утӑ утӑ_ҫурла ҫур_авӑн авн_юпа юпа_чӳк чӳк_раштав раш'.split('_'), i; | |
5429 for (i = 0; i < expected.length; i++) { | |
5430 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
5431 } | |
5432 }); | |
5433 | |
5434 test('format week', function (assert) { | |
5435 var expected = 'вырсарникун выр вр_тунтикун тун тн_ытларикун ытл ыт_юнкун юн юн_кӗҫнерникун кӗҫ кҫ_эрнекун эрн эр_шӑматкун шӑм шм'.split('_'), i; | |
5436 for (i = 0; i < expected.length; i++) { | |
5437 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
5438 } | |
5439 }); | |
5440 | |
5441 test('from', function (assert) { | |
5442 var start = moment([2007, 1, 28]); | |
5443 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'пӗр-ик ҫеккунт', '44 sekunder = a few seconds'); | |
5444 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'пӗр минут', '45 seconds = a minute'); | |
5445 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'пӗр минут', '89 seconds = a minute'); | |
5446 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 минут', '90 seconds = 2 minutes'); | |
5447 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 минут', '44 minutes = 44 minutes'); | |
5448 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'пӗр сехет', '45 minutes = an hour'); | |
5449 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'пӗр сехет', '89 minutes = an hour'); | |
5450 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 сехет', '90 minutes = 2 hours'); | |
5451 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 сехет', '5 hours = 5 hours'); | |
5452 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 сехет', '21 hours = 21 hours'); | |
5453 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'пӗр кун', '22 hours = a day'); | |
5454 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'пӗр кун', '35 hours = a day'); | |
5455 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 кун', '36 hours = 2 days'); | |
5456 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'пӗр кун', '1 day = a day'); | |
5457 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 кун', '5 days = 5 days'); | |
5458 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 кун', '25 days = 25 days'); | |
5459 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'пӗр уйӑх', '26 days = a month'); | |
5460 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'пӗр уйӑх', '30 days = a month'); | |
5461 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'пӗр уйӑх', '43 days = a month'); | |
5462 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 уйӑх', '46 days = 2 months'); | |
5463 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 уйӑх', '75 days = 2 months'); | |
5464 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 уйӑх', '76 days = 3 months'); | |
5465 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'пӗр уйӑх', '1 month = a month'); | |
5466 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 уйӑх', '5 months = 5 months'); | |
5467 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'пӗр ҫул', '345 days = a year'); | |
5468 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ҫул', '548 days = 2 years'); | |
5469 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'пӗр ҫул', '1 year = a year'); | |
5470 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ҫул', '5 years = 5 years'); | |
5471 }); | |
5472 | |
5473 test('suffix', function (assert) { | |
5474 assert.equal(moment(30000).from(0), 'пӗр-ик ҫеккунтран', 'prefix'); | |
5475 assert.equal(moment(0).from(30000), 'пӗр-ик ҫеккунт каялла', 'suffix'); | |
5476 }); | |
5477 | |
5478 test('now from now', function (assert) { | |
5479 assert.equal(moment().fromNow(), 'пӗр-ик ҫеккунт каялла', 'now from now should display as in the past'); | |
5480 }); | |
5481 | |
5482 test('fromNow', function (assert) { | |
5483 assert.equal(moment().add({s: 30}).fromNow(), 'пӗр-ик ҫеккунтран', 'in a few seconds'); | |
5484 assert.equal(moment().add({d: 5}).fromNow(), '5 кунран', 'in 5 days'); | |
5485 assert.equal(moment().add({h: 2}).fromNow(), '2 сехетрен', 'in 2 hours, the right suffix!'); | |
5486 assert.equal(moment().add({y: 3}).fromNow(), '3 ҫултан', 'in 3 years, the right suffix!'); | |
5487 }); | |
5488 | |
5489 test('calendar day', function (assert) { | |
5490 var a = moment().hours(2).minutes(0).seconds(0); | |
5491 assert.equal(moment(a).calendar(), 'Паян 02:00 сехетре', 'today at the same time'); | |
5492 assert.equal(moment(a).add({m: 25}).calendar(), 'Паян 02:25 сехетре', 'Now plus 25 min'); | |
5493 assert.equal(moment(a).add({h: 1}).calendar(), 'Паян 03:00 сехетре', 'Now plus 1 hour'); | |
5494 assert.equal(moment(a).add({d: 1}).calendar(), 'Ыран 02:00 сехетре', 'tomorrow at the same time'); | |
5495 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Паян 01:00 сехетре', 'Now minus 1 hour'); | |
5496 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Ӗнер 02:00 сехетре', 'yesterday at the same time'); | |
5497 }); | |
5498 | |
5499 test('calendar next week', function (assert) { | |
5500 var i, m; | |
5501 | |
5502 for (i = 2; i < 7; i++) { | |
5503 m = moment().add({d: i}); | |
5504 assert.equal(m.calendar(), m.format('[Ҫитес] dddd LT [сехетре]'), 'Today + ' + i + ' days current time'); | |
5505 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
5506 assert.equal(m.calendar(), m.format('[Ҫитес] dddd LT [сехетре]'), 'Today + ' + i + ' days beginning of day'); | |
5507 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
5508 assert.equal(m.calendar(), m.format('[Ҫитес] dddd LT [сехетре]'), 'Today + ' + i + ' days end of day'); | |
5509 } | |
5510 }); | |
5511 | |
5512 test('calendar last week', function (assert) { | |
5513 var i, m; | |
5514 | |
5515 for (i = 2; i < 7; i++) { | |
5516 m = moment().subtract({d: i}); | |
5517 assert.equal(m.calendar(), m.format('[Иртнӗ] dddd LT [сехетре]'), 'Today - ' + i + ' days current time'); | |
5518 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
5519 assert.equal(m.calendar(), m.format('[Иртнӗ] dddd LT [сехетре]'), 'Today - ' + i + ' days beginning of day'); | |
5520 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
5521 assert.equal(m.calendar(), m.format('[Иртнӗ] dddd LT [сехетре]'), 'Today - ' + i + ' days end of day'); | |
5522 } | |
5523 }); | |
5524 | |
5525 test('calendar all else', function (assert) { | |
5526 var weeksAgo = moment().subtract({w: 1}), | |
5527 weeksFromNow = moment().add({w: 1}); | |
5528 | |
5529 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
5530 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
5531 | |
5532 weeksAgo = moment().subtract({w: 2}); | |
5533 weeksFromNow = moment().add({w: 2}); | |
5534 | |
5535 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
5536 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
5537 }); | |
5538 | |
5539 // Monday is the first day of the week. | |
5540 // The week that contains Jan 1st is the first week of the year. | |
5541 | |
5542 test('weeks year starting sunday', function (assert) { | |
5543 assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1'); | |
5544 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
5545 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2'); | |
5546 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
5547 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3'); | |
5548 }); | |
5549 | |
5550 test('weeks year starting monday', function (assert) { | |
5551 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
5552 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
5553 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
5554 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
5555 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
5556 }); | |
5557 | |
5558 test('weeks year starting tuesday', function (assert) { | |
5559 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
5560 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
5561 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
5562 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
5563 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
5564 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
5565 }); | |
5566 | |
5567 test('weeks year starting wednesday', function (assert) { | |
5568 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
5569 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
5570 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
5571 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
5572 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
5573 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
5574 }); | |
5575 | |
5576 test('weeks year starting thursday', function (assert) { | |
5577 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
5578 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
5579 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
5580 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
5581 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
5582 assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3'); | |
5583 }); | |
5584 | |
5585 test('weeks year starting friday', function (assert) { | |
5586 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1'); | |
5587 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
5588 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1'); | |
5589 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2'); | |
5590 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2'); | |
5591 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3'); | |
5592 }); | |
5593 | |
5594 test('weeks year starting saturday', function (assert) { | |
5595 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1'); | |
5596 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
5597 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1'); | |
5598 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2'); | |
5599 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2'); | |
5600 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3'); | |
5601 }); | |
5602 | |
5603 test('weeks year starting sunday formatted', function (assert) { | |
5604 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-мӗш', 'Dec 26 2011 should be week 1'); | |
5605 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-мӗш', 'Jan 1 2012 should be week 1'); | |
5606 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-мӗш', 'Jan 2 2012 should be week 2'); | |
5607 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-мӗш', 'Jan 8 2012 should be week 2'); | |
5608 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-мӗш', 'Jan 9 2012 should be week 3'); | |
5609 }); | |
5610 | |
5611 test('lenient ordinal parsing', function (assert) { | |
5612 var i, ordinalStr, testMoment; | |
5613 for (i = 1; i <= 31; ++i) { | |
5614 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
5615 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
5616 assert.equal(testMoment.year(), 2014, | |
5617 'lenient ordinal parsing ' + i + ' year check'); | |
5618 assert.equal(testMoment.month(), 0, | |
5619 'lenient ordinal parsing ' + i + ' month check'); | |
5620 assert.equal(testMoment.date(), i, | |
5621 'lenient ordinal parsing ' + i + ' date check'); | |
5622 } | |
5623 }); | |
5624 | |
5625 test('lenient ordinal parsing of number', function (assert) { | |
5626 var i, testMoment; | |
5627 for (i = 1; i <= 31; ++i) { | |
5628 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
5629 assert.equal(testMoment.year(), 2014, | |
5630 'lenient ordinal parsing of number ' + i + ' year check'); | |
5631 assert.equal(testMoment.month(), 0, | |
5632 'lenient ordinal parsing of number ' + i + ' month check'); | |
5633 assert.equal(testMoment.date(), i, | |
5634 'lenient ordinal parsing of number ' + i + ' date check'); | |
5635 } | |
5636 }); | |
5637 | |
5638 test('strict ordinal parsing', function (assert) { | |
5639 var i, ordinalStr, testMoment; | |
5640 for (i = 1; i <= 31; ++i) { | |
5641 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
5642 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
5643 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
5644 } | |
5645 }); | |
5646 | |
5647 })); | |
5648 | |
5649 (function (global, factory) { | |
5650 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
5651 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
5652 factory(global.moment) | |
5653 }(this, function (moment) { 'use strict'; | |
5654 | |
5655 /*global QUnit:false*/ | |
5656 | |
5657 var test = QUnit.test; | |
5658 | |
5659 function module (name, lifecycle) { | |
5660 QUnit.module(name, { | |
5661 setup : function () { | |
5662 moment.locale('en'); | |
5663 moment.createFromInputFallback = function () { | |
5664 throw new Error('input not handled by moment'); | |
5665 }; | |
5666 if (lifecycle && lifecycle.setup) { | |
5667 lifecycle.setup(); | |
5668 } | |
5669 }, | |
5670 teardown : function () { | |
5671 if (lifecycle && lifecycle.teardown) { | |
5672 lifecycle.teardown(); | |
5673 } | |
5674 } | |
5675 }); | |
5676 } | |
5677 | |
5678 function localeModule (name, lifecycle) { | |
5679 QUnit.module('locale:' + name, { | |
5680 setup : function () { | |
5681 moment.locale(name); | |
5682 moment.createFromInputFallback = function () { | |
5683 throw new Error('input not handled by moment'); | |
5684 }; | |
5685 if (lifecycle && lifecycle.setup) { | |
5686 lifecycle.setup(); | |
5687 } | |
5688 }, | |
5689 teardown : function () { | |
5690 moment.locale('en'); | |
5691 if (lifecycle && lifecycle.teardown) { | |
5692 lifecycle.teardown(); | |
5693 } | |
5694 } | |
5695 }); | |
5696 } | |
5697 | |
5698 localeModule('cy'); | |
5699 | |
5700 test('parse', function (assert) { | |
5701 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('_'), | |
5702 i; | |
5703 function equalTest(input, mmm, i) { | |
5704 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
5705 } | |
5706 for (i = 0; i < 12; i++) { | |
5707 tests[i] = tests[i].split(' '); | |
5708 equalTest(tests[i][0], 'MMM', i); | |
5709 equalTest(tests[i][1], 'MMM', i); | |
5710 equalTest(tests[i][0], 'MMMM', i); | |
5711 equalTest(tests[i][1], 'MMMM', i); | |
5712 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
5713 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
5714 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
5715 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
5716 } | |
5717 }); | |
5718 | |
5719 test('format', function (assert) { | |
5720 var a = [ | |
5721 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Dydd Sul, Chwefror 14eg 2010, 3:25:50 pm'], | |
5722 ['ddd, hA', 'Sul, 3PM'], | |
5723 ['M Mo MM MMMM MMM', '2 2il 02 Chwefror Chwe'], | |
5724 ['YYYY YY', '2010 10'], | |
5725 ['D Do DD', '14 14eg 14'], | |
5726 ['d do dddd ddd dd', '0 0 Dydd Sul Sul Su'], | |
5727 ['DDD DDDo DDDD', '45 45ain 045'], | |
5728 ['w wo ww', '6 6ed 06'], | |
5729 ['h hh', '3 03'], | |
5730 ['H HH', '15 15'], | |
5731 ['m mm', '25 25'], | |
5732 ['s ss', '50 50'], | |
5733 ['a A', 'pm PM'], | |
5734 ['[the] DDDo [day of the year]', 'the 45ain day of the year'], | |
5735 ['LTS', '15:25:50'], | |
5736 ['L', '14/02/2010'], | |
5737 ['LL', '14 Chwefror 2010'], | |
5738 ['LLL', '14 Chwefror 2010 15:25'], | |
5739 ['LLLL', 'Dydd Sul, 14 Chwefror 2010 15:25'], | |
5740 ['l', '14/2/2010'], | |
5741 ['ll', '14 Chwe 2010'], | |
5742 ['lll', '14 Chwe 2010 15:25'], | |
5743 ['llll', 'Sul, 14 Chwe 2010 15:25'] | |
5744 ], | |
5745 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
5746 i; | |
5747 for (i = 0; i < a.length; i++) { | |
5748 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
5749 } | |
5750 }); | |
5751 | |
5752 test('format ordinal', function (assert) { | |
5753 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1af', '1af'); | |
5754 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2il', '2il'); | |
5755 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3ydd', '3ydd'); | |
5756 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4ydd', '4ydd'); | |
5757 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5ed', '5ed'); | |
5758 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6ed', '6ed'); | |
5759 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7ed', '7ed'); | |
5760 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8fed', '8fed'); | |
5761 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9fed', '9fed'); | |
5762 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10fed', '10fed'); | |
5763 | |
5764 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11eg', '11eg'); | |
5765 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12fed', '12fed'); | |
5766 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13eg', '13eg'); | |
5767 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14eg', '14eg'); | |
5768 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15fed', '15fed'); | |
5769 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16eg', '16eg'); | |
5770 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17eg', '17eg'); | |
5771 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18fed', '18fed'); | |
5772 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19eg', '19eg'); | |
5773 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20fed', '20fed'); | |
5774 | |
5775 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21ain', '21ain'); | |
5776 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22ain', '22ain'); | |
5777 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23ain', '23ain'); | |
5778 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24ain', '24ain'); | |
5779 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25ain', '25ain'); | |
5780 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26ain', '26ain'); | |
5781 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27ain', '27ain'); | |
5782 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28ain', '28ain'); | |
5783 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29ain', '29ain'); | |
5784 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30ain', '30ain'); | |
5785 | |
5786 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31ain', '31ain'); | |
5787 }); | |
5788 | |
5789 test('format month', function (assert) { | |
5790 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; | |
5791 for (i = 0; i < expected.length; i++) { | |
5792 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
5793 } | |
5794 }); | |
5795 | |
5796 test('format week', function (assert) { | |
5797 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; | |
5798 for (i = 0; i < expected.length; i++) { | |
5799 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
5800 } | |
5801 }); | |
5802 | |
5803 test('from', function (assert) { | |
5804 var start = moment([2007, 1, 28]); | |
5805 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ychydig eiliadau', '44 seconds = a few seconds'); | |
5806 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'munud', '45 seconds = a minute'); | |
5807 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'munud', '89 seconds = a minute'); | |
5808 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 munud', '90 seconds = 2 minutes'); | |
5809 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 munud', '44 minutes = 44 minutes'); | |
5810 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'awr', '45 minutes = an hour'); | |
5811 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'awr', '89 minutes = an hour'); | |
5812 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 awr', '90 minutes = 2 hours'); | |
5813 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 awr', '5 hours = 5 hours'); | |
5814 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 awr', '21 hours = 21 hours'); | |
5815 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'diwrnod', '22 hours = a day'); | |
5816 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'diwrnod', '35 hours = a day'); | |
5817 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 diwrnod', '36 hours = 2 days'); | |
5818 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'diwrnod', '1 day = a day'); | |
5819 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 diwrnod', '5 days = 5 days'); | |
5820 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 diwrnod', '25 days = 25 days'); | |
5821 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mis', '26 days = a month'); | |
5822 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mis', '30 days = a month'); | |
5823 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mis', '43 days = a month'); | |
5824 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mis', '46 days = 2 months'); | |
5825 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mis', '75 days = 2 months'); | |
5826 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mis', '76 days = 3 months'); | |
5827 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mis', '1 month = a month'); | |
5828 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mis', '5 months = 5 months'); | |
5829 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'blwyddyn', '345 days = a year'); | |
5830 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 flynedd', '548 days = 2 years'); | |
5831 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'blwyddyn', '1 year = a year'); | |
5832 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 flynedd', '5 years = 5 years'); | |
5833 }); | |
5834 | |
5835 test('suffix', function (assert) { | |
5836 assert.equal(moment(30000).from(0), 'mewn ychydig eiliadau', 'prefix'); | |
5837 assert.equal(moment(0).from(30000), 'ychydig eiliadau yn ôl', 'suffix'); | |
5838 }); | |
5839 | |
5840 test('fromNow', function (assert) { | |
5841 assert.equal(moment().add({s: 30}).fromNow(), 'mewn ychydig eiliadau', 'in a few seconds'); | |
5842 assert.equal(moment().add({d: 5}).fromNow(), 'mewn 5 diwrnod', 'in 5 days'); | |
5843 }); | |
5844 | |
5845 test('same day', function (assert) { | |
5846 var a = moment().hours(2).minutes(0).seconds(0); | |
5847 | |
5848 assert.equal(moment(a).calendar(), 'Heddiw am 02:00', 'today at the same time'); | |
5849 assert.equal(moment(a).add({m: 25}).calendar(), 'Heddiw am 02:25', 'Now plus 25 min'); | |
5850 assert.equal(moment(a).add({h: 1}).calendar(), 'Heddiw am 03:00', 'Now plus 1 hour'); | |
5851 assert.equal(moment(a).add({d: 1}).calendar(), 'Yfory am 02:00', 'tomorrow at the same time'); | |
5852 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Heddiw am 01:00', 'Now minus 1 hour'); | |
5853 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Ddoe am 02:00', 'yesterday at the same time'); | |
5854 }); | |
5855 | |
5856 test('same next week', function (assert) { | |
5857 var i, m; | |
5858 | |
5859 for (i = 2; i < 7; i++) { | |
5860 m = moment().add({d: i}); | |
5861 assert.equal(m.calendar(), m.format('dddd [am] LT'), 'Today + ' + i + ' days current time'); | |
5862 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
5863 assert.equal(m.calendar(), m.format('dddd [am] LT'), 'Today + ' + i + ' days beginning of day'); | |
5864 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
5865 assert.equal(m.calendar(), m.format('dddd [am] LT'), 'Today + ' + i + ' days end of day'); | |
5866 } | |
5867 }); | |
5868 | |
5869 test('same last week', function (assert) { | |
5870 var i, m; | |
5871 | |
5872 for (i = 2; i < 7; i++) { | |
5873 m = moment().subtract({d: i}); | |
5874 assert.equal(m.calendar(), m.format('dddd [diwethaf am] LT'), 'Today - ' + i + ' days current time'); | |
5875 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
5876 assert.equal(m.calendar(), m.format('dddd [diwethaf am] LT'), 'Today - ' + i + ' days beginning of day'); | |
5877 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
5878 assert.equal(m.calendar(), m.format('dddd [diwethaf am] LT'), 'Today - ' + i + ' days end of day'); | |
5879 } | |
5880 }); | |
5881 | |
5882 test('same all else', function (assert) { | |
5883 var weeksAgo = moment().subtract({w: 1}), | |
5884 weeksFromNow = moment().add({w: 1}); | |
5885 | |
5886 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
5887 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
5888 | |
5889 weeksAgo = moment().subtract({w: 2}); | |
5890 weeksFromNow = moment().add({w: 2}); | |
5891 | |
5892 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
5893 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
5894 }); | |
5895 | |
5896 test('weeks year starting sunday', function (assert) { | |
5897 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
5898 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
5899 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
5900 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
5901 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
5902 }); | |
5903 | |
5904 test('weeks year starting monday', function (assert) { | |
5905 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
5906 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
5907 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
5908 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
5909 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
5910 }); | |
5911 | |
5912 test('weeks year starting tuesday', function (assert) { | |
5913 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
5914 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
5915 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
5916 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
5917 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
5918 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
5919 }); | |
5920 | |
5921 test('weeks year starting wednesday', function (assert) { | |
5922 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
5923 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
5924 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
5925 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
5926 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
5927 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
5928 }); | |
5929 | |
5930 test('weeks year starting thursday', function (assert) { | |
5931 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
5932 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
5933 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
5934 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
5935 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
5936 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
5937 }); | |
5938 | |
5939 test('weeks year starting friday', function (assert) { | |
5940 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
5941 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
5942 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
5943 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
5944 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
5945 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
5946 }); | |
5947 | |
5948 test('weeks year starting saturday', function (assert) { | |
5949 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
5950 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
5951 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
5952 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
5953 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
5954 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
5955 }); | |
5956 | |
5957 test('weeks year starting sunday formatted', function (assert) { | |
5958 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52ain', 'Jan 1 2012 should be week 52'); | |
5959 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1af', 'Jan 2 2012 should be week 1'); | |
5960 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1af', 'Jan 8 2012 should be week 1'); | |
5961 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2il', 'Jan 9 2012 should be week 2'); | |
5962 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2il', 'Jan 15 2012 should be week 2'); | |
5963 }); | |
5964 | |
5965 test('lenient ordinal parsing', function (assert) { | |
5966 var i, ordinalStr, testMoment; | |
5967 for (i = 1; i <= 31; ++i) { | |
5968 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
5969 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
5970 assert.equal(testMoment.year(), 2014, | |
5971 'lenient ordinal parsing ' + i + ' year check'); | |
5972 assert.equal(testMoment.month(), 0, | |
5973 'lenient ordinal parsing ' + i + ' month check'); | |
5974 assert.equal(testMoment.date(), i, | |
5975 'lenient ordinal parsing ' + i + ' date check'); | |
5976 } | |
5977 }); | |
5978 | |
5979 test('lenient ordinal parsing of number', function (assert) { | |
5980 var i, testMoment; | |
5981 for (i = 1; i <= 31; ++i) { | |
5982 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
5983 assert.equal(testMoment.year(), 2014, | |
5984 'lenient ordinal parsing of number ' + i + ' year check'); | |
5985 assert.equal(testMoment.month(), 0, | |
5986 'lenient ordinal parsing of number ' + i + ' month check'); | |
5987 assert.equal(testMoment.date(), i, | |
5988 'lenient ordinal parsing of number ' + i + ' date check'); | |
5989 } | |
5990 }); | |
5991 | |
5992 test('strict ordinal parsing', function (assert) { | |
5993 var i, ordinalStr, testMoment; | |
5994 for (i = 1; i <= 31; ++i) { | |
5995 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
5996 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
5997 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
5998 } | |
5999 }); | |
6000 | |
6001 })); | |
6002 | |
6003 (function (global, factory) { | |
6004 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
6005 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
6006 factory(global.moment) | |
6007 }(this, function (moment) { 'use strict'; | |
6008 | |
6009 /*global QUnit:false*/ | |
6010 | |
6011 var test = QUnit.test; | |
6012 | |
6013 function module (name, lifecycle) { | |
6014 QUnit.module(name, { | |
6015 setup : function () { | |
6016 moment.locale('en'); | |
6017 moment.createFromInputFallback = function () { | |
6018 throw new Error('input not handled by moment'); | |
6019 }; | |
6020 if (lifecycle && lifecycle.setup) { | |
6021 lifecycle.setup(); | |
6022 } | |
6023 }, | |
6024 teardown : function () { | |
6025 if (lifecycle && lifecycle.teardown) { | |
6026 lifecycle.teardown(); | |
6027 } | |
6028 } | |
6029 }); | |
6030 } | |
6031 | |
6032 function localeModule (name, lifecycle) { | |
6033 QUnit.module('locale:' + name, { | |
6034 setup : function () { | |
6035 moment.locale(name); | |
6036 moment.createFromInputFallback = function () { | |
6037 throw new Error('input not handled by moment'); | |
6038 }; | |
6039 if (lifecycle && lifecycle.setup) { | |
6040 lifecycle.setup(); | |
6041 } | |
6042 }, | |
6043 teardown : function () { | |
6044 moment.locale('en'); | |
6045 if (lifecycle && lifecycle.teardown) { | |
6046 lifecycle.teardown(); | |
6047 } | |
6048 } | |
6049 }); | |
6050 } | |
6051 | |
6052 localeModule('da'); | |
6053 | |
6054 test('parse', function (assert) { | |
6055 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; | |
6056 function equalTest(input, mmm, i) { | |
6057 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
6058 } | |
6059 for (i = 0; i < 12; i++) { | |
6060 tests[i] = tests[i].split(' '); | |
6061 equalTest(tests[i][0], 'MMM', i); | |
6062 equalTest(tests[i][1], 'MMM', i); | |
6063 equalTest(tests[i][0], 'MMMM', i); | |
6064 equalTest(tests[i][1], 'MMMM', i); | |
6065 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
6066 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
6067 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
6068 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
6069 } | |
6070 }); | |
6071 | |
6072 test('format', function (assert) { | |
6073 var a = [ | |
6074 ['dddd [den] Do MMMM YYYY, h:mm:ss a', 'søndag den 14. februar 2010, 3:25:50 pm'], | |
6075 ['ddd hA', 'søn 3PM'], | |
6076 ['M Mo MM MMMM MMM', '2 2. 02 februar feb'], | |
6077 ['YYYY YY', '2010 10'], | |
6078 ['D Do DD', '14 14. 14'], | |
6079 ['d do dddd ddd dd', '0 0. søndag søn sø'], | |
6080 ['DDD DDDo DDDD', '45 45. 045'], | |
6081 ['w wo ww', '6 6. 06'], | |
6082 ['h hh', '3 03'], | |
6083 ['H HH', '15 15'], | |
6084 ['m mm', '25 25'], | |
6085 ['s ss', '50 50'], | |
6086 ['a A', 'pm PM'], | |
6087 ['[den] DDDo [dag på året]', 'den 45. dag på året'], | |
6088 ['LTS', '15:25:50'], | |
6089 ['L', '14/02/2010'], | |
6090 ['LL', '14. februar 2010'], | |
6091 ['LLL', '14. februar 2010 15:25'], | |
6092 ['LLLL', 'søndag d. 14. februar 2010 15:25'], | |
6093 ['l', '14/2/2010'], | |
6094 ['ll', '14. feb 2010'], | |
6095 ['lll', '14. feb 2010 15:25'], | |
6096 ['llll', 'søn d. 14. feb 2010 15:25'] | |
6097 ], | |
6098 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
6099 i; | |
6100 for (i = 0; i < a.length; i++) { | |
6101 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
6102 } | |
6103 }); | |
6104 | |
6105 test('format ordinal', function (assert) { | |
6106 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.'); | |
6107 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.'); | |
6108 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.'); | |
6109 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.'); | |
6110 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.'); | |
6111 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.'); | |
6112 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.'); | |
6113 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.'); | |
6114 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.'); | |
6115 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.'); | |
6116 | |
6117 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.'); | |
6118 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.'); | |
6119 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.'); | |
6120 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.'); | |
6121 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.'); | |
6122 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.'); | |
6123 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.'); | |
6124 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.'); | |
6125 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.'); | |
6126 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.'); | |
6127 | |
6128 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.'); | |
6129 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.'); | |
6130 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.'); | |
6131 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.'); | |
6132 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.'); | |
6133 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.'); | |
6134 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.'); | |
6135 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.'); | |
6136 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.'); | |
6137 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.'); | |
6138 | |
6139 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.'); | |
6140 }); | |
6141 | |
6142 test('format month', function (assert) { | |
6143 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; | |
6144 for (i = 0; i < expected.length; i++) { | |
6145 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
6146 } | |
6147 }); | |
6148 | |
6149 test('format week', function (assert) { | |
6150 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; | |
6151 for (i = 0; i < expected.length; i++) { | |
6152 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
6153 } | |
6154 }); | |
6155 | |
6156 test('from', function (assert) { | |
6157 var start = moment([2007, 1, 28]); | |
6158 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'få sekunder', '44 seconds = a few seconds'); | |
6159 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'et minut', '45 seconds = a minute'); | |
6160 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'et minut', '89 seconds = a minute'); | |
6161 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutter', '90 seconds = 2 minutes'); | |
6162 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutter', '44 minutes = 44 minutes'); | |
6163 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'en time', '45 minutes = an hour'); | |
6164 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'en time', '89 minutes = an hour'); | |
6165 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 timer', '90 minutes = 2 hours'); | |
6166 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 timer', '5 hours = 5 hours'); | |
6167 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 timer', '21 hours = 21 hours'); | |
6168 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'en dag', '22 hours = a day'); | |
6169 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'en dag', '35 hours = a day'); | |
6170 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dage', '36 hours = 2 days'); | |
6171 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'en dag', '1 day = a day'); | |
6172 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dage', '5 days = 5 days'); | |
6173 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dage', '25 days = 25 days'); | |
6174 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'en måned', '26 days = a month'); | |
6175 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'en måned', '30 days = a month'); | |
6176 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'en måned', '43 days = a month'); | |
6177 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 måneder', '46 days = 2 months'); | |
6178 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 måneder', '75 days = 2 months'); | |
6179 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 måneder', '76 days = 3 months'); | |
6180 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'en måned', '1 month = a month'); | |
6181 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 måneder', '5 months = 5 months'); | |
6182 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'et år', '345 days = a year'); | |
6183 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 år', '548 days = 2 years'); | |
6184 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'et år', '1 year = a year'); | |
6185 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 år', '5 years = 5 years'); | |
6186 }); | |
6187 | |
6188 test('suffix', function (assert) { | |
6189 assert.equal(moment(30000).from(0), 'om få sekunder', 'prefix'); | |
6190 assert.equal(moment(0).from(30000), 'få sekunder siden', 'suffix'); | |
6191 }); | |
6192 | |
6193 test('now from now', function (assert) { | |
6194 assert.equal(moment().fromNow(), 'få sekunder siden', 'now from now should display as in the past'); | |
6195 }); | |
6196 | |
6197 test('fromNow', function (assert) { | |
6198 assert.equal(moment().add({s: 30}).fromNow(), 'om få sekunder', 'in a few seconds'); | |
6199 assert.equal(moment().add({d: 5}).fromNow(), 'om 5 dage', 'in 5 days'); | |
6200 }); | |
6201 | |
6202 test('weeks year starting sunday', function (assert) { | |
6203 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
6204 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
6205 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
6206 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
6207 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
6208 }); | |
6209 | |
6210 test('weeks year starting monday', function (assert) { | |
6211 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
6212 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
6213 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
6214 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
6215 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
6216 }); | |
6217 | |
6218 test('weeks year starting tuesday', function (assert) { | |
6219 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
6220 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
6221 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
6222 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
6223 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
6224 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
6225 }); | |
6226 | |
6227 test('weeks year starting wednesday', function (assert) { | |
6228 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
6229 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
6230 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
6231 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
6232 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
6233 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
6234 }); | |
6235 | |
6236 test('weeks year starting thursday', function (assert) { | |
6237 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
6238 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
6239 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
6240 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
6241 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
6242 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
6243 }); | |
6244 | |
6245 test('weeks year starting friday', function (assert) { | |
6246 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
6247 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
6248 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
6249 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
6250 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
6251 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
6252 }); | |
6253 | |
6254 test('weeks year starting saturday', function (assert) { | |
6255 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
6256 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
6257 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
6258 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
6259 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
6260 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
6261 }); | |
6262 | |
6263 test('weeks year starting sunday formatted', function (assert) { | |
6264 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52'); | |
6265 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1'); | |
6266 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1'); | |
6267 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2'); | |
6268 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2'); | |
6269 }); | |
6270 | |
6271 test('lenient ordinal parsing', function (assert) { | |
6272 var i, ordinalStr, testMoment; | |
6273 for (i = 1; i <= 31; ++i) { | |
6274 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
6275 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
6276 assert.equal(testMoment.year(), 2014, | |
6277 'lenient ordinal parsing ' + i + ' year check'); | |
6278 assert.equal(testMoment.month(), 0, | |
6279 'lenient ordinal parsing ' + i + ' month check'); | |
6280 assert.equal(testMoment.date(), i, | |
6281 'lenient ordinal parsing ' + i + ' date check'); | |
6282 } | |
6283 }); | |
6284 | |
6285 test('lenient ordinal parsing of number', function (assert) { | |
6286 var i, testMoment; | |
6287 for (i = 1; i <= 31; ++i) { | |
6288 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
6289 assert.equal(testMoment.year(), 2014, | |
6290 'lenient ordinal parsing of number ' + i + ' year check'); | |
6291 assert.equal(testMoment.month(), 0, | |
6292 'lenient ordinal parsing of number ' + i + ' month check'); | |
6293 assert.equal(testMoment.date(), i, | |
6294 'lenient ordinal parsing of number ' + i + ' date check'); | |
6295 } | |
6296 }); | |
6297 | |
6298 test('strict ordinal parsing', function (assert) { | |
6299 var i, ordinalStr, testMoment; | |
6300 for (i = 1; i <= 31; ++i) { | |
6301 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
6302 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
6303 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
6304 } | |
6305 }); | |
6306 | |
6307 })); | |
6308 | |
6309 (function (global, factory) { | |
6310 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
6311 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
6312 factory(global.moment) | |
6313 }(this, function (moment) { 'use strict'; | |
6314 | |
6315 /*global QUnit:false*/ | |
6316 | |
6317 var test = QUnit.test; | |
6318 | |
6319 function module (name, lifecycle) { | |
6320 QUnit.module(name, { | |
6321 setup : function () { | |
6322 moment.locale('en'); | |
6323 moment.createFromInputFallback = function () { | |
6324 throw new Error('input not handled by moment'); | |
6325 }; | |
6326 if (lifecycle && lifecycle.setup) { | |
6327 lifecycle.setup(); | |
6328 } | |
6329 }, | |
6330 teardown : function () { | |
6331 if (lifecycle && lifecycle.teardown) { | |
6332 lifecycle.teardown(); | |
6333 } | |
6334 } | |
6335 }); | |
6336 } | |
6337 | |
6338 function localeModule (name, lifecycle) { | |
6339 QUnit.module('locale:' + name, { | |
6340 setup : function () { | |
6341 moment.locale(name); | |
6342 moment.createFromInputFallback = function () { | |
6343 throw new Error('input not handled by moment'); | |
6344 }; | |
6345 if (lifecycle && lifecycle.setup) { | |
6346 lifecycle.setup(); | |
6347 } | |
6348 }, | |
6349 teardown : function () { | |
6350 moment.locale('en'); | |
6351 if (lifecycle && lifecycle.teardown) { | |
6352 lifecycle.teardown(); | |
6353 } | |
6354 } | |
6355 }); | |
6356 } | |
6357 | |
6358 localeModule('de-at'); | |
6359 | |
6360 test('parse', function (assert) { | |
6361 var tests = 'Jänner Jän._Februar Febr._März Mrz._April Apr._Mai Mai_Juni Jun._Juli Jul._August Aug._September Sept._Oktober Okt._November Nov._Dezember Dez.'.split('_'), i; | |
6362 | |
6363 function equalTest(input, mmm, i) { | |
6364 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
6365 } | |
6366 | |
6367 for (i = 0; i < 12; i++) { | |
6368 tests[i] = tests[i].split(' '); | |
6369 equalTest(tests[i][0], 'MMM', i); | |
6370 equalTest(tests[i][1], 'MMM', i); | |
6371 equalTest(tests[i][0], 'MMMM', i); | |
6372 equalTest(tests[i][1], 'MMMM', i); | |
6373 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
6374 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
6375 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
6376 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
6377 } | |
6378 }); | |
6379 | |
6380 test('format', function (assert) { | |
6381 var a = [ | |
6382 ['dddd, Do MMMM YYYY, h:mm:ss a', 'Sonntag, 14. Februar 2010, 3:25:50 pm'], | |
6383 ['ddd, hA', 'So., 3PM'], | |
6384 ['M Mo MM MMMM MMM', '2 2. 02 Februar Febr.'], | |
6385 ['YYYY YY', '2010 10'], | |
6386 ['D Do DD', '14 14. 14'], | |
6387 ['d do dddd ddd dd', '0 0. Sonntag So. So'], | |
6388 ['DDD DDDo DDDD', '45 45. 045'], | |
6389 ['w wo ww', '6 6. 06'], | |
6390 ['h hh', '3 03'], | |
6391 ['H HH', '15 15'], | |
6392 ['m mm', '25 25'], | |
6393 ['s ss', '50 50'], | |
6394 ['a A', 'pm PM'], | |
6395 ['[the] DDDo [day of the year]', 'the 45. day of the year'], | |
6396 ['LTS', '15:25:50'], | |
6397 ['L', '14.02.2010'], | |
6398 ['LL', '14. Februar 2010'], | |
6399 ['LLL', '14. Februar 2010 15:25'], | |
6400 ['LLLL', 'Sonntag, 14. Februar 2010 15:25'], | |
6401 ['l', '14.2.2010'], | |
6402 ['ll', '14. Febr. 2010'], | |
6403 ['lll', '14. Febr. 2010 15:25'], | |
6404 ['llll', 'So., 14. Febr. 2010 15:25'] | |
6405 ], | |
6406 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
6407 i; | |
6408 for (i = 0; i < a.length; i++) { | |
6409 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
6410 } | |
6411 }); | |
6412 | |
6413 test('format ordinal', function (assert) { | |
6414 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.'); | |
6415 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.'); | |
6416 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.'); | |
6417 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.'); | |
6418 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.'); | |
6419 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.'); | |
6420 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.'); | |
6421 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.'); | |
6422 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.'); | |
6423 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.'); | |
6424 | |
6425 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.'); | |
6426 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.'); | |
6427 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.'); | |
6428 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.'); | |
6429 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.'); | |
6430 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.'); | |
6431 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.'); | |
6432 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.'); | |
6433 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.'); | |
6434 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.'); | |
6435 | |
6436 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.'); | |
6437 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.'); | |
6438 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.'); | |
6439 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.'); | |
6440 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.'); | |
6441 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.'); | |
6442 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.'); | |
6443 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.'); | |
6444 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.'); | |
6445 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.'); | |
6446 | |
6447 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.'); | |
6448 }); | |
6449 | |
6450 test('format month', function (assert) { | |
6451 var expected = 'Jänner Jän._Februar Febr._März Mrz._April Apr._Mai Mai_Juni Jun._Juli Jul._August Aug._September Sept._Oktober Okt._November Nov._Dezember Dez.'.split('_'), i; | |
6452 for (i = 0; i < expected.length; i++) { | |
6453 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
6454 } | |
6455 }); | |
6456 | |
6457 test('format week', function (assert) { | |
6458 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; | |
6459 for (i = 0; i < expected.length; i++) { | |
6460 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
6461 } | |
6462 }); | |
6463 | |
6464 test('from', function (assert) { | |
6465 var start = moment([2007, 1, 28]); | |
6466 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ein paar Sekunden', '44 seconds = a few seconds'); | |
6467 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'eine Minute', '45 seconds = a minute'); | |
6468 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'eine Minute', '89 seconds = a minute'); | |
6469 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 Minuten', '90 seconds = 2 minutes'); | |
6470 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 Minuten', '44 minutes = 44 minutes'); | |
6471 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'eine Stunde', '45 minutes = an hour'); | |
6472 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'eine Stunde', '89 minutes = an hour'); | |
6473 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 Stunden', '90 minutes = 2 hours'); | |
6474 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 Stunden', '5 hours = 5 hours'); | |
6475 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 Stunden', '21 hours = 21 hours'); | |
6476 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ein Tag', '22 hours = a day'); | |
6477 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ein Tag', '35 hours = a day'); | |
6478 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 Tage', '36 hours = 2 days'); | |
6479 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ein Tag', '1 day = a day'); | |
6480 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 Tage', '5 days = 5 days'); | |
6481 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 Tage', '25 days = 25 days'); | |
6482 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ein Monat', '26 days = a month'); | |
6483 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ein Monat', '30 days = a month'); | |
6484 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 Monate', '46 days = 2 months'); | |
6485 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 Monate', '75 days = 2 months'); | |
6486 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 Monate', '76 days = 3 months'); | |
6487 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ein Monat', '1 month = a month'); | |
6488 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 Monate', '5 months = 5 months'); | |
6489 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ein Jahr', '345 days = a year'); | |
6490 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 Jahre', '548 days = 2 years'); | |
6491 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ein Jahr', '1 year = a year'); | |
6492 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 Jahre', '5 years = 5 years'); | |
6493 }); | |
6494 | |
6495 test('suffix', function (assert) { | |
6496 assert.equal(moment(30000).from(0), 'in ein paar Sekunden', 'prefix'); | |
6497 assert.equal(moment(0).from(30000), 'vor ein paar Sekunden', 'suffix'); | |
6498 }); | |
6499 | |
6500 test('fromNow', function (assert) { | |
6501 assert.equal(moment().add({s: 30}).fromNow(), 'in ein paar Sekunden', 'in a few seconds'); | |
6502 assert.equal(moment().add({d: 5}).fromNow(), 'in 5 Tagen', 'in 5 days'); | |
6503 }); | |
6504 | |
6505 test('calendar day', function (assert) { | |
6506 var a = moment().hours(2).minutes(0).seconds(0); | |
6507 | |
6508 assert.equal(moment(a).calendar(), 'Heute um 02:00 Uhr', 'today at the same time'); | |
6509 assert.equal(moment(a).add({m: 25}).calendar(), 'Heute um 02:25 Uhr', 'Now plus 25 min'); | |
6510 assert.equal(moment(a).add({h: 1}).calendar(), 'Heute um 03:00 Uhr', 'Now plus 1 hour'); | |
6511 assert.equal(moment(a).add({d: 1}).calendar(), 'Morgen um 02:00 Uhr', 'tomorrow at the same time'); | |
6512 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Heute um 01:00 Uhr', 'Now minus 1 hour'); | |
6513 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Gestern um 02:00 Uhr', 'yesterday at the same time'); | |
6514 }); | |
6515 | |
6516 test('calendar next week', function (assert) { | |
6517 var i, m; | |
6518 for (i = 2; i < 7; i++) { | |
6519 m = moment().add({d: i}); | |
6520 assert.equal(m.calendar(), m.format('dddd [um] LT [Uhr]'), 'Today + ' + i + ' days current time'); | |
6521 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
6522 assert.equal(m.calendar(), m.format('dddd [um] LT [Uhr]'), 'Today + ' + i + ' days beginning of day'); | |
6523 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
6524 assert.equal(m.calendar(), m.format('dddd [um] LT [Uhr]'), 'Today + ' + i + ' days end of day'); | |
6525 } | |
6526 }); | |
6527 | |
6528 test('calendar last week', function (assert) { | |
6529 var i, m; | |
6530 for (i = 2; i < 7; i++) { | |
6531 m = moment().subtract({d: i}); | |
6532 assert.equal(m.calendar(), m.format('[letzten] dddd [um] LT [Uhr]'), 'Today + ' + i + ' days current time'); | |
6533 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
6534 assert.equal(m.calendar(), m.format('[letzten] dddd [um] LT [Uhr]'), 'Today + ' + i + ' days beginning of day'); | |
6535 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
6536 assert.equal(m.calendar(), m.format('[letzten] dddd [um] LT [Uhr]'), 'Today + ' + i + ' days end of day'); | |
6537 } | |
6538 }); | |
6539 | |
6540 test('calendar all else', function (assert) { | |
6541 var weeksAgo = moment().subtract({w: 1}), | |
6542 weeksFromNow = moment().add({w: 1}); | |
6543 | |
6544 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
6545 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
6546 | |
6547 weeksAgo = moment().subtract({w: 2}); | |
6548 weeksFromNow = moment().add({w: 2}); | |
6549 | |
6550 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
6551 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
6552 }); | |
6553 | |
6554 test('weeks year starting sunday', function (assert) { | |
6555 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
6556 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
6557 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
6558 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
6559 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
6560 }); | |
6561 | |
6562 test('weeks year starting monday', function (assert) { | |
6563 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
6564 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
6565 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
6566 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
6567 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
6568 }); | |
6569 | |
6570 test('weeks year starting tuesday', function (assert) { | |
6571 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
6572 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
6573 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
6574 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
6575 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
6576 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
6577 }); | |
6578 | |
6579 test('weeks year starting wednesday', function (assert) { | |
6580 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
6581 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
6582 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
6583 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
6584 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
6585 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
6586 }); | |
6587 | |
6588 test('weeks year starting thursday', function (assert) { | |
6589 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
6590 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
6591 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
6592 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
6593 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
6594 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
6595 }); | |
6596 | |
6597 test('weeks year starting friday', function (assert) { | |
6598 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
6599 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
6600 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
6601 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
6602 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
6603 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
6604 }); | |
6605 | |
6606 test('weeks year starting saturday', function (assert) { | |
6607 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
6608 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
6609 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
6610 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
6611 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
6612 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
6613 }); | |
6614 | |
6615 test('weeks year starting sunday formatted', function (assert) { | |
6616 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52'); | |
6617 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1'); | |
6618 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1'); | |
6619 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2'); | |
6620 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2'); | |
6621 }); | |
6622 | |
6623 test('lenient ordinal parsing', function (assert) { | |
6624 var i, ordinalStr, testMoment; | |
6625 for (i = 1; i <= 31; ++i) { | |
6626 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
6627 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
6628 assert.equal(testMoment.year(), 2014, | |
6629 'lenient ordinal parsing ' + i + ' year check'); | |
6630 assert.equal(testMoment.month(), 0, | |
6631 'lenient ordinal parsing ' + i + ' month check'); | |
6632 assert.equal(testMoment.date(), i, | |
6633 'lenient ordinal parsing ' + i + ' date check'); | |
6634 } | |
6635 }); | |
6636 | |
6637 test('lenient ordinal parsing of number', function (assert) { | |
6638 var i, testMoment; | |
6639 for (i = 1; i <= 31; ++i) { | |
6640 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
6641 assert.equal(testMoment.year(), 2014, | |
6642 'lenient ordinal parsing of number ' + i + ' year check'); | |
6643 assert.equal(testMoment.month(), 0, | |
6644 'lenient ordinal parsing of number ' + i + ' month check'); | |
6645 assert.equal(testMoment.date(), i, | |
6646 'lenient ordinal parsing of number ' + i + ' date check'); | |
6647 } | |
6648 }); | |
6649 | |
6650 test('strict ordinal parsing', function (assert) { | |
6651 var i, ordinalStr, testMoment; | |
6652 for (i = 1; i <= 31; ++i) { | |
6653 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
6654 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
6655 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
6656 } | |
6657 }); | |
6658 | |
6659 })); | |
6660 | |
6661 (function (global, factory) { | |
6662 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
6663 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
6664 factory(global.moment) | |
6665 }(this, function (moment) { 'use strict'; | |
6666 | |
6667 /*global QUnit:false*/ | |
6668 | |
6669 var test = QUnit.test; | |
6670 | |
6671 function module (name, lifecycle) { | |
6672 QUnit.module(name, { | |
6673 setup : function () { | |
6674 moment.locale('en'); | |
6675 moment.createFromInputFallback = function () { | |
6676 throw new Error('input not handled by moment'); | |
6677 }; | |
6678 if (lifecycle && lifecycle.setup) { | |
6679 lifecycle.setup(); | |
6680 } | |
6681 }, | |
6682 teardown : function () { | |
6683 if (lifecycle && lifecycle.teardown) { | |
6684 lifecycle.teardown(); | |
6685 } | |
6686 } | |
6687 }); | |
6688 } | |
6689 | |
6690 function localeModule (name, lifecycle) { | |
6691 QUnit.module('locale:' + name, { | |
6692 setup : function () { | |
6693 moment.locale(name); | |
6694 moment.createFromInputFallback = function () { | |
6695 throw new Error('input not handled by moment'); | |
6696 }; | |
6697 if (lifecycle && lifecycle.setup) { | |
6698 lifecycle.setup(); | |
6699 } | |
6700 }, | |
6701 teardown : function () { | |
6702 moment.locale('en'); | |
6703 if (lifecycle && lifecycle.teardown) { | |
6704 lifecycle.teardown(); | |
6705 } | |
6706 } | |
6707 }); | |
6708 } | |
6709 | |
6710 localeModule('de'); | |
6711 | |
6712 test('parse', function (assert) { | |
6713 var tests = 'Januar Jan._Februar Febr._März Mrz._April Apr._Mai Mai_Juni Jun._Juli Jul._August Aug._September Sept._Oktober Okt._November Nov._Dezember Dez.'.split('_'), i; | |
6714 function equalTest(input, mmm, i) { | |
6715 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
6716 } | |
6717 for (i = 0; i < 12; i++) { | |
6718 tests[i] = tests[i].split(' '); | |
6719 equalTest(tests[i][0], 'MMM', i); | |
6720 equalTest(tests[i][1], 'MMM', i); | |
6721 equalTest(tests[i][0], 'MMMM', i); | |
6722 equalTest(tests[i][1], 'MMMM', i); | |
6723 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
6724 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
6725 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
6726 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
6727 } | |
6728 }); | |
6729 | |
6730 test('format', function (assert) { | |
6731 var a = [ | |
6732 ['dddd, Do MMMM YYYY, h:mm:ss a', 'Sonntag, 14. Februar 2010, 3:25:50 pm'], | |
6733 ['ddd, hA', 'So., 3PM'], | |
6734 ['M Mo MM MMMM MMM', '2 2. 02 Februar Febr.'], | |
6735 ['YYYY YY', '2010 10'], | |
6736 ['D Do DD', '14 14. 14'], | |
6737 ['d do dddd ddd dd', '0 0. Sonntag So. So'], | |
6738 ['DDD DDDo DDDD', '45 45. 045'], | |
6739 ['w wo ww', '6 6. 06'], | |
6740 ['h hh', '3 03'], | |
6741 ['H HH', '15 15'], | |
6742 ['m mm', '25 25'], | |
6743 ['s ss', '50 50'], | |
6744 ['a A', 'pm PM'], | |
6745 ['[the] DDDo [day of the year]', 'the 45. day of the year'], | |
6746 ['LTS', '15:25:50'], | |
6747 ['L', '14.02.2010'], | |
6748 ['LL', '14. Februar 2010'], | |
6749 ['LLL', '14. Februar 2010 15:25'], | |
6750 ['LLLL', 'Sonntag, 14. Februar 2010 15:25'], | |
6751 ['l', '14.2.2010'], | |
6752 ['ll', '14. Febr. 2010'], | |
6753 ['lll', '14. Febr. 2010 15:25'], | |
6754 ['llll', 'So., 14. Febr. 2010 15:25'] | |
6755 ], | |
6756 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
6757 i; | |
6758 for (i = 0; i < a.length; i++) { | |
6759 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
6760 } | |
6761 }); | |
6762 | |
6763 test('format ordinal', function (assert) { | |
6764 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.'); | |
6765 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.'); | |
6766 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.'); | |
6767 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.'); | |
6768 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.'); | |
6769 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.'); | |
6770 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.'); | |
6771 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.'); | |
6772 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.'); | |
6773 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.'); | |
6774 | |
6775 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.'); | |
6776 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.'); | |
6777 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.'); | |
6778 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.'); | |
6779 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.'); | |
6780 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.'); | |
6781 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.'); | |
6782 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.'); | |
6783 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.'); | |
6784 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.'); | |
6785 | |
6786 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.'); | |
6787 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.'); | |
6788 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.'); | |
6789 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.'); | |
6790 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.'); | |
6791 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.'); | |
6792 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.'); | |
6793 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.'); | |
6794 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.'); | |
6795 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.'); | |
6796 | |
6797 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.'); | |
6798 }); | |
6799 | |
6800 test('format month', function (assert) { | |
6801 var expected = 'Januar Jan._Februar Febr._März Mrz._April Apr._Mai Mai_Juni Jun._Juli Jul._August Aug._September Sept._Oktober Okt._November Nov._Dezember Dez.'.split('_'), i; | |
6802 for (i = 0; i < expected.length; i++) { | |
6803 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
6804 } | |
6805 }); | |
6806 | |
6807 test('format week', function (assert) { | |
6808 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; | |
6809 for (i = 0; i < expected.length; i++) { | |
6810 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
6811 } | |
6812 }); | |
6813 | |
6814 test('from', function (assert) { | |
6815 var start = moment([2007, 1, 28]); | |
6816 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ein paar Sekunden', '44 seconds = a few seconds'); | |
6817 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'eine Minute', '45 seconds = a minute'); | |
6818 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'eine Minute', '89 seconds = a minute'); | |
6819 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 Minuten', '90 seconds = 2 minutes'); | |
6820 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 Minuten', '44 minutes = 44 minutes'); | |
6821 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'eine Stunde', '45 minutes = an hour'); | |
6822 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'eine Stunde', '89 minutes = an hour'); | |
6823 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 Stunden', '90 minutes = 2 hours'); | |
6824 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 Stunden', '5 hours = 5 hours'); | |
6825 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 Stunden', '21 hours = 21 hours'); | |
6826 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ein Tag', '22 hours = a day'); | |
6827 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ein Tag', '35 hours = a day'); | |
6828 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 Tage', '36 hours = 2 days'); | |
6829 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ein Tag', '1 day = a day'); | |
6830 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 Tage', '5 days = 5 days'); | |
6831 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 Tage', '25 days = 25 days'); | |
6832 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ein Monat', '26 days = a month'); | |
6833 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ein Monat', '30 days = a month'); | |
6834 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ein Monat', '43 days = a month'); | |
6835 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 Monate', '46 days = 2 months'); | |
6836 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 Monate', '75 days = 2 months'); | |
6837 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 Monate', '76 days = 3 months'); | |
6838 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ein Monat', '1 month = a month'); | |
6839 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 Monate', '5 months = 5 months'); | |
6840 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ein Jahr', '345 days = a year'); | |
6841 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 Jahre', '548 days = 2 years'); | |
6842 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ein Jahr', '1 year = a year'); | |
6843 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 Jahre', '5 years = 5 years'); | |
6844 }); | |
6845 | |
6846 test('suffix', function (assert) { | |
6847 assert.equal(moment(30000).from(0), 'in ein paar Sekunden', 'prefix'); | |
6848 assert.equal(moment(0).from(30000), 'vor ein paar Sekunden', 'suffix'); | |
6849 }); | |
6850 | |
6851 test('fromNow', function (assert) { | |
6852 assert.equal(moment().add({s: 30}).fromNow(), 'in ein paar Sekunden', 'in a few seconds'); | |
6853 assert.equal(moment().add({d: 5}).fromNow(), 'in 5 Tagen', 'in 5 days'); | |
6854 }); | |
6855 | |
6856 test('calendar day', function (assert) { | |
6857 var a = moment().hours(2).minutes(0).seconds(0); | |
6858 | |
6859 assert.equal(moment(a).calendar(), 'Heute um 02:00 Uhr', 'today at the same time'); | |
6860 assert.equal(moment(a).add({m: 25}).calendar(), 'Heute um 02:25 Uhr', 'Now plus 25 min'); | |
6861 assert.equal(moment(a).add({h: 1}).calendar(), 'Heute um 03:00 Uhr', 'Now plus 1 hour'); | |
6862 assert.equal(moment(a).add({d: 1}).calendar(), 'Morgen um 02:00 Uhr', 'tomorrow at the same time'); | |
6863 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Heute um 01:00 Uhr', 'Now minus 1 hour'); | |
6864 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Gestern um 02:00 Uhr', 'yesterday at the same time'); | |
6865 }); | |
6866 | |
6867 test('calendar next week', function (assert) { | |
6868 var i, m; | |
6869 for (i = 2; i < 7; i++) { | |
6870 m = moment().add({d: i}); | |
6871 assert.equal(m.calendar(), m.format('dddd [um] LT [Uhr]'), 'Today + ' + i + ' days current time'); | |
6872 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
6873 assert.equal(m.calendar(), m.format('dddd [um] LT [Uhr]'), 'Today + ' + i + ' days beginning of day'); | |
6874 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
6875 assert.equal(m.calendar(), m.format('dddd [um] LT [Uhr]'), 'Today + ' + i + ' days end of day'); | |
6876 } | |
6877 }); | |
6878 | |
6879 test('calendar last week', function (assert) { | |
6880 var i, m; | |
6881 for (i = 2; i < 7; i++) { | |
6882 m = moment().subtract({d: i}); | |
6883 assert.equal(m.calendar(), m.format('[letzten] dddd [um] LT [Uhr]'), 'Today + ' + i + ' days current time'); | |
6884 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
6885 assert.equal(m.calendar(), m.format('[letzten] dddd [um] LT [Uhr]'), 'Today + ' + i + ' days beginning of day'); | |
6886 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
6887 assert.equal(m.calendar(), m.format('[letzten] dddd [um] LT [Uhr]'), 'Today + ' + i + ' days end of day'); | |
6888 } | |
6889 }); | |
6890 | |
6891 test('calendar all else', function (assert) { | |
6892 var weeksAgo = moment().subtract({w: 1}), | |
6893 weeksFromNow = moment().add({w: 1}); | |
6894 | |
6895 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
6896 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
6897 | |
6898 weeksAgo = moment().subtract({w: 2}); | |
6899 weeksFromNow = moment().add({w: 2}); | |
6900 | |
6901 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
6902 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
6903 }); | |
6904 | |
6905 test('weeks year starting sunday', function (assert) { | |
6906 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
6907 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
6908 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
6909 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
6910 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
6911 }); | |
6912 | |
6913 test('weeks year starting monday', function (assert) { | |
6914 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
6915 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
6916 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
6917 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
6918 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
6919 }); | |
6920 | |
6921 test('weeks year starting tuesday', function (assert) { | |
6922 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
6923 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
6924 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
6925 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
6926 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
6927 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
6928 }); | |
6929 | |
6930 test('weeks year starting wednesday', function (assert) { | |
6931 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
6932 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
6933 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
6934 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
6935 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
6936 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
6937 }); | |
6938 | |
6939 test('weeks year starting thursday', function (assert) { | |
6940 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
6941 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
6942 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
6943 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
6944 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
6945 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
6946 }); | |
6947 | |
6948 test('weeks year starting friday', function (assert) { | |
6949 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
6950 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
6951 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
6952 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
6953 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
6954 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
6955 }); | |
6956 | |
6957 test('weeks year starting saturday', function (assert) { | |
6958 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
6959 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
6960 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
6961 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
6962 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
6963 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
6964 }); | |
6965 | |
6966 test('weeks year starting sunday formatted', function (assert) { | |
6967 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52'); | |
6968 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1'); | |
6969 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1'); | |
6970 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2'); | |
6971 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2'); | |
6972 }); | |
6973 | |
6974 test('lenient ordinal parsing', function (assert) { | |
6975 var i, ordinalStr, testMoment; | |
6976 for (i = 1; i <= 31; ++i) { | |
6977 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
6978 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
6979 assert.equal(testMoment.year(), 2014, | |
6980 'lenient ordinal parsing ' + i + ' year check'); | |
6981 assert.equal(testMoment.month(), 0, | |
6982 'lenient ordinal parsing ' + i + ' month check'); | |
6983 assert.equal(testMoment.date(), i, | |
6984 'lenient ordinal parsing ' + i + ' date check'); | |
6985 } | |
6986 }); | |
6987 | |
6988 test('lenient ordinal parsing of number', function (assert) { | |
6989 var i, testMoment; | |
6990 for (i = 1; i <= 31; ++i) { | |
6991 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
6992 assert.equal(testMoment.year(), 2014, | |
6993 'lenient ordinal parsing of number ' + i + ' year check'); | |
6994 assert.equal(testMoment.month(), 0, | |
6995 'lenient ordinal parsing of number ' + i + ' month check'); | |
6996 assert.equal(testMoment.date(), i, | |
6997 'lenient ordinal parsing of number ' + i + ' date check'); | |
6998 } | |
6999 }); | |
7000 | |
7001 test('strict ordinal parsing', function (assert) { | |
7002 var i, ordinalStr, testMoment; | |
7003 for (i = 1; i <= 31; ++i) { | |
7004 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
7005 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
7006 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
7007 } | |
7008 }); | |
7009 | |
7010 })); | |
7011 | |
7012 (function (global, factory) { | |
7013 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
7014 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
7015 factory(global.moment) | |
7016 }(this, function (moment) { 'use strict'; | |
7017 | |
7018 /*global QUnit:false*/ | |
7019 | |
7020 var test = QUnit.test; | |
7021 | |
7022 function module (name, lifecycle) { | |
7023 QUnit.module(name, { | |
7024 setup : function () { | |
7025 moment.locale('en'); | |
7026 moment.createFromInputFallback = function () { | |
7027 throw new Error('input not handled by moment'); | |
7028 }; | |
7029 if (lifecycle && lifecycle.setup) { | |
7030 lifecycle.setup(); | |
7031 } | |
7032 }, | |
7033 teardown : function () { | |
7034 if (lifecycle && lifecycle.teardown) { | |
7035 lifecycle.teardown(); | |
7036 } | |
7037 } | |
7038 }); | |
7039 } | |
7040 | |
7041 function localeModule (name, lifecycle) { | |
7042 QUnit.module('locale:' + name, { | |
7043 setup : function () { | |
7044 moment.locale(name); | |
7045 moment.createFromInputFallback = function () { | |
7046 throw new Error('input not handled by moment'); | |
7047 }; | |
7048 if (lifecycle && lifecycle.setup) { | |
7049 lifecycle.setup(); | |
7050 } | |
7051 }, | |
7052 teardown : function () { | |
7053 moment.locale('en'); | |
7054 if (lifecycle && lifecycle.teardown) { | |
7055 lifecycle.teardown(); | |
7056 } | |
7057 } | |
7058 }); | |
7059 } | |
7060 | |
7061 localeModule('el'); | |
7062 | |
7063 test('parse', function (assert) { | |
7064 var i, | |
7065 tests = 'Ιανουάριος Ιαν_Φεβρουάριος Φεβ_Μάρτιος Μαρ_Απρίλιος Απρ_Μάιος Μαϊ_Ιούνιος Ιουν_Ιούλιος Ιουλ_Αύγουστος Αυγ_Σεπτέμβριος Σεπ_Οκτώβριος Οκτ_Νοέμβριος Νοε_Δεκέμβριος Δεκ'.split('_'); | |
7066 | |
7067 function equalTest(input, mmm, i) { | |
7068 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
7069 } | |
7070 | |
7071 for (i = 0; i < 12; i++) { | |
7072 tests[i] = tests[i].split(' '); | |
7073 equalTest(tests[i][0], 'MMM', i); | |
7074 equalTest(tests[i][1], 'MMM', i); | |
7075 equalTest(tests[i][0], 'MMMM', i); | |
7076 equalTest(tests[i][1], 'MMMM', i); | |
7077 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
7078 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
7079 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
7080 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
7081 } | |
7082 }); | |
7083 | |
7084 test('parse meridiem', function (assert) { | |
7085 var i, | |
7086 b = moment(), | |
7087 meridiemTests = [ | |
7088 // h a patterns, expected hours, isValid | |
7089 ['10 πμ', 10, true], | |
7090 ['10 μμ', 22, true], | |
7091 ['10 π.μ.', 10, true], | |
7092 ['10 μ.μ.', 22, true], | |
7093 ['10 π', 10, true], | |
7094 ['10 μ', 22, true], | |
7095 ['10 ΠΜ', 10, true], | |
7096 ['10 ΜΜ', 22, true], | |
7097 ['10 Π.Μ.', 10, true], | |
7098 ['10 Μ.Μ.', 22, true], | |
7099 ['10 Π', 10, true], | |
7100 ['10 Μ', 22, true], | |
7101 ['10 am', 10, false], | |
7102 ['10 pm', 10, false] | |
7103 ]; | |
7104 | |
7105 // test that a formatted moment including meridiem string can be parsed back to the same moment | |
7106 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')); | |
7107 | |
7108 // test that a formatted moment having a meridiem string can be parsed with strict flag | |
7109 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'); | |
7110 | |
7111 for (i = 0; i < meridiemTests.length; i++) { | |
7112 assert.equal(moment(meridiemTests[i][0], 'h a', 'el', true).hours(), meridiemTests[i][1], moment(meridiemTests[i][0], 'h a', 'el', true).hours() + ' should be ' + meridiemTests[i][1]); | |
7113 assert.ok(moment(meridiemTests[i][0], 'h a', 'el', true).isValid() === meridiemTests[i][2], meridiemTests[i][0] + ' ----> ' + meridiemTests[i][2]); | |
7114 } | |
7115 }); | |
7116 | |
7117 test('format', function (assert) { | |
7118 var a = [ | |
7119 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Κυριακή, Φεβρουάριος 14η 2010, 3:25:50 μμ'], | |
7120 ['dddd, D MMMM YYYY, h:mm:ss a', 'Κυριακή, 14 Φεβρουαρίου 2010, 3:25:50 μμ'], | |
7121 ['ddd, hA', 'Κυρ, 3ΜΜ'], | |
7122 ['dddd, MMMM YYYY', 'Κυριακή, Φεβρουάριος 2010'], | |
7123 ['M Mo MM MMMM MMM', '2 2η 02 Φεβρουάριος Φεβ'], | |
7124 ['YYYY YY', '2010 10'], | |
7125 ['D Do DD', '14 14η 14'], | |
7126 ['d do dddd ddd dd', '0 0η Κυριακή Κυρ Κυ'], | |
7127 ['DDD DDDo DDDD', '45 45η 045'], | |
7128 ['w wo ww', '6 6η 06'], | |
7129 ['h hh', '3 03'], | |
7130 ['H HH', '15 15'], | |
7131 ['m mm', '25 25'], | |
7132 ['s ss', '50 50'], | |
7133 ['a A', 'μμ ΜΜ'], | |
7134 ['[the] DDDo [day of the year]', 'the 45η day of the year'], | |
7135 ['LTS', '3:25:50 ΜΜ'], | |
7136 ['L', '14/02/2010'], | |
7137 ['LL', '14 Φεβρουαρίου 2010'], | |
7138 ['LLL', '14 Φεβρουαρίου 2010 3:25 ΜΜ'], | |
7139 ['LLLL', 'Κυριακή, 14 Φεβρουαρίου 2010 3:25 ΜΜ'], | |
7140 ['l', '14/2/2010'], | |
7141 ['ll', '14 Φεβ 2010'], | |
7142 ['lll', '14 Φεβ 2010 3:25 ΜΜ'], | |
7143 ['llll', 'Κυρ, 14 Φεβ 2010 3:25 ΜΜ'] | |
7144 ], | |
7145 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
7146 i; | |
7147 | |
7148 for (i = 0; i < a.length; i++) { | |
7149 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
7150 } | |
7151 }); | |
7152 | |
7153 test('format ordinal', function (assert) { | |
7154 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1η', '1η'); | |
7155 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2η', '2η'); | |
7156 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3η', '3η'); | |
7157 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4η', '4η'); | |
7158 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5η', '5η'); | |
7159 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6η', '6η'); | |
7160 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7η', '7η'); | |
7161 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8η', '8η'); | |
7162 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9η', '9η'); | |
7163 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10η', '10η'); | |
7164 | |
7165 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11η', '11η'); | |
7166 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12η', '12η'); | |
7167 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13η', '13η'); | |
7168 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14η', '14η'); | |
7169 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15η', '15η'); | |
7170 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16η', '16η'); | |
7171 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17η', '17η'); | |
7172 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18η', '18η'); | |
7173 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19η', '19η'); | |
7174 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20η', '20η'); | |
7175 | |
7176 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21η', '21η'); | |
7177 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22η', '22η'); | |
7178 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23η', '23η'); | |
7179 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24η', '24η'); | |
7180 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25η', '25η'); | |
7181 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26η', '26η'); | |
7182 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27η', '27η'); | |
7183 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28η', '28η'); | |
7184 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29η', '29η'); | |
7185 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30η', '30η'); | |
7186 | |
7187 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31η', '31η'); | |
7188 }); | |
7189 | |
7190 test('format month', function (assert) { | |
7191 var i, | |
7192 expected = 'Ιανουάριος Ιαν_Φεβρουάριος Φεβ_Μάρτιος Μαρ_Απρίλιος Απρ_Μάιος Μαϊ_Ιούνιος Ιουν_Ιούλιος Ιουλ_Αύγουστος Αυγ_Σεπτέμβριος Σεπ_Οκτώβριος Οκτ_Νοέμβριος Νοε_Δεκέμβριος Δεκ'.split('_'); | |
7193 | |
7194 for (i = 0; i < expected.length; i++) { | |
7195 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
7196 } | |
7197 }); | |
7198 | |
7199 test('format week', function (assert) { | |
7200 var i, | |
7201 expected = 'Κυριακή Κυρ Κυ_Δευτέρα Δευ Δε_Τρίτη Τρι Τρ_Τετάρτη Τετ Τε_Πέμπτη Πεμ Πε_Παρασκευή Παρ Πα_Σάββατο Σαβ Σα'.split('_'); | |
7202 | |
7203 for (i = 0; i < expected.length; i++) { | |
7204 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
7205 } | |
7206 }); | |
7207 | |
7208 test('from', function (assert) { | |
7209 var start = moment([2007, 1, 28]); | |
7210 | |
7211 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'λίγα δευτερόλεπτα', '44 seconds = a few seconds'); | |
7212 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ένα λεπτό', '45 seconds = a minute'); | |
7213 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ένα λεπτό', '89 seconds = a minute'); | |
7214 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 λεπτά', '90 seconds = 2 minutes'); | |
7215 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 λεπτά', '44 minutes = 44 minutes'); | |
7216 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'μία ώρα', '45 minutes = an hour'); | |
7217 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'μία ώρα', '89 minutes = an hour'); | |
7218 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ώρες', '90 minutes = 2 hours'); | |
7219 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ώρες', '5 hours = 5 hours'); | |
7220 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ώρες', '21 hours = 21 hours'); | |
7221 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'μία μέρα', '22 hours = a day'); | |
7222 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'μία μέρα', '35 hours = a day'); | |
7223 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 μέρες', '36 hours = 2 days'); | |
7224 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'μία μέρα', '1 day = a day'); | |
7225 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 μέρες', '5 days = 5 days'); | |
7226 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 μέρες', '25 days = 25 days'); | |
7227 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ένας μήνας', '26 days = a month'); | |
7228 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ένας μήνας', '30 days = a month'); | |
7229 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ένας μήνας', '43 days = a month'); | |
7230 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 μήνες', '46 days = 2 months'); | |
7231 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 μήνες', '75 days = 2 months'); | |
7232 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 μήνες', '76 days = 3 months'); | |
7233 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ένας μήνας', '1 month = a month'); | |
7234 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 μήνες', '5 months = 5 months'); | |
7235 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ένας χρόνος', '345 days = a year'); | |
7236 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 χρόνια', '548 days = 2 years'); | |
7237 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ένας χρόνος', '1 year = a year'); | |
7238 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 χρόνια', '5 years = 5 years'); | |
7239 }); | |
7240 | |
7241 test('suffix', function (assert) { | |
7242 assert.equal(moment(30000).from(0), 'σε λίγα δευτερόλεπτα', 'prefix'); | |
7243 assert.equal(moment(0).from(30000), 'λίγα δευτερόλεπτα πριν', 'suffix'); | |
7244 }); | |
7245 | |
7246 test('now from now', function (assert) { | |
7247 assert.equal(moment().fromNow(), 'λίγα δευτερόλεπτα πριν', 'now from now should display as in the past'); | |
7248 }); | |
7249 | |
7250 test('fromNow', function (assert) { | |
7251 assert.equal(moment().add({s: 30}).fromNow(), 'σε λίγα δευτερόλεπτα', 'in a few seconds'); | |
7252 assert.equal(moment().add({d: 5}).fromNow(), 'σε 5 μέρες', 'in 5 days'); | |
7253 }); | |
7254 | |
7255 test('calendar day', function (assert) { | |
7256 var a = moment().hours(2).minutes(0).seconds(0); | |
7257 | |
7258 assert.equal(moment(a).calendar(), 'Σήμερα στις 2:00 ΠΜ', 'today at the same time'); | |
7259 assert.equal(moment(a).add({m: 25}).calendar(), 'Σήμερα στις 2:25 ΠΜ', 'Now plus 25 min'); | |
7260 assert.equal(moment(a).add({h: 1}).calendar(), 'Σήμερα στις 3:00 ΠΜ', 'Now plus 1 hour'); | |
7261 assert.equal(moment(a).add({d: 1}).calendar(), 'Αύριο στις 2:00 ΠΜ', 'tomorrow at the same time'); | |
7262 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Σήμερα στη 1:00 ΠΜ', 'Now minus 1 hour'); | |
7263 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Χθες στις 2:00 ΠΜ', 'yesterday at the same time'); | |
7264 }); | |
7265 | |
7266 test('calendar next week', function (assert) { | |
7267 var i, m; | |
7268 for (i = 2; i < 7; i++) { | |
7269 m = moment().add({d: i}); | |
7270 assert.equal(m.calendar(), m.format('dddd [' + (m.hours() % 12 === 1 ? 'στη' : 'στις') + '] LT'), 'Today + ' + i + ' days current time'); | |
7271 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
7272 assert.equal(m.calendar(), m.format('dddd [στις] LT'), 'Today + ' + i + ' days beginning of day'); | |
7273 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
7274 assert.equal(m.calendar(), m.format('dddd [στις] LT'), 'Today + ' + i + ' days end of day'); | |
7275 } | |
7276 }); | |
7277 | |
7278 test('calendar last week', function (assert) { | |
7279 var i, m, dayString; | |
7280 for (i = 2; i < 7; i++) { | |
7281 m = moment().subtract({d: i}); | |
7282 dayString = m.day() === 6 ? '[το προηγούμενο Σάββατο]' : '[την προηγούμενη] dddd'; | |
7283 assert.equal(m.calendar(), m.format(dayString + ' [' + (m.hours() % 12 === 1 ? 'στη' : 'στις') + '] LT'), 'Today - ' + i + ' days current time'); | |
7284 m.hours(1).minutes(30).seconds(0).milliseconds(0); | |
7285 assert.equal(m.calendar(), m.format(dayString + ' [στη] LT'), 'Today - ' + i + ' days one o clock'); | |
7286 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
7287 assert.equal(m.calendar(), m.format(dayString + ' [στις] LT'), 'Today - ' + i + ' days beginning of day'); | |
7288 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
7289 assert.equal(m.calendar(), m.format(dayString + ' [στις] LT'), 'Today - ' + i + ' days end of day'); | |
7290 } | |
7291 }); | |
7292 | |
7293 test('calendar all else', function (assert) { | |
7294 var weeksAgo = moment().subtract({w: 1}), | |
7295 weeksFromNow = moment().add({w: 1}); | |
7296 | |
7297 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
7298 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
7299 | |
7300 weeksAgo = moment().subtract({w: 2}); | |
7301 weeksFromNow = moment().add({w: 2}); | |
7302 | |
7303 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
7304 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
7305 }); | |
7306 | |
7307 test('weeks year starting sunday', function (assert) { | |
7308 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
7309 assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1'); | |
7310 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
7311 assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2'); | |
7312 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
7313 }); | |
7314 | |
7315 test('weeks year starting monday', function (assert) { | |
7316 assert.equal(moment([2006, 11, 31]).week(), 52, 'Dec 31 2006 should be week 52'); | |
7317 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
7318 assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1'); | |
7319 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
7320 assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2'); | |
7321 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
7322 }); | |
7323 | |
7324 test('weeks year starting tuesday', function (assert) { | |
7325 assert.equal(moment([2007, 11, 30]).week(), 52, 'Dec 30 2007 should be week 52'); | |
7326 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
7327 assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1'); | |
7328 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
7329 assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2'); | |
7330 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
7331 }); | |
7332 | |
7333 test('weeks year starting wednesday', function (assert) { | |
7334 assert.equal(moment([2002, 11, 29]).week(), 52, 'Dec 29 2002 should be week 52'); | |
7335 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
7336 assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1'); | |
7337 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
7338 assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2'); | |
7339 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
7340 }); | |
7341 | |
7342 test('weeks year starting thursday', function (assert) { | |
7343 assert.equal(moment([2008, 11, 28]).week(), 52, 'Dec 28 2008 should be week 52'); | |
7344 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
7345 assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1'); | |
7346 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
7347 assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2'); | |
7348 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
7349 }); | |
7350 | |
7351 test('weeks year starting friday', function (assert) { | |
7352 assert.equal(moment([2009, 11, 27]).week(), 52, 'Dec 27 2009 should be week 52'); | |
7353 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
7354 assert.equal(moment([2010, 0, 2]).week(), 53, 'Jan 2 2010 should be week 53'); | |
7355 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 1'); | |
7356 assert.equal(moment([2010, 0, 9]).week(), 1, 'Jan 9 2010 should be week 1'); | |
7357 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
7358 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
7359 }); | |
7360 | |
7361 test('weeks year starting saturday', function (assert) { | |
7362 assert.equal(moment([2010, 11, 26]).week(), 51, 'Dec 26 2010 should be week 51'); | |
7363 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
7364 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
7365 assert.equal(moment([2011, 0, 8]).week(), 1, 'Jan 8 2011 should be week 1'); | |
7366 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
7367 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
7368 }); | |
7369 | |
7370 test('weeks year starting sunday format', function (assert) { | |
7371 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52η', 'Jan 1 2012 should be week 52'); | |
7372 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1η', 'Jan 7 2012 should be week 1'); | |
7373 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1η', 'Jan 8 2012 should be week 1'); | |
7374 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2η', 'Jan 14 2012 should be week 2'); | |
7375 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2η', 'Jan 15 2012 should be week 2'); | |
7376 }); | |
7377 | |
7378 test('lenient ordinal parsing', function (assert) { | |
7379 var i, ordinalStr, testMoment; | |
7380 for (i = 1; i <= 31; ++i) { | |
7381 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
7382 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
7383 assert.equal(testMoment.year(), 2014, | |
7384 'lenient ordinal parsing ' + i + ' year check'); | |
7385 assert.equal(testMoment.month(), 0, | |
7386 'lenient ordinal parsing ' + i + ' month check'); | |
7387 assert.equal(testMoment.date(), i, | |
7388 'lenient ordinal parsing ' + i + ' date check'); | |
7389 } | |
7390 }); | |
7391 | |
7392 test('lenient ordinal parsing of number', function (assert) { | |
7393 var i, testMoment; | |
7394 for (i = 1; i <= 31; ++i) { | |
7395 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
7396 assert.equal(testMoment.year(), 2014, | |
7397 'lenient ordinal parsing of number ' + i + ' year check'); | |
7398 assert.equal(testMoment.month(), 0, | |
7399 'lenient ordinal parsing of number ' + i + ' month check'); | |
7400 assert.equal(testMoment.date(), i, | |
7401 'lenient ordinal parsing of number ' + i + ' date check'); | |
7402 } | |
7403 }); | |
7404 | |
7405 test('strict ordinal parsing', function (assert) { | |
7406 var i, ordinalStr, testMoment; | |
7407 for (i = 1; i <= 31; ++i) { | |
7408 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
7409 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
7410 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
7411 } | |
7412 }); | |
7413 | |
7414 })); | |
7415 | |
7416 (function (global, factory) { | |
7417 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
7418 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
7419 factory(global.moment) | |
7420 }(this, function (moment) { 'use strict'; | |
7421 | |
7422 /*global QUnit:false*/ | |
7423 | |
7424 var test = QUnit.test; | |
7425 | |
7426 function module (name, lifecycle) { | |
7427 QUnit.module(name, { | |
7428 setup : function () { | |
7429 moment.locale('en'); | |
7430 moment.createFromInputFallback = function () { | |
7431 throw new Error('input not handled by moment'); | |
7432 }; | |
7433 if (lifecycle && lifecycle.setup) { | |
7434 lifecycle.setup(); | |
7435 } | |
7436 }, | |
7437 teardown : function () { | |
7438 if (lifecycle && lifecycle.teardown) { | |
7439 lifecycle.teardown(); | |
7440 } | |
7441 } | |
7442 }); | |
7443 } | |
7444 | |
7445 function localeModule (name, lifecycle) { | |
7446 QUnit.module('locale:' + name, { | |
7447 setup : function () { | |
7448 moment.locale(name); | |
7449 moment.createFromInputFallback = function () { | |
7450 throw new Error('input not handled by moment'); | |
7451 }; | |
7452 if (lifecycle && lifecycle.setup) { | |
7453 lifecycle.setup(); | |
7454 } | |
7455 }, | |
7456 teardown : function () { | |
7457 moment.locale('en'); | |
7458 if (lifecycle && lifecycle.teardown) { | |
7459 lifecycle.teardown(); | |
7460 } | |
7461 } | |
7462 }); | |
7463 } | |
7464 | |
7465 localeModule('en-au'); | |
7466 | |
7467 test('parse', function (assert) { | |
7468 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; | |
7469 function equalTest(input, mmm, i) { | |
7470 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
7471 } | |
7472 for (i = 0; i < 12; i++) { | |
7473 tests[i] = tests[i].split(' '); | |
7474 equalTest(tests[i][0], 'MMM', i); | |
7475 equalTest(tests[i][1], 'MMM', i); | |
7476 equalTest(tests[i][0], 'MMMM', i); | |
7477 equalTest(tests[i][1], 'MMMM', i); | |
7478 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
7479 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
7480 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
7481 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
7482 } | |
7483 }); | |
7484 | |
7485 test('format', function (assert) { | |
7486 var a = [ | |
7487 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Sunday, February 14th 2010, 3:25:50 pm'], | |
7488 ['ddd, hA', 'Sun, 3PM'], | |
7489 ['M Mo MM MMMM MMM', '2 2nd 02 February Feb'], | |
7490 ['YYYY YY', '2010 10'], | |
7491 ['D Do DD', '14 14th 14'], | |
7492 ['d do dddd ddd dd', '0 0th Sunday Sun Su'], | |
7493 ['DDD DDDo DDDD', '45 45th 045'], | |
7494 ['w wo ww', '6 6th 06'], | |
7495 ['h hh', '3 03'], | |
7496 ['H HH', '15 15'], | |
7497 ['m mm', '25 25'], | |
7498 ['s ss', '50 50'], | |
7499 ['a A', 'pm PM'], | |
7500 ['[the] DDDo [day of the year]', 'the 45th day of the year'], | |
7501 ['LTS', '3:25:50 PM'], | |
7502 ['L', '14/02/2010'], | |
7503 ['LL', '14 February 2010'], | |
7504 ['LLL', '14 February 2010 3:25 PM'], | |
7505 ['LLLL', 'Sunday, 14 February 2010 3:25 PM'], | |
7506 ['l', '14/2/2010'], | |
7507 ['ll', '14 Feb 2010'], | |
7508 ['lll', '14 Feb 2010 3:25 PM'], | |
7509 ['llll', 'Sun, 14 Feb 2010 3:25 PM'] | |
7510 ], | |
7511 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
7512 i; | |
7513 for (i = 0; i < a.length; i++) { | |
7514 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
7515 } | |
7516 }); | |
7517 | |
7518 test('format ordinal', function (assert) { | |
7519 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1st', '1st'); | |
7520 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2nd', '2nd'); | |
7521 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3rd', '3rd'); | |
7522 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4th', '4th'); | |
7523 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5th', '5th'); | |
7524 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6th', '6th'); | |
7525 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7th', '7th'); | |
7526 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8th', '8th'); | |
7527 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9th', '9th'); | |
7528 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10th', '10th'); | |
7529 | |
7530 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11th', '11th'); | |
7531 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12th', '12th'); | |
7532 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13th', '13th'); | |
7533 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14th', '14th'); | |
7534 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15th', '15th'); | |
7535 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16th', '16th'); | |
7536 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17th', '17th'); | |
7537 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18th', '18th'); | |
7538 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19th', '19th'); | |
7539 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20th', '20th'); | |
7540 | |
7541 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21st', '21st'); | |
7542 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22nd', '22nd'); | |
7543 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23rd', '23rd'); | |
7544 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24th', '24th'); | |
7545 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25th', '25th'); | |
7546 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26th', '26th'); | |
7547 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27th', '27th'); | |
7548 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28th', '28th'); | |
7549 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29th', '29th'); | |
7550 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30th', '30th'); | |
7551 | |
7552 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31st', '31st'); | |
7553 }); | |
7554 | |
7555 test('format month', function (assert) { | |
7556 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; | |
7557 for (i = 0; i < expected.length; i++) { | |
7558 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
7559 } | |
7560 }); | |
7561 | |
7562 test('format week', function (assert) { | |
7563 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; | |
7564 for (i = 0; i < expected.length; i++) { | |
7565 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
7566 } | |
7567 }); | |
7568 | |
7569 test('from', function (assert) { | |
7570 var start = moment([2007, 1, 28]); | |
7571 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'a few seconds', '44 seconds = a few seconds'); | |
7572 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'a minute', '45 seconds = a minute'); | |
7573 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'a minute', '89 seconds = a minute'); | |
7574 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes'); | |
7575 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes'); | |
7576 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'an hour', '45 minutes = an hour'); | |
7577 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'an hour', '89 minutes = an hour'); | |
7578 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hours', '90 minutes = 2 hours'); | |
7579 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hours', '5 hours = 5 hours'); | |
7580 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hours', '21 hours = 21 hours'); | |
7581 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'a day', '22 hours = a day'); | |
7582 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'a day', '35 hours = a day'); | |
7583 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 days', '36 hours = 2 days'); | |
7584 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'a day', '1 day = a day'); | |
7585 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 days', '5 days = 5 days'); | |
7586 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 days', '25 days = 25 days'); | |
7587 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'a month', '26 days = a month'); | |
7588 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'a month', '30 days = a month'); | |
7589 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'a month', '43 days = a month'); | |
7590 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 months', '46 days = 2 months'); | |
7591 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 months', '75 days = 2 months'); | |
7592 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 months', '76 days = 3 months'); | |
7593 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'a month', '1 month = a month'); | |
7594 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 months', '5 months = 5 months'); | |
7595 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'a year', '345 days = a year'); | |
7596 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 years', '548 days = 2 years'); | |
7597 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'a year', '1 year = a year'); | |
7598 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 years', '5 years = 5 years'); | |
7599 }); | |
7600 | |
7601 test('suffix', function (assert) { | |
7602 assert.equal(moment(30000).from(0), 'in a few seconds', 'prefix'); | |
7603 assert.equal(moment(0).from(30000), 'a few seconds ago', 'suffix'); | |
7604 }); | |
7605 | |
7606 test('now from now', function (assert) { | |
7607 assert.equal(moment().fromNow(), 'a few seconds ago', 'now from now should display as in the past'); | |
7608 }); | |
7609 | |
7610 test('fromNow', function (assert) { | |
7611 assert.equal(moment().add({s: 30}).fromNow(), 'in a few seconds', 'in a few seconds'); | |
7612 assert.equal(moment().add({d: 5}).fromNow(), 'in 5 days', 'in 5 days'); | |
7613 }); | |
7614 | |
7615 test('calendar day', function (assert) { | |
7616 var a = moment().hours(2).minutes(0).seconds(0); | |
7617 | |
7618 assert.equal(moment(a).calendar(), 'Today at 2:00 AM', 'today at the same time'); | |
7619 assert.equal(moment(a).add({m: 25}).calendar(), 'Today at 2:25 AM', 'Now plus 25 min'); | |
7620 assert.equal(moment(a).add({h: 1}).calendar(), 'Today at 3:00 AM', 'Now plus 1 hour'); | |
7621 assert.equal(moment(a).add({d: 1}).calendar(), 'Tomorrow at 2:00 AM', 'tomorrow at the same time'); | |
7622 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Today at 1:00 AM', 'Now minus 1 hour'); | |
7623 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Yesterday at 2:00 AM', 'yesterday at the same time'); | |
7624 }); | |
7625 | |
7626 test('calendar next week', function (assert) { | |
7627 var i, m; | |
7628 for (i = 2; i < 7; i++) { | |
7629 m = moment().add({d: i}); | |
7630 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days current time'); | |
7631 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
7632 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days beginning of day'); | |
7633 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
7634 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days end of day'); | |
7635 } | |
7636 }); | |
7637 | |
7638 test('calendar last week', function (assert) { | |
7639 var i, m; | |
7640 | |
7641 for (i = 2; i < 7; i++) { | |
7642 m = moment().subtract({d: i}); | |
7643 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days current time'); | |
7644 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
7645 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days beginning of day'); | |
7646 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
7647 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days end of day'); | |
7648 } | |
7649 }); | |
7650 | |
7651 test('calendar all else', function (assert) { | |
7652 var weeksAgo = moment().subtract({w: 1}), | |
7653 weeksFromNow = moment().add({w: 1}); | |
7654 | |
7655 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
7656 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
7657 | |
7658 weeksAgo = moment().subtract({w: 2}); | |
7659 weeksFromNow = moment().add({w: 2}); | |
7660 | |
7661 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
7662 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
7663 }); | |
7664 | |
7665 test('weeks year starting sunday', function (assert) { | |
7666 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
7667 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
7668 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
7669 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
7670 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
7671 }); | |
7672 | |
7673 test('weeks year starting monday', function (assert) { | |
7674 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
7675 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
7676 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
7677 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
7678 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
7679 }); | |
7680 | |
7681 test('weeks year starting tuesday', function (assert) { | |
7682 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
7683 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
7684 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
7685 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
7686 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
7687 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
7688 }); | |
7689 | |
7690 test('weeks year starting wednesday', function (assert) { | |
7691 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
7692 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
7693 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
7694 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
7695 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
7696 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
7697 }); | |
7698 | |
7699 test('weeks year starting thursday', function (assert) { | |
7700 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
7701 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
7702 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
7703 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
7704 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
7705 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
7706 }); | |
7707 | |
7708 test('weeks year starting friday', function (assert) { | |
7709 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
7710 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
7711 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
7712 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
7713 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
7714 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
7715 }); | |
7716 | |
7717 test('weeks year starting saturday', function (assert) { | |
7718 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
7719 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
7720 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
7721 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
7722 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
7723 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
7724 }); | |
7725 | |
7726 test('weeks year starting sunday formatted', function (assert) { | |
7727 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52nd', 'Jan 1 2012 should be week 52'); | |
7728 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1st', 'Jan 2 2012 should be week 1'); | |
7729 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1st', 'Jan 8 2012 should be week 1'); | |
7730 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2nd', 'Jan 9 2012 should be week 2'); | |
7731 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2nd', 'Jan 15 2012 should be week 2'); | |
7732 }); | |
7733 | |
7734 test('lenient ordinal parsing', function (assert) { | |
7735 var i, ordinalStr, testStr; | |
7736 for (i = 1; i <= 31; ++i) { | |
7737 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
7738 testStr = moment(ordinalStr, 'YYYY MM Do').format('YYYY MM D'); | |
7739 assert.equal(testStr, '2014 01 ' + i, 'lenient ordinal parsing ' + i); | |
7740 } | |
7741 }); | |
7742 | |
7743 test('lenient ordinal parsing of number', function (assert) { | |
7744 var i, testStr; | |
7745 for (i = 1; i <= 31; ++i) { | |
7746 testStr = moment('2014 01 ' + i, 'YYYY MM Do').format('YYYY MM D'); | |
7747 assert.equal(testStr, '2014 01 ' + i, | |
7748 'lenient ordinal parsing of number ' + i); | |
7749 } | |
7750 }); | |
7751 | |
7752 test('strict ordinal parsing', function (assert) { | |
7753 var i, ordinalStr, testMoment; | |
7754 for (i = 1; i <= 31; ++i) { | |
7755 ordinalStr = moment([2014, 0, i]).format('YYYY MMM Do'); | |
7756 testMoment = moment(ordinalStr, 'YYYY MMM Do', true); | |
7757 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
7758 } | |
7759 }); | |
7760 | |
7761 })); | |
7762 | |
7763 (function (global, factory) { | |
7764 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
7765 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
7766 factory(global.moment) | |
7767 }(this, function (moment) { 'use strict'; | |
7768 | |
7769 /*global QUnit:false*/ | |
7770 | |
7771 var test = QUnit.test; | |
7772 | |
7773 function module (name, lifecycle) { | |
7774 QUnit.module(name, { | |
7775 setup : function () { | |
7776 moment.locale('en'); | |
7777 moment.createFromInputFallback = function () { | |
7778 throw new Error('input not handled by moment'); | |
7779 }; | |
7780 if (lifecycle && lifecycle.setup) { | |
7781 lifecycle.setup(); | |
7782 } | |
7783 }, | |
7784 teardown : function () { | |
7785 if (lifecycle && lifecycle.teardown) { | |
7786 lifecycle.teardown(); | |
7787 } | |
7788 } | |
7789 }); | |
7790 } | |
7791 | |
7792 function localeModule (name, lifecycle) { | |
7793 QUnit.module('locale:' + name, { | |
7794 setup : function () { | |
7795 moment.locale(name); | |
7796 moment.createFromInputFallback = function () { | |
7797 throw new Error('input not handled by moment'); | |
7798 }; | |
7799 if (lifecycle && lifecycle.setup) { | |
7800 lifecycle.setup(); | |
7801 } | |
7802 }, | |
7803 teardown : function () { | |
7804 moment.locale('en'); | |
7805 if (lifecycle && lifecycle.teardown) { | |
7806 lifecycle.teardown(); | |
7807 } | |
7808 } | |
7809 }); | |
7810 } | |
7811 | |
7812 localeModule('en-ca'); | |
7813 | |
7814 test('parse', function (assert) { | |
7815 var i, | |
7816 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('_'); | |
7817 | |
7818 function equalTest(input, mmm, i) { | |
7819 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
7820 } | |
7821 | |
7822 for (i = 0; i < 12; i++) { | |
7823 tests[i] = tests[i].split(' '); | |
7824 equalTest(tests[i][0], 'MMM', i); | |
7825 equalTest(tests[i][1], 'MMM', i); | |
7826 equalTest(tests[i][0], 'MMMM', i); | |
7827 equalTest(tests[i][1], 'MMMM', i); | |
7828 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
7829 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
7830 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
7831 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
7832 } | |
7833 }); | |
7834 | |
7835 test('format', function (assert) { | |
7836 var a = [ | |
7837 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Sunday, February 14th 2010, 3:25:50 pm'], | |
7838 ['ddd, hA', 'Sun, 3PM'], | |
7839 ['M Mo MM MMMM MMM', '2 2nd 02 February Feb'], | |
7840 ['YYYY YY', '2010 10'], | |
7841 ['D Do DD', '14 14th 14'], | |
7842 ['d do dddd ddd dd', '0 0th Sunday Sun Su'], | |
7843 ['DDD DDDo DDDD', '45 45th 045'], | |
7844 ['w wo ww', '8 8th 08'], | |
7845 ['h hh', '3 03'], | |
7846 ['H HH', '15 15'], | |
7847 ['m mm', '25 25'], | |
7848 ['s ss', '50 50'], | |
7849 ['a A', 'pm PM'], | |
7850 ['[the] DDDo [day of the year]', 'the 45th day of the year'], | |
7851 ['L', '2010-02-14'], | |
7852 ['LTS', '3:25:50 PM'], | |
7853 ['LL', '14 February, 2010'], | |
7854 ['LLL', '14 February, 2010 3:25 PM'], | |
7855 ['LLLL', 'Sunday, 14 February, 2010 3:25 PM'], | |
7856 ['l', '2010-2-14'], | |
7857 ['ll', '14 Feb, 2010'], | |
7858 ['lll', '14 Feb, 2010 3:25 PM'], | |
7859 ['llll', 'Sun, 14 Feb, 2010 3:25 PM'] | |
7860 ], | |
7861 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
7862 i; | |
7863 | |
7864 for (i = 0; i < a.length; i++) { | |
7865 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
7866 } | |
7867 }); | |
7868 | |
7869 test('format ordinal', function (assert) { | |
7870 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1st', '1st'); | |
7871 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2nd', '2nd'); | |
7872 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3rd', '3rd'); | |
7873 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4th', '4th'); | |
7874 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5th', '5th'); | |
7875 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6th', '6th'); | |
7876 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7th', '7th'); | |
7877 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8th', '8th'); | |
7878 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9th', '9th'); | |
7879 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10th', '10th'); | |
7880 | |
7881 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11th', '11th'); | |
7882 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12th', '12th'); | |
7883 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13th', '13th'); | |
7884 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14th', '14th'); | |
7885 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15th', '15th'); | |
7886 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16th', '16th'); | |
7887 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17th', '17th'); | |
7888 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18th', '18th'); | |
7889 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19th', '19th'); | |
7890 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20th', '20th'); | |
7891 | |
7892 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21st', '21st'); | |
7893 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22nd', '22nd'); | |
7894 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23rd', '23rd'); | |
7895 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24th', '24th'); | |
7896 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25th', '25th'); | |
7897 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26th', '26th'); | |
7898 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27th', '27th'); | |
7899 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28th', '28th'); | |
7900 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29th', '29th'); | |
7901 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30th', '30th'); | |
7902 | |
7903 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31st', '31st'); | |
7904 }); | |
7905 | |
7906 test('format month', function (assert) { | |
7907 var i, | |
7908 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('_'); | |
7909 | |
7910 for (i = 0; i < expected.length; i++) { | |
7911 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
7912 } | |
7913 }); | |
7914 | |
7915 test('format week', function (assert) { | |
7916 var i, | |
7917 expected = 'Sunday Sun Su_Monday Mon Mo_Tuesday Tue Tu_Wednesday Wed We_Thursday Thu Th_Friday Fri Fr_Saturday Sat Sa'.split('_'); | |
7918 | |
7919 for (i = 0; i < expected.length; i++) { | |
7920 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
7921 } | |
7922 }); | |
7923 | |
7924 test('from', function (assert) { | |
7925 var start = moment([2007, 1, 28]); | |
7926 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'a few seconds', '44 seconds = a few seconds'); | |
7927 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'a minute', '45 seconds = a minute'); | |
7928 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'a minute', '89 seconds = a minute'); | |
7929 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes'); | |
7930 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes'); | |
7931 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'an hour', '45 minutes = an hour'); | |
7932 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'an hour', '89 minutes = an hour'); | |
7933 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hours', '90 minutes = 2 hours'); | |
7934 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hours', '5 hours = 5 hours'); | |
7935 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hours', '21 hours = 21 hours'); | |
7936 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'a day', '22 hours = a day'); | |
7937 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'a day', '35 hours = a day'); | |
7938 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 days', '36 hours = 2 days'); | |
7939 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'a day', '1 day = a day'); | |
7940 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 days', '5 days = 5 days'); | |
7941 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 days', '25 days = 25 days'); | |
7942 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'a month', '26 days = a month'); | |
7943 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'a month', '30 days = a month'); | |
7944 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'a month', '43 days = a month'); | |
7945 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 months', '46 days = 2 months'); | |
7946 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 months', '75 days = 2 months'); | |
7947 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 months', '76 days = 3 months'); | |
7948 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'a month', '1 month = a month'); | |
7949 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 months', '5 months = 5 months'); | |
7950 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'a year', '345 days = a year'); | |
7951 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 years', '548 days = 2 years'); | |
7952 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'a year', '1 year = a year'); | |
7953 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 years', '5 years = 5 years'); | |
7954 }); | |
7955 | |
7956 test('suffix', function (assert) { | |
7957 assert.equal(moment(30000).from(0), 'in a few seconds', 'prefix'); | |
7958 assert.equal(moment(0).from(30000), 'a few seconds ago', 'suffix'); | |
7959 }); | |
7960 | |
7961 test('now from now', function (assert) { | |
7962 assert.equal(moment().fromNow(), 'a few seconds ago', 'now from now should display as in the past'); | |
7963 }); | |
7964 | |
7965 test('fromNow', function (assert) { | |
7966 assert.equal(moment().add({s: 30}).fromNow(), 'in a few seconds', 'in a few seconds'); | |
7967 assert.equal(moment().add({d: 5}).fromNow(), 'in 5 days', 'in 5 days'); | |
7968 }); | |
7969 | |
7970 test('calendar day', function (assert) { | |
7971 var a = moment().hours(2).minutes(0).seconds(0); | |
7972 | |
7973 assert.equal(moment(a).calendar(), 'Today at 2:00 AM', 'today at the same time'); | |
7974 assert.equal(moment(a).add({m: 25}).calendar(), 'Today at 2:25 AM', 'Now plus 25 min'); | |
7975 assert.equal(moment(a).add({h: 1}).calendar(), 'Today at 3:00 AM', 'Now plus 1 hour'); | |
7976 assert.equal(moment(a).add({d: 1}).calendar(), 'Tomorrow at 2:00 AM', 'tomorrow at the same time'); | |
7977 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Today at 1:00 AM', 'Now minus 1 hour'); | |
7978 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Yesterday at 2:00 AM', 'yesterday at the same time'); | |
7979 }); | |
7980 | |
7981 test('calendar next week', function (assert) { | |
7982 var i, m; | |
7983 | |
7984 for (i = 2; i < 7; i++) { | |
7985 m = moment().add({d: i}); | |
7986 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days current time'); | |
7987 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
7988 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days beginning of day'); | |
7989 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
7990 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days end of day'); | |
7991 } | |
7992 }); | |
7993 | |
7994 test('calendar last week', function (assert) { | |
7995 var i, m; | |
7996 | |
7997 for (i = 2; i < 7; i++) { | |
7998 m = moment().subtract({d: i}); | |
7999 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days current time'); | |
8000 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
8001 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days beginning of day'); | |
8002 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
8003 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days end of day'); | |
8004 } | |
8005 }); | |
8006 | |
8007 test('calendar all else', function (assert) { | |
8008 var weeksAgo = moment().subtract({w: 1}), | |
8009 weeksFromNow = moment().add({w: 1}); | |
8010 | |
8011 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
8012 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
8013 | |
8014 weeksAgo = moment().subtract({w: 2}); | |
8015 weeksFromNow = moment().add({w: 2}); | |
8016 | |
8017 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
8018 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
8019 }); | |
8020 | |
8021 test('weeks year starting sunday', function (assert) { | |
8022 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
8023 assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1'); | |
8024 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
8025 assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2'); | |
8026 assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3'); | |
8027 }); | |
8028 | |
8029 test('weeks year starting monday', function (assert) { | |
8030 assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1'); | |
8031 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
8032 assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1'); | |
8033 assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2'); | |
8034 assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2'); | |
8035 assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3'); | |
8036 }); | |
8037 | |
8038 test('weeks year starting tuesday', function (assert) { | |
8039 assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52'); | |
8040 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
8041 assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1'); | |
8042 assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2'); | |
8043 assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2'); | |
8044 assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3'); | |
8045 }); | |
8046 | |
8047 test('weeks year starting wednesday', function (assert) { | |
8048 assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1'); | |
8049 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
8050 assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1'); | |
8051 assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2'); | |
8052 assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2'); | |
8053 assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3'); | |
8054 }); | |
8055 | |
8056 test('weeks year starting thursday', function (assert) { | |
8057 assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1'); | |
8058 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
8059 assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1'); | |
8060 assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2'); | |
8061 assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2'); | |
8062 assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3'); | |
8063 }); | |
8064 | |
8065 test('weeks year starting friday', function (assert) { | |
8066 assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1'); | |
8067 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
8068 assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1'); | |
8069 assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2'); | |
8070 assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2'); | |
8071 assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3'); | |
8072 }); | |
8073 | |
8074 test('weeks year starting saturday', function (assert) { | |
8075 assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1'); | |
8076 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
8077 assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2'); | |
8078 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2'); | |
8079 assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3'); | |
8080 }); | |
8081 | |
8082 test('weeks year starting sunday format', function (assert) { | |
8083 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1st', 'Jan 1 2012 should be week 1'); | |
8084 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1st', 'Jan 7 2012 should be week 1'); | |
8085 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2nd', 'Jan 8 2012 should be week 2'); | |
8086 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2nd', 'Jan 14 2012 should be week 2'); | |
8087 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3rd', 'Jan 15 2012 should be week 3'); | |
8088 }); | |
8089 | |
8090 test('lenient ordinal parsing', function (assert) { | |
8091 var i, ordinalStr, testMoment; | |
8092 for (i = 1; i <= 31; ++i) { | |
8093 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
8094 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
8095 assert.equal(testMoment.year(), 2014, | |
8096 'lenient ordinal parsing ' + i + ' year check'); | |
8097 assert.equal(testMoment.month(), 0, | |
8098 'lenient ordinal parsing ' + i + ' month check'); | |
8099 assert.equal(testMoment.date(), i, | |
8100 'lenient ordinal parsing ' + i + ' date check'); | |
8101 } | |
8102 }); | |
8103 | |
8104 test('lenient ordinal parsing of number', function (assert) { | |
8105 var i, testMoment; | |
8106 for (i = 1; i <= 31; ++i) { | |
8107 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
8108 assert.equal(testMoment.year(), 2014, | |
8109 'lenient ordinal parsing of number ' + i + ' year check'); | |
8110 assert.equal(testMoment.month(), 0, | |
8111 'lenient ordinal parsing of number ' + i + ' month check'); | |
8112 assert.equal(testMoment.date(), i, | |
8113 'lenient ordinal parsing of number ' + i + ' date check'); | |
8114 } | |
8115 }); | |
8116 | |
8117 test('strict ordinal parsing', function (assert) { | |
8118 var i, ordinalStr, testMoment; | |
8119 for (i = 1; i <= 31; ++i) { | |
8120 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
8121 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
8122 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
8123 } | |
8124 }); | |
8125 | |
8126 })); | |
8127 | |
8128 (function (global, factory) { | |
8129 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
8130 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
8131 factory(global.moment) | |
8132 }(this, function (moment) { 'use strict'; | |
8133 | |
8134 /*global QUnit:false*/ | |
8135 | |
8136 var test = QUnit.test; | |
8137 | |
8138 function module (name, lifecycle) { | |
8139 QUnit.module(name, { | |
8140 setup : function () { | |
8141 moment.locale('en'); | |
8142 moment.createFromInputFallback = function () { | |
8143 throw new Error('input not handled by moment'); | |
8144 }; | |
8145 if (lifecycle && lifecycle.setup) { | |
8146 lifecycle.setup(); | |
8147 } | |
8148 }, | |
8149 teardown : function () { | |
8150 if (lifecycle && lifecycle.teardown) { | |
8151 lifecycle.teardown(); | |
8152 } | |
8153 } | |
8154 }); | |
8155 } | |
8156 | |
8157 function localeModule (name, lifecycle) { | |
8158 QUnit.module('locale:' + name, { | |
8159 setup : function () { | |
8160 moment.locale(name); | |
8161 moment.createFromInputFallback = function () { | |
8162 throw new Error('input not handled by moment'); | |
8163 }; | |
8164 if (lifecycle && lifecycle.setup) { | |
8165 lifecycle.setup(); | |
8166 } | |
8167 }, | |
8168 teardown : function () { | |
8169 moment.locale('en'); | |
8170 if (lifecycle && lifecycle.teardown) { | |
8171 lifecycle.teardown(); | |
8172 } | |
8173 } | |
8174 }); | |
8175 } | |
8176 | |
8177 localeModule('en-gb'); | |
8178 | |
8179 test('parse', function (assert) { | |
8180 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; | |
8181 function equalTest(input, mmm, i) { | |
8182 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
8183 } | |
8184 for (i = 0; i < 12; i++) { | |
8185 tests[i] = tests[i].split(' '); | |
8186 equalTest(tests[i][0], 'MMM', i); | |
8187 equalTest(tests[i][1], 'MMM', i); | |
8188 equalTest(tests[i][0], 'MMMM', i); | |
8189 equalTest(tests[i][1], 'MMMM', i); | |
8190 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
8191 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
8192 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
8193 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
8194 } | |
8195 }); | |
8196 | |
8197 test('format', function (assert) { | |
8198 var a = [ | |
8199 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Sunday, February 14th 2010, 3:25:50 pm'], | |
8200 ['ddd, hA', 'Sun, 3PM'], | |
8201 ['M Mo MM MMMM MMM', '2 2nd 02 February Feb'], | |
8202 ['YYYY YY', '2010 10'], | |
8203 ['D Do DD', '14 14th 14'], | |
8204 ['d do dddd ddd dd', '0 0th Sunday Sun Su'], | |
8205 ['DDD DDDo DDDD', '45 45th 045'], | |
8206 ['w wo ww', '6 6th 06'], | |
8207 ['h hh', '3 03'], | |
8208 ['H HH', '15 15'], | |
8209 ['m mm', '25 25'], | |
8210 ['s ss', '50 50'], | |
8211 ['a A', 'pm PM'], | |
8212 ['[the] DDDo [day of the year]', 'the 45th day of the year'], | |
8213 ['LTS', '15:25:50'], | |
8214 ['L', '14/02/2010'], | |
8215 ['LL', '14 February 2010'], | |
8216 ['LLL', '14 February 2010 15:25'], | |
8217 ['LLLL', 'Sunday, 14 February 2010 15:25'], | |
8218 ['l', '14/2/2010'], | |
8219 ['ll', '14 Feb 2010'], | |
8220 ['lll', '14 Feb 2010 15:25'], | |
8221 ['llll', 'Sun, 14 Feb 2010 15:25'] | |
8222 ], | |
8223 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
8224 i; | |
8225 for (i = 0; i < a.length; i++) { | |
8226 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
8227 } | |
8228 }); | |
8229 | |
8230 test('format ordinal', function (assert) { | |
8231 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1st', '1st'); | |
8232 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2nd', '2nd'); | |
8233 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3rd', '3rd'); | |
8234 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4th', '4th'); | |
8235 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5th', '5th'); | |
8236 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6th', '6th'); | |
8237 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7th', '7th'); | |
8238 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8th', '8th'); | |
8239 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9th', '9th'); | |
8240 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10th', '10th'); | |
8241 | |
8242 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11th', '11th'); | |
8243 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12th', '12th'); | |
8244 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13th', '13th'); | |
8245 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14th', '14th'); | |
8246 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15th', '15th'); | |
8247 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16th', '16th'); | |
8248 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17th', '17th'); | |
8249 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18th', '18th'); | |
8250 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19th', '19th'); | |
8251 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20th', '20th'); | |
8252 | |
8253 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21st', '21st'); | |
8254 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22nd', '22nd'); | |
8255 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23rd', '23rd'); | |
8256 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24th', '24th'); | |
8257 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25th', '25th'); | |
8258 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26th', '26th'); | |
8259 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27th', '27th'); | |
8260 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28th', '28th'); | |
8261 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29th', '29th'); | |
8262 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30th', '30th'); | |
8263 | |
8264 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31st', '31st'); | |
8265 }); | |
8266 | |
8267 test('format month', function (assert) { | |
8268 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; | |
8269 for (i = 0; i < expected.length; i++) { | |
8270 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
8271 } | |
8272 }); | |
8273 | |
8274 test('format week', function (assert) { | |
8275 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; | |
8276 for (i = 0; i < expected.length; i++) { | |
8277 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
8278 } | |
8279 }); | |
8280 | |
8281 test('from', function (assert) { | |
8282 var start = moment([2007, 1, 28]); | |
8283 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'a few seconds', '44 seconds = a few seconds'); | |
8284 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'a minute', '45 seconds = a minute'); | |
8285 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'a minute', '89 seconds = a minute'); | |
8286 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes'); | |
8287 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes'); | |
8288 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'an hour', '45 minutes = an hour'); | |
8289 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'an hour', '89 minutes = an hour'); | |
8290 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hours', '90 minutes = 2 hours'); | |
8291 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hours', '5 hours = 5 hours'); | |
8292 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hours', '21 hours = 21 hours'); | |
8293 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'a day', '22 hours = a day'); | |
8294 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'a day', '35 hours = a day'); | |
8295 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 days', '36 hours = 2 days'); | |
8296 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'a day', '1 day = a day'); | |
8297 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 days', '5 days = 5 days'); | |
8298 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 days', '25 days = 25 days'); | |
8299 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'a month', '26 days = a month'); | |
8300 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'a month', '30 days = a month'); | |
8301 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'a month', '43 days = a month'); | |
8302 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 months', '46 days = 2 months'); | |
8303 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 months', '75 days = 2 months'); | |
8304 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 months', '76 days = 3 months'); | |
8305 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'a month', '1 month = a month'); | |
8306 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 months', '5 months = 5 months'); | |
8307 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'a year', '345 days = a year'); | |
8308 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 years', '548 days = 2 years'); | |
8309 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'a year', '1 year = a year'); | |
8310 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 years', '5 years = 5 years'); | |
8311 }); | |
8312 | |
8313 test('suffix', function (assert) { | |
8314 assert.equal(moment(30000).from(0), 'in a few seconds', 'prefix'); | |
8315 assert.equal(moment(0).from(30000), 'a few seconds ago', 'suffix'); | |
8316 }); | |
8317 | |
8318 test('now from now', function (assert) { | |
8319 assert.equal(moment().fromNow(), 'a few seconds ago', 'now from now should display as in the past'); | |
8320 }); | |
8321 | |
8322 test('fromNow', function (assert) { | |
8323 assert.equal(moment().add({s: 30}).fromNow(), 'in a few seconds', 'in a few seconds'); | |
8324 assert.equal(moment().add({d: 5}).fromNow(), 'in 5 days', 'in 5 days'); | |
8325 }); | |
8326 | |
8327 test('calendar day', function (assert) { | |
8328 var a = moment().hours(2).minutes(0).seconds(0); | |
8329 | |
8330 assert.equal(moment(a).calendar(), 'Today at 02:00', 'today at the same time'); | |
8331 assert.equal(moment(a).add({m: 25}).calendar(), 'Today at 02:25', 'Now plus 25 min'); | |
8332 assert.equal(moment(a).add({h: 1}).calendar(), 'Today at 03:00', 'Now plus 1 hour'); | |
8333 assert.equal(moment(a).add({d: 1}).calendar(), 'Tomorrow at 02:00', 'tomorrow at the same time'); | |
8334 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Today at 01:00', 'Now minus 1 hour'); | |
8335 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Yesterday at 02:00', 'yesterday at the same time'); | |
8336 }); | |
8337 | |
8338 test('calendar next week', function (assert) { | |
8339 var i, m; | |
8340 for (i = 2; i < 7; i++) { | |
8341 m = moment().add({d: i}); | |
8342 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days current time'); | |
8343 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
8344 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days beginning of day'); | |
8345 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
8346 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days end of day'); | |
8347 } | |
8348 }); | |
8349 | |
8350 test('calendar last week', function (assert) { | |
8351 var i, m; | |
8352 | |
8353 for (i = 2; i < 7; i++) { | |
8354 m = moment().subtract({d: i}); | |
8355 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days current time'); | |
8356 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
8357 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days beginning of day'); | |
8358 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
8359 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days end of day'); | |
8360 } | |
8361 }); | |
8362 | |
8363 test('calendar all else', function (assert) { | |
8364 var weeksAgo = moment().subtract({w: 1}), | |
8365 weeksFromNow = moment().add({w: 1}); | |
8366 | |
8367 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
8368 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
8369 | |
8370 weeksAgo = moment().subtract({w: 2}); | |
8371 weeksFromNow = moment().add({w: 2}); | |
8372 | |
8373 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
8374 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
8375 }); | |
8376 | |
8377 test('weeks year starting sunday', function (assert) { | |
8378 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
8379 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
8380 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
8381 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
8382 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
8383 }); | |
8384 | |
8385 test('weeks year starting monday', function (assert) { | |
8386 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
8387 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
8388 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
8389 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
8390 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
8391 }); | |
8392 | |
8393 test('weeks year starting tuesday', function (assert) { | |
8394 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
8395 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
8396 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
8397 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
8398 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
8399 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
8400 }); | |
8401 | |
8402 test('weeks year starting wednesday', function (assert) { | |
8403 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
8404 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
8405 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
8406 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
8407 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
8408 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
8409 }); | |
8410 | |
8411 test('weeks year starting thursday', function (assert) { | |
8412 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
8413 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
8414 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
8415 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
8416 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
8417 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
8418 }); | |
8419 | |
8420 test('weeks year starting friday', function (assert) { | |
8421 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
8422 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
8423 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
8424 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
8425 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
8426 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
8427 }); | |
8428 | |
8429 test('weeks year starting saturday', function (assert) { | |
8430 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
8431 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
8432 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
8433 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
8434 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
8435 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
8436 }); | |
8437 | |
8438 test('weeks year starting sunday formatted', function (assert) { | |
8439 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52nd', 'Jan 1 2012 should be week 52'); | |
8440 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1st', 'Jan 2 2012 should be week 1'); | |
8441 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1st', 'Jan 8 2012 should be week 1'); | |
8442 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2nd', 'Jan 9 2012 should be week 2'); | |
8443 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2nd', 'Jan 15 2012 should be week 2'); | |
8444 }); | |
8445 | |
8446 test('lenient ordinal parsing', function (assert) { | |
8447 var i, ordinalStr, testMoment; | |
8448 for (i = 1; i <= 31; ++i) { | |
8449 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
8450 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
8451 assert.equal(testMoment.year(), 2014, | |
8452 'lenient ordinal parsing ' + i + ' year check'); | |
8453 assert.equal(testMoment.month(), 0, | |
8454 'lenient ordinal parsing ' + i + ' month check'); | |
8455 assert.equal(testMoment.date(), i, | |
8456 'lenient ordinal parsing ' + i + ' date check'); | |
8457 } | |
8458 }); | |
8459 | |
8460 test('lenient ordinal parsing of number', function (assert) { | |
8461 var i, testMoment; | |
8462 for (i = 1; i <= 31; ++i) { | |
8463 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
8464 assert.equal(testMoment.year(), 2014, | |
8465 'lenient ordinal parsing of number ' + i + ' year check'); | |
8466 assert.equal(testMoment.month(), 0, | |
8467 'lenient ordinal parsing of number ' + i + ' month check'); | |
8468 assert.equal(testMoment.date(), i, | |
8469 'lenient ordinal parsing of number ' + i + ' date check'); | |
8470 } | |
8471 }); | |
8472 | |
8473 test('strict ordinal parsing', function (assert) { | |
8474 var i, ordinalStr, testMoment; | |
8475 for (i = 1; i <= 31; ++i) { | |
8476 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
8477 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
8478 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
8479 } | |
8480 }); | |
8481 | |
8482 })); | |
8483 | |
8484 (function (global, factory) { | |
8485 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
8486 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
8487 factory(global.moment) | |
8488 }(this, function (moment) { 'use strict'; | |
8489 | |
8490 /*global QUnit:false*/ | |
8491 | |
8492 var test = QUnit.test; | |
8493 | |
8494 function module (name, lifecycle) { | |
8495 QUnit.module(name, { | |
8496 setup : function () { | |
8497 moment.locale('en'); | |
8498 moment.createFromInputFallback = function () { | |
8499 throw new Error('input not handled by moment'); | |
8500 }; | |
8501 if (lifecycle && lifecycle.setup) { | |
8502 lifecycle.setup(); | |
8503 } | |
8504 }, | |
8505 teardown : function () { | |
8506 if (lifecycle && lifecycle.teardown) { | |
8507 lifecycle.teardown(); | |
8508 } | |
8509 } | |
8510 }); | |
8511 } | |
8512 | |
8513 function localeModule (name, lifecycle) { | |
8514 QUnit.module('locale:' + name, { | |
8515 setup : function () { | |
8516 moment.locale(name); | |
8517 moment.createFromInputFallback = function () { | |
8518 throw new Error('input not handled by moment'); | |
8519 }; | |
8520 if (lifecycle && lifecycle.setup) { | |
8521 lifecycle.setup(); | |
8522 } | |
8523 }, | |
8524 teardown : function () { | |
8525 moment.locale('en'); | |
8526 if (lifecycle && lifecycle.teardown) { | |
8527 lifecycle.teardown(); | |
8528 } | |
8529 } | |
8530 }); | |
8531 } | |
8532 | |
8533 localeModule('en'); | |
8534 | |
8535 test('parse', function (assert) { | |
8536 var i, | |
8537 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('_'); | |
8538 | |
8539 function equalTest(input, mmm, i) { | |
8540 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
8541 } | |
8542 | |
8543 for (i = 0; i < 12; i++) { | |
8544 tests[i] = tests[i].split(' '); | |
8545 equalTest(tests[i][0], 'MMM', i); | |
8546 equalTest(tests[i][1], 'MMM', i); | |
8547 equalTest(tests[i][0], 'MMMM', i); | |
8548 equalTest(tests[i][1], 'MMMM', i); | |
8549 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
8550 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
8551 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
8552 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
8553 } | |
8554 }); | |
8555 | |
8556 test('format', function (assert) { | |
8557 var a = [ | |
8558 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Sunday, February 14th 2010, 3:25:50 pm'], | |
8559 ['ddd, hA', 'Sun, 3PM'], | |
8560 ['M Mo MM MMMM MMM', '2 2nd 02 February Feb'], | |
8561 ['YYYY YY', '2010 10'], | |
8562 ['D Do DD', '14 14th 14'], | |
8563 ['d do dddd ddd dd', '0 0th Sunday Sun Su'], | |
8564 ['DDD DDDo DDDD', '45 45th 045'], | |
8565 ['w wo ww', '8 8th 08'], | |
8566 ['h hh', '3 03'], | |
8567 ['H HH', '15 15'], | |
8568 ['m mm', '25 25'], | |
8569 ['s ss', '50 50'], | |
8570 ['a A', 'pm PM'], | |
8571 ['[the] DDDo [day of the year]', 'the 45th day of the year'], | |
8572 ['LTS', '3:25:50 PM'], | |
8573 ['L', '02/14/2010'], | |
8574 ['LL', 'February 14, 2010'], | |
8575 ['LLL', 'February 14, 2010 3:25 PM'], | |
8576 ['LLLL', 'Sunday, February 14, 2010 3:25 PM'], | |
8577 ['l', '2/14/2010'], | |
8578 ['ll', 'Feb 14, 2010'], | |
8579 ['lll', 'Feb 14, 2010 3:25 PM'], | |
8580 ['llll', 'Sun, Feb 14, 2010 3:25 PM'] | |
8581 ], | |
8582 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
8583 i; | |
8584 | |
8585 for (i = 0; i < a.length; i++) { | |
8586 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
8587 } | |
8588 }); | |
8589 | |
8590 test('format ordinal', function (assert) { | |
8591 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1st', '1st'); | |
8592 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2nd', '2nd'); | |
8593 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3rd', '3rd'); | |
8594 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4th', '4th'); | |
8595 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5th', '5th'); | |
8596 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6th', '6th'); | |
8597 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7th', '7th'); | |
8598 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8th', '8th'); | |
8599 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9th', '9th'); | |
8600 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10th', '10th'); | |
8601 | |
8602 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11th', '11th'); | |
8603 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12th', '12th'); | |
8604 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13th', '13th'); | |
8605 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14th', '14th'); | |
8606 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15th', '15th'); | |
8607 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16th', '16th'); | |
8608 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17th', '17th'); | |
8609 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18th', '18th'); | |
8610 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19th', '19th'); | |
8611 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20th', '20th'); | |
8612 | |
8613 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21st', '21st'); | |
8614 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22nd', '22nd'); | |
8615 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23rd', '23rd'); | |
8616 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24th', '24th'); | |
8617 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25th', '25th'); | |
8618 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26th', '26th'); | |
8619 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27th', '27th'); | |
8620 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28th', '28th'); | |
8621 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29th', '29th'); | |
8622 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30th', '30th'); | |
8623 | |
8624 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31st', '31st'); | |
8625 }); | |
8626 | |
8627 test('format month', function (assert) { | |
8628 var i, | |
8629 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('_'); | |
8630 | |
8631 for (i = 0; i < expected.length; i++) { | |
8632 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
8633 } | |
8634 }); | |
8635 | |
8636 test('format week', function (assert) { | |
8637 var i, | |
8638 expected = 'Sunday Sun Su_Monday Mon Mo_Tuesday Tue Tu_Wednesday Wed We_Thursday Thu Th_Friday Fri Fr_Saturday Sat Sa'.split('_'); | |
8639 | |
8640 for (i = 0; i < expected.length; i++) { | |
8641 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
8642 } | |
8643 }); | |
8644 | |
8645 test('from', function (assert) { | |
8646 var start = moment([2007, 1, 28]); | |
8647 | |
8648 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'a few seconds', '44 seconds = a few seconds'); | |
8649 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'a minute', '45 seconds = a minute'); | |
8650 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'a minute', '89 seconds = a minute'); | |
8651 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes'); | |
8652 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes'); | |
8653 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'an hour', '45 minutes = an hour'); | |
8654 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'an hour', '89 minutes = an hour'); | |
8655 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hours', '90 minutes = 2 hours'); | |
8656 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hours', '5 hours = 5 hours'); | |
8657 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hours', '21 hours = 21 hours'); | |
8658 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'a day', '22 hours = a day'); | |
8659 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'a day', '35 hours = a day'); | |
8660 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 days', '36 hours = 2 days'); | |
8661 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'a day', '1 day = a day'); | |
8662 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 days', '5 days = 5 days'); | |
8663 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 days', '25 days = 25 days'); | |
8664 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'a month', '26 days = a month'); | |
8665 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'a month', '30 days = a month'); | |
8666 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'a month', '43 days = a month'); | |
8667 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 months', '46 days = 2 months'); | |
8668 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 months', '75 days = 2 months'); | |
8669 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 months', '76 days = 3 months'); | |
8670 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'a month', '1 month = a month'); | |
8671 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 months', '5 months = 5 months'); | |
8672 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'a year', '345 days = a year'); | |
8673 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 years', '548 days = 2 years'); | |
8674 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'a year', '1 year = a year'); | |
8675 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 years', '5 years = 5 years'); | |
8676 }); | |
8677 | |
8678 test('suffix', function (assert) { | |
8679 assert.equal(moment(30000).from(0), 'in a few seconds', 'prefix'); | |
8680 assert.equal(moment(0).from(30000), 'a few seconds ago', 'suffix'); | |
8681 }); | |
8682 | |
8683 test('now from now', function (assert) { | |
8684 assert.equal(moment().fromNow(), 'a few seconds ago', 'now from now should display as in the past'); | |
8685 }); | |
8686 | |
8687 test('fromNow', function (assert) { | |
8688 assert.equal(moment().add({s: 30}).fromNow(), 'in a few seconds', 'in a few seconds'); | |
8689 assert.equal(moment().add({d: 5}).fromNow(), 'in 5 days', 'in 5 days'); | |
8690 }); | |
8691 | |
8692 test('calendar day', function (assert) { | |
8693 var a = moment().hours(2).minutes(0).seconds(0); | |
8694 | |
8695 assert.equal(moment(a).calendar(), 'Today at 2:00 AM', 'today at the same time'); | |
8696 assert.equal(moment(a).add({m: 25}).calendar(), 'Today at 2:25 AM', 'Now plus 25 min'); | |
8697 assert.equal(moment(a).add({h: 1}).calendar(), 'Today at 3:00 AM', 'Now plus 1 hour'); | |
8698 assert.equal(moment(a).add({d: 1}).calendar(), 'Tomorrow at 2:00 AM', 'tomorrow at the same time'); | |
8699 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Today at 1:00 AM', 'Now minus 1 hour'); | |
8700 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Yesterday at 2:00 AM', 'yesterday at the same time'); | |
8701 }); | |
8702 | |
8703 test('calendar next week', function (assert) { | |
8704 var i, m; | |
8705 | |
8706 for (i = 2; i < 7; i++) { | |
8707 m = moment().add({d: i}); | |
8708 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days current time'); | |
8709 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
8710 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days beginning of day'); | |
8711 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
8712 assert.equal(m.calendar(), m.format('dddd [at] LT'), 'Today + ' + i + ' days end of day'); | |
8713 } | |
8714 }); | |
8715 | |
8716 test('calendar last week', function (assert) { | |
8717 var i, m; | |
8718 | |
8719 for (i = 2; i < 7; i++) { | |
8720 m = moment().subtract({d: i}); | |
8721 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days current time'); | |
8722 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
8723 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days beginning of day'); | |
8724 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
8725 assert.equal(m.calendar(), m.format('[Last] dddd [at] LT'), 'Today - ' + i + ' days end of day'); | |
8726 } | |
8727 }); | |
8728 | |
8729 test('calendar all else', function (assert) { | |
8730 var weeksAgo = moment().subtract({w: 1}), | |
8731 weeksFromNow = moment().add({w: 1}); | |
8732 | |
8733 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
8734 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
8735 | |
8736 weeksAgo = moment().subtract({w: 2}); | |
8737 weeksFromNow = moment().add({w: 2}); | |
8738 | |
8739 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
8740 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
8741 }); | |
8742 | |
8743 test('weeks year starting sunday', function (assert) { | |
8744 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
8745 assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1'); | |
8746 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
8747 assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2'); | |
8748 assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3'); | |
8749 }); | |
8750 | |
8751 test('weeks year starting monday', function (assert) { | |
8752 assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1'); | |
8753 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
8754 assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1'); | |
8755 assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2'); | |
8756 assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2'); | |
8757 assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3'); | |
8758 }); | |
8759 | |
8760 test('weeks year starting tuesday', function (assert) { | |
8761 assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52'); | |
8762 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
8763 assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1'); | |
8764 assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2'); | |
8765 assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2'); | |
8766 assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3'); | |
8767 }); | |
8768 | |
8769 test('weeks year starting wednesday', function (assert) { | |
8770 assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1'); | |
8771 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
8772 assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1'); | |
8773 assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2'); | |
8774 assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2'); | |
8775 assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3'); | |
8776 }); | |
8777 | |
8778 test('weeks year starting thursday', function (assert) { | |
8779 assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1'); | |
8780 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
8781 assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1'); | |
8782 assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2'); | |
8783 assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2'); | |
8784 assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3'); | |
8785 }); | |
8786 | |
8787 test('weeks year starting friday', function (assert) { | |
8788 assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1'); | |
8789 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
8790 assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1'); | |
8791 assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2'); | |
8792 assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2'); | |
8793 assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3'); | |
8794 }); | |
8795 | |
8796 test('weeks year starting saturday', function (assert) { | |
8797 assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1'); | |
8798 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
8799 assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2'); | |
8800 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2'); | |
8801 assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3'); | |
8802 }); | |
8803 | |
8804 test('weeks year starting sunday format', function (assert) { | |
8805 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1st', 'Jan 1 2012 should be week 1'); | |
8806 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1st', 'Jan 7 2012 should be week 1'); | |
8807 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2nd', 'Jan 8 2012 should be week 2'); | |
8808 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2nd', 'Jan 14 2012 should be week 2'); | |
8809 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3rd', 'Jan 15 2012 should be week 3'); | |
8810 }); | |
8811 | |
8812 test('lenient ordinal parsing', function (assert) { | |
8813 var i, ordinalStr, testMoment; | |
8814 for (i = 1; i <= 31; ++i) { | |
8815 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
8816 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
8817 assert.equal(testMoment.year(), 2014, | |
8818 'lenient ordinal parsing ' + i + ' year check'); | |
8819 assert.equal(testMoment.month(), 0, | |
8820 'lenient ordinal parsing ' + i + ' month check'); | |
8821 assert.equal(testMoment.date(), i, | |
8822 'lenient ordinal parsing ' + i + ' date check'); | |
8823 } | |
8824 }); | |
8825 | |
8826 test('lenient ordinal parsing of number', function (assert) { | |
8827 var i, testMoment; | |
8828 for (i = 1; i <= 31; ++i) { | |
8829 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
8830 assert.equal(testMoment.year(), 2014, | |
8831 'lenient ordinal parsing of number ' + i + ' year check'); | |
8832 assert.equal(testMoment.month(), 0, | |
8833 'lenient ordinal parsing of number ' + i + ' month check'); | |
8834 assert.equal(testMoment.date(), i, | |
8835 'lenient ordinal parsing of number ' + i + ' date check'); | |
8836 } | |
8837 }); | |
8838 | |
8839 test('strict ordinal parsing', function (assert) { | |
8840 var i, ordinalStr, testMoment; | |
8841 for (i = 1; i <= 31; ++i) { | |
8842 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
8843 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
8844 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
8845 } | |
8846 }); | |
8847 | |
8848 })); | |
8849 | |
8850 (function (global, factory) { | |
8851 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
8852 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
8853 factory(global.moment) | |
8854 }(this, function (moment) { 'use strict'; | |
8855 | |
8856 /*global QUnit:false*/ | |
8857 | |
8858 var test = QUnit.test; | |
8859 | |
8860 function module (name, lifecycle) { | |
8861 QUnit.module(name, { | |
8862 setup : function () { | |
8863 moment.locale('en'); | |
8864 moment.createFromInputFallback = function () { | |
8865 throw new Error('input not handled by moment'); | |
8866 }; | |
8867 if (lifecycle && lifecycle.setup) { | |
8868 lifecycle.setup(); | |
8869 } | |
8870 }, | |
8871 teardown : function () { | |
8872 if (lifecycle && lifecycle.teardown) { | |
8873 lifecycle.teardown(); | |
8874 } | |
8875 } | |
8876 }); | |
8877 } | |
8878 | |
8879 function localeModule (name, lifecycle) { | |
8880 QUnit.module('locale:' + name, { | |
8881 setup : function () { | |
8882 moment.locale(name); | |
8883 moment.createFromInputFallback = function () { | |
8884 throw new Error('input not handled by moment'); | |
8885 }; | |
8886 if (lifecycle && lifecycle.setup) { | |
8887 lifecycle.setup(); | |
8888 } | |
8889 }, | |
8890 teardown : function () { | |
8891 moment.locale('en'); | |
8892 if (lifecycle && lifecycle.teardown) { | |
8893 lifecycle.teardown(); | |
8894 } | |
8895 } | |
8896 }); | |
8897 } | |
8898 | |
8899 localeModule('eo'); | |
8900 | |
8901 test('parse', function (assert) { | |
8902 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; | |
8903 function equalTest(input, mmm, i) { | |
8904 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
8905 } | |
8906 for (i = 0; i < 12; i++) { | |
8907 tests[i] = tests[i].split(' '); | |
8908 equalTest(tests[i][0], 'MMM', i); | |
8909 equalTest(tests[i][1], 'MMM', i); | |
8910 equalTest(tests[i][0], 'MMMM', i); | |
8911 equalTest(tests[i][1], 'MMMM', i); | |
8912 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
8913 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
8914 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
8915 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
8916 } | |
8917 }); | |
8918 | |
8919 test('format', function (assert) { | |
8920 var a = [ | |
8921 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Dimanĉo, februaro 14a 2010, 3:25:50 p.t.m.'], | |
8922 ['ddd, hA', 'Dim, 3P.T.M.'], | |
8923 ['M Mo MM MMMM MMM', '2 2a 02 februaro feb'], | |
8924 ['YYYY YY', '2010 10'], | |
8925 ['D Do DD', '14 14a 14'], | |
8926 ['d do dddd ddd dd', '0 0a Dimanĉo Dim Di'], | |
8927 ['DDD DDDo DDDD', '45 45a 045'], | |
8928 ['w wo ww', '7 7a 07'], | |
8929 ['h hh', '3 03'], | |
8930 ['H HH', '15 15'], | |
8931 ['m mm', '25 25'], | |
8932 ['s ss', '50 50'], | |
8933 ['a A', 'p.t.m. P.T.M.'], | |
8934 ['[la] DDDo [tago] [de] [la] [jaro]', 'la 45a tago de la jaro'], | |
8935 ['LTS', '15:25:50'], | |
8936 ['L', '2010-02-14'], | |
8937 ['LL', '14-an de februaro, 2010'], | |
8938 ['LLL', '14-an de februaro, 2010 15:25'], | |
8939 ['LLLL', 'Dimanĉo, la 14-an de februaro, 2010 15:25'], | |
8940 ['l', '2010-2-14'], | |
8941 ['ll', '14-an de feb, 2010'], | |
8942 ['lll', '14-an de feb, 2010 15:25'], | |
8943 ['llll', 'Dim, la 14-an de feb, 2010 15:25'] | |
8944 ], | |
8945 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
8946 i; | |
8947 for (i = 0; i < a.length; i++) { | |
8948 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
8949 } | |
8950 }); | |
8951 | |
8952 test('format ordinal', function (assert) { | |
8953 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1a', '1a'); | |
8954 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2a', '2a'); | |
8955 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3a', '3a'); | |
8956 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4a', '4a'); | |
8957 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5a', '5a'); | |
8958 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6a', '6a'); | |
8959 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7a', '7a'); | |
8960 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8a', '8a'); | |
8961 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9a', '9a'); | |
8962 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10a', '10a'); | |
8963 | |
8964 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11a', '11a'); | |
8965 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12a', '12a'); | |
8966 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13a', '13a'); | |
8967 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14a', '14a'); | |
8968 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15a', '15a'); | |
8969 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16a', '16a'); | |
8970 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17a', '17a'); | |
8971 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18a', '18a'); | |
8972 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19a', '19a'); | |
8973 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20a', '20a'); | |
8974 | |
8975 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21a', '21a'); | |
8976 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22a', '22a'); | |
8977 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23a', '23a'); | |
8978 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24a', '24a'); | |
8979 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25a', '25a'); | |
8980 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26a', '26a'); | |
8981 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27a', '27a'); | |
8982 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28a', '28a'); | |
8983 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29a', '29a'); | |
8984 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30a', '30a'); | |
8985 | |
8986 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31a', '31a'); | |
8987 }); | |
8988 | |
8989 test('format month', function (assert) { | |
8990 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; | |
8991 for (i = 0; i < expected.length; i++) { | |
8992 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
8993 } | |
8994 }); | |
8995 | |
8996 test('format week', function (assert) { | |
8997 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; | |
8998 for (i = 0; i < expected.length; i++) { | |
8999 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
9000 } | |
9001 }); | |
9002 | |
9003 test('from', function (assert) { | |
9004 var start = moment([2007, 1, 28]); | |
9005 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'sekundoj', '44 seconds = a few seconds'); | |
9006 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minuto', '45 seconds = a minute'); | |
9007 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minuto', '89 seconds = a minute'); | |
9008 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutoj', '90 seconds = 2 minutes'); | |
9009 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutoj', '44 minutes = 44 minutes'); | |
9010 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'horo', '45 minutes = an hour'); | |
9011 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'horo', '89 minutes = an hour'); | |
9012 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 horoj', '90 minutes = 2 hours'); | |
9013 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 horoj', '5 hours = 5 hours'); | |
9014 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 horoj', '21 hours = 21 hours'); | |
9015 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'tago', '22 hours = a day'); | |
9016 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'tago', '35 hours = a day'); | |
9017 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 tagoj', '36 hours = 2 days'); | |
9018 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'tago', '1 day = a day'); | |
9019 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 tagoj', '5 days = 5 days'); | |
9020 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 tagoj', '25 days = 25 days'); | |
9021 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'monato', '26 days = a month'); | |
9022 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'monato', '30 days = a month'); | |
9023 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'monato', '43 days = a month'); | |
9024 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 monatoj', '46 days = 2 months'); | |
9025 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 monatoj', '75 days = 2 months'); | |
9026 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 monatoj', '76 days = 3 months'); | |
9027 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'monato', '1 month = a month'); | |
9028 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 monatoj', '5 months = 5 months'); | |
9029 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'jaro', '345 days = a year'); | |
9030 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 jaroj', '548 days = 2 years'); | |
9031 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'jaro', '1 year = a year'); | |
9032 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 jaroj', '5 years = 5 years'); | |
9033 }); | |
9034 | |
9035 test('suffix', function (assert) { | |
9036 assert.equal(moment(30000).from(0), 'je sekundoj', 'je prefix'); | |
9037 assert.equal(moment(0).from(30000), 'antaŭ sekundoj', 'antaŭ prefix'); | |
9038 }); | |
9039 | |
9040 test('now from now', function (assert) { | |
9041 assert.equal(moment().fromNow(), 'antaŭ sekundoj', 'now from now should display as in the past'); | |
9042 }); | |
9043 | |
9044 test('fromNow', function (assert) { | |
9045 assert.equal(moment().add({s: 30}).fromNow(), 'je sekundoj', 'je sekundoj'); | |
9046 assert.equal(moment().add({d: 5}).fromNow(), 'je 5 tagoj', 'je 5 tagoj'); | |
9047 }); | |
9048 | |
9049 test('calendar day', function (assert) { | |
9050 var a = moment().hours(2).minutes(0).seconds(0); | |
9051 | |
9052 assert.equal(moment(a).calendar(), 'Hodiaŭ je 02:00', 'today at the same time'); | |
9053 assert.equal(moment(a).add({m: 25}).calendar(), 'Hodiaŭ je 02:25', 'Now plus 25 min'); | |
9054 assert.equal(moment(a).add({h: 1}).calendar(), 'Hodiaŭ je 03:00', 'Now plus 1 hour'); | |
9055 assert.equal(moment(a).add({d: 1}).calendar(), 'Morgaŭ je 02:00', 'tomorrow at the same time'); | |
9056 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Hodiaŭ je 01:00', 'Now minus 1 hour'); | |
9057 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Hieraŭ je 02:00', 'yesterday at the same time'); | |
9058 }); | |
9059 | |
9060 test('calendar next week', function (assert) { | |
9061 var i, m; | |
9062 | |
9063 for (i = 2; i < 7; i++) { | |
9064 m = moment().add({d: i}); | |
9065 assert.equal(m.calendar(), m.format('dddd [je] LT'), 'Today + ' + i + ' days current time'); | |
9066 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
9067 assert.equal(m.calendar(), m.format('dddd [je] LT'), 'Today + ' + i + ' days beginning of day'); | |
9068 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
9069 assert.equal(m.calendar(), m.format('dddd [je] LT'), 'Today + ' + i + ' days end of day'); | |
9070 } | |
9071 }); | |
9072 | |
9073 test('calendar last week', function (assert) { | |
9074 var i, m; | |
9075 | |
9076 for (i = 2; i < 7; i++) { | |
9077 m = moment().subtract({d: i}); | |
9078 assert.equal(m.calendar(), m.format('[pasinta] dddd [je] LT'), 'Today - ' + i + ' days current time'); | |
9079 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
9080 assert.equal(m.calendar(), m.format('[pasinta] dddd [je] LT'), 'Today - ' + i + ' days beginning of day'); | |
9081 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
9082 assert.equal(m.calendar(), m.format('[pasinta] dddd [je] LT'), 'Today - ' + i + ' days end of day'); | |
9083 } | |
9084 }); | |
9085 | |
9086 test('calendar all else', function (assert) { | |
9087 var weeksAgo = moment().subtract({w: 1}), | |
9088 weeksFromNow = moment().add({w: 1}); | |
9089 | |
9090 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
9091 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
9092 | |
9093 weeksAgo = moment().subtract({w: 2}); | |
9094 weeksFromNow = moment().add({w: 2}); | |
9095 | |
9096 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
9097 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
9098 }); | |
9099 | |
9100 test('weeks year starting sunday', function (assert) { | |
9101 assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1'); | |
9102 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
9103 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2'); | |
9104 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
9105 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3'); | |
9106 }); | |
9107 | |
9108 test('weeks year starting monday', function (assert) { | |
9109 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
9110 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
9111 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
9112 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
9113 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
9114 }); | |
9115 | |
9116 test('weeks year starting tuesday', function (assert) { | |
9117 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
9118 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
9119 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
9120 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
9121 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
9122 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
9123 }); | |
9124 | |
9125 test('weeks year starting wednesday', function (assert) { | |
9126 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
9127 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
9128 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
9129 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
9130 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
9131 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
9132 }); | |
9133 | |
9134 test('weeks year starting thursday', function (assert) { | |
9135 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
9136 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
9137 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
9138 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
9139 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
9140 assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3'); | |
9141 }); | |
9142 | |
9143 test('weeks year starting friday', function (assert) { | |
9144 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1'); | |
9145 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
9146 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1'); | |
9147 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2'); | |
9148 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2'); | |
9149 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3'); | |
9150 }); | |
9151 | |
9152 test('weeks year starting saturday', function (assert) { | |
9153 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1'); | |
9154 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
9155 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1'); | |
9156 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2'); | |
9157 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2'); | |
9158 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3'); | |
9159 }); | |
9160 | |
9161 test('weeks year starting sunday formatted', function (assert) { | |
9162 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1a', 'Dec 26 2011 should be week 1'); | |
9163 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1a', 'Jan 1 2012 should be week 1'); | |
9164 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2a', 'Jan 2 2012 should be week 2'); | |
9165 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2a', 'Jan 8 2012 should be week 2'); | |
9166 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3a', 'Jan 9 2012 should be week 3'); | |
9167 }); | |
9168 | |
9169 test('lenient ordinal parsing', function (assert) { | |
9170 var i, ordinalStr, testMoment; | |
9171 for (i = 1; i <= 31; ++i) { | |
9172 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
9173 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
9174 assert.equal(testMoment.year(), 2014, | |
9175 'lenient ordinal parsing ' + i + ' year check'); | |
9176 assert.equal(testMoment.month(), 0, | |
9177 'lenient ordinal parsing ' + i + ' month check'); | |
9178 assert.equal(testMoment.date(), i, | |
9179 'lenient ordinal parsing ' + i + ' date check'); | |
9180 } | |
9181 }); | |
9182 | |
9183 test('lenient ordinal parsing of number', function (assert) { | |
9184 var i, testMoment; | |
9185 for (i = 1; i <= 31; ++i) { | |
9186 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
9187 assert.equal(testMoment.year(), 2014, | |
9188 'lenient ordinal parsing of number ' + i + ' year check'); | |
9189 assert.equal(testMoment.month(), 0, | |
9190 'lenient ordinal parsing of number ' + i + ' month check'); | |
9191 assert.equal(testMoment.date(), i, | |
9192 'lenient ordinal parsing of number ' + i + ' date check'); | |
9193 } | |
9194 }); | |
9195 | |
9196 test('strict ordinal parsing', function (assert) { | |
9197 var i, ordinalStr, testMoment; | |
9198 for (i = 1; i <= 31; ++i) { | |
9199 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
9200 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
9201 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
9202 } | |
9203 }); | |
9204 | |
9205 })); | |
9206 | |
9207 (function (global, factory) { | |
9208 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
9209 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
9210 factory(global.moment) | |
9211 }(this, function (moment) { 'use strict'; | |
9212 | |
9213 /*global QUnit:false*/ | |
9214 | |
9215 var test = QUnit.test; | |
9216 | |
9217 function module (name, lifecycle) { | |
9218 QUnit.module(name, { | |
9219 setup : function () { | |
9220 moment.locale('en'); | |
9221 moment.createFromInputFallback = function () { | |
9222 throw new Error('input not handled by moment'); | |
9223 }; | |
9224 if (lifecycle && lifecycle.setup) { | |
9225 lifecycle.setup(); | |
9226 } | |
9227 }, | |
9228 teardown : function () { | |
9229 if (lifecycle && lifecycle.teardown) { | |
9230 lifecycle.teardown(); | |
9231 } | |
9232 } | |
9233 }); | |
9234 } | |
9235 | |
9236 function localeModule (name, lifecycle) { | |
9237 QUnit.module('locale:' + name, { | |
9238 setup : function () { | |
9239 moment.locale(name); | |
9240 moment.createFromInputFallback = function () { | |
9241 throw new Error('input not handled by moment'); | |
9242 }; | |
9243 if (lifecycle && lifecycle.setup) { | |
9244 lifecycle.setup(); | |
9245 } | |
9246 }, | |
9247 teardown : function () { | |
9248 moment.locale('en'); | |
9249 if (lifecycle && lifecycle.teardown) { | |
9250 lifecycle.teardown(); | |
9251 } | |
9252 } | |
9253 }); | |
9254 } | |
9255 | |
9256 localeModule('es'); | |
9257 | |
9258 test('parse', function (assert) { | |
9259 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; | |
9260 function equalTest(input, mmm, i) { | |
9261 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
9262 } | |
9263 for (i = 0; i < 12; i++) { | |
9264 tests[i] = tests[i].split(' '); | |
9265 equalTest(tests[i][0], 'MMM', i); | |
9266 equalTest(tests[i][1], 'MMM', i); | |
9267 equalTest(tests[i][0], 'MMMM', i); | |
9268 equalTest(tests[i][1], 'MMMM', i); | |
9269 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
9270 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
9271 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
9272 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
9273 } | |
9274 }); | |
9275 | |
9276 test('format', function (assert) { | |
9277 var a = [ | |
9278 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Domingo, Febrero 14º 2010, 3:25:50 pm'], | |
9279 ['ddd, hA', 'Dom., 3PM'], | |
9280 ['M Mo MM MMMM MMM', '2 2º 02 Febrero Feb.'], | |
9281 ['YYYY YY', '2010 10'], | |
9282 ['D Do DD', '14 14º 14'], | |
9283 ['d do dddd ddd dd', '0 0º Domingo Dom. Do'], | |
9284 ['DDD DDDo DDDD', '45 45º 045'], | |
9285 ['w wo ww', '6 6º 06'], | |
9286 ['YYYY-MMM-DD', '2010-Feb-14'], | |
9287 ['h hh', '3 03'], | |
9288 ['H HH', '15 15'], | |
9289 ['m mm', '25 25'], | |
9290 ['s ss', '50 50'], | |
9291 ['a A', 'pm PM'], | |
9292 ['[the] DDDo [day of the year]', 'the 45º day of the year'], | |
9293 ['LTS', '15:25:50'], | |
9294 ['L', '14/02/2010'], | |
9295 ['LL', '14 de Febrero de 2010'], | |
9296 ['LLL', '14 de Febrero de 2010 15:25'], | |
9297 ['LLLL', 'Domingo, 14 de Febrero de 2010 15:25'], | |
9298 ['l', '14/2/2010'], | |
9299 ['ll', '14 de Feb. de 2010'], | |
9300 ['lll', '14 de Feb. de 2010 15:25'], | |
9301 ['llll', 'Dom., 14 de Feb. de 2010 15:25'] | |
9302 ], | |
9303 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
9304 i; | |
9305 for (i = 0; i < a.length; i++) { | |
9306 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
9307 } | |
9308 }); | |
9309 | |
9310 test('format ordinal', function (assert) { | |
9311 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1º', '1º'); | |
9312 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2º', '2º'); | |
9313 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3º', '3º'); | |
9314 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4º', '4º'); | |
9315 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5º', '5º'); | |
9316 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6º', '6º'); | |
9317 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7º', '7º'); | |
9318 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8º', '8º'); | |
9319 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9º', '9º'); | |
9320 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10º', '10º'); | |
9321 | |
9322 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11º', '11º'); | |
9323 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12º', '12º'); | |
9324 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13º', '13º'); | |
9325 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14º', '14º'); | |
9326 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15º', '15º'); | |
9327 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16º', '16º'); | |
9328 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17º', '17º'); | |
9329 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18º', '18º'); | |
9330 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19º', '19º'); | |
9331 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20º', '20º'); | |
9332 | |
9333 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21º', '21º'); | |
9334 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22º', '22º'); | |
9335 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23º', '23º'); | |
9336 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24º', '24º'); | |
9337 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25º', '25º'); | |
9338 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26º', '26º'); | |
9339 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27º', '27º'); | |
9340 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28º', '28º'); | |
9341 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29º', '29º'); | |
9342 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30º', '30º'); | |
9343 | |
9344 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31º', '31º'); | |
9345 }); | |
9346 | |
9347 test('format month', function (assert) { | |
9348 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; | |
9349 for (i = 0; i < expected.length; i++) { | |
9350 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
9351 } | |
9352 }); | |
9353 | |
9354 test('format week', function (assert) { | |
9355 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; | |
9356 for (i = 0; i < expected.length; i++) { | |
9357 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
9358 } | |
9359 }); | |
9360 | |
9361 test('from', function (assert) { | |
9362 var start = moment([2007, 1, 28]); | |
9363 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'unos segundos', '44 seconds = a few seconds'); | |
9364 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'un minuto', '45 seconds = a minute'); | |
9365 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'un minuto', '89 seconds = a minute'); | |
9366 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutos', '90 seconds = 2 minutes'); | |
9367 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutos', '44 minutes = 44 minutes'); | |
9368 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'una hora', '45 minutes = an hour'); | |
9369 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'una hora', '89 minutes = an hour'); | |
9370 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 horas', '90 minutes = 2 hours'); | |
9371 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 horas', '5 hours = 5 hours'); | |
9372 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 horas', '21 hours = 21 hours'); | |
9373 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un día', '22 hours = a day'); | |
9374 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un día', '35 hours = a day'); | |
9375 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 días', '36 hours = 2 days'); | |
9376 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un día', '1 day = a day'); | |
9377 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 días', '5 days = 5 days'); | |
9378 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 días', '25 days = 25 days'); | |
9379 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'un mes', '26 days = a month'); | |
9380 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'un mes', '30 days = a month'); | |
9381 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'un mes', '43 days = a month'); | |
9382 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 meses', '46 days = 2 months'); | |
9383 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 meses', '75 days = 2 months'); | |
9384 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 meses', '76 days = 3 months'); | |
9385 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'un mes', '1 month = a month'); | |
9386 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 meses', '5 months = 5 months'); | |
9387 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un año', '345 days = a year'); | |
9388 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 años', '548 days = 2 years'); | |
9389 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un año', '1 year = a year'); | |
9390 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 años', '5 years = 5 years'); | |
9391 }); | |
9392 | |
9393 test('suffix', function (assert) { | |
9394 assert.equal(moment(30000).from(0), 'en unos segundos', 'prefix'); | |
9395 assert.equal(moment(0).from(30000), 'hace unos segundos', 'suffix'); | |
9396 }); | |
9397 | |
9398 test('now from now', function (assert) { | |
9399 assert.equal(moment().fromNow(), 'hace unos segundos', 'now from now should display as in the past'); | |
9400 }); | |
9401 | |
9402 test('fromNow', function (assert) { | |
9403 assert.equal(moment().add({s: 30}).fromNow(), 'en unos segundos', 'en unos segundos'); | |
9404 assert.equal(moment().add({d: 5}).fromNow(), 'en 5 días', 'en 5 días'); | |
9405 }); | |
9406 | |
9407 test('calendar day', function (assert) { | |
9408 var a = moment().hours(2).minutes(0).seconds(0); | |
9409 | |
9410 assert.equal(moment(a).calendar(), 'hoy a las 2:00', 'today at the same time'); | |
9411 assert.equal(moment(a).add({m: 25}).calendar(), 'hoy a las 2:25', 'Now plus 25 min'); | |
9412 assert.equal(moment(a).add({h: 1}).calendar(), 'hoy a las 3:00', 'Now plus 1 hour'); | |
9413 assert.equal(moment(a).add({d: 1}).calendar(), 'mañana a las 2:00', 'tomorrow at the same time'); | |
9414 assert.equal(moment(a).add({d: 1, h : -1}).calendar(), 'mañana a la 1:00', 'tomorrow minus 1 hour'); | |
9415 assert.equal(moment(a).subtract({h: 1}).calendar(), 'hoy a la 1:00', 'Now minus 1 hour'); | |
9416 assert.equal(moment(a).subtract({d: 1}).calendar(), 'ayer a las 2:00', 'yesterday at the same time'); | |
9417 }); | |
9418 | |
9419 test('calendar next week', function (assert) { | |
9420 var i, m; | |
9421 | |
9422 for (i = 2; i < 7; i++) { | |
9423 m = moment().add({d: i}); | |
9424 assert.equal(m.calendar(), m.format('dddd [a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today + ' + i + ' days current time'); | |
9425 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
9426 assert.equal(m.calendar(), m.format('dddd [a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today + ' + i + ' days beginning of day'); | |
9427 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
9428 assert.equal(m.calendar(), m.format('dddd [a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today + ' + i + ' days end of day'); | |
9429 } | |
9430 }); | |
9431 | |
9432 test('calendar last week', function (assert) { | |
9433 var i, m; | |
9434 | |
9435 for (i = 2; i < 7; i++) { | |
9436 m = moment().subtract({d: i}); | |
9437 assert.equal(m.calendar(), m.format('[el] dddd [pasado a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today - ' + i + ' days current time'); | |
9438 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
9439 assert.equal(m.calendar(), m.format('[el] dddd [pasado a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today - ' + i + ' days beginning of day'); | |
9440 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
9441 assert.equal(m.calendar(), m.format('[el] dddd [pasado a la' + ((m.hours() !== 1) ? 's' : '') + '] LT'), 'Today - ' + i + ' days end of day'); | |
9442 } | |
9443 }); | |
9444 | |
9445 test('calendar all else', function (assert) { | |
9446 var weeksAgo = moment().subtract({w: 1}), | |
9447 weeksFromNow = moment().add({w: 1}); | |
9448 | |
9449 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
9450 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
9451 | |
9452 weeksAgo = moment().subtract({w: 2}); | |
9453 weeksFromNow = moment().add({w: 2}); | |
9454 | |
9455 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
9456 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
9457 }); | |
9458 | |
9459 test('weeks year starting sunday', function (assert) { | |
9460 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
9461 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
9462 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
9463 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
9464 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
9465 }); | |
9466 | |
9467 test('weeks year starting monday', function (assert) { | |
9468 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
9469 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
9470 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
9471 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
9472 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
9473 }); | |
9474 | |
9475 test('weeks year starting tuesday', function (assert) { | |
9476 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
9477 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
9478 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
9479 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
9480 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
9481 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
9482 }); | |
9483 | |
9484 test('weeks year starting wednesday', function (assert) { | |
9485 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
9486 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
9487 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
9488 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
9489 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
9490 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
9491 }); | |
9492 | |
9493 test('weeks year starting thursday', function (assert) { | |
9494 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
9495 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
9496 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
9497 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
9498 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
9499 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
9500 }); | |
9501 | |
9502 test('weeks year starting friday', function (assert) { | |
9503 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
9504 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
9505 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
9506 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
9507 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
9508 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
9509 }); | |
9510 | |
9511 test('weeks year starting saturday', function (assert) { | |
9512 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
9513 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
9514 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
9515 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
9516 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
9517 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
9518 }); | |
9519 | |
9520 test('weeks year starting sunday formatted', function (assert) { | |
9521 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52º', 'Jan 1 2012 should be week 52'); | |
9522 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1º', 'Jan 2 2012 should be week 1'); | |
9523 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1º', 'Jan 8 2012 should be week 1'); | |
9524 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2º', 'Jan 9 2012 should be week 2'); | |
9525 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2º', 'Jan 15 2012 should be week 2'); | |
9526 }); | |
9527 | |
9528 test('lenient ordinal parsing', function (assert) { | |
9529 var i, ordinalStr, testMoment; | |
9530 for (i = 1; i <= 31; ++i) { | |
9531 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
9532 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
9533 assert.equal(testMoment.year(), 2014, | |
9534 'lenient ordinal parsing ' + i + ' year check'); | |
9535 assert.equal(testMoment.month(), 0, | |
9536 'lenient ordinal parsing ' + i + ' month check'); | |
9537 assert.equal(testMoment.date(), i, | |
9538 'lenient ordinal parsing ' + i + ' date check'); | |
9539 } | |
9540 }); | |
9541 | |
9542 test('lenient ordinal parsing of number', function (assert) { | |
9543 var i, testMoment; | |
9544 for (i = 1; i <= 31; ++i) { | |
9545 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
9546 assert.equal(testMoment.year(), 2014, | |
9547 'lenient ordinal parsing of number ' + i + ' year check'); | |
9548 assert.equal(testMoment.month(), 0, | |
9549 'lenient ordinal parsing of number ' + i + ' month check'); | |
9550 assert.equal(testMoment.date(), i, | |
9551 'lenient ordinal parsing of number ' + i + ' date check'); | |
9552 } | |
9553 }); | |
9554 | |
9555 test('strict ordinal parsing', function (assert) { | |
9556 var i, ordinalStr, testMoment; | |
9557 for (i = 1; i <= 31; ++i) { | |
9558 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
9559 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
9560 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
9561 } | |
9562 }); | |
9563 | |
9564 })); | |
9565 | |
9566 (function (global, factory) { | |
9567 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
9568 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
9569 factory(global.moment) | |
9570 }(this, function (moment) { 'use strict'; | |
9571 | |
9572 /*global QUnit:false*/ | |
9573 | |
9574 var test = QUnit.test; | |
9575 | |
9576 function module (name, lifecycle) { | |
9577 QUnit.module(name, { | |
9578 setup : function () { | |
9579 moment.locale('en'); | |
9580 moment.createFromInputFallback = function () { | |
9581 throw new Error('input not handled by moment'); | |
9582 }; | |
9583 if (lifecycle && lifecycle.setup) { | |
9584 lifecycle.setup(); | |
9585 } | |
9586 }, | |
9587 teardown : function () { | |
9588 if (lifecycle && lifecycle.teardown) { | |
9589 lifecycle.teardown(); | |
9590 } | |
9591 } | |
9592 }); | |
9593 } | |
9594 | |
9595 function localeModule (name, lifecycle) { | |
9596 QUnit.module('locale:' + name, { | |
9597 setup : function () { | |
9598 moment.locale(name); | |
9599 moment.createFromInputFallback = function () { | |
9600 throw new Error('input not handled by moment'); | |
9601 }; | |
9602 if (lifecycle && lifecycle.setup) { | |
9603 lifecycle.setup(); | |
9604 } | |
9605 }, | |
9606 teardown : function () { | |
9607 moment.locale('en'); | |
9608 if (lifecycle && lifecycle.teardown) { | |
9609 lifecycle.teardown(); | |
9610 } | |
9611 } | |
9612 }); | |
9613 } | |
9614 | |
9615 localeModule('et'); | |
9616 | |
9617 test('parse', function (assert) { | |
9618 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; | |
9619 function equalTest(input, mmm, i) { | |
9620 assert.equal(moment(input, mmm).month(), i, input + ' peaks olema kuu ' + (i + 1)); | |
9621 } | |
9622 for (i = 0; i < 12; i++) { | |
9623 tests[i] = tests[i].split(' '); | |
9624 equalTest(tests[i][0], 'MMM', i); | |
9625 equalTest(tests[i][1], 'MMM', i); | |
9626 equalTest(tests[i][0], 'MMMM', i); | |
9627 equalTest(tests[i][1], 'MMMM', i); | |
9628 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
9629 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
9630 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
9631 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
9632 } | |
9633 }); | |
9634 | |
9635 test('format', function (assert) { | |
9636 var a = [ | |
9637 ['dddd, Do MMMM YYYY, H:mm:ss', 'pühapäev, 14. veebruar 2010, 15:25:50'], | |
9638 ['ddd, h', 'P, 3'], | |
9639 ['M Mo MM MMMM MMM', '2 2. 02 veebruar veebr'], | |
9640 ['YYYY YY', '2010 10'], | |
9641 ['D Do DD', '14 14. 14'], | |
9642 ['d do dddd ddd dd', '0 0. pühapäev P P'], | |
9643 ['DDD DDDo DDDD', '45 45. 045'], | |
9644 ['w wo ww', '6 6. 06'], | |
9645 ['h hh', '3 03'], | |
9646 ['H HH', '15 15'], | |
9647 ['m mm', '25 25'], | |
9648 ['s ss', '50 50'], | |
9649 ['a A', 'pm PM'], | |
9650 ['[aasta] DDDo [päev]', 'aasta 45. päev'], | |
9651 ['LTS', '15:25:50'], | |
9652 ['L', '14.02.2010'], | |
9653 ['LL', '14. veebruar 2010'], | |
9654 ['LLL', '14. veebruar 2010 15:25'], | |
9655 ['LLLL', 'pühapäev, 14. veebruar 2010 15:25'], | |
9656 ['l', '14.2.2010'], | |
9657 ['ll', '14. veebr 2010'], | |
9658 ['lll', '14. veebr 2010 15:25'], | |
9659 ['llll', 'P, 14. veebr 2010 15:25'] | |
9660 ], | |
9661 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
9662 i; | |
9663 for (i = 0; i < a.length; i++) { | |
9664 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
9665 } | |
9666 }); | |
9667 | |
9668 test('format ordinal', function (assert) { | |
9669 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.'); | |
9670 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.'); | |
9671 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.'); | |
9672 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.'); | |
9673 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.'); | |
9674 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.'); | |
9675 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.'); | |
9676 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.'); | |
9677 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.'); | |
9678 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.'); | |
9679 | |
9680 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.'); | |
9681 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.'); | |
9682 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.'); | |
9683 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.'); | |
9684 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.'); | |
9685 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.'); | |
9686 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.'); | |
9687 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.'); | |
9688 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.'); | |
9689 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.'); | |
9690 | |
9691 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.'); | |
9692 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.'); | |
9693 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.'); | |
9694 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.'); | |
9695 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.'); | |
9696 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.'); | |
9697 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.'); | |
9698 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.'); | |
9699 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.'); | |
9700 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.'); | |
9701 | |
9702 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.'); | |
9703 }); | |
9704 | |
9705 test('format month', function (assert) { | |
9706 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; | |
9707 for (i = 0; i < expected.length; i++) { | |
9708 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
9709 } | |
9710 }); | |
9711 | |
9712 test('format week', function (assert) { | |
9713 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; | |
9714 for (i = 0; i < expected.length; i++) { | |
9715 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
9716 } | |
9717 }); | |
9718 | |
9719 test('from', function (assert) { | |
9720 var start = moment([2007, 1, 28]); | |
9721 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'paar sekundit', '44 seconds = paar sekundit'); | |
9722 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'üks minut', '45 seconds = üks minut'); | |
9723 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'üks minut', '89 seconds = üks minut'); | |
9724 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutit', '90 seconds = 2 minutit'); | |
9725 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutit', '44 minutes = 44 minutit'); | |
9726 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'üks tund', '45 minutes = tund aega'); | |
9727 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'üks tund', '89 minutes = üks tund'); | |
9728 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 tundi', '90 minutes = 2 tundi'); | |
9729 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 tundi', '5 hours = 5 tundi'); | |
9730 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 tundi', '21 hours = 21 tundi'); | |
9731 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'üks päev', '22 hours = üks päev'); | |
9732 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'üks päev', '35 hours = üks päev'); | |
9733 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 päeva', '36 hours = 2 päeva'); | |
9734 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'üks päev', '1 day = üks päev'); | |
9735 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 päeva', '5 days = 5 päeva'); | |
9736 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 päeva', '25 days = 25 päeva'); | |
9737 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'üks kuu', '26 days = üks kuu'); | |
9738 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'üks kuu', '30 days = üks kuu'); | |
9739 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'üks kuu', '43 days = üks kuu'); | |
9740 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 kuud', '46 days = 2 kuud'); | |
9741 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 kuud', '75 days = 2 kuud'); | |
9742 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 kuud', '76 days = 3 kuud'); | |
9743 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'üks kuu', '1 month = üks kuu'); | |
9744 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 kuud', '5 months = 5 kuud'); | |
9745 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'üks aasta', '345 days = üks aasta'); | |
9746 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 aastat', '548 days = 2 aastat'); | |
9747 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'üks aasta', '1 year = üks aasta'); | |
9748 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 aastat', '5 years = 5 aastat'); | |
9749 }); | |
9750 | |
9751 test('suffix', function (assert) { | |
9752 assert.equal(moment(30000).from(0), 'mõne sekundi pärast', 'prefix'); | |
9753 assert.equal(moment(0).from(30000), 'mõni sekund tagasi', 'suffix'); | |
9754 }); | |
9755 | |
9756 test('now from now', function (assert) { | |
9757 assert.equal(moment().fromNow(), 'mõni sekund tagasi', 'now from now should display as in the past'); | |
9758 }); | |
9759 | |
9760 test('fromNow', function (assert) { | |
9761 assert.equal(moment().add({s: 30}).fromNow(), 'mõne sekundi pärast', 'in a few seconds'); | |
9762 assert.equal(moment().subtract({s: 30}).fromNow(), 'mõni sekund tagasi', 'a few seconds ago'); | |
9763 | |
9764 assert.equal(moment().add({m: 1}).fromNow(), 'ühe minuti pärast', 'in a minute'); | |
9765 assert.equal(moment().subtract({m: 1}).fromNow(), 'üks minut tagasi', 'a minute ago'); | |
9766 | |
9767 assert.equal(moment().add({m: 5}).fromNow(), '5 minuti pärast', 'in 5 minutes'); | |
9768 assert.equal(moment().subtract({m: 5}).fromNow(), '5 minutit tagasi', '5 minutes ago'); | |
9769 | |
9770 assert.equal(moment().add({d: 1}).fromNow(), 'ühe päeva pärast', 'in one day'); | |
9771 assert.equal(moment().subtract({d: 1}).fromNow(), 'üks päev tagasi', 'one day ago'); | |
9772 | |
9773 assert.equal(moment().add({d: 5}).fromNow(), '5 päeva pärast', 'in 5 days'); | |
9774 assert.equal(moment().subtract({d: 5}).fromNow(), '5 päeva tagasi', '5 days ago'); | |
9775 | |
9776 assert.equal(moment().add({M: 1}).fromNow(), 'kuu aja pärast', 'in a month'); | |
9777 assert.equal(moment().subtract({M: 1}).fromNow(), 'kuu aega tagasi', 'a month ago'); | |
9778 | |
9779 assert.equal(moment().add({M: 5}).fromNow(), '5 kuu pärast', 'in 5 months'); | |
9780 assert.equal(moment().subtract({M: 5}).fromNow(), '5 kuud tagasi', '5 months ago'); | |
9781 | |
9782 assert.equal(moment().add({y: 1}).fromNow(), 'ühe aasta pärast', 'in a year'); | |
9783 assert.equal(moment().subtract({y: 1}).fromNow(), 'aasta tagasi', 'a year ago'); | |
9784 | |
9785 assert.equal(moment().add({y: 5}).fromNow(), '5 aasta pärast', 'in 5 years'); | |
9786 assert.equal(moment().subtract({y: 5}).fromNow(), '5 aastat tagasi', '5 years ago'); | |
9787 }); | |
9788 | |
9789 test('calendar day', function (assert) { | |
9790 var a = moment().hours(2).minutes(0).seconds(0); | |
9791 | |
9792 assert.equal(moment(a).calendar(), 'Täna, 2:00', 'today at the same time'); | |
9793 assert.equal(moment(a).add({m: 25}).calendar(), 'Täna, 2:25', 'Now plus 25 min'); | |
9794 assert.equal(moment(a).add({h: 1}).calendar(), 'Täna, 3:00', 'Now plus 1 hour'); | |
9795 assert.equal(moment(a).add({d: 1}).calendar(), 'Homme, 2:00', 'tomorrow at the same time'); | |
9796 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Täna, 1:00', 'Now minus 1 hour'); | |
9797 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Eile, 2:00', 'yesterday at the same time'); | |
9798 }); | |
9799 | |
9800 test('calendar next week', function (assert) { | |
9801 var i, m; | |
9802 for (i = 2; i < 7; i++) { | |
9803 m = moment().add({d: i}); | |
9804 assert.equal(m.calendar(), m.format('[Järgmine] dddd LT'), 'Today + ' + i + ' days current time'); | |
9805 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
9806 assert.equal(m.calendar(), m.format('[Järgmine] dddd LT'), 'Today + ' + i + ' days beginning of day'); | |
9807 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
9808 assert.equal(m.calendar(), m.format('[Järgmine] dddd LT'), 'Today + ' + i + ' days end of day'); | |
9809 } | |
9810 }); | |
9811 | |
9812 test('calendar last week', function (assert) { | |
9813 var i, m; | |
9814 for (i = 2; i < 7; i++) { | |
9815 m = moment().subtract({d: i}); | |
9816 assert.equal(m.calendar(), m.format('[Eelmine] dddd LT'), 'Today - ' + i + ' days current time'); | |
9817 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
9818 assert.equal(m.calendar(), m.format('[Eelmine] dddd LT'), 'Today - ' + i + ' days beginning of day'); | |
9819 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
9820 assert.equal(m.calendar(), m.format('[Eelmine] dddd LT'), 'Today - ' + i + ' days end of day'); | |
9821 } | |
9822 }); | |
9823 | |
9824 test('calendar all else', function (assert) { | |
9825 var weeksAgo = moment().subtract({w: 1}), | |
9826 weeksFromNow = moment().add({w: 1}); | |
9827 | |
9828 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 nädal tagasi'); | |
9829 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), '1 nädala pärast'); | |
9830 | |
9831 weeksAgo = moment().subtract({w: 2}); | |
9832 weeksFromNow = moment().add({w: 2}); | |
9833 | |
9834 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 nädalat tagasi'); | |
9835 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), '2 nädala pärast'); | |
9836 }); | |
9837 | |
9838 test('weeks year starting sunday', function (assert) { | |
9839 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
9840 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
9841 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
9842 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
9843 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
9844 }); | |
9845 | |
9846 test('weeks year starting monday', function (assert) { | |
9847 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
9848 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
9849 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
9850 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
9851 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
9852 }); | |
9853 | |
9854 test('weeks year starting tuesday', function (assert) { | |
9855 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
9856 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
9857 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
9858 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
9859 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
9860 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
9861 }); | |
9862 | |
9863 test('weeks year starting wednesday', function (assert) { | |
9864 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
9865 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
9866 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
9867 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
9868 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
9869 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
9870 }); | |
9871 | |
9872 test('weeks year starting thursday', function (assert) { | |
9873 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
9874 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
9875 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
9876 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
9877 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
9878 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
9879 }); | |
9880 | |
9881 test('weeks year starting friday', function (assert) { | |
9882 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
9883 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
9884 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
9885 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
9886 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
9887 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
9888 }); | |
9889 | |
9890 test('weeks year starting saturday', function (assert) { | |
9891 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
9892 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
9893 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
9894 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
9895 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
9896 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
9897 }); | |
9898 | |
9899 test('weeks year starting sunday formatted', function (assert) { | |
9900 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52'); | |
9901 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1'); | |
9902 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1'); | |
9903 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2'); | |
9904 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2'); | |
9905 }); | |
9906 | |
9907 test('lenient ordinal parsing', function (assert) { | |
9908 var i, ordinalStr, testMoment; | |
9909 for (i = 1; i <= 31; ++i) { | |
9910 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
9911 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
9912 assert.equal(testMoment.year(), 2014, | |
9913 'lenient ordinal parsing ' + i + ' year check'); | |
9914 assert.equal(testMoment.month(), 0, | |
9915 'lenient ordinal parsing ' + i + ' month check'); | |
9916 assert.equal(testMoment.date(), i, | |
9917 'lenient ordinal parsing ' + i + ' date check'); | |
9918 } | |
9919 }); | |
9920 | |
9921 test('lenient ordinal parsing of number', function (assert) { | |
9922 var i, testMoment; | |
9923 for (i = 1; i <= 31; ++i) { | |
9924 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
9925 assert.equal(testMoment.year(), 2014, | |
9926 'lenient ordinal parsing of number ' + i + ' year check'); | |
9927 assert.equal(testMoment.month(), 0, | |
9928 'lenient ordinal parsing of number ' + i + ' month check'); | |
9929 assert.equal(testMoment.date(), i, | |
9930 'lenient ordinal parsing of number ' + i + ' date check'); | |
9931 } | |
9932 }); | |
9933 | |
9934 test('strict ordinal parsing', function (assert) { | |
9935 var i, ordinalStr, testMoment; | |
9936 for (i = 1; i <= 31; ++i) { | |
9937 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
9938 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
9939 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
9940 } | |
9941 }); | |
9942 | |
9943 })); | |
9944 | |
9945 (function (global, factory) { | |
9946 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
9947 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
9948 factory(global.moment) | |
9949 }(this, function (moment) { 'use strict'; | |
9950 | |
9951 /*global QUnit:false*/ | |
9952 | |
9953 var test = QUnit.test; | |
9954 | |
9955 function module (name, lifecycle) { | |
9956 QUnit.module(name, { | |
9957 setup : function () { | |
9958 moment.locale('en'); | |
9959 moment.createFromInputFallback = function () { | |
9960 throw new Error('input not handled by moment'); | |
9961 }; | |
9962 if (lifecycle && lifecycle.setup) { | |
9963 lifecycle.setup(); | |
9964 } | |
9965 }, | |
9966 teardown : function () { | |
9967 if (lifecycle && lifecycle.teardown) { | |
9968 lifecycle.teardown(); | |
9969 } | |
9970 } | |
9971 }); | |
9972 } | |
9973 | |
9974 function localeModule (name, lifecycle) { | |
9975 QUnit.module('locale:' + name, { | |
9976 setup : function () { | |
9977 moment.locale(name); | |
9978 moment.createFromInputFallback = function () { | |
9979 throw new Error('input not handled by moment'); | |
9980 }; | |
9981 if (lifecycle && lifecycle.setup) { | |
9982 lifecycle.setup(); | |
9983 } | |
9984 }, | |
9985 teardown : function () { | |
9986 moment.locale('en'); | |
9987 if (lifecycle && lifecycle.teardown) { | |
9988 lifecycle.teardown(); | |
9989 } | |
9990 } | |
9991 }); | |
9992 } | |
9993 | |
9994 localeModule('eu'); | |
9995 | |
9996 test('parse', function (assert) { | |
9997 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; | |
9998 function equalTest(input, mmm, i) { | |
9999 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
10000 } | |
10001 for (i = 0; i < 12; i++) { | |
10002 tests[i] = tests[i].split(' '); | |
10003 equalTest(tests[i][0], 'MMM', i); | |
10004 equalTest(tests[i][1], 'MMM', i); | |
10005 equalTest(tests[i][0], 'MMMM', i); | |
10006 equalTest(tests[i][1], 'MMMM', i); | |
10007 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
10008 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
10009 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
10010 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
10011 } | |
10012 }); | |
10013 | |
10014 test('format', function (assert) { | |
10015 var a = [ | |
10016 ['dddd, MMMM Do YYYY, h:mm:ss a', 'igandea, otsaila 14. 2010, 3:25:50 pm'], | |
10017 ['ddd, hA', 'ig., 3PM'], | |
10018 ['M Mo MM MMMM MMM', '2 2. 02 otsaila ots.'], | |
10019 ['YYYY YY', '2010 10'], | |
10020 ['D Do DD', '14 14. 14'], | |
10021 ['d do dddd ddd dd', '0 0. igandea ig. ig'], | |
10022 ['DDD DDDo DDDD', '45 45. 045'], | |
10023 ['w wo ww', '7 7. 07'], | |
10024 ['h hh', '3 03'], | |
10025 ['H HH', '15 15'], | |
10026 ['m mm', '25 25'], | |
10027 ['s ss', '50 50'], | |
10028 ['a A', 'pm PM'], | |
10029 ['[the] DDDo [day of the year]', 'the 45. day of the year'], | |
10030 ['LTS', '15:25:50'], | |
10031 ['L', '2010-02-14'], | |
10032 ['LL', '2010ko otsailaren 14a'], | |
10033 ['LLL', '2010ko otsailaren 14a 15:25'], | |
10034 ['LLLL', 'igandea, 2010ko otsailaren 14a 15:25'], | |
10035 ['l', '2010-2-14'], | |
10036 ['ll', '2010ko ots. 14a'], | |
10037 ['lll', '2010ko ots. 14a 15:25'], | |
10038 ['llll', 'ig., 2010ko ots. 14a 15:25'] | |
10039 ], | |
10040 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
10041 i; | |
10042 for (i = 0; i < a.length; i++) { | |
10043 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
10044 } | |
10045 }); | |
10046 | |
10047 test('format ordinal', function (assert) { | |
10048 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.'); | |
10049 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.'); | |
10050 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.'); | |
10051 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.'); | |
10052 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.'); | |
10053 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.'); | |
10054 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.'); | |
10055 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.'); | |
10056 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.'); | |
10057 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.'); | |
10058 | |
10059 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.'); | |
10060 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.'); | |
10061 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.'); | |
10062 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.'); | |
10063 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.'); | |
10064 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.'); | |
10065 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.'); | |
10066 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.'); | |
10067 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.'); | |
10068 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.'); | |
10069 | |
10070 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.'); | |
10071 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.'); | |
10072 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.'); | |
10073 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.'); | |
10074 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.'); | |
10075 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.'); | |
10076 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.'); | |
10077 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.'); | |
10078 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.'); | |
10079 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.'); | |
10080 | |
10081 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.'); | |
10082 }); | |
10083 | |
10084 test('format month', function (assert) { | |
10085 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; | |
10086 for (i = 0; i < expected.length; i++) { | |
10087 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
10088 } | |
10089 }); | |
10090 | |
10091 test('format week', function (assert) { | |
10092 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; | |
10093 for (i = 0; i < expected.length; i++) { | |
10094 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
10095 } | |
10096 }); | |
10097 | |
10098 test('from', function (assert) { | |
10099 var start = moment([2007, 1, 28]); | |
10100 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'segundo batzuk', '44 seconds = a few seconds'); | |
10101 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minutu bat', '45 seconds = a minute'); | |
10102 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minutu bat', '89 seconds = a minute'); | |
10103 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutu', '90 seconds = 2 minutes'); | |
10104 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutu', '44 minutes = 44 minutes'); | |
10105 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ordu bat', '45 minutes = an hour'); | |
10106 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ordu bat', '89 minutes = an hour'); | |
10107 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ordu', '90 minutes = 2 hours'); | |
10108 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ordu', '5 hours = 5 hours'); | |
10109 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ordu', '21 hours = 21 hours'); | |
10110 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'egun bat', '22 hours = a day'); | |
10111 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'egun bat', '35 hours = a day'); | |
10112 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 egun', '36 hours = 2 days'); | |
10113 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'egun bat', '1 day = a day'); | |
10114 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 egun', '5 days = 5 days'); | |
10115 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 egun', '25 days = 25 days'); | |
10116 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'hilabete bat', '26 days = a month'); | |
10117 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'hilabete bat', '30 days = a month'); | |
10118 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'hilabete bat', '43 days = a month'); | |
10119 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 hilabete', '46 days = 2 months'); | |
10120 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 hilabete', '75 days = 2 months'); | |
10121 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 hilabete', '76 days = 3 months'); | |
10122 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'hilabete bat', '1 month = a month'); | |
10123 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 hilabete', '5 months = 5 months'); | |
10124 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'urte bat', '345 days = a year'); | |
10125 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 urte', '548 days = 2 years'); | |
10126 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'urte bat', '1 year = a year'); | |
10127 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 urte', '5 years = 5 years'); | |
10128 }); | |
10129 | |
10130 test('suffix', function (assert) { | |
10131 assert.equal(moment(30000).from(0), 'segundo batzuk barru', 'prefix'); | |
10132 assert.equal(moment(0).from(30000), 'duela segundo batzuk', 'suffix'); | |
10133 }); | |
10134 | |
10135 test('now from now', function (assert) { | |
10136 assert.equal(moment().fromNow(), 'duela segundo batzuk', 'now from now should display as in the past'); | |
10137 }); | |
10138 | |
10139 test('fromNow', function (assert) { | |
10140 assert.equal(moment().add({s: 30}).fromNow(), 'segundo batzuk barru', 'in seconds'); | |
10141 assert.equal(moment().add({d: 5}).fromNow(), '5 egun barru', 'in 5 days'); | |
10142 }); | |
10143 | |
10144 test('calendar day', function (assert) { | |
10145 var a = moment().hours(2).minutes(0).seconds(0); | |
10146 | |
10147 assert.equal(moment(a).calendar(), 'gaur 02:00etan', 'today at the same time'); | |
10148 assert.equal(moment(a).add({m: 25}).calendar(), 'gaur 02:25etan', 'now plus 25 min'); | |
10149 assert.equal(moment(a).add({h: 1}).calendar(), 'gaur 03:00etan', 'now plus 1 hour'); | |
10150 assert.equal(moment(a).add({d: 1}).calendar(), 'bihar 02:00etan', 'tomorrow at the same time'); | |
10151 assert.equal(moment(a).subtract({h: 1}).calendar(), 'gaur 01:00etan', 'now minus 1 hour'); | |
10152 assert.equal(moment(a).subtract({d: 1}).calendar(), 'atzo 02:00etan', 'yesterday at the same time'); | |
10153 }); | |
10154 | |
10155 test('calendar next week', function (assert) { | |
10156 var i, m; | |
10157 for (i = 2; i < 7; i++) { | |
10158 m = moment().add({d: i}); | |
10159 assert.equal(m.calendar(), m.format('dddd LT[etan]'), 'Today + ' + i + ' days current time'); | |
10160 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
10161 assert.equal(m.calendar(), m.format('dddd LT[etan]'), 'Today + ' + i + ' days beginning of day'); | |
10162 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
10163 assert.equal(m.calendar(), m.format('dddd LT[etan]'), 'Today + ' + i + ' days end of day'); | |
10164 } | |
10165 }); | |
10166 | |
10167 test('calendar last week', function (assert) { | |
10168 var i, m; | |
10169 for (i = 2; i < 7; i++) { | |
10170 m = moment().subtract({d: i}); | |
10171 assert.equal(m.calendar(), m.format('[aurreko] dddd LT[etan]'), 'Today - ' + i + ' days current time'); | |
10172 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
10173 assert.equal(m.calendar(), m.format('[aurreko] dddd LT[etan]'), 'Today - ' + i + ' days beginning of day'); | |
10174 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
10175 assert.equal(m.calendar(), m.format('[aurreko] dddd LT[etan]'), 'Today - ' + i + ' days end of day'); | |
10176 } | |
10177 }); | |
10178 | |
10179 test('calendar all else', function (assert) { | |
10180 var weeksAgo = moment().subtract({w: 1}), | |
10181 weeksFromNow = moment().add({w: 1}); | |
10182 | |
10183 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
10184 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
10185 | |
10186 weeksAgo = moment().subtract({w: 2}); | |
10187 weeksFromNow = moment().add({w: 2}); | |
10188 | |
10189 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
10190 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
10191 }); | |
10192 | |
10193 test('weeks year starting sunday', function (assert) { | |
10194 assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1'); | |
10195 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
10196 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2'); | |
10197 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
10198 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3'); | |
10199 }); | |
10200 | |
10201 test('weeks year starting monday', function (assert) { | |
10202 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
10203 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
10204 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
10205 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
10206 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
10207 }); | |
10208 | |
10209 test('weeks year starting tuesday', function (assert) { | |
10210 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
10211 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
10212 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
10213 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
10214 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
10215 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
10216 }); | |
10217 | |
10218 test('weeks year starting wednesday', function (assert) { | |
10219 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
10220 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
10221 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
10222 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
10223 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
10224 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
10225 }); | |
10226 | |
10227 test('weeks year starting thursday', function (assert) { | |
10228 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
10229 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
10230 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
10231 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
10232 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
10233 assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3'); | |
10234 }); | |
10235 | |
10236 test('weeks year starting friday', function (assert) { | |
10237 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1'); | |
10238 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
10239 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1'); | |
10240 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2'); | |
10241 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2'); | |
10242 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3'); | |
10243 }); | |
10244 | |
10245 test('weeks year starting saturday', function (assert) { | |
10246 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1'); | |
10247 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
10248 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1'); | |
10249 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2'); | |
10250 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2'); | |
10251 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3'); | |
10252 }); | |
10253 | |
10254 test('weeks year starting sunday formatted', function (assert) { | |
10255 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', 'Dec 26 2011 should be week 1'); | |
10256 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1.', 'Jan 1 2012 should be week 1'); | |
10257 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2.', 'Jan 2 2012 should be week 2'); | |
10258 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2.', 'Jan 8 2012 should be week 2'); | |
10259 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3.', 'Jan 9 2012 should be week 3'); | |
10260 }); | |
10261 | |
10262 test('lenient ordinal parsing', function (assert) { | |
10263 var i, ordinalStr, testMoment; | |
10264 for (i = 1; i <= 31; ++i) { | |
10265 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
10266 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
10267 assert.equal(testMoment.year(), 2014, | |
10268 'lenient ordinal parsing ' + i + ' year check'); | |
10269 assert.equal(testMoment.month(), 0, | |
10270 'lenient ordinal parsing ' + i + ' month check'); | |
10271 assert.equal(testMoment.date(), i, | |
10272 'lenient ordinal parsing ' + i + ' date check'); | |
10273 } | |
10274 }); | |
10275 | |
10276 test('lenient ordinal parsing of number', function (assert) { | |
10277 var i, testMoment; | |
10278 for (i = 1; i <= 31; ++i) { | |
10279 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
10280 assert.equal(testMoment.year(), 2014, | |
10281 'lenient ordinal parsing of number ' + i + ' year check'); | |
10282 assert.equal(testMoment.month(), 0, | |
10283 'lenient ordinal parsing of number ' + i + ' month check'); | |
10284 assert.equal(testMoment.date(), i, | |
10285 'lenient ordinal parsing of number ' + i + ' date check'); | |
10286 } | |
10287 }); | |
10288 | |
10289 test('strict ordinal parsing', function (assert) { | |
10290 var i, ordinalStr, testMoment; | |
10291 for (i = 1; i <= 31; ++i) { | |
10292 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
10293 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
10294 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
10295 } | |
10296 }); | |
10297 | |
10298 })); | |
10299 | |
10300 (function (global, factory) { | |
10301 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
10302 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
10303 factory(global.moment) | |
10304 }(this, function (moment) { 'use strict'; | |
10305 | |
10306 /*global QUnit:false*/ | |
10307 | |
10308 var test = QUnit.test; | |
10309 | |
10310 function module (name, lifecycle) { | |
10311 QUnit.module(name, { | |
10312 setup : function () { | |
10313 moment.locale('en'); | |
10314 moment.createFromInputFallback = function () { | |
10315 throw new Error('input not handled by moment'); | |
10316 }; | |
10317 if (lifecycle && lifecycle.setup) { | |
10318 lifecycle.setup(); | |
10319 } | |
10320 }, | |
10321 teardown : function () { | |
10322 if (lifecycle && lifecycle.teardown) { | |
10323 lifecycle.teardown(); | |
10324 } | |
10325 } | |
10326 }); | |
10327 } | |
10328 | |
10329 function localeModule (name, lifecycle) { | |
10330 QUnit.module('locale:' + name, { | |
10331 setup : function () { | |
10332 moment.locale(name); | |
10333 moment.createFromInputFallback = function () { | |
10334 throw new Error('input not handled by moment'); | |
10335 }; | |
10336 if (lifecycle && lifecycle.setup) { | |
10337 lifecycle.setup(); | |
10338 } | |
10339 }, | |
10340 teardown : function () { | |
10341 moment.locale('en'); | |
10342 if (lifecycle && lifecycle.teardown) { | |
10343 lifecycle.teardown(); | |
10344 } | |
10345 } | |
10346 }); | |
10347 } | |
10348 | |
10349 localeModule('fa'); | |
10350 | |
10351 test('parse', function (assert) { | |
10352 var tests = 'ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر'.split('_'), i; | |
10353 function equalTest(input, mmm, i) { | |
10354 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1) + ' instead is month ' + moment(input, mmm).month()); | |
10355 } | |
10356 for (i = 0; i < 12; i++) { | |
10357 equalTest(tests[i], 'MMM', i); | |
10358 equalTest(tests[i], 'MMMM', i); | |
10359 } | |
10360 }); | |
10361 | |
10362 test('format', function (assert) { | |
10363 var a = [ | |
10364 ['dddd, MMMM Do YYYY, h:mm:ss a', 'یک\u200cشنبه، فوریه ۱۴م ۲۰۱۰، ۳:۲۵:۵۰ بعد از ظهر'], | |
10365 ['ddd, hA', 'یک\u200cشنبه، ۳بعد از ظهر'], | |
10366 ['M Mo MM MMMM MMM', '۲ ۲م ۰۲ فوریه فوریه'], | |
10367 ['YYYY YY', '۲۰۱۰ ۱۰'], | |
10368 ['D Do DD', '۱۴ ۱۴م ۱۴'], | |
10369 ['d do dddd ddd dd', '۰ ۰م یک\u200cشنبه یک\u200cشنبه ی'], | |
10370 ['DDD DDDo DDDD', '۴۵ ۴۵م ۰۴۵'], | |
10371 ['w wo ww', '۸ ۸م ۰۸'], | |
10372 ['h hh', '۳ ۰۳'], | |
10373 ['H HH', '۱۵ ۱۵'], | |
10374 ['m mm', '۲۵ ۲۵'], | |
10375 ['s ss', '۵۰ ۵۰'], | |
10376 ['a A', 'بعد از ظهر بعد از ظهر'], | |
10377 ['DDDo [روز سال]', '۴۵م روز سال'], | |
10378 ['LTS', '۱۵:۲۵:۵۰'], | |
10379 ['L', '۱۴/۰۲/۲۰۱۰'], | |
10380 ['LL', '۱۴ فوریه ۲۰۱۰'], | |
10381 ['LLL', '۱۴ فوریه ۲۰۱۰ ۱۵:۲۵'], | |
10382 ['LLLL', 'یک\u200cشنبه، ۱۴ فوریه ۲۰۱۰ ۱۵:۲۵'], | |
10383 ['l', '۱۴/۲/۲۰۱۰'], | |
10384 ['ll', '۱۴ فوریه ۲۰۱۰'], | |
10385 ['lll', '۱۴ فوریه ۲۰۱۰ ۱۵:۲۵'], | |
10386 ['llll', 'یک\u200cشنبه، ۱۴ فوریه ۲۰۱۰ ۱۵:۲۵'] | |
10387 ], | |
10388 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
10389 i; | |
10390 for (i = 0; i < a.length; i++) { | |
10391 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
10392 } | |
10393 }); | |
10394 | |
10395 test('format ordinal', function (assert) { | |
10396 assert.equal(moment([2011, 0, 1]).format('DDDo'), '۱م', '1'); | |
10397 assert.equal(moment([2011, 0, 2]).format('DDDo'), '۲م', '2'); | |
10398 assert.equal(moment([2011, 0, 3]).format('DDDo'), '۳م', '3'); | |
10399 assert.equal(moment([2011, 0, 4]).format('DDDo'), '۴م', '4'); | |
10400 assert.equal(moment([2011, 0, 5]).format('DDDo'), '۵م', '5'); | |
10401 assert.equal(moment([2011, 0, 6]).format('DDDo'), '۶م', '6'); | |
10402 assert.equal(moment([2011, 0, 7]).format('DDDo'), '۷م', '7'); | |
10403 assert.equal(moment([2011, 0, 8]).format('DDDo'), '۸م', '8'); | |
10404 assert.equal(moment([2011, 0, 9]).format('DDDo'), '۹م', '9'); | |
10405 assert.equal(moment([2011, 0, 10]).format('DDDo'), '۱۰م', '10'); | |
10406 | |
10407 assert.equal(moment([2011, 0, 11]).format('DDDo'), '۱۱م', '11'); | |
10408 assert.equal(moment([2011, 0, 12]).format('DDDo'), '۱۲م', '12'); | |
10409 assert.equal(moment([2011, 0, 13]).format('DDDo'), '۱۳م', '13'); | |
10410 assert.equal(moment([2011, 0, 14]).format('DDDo'), '۱۴م', '14'); | |
10411 assert.equal(moment([2011, 0, 15]).format('DDDo'), '۱۵م', '15'); | |
10412 assert.equal(moment([2011, 0, 16]).format('DDDo'), '۱۶م', '16'); | |
10413 assert.equal(moment([2011, 0, 17]).format('DDDo'), '۱۷م', '17'); | |
10414 assert.equal(moment([2011, 0, 18]).format('DDDo'), '۱۸م', '18'); | |
10415 assert.equal(moment([2011, 0, 19]).format('DDDo'), '۱۹م', '19'); | |
10416 assert.equal(moment([2011, 0, 20]).format('DDDo'), '۲۰م', '20'); | |
10417 | |
10418 assert.equal(moment([2011, 0, 21]).format('DDDo'), '۲۱م', '21'); | |
10419 assert.equal(moment([2011, 0, 22]).format('DDDo'), '۲۲م', '22'); | |
10420 assert.equal(moment([2011, 0, 23]).format('DDDo'), '۲۳م', '23'); | |
10421 assert.equal(moment([2011, 0, 24]).format('DDDo'), '۲۴م', '24'); | |
10422 assert.equal(moment([2011, 0, 25]).format('DDDo'), '۲۵م', '25'); | |
10423 assert.equal(moment([2011, 0, 26]).format('DDDo'), '۲۶م', '26'); | |
10424 assert.equal(moment([2011, 0, 27]).format('DDDo'), '۲۷م', '27'); | |
10425 assert.equal(moment([2011, 0, 28]).format('DDDo'), '۲۸م', '28'); | |
10426 assert.equal(moment([2011, 0, 29]).format('DDDo'), '۲۹م', '29'); | |
10427 assert.equal(moment([2011, 0, 30]).format('DDDo'), '۳۰م', '30'); | |
10428 | |
10429 assert.equal(moment([2011, 0, 31]).format('DDDo'), '۳۱م', '31'); | |
10430 }); | |
10431 | |
10432 test('format month', function (assert) { | |
10433 var expected = 'ژانویه ژانویه_فوریه فوریه_مارس مارس_آوریل آوریل_مه مه_ژوئن ژوئن_ژوئیه ژوئیه_اوت اوت_سپتامبر سپتامبر_اکتبر اکتبر_نوامبر نوامبر_دسامبر دسامبر'.split('_'), i; | |
10434 for (i = 0; i < expected.length; i++) { | |
10435 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
10436 } | |
10437 }); | |
10438 | |
10439 test('format week', function (assert) { | |
10440 var expected = 'یک\u200cشنبه یک\u200cشنبه ی_دوشنبه دوشنبه د_سه\u200cشنبه سه\u200cشنبه س_چهارشنبه چهارشنبه چ_پنج\u200cشنبه پنج\u200cشنبه پ_جمعه جمعه ج_شنبه شنبه ش'.split('_'), i; | |
10441 for (i = 0; i < expected.length; i++) { | |
10442 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
10443 } | |
10444 }); | |
10445 | |
10446 test('from', function (assert) { | |
10447 var start = moment([2007, 1, 28]); | |
10448 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'چندین ثانیه', '44 seconds = a few seconds'); | |
10449 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'یک دقیقه', '45 seconds = a minute'); | |
10450 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'یک دقیقه', '89 seconds = a minute'); | |
10451 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '۲ دقیقه', '90 seconds = 2 minutes'); | |
10452 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '۴۴ دقیقه', '44 minutes = 44 minutes'); | |
10453 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'یک ساعت', '45 minutes = an hour'); | |
10454 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'یک ساعت', '89 minutes = an hour'); | |
10455 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '۲ ساعت', '90 minutes = 2 hours'); | |
10456 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '۵ ساعت', '5 hours = 5 hours'); | |
10457 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '۲۱ ساعت', '21 hours = 21 hours'); | |
10458 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'یک روز', '22 hours = a day'); | |
10459 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'یک روز', '35 hours = a day'); | |
10460 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '۲ روز', '36 hours = 2 days'); | |
10461 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'یک روز', '1 day = a day'); | |
10462 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '۵ روز', '5 days = 5 days'); | |
10463 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '۲۵ روز', '25 days = 25 days'); | |
10464 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'یک ماه', '26 days = a month'); | |
10465 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'یک ماه', '30 days = a month'); | |
10466 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'یک ماه', '43 days = a month'); | |
10467 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '۲ ماه', '46 days = 2 months'); | |
10468 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '۲ ماه', '75 days = 2 months'); | |
10469 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '۳ ماه', '76 days = 3 months'); | |
10470 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'یک ماه', '1 month = a month'); | |
10471 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '۵ ماه', '5 months = 5 months'); | |
10472 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'یک سال', '345 days = a year'); | |
10473 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '۲ سال', '548 days = 2 years'); | |
10474 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'یک سال', '1 year = a year'); | |
10475 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '۵ سال', '5 years = 5 years'); | |
10476 }); | |
10477 | |
10478 test('suffix', function (assert) { | |
10479 assert.equal(moment(30000).from(0), 'در چندین ثانیه', 'prefix'); | |
10480 assert.equal(moment(0).from(30000), 'چندین ثانیه پیش', 'suffix'); | |
10481 }); | |
10482 | |
10483 test('now from now', function (assert) { | |
10484 assert.equal(moment().fromNow(), 'چندین ثانیه پیش', 'now from now should display as in the past'); | |
10485 }); | |
10486 | |
10487 test('fromNow', function (assert) { | |
10488 assert.equal(moment().add({s: 30}).fromNow(), 'در چندین ثانیه', 'in a few seconds'); | |
10489 assert.equal(moment().add({d: 5}).fromNow(), 'در ۵ روز', 'in 5 days'); | |
10490 }); | |
10491 | |
10492 test('calendar day', function (assert) { | |
10493 var a = moment().hours(2).minutes(0).seconds(0); | |
10494 | |
10495 assert.equal(moment(a).calendar(), 'امروز ساعت ۰۲:۰۰', 'today at the same time'); | |
10496 assert.equal(moment(a).add({m: 25}).calendar(), 'امروز ساعت ۰۲:۲۵', 'Now plus 25 min'); | |
10497 assert.equal(moment(a).add({h: 1}).calendar(), 'امروز ساعت ۰۳:۰۰', 'Now plus 1 hour'); | |
10498 assert.equal(moment(a).add({d: 1}).calendar(), 'فردا ساعت ۰۲:۰۰', 'tomorrow at the same time'); | |
10499 assert.equal(moment(a).subtract({h: 1}).calendar(), 'امروز ساعت ۰۱:۰۰', 'Now minus 1 hour'); | |
10500 assert.equal(moment(a).subtract({d: 1}).calendar(), 'دیروز ساعت ۰۲:۰۰', 'yesterday at the same time'); | |
10501 }); | |
10502 | |
10503 test('calendar next week', function (assert) { | |
10504 var i, m; | |
10505 for (i = 2; i < 7; i++) { | |
10506 m = moment().add({d: i}); | |
10507 assert.equal(m.calendar(), m.format('dddd [ساعت] LT'), 'Today + ' + i + ' days current time'); | |
10508 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
10509 assert.equal(m.calendar(), m.format('dddd [ساعت] LT'), 'Today + ' + i + ' days beginning of day'); | |
10510 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
10511 assert.equal(m.calendar(), m.format('dddd [ساعت] LT'), 'Today + ' + i + ' days end of day'); | |
10512 } | |
10513 }); | |
10514 | |
10515 test('calendar last week', function (assert) { | |
10516 var i, m; | |
10517 for (i = 2; i < 7; i++) { | |
10518 m = moment().subtract({d: i}); | |
10519 assert.equal(m.calendar(), m.format('dddd [پیش ساعت] LT'), 'Today - ' + i + ' days current time'); | |
10520 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
10521 assert.equal(m.calendar(), m.format('dddd [پیش ساعت] LT'), 'Today - ' + i + ' days beginning of day'); | |
10522 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
10523 assert.equal(m.calendar(), m.format('dddd [پیش ساعت] LT'), 'Today - ' + i + ' days end of day'); | |
10524 } | |
10525 }); | |
10526 | |
10527 test('calendar all else', function (assert) { | |
10528 var weeksAgo = moment().subtract({w: 1}), | |
10529 weeksFromNow = moment().add({w: 1}); | |
10530 | |
10531 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
10532 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
10533 | |
10534 weeksAgo = moment().subtract({w: 2}); | |
10535 weeksFromNow = moment().add({w: 2}); | |
10536 | |
10537 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
10538 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
10539 }); | |
10540 | |
10541 test('weeks year starting sunday', function (assert) { | |
10542 assert.equal(moment([2011, 11, 31]).week(), 1, 'Dec 31 2011 should be week 1'); | |
10543 assert.equal(moment([2012, 0, 6]).week(), 1, 'Jan 6 2012 should be week 1'); | |
10544 assert.equal(moment([2012, 0, 7]).week(), 2, 'Jan 7 2012 should be week 2'); | |
10545 assert.equal(moment([2012, 0, 13]).week(), 2, 'Jan 13 2012 should be week 2'); | |
10546 assert.equal(moment([2012, 0, 14]).week(), 3, 'Jan 14 2012 should be week 3'); | |
10547 }); | |
10548 | |
10549 test('weeks year starting monday', function (assert) { | |
10550 assert.equal(moment([2006, 11, 30]).week(), 1, 'Dec 30 2006 should be week 1'); | |
10551 assert.equal(moment([2007, 0, 5]).week(), 1, 'Jan 5 2007 should be week 1'); | |
10552 assert.equal(moment([2007, 0, 6]).week(), 2, 'Jan 6 2007 should be week 2'); | |
10553 assert.equal(moment([2007, 0, 12]).week(), 2, 'Jan 12 2007 should be week 2'); | |
10554 assert.equal(moment([2007, 0, 13]).week(), 3, 'Jan 13 2007 should be week 3'); | |
10555 }); | |
10556 | |
10557 test('weeks year starting tuesday', function (assert) { | |
10558 assert.equal(moment([2007, 11, 29]).week(), 1, 'Dec 29 2007 should be week 1'); | |
10559 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
10560 assert.equal(moment([2008, 0, 4]).week(), 1, 'Jan 4 2008 should be week 1'); | |
10561 assert.equal(moment([2008, 0, 5]).week(), 2, 'Jan 5 2008 should be week 2'); | |
10562 assert.equal(moment([2008, 0, 11]).week(), 2, 'Jan 11 2008 should be week 2'); | |
10563 assert.equal(moment([2008, 0, 12]).week(), 3, 'Jan 12 2008 should be week 3'); | |
10564 }); | |
10565 | |
10566 test('weeks year starting wednesday', function (assert) { | |
10567 assert.equal(moment([2002, 11, 28]).week(), 1, 'Dec 28 2002 should be week 1'); | |
10568 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
10569 assert.equal(moment([2003, 0, 3]).week(), 1, 'Jan 3 2003 should be week 1'); | |
10570 assert.equal(moment([2003, 0, 4]).week(), 2, 'Jan 4 2003 should be week 2'); | |
10571 assert.equal(moment([2003, 0, 10]).week(), 2, 'Jan 10 2003 should be week 2'); | |
10572 assert.equal(moment([2003, 0, 11]).week(), 3, 'Jan 11 2003 should be week 3'); | |
10573 }); | |
10574 | |
10575 test('weeks year starting thursday', function (assert) { | |
10576 assert.equal(moment([2008, 11, 27]).week(), 1, 'Dec 27 2008 should be week 1'); | |
10577 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
10578 assert.equal(moment([2009, 0, 2]).week(), 1, 'Jan 2 2009 should be week 1'); | |
10579 assert.equal(moment([2009, 0, 3]).week(), 2, 'Jan 3 2009 should be week 2'); | |
10580 assert.equal(moment([2009, 0, 9]).week(), 2, 'Jan 9 2009 should be week 2'); | |
10581 assert.equal(moment([2009, 0, 10]).week(), 3, 'Jan 10 2009 should be week 3'); | |
10582 }); | |
10583 | |
10584 test('weeks year starting friday', function (assert) { | |
10585 assert.equal(moment([2009, 11, 26]).week(), 1, 'Dec 26 2009 should be week 1'); | |
10586 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
10587 assert.equal(moment([2010, 0, 2]).week(), 2, 'Jan 2 2010 should be week 2'); | |
10588 assert.equal(moment([2010, 0, 8]).week(), 2, 'Jan 8 2010 should be week 2'); | |
10589 assert.equal(moment([2010, 0, 9]).week(), 3, 'Jan 9 2010 should be week 3'); | |
10590 }); | |
10591 | |
10592 test('weeks year starting saturday', function (assert) { | |
10593 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
10594 assert.equal(moment([2011, 0, 7]).week(), 1, 'Jan 7 2011 should be week 1'); | |
10595 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2'); | |
10596 assert.equal(moment([2011, 0, 14]).week(), 2, 'Jan 14 2011 should be week 2'); | |
10597 assert.equal(moment([2011, 0, 15]).week(), 3, 'Jan 15 2011 should be week 3'); | |
10598 }); | |
10599 | |
10600 test('weeks year starting sunday formatted', function (assert) { | |
10601 assert.equal(moment([2011, 11, 31]).format('w ww wo'), '۱ ۰۱ ۱م', 'Dec 31 2011 should be week 1'); | |
10602 assert.equal(moment([2012, 0, 6]).format('w ww wo'), '۱ ۰۱ ۱م', 'Jan 6 2012 should be week 1'); | |
10603 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '۲ ۰۲ ۲م', 'Jan 7 2012 should be week 2'); | |
10604 assert.equal(moment([2012, 0, 13]).format('w ww wo'), '۲ ۰۲ ۲م', 'Jan 13 2012 should be week 2'); | |
10605 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '۳ ۰۳ ۳م', 'Jan 14 2012 should be week 3'); | |
10606 }); | |
10607 | |
10608 test('lenient ordinal parsing', function (assert) { | |
10609 var i, ordinalStr, testMoment; | |
10610 for (i = 1; i <= 31; ++i) { | |
10611 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
10612 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
10613 assert.equal(testMoment.year(), 2014, | |
10614 'lenient ordinal parsing ' + i + ' year check'); | |
10615 assert.equal(testMoment.month(), 0, | |
10616 'lenient ordinal parsing ' + i + ' month check'); | |
10617 assert.equal(testMoment.date(), i, | |
10618 'lenient ordinal parsing ' + i + ' date check'); | |
10619 } | |
10620 }); | |
10621 | |
10622 test('lenient ordinal parsing of number', function (assert) { | |
10623 var i, testMoment; | |
10624 for (i = 1; i <= 31; ++i) { | |
10625 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
10626 assert.equal(testMoment.year(), 2014, | |
10627 'lenient ordinal parsing of number ' + i + ' year check'); | |
10628 assert.equal(testMoment.month(), 0, | |
10629 'lenient ordinal parsing of number ' + i + ' month check'); | |
10630 assert.equal(testMoment.date(), i, | |
10631 'lenient ordinal parsing of number ' + i + ' date check'); | |
10632 } | |
10633 }); | |
10634 | |
10635 test('strict ordinal parsing', function (assert) { | |
10636 var i, ordinalStr, testMoment; | |
10637 for (i = 1; i <= 31; ++i) { | |
10638 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
10639 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
10640 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
10641 } | |
10642 }); | |
10643 | |
10644 })); | |
10645 | |
10646 (function (global, factory) { | |
10647 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
10648 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
10649 factory(global.moment) | |
10650 }(this, function (moment) { 'use strict'; | |
10651 | |
10652 /*global QUnit:false*/ | |
10653 | |
10654 var test = QUnit.test; | |
10655 | |
10656 function module (name, lifecycle) { | |
10657 QUnit.module(name, { | |
10658 setup : function () { | |
10659 moment.locale('en'); | |
10660 moment.createFromInputFallback = function () { | |
10661 throw new Error('input not handled by moment'); | |
10662 }; | |
10663 if (lifecycle && lifecycle.setup) { | |
10664 lifecycle.setup(); | |
10665 } | |
10666 }, | |
10667 teardown : function () { | |
10668 if (lifecycle && lifecycle.teardown) { | |
10669 lifecycle.teardown(); | |
10670 } | |
10671 } | |
10672 }); | |
10673 } | |
10674 | |
10675 function localeModule (name, lifecycle) { | |
10676 QUnit.module('locale:' + name, { | |
10677 setup : function () { | |
10678 moment.locale(name); | |
10679 moment.createFromInputFallback = function () { | |
10680 throw new Error('input not handled by moment'); | |
10681 }; | |
10682 if (lifecycle && lifecycle.setup) { | |
10683 lifecycle.setup(); | |
10684 } | |
10685 }, | |
10686 teardown : function () { | |
10687 moment.locale('en'); | |
10688 if (lifecycle && lifecycle.teardown) { | |
10689 lifecycle.teardown(); | |
10690 } | |
10691 } | |
10692 }); | |
10693 } | |
10694 | |
10695 localeModule('fi'); | |
10696 | |
10697 test('parse', function (assert) { | |
10698 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; | |
10699 function equalTest(input, mmm, i) { | |
10700 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
10701 } | |
10702 for (i = 0; i < 12; i++) { | |
10703 tests[i] = tests[i].split(' '); | |
10704 equalTest(tests[i][0], 'MMM', i); | |
10705 equalTest(tests[i][1], 'MMM', i); | |
10706 equalTest(tests[i][0], 'MMMM', i); | |
10707 equalTest(tests[i][1], 'MMMM', i); | |
10708 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
10709 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
10710 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
10711 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
10712 } | |
10713 }); | |
10714 | |
10715 test('format', function (assert) { | |
10716 var a = [ | |
10717 ['dddd, MMMM Do YYYY, h:mm:ss a', 'sunnuntai, helmikuu 14. 2010, 3:25:50 pm'], | |
10718 ['ddd, hA', 'su, 3PM'], | |
10719 ['M Mo MM MMMM MMM', '2 2. 02 helmikuu helmi'], | |
10720 ['YYYY YY', '2010 10'], | |
10721 ['D Do DD', '14 14. 14'], | |
10722 ['d do dddd ddd dd', '0 0. sunnuntai su su'], | |
10723 ['DDD DDDo DDDD', '45 45. 045'], | |
10724 ['w wo ww', '6 6. 06'], | |
10725 ['h hh', '3 03'], | |
10726 ['H HH', '15 15'], | |
10727 ['m mm', '25 25'], | |
10728 ['s ss', '50 50'], | |
10729 ['a A', 'pm PM'], | |
10730 ['[vuoden] DDDo [päivä]', 'vuoden 45. päivä'], | |
10731 ['LTS', '15.25.50'], | |
10732 ['L', '14.02.2010'], | |
10733 ['LL', '14. helmikuuta 2010'], | |
10734 ['LLL', '14. helmikuuta 2010, klo 15.25'], | |
10735 ['LLLL', 'sunnuntai, 14. helmikuuta 2010, klo 15.25'], | |
10736 ['l', '14.2.2010'], | |
10737 ['ll', '14. helmi 2010'], | |
10738 ['lll', '14. helmi 2010, klo 15.25'], | |
10739 ['llll', 'su, 14. helmi 2010, klo 15.25'] | |
10740 ], | |
10741 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
10742 i; | |
10743 for (i = 0; i < a.length; i++) { | |
10744 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
10745 } | |
10746 }); | |
10747 | |
10748 test('format ordinal', function (assert) { | |
10749 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1st'); | |
10750 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2nd'); | |
10751 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3rd'); | |
10752 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4th'); | |
10753 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5th'); | |
10754 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6th'); | |
10755 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7th'); | |
10756 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8th'); | |
10757 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9th'); | |
10758 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10th'); | |
10759 | |
10760 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11th'); | |
10761 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12th'); | |
10762 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13th'); | |
10763 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14th'); | |
10764 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15th'); | |
10765 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16th'); | |
10766 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17th'); | |
10767 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18th'); | |
10768 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19th'); | |
10769 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20th'); | |
10770 | |
10771 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21st'); | |
10772 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22nd'); | |
10773 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23rd'); | |
10774 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24th'); | |
10775 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25th'); | |
10776 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26th'); | |
10777 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27th'); | |
10778 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28th'); | |
10779 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29th'); | |
10780 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30th'); | |
10781 | |
10782 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31st'); | |
10783 }); | |
10784 | |
10785 test('format month', function (assert) { | |
10786 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; | |
10787 for (i = 0; i < expected.length; i++) { | |
10788 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
10789 } | |
10790 }); | |
10791 | |
10792 test('format week', function (assert) { | |
10793 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; | |
10794 for (i = 0; i < expected.length; i++) { | |
10795 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
10796 } | |
10797 }); | |
10798 | |
10799 test('from', function (assert) { | |
10800 var start = moment([2007, 1, 28]); | |
10801 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'muutama sekunti', '44 seconds = few seconds'); | |
10802 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minuutti', '45 seconds = a minute'); | |
10803 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minuutti', '89 seconds = a minute'); | |
10804 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), 'kaksi minuuttia', '90 seconds = 2 minutes'); | |
10805 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuuttia', '44 minutes = 44 minutes'); | |
10806 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'tunti', '45 minutes = an hour'); | |
10807 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'tunti', '89 minutes = an hour'); | |
10808 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), 'kaksi tuntia', '90 minutes = 2 hours'); | |
10809 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), 'viisi tuntia', '5 hours = 5 hours'); | |
10810 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 tuntia', '21 hours = 21 hours'); | |
10811 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'päivä', '22 hours = a day'); | |
10812 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'päivä', '35 hours = a day'); | |
10813 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), 'kaksi päivää', '36 hours = 2 days'); | |
10814 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'päivä', '1 day = a day'); | |
10815 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), 'viisi päivää', '5 days = 5 days'); | |
10816 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 päivää', '25 days = 25 days'); | |
10817 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'kuukausi', '26 days = a month'); | |
10818 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'kuukausi', '30 days = a month'); | |
10819 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'kuukausi', '43 days = a month'); | |
10820 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), 'kaksi kuukautta', '46 days = 2 months'); | |
10821 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), 'kaksi kuukautta', '75 days = 2 months'); | |
10822 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), 'kolme kuukautta', '76 days = 3 months'); | |
10823 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'kuukausi', '1 month = a month'); | |
10824 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), 'viisi kuukautta', '5 months = 5 months'); | |
10825 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'vuosi', '345 days = a year'); | |
10826 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), 'kaksi vuotta', '548 days = 2 years'); | |
10827 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'vuosi', '1 year = a year'); | |
10828 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), 'viisi vuotta', '5 years = 5 years'); | |
10829 }); | |
10830 | |
10831 test('suffix', function (assert) { | |
10832 assert.equal(moment(30000).from(0), 'muutaman sekunnin päästä', 'prefix'); | |
10833 assert.equal(moment(0).from(30000), 'muutama sekunti sitten', 'suffix'); | |
10834 }); | |
10835 | |
10836 test('now from now', function (assert) { | |
10837 assert.equal(moment().fromNow(), 'muutama sekunti sitten', 'now from now should display as in the past'); | |
10838 }); | |
10839 | |
10840 test('fromNow', function (assert) { | |
10841 assert.equal(moment().add({s: 30}).fromNow(), 'muutaman sekunnin päästä', 'in a few seconds'); | |
10842 assert.equal(moment().add({d: 5}).fromNow(), 'viiden päivän päästä', 'in 5 days'); | |
10843 }); | |
10844 | |
10845 test('calendar day', function (assert) { | |
10846 var a = moment().hours(2).minutes(0).seconds(0); | |
10847 | |
10848 assert.equal(moment(a).calendar(), 'tänään klo 02.00', 'today at the same time'); | |
10849 assert.equal(moment(a).add({m: 25}).calendar(), 'tänään klo 02.25', 'Now plus 25 min'); | |
10850 assert.equal(moment(a).add({h: 1}).calendar(), 'tänään klo 03.00', 'Now plus 1 hour'); | |
10851 assert.equal(moment(a).add({d: 1}).calendar(), 'huomenna klo 02.00', 'tomorrow at the same time'); | |
10852 assert.equal(moment(a).subtract({h: 1}).calendar(), 'tänään klo 01.00', 'Now minus 1 hour'); | |
10853 assert.equal(moment(a).subtract({d: 1}).calendar(), 'eilen klo 02.00', 'yesterday at the same time'); | |
10854 }); | |
10855 | |
10856 test('calendar next week', function (assert) { | |
10857 var i, m; | |
10858 | |
10859 for (i = 2; i < 7; i++) { | |
10860 m = moment().add({d: i}); | |
10861 assert.equal(m.calendar(), m.format('dddd [klo] LT'), 'today + ' + i + ' days current time'); | |
10862 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
10863 assert.equal(m.calendar(), m.format('dddd [klo] LT'), 'today + ' + i + ' days beginning of day'); | |
10864 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
10865 assert.equal(m.calendar(), m.format('dddd [klo] LT'), 'today + ' + i + ' days end of day'); | |
10866 } | |
10867 }); | |
10868 | |
10869 test('calendar last week', function (assert) { | |
10870 var i, m; | |
10871 for (i = 2; i < 7; i++) { | |
10872 m = moment().subtract({d: i}); | |
10873 assert.equal(m.calendar(), m.format('[viime] dddd[na] [klo] LT'), 'today - ' + i + ' days current time'); | |
10874 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
10875 assert.equal(m.calendar(), m.format('[viime] dddd[na] [klo] LT'), 'today - ' + i + ' days beginning of day'); | |
10876 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
10877 assert.equal(m.calendar(), m.format('[viime] dddd[na] [klo] LT'), 'today - ' + i + ' days end of day'); | |
10878 } | |
10879 }); | |
10880 | |
10881 test('calendar all else', function (assert) { | |
10882 var weeksAgo = moment().subtract({w: 1}), | |
10883 weeksFromNow = moment().add({w: 1}); | |
10884 | |
10885 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), 'yksi viikko sitten'); | |
10886 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'yhden viikon päästä'); | |
10887 | |
10888 weeksAgo = moment().subtract({w: 2}); | |
10889 weeksFromNow = moment().add({w: 2}); | |
10890 | |
10891 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), 'kaksi viikkoa sitten'); | |
10892 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'kaden viikon päästä'); | |
10893 }); | |
10894 | |
10895 test('weeks year starting sunday', function (assert) { | |
10896 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
10897 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
10898 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
10899 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
10900 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
10901 }); | |
10902 | |
10903 test('weeks year starting monday', function (assert) { | |
10904 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
10905 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
10906 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
10907 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
10908 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
10909 }); | |
10910 | |
10911 test('weeks year starting tuesday', function (assert) { | |
10912 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
10913 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
10914 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
10915 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
10916 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
10917 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
10918 }); | |
10919 | |
10920 test('weeks year starting wednesday', function (assert) { | |
10921 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
10922 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
10923 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
10924 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
10925 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
10926 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
10927 }); | |
10928 | |
10929 test('weeks year starting thursday', function (assert) { | |
10930 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
10931 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
10932 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
10933 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
10934 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
10935 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
10936 }); | |
10937 | |
10938 test('weeks year starting friday', function (assert) { | |
10939 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
10940 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
10941 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
10942 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
10943 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
10944 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
10945 }); | |
10946 | |
10947 test('weeks year starting saturday', function (assert) { | |
10948 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
10949 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
10950 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
10951 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
10952 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
10953 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
10954 }); | |
10955 | |
10956 test('weeks year starting sunday formatted', function (assert) { | |
10957 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52'); | |
10958 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1'); | |
10959 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1'); | |
10960 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2'); | |
10961 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2'); | |
10962 }); | |
10963 | |
10964 test('lenient ordinal parsing', function (assert) { | |
10965 var i, ordinalStr, testMoment; | |
10966 for (i = 1; i <= 31; ++i) { | |
10967 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
10968 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
10969 assert.equal(testMoment.year(), 2014, | |
10970 'lenient ordinal parsing ' + i + ' year check'); | |
10971 assert.equal(testMoment.month(), 0, | |
10972 'lenient ordinal parsing ' + i + ' month check'); | |
10973 assert.equal(testMoment.date(), i, | |
10974 'lenient ordinal parsing ' + i + ' date check'); | |
10975 } | |
10976 }); | |
10977 | |
10978 test('lenient ordinal parsing of number', function (assert) { | |
10979 var i, testMoment; | |
10980 for (i = 1; i <= 31; ++i) { | |
10981 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
10982 assert.equal(testMoment.year(), 2014, | |
10983 'lenient ordinal parsing of number ' + i + ' year check'); | |
10984 assert.equal(testMoment.month(), 0, | |
10985 'lenient ordinal parsing of number ' + i + ' month check'); | |
10986 assert.equal(testMoment.date(), i, | |
10987 'lenient ordinal parsing of number ' + i + ' date check'); | |
10988 } | |
10989 }); | |
10990 | |
10991 test('strict ordinal parsing', function (assert) { | |
10992 var i, ordinalStr, testMoment; | |
10993 for (i = 1; i <= 31; ++i) { | |
10994 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
10995 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
10996 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
10997 } | |
10998 }); | |
10999 | |
11000 })); | |
11001 | |
11002 (function (global, factory) { | |
11003 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
11004 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
11005 factory(global.moment) | |
11006 }(this, function (moment) { 'use strict'; | |
11007 | |
11008 /*global QUnit:false*/ | |
11009 | |
11010 var test = QUnit.test; | |
11011 | |
11012 function module (name, lifecycle) { | |
11013 QUnit.module(name, { | |
11014 setup : function () { | |
11015 moment.locale('en'); | |
11016 moment.createFromInputFallback = function () { | |
11017 throw new Error('input not handled by moment'); | |
11018 }; | |
11019 if (lifecycle && lifecycle.setup) { | |
11020 lifecycle.setup(); | |
11021 } | |
11022 }, | |
11023 teardown : function () { | |
11024 if (lifecycle && lifecycle.teardown) { | |
11025 lifecycle.teardown(); | |
11026 } | |
11027 } | |
11028 }); | |
11029 } | |
11030 | |
11031 function localeModule (name, lifecycle) { | |
11032 QUnit.module('locale:' + name, { | |
11033 setup : function () { | |
11034 moment.locale(name); | |
11035 moment.createFromInputFallback = function () { | |
11036 throw new Error('input not handled by moment'); | |
11037 }; | |
11038 if (lifecycle && lifecycle.setup) { | |
11039 lifecycle.setup(); | |
11040 } | |
11041 }, | |
11042 teardown : function () { | |
11043 moment.locale('en'); | |
11044 if (lifecycle && lifecycle.teardown) { | |
11045 lifecycle.teardown(); | |
11046 } | |
11047 } | |
11048 }); | |
11049 } | |
11050 | |
11051 localeModule('fo'); | |
11052 | |
11053 test('parse', function (assert) { | |
11054 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; | |
11055 function equalTest(input, mmm, i) { | |
11056 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
11057 } | |
11058 for (i = 0; i < 12; i++) { | |
11059 tests[i] = tests[i].split(' '); | |
11060 equalTest(tests[i][0], 'MMM', i); | |
11061 equalTest(tests[i][1], 'MMM', i); | |
11062 equalTest(tests[i][0], 'MMMM', i); | |
11063 equalTest(tests[i][1], 'MMMM', i); | |
11064 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
11065 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
11066 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
11067 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
11068 } | |
11069 }); | |
11070 | |
11071 test('format', function (assert) { | |
11072 var a = [ | |
11073 ['dddd [tann] Do MMMM YYYY, h:mm:ss a', 'sunnudagur tann 14. februar 2010, 3:25:50 pm'], | |
11074 ['ddd hA', 'sun 3PM'], | |
11075 ['M Mo MM MMMM MMM', '2 2. 02 februar feb'], | |
11076 ['YYYY YY', '2010 10'], | |
11077 ['D Do DD', '14 14. 14'], | |
11078 ['d do dddd ddd dd', '0 0. sunnudagur sun su'], | |
11079 ['DDD DDDo DDDD', '45 45. 045'], | |
11080 ['w wo ww', '6 6. 06'], | |
11081 ['h hh', '3 03'], | |
11082 ['H HH', '15 15'], | |
11083 ['m mm', '25 25'], | |
11084 ['s ss', '50 50'], | |
11085 ['a A', 'pm PM'], | |
11086 ['[tann] DDDo [dagin á árinum]', 'tann 45. dagin á árinum'], | |
11087 ['LTS', '15:25:50'], | |
11088 ['L', '14/02/2010'], | |
11089 ['LL', '14 februar 2010'], | |
11090 ['LLL', '14 februar 2010 15:25'], | |
11091 ['LLLL', 'sunnudagur 14. februar, 2010 15:25'], | |
11092 ['l', '14/2/2010'], | |
11093 ['ll', '14 feb 2010'], | |
11094 ['lll', '14 feb 2010 15:25'], | |
11095 ['llll', 'sun 14. feb, 2010 15:25'] | |
11096 ], | |
11097 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
11098 i; | |
11099 for (i = 0; i < a.length; i++) { | |
11100 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
11101 } | |
11102 }); | |
11103 | |
11104 test('format ordinal', function (assert) { | |
11105 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.'); | |
11106 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.'); | |
11107 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.'); | |
11108 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.'); | |
11109 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.'); | |
11110 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.'); | |
11111 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.'); | |
11112 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.'); | |
11113 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.'); | |
11114 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.'); | |
11115 | |
11116 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.'); | |
11117 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.'); | |
11118 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.'); | |
11119 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.'); | |
11120 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.'); | |
11121 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.'); | |
11122 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.'); | |
11123 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.'); | |
11124 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.'); | |
11125 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.'); | |
11126 | |
11127 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.'); | |
11128 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.'); | |
11129 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.'); | |
11130 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.'); | |
11131 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.'); | |
11132 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.'); | |
11133 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.'); | |
11134 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.'); | |
11135 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.'); | |
11136 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.'); | |
11137 | |
11138 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.'); | |
11139 }); | |
11140 | |
11141 test('format month', function (assert) { | |
11142 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; | |
11143 for (i = 0; i < expected.length; i++) { | |
11144 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
11145 } | |
11146 }); | |
11147 | |
11148 test('format week', function (assert) { | |
11149 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; | |
11150 for (i = 0; i < expected.length; i++) { | |
11151 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
11152 } | |
11153 }); | |
11154 | |
11155 test('from', function (assert) { | |
11156 var start = moment([2007, 1, 28]); | |
11157 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'fá sekund', '44 seconds = a few seconds'); | |
11158 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ein minutt', '45 seconds = a minute'); | |
11159 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ein minutt', '89 seconds = a minute'); | |
11160 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuttir', '90 seconds = 2 minutes'); | |
11161 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuttir', '44 minutes = 44 minutes'); | |
11162 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ein tími', '45 minutes = an hour'); | |
11163 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ein tími', '89 minutes = an hour'); | |
11164 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 tímar', '90 minutes = 2 hours'); | |
11165 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 tímar', '5 hours = 5 hours'); | |
11166 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 tímar', '21 hours = 21 hours'); | |
11167 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ein dagur', '22 hours = a day'); | |
11168 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ein dagur', '35 hours = a day'); | |
11169 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dagar', '36 hours = 2 days'); | |
11170 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ein dagur', '1 day = a day'); | |
11171 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dagar', '5 days = 5 days'); | |
11172 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dagar', '25 days = 25 days'); | |
11173 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ein mánaði', '26 days = a month'); | |
11174 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ein mánaði', '30 days = a month'); | |
11175 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ein mánaði', '43 days = a month'); | |
11176 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mánaðir', '46 days = 2 months'); | |
11177 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mánaðir', '75 days = 2 months'); | |
11178 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mánaðir', '76 days = 3 months'); | |
11179 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ein mánaði', '1 month = a month'); | |
11180 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mánaðir', '5 months = 5 months'); | |
11181 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'eitt ár', '345 days = a year'); | |
11182 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ár', '548 days = 2 years'); | |
11183 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'eitt ár', '1 year = a year'); | |
11184 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ár', '5 years = 5 years'); | |
11185 }); | |
11186 | |
11187 test('suffix', function (assert) { | |
11188 assert.equal(moment(30000).from(0), 'um fá sekund', 'prefix'); | |
11189 assert.equal(moment(0).from(30000), 'fá sekund síðani', 'suffix'); | |
11190 }); | |
11191 | |
11192 test('now from now', function (assert) { | |
11193 assert.equal(moment().fromNow(), 'fá sekund síðani', 'now from now should display as in the past'); | |
11194 }); | |
11195 | |
11196 test('fromNow', function (assert) { | |
11197 assert.equal(moment().add({s: 30}).fromNow(), 'um fá sekund', 'in a few seconds'); | |
11198 assert.equal(moment().add({d: 5}).fromNow(), 'um 5 dagar', 'in 5 days'); | |
11199 }); | |
11200 | |
11201 test('weeks year starting sunday', function (assert) { | |
11202 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
11203 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
11204 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
11205 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
11206 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
11207 }); | |
11208 | |
11209 test('weeks year starting monday', function (assert) { | |
11210 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
11211 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
11212 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
11213 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
11214 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
11215 }); | |
11216 | |
11217 test('weeks year starting tuesday', function (assert) { | |
11218 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
11219 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
11220 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
11221 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
11222 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
11223 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
11224 }); | |
11225 | |
11226 test('weeks year starting wednesday', function (assert) { | |
11227 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
11228 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
11229 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
11230 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
11231 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
11232 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
11233 }); | |
11234 | |
11235 test('weeks year starting thursday', function (assert) { | |
11236 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
11237 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
11238 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
11239 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
11240 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
11241 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
11242 }); | |
11243 | |
11244 test('weeks year starting friday', function (assert) { | |
11245 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
11246 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
11247 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
11248 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
11249 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
11250 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
11251 }); | |
11252 | |
11253 test('weeks year starting saturday', function (assert) { | |
11254 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
11255 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
11256 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
11257 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
11258 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
11259 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
11260 }); | |
11261 | |
11262 test('weeks year starting sunday formatted', function (assert) { | |
11263 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52'); | |
11264 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1'); | |
11265 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1'); | |
11266 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2'); | |
11267 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2'); | |
11268 }); | |
11269 | |
11270 test('lenient ordinal parsing', function (assert) { | |
11271 var i, ordinalStr, testMoment; | |
11272 for (i = 1; i <= 31; ++i) { | |
11273 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
11274 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
11275 assert.equal(testMoment.year(), 2014, | |
11276 'lenient ordinal parsing ' + i + ' year check'); | |
11277 assert.equal(testMoment.month(), 0, | |
11278 'lenient ordinal parsing ' + i + ' month check'); | |
11279 assert.equal(testMoment.date(), i, | |
11280 'lenient ordinal parsing ' + i + ' date check'); | |
11281 } | |
11282 }); | |
11283 | |
11284 test('lenient ordinal parsing of number', function (assert) { | |
11285 var i, testMoment; | |
11286 for (i = 1; i <= 31; ++i) { | |
11287 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
11288 assert.equal(testMoment.year(), 2014, | |
11289 'lenient ordinal parsing of number ' + i + ' year check'); | |
11290 assert.equal(testMoment.month(), 0, | |
11291 'lenient ordinal parsing of number ' + i + ' month check'); | |
11292 assert.equal(testMoment.date(), i, | |
11293 'lenient ordinal parsing of number ' + i + ' date check'); | |
11294 } | |
11295 }); | |
11296 | |
11297 test('strict ordinal parsing', function (assert) { | |
11298 var i, ordinalStr, testMoment; | |
11299 for (i = 1; i <= 31; ++i) { | |
11300 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
11301 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
11302 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
11303 } | |
11304 }); | |
11305 | |
11306 })); | |
11307 | |
11308 (function (global, factory) { | |
11309 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
11310 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
11311 factory(global.moment) | |
11312 }(this, function (moment) { 'use strict'; | |
11313 | |
11314 /*global QUnit:false*/ | |
11315 | |
11316 var test = QUnit.test; | |
11317 | |
11318 function module (name, lifecycle) { | |
11319 QUnit.module(name, { | |
11320 setup : function () { | |
11321 moment.locale('en'); | |
11322 moment.createFromInputFallback = function () { | |
11323 throw new Error('input not handled by moment'); | |
11324 }; | |
11325 if (lifecycle && lifecycle.setup) { | |
11326 lifecycle.setup(); | |
11327 } | |
11328 }, | |
11329 teardown : function () { | |
11330 if (lifecycle && lifecycle.teardown) { | |
11331 lifecycle.teardown(); | |
11332 } | |
11333 } | |
11334 }); | |
11335 } | |
11336 | |
11337 function localeModule (name, lifecycle) { | |
11338 QUnit.module('locale:' + name, { | |
11339 setup : function () { | |
11340 moment.locale(name); | |
11341 moment.createFromInputFallback = function () { | |
11342 throw new Error('input not handled by moment'); | |
11343 }; | |
11344 if (lifecycle && lifecycle.setup) { | |
11345 lifecycle.setup(); | |
11346 } | |
11347 }, | |
11348 teardown : function () { | |
11349 moment.locale('en'); | |
11350 if (lifecycle && lifecycle.teardown) { | |
11351 lifecycle.teardown(); | |
11352 } | |
11353 } | |
11354 }); | |
11355 } | |
11356 | |
11357 localeModule('fr-ca'); | |
11358 | |
11359 test('parse', function (assert) { | |
11360 var i, | |
11361 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('_'); | |
11362 | |
11363 function equalTest(input, mmm, i) { | |
11364 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
11365 } | |
11366 | |
11367 for (i = 0; i < 12; i++) { | |
11368 tests[i] = tests[i].split(' '); | |
11369 equalTest(tests[i][0], 'MMM', i); | |
11370 equalTest(tests[i][1], 'MMM', i); | |
11371 equalTest(tests[i][0], 'MMMM', i); | |
11372 equalTest(tests[i][1], 'MMMM', i); | |
11373 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
11374 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
11375 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
11376 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
11377 } | |
11378 }); | |
11379 | |
11380 test('format', function (assert) { | |
11381 var a = [ | |
11382 ['dddd, MMMM Do YYYY, h:mm:ss a', 'dimanche, février 14e 2010, 3:25:50 pm'], | |
11383 ['ddd, hA', 'dim., 3PM'], | |
11384 ['M Mo MM MMMM MMM', '2 2e 02 février févr.'], | |
11385 ['YYYY YY', '2010 10'], | |
11386 ['D Do DD', '14 14e 14'], | |
11387 ['d do dddd ddd dd', '0 0e dimanche dim. Di'], | |
11388 ['DDD DDDo DDDD', '45 45e 045'], | |
11389 ['w wo ww', '8 8e 08'], | |
11390 ['h hh', '3 03'], | |
11391 ['H HH', '15 15'], | |
11392 ['m mm', '25 25'], | |
11393 ['s ss', '50 50'], | |
11394 ['a A', 'pm PM'], | |
11395 ['[the] DDDo [day of the year]', 'the 45e day of the year'], | |
11396 ['LTS', '15:25:50'], | |
11397 ['L', '2010-02-14'], | |
11398 ['LL', '14 février 2010'], | |
11399 ['LLL', '14 février 2010 15:25'], | |
11400 ['LLLL', 'dimanche 14 février 2010 15:25'], | |
11401 ['l', '2010-2-14'], | |
11402 ['ll', '14 févr. 2010'], | |
11403 ['lll', '14 févr. 2010 15:25'], | |
11404 ['llll', 'dim. 14 févr. 2010 15:25'] | |
11405 ], | |
11406 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
11407 i; | |
11408 | |
11409 for (i = 0; i < a.length; i++) { | |
11410 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
11411 } | |
11412 }); | |
11413 | |
11414 test('format ordinal', function (assert) { | |
11415 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1er', '1er'); | |
11416 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2e', '2e'); | |
11417 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3e', '3e'); | |
11418 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4e', '4e'); | |
11419 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5e', '5e'); | |
11420 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6e', '6e'); | |
11421 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7e', '7e'); | |
11422 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8e', '8e'); | |
11423 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9e', '9e'); | |
11424 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10e', '10e'); | |
11425 | |
11426 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11e', '11e'); | |
11427 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12e', '12e'); | |
11428 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13e', '13e'); | |
11429 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14e', '14e'); | |
11430 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15e', '15e'); | |
11431 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16e', '16e'); | |
11432 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17e', '17e'); | |
11433 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18e', '18e'); | |
11434 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19e', '19e'); | |
11435 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20e', '20e'); | |
11436 | |
11437 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21e', '21e'); | |
11438 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22e', '22e'); | |
11439 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23e', '23e'); | |
11440 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24e', '24e'); | |
11441 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25e', '25e'); | |
11442 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26e', '26e'); | |
11443 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27e', '27e'); | |
11444 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28e', '28e'); | |
11445 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29e', '29e'); | |
11446 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30e', '30e'); | |
11447 | |
11448 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31e', '31e'); | |
11449 }); | |
11450 | |
11451 test('format month', function (assert) { | |
11452 var i, | |
11453 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('_'); | |
11454 | |
11455 for (i = 0; i < expected.length; i++) { | |
11456 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
11457 } | |
11458 }); | |
11459 | |
11460 test('format week', function (assert) { | |
11461 var i, | |
11462 expected = 'dimanche dim. Di_lundi lun. Lu_mardi mar. Ma_mercredi mer. Me_jeudi jeu. Je_vendredi ven. Ve_samedi sam. Sa'.split('_'); | |
11463 | |
11464 for (i = 0; i < expected.length; i++) { | |
11465 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
11466 } | |
11467 }); | |
11468 | |
11469 test('from', function (assert) { | |
11470 var start = moment([2007, 1, 28]); | |
11471 | |
11472 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'quelques secondes', '44 seconds = a few seconds'); | |
11473 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'une minute', '45 seconds = a minute'); | |
11474 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'une minute', '89 seconds = a minute'); | |
11475 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes'); | |
11476 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes'); | |
11477 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'une heure', '45 minutes = an hour'); | |
11478 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'une heure', '89 minutes = an hour'); | |
11479 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 heures', '90 minutes = 2 hours'); | |
11480 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 heures', '5 hours = 5 hours'); | |
11481 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 heures', '21 hours = 21 hours'); | |
11482 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un jour', '22 hours = a day'); | |
11483 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un jour', '35 hours = a day'); | |
11484 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 jours', '36 hours = 2 days'); | |
11485 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un jour', '1 day = a day'); | |
11486 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 jours', '5 days = 5 days'); | |
11487 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 jours', '25 days = 25 days'); | |
11488 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'un mois', '26 days = a month'); | |
11489 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'un mois', '30 days = a month'); | |
11490 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'un mois', '43 days = a month'); | |
11491 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mois', '46 days = 2 months'); | |
11492 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mois', '75 days = 2 months'); | |
11493 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mois', '76 days = 3 months'); | |
11494 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'un mois', '1 month = a month'); | |
11495 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mois', '5 months = 5 months'); | |
11496 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un an', '345 days = a year'); | |
11497 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ans', '548 days = 2 years'); | |
11498 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un an', '1 year = a year'); | |
11499 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ans', '5 years = 5 years'); | |
11500 }); | |
11501 | |
11502 test('suffix', function (assert) { | |
11503 assert.equal(moment(30000).from(0), 'dans quelques secondes', 'prefix'); | |
11504 assert.equal(moment(0).from(30000), 'il y a quelques secondes', 'suffix'); | |
11505 }); | |
11506 | |
11507 test('fromNow', function (assert) { | |
11508 assert.equal(moment().add({s: 30}).fromNow(), 'dans quelques secondes', 'in a few seconds'); | |
11509 assert.equal(moment().add({d: 5}).fromNow(), 'dans 5 jours', 'in 5 days'); | |
11510 }); | |
11511 | |
11512 test('same day', function (assert) { | |
11513 var a = moment().hours(2).minutes(0).seconds(0); | |
11514 | |
11515 assert.equal(moment(a).calendar(), 'Aujourd\'hui à 02:00', 'today at the same time'); | |
11516 assert.equal(moment(a).add({m: 25}).calendar(), 'Aujourd\'hui à 02:25', 'Now plus 25 min'); | |
11517 assert.equal(moment(a).add({h: 1}).calendar(), 'Aujourd\'hui à 03:00', 'Now plus 1 hour'); | |
11518 assert.equal(moment(a).add({d: 1}).calendar(), 'Demain à 02:00', 'tomorrow at the same time'); | |
11519 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Aujourd\'hui à 01:00', 'Now minus 1 hour'); | |
11520 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Hier à 02:00', 'yesterday at the same time'); | |
11521 }); | |
11522 | |
11523 test('same next week', function (assert) { | |
11524 var i, m; | |
11525 | |
11526 for (i = 2; i < 7; i++) { | |
11527 m = moment().add({d: i}); | |
11528 assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days current time'); | |
11529 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
11530 assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days beginning of day'); | |
11531 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
11532 assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days end of day'); | |
11533 } | |
11534 }); | |
11535 | |
11536 test('same last week', function (assert) { | |
11537 var i, m; | |
11538 | |
11539 for (i = 2; i < 7; i++) { | |
11540 m = moment().subtract({d: i}); | |
11541 assert.equal(m.calendar(), m.format('dddd [dernier à] LT'), 'Today - ' + i + ' days current time'); | |
11542 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
11543 assert.equal(m.calendar(), m.format('dddd [dernier à] LT'), 'Today - ' + i + ' days beginning of day'); | |
11544 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
11545 assert.equal(m.calendar(), m.format('dddd [dernier à] LT'), 'Today - ' + i + ' days end of day'); | |
11546 } | |
11547 }); | |
11548 | |
11549 test('same all else', function (assert) { | |
11550 var weeksAgo = moment().subtract({w: 1}), | |
11551 weeksFromNow = moment().add({w: 1}); | |
11552 | |
11553 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
11554 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
11555 | |
11556 weeksAgo = moment().subtract({w: 2}); | |
11557 weeksFromNow = moment().add({w: 2}); | |
11558 | |
11559 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
11560 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
11561 }); | |
11562 | |
11563 test('weeks year starting sunday', function (assert) { | |
11564 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
11565 assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1'); | |
11566 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
11567 assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2'); | |
11568 assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3'); | |
11569 }); | |
11570 | |
11571 test('weeks year starting monday', function (assert) { | |
11572 assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1'); | |
11573 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
11574 assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1'); | |
11575 assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2'); | |
11576 assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2'); | |
11577 assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3'); | |
11578 }); | |
11579 | |
11580 test('weeks year starting tuesday', function (assert) { | |
11581 assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52'); | |
11582 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
11583 assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1'); | |
11584 assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2'); | |
11585 assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2'); | |
11586 assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3'); | |
11587 }); | |
11588 | |
11589 test('weeks year starting wednesday', function (assert) { | |
11590 assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1'); | |
11591 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
11592 assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1'); | |
11593 assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2'); | |
11594 assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2'); | |
11595 assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3'); | |
11596 }); | |
11597 | |
11598 test('weeks year starting thursday', function (assert) { | |
11599 assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1'); | |
11600 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
11601 assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1'); | |
11602 assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2'); | |
11603 assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2'); | |
11604 assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3'); | |
11605 }); | |
11606 | |
11607 test('weeks year starting friday', function (assert) { | |
11608 assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1'); | |
11609 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
11610 assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1'); | |
11611 assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2'); | |
11612 assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2'); | |
11613 assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3'); | |
11614 }); | |
11615 | |
11616 test('weeks year starting saturday', function (assert) { | |
11617 assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1'); | |
11618 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
11619 assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2'); | |
11620 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2'); | |
11621 assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3'); | |
11622 }); | |
11623 | |
11624 test('weeks year starting sunday format', function (assert) { | |
11625 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1er', 'Jan 1 2012 should be week 1'); | |
11626 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1er', 'Jan 7 2012 should be week 1'); | |
11627 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2e', 'Jan 8 2012 should be week 2'); | |
11628 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2e', 'Jan 14 2012 should be week 2'); | |
11629 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3e', 'Jan 15 2012 should be week 3'); | |
11630 }); | |
11631 | |
11632 test('lenient ordinal parsing', function (assert) { | |
11633 var i, ordinalStr, testMoment; | |
11634 for (i = 1; i <= 31; ++i) { | |
11635 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
11636 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
11637 assert.equal(testMoment.year(), 2014, | |
11638 'lenient ordinal parsing ' + i + ' year check'); | |
11639 assert.equal(testMoment.month(), 0, | |
11640 'lenient ordinal parsing ' + i + ' month check'); | |
11641 assert.equal(testMoment.date(), i, | |
11642 'lenient ordinal parsing ' + i + ' date check'); | |
11643 } | |
11644 }); | |
11645 | |
11646 test('lenient ordinal parsing of number', function (assert) { | |
11647 var i, testMoment; | |
11648 for (i = 1; i <= 31; ++i) { | |
11649 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
11650 assert.equal(testMoment.year(), 2014, | |
11651 'lenient ordinal parsing of number ' + i + ' year check'); | |
11652 assert.equal(testMoment.month(), 0, | |
11653 'lenient ordinal parsing of number ' + i + ' month check'); | |
11654 assert.equal(testMoment.date(), i, | |
11655 'lenient ordinal parsing of number ' + i + ' date check'); | |
11656 } | |
11657 }); | |
11658 | |
11659 test('strict ordinal parsing', function (assert) { | |
11660 var i, ordinalStr, testMoment; | |
11661 for (i = 1; i <= 31; ++i) { | |
11662 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
11663 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
11664 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
11665 } | |
11666 }); | |
11667 | |
11668 })); | |
11669 | |
11670 (function (global, factory) { | |
11671 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
11672 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
11673 factory(global.moment) | |
11674 }(this, function (moment) { 'use strict'; | |
11675 | |
11676 /*global QUnit:false*/ | |
11677 | |
11678 var test = QUnit.test; | |
11679 | |
11680 function module (name, lifecycle) { | |
11681 QUnit.module(name, { | |
11682 setup : function () { | |
11683 moment.locale('en'); | |
11684 moment.createFromInputFallback = function () { | |
11685 throw new Error('input not handled by moment'); | |
11686 }; | |
11687 if (lifecycle && lifecycle.setup) { | |
11688 lifecycle.setup(); | |
11689 } | |
11690 }, | |
11691 teardown : function () { | |
11692 if (lifecycle && lifecycle.teardown) { | |
11693 lifecycle.teardown(); | |
11694 } | |
11695 } | |
11696 }); | |
11697 } | |
11698 | |
11699 function localeModule (name, lifecycle) { | |
11700 QUnit.module('locale:' + name, { | |
11701 setup : function () { | |
11702 moment.locale(name); | |
11703 moment.createFromInputFallback = function () { | |
11704 throw new Error('input not handled by moment'); | |
11705 }; | |
11706 if (lifecycle && lifecycle.setup) { | |
11707 lifecycle.setup(); | |
11708 } | |
11709 }, | |
11710 teardown : function () { | |
11711 moment.locale('en'); | |
11712 if (lifecycle && lifecycle.teardown) { | |
11713 lifecycle.teardown(); | |
11714 } | |
11715 } | |
11716 }); | |
11717 } | |
11718 | |
11719 localeModule('fr'); | |
11720 | |
11721 test('parse', function (assert) { | |
11722 var 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('_'), | |
11723 i; | |
11724 function equalTest(input, mmm, i) { | |
11725 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
11726 } | |
11727 for (i = 0; i < 12; i++) { | |
11728 tests[i] = tests[i].split(' '); | |
11729 equalTest(tests[i][0], 'MMM', i); | |
11730 equalTest(tests[i][1], 'MMM', i); | |
11731 equalTest(tests[i][0], 'MMMM', i); | |
11732 equalTest(tests[i][1], 'MMMM', i); | |
11733 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
11734 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
11735 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
11736 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
11737 } | |
11738 }); | |
11739 | |
11740 test('format', function (assert) { | |
11741 var a = [ | |
11742 ['dddd, MMMM Do YYYY, h:mm:ss a', 'dimanche, février 14 2010, 3:25:50 pm'], | |
11743 ['ddd, hA', 'dim., 3PM'], | |
11744 ['M Mo MM MMMM MMM', '2 2 02 février févr.'], | |
11745 ['YYYY YY', '2010 10'], | |
11746 ['D Do DD', '14 14 14'], | |
11747 ['d do dddd ddd dd', '0 0 dimanche dim. Di'], | |
11748 ['DDD DDDo DDDD', '45 45 045'], | |
11749 ['w wo ww', '6 6 06'], | |
11750 ['h hh', '3 03'], | |
11751 ['H HH', '15 15'], | |
11752 ['m mm', '25 25'], | |
11753 ['s ss', '50 50'], | |
11754 ['a A', 'pm PM'], | |
11755 ['[the] DDDo [day of the year]', 'the 45 day of the year'], | |
11756 ['LTS', '15:25:50'], | |
11757 ['L', '14/02/2010'], | |
11758 ['LL', '14 février 2010'], | |
11759 ['LLL', '14 février 2010 15:25'], | |
11760 ['LLLL', 'dimanche 14 février 2010 15:25'], | |
11761 ['l', '14/2/2010'], | |
11762 ['ll', '14 févr. 2010'], | |
11763 ['lll', '14 févr. 2010 15:25'], | |
11764 ['llll', 'dim. 14 févr. 2010 15:25'] | |
11765 ], | |
11766 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
11767 i; | |
11768 for (i = 0; i < a.length; i++) { | |
11769 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
11770 } | |
11771 }); | |
11772 | |
11773 test('format ordinal', function (assert) { | |
11774 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1er', '1er'); | |
11775 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2'); | |
11776 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3'); | |
11777 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4'); | |
11778 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5'); | |
11779 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6'); | |
11780 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7'); | |
11781 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8'); | |
11782 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9'); | |
11783 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10'); | |
11784 | |
11785 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11'); | |
11786 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12'); | |
11787 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13'); | |
11788 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14'); | |
11789 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15'); | |
11790 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16'); | |
11791 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17'); | |
11792 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18'); | |
11793 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19'); | |
11794 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20'); | |
11795 | |
11796 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21'); | |
11797 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22'); | |
11798 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23'); | |
11799 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24'); | |
11800 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25'); | |
11801 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26'); | |
11802 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27'); | |
11803 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28'); | |
11804 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29'); | |
11805 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30'); | |
11806 | |
11807 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31'); | |
11808 }); | |
11809 | |
11810 test('format month', function (assert) { | |
11811 var 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('_'), i; | |
11812 for (i = 0; i < expected.length; i++) { | |
11813 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
11814 } | |
11815 }); | |
11816 | |
11817 test('format week', function (assert) { | |
11818 var expected = 'dimanche dim. Di_lundi lun. Lu_mardi mar. Ma_mercredi mer. Me_jeudi jeu. Je_vendredi ven. Ve_samedi sam. Sa'.split('_'), i; | |
11819 for (i = 0; i < expected.length; i++) { | |
11820 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
11821 } | |
11822 }); | |
11823 | |
11824 test('from', function (assert) { | |
11825 var start = moment([2007, 1, 28]); | |
11826 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'quelques secondes', '44 seconds = a few seconds'); | |
11827 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'une minute', '45 seconds = a minute'); | |
11828 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'une minute', '89 seconds = a minute'); | |
11829 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutes', '90 seconds = 2 minutes'); | |
11830 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutes', '44 minutes = 44 minutes'); | |
11831 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'une heure', '45 minutes = an hour'); | |
11832 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'une heure', '89 minutes = an hour'); | |
11833 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 heures', '90 minutes = 2 hours'); | |
11834 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 heures', '5 hours = 5 hours'); | |
11835 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 heures', '21 hours = 21 hours'); | |
11836 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un jour', '22 hours = a day'); | |
11837 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un jour', '35 hours = a day'); | |
11838 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 jours', '36 hours = 2 days'); | |
11839 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un jour', '1 day = a day'); | |
11840 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 jours', '5 days = 5 days'); | |
11841 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 jours', '25 days = 25 days'); | |
11842 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'un mois', '26 days = a month'); | |
11843 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'un mois', '30 days = a month'); | |
11844 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'un mois', '43 days = a month'); | |
11845 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mois', '46 days = 2 months'); | |
11846 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mois', '75 days = 2 months'); | |
11847 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mois', '76 days = 3 months'); | |
11848 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'un mois', '1 month = a month'); | |
11849 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mois', '5 months = 5 months'); | |
11850 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un an', '345 days = a year'); | |
11851 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ans', '548 days = 2 years'); | |
11852 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un an', '1 year = a year'); | |
11853 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ans', '5 years = 5 years'); | |
11854 }); | |
11855 | |
11856 test('suffix', function (assert) { | |
11857 assert.equal(moment(30000).from(0), 'dans quelques secondes', 'prefix'); | |
11858 assert.equal(moment(0).from(30000), 'il y a quelques secondes', 'suffix'); | |
11859 }); | |
11860 | |
11861 test('fromNow', function (assert) { | |
11862 assert.equal(moment().add({s: 30}).fromNow(), 'dans quelques secondes', 'in a few seconds'); | |
11863 assert.equal(moment().add({d: 5}).fromNow(), 'dans 5 jours', 'in 5 days'); | |
11864 }); | |
11865 | |
11866 test('same day', function (assert) { | |
11867 var a = moment().hours(2).minutes(0).seconds(0); | |
11868 | |
11869 assert.equal(moment(a).calendar(), 'Aujourd\'hui à 02:00', 'today at the same time'); | |
11870 assert.equal(moment(a).add({m: 25}).calendar(), 'Aujourd\'hui à 02:25', 'Now plus 25 min'); | |
11871 assert.equal(moment(a).add({h: 1}).calendar(), 'Aujourd\'hui à 03:00', 'Now plus 1 hour'); | |
11872 assert.equal(moment(a).add({d: 1}).calendar(), 'Demain à 02:00', 'tomorrow at the same time'); | |
11873 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Aujourd\'hui à 01:00', 'Now minus 1 hour'); | |
11874 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Hier à 02:00', 'yesterday at the same time'); | |
11875 }); | |
11876 | |
11877 test('same next week', function (assert) { | |
11878 var i, m; | |
11879 | |
11880 for (i = 2; i < 7; i++) { | |
11881 m = moment().add({d: i}); | |
11882 assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days current time'); | |
11883 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
11884 assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days beginning of day'); | |
11885 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
11886 assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days end of day'); | |
11887 } | |
11888 }); | |
11889 | |
11890 test('same last week', function (assert) { | |
11891 var i, m; | |
11892 | |
11893 for (i = 2; i < 7; i++) { | |
11894 m = moment().subtract({d: i}); | |
11895 assert.equal(m.calendar(), m.format('dddd [dernier à] LT'), 'Today - ' + i + ' days current time'); | |
11896 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
11897 assert.equal(m.calendar(), m.format('dddd [dernier à] LT'), 'Today - ' + i + ' days beginning of day'); | |
11898 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
11899 assert.equal(m.calendar(), m.format('dddd [dernier à] LT'), 'Today - ' + i + ' days end of day'); | |
11900 } | |
11901 }); | |
11902 | |
11903 test('same all else', function (assert) { | |
11904 var weeksAgo = moment().subtract({w: 1}), | |
11905 weeksFromNow = moment().add({w: 1}); | |
11906 | |
11907 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
11908 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
11909 | |
11910 weeksAgo = moment().subtract({w: 2}); | |
11911 weeksFromNow = moment().add({w: 2}); | |
11912 | |
11913 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
11914 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
11915 }); | |
11916 | |
11917 test('weeks year starting sunday', function (assert) { | |
11918 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
11919 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
11920 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
11921 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
11922 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
11923 }); | |
11924 | |
11925 test('weeks year starting monday', function (assert) { | |
11926 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
11927 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
11928 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
11929 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
11930 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
11931 }); | |
11932 | |
11933 test('weeks year starting tuesday', function (assert) { | |
11934 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
11935 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
11936 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
11937 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
11938 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
11939 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
11940 }); | |
11941 | |
11942 test('weeks year starting wednesday', function (assert) { | |
11943 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
11944 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
11945 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
11946 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
11947 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
11948 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
11949 }); | |
11950 | |
11951 test('weeks year starting thursday', function (assert) { | |
11952 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
11953 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
11954 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
11955 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
11956 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
11957 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
11958 }); | |
11959 | |
11960 test('weeks year starting friday', function (assert) { | |
11961 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
11962 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
11963 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
11964 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
11965 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
11966 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
11967 }); | |
11968 | |
11969 test('weeks year starting saturday', function (assert) { | |
11970 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
11971 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
11972 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
11973 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
11974 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
11975 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
11976 }); | |
11977 | |
11978 test('weeks year starting sunday formatted', function (assert) { | |
11979 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52', 'Jan 1 2012 should be week 52'); | |
11980 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1er', 'Jan 2 2012 should be week 1'); | |
11981 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1er', 'Jan 8 2012 should be week 1'); | |
11982 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2', 'Jan 9 2012 should be week 2'); | |
11983 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2', 'Jan 15 2012 should be week 2'); | |
11984 }); | |
11985 | |
11986 test('lenient ordinal parsing', function (assert) { | |
11987 var i, ordinalStr, testMoment; | |
11988 for (i = 1; i <= 31; ++i) { | |
11989 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
11990 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
11991 assert.equal(testMoment.year(), 2014, | |
11992 'lenient ordinal parsing ' + i + ' year check'); | |
11993 assert.equal(testMoment.month(), 0, | |
11994 'lenient ordinal parsing ' + i + ' month check'); | |
11995 assert.equal(testMoment.date(), i, | |
11996 'lenient ordinal parsing ' + i + ' date check'); | |
11997 } | |
11998 }); | |
11999 | |
12000 test('lenient ordinal parsing of number', function (assert) { | |
12001 var i, testMoment; | |
12002 for (i = 1; i <= 31; ++i) { | |
12003 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
12004 assert.equal(testMoment.year(), 2014, | |
12005 'lenient ordinal parsing of number ' + i + ' year check'); | |
12006 assert.equal(testMoment.month(), 0, | |
12007 'lenient ordinal parsing of number ' + i + ' month check'); | |
12008 assert.equal(testMoment.date(), i, | |
12009 'lenient ordinal parsing of number ' + i + ' date check'); | |
12010 } | |
12011 }); | |
12012 | |
12013 test('strict ordinal parsing', function (assert) { | |
12014 var i, ordinalStr, testMoment; | |
12015 for (i = 1; i <= 31; ++i) { | |
12016 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
12017 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
12018 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
12019 } | |
12020 }); | |
12021 | |
12022 })); | |
12023 | |
12024 (function (global, factory) { | |
12025 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
12026 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
12027 factory(global.moment) | |
12028 }(this, function (moment) { 'use strict'; | |
12029 | |
12030 /*global QUnit:false*/ | |
12031 | |
12032 var test = QUnit.test; | |
12033 | |
12034 function module (name, lifecycle) { | |
12035 QUnit.module(name, { | |
12036 setup : function () { | |
12037 moment.locale('en'); | |
12038 moment.createFromInputFallback = function () { | |
12039 throw new Error('input not handled by moment'); | |
12040 }; | |
12041 if (lifecycle && lifecycle.setup) { | |
12042 lifecycle.setup(); | |
12043 } | |
12044 }, | |
12045 teardown : function () { | |
12046 if (lifecycle && lifecycle.teardown) { | |
12047 lifecycle.teardown(); | |
12048 } | |
12049 } | |
12050 }); | |
12051 } | |
12052 | |
12053 function localeModule (name, lifecycle) { | |
12054 QUnit.module('locale:' + name, { | |
12055 setup : function () { | |
12056 moment.locale(name); | |
12057 moment.createFromInputFallback = function () { | |
12058 throw new Error('input not handled by moment'); | |
12059 }; | |
12060 if (lifecycle && lifecycle.setup) { | |
12061 lifecycle.setup(); | |
12062 } | |
12063 }, | |
12064 teardown : function () { | |
12065 moment.locale('en'); | |
12066 if (lifecycle && lifecycle.teardown) { | |
12067 lifecycle.teardown(); | |
12068 } | |
12069 } | |
12070 }); | |
12071 } | |
12072 | |
12073 localeModule('fy'); | |
12074 | |
12075 test('parse', function (assert) { | |
12076 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; | |
12077 function equalTest(input, mmm, i) { | |
12078 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
12079 } | |
12080 for (i = 0; i < 12; i++) { | |
12081 tests[i] = tests[i].split(' '); | |
12082 equalTest(tests[i][0], 'MMM', i); | |
12083 equalTest(tests[i][1], 'MMM', i); | |
12084 equalTest(tests[i][0], 'MMMM', i); | |
12085 equalTest(tests[i][1], 'MMMM', i); | |
12086 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
12087 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
12088 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
12089 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
12090 } | |
12091 }); | |
12092 | |
12093 test('format', function (assert) { | |
12094 var a = [ | |
12095 ['dddd, MMMM Do YYYY, HH:mm:ss', 'snein, febrewaris 14de 2010, 15:25:50'], | |
12096 ['ddd, HH', 'si., 15'], | |
12097 ['M Mo MM MMMM MMM', '2 2de 02 febrewaris feb.'], | |
12098 ['YYYY YY', '2010 10'], | |
12099 ['D Do DD', '14 14de 14'], | |
12100 ['d do dddd ddd dd', '0 0de snein si. Si'], | |
12101 ['DDD DDDo DDDD', '45 45ste 045'], | |
12102 ['w wo ww', '6 6de 06'], | |
12103 ['h hh', '3 03'], | |
12104 ['H HH', '15 15'], | |
12105 ['m mm', '25 25'], | |
12106 ['s ss', '50 50'], | |
12107 ['a A', 'pm PM'], | |
12108 ['[the] DDDo [day of the year]', 'the 45ste day of the year'], | |
12109 ['LTS', '15:25:50'], | |
12110 ['L', '14-02-2010'], | |
12111 ['LL', '14 febrewaris 2010'], | |
12112 ['LLL', '14 febrewaris 2010 15:25'], | |
12113 ['LLLL', 'snein 14 febrewaris 2010 15:25'], | |
12114 ['l', '14-2-2010'], | |
12115 ['ll', '14 feb. 2010'], | |
12116 ['lll', '14 feb. 2010 15:25'], | |
12117 ['llll', 'si. 14 feb. 2010 15:25'] | |
12118 ], | |
12119 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
12120 i; | |
12121 for (i = 0; i < a.length; i++) { | |
12122 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
12123 } | |
12124 }); | |
12125 | |
12126 test('format ordinal', function (assert) { | |
12127 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1ste', '1ste'); | |
12128 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2de', '2de'); | |
12129 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3de', '3de'); | |
12130 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4de', '4de'); | |
12131 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5de', '5de'); | |
12132 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6de', '6de'); | |
12133 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7de', '7de'); | |
12134 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8ste', '8ste'); | |
12135 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9de', '9de'); | |
12136 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10de', '10de'); | |
12137 | |
12138 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11de', '11de'); | |
12139 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12de', '12de'); | |
12140 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13de', '13de'); | |
12141 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14de', '14de'); | |
12142 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15de', '15de'); | |
12143 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16de', '16de'); | |
12144 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17de', '17de'); | |
12145 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18de', '18de'); | |
12146 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19de', '19de'); | |
12147 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20ste', '20ste'); | |
12148 | |
12149 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21ste', '21ste'); | |
12150 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22ste', '22ste'); | |
12151 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23ste', '23ste'); | |
12152 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24ste', '24ste'); | |
12153 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25ste', '25ste'); | |
12154 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26ste', '26ste'); | |
12155 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27ste', '27ste'); | |
12156 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28ste', '28ste'); | |
12157 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29ste', '29ste'); | |
12158 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30ste', '30ste'); | |
12159 | |
12160 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31ste', '31ste'); | |
12161 }); | |
12162 | |
12163 test('format month', function (assert) { | |
12164 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; | |
12165 for (i = 0; i < expected.length; i++) { | |
12166 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
12167 } | |
12168 }); | |
12169 | |
12170 test('format week', function (assert) { | |
12171 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; | |
12172 for (i = 0; i < expected.length; i++) { | |
12173 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
12174 } | |
12175 }); | |
12176 | |
12177 test('from', function (assert) { | |
12178 var start = moment([2007, 1, 28]); | |
12179 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'in pear sekonden', '44 seconds = a few seconds'); | |
12180 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ien minút', '45 seconds = a minute'); | |
12181 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ien minút', '89 seconds = a minute'); | |
12182 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuten', '90 seconds = 2 minutes'); | |
12183 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuten', '44 minutes = 44 minutes'); | |
12184 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ien oere', '45 minutes = an hour'); | |
12185 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ien oere', '89 minutes = an hour'); | |
12186 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 oeren', '90 minutes = 2 hours'); | |
12187 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 oeren', '5 hours = 5 hours'); | |
12188 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 oeren', '21 hours = 21 hours'); | |
12189 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ien dei', '22 hours = a day'); | |
12190 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ien dei', '35 hours = a day'); | |
12191 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dagen', '36 hours = 2 days'); | |
12192 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ien dei', '1 day = a day'); | |
12193 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dagen', '5 days = 5 days'); | |
12194 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dagen', '25 days = 25 days'); | |
12195 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ien moanne', '26 days = a month'); | |
12196 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ien moanne', '30 days = a month'); | |
12197 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ien moanne', '43 days = a month'); | |
12198 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 moannen', '46 days = 2 months'); | |
12199 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 moannen', '75 days = 2 months'); | |
12200 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 moannen', '76 days = 3 months'); | |
12201 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ien moanne', '1 month = a month'); | |
12202 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 moannen', '5 months = 5 months'); | |
12203 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ien jier', '345 days = a year'); | |
12204 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 jierren', '548 days = 2 years'); | |
12205 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ien jier', '1 year = a year'); | |
12206 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 jierren', '5 years = 5 years'); | |
12207 }); | |
12208 | |
12209 test('suffix', function (assert) { | |
12210 assert.equal(moment(30000).from(0), 'oer in pear sekonden', 'prefix'); | |
12211 assert.equal(moment(0).from(30000), 'in pear sekonden lyn', 'suffix'); | |
12212 }); | |
12213 | |
12214 test('now from now', function (assert) { | |
12215 assert.equal(moment().fromNow(), 'in pear sekonden lyn', 'now from now should display as in the past'); | |
12216 }); | |
12217 | |
12218 test('fromNow', function (assert) { | |
12219 assert.equal(moment().add({s: 30}).fromNow(), 'oer in pear sekonden', 'in a few seconds'); | |
12220 assert.equal(moment().add({d: 5}).fromNow(), 'oer 5 dagen', 'in 5 days'); | |
12221 }); | |
12222 | |
12223 test('calendar day', function (assert) { | |
12224 var a = moment().hours(2).minutes(0).seconds(0); | |
12225 | |
12226 assert.equal(moment(a).calendar(), 'hjoed om 02:00', 'today at the same time'); | |
12227 assert.equal(moment(a).add({m: 25}).calendar(), 'hjoed om 02:25', 'Now plus 25 min'); | |
12228 assert.equal(moment(a).add({h: 1}).calendar(), 'hjoed om 03:00', 'Now plus 1 hour'); | |
12229 assert.equal(moment(a).add({d: 1}).calendar(), 'moarn om 02:00', 'tomorrow at the same time'); | |
12230 assert.equal(moment(a).subtract({h: 1}).calendar(), 'hjoed om 01:00', 'Now minus 1 hour'); | |
12231 assert.equal(moment(a).subtract({d: 1}).calendar(), 'juster om 02:00', 'yesterday at the same time'); | |
12232 }); | |
12233 | |
12234 test('calendar next week', function (assert) { | |
12235 var i, m; | |
12236 for (i = 2; i < 7; i++) { | |
12237 m = moment().add({d: i}); | |
12238 assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days current time'); | |
12239 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
12240 assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days beginning of day'); | |
12241 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
12242 assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days end of day'); | |
12243 } | |
12244 }); | |
12245 | |
12246 test('calendar last week', function (assert) { | |
12247 var i, m; | |
12248 for (i = 2; i < 7; i++) { | |
12249 m = moment().subtract({d: i}); | |
12250 assert.equal(m.calendar(), m.format('[ôfrûne] dddd [om] LT'), 'Today - ' + i + ' days current time'); | |
12251 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
12252 assert.equal(m.calendar(), m.format('[ôfrûne] dddd [om] LT'), 'Today - ' + i + ' days beginning of day'); | |
12253 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
12254 assert.equal(m.calendar(), m.format('[ôfrûne] dddd [om] LT'), 'Today - ' + i + ' days end of day'); | |
12255 } | |
12256 }); | |
12257 | |
12258 test('calendar all else', function (assert) { | |
12259 var weeksAgo = moment().subtract({w: 1}), | |
12260 weeksFromNow = moment().add({w: 1}); | |
12261 | |
12262 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
12263 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
12264 | |
12265 weeksAgo = moment().subtract({w: 2}); | |
12266 weeksFromNow = moment().add({w: 2}); | |
12267 | |
12268 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
12269 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
12270 }); | |
12271 | |
12272 test('month abbreviation', function (assert) { | |
12273 assert.equal(moment([2012, 5, 23]).format('D-MMM-YYYY'), '23-jun-2012', 'format month abbreviation surrounded by dashes should not include a dot'); | |
12274 assert.equal(moment([2012, 5, 23]).format('D MMM YYYY'), '23 jun. 2012', 'format month abbreviation not surrounded by dashes should include a dot'); | |
12275 }); | |
12276 | |
12277 test('weeks year starting sunday', function (assert) { | |
12278 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
12279 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
12280 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
12281 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
12282 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
12283 }); | |
12284 | |
12285 test('weeks year starting monday', function (assert) { | |
12286 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
12287 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
12288 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
12289 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
12290 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
12291 }); | |
12292 | |
12293 test('weeks year starting tuesday', function (assert) { | |
12294 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
12295 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
12296 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
12297 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
12298 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
12299 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
12300 }); | |
12301 | |
12302 test('weeks year starting wednesday', function (assert) { | |
12303 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
12304 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
12305 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
12306 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
12307 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
12308 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
12309 }); | |
12310 | |
12311 test('weeks year starting thursday', function (assert) { | |
12312 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
12313 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
12314 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
12315 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
12316 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
12317 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
12318 }); | |
12319 | |
12320 test('weeks year starting friday', function (assert) { | |
12321 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
12322 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
12323 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
12324 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
12325 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
12326 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
12327 }); | |
12328 | |
12329 test('weeks year starting saturday', function (assert) { | |
12330 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
12331 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
12332 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
12333 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
12334 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
12335 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
12336 }); | |
12337 | |
12338 test('weeks year starting sunday formatted', function (assert) { | |
12339 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52ste', 'Jan 1 2012 should be week 52'); | |
12340 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1ste', 'Jan 2 2012 should be week 1'); | |
12341 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1ste', 'Jan 8 2012 should be week 1'); | |
12342 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2de', 'Jan 9 2012 should be week 2'); | |
12343 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2de', 'Jan 15 2012 should be week 2'); | |
12344 }); | |
12345 | |
12346 test('lenient ordinal parsing', function (assert) { | |
12347 var i, ordinalStr, testMoment; | |
12348 for (i = 1; i <= 31; ++i) { | |
12349 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
12350 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
12351 assert.equal(testMoment.year(), 2014, | |
12352 'lenient ordinal parsing ' + i + ' year check'); | |
12353 assert.equal(testMoment.month(), 0, | |
12354 'lenient ordinal parsing ' + i + ' month check'); | |
12355 assert.equal(testMoment.date(), i, | |
12356 'lenient ordinal parsing ' + i + ' date check'); | |
12357 } | |
12358 }); | |
12359 | |
12360 test('lenient ordinal parsing of number', function (assert) { | |
12361 var i, testMoment; | |
12362 for (i = 1; i <= 31; ++i) { | |
12363 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
12364 assert.equal(testMoment.year(), 2014, | |
12365 'lenient ordinal parsing of number ' + i + ' year check'); | |
12366 assert.equal(testMoment.month(), 0, | |
12367 'lenient ordinal parsing of number ' + i + ' month check'); | |
12368 assert.equal(testMoment.date(), i, | |
12369 'lenient ordinal parsing of number ' + i + ' date check'); | |
12370 } | |
12371 }); | |
12372 | |
12373 test('strict ordinal parsing', function (assert) { | |
12374 var i, ordinalStr, testMoment; | |
12375 for (i = 1; i <= 31; ++i) { | |
12376 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
12377 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
12378 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
12379 } | |
12380 }); | |
12381 | |
12382 })); | |
12383 | |
12384 (function (global, factory) { | |
12385 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
12386 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
12387 factory(global.moment) | |
12388 }(this, function (moment) { 'use strict'; | |
12389 | |
12390 /*global QUnit:false*/ | |
12391 | |
12392 var test = QUnit.test; | |
12393 | |
12394 function module (name, lifecycle) { | |
12395 QUnit.module(name, { | |
12396 setup : function () { | |
12397 moment.locale('en'); | |
12398 moment.createFromInputFallback = function () { | |
12399 throw new Error('input not handled by moment'); | |
12400 }; | |
12401 if (lifecycle && lifecycle.setup) { | |
12402 lifecycle.setup(); | |
12403 } | |
12404 }, | |
12405 teardown : function () { | |
12406 if (lifecycle && lifecycle.teardown) { | |
12407 lifecycle.teardown(); | |
12408 } | |
12409 } | |
12410 }); | |
12411 } | |
12412 | |
12413 function localeModule (name, lifecycle) { | |
12414 QUnit.module('locale:' + name, { | |
12415 setup : function () { | |
12416 moment.locale(name); | |
12417 moment.createFromInputFallback = function () { | |
12418 throw new Error('input not handled by moment'); | |
12419 }; | |
12420 if (lifecycle && lifecycle.setup) { | |
12421 lifecycle.setup(); | |
12422 } | |
12423 }, | |
12424 teardown : function () { | |
12425 moment.locale('en'); | |
12426 if (lifecycle && lifecycle.teardown) { | |
12427 lifecycle.teardown(); | |
12428 } | |
12429 } | |
12430 }); | |
12431 } | |
12432 | |
12433 localeModule('gl'); | |
12434 | |
12435 test('parse', function (assert) { | |
12436 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; | |
12437 function equalTest(input, mmm, i) { | |
12438 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
12439 } | |
12440 for (i = 0; i < 12; i++) { | |
12441 tests[i] = tests[i].split(' '); | |
12442 equalTest(tests[i][0], 'MMM', i); | |
12443 equalTest(tests[i][1], 'MMM', i); | |
12444 equalTest(tests[i][0], 'MMMM', i); | |
12445 equalTest(tests[i][1], 'MMMM', i); | |
12446 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
12447 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
12448 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
12449 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
12450 } | |
12451 }); | |
12452 | |
12453 test('format', function (assert) { | |
12454 var a = [ | |
12455 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Domingo, Febreiro 14º 2010, 3:25:50 pm'], | |
12456 ['ddd, hA', 'Dom., 3PM'], | |
12457 ['M Mo MM MMMM MMM', '2 2º 02 Febreiro Feb.'], | |
12458 ['YYYY YY', '2010 10'], | |
12459 ['D Do DD', '14 14º 14'], | |
12460 ['d do dddd ddd dd', '0 0º Domingo Dom. Do'], | |
12461 ['DDD DDDo DDDD', '45 45º 045'], | |
12462 ['w wo ww', '7 7º 07'], | |
12463 ['h hh', '3 03'], | |
12464 ['H HH', '15 15'], | |
12465 ['m mm', '25 25'], | |
12466 ['s ss', '50 50'], | |
12467 ['a A', 'pm PM'], | |
12468 ['[the] DDDo [day of the year]', 'the 45º day of the year'], | |
12469 ['LTS', '15:25:50'], | |
12470 ['L', '14/02/2010'], | |
12471 ['LL', '14 Febreiro 2010'], | |
12472 ['LLL', '14 Febreiro 2010 15:25'], | |
12473 ['LLLL', 'Domingo 14 Febreiro 2010 15:25'], | |
12474 ['l', '14/2/2010'], | |
12475 ['ll', '14 Feb. 2010'], | |
12476 ['lll', '14 Feb. 2010 15:25'], | |
12477 ['llll', 'Dom. 14 Feb. 2010 15:25'] | |
12478 ], | |
12479 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
12480 i; | |
12481 for (i = 0; i < a.length; i++) { | |
12482 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
12483 } | |
12484 }); | |
12485 | |
12486 test('format ordinal', function (assert) { | |
12487 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1º', '1º'); | |
12488 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2º', '2º'); | |
12489 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3º', '3º'); | |
12490 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4º', '4º'); | |
12491 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5º', '5º'); | |
12492 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6º', '6º'); | |
12493 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7º', '7º'); | |
12494 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8º', '8º'); | |
12495 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9º', '9º'); | |
12496 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10º', '10º'); | |
12497 | |
12498 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11º', '11º'); | |
12499 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12º', '12º'); | |
12500 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13º', '13º'); | |
12501 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14º', '14º'); | |
12502 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15º', '15º'); | |
12503 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16º', '16º'); | |
12504 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17º', '17º'); | |
12505 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18º', '18º'); | |
12506 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19º', '19º'); | |
12507 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20º', '20º'); | |
12508 | |
12509 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21º', '21º'); | |
12510 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22º', '22º'); | |
12511 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23º', '23º'); | |
12512 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24º', '24º'); | |
12513 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25º', '25º'); | |
12514 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26º', '26º'); | |
12515 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27º', '27º'); | |
12516 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28º', '28º'); | |
12517 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29º', '29º'); | |
12518 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30º', '30º'); | |
12519 | |
12520 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31º', '31º'); | |
12521 }); | |
12522 | |
12523 test('format month', function (assert) { | |
12524 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; | |
12525 for (i = 0; i < expected.length; i++) { | |
12526 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
12527 } | |
12528 }); | |
12529 | |
12530 test('format week', function (assert) { | |
12531 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('_'), | |
12532 i; | |
12533 for (i = 0; i < expected.length; i++) { | |
12534 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
12535 } | |
12536 }); | |
12537 | |
12538 test('from', function (assert) { | |
12539 var start = moment([2007, 1, 28]); | |
12540 | |
12541 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'uns segundos', '44 seconds = a few seconds'); | |
12542 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'un minuto', '45 seconds = a minute'); | |
12543 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'un minuto', '89 seconds = a minute'); | |
12544 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutos', '90 seconds = 2 minutes'); | |
12545 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutos', '44 minutes = 44 minutes'); | |
12546 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'unha hora', '45 minutes = an hour'); | |
12547 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'unha hora', '89 minutes = an hour'); | |
12548 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 horas', '90 minutes = 2 hours'); | |
12549 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 horas', '5 hours = 5 hours'); | |
12550 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 horas', '21 hours = 21 hours'); | |
12551 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un día', '22 hours = a day'); | |
12552 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un día', '35 hours = a day'); | |
12553 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 días', '36 hours = 2 days'); | |
12554 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un día', '1 day = a day'); | |
12555 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 días', '5 days = 5 days'); | |
12556 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 días', '25 days = 25 days'); | |
12557 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'un mes', '26 days = a month'); | |
12558 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'un mes', '30 days = a month'); | |
12559 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'un mes', '43 days = a month'); | |
12560 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 meses', '46 days = 2 months'); | |
12561 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 meses', '75 days = 2 months'); | |
12562 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 meses', '76 days = 3 months'); | |
12563 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'un mes', '1 month = a month'); | |
12564 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 meses', '5 months = 5 months'); | |
12565 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un ano', '345 days = a year'); | |
12566 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 anos', '548 days = 2 years'); | |
12567 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un ano', '1 year = a year'); | |
12568 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 anos', '5 years = 5 years'); | |
12569 }); | |
12570 | |
12571 test('suffix', function (assert) { | |
12572 assert.equal(moment(30000).from(0), 'nuns segundos', 'prefix'); | |
12573 assert.equal(moment(0).from(30000), 'hai uns segundos', 'suffix'); | |
12574 }); | |
12575 | |
12576 test('now from now', function (assert) { | |
12577 assert.equal(moment().fromNow(), 'hai uns segundos', 'now from now should display as in the past'); | |
12578 }); | |
12579 | |
12580 test('fromNow', function (assert) { | |
12581 assert.equal(moment().add({s: 30}).fromNow(), 'nuns segundos', 'en unos segundos'); | |
12582 assert.equal(moment().add({d: 5}).fromNow(), 'en 5 días', 'en 5 días'); | |
12583 }); | |
12584 | |
12585 test('calendar day', function (assert) { | |
12586 var a = moment().hours(2).minutes(0).seconds(0); | |
12587 | |
12588 assert.equal(moment(a).calendar(), 'hoxe ás 2:00', 'today at the same time'); | |
12589 assert.equal(moment(a).add({m: 25}).calendar(), 'hoxe ás 2:25', 'Now plus 25 min'); | |
12590 assert.equal(moment(a).add({h: 1}).calendar(), 'hoxe ás 3:00', 'Now plus 1 hour'); | |
12591 assert.equal(moment(a).add({d: 1}).calendar(), 'mañá ás 2:00', 'tomorrow at the same time'); | |
12592 assert.equal(moment(a).add({d: 1, h : -1}).calendar(), 'mañá á 1:00', 'tomorrow minus 1 hour'); | |
12593 assert.equal(moment(a).subtract({h: 1}).calendar(), 'hoxe á 1:00', 'Now minus 1 hour'); | |
12594 assert.equal(moment(a).subtract({d: 1}).calendar(), 'onte á 2:00', 'yesterday at the same time'); | |
12595 }); | |
12596 | |
12597 test('calendar next week', function (assert) { | |
12598 var i, m; | |
12599 | |
12600 for (i = 2; i < 7; i++) { | |
12601 m = moment().add({d: i}); | |
12602 assert.equal(m.calendar(), m.format('dddd [' + ((m.hours() !== 1) ? 'ás' : 'a') + '] LT'), 'Today + ' + i + ' days current time'); | |
12603 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
12604 assert.equal(m.calendar(), m.format('dddd [' + ((m.hours() !== 1) ? 'ás' : 'a') + '] LT'), 'Today + ' + i + ' days beginning of day'); | |
12605 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
12606 assert.equal(m.calendar(), m.format('dddd [' + ((m.hours() !== 1) ? 'ás' : 'a') + '] LT'), 'Today + ' + i + ' days end of day'); | |
12607 } | |
12608 }); | |
12609 | |
12610 test('calendar last week', function (assert) { | |
12611 var i, m; | |
12612 for (i = 2; i < 7; i++) { | |
12613 m = moment().subtract({d: i}); | |
12614 assert.equal(m.calendar(), m.format('[o] dddd [pasado ' + ((m.hours() !== 1) ? 'ás' : 'a') + '] LT'), 'Today - ' + i + ' days current time'); | |
12615 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
12616 assert.equal(m.calendar(), m.format('[o] dddd [pasado ' + ((m.hours() !== 1) ? 'ás' : 'a') + '] LT'), 'Today - ' + i + ' days beginning of day'); | |
12617 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
12618 assert.equal(m.calendar(), m.format('[o] dddd [pasado ' + ((m.hours() !== 1) ? 'ás' : 'a') + '] LT'), 'Today - ' + i + ' days end of day'); | |
12619 } | |
12620 }); | |
12621 | |
12622 test('calendar all else', function (assert) { | |
12623 var weeksAgo = moment().subtract({w: 1}), | |
12624 weeksFromNow = moment().add({w: 1}); | |
12625 | |
12626 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
12627 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
12628 | |
12629 weeksAgo = moment().subtract({w: 2}); | |
12630 weeksFromNow = moment().add({w: 2}); | |
12631 | |
12632 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
12633 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
12634 }); | |
12635 | |
12636 test('regression tests', function (assert) { | |
12637 var lastWeek = moment().subtract({d: 4}).hours(1); | |
12638 assert.equal(lastWeek.calendar(), lastWeek.format('[o] dddd [pasado a] LT'), '1 o\'clock bug'); | |
12639 }); | |
12640 | |
12641 test('weeks year starting sunday', function (assert) { | |
12642 assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1'); | |
12643 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
12644 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2'); | |
12645 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
12646 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3'); | |
12647 }); | |
12648 | |
12649 test('weeks year starting monday', function (assert) { | |
12650 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
12651 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
12652 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
12653 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
12654 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
12655 }); | |
12656 | |
12657 test('weeks year starting tuesday', function (assert) { | |
12658 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
12659 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
12660 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
12661 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
12662 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
12663 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
12664 }); | |
12665 | |
12666 test('weeks year starting wednesday', function (assert) { | |
12667 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
12668 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
12669 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
12670 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
12671 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
12672 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
12673 }); | |
12674 | |
12675 test('weeks year starting thursday', function (assert) { | |
12676 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
12677 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
12678 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
12679 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
12680 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
12681 assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3'); | |
12682 }); | |
12683 | |
12684 test('weeks year starting friday', function (assert) { | |
12685 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1'); | |
12686 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
12687 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1'); | |
12688 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2'); | |
12689 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2'); | |
12690 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3'); | |
12691 }); | |
12692 | |
12693 test('weeks year starting saturday', function (assert) { | |
12694 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1'); | |
12695 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
12696 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1'); | |
12697 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2'); | |
12698 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2'); | |
12699 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3'); | |
12700 }); | |
12701 | |
12702 test('weeks year starting sunday formatted', function (assert) { | |
12703 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1º', 'Dec 26 2011 should be week 1'); | |
12704 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1º', 'Jan 1 2012 should be week 1'); | |
12705 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2º', 'Jan 2 2012 should be week 2'); | |
12706 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2º', 'Jan 8 2012 should be week 2'); | |
12707 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3º', 'Jan 9 2012 should be week 3'); | |
12708 }); | |
12709 | |
12710 test('lenient ordinal parsing', function (assert) { | |
12711 var i, ordinalStr, testMoment; | |
12712 for (i = 1; i <= 31; ++i) { | |
12713 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
12714 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
12715 assert.equal(testMoment.year(), 2014, | |
12716 'lenient ordinal parsing ' + i + ' year check'); | |
12717 assert.equal(testMoment.month(), 0, | |
12718 'lenient ordinal parsing ' + i + ' month check'); | |
12719 assert.equal(testMoment.date(), i, | |
12720 'lenient ordinal parsing ' + i + ' date check'); | |
12721 } | |
12722 }); | |
12723 | |
12724 test('lenient ordinal parsing of number', function (assert) { | |
12725 var i, testMoment; | |
12726 for (i = 1; i <= 31; ++i) { | |
12727 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
12728 assert.equal(testMoment.year(), 2014, | |
12729 'lenient ordinal parsing of number ' + i + ' year check'); | |
12730 assert.equal(testMoment.month(), 0, | |
12731 'lenient ordinal parsing of number ' + i + ' month check'); | |
12732 assert.equal(testMoment.date(), i, | |
12733 'lenient ordinal parsing of number ' + i + ' date check'); | |
12734 } | |
12735 }); | |
12736 | |
12737 test('strict ordinal parsing', function (assert) { | |
12738 var i, ordinalStr, testMoment; | |
12739 for (i = 1; i <= 31; ++i) { | |
12740 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
12741 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
12742 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
12743 } | |
12744 }); | |
12745 | |
12746 })); | |
12747 | |
12748 (function (global, factory) { | |
12749 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
12750 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
12751 factory(global.moment) | |
12752 }(this, function (moment) { 'use strict'; | |
12753 | |
12754 /*global QUnit:false*/ | |
12755 | |
12756 var test = QUnit.test; | |
12757 | |
12758 function module (name, lifecycle) { | |
12759 QUnit.module(name, { | |
12760 setup : function () { | |
12761 moment.locale('en'); | |
12762 moment.createFromInputFallback = function () { | |
12763 throw new Error('input not handled by moment'); | |
12764 }; | |
12765 if (lifecycle && lifecycle.setup) { | |
12766 lifecycle.setup(); | |
12767 } | |
12768 }, | |
12769 teardown : function () { | |
12770 if (lifecycle && lifecycle.teardown) { | |
12771 lifecycle.teardown(); | |
12772 } | |
12773 } | |
12774 }); | |
12775 } | |
12776 | |
12777 function localeModule (name, lifecycle) { | |
12778 QUnit.module('locale:' + name, { | |
12779 setup : function () { | |
12780 moment.locale(name); | |
12781 moment.createFromInputFallback = function () { | |
12782 throw new Error('input not handled by moment'); | |
12783 }; | |
12784 if (lifecycle && lifecycle.setup) { | |
12785 lifecycle.setup(); | |
12786 } | |
12787 }, | |
12788 teardown : function () { | |
12789 moment.locale('en'); | |
12790 if (lifecycle && lifecycle.teardown) { | |
12791 lifecycle.teardown(); | |
12792 } | |
12793 } | |
12794 }); | |
12795 } | |
12796 | |
12797 localeModule('he'); | |
12798 | |
12799 test('parse', function (assert) { | |
12800 var tests = 'ינואר ינו׳_פברואר פבר׳_מרץ מרץ_אפריל אפר׳_מאי מאי_יוני יוני_יולי יולי_אוגוסט אוג׳_ספטמבר ספט׳_אוקטובר אוק׳_נובמבר נוב׳_דצמבר דצמ׳'.split('_'), i; | |
12801 function equalTest(input, mmm, i) { | |
12802 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
12803 } | |
12804 for (i = 0; i < 12; i++) { | |
12805 tests[i] = tests[i].split(' '); | |
12806 equalTest(tests[i][0], 'MMM', i); | |
12807 equalTest(tests[i][1], 'MMM', i); | |
12808 equalTest(tests[i][0], 'MMMM', i); | |
12809 equalTest(tests[i][1], 'MMMM', i); | |
12810 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
12811 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
12812 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
12813 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
12814 } | |
12815 }); | |
12816 | |
12817 test('format', function (assert) { | |
12818 var a = [ | |
12819 ['dddd, MMMM Do YYYY, h:mm:ss a', 'ראשון, פברואר 14 2010, 3:25:50 pm'], | |
12820 ['ddd, hA', 'א׳, 3PM'], | |
12821 ['M Mo MM MMMM MMM', '2 2 02 פברואר פבר׳'], | |
12822 ['YYYY YY', '2010 10'], | |
12823 ['D Do DD', '14 14 14'], | |
12824 ['d do dddd ddd dd', '0 0 ראשון א׳ א'], | |
12825 ['DDD DDDo DDDD', '45 45 045'], | |
12826 ['w wo ww', '8 8 08'], | |
12827 ['h hh', '3 03'], | |
12828 ['H HH', '15 15'], | |
12829 ['m mm', '25 25'], | |
12830 ['s ss', '50 50'], | |
12831 ['a A', 'pm PM'], | |
12832 ['[the] DDDo [day of the year]', 'the 45 day of the year'], | |
12833 ['LTS', '15:25:50'], | |
12834 ['L', '14/02/2010'], | |
12835 ['LL', '14 בפברואר 2010'], | |
12836 ['LLL', '14 בפברואר 2010 15:25'], | |
12837 ['LLLL', 'ראשון, 14 בפברואר 2010 15:25'], | |
12838 ['l', '14/2/2010'], | |
12839 ['ll', '14 פבר׳ 2010'], | |
12840 ['lll', '14 פבר׳ 2010 15:25'], | |
12841 ['llll', 'א׳, 14 פבר׳ 2010 15:25'] | |
12842 ], | |
12843 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
12844 i; | |
12845 for (i = 0; i < a.length; i++) { | |
12846 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
12847 } | |
12848 }); | |
12849 | |
12850 test('format month', function (assert) { | |
12851 var expected = 'ינואר ינו׳_פברואר פבר׳_מרץ מרץ_אפריל אפר׳_מאי מאי_יוני יוני_יולי יולי_אוגוסט אוג׳_ספטמבר ספט׳_אוקטובר אוק׳_נובמבר נוב׳_דצמבר דצמ׳'.split('_'), i; | |
12852 for (i = 0; i < expected.length; i++) { | |
12853 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
12854 } | |
12855 }); | |
12856 | |
12857 test('format week', function (assert) { | |
12858 var expected = 'ראשון א׳ א|שני ב׳ ב|שלישי ג׳ ג|רביעי ד׳ ד|חמישי ה׳ ה|שישי ו׳ ו|שבת ש׳ ש'.split('|'), i; | |
12859 for (i = 0; i < expected.length; i++) { | |
12860 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
12861 } | |
12862 }); | |
12863 | |
12864 test('from', function (assert) { | |
12865 var start = moment([2007, 1, 28]); | |
12866 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'מספר שניות', '44 seconds = a few seconds'); | |
12867 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'דקה', '45 seconds = a minute'); | |
12868 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'דקה', '89 seconds = a minute'); | |
12869 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 דקות', '90 seconds = 2 minutes'); | |
12870 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 דקות', '44 minutes = 44 minutes'); | |
12871 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'שעה', '45 minutes = an hour'); | |
12872 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'שעה', '89 minutes = an hour'); | |
12873 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), 'שעתיים', '90 minutes = 2 hours'); | |
12874 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 שעות', '5 hours = 5 hours'); | |
12875 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 שעות', '21 hours = 21 hours'); | |
12876 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'יום', '22 hours = a day'); | |
12877 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'יום', '35 hours = a day'); | |
12878 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), 'יומיים', '36 hours = 2 days'); | |
12879 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'יום', '1 day = a day'); | |
12880 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ימים', '5 days = 5 days'); | |
12881 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ימים', '25 days = 25 days'); | |
12882 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'חודש', '26 days = a month'); | |
12883 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'חודש', '30 days = a month'); | |
12884 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'חודש', '43 days = a month'); | |
12885 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), 'חודשיים', '46 days = 2 months'); | |
12886 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), 'חודשיים', '75 days = 2 months'); | |
12887 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 חודשים', '76 days = 3 months'); | |
12888 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'חודש', '1 month = a month'); | |
12889 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 חודשים', '5 months = 5 months'); | |
12890 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'שנה', '345 days = a year'); | |
12891 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), 'שנתיים', '548 days = 2 years'); | |
12892 assert.equal(start.from(moment([2007, 1, 28]).add({d: 3699}), true), '10 שנים', '345 days = 10 years'); | |
12893 assert.equal(start.from(moment([2007, 1, 28]).add({d: 7340}), true), '20 שנה', '548 days = 20 years'); | |
12894 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'שנה', '1 year = a year'); | |
12895 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 שנים', '5 years = 5 years'); | |
12896 }); | |
12897 | |
12898 test('suffix', function (assert) { | |
12899 assert.equal(moment(30000).from(0), 'בעוד מספר שניות', 'prefix'); | |
12900 assert.equal(moment(0).from(30000), 'לפני מספר שניות', 'suffix'); | |
12901 }); | |
12902 | |
12903 test('now from now', function (assert) { | |
12904 assert.equal(moment().fromNow(), 'לפני מספר שניות', 'now from now should display as in the past'); | |
12905 }); | |
12906 | |
12907 test('fromNow', function (assert) { | |
12908 assert.equal(moment().add({s: 30}).fromNow(), 'בעוד מספר שניות', 'in a few seconds'); | |
12909 assert.equal(moment().add({d: 5}).fromNow(), 'בעוד 5 ימים', 'in 5 days'); | |
12910 }); | |
12911 | |
12912 test('calendar day', function (assert) { | |
12913 var a = moment().hours(2).minutes(0).seconds(0); | |
12914 | |
12915 assert.equal(moment(a).calendar(), 'היום ב־02:00', 'today at the same time'); | |
12916 assert.equal(moment(a).add({m: 25}).calendar(), 'היום ב־02:25', 'Now plus 25 min'); | |
12917 assert.equal(moment(a).add({h: 1}).calendar(), 'היום ב־03:00', 'Now plus 1 hour'); | |
12918 assert.equal(moment(a).add({d: 1}).calendar(), 'מחר ב־02:00', 'tomorrow at the same time'); | |
12919 assert.equal(moment(a).subtract({h: 1}).calendar(), 'היום ב־01:00', 'Now minus 1 hour'); | |
12920 assert.equal(moment(a).subtract({d: 1}).calendar(), 'אתמול ב־02:00', 'yesterday at the same time'); | |
12921 }); | |
12922 | |
12923 test('calendar next week', function (assert) { | |
12924 var i, m; | |
12925 for (i = 2; i < 7; i++) { | |
12926 m = moment().add({d: i}); | |
12927 assert.equal(m.calendar(), m.format('dddd [בשעה] LT'), 'Today + ' + i + ' days current time'); | |
12928 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
12929 assert.equal(m.calendar(), m.format('dddd [בשעה] LT'), 'Today + ' + i + ' days beginning of day'); | |
12930 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
12931 assert.equal(m.calendar(), m.format('dddd [בשעה] LT'), 'Today + ' + i + ' days end of day'); | |
12932 } | |
12933 }); | |
12934 | |
12935 test('calendar last week', function (assert) { | |
12936 var i, m; | |
12937 for (i = 2; i < 7; i++) { | |
12938 m = moment().subtract({d: i}); | |
12939 assert.equal(m.calendar(), m.format('[ביום] dddd [האחרון בשעה] LT'), 'Today - ' + i + ' days current time'); | |
12940 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
12941 assert.equal(m.calendar(), m.format('[ביום] dddd [האחרון בשעה] LT'), 'Today - ' + i + ' days beginning of day'); | |
12942 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
12943 assert.equal(m.calendar(), m.format('[ביום] dddd [האחרון בשעה] LT'), 'Today - ' + i + ' days end of day'); | |
12944 } | |
12945 }); | |
12946 | |
12947 test('calendar all else', function (assert) { | |
12948 var weeksAgo = moment().subtract({w: 1}), | |
12949 weeksFromNow = moment().add({w: 1}); | |
12950 | |
12951 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
12952 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
12953 | |
12954 weeksAgo = moment().subtract({w: 2}); | |
12955 weeksFromNow = moment().add({w: 2}); | |
12956 | |
12957 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
12958 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
12959 }); | |
12960 | |
12961 test('weeks year starting sunday', function (assert) { | |
12962 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
12963 assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1'); | |
12964 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
12965 assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2'); | |
12966 assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3'); | |
12967 }); | |
12968 | |
12969 test('weeks year starting monday', function (assert) { | |
12970 assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1'); | |
12971 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
12972 assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1'); | |
12973 assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2'); | |
12974 assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2'); | |
12975 assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3'); | |
12976 }); | |
12977 | |
12978 test('weeks year starting tuesday', function (assert) { | |
12979 assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52'); | |
12980 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
12981 assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1'); | |
12982 assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2'); | |
12983 assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2'); | |
12984 assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3'); | |
12985 }); | |
12986 | |
12987 test('weeks year starting wednesday', function (assert) { | |
12988 assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1'); | |
12989 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
12990 assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1'); | |
12991 assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2'); | |
12992 assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2'); | |
12993 assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3'); | |
12994 }); | |
12995 | |
12996 test('weeks year starting thursday', function (assert) { | |
12997 assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1'); | |
12998 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
12999 assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1'); | |
13000 assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2'); | |
13001 assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2'); | |
13002 assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3'); | |
13003 }); | |
13004 | |
13005 test('weeks year starting friday', function (assert) { | |
13006 assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1'); | |
13007 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
13008 assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1'); | |
13009 assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2'); | |
13010 assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2'); | |
13011 assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3'); | |
13012 }); | |
13013 | |
13014 test('weeks year starting saturday', function (assert) { | |
13015 assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1'); | |
13016 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
13017 assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2'); | |
13018 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2'); | |
13019 assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3'); | |
13020 }); | |
13021 | |
13022 test('weeks year starting sunday format', function (assert) { | |
13023 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1'); | |
13024 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1', 'Jan 7 2012 should be week 1'); | |
13025 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2'); | |
13026 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2', 'Jan 14 2012 should be week 2'); | |
13027 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', 'Jan 15 2012 should be week 3'); | |
13028 }); | |
13029 | |
13030 test('lenient ordinal parsing', function (assert) { | |
13031 var i, ordinalStr, testMoment; | |
13032 for (i = 1; i <= 31; ++i) { | |
13033 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
13034 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
13035 assert.equal(testMoment.year(), 2014, | |
13036 'lenient ordinal parsing ' + i + ' year check'); | |
13037 assert.equal(testMoment.month(), 0, | |
13038 'lenient ordinal parsing ' + i + ' month check'); | |
13039 assert.equal(testMoment.date(), i, | |
13040 'lenient ordinal parsing ' + i + ' date check'); | |
13041 } | |
13042 }); | |
13043 | |
13044 test('lenient ordinal parsing of number', function (assert) { | |
13045 var i, testMoment; | |
13046 for (i = 1; i <= 31; ++i) { | |
13047 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
13048 assert.equal(testMoment.year(), 2014, | |
13049 'lenient ordinal parsing of number ' + i + ' year check'); | |
13050 assert.equal(testMoment.month(), 0, | |
13051 'lenient ordinal parsing of number ' + i + ' month check'); | |
13052 assert.equal(testMoment.date(), i, | |
13053 'lenient ordinal parsing of number ' + i + ' date check'); | |
13054 } | |
13055 }); | |
13056 | |
13057 test('strict ordinal parsing', function (assert) { | |
13058 var i, ordinalStr, testMoment; | |
13059 for (i = 1; i <= 31; ++i) { | |
13060 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
13061 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
13062 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
13063 } | |
13064 }); | |
13065 | |
13066 })); | |
13067 | |
13068 (function (global, factory) { | |
13069 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
13070 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
13071 factory(global.moment) | |
13072 }(this, function (moment) { 'use strict'; | |
13073 | |
13074 /*global QUnit:false*/ | |
13075 | |
13076 var test = QUnit.test; | |
13077 | |
13078 function module (name, lifecycle) { | |
13079 QUnit.module(name, { | |
13080 setup : function () { | |
13081 moment.locale('en'); | |
13082 moment.createFromInputFallback = function () { | |
13083 throw new Error('input not handled by moment'); | |
13084 }; | |
13085 if (lifecycle && lifecycle.setup) { | |
13086 lifecycle.setup(); | |
13087 } | |
13088 }, | |
13089 teardown : function () { | |
13090 if (lifecycle && lifecycle.teardown) { | |
13091 lifecycle.teardown(); | |
13092 } | |
13093 } | |
13094 }); | |
13095 } | |
13096 | |
13097 function localeModule (name, lifecycle) { | |
13098 QUnit.module('locale:' + name, { | |
13099 setup : function () { | |
13100 moment.locale(name); | |
13101 moment.createFromInputFallback = function () { | |
13102 throw new Error('input not handled by moment'); | |
13103 }; | |
13104 if (lifecycle && lifecycle.setup) { | |
13105 lifecycle.setup(); | |
13106 } | |
13107 }, | |
13108 teardown : function () { | |
13109 moment.locale('en'); | |
13110 if (lifecycle && lifecycle.teardown) { | |
13111 lifecycle.teardown(); | |
13112 } | |
13113 } | |
13114 }); | |
13115 } | |
13116 | |
13117 localeModule('hi'); | |
13118 | |
13119 test('parse', function (assert) { | |
13120 var tests = 'जनवरी जन._फ़रवरी फ़र._मार्च मार्च_अप्रैल अप्रै._मई मई_जून जून_जुलाई जुल._अगस्त अग._सितम्बर सित._अक्टूबर अक्टू._नवम्बर नव._दिसम्बर दिस.'.split('_'), i; | |
13121 function equalTest(input, mmm, i) { | |
13122 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
13123 } | |
13124 for (i = 0; i < 12; i++) { | |
13125 tests[i] = tests[i].split(' '); | |
13126 equalTest(tests[i][0], 'MMM', i); | |
13127 equalTest(tests[i][1], 'MMM', i); | |
13128 equalTest(tests[i][0], 'MMMM', i); | |
13129 equalTest(tests[i][1], 'MMMM', i); | |
13130 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
13131 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
13132 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
13133 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
13134 } | |
13135 }); | |
13136 | |
13137 test('format', function (assert) { | |
13138 var a = [ | |
13139 ['dddd, Do MMMM YYYY, a h:mm:ss बजे', 'रविवार, १४ फ़रवरी २०१०, दोपहर ३:२५:५० बजे'], | |
13140 ['ddd, a h बजे', 'रवि, दोपहर ३ बजे'], | |
13141 ['M Mo MM MMMM MMM', '२ २ ०२ फ़रवरी फ़र.'], | |
13142 ['YYYY YY', '२०१० १०'], | |
13143 ['D Do DD', '१४ १४ १४'], | |
13144 ['d do dddd ddd dd', '० ० रविवार रवि र'], | |
13145 ['DDD DDDo DDDD', '४५ ४५ ०४५'], | |
13146 ['w wo ww', '८ ८ ०८'], | |
13147 ['h hh', '३ ०३'], | |
13148 ['H HH', '१५ १५'], | |
13149 ['m mm', '२५ २५'], | |
13150 ['s ss', '५० ५०'], | |
13151 ['a A', 'दोपहर दोपहर'], | |
13152 ['LTS', 'दोपहर ३:२५:५० बजे'], | |
13153 ['L', '१४/०२/२०१०'], | |
13154 ['LL', '१४ फ़रवरी २०१०'], | |
13155 ['LLL', '१४ फ़रवरी २०१०, दोपहर ३:२५ बजे'], | |
13156 ['LLLL', 'रविवार, १४ फ़रवरी २०१०, दोपहर ३:२५ बजे'], | |
13157 ['l', '१४/२/२०१०'], | |
13158 ['ll', '१४ फ़र. २०१०'], | |
13159 ['lll', '१४ फ़र. २०१०, दोपहर ३:२५ बजे'], | |
13160 ['llll', 'रवि, १४ फ़र. २०१०, दोपहर ३:२५ बजे'] | |
13161 ], | |
13162 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
13163 i; | |
13164 for (i = 0; i < a.length; i++) { | |
13165 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
13166 } | |
13167 }); | |
13168 | |
13169 test('format ordinal', function (assert) { | |
13170 assert.equal(moment([2011, 0, 1]).format('DDDo'), '१', '१'); | |
13171 assert.equal(moment([2011, 0, 2]).format('DDDo'), '२', '२'); | |
13172 assert.equal(moment([2011, 0, 3]).format('DDDo'), '३', '३'); | |
13173 assert.equal(moment([2011, 0, 4]).format('DDDo'), '४', '४'); | |
13174 assert.equal(moment([2011, 0, 5]).format('DDDo'), '५', '५'); | |
13175 assert.equal(moment([2011, 0, 6]).format('DDDo'), '६', '६'); | |
13176 assert.equal(moment([2011, 0, 7]).format('DDDo'), '७', '७'); | |
13177 assert.equal(moment([2011, 0, 8]).format('DDDo'), '८', '८'); | |
13178 assert.equal(moment([2011, 0, 9]).format('DDDo'), '९', '९'); | |
13179 assert.equal(moment([2011, 0, 10]).format('DDDo'), '१०', '१०'); | |
13180 | |
13181 assert.equal(moment([2011, 0, 11]).format('DDDo'), '११', '११'); | |
13182 assert.equal(moment([2011, 0, 12]).format('DDDo'), '१२', '१२'); | |
13183 assert.equal(moment([2011, 0, 13]).format('DDDo'), '१३', '१३'); | |
13184 assert.equal(moment([2011, 0, 14]).format('DDDo'), '१४', '१४'); | |
13185 assert.equal(moment([2011, 0, 15]).format('DDDo'), '१५', '१५'); | |
13186 assert.equal(moment([2011, 0, 16]).format('DDDo'), '१६', '१६'); | |
13187 assert.equal(moment([2011, 0, 17]).format('DDDo'), '१७', '१७'); | |
13188 assert.equal(moment([2011, 0, 18]).format('DDDo'), '१८', '१८'); | |
13189 assert.equal(moment([2011, 0, 19]).format('DDDo'), '१९', '१९'); | |
13190 assert.equal(moment([2011, 0, 20]).format('DDDo'), '२०', '२०'); | |
13191 | |
13192 assert.equal(moment([2011, 0, 21]).format('DDDo'), '२१', '२१'); | |
13193 assert.equal(moment([2011, 0, 22]).format('DDDo'), '२२', '२२'); | |
13194 assert.equal(moment([2011, 0, 23]).format('DDDo'), '२३', '२३'); | |
13195 assert.equal(moment([2011, 0, 24]).format('DDDo'), '२४', '२४'); | |
13196 assert.equal(moment([2011, 0, 25]).format('DDDo'), '२५', '२५'); | |
13197 assert.equal(moment([2011, 0, 26]).format('DDDo'), '२६', '२६'); | |
13198 assert.equal(moment([2011, 0, 27]).format('DDDo'), '२७', '२७'); | |
13199 assert.equal(moment([2011, 0, 28]).format('DDDo'), '२८', '२८'); | |
13200 assert.equal(moment([2011, 0, 29]).format('DDDo'), '२९', '२९'); | |
13201 assert.equal(moment([2011, 0, 30]).format('DDDo'), '३०', '३०'); | |
13202 | |
13203 assert.equal(moment([2011, 0, 31]).format('DDDo'), '३१', '३१'); | |
13204 }); | |
13205 | |
13206 test('format month', function (assert) { | |
13207 var expected = 'जनवरी जन._फ़रवरी फ़र._मार्च मार्च_अप्रैल अप्रै._मई मई_जून जून_जुलाई जुल._अगस्त अग._सितम्बर सित._अक्टूबर अक्टू._नवम्बर नव._दिसम्बर दिस.'.split('_'), i; | |
13208 for (i = 0; i < expected.length; i++) { | |
13209 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
13210 } | |
13211 }); | |
13212 | |
13213 test('format week', function (assert) { | |
13214 var expected = 'रविवार रवि र_सोमवार सोम सो_मंगलवार मंगल मं_बुधवार बुध बु_गुरूवार गुरू गु_शुक्रवार शुक्र शु_शनिवार शनि श'.split('_'), i; | |
13215 for (i = 0; i < expected.length; i++) { | |
13216 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
13217 } | |
13218 }); | |
13219 | |
13220 test('from', function (assert) { | |
13221 var start = moment([2007, 1, 28]); | |
13222 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'कुछ ही क्षण', '44 seconds = a few seconds'); | |
13223 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'एक मिनट', '45 seconds = a minute'); | |
13224 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'एक मिनट', '89 seconds = a minute'); | |
13225 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '२ मिनट', '90 seconds = 2 minutes'); | |
13226 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '४४ मिनट', '44 minutes = 44 minutes'); | |
13227 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'एक घंटा', '45 minutes = an hour'); | |
13228 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'एक घंटा', '89 minutes = an hour'); | |
13229 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '२ घंटे', '90 minutes = 2 hours'); | |
13230 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '५ घंटे', '5 hours = 5 hours'); | |
13231 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '२१ घंटे', '21 hours = 21 hours'); | |
13232 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'एक दिन', '22 hours = a day'); | |
13233 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'एक दिन', '35 hours = a day'); | |
13234 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '२ दिन', '36 hours = 2 days'); | |
13235 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'एक दिन', '1 day = a day'); | |
13236 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '५ दिन', '5 days = 5 days'); | |
13237 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '२५ दिन', '25 days = 25 days'); | |
13238 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'एक महीने', '26 days = a month'); | |
13239 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'एक महीने', '30 days = a month'); | |
13240 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'एक महीने', '43 days = a month'); | |
13241 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '२ महीने', '46 days = 2 months'); | |
13242 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '२ महीने', '75 days = 2 months'); | |
13243 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '३ महीने', '76 days = 3 months'); | |
13244 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'एक महीने', '1 month = a month'); | |
13245 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '५ महीने', '5 months = 5 months'); | |
13246 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'एक वर्ष', '345 days = a year'); | |
13247 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '२ वर्ष', '548 days = 2 years'); | |
13248 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'एक वर्ष', '1 year = a year'); | |
13249 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '५ वर्ष', '5 years = 5 years'); | |
13250 }); | |
13251 | |
13252 test('suffix', function (assert) { | |
13253 assert.equal(moment(30000).from(0), 'कुछ ही क्षण में', 'prefix'); | |
13254 assert.equal(moment(0).from(30000), 'कुछ ही क्षण पहले', 'suffix'); | |
13255 }); | |
13256 | |
13257 test('now from now', function (assert) { | |
13258 assert.equal(moment().fromNow(), 'कुछ ही क्षण पहले', 'now from now should display as in the past'); | |
13259 }); | |
13260 | |
13261 test('fromNow', function (assert) { | |
13262 assert.equal(moment().add({s: 30}).fromNow(), 'कुछ ही क्षण में', 'कुछ ही क्षण में'); | |
13263 assert.equal(moment().add({d: 5}).fromNow(), '५ दिन में', '५ दिन में'); | |
13264 }); | |
13265 | |
13266 test('calendar day', function (assert) { | |
13267 var a = moment().hours(2).minutes(0).seconds(0); | |
13268 | |
13269 assert.equal(moment(a).calendar(), 'आज रात २:०० बजे', 'today at the same time'); | |
13270 assert.equal(moment(a).add({m: 25}).calendar(), 'आज रात २:२५ बजे', 'Now plus 25 min'); | |
13271 assert.equal(moment(a).add({h: 3}).calendar(), 'आज सुबह ५:०० बजे', 'Now plus 3 hour'); | |
13272 assert.equal(moment(a).add({d: 1}).calendar(), 'कल रात २:०० बजे', 'tomorrow at the same time'); | |
13273 assert.equal(moment(a).subtract({h: 1}).calendar(), 'आज रात १:०० बजे', 'Now minus 1 hour'); | |
13274 assert.equal(moment(a).subtract({d: 1}).calendar(), 'कल रात २:०० बजे', 'yesterday at the same time'); | |
13275 }); | |
13276 | |
13277 test('calendar next week', function (assert) { | |
13278 var i, m; | |
13279 for (i = 2; i < 7; i++) { | |
13280 m = moment().add({d: i}); | |
13281 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days current time'); | |
13282 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
13283 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days beginning of day'); | |
13284 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
13285 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days end of day'); | |
13286 } | |
13287 }); | |
13288 | |
13289 test('calendar last week', function (assert) { | |
13290 var i, m; | |
13291 | |
13292 for (i = 2; i < 7; i++) { | |
13293 m = moment().subtract({d: i}); | |
13294 assert.equal(m.calendar(), m.format('[पिछले] dddd[,] LT'), 'Today - ' + i + ' days current time'); | |
13295 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
13296 assert.equal(m.calendar(), m.format('[पिछले] dddd[,] LT'), 'Today - ' + i + ' days beginning of day'); | |
13297 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
13298 assert.equal(m.calendar(), m.format('[पिछले] dddd[,] LT'), 'Today - ' + i + ' days end of day'); | |
13299 } | |
13300 }); | |
13301 | |
13302 test('calendar all else', function (assert) { | |
13303 var weeksAgo = moment().subtract({w: 1}), | |
13304 weeksFromNow = moment().add({w: 1}); | |
13305 | |
13306 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
13307 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
13308 | |
13309 weeksAgo = moment().subtract({w: 2}); | |
13310 weeksFromNow = moment().add({w: 2}); | |
13311 | |
13312 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
13313 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
13314 }); | |
13315 | |
13316 test('meridiem invariant', function (assert) { | |
13317 assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), 'रात', 'before dawn'); | |
13318 assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), 'सुबह', 'morning'); | |
13319 assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), 'दोपहर', 'during day'); | |
13320 assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), 'शाम', 'evening'); | |
13321 assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), 'शाम', 'late evening'); | |
13322 assert.equal(moment([2011, 2, 23, 21, 20]).format('a'), 'रात', 'night'); | |
13323 | |
13324 assert.equal(moment([2011, 2, 23, 2, 30]).format('A'), 'रात', 'before dawn'); | |
13325 assert.equal(moment([2011, 2, 23, 9, 30]).format('A'), 'सुबह', 'morning'); | |
13326 assert.equal(moment([2011, 2, 23, 14, 30]).format('A'), 'दोपहर', ' during day'); | |
13327 assert.equal(moment([2011, 2, 23, 17, 30]).format('A'), 'शाम', 'evening'); | |
13328 assert.equal(moment([2011, 2, 23, 19, 30]).format('A'), 'शाम', 'late evening'); | |
13329 assert.equal(moment([2011, 2, 23, 21, 20]).format('A'), 'रात', 'night'); | |
13330 }); | |
13331 | |
13332 test('weeks year starting sunday', function (assert) { | |
13333 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
13334 assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1'); | |
13335 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
13336 assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2'); | |
13337 assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3'); | |
13338 }); | |
13339 | |
13340 test('weeks year starting monday', function (assert) { | |
13341 assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1'); | |
13342 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
13343 assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1'); | |
13344 assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2'); | |
13345 assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2'); | |
13346 assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3'); | |
13347 }); | |
13348 | |
13349 test('weeks year starting tuesday', function (assert) { | |
13350 assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52'); | |
13351 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
13352 assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1'); | |
13353 assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2'); | |
13354 assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2'); | |
13355 assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3'); | |
13356 }); | |
13357 | |
13358 test('weeks year starting wednesday', function (assert) { | |
13359 assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1'); | |
13360 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
13361 assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1'); | |
13362 assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2'); | |
13363 assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2'); | |
13364 assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3'); | |
13365 }); | |
13366 | |
13367 test('weeks year starting thursday', function (assert) { | |
13368 assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1'); | |
13369 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
13370 assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1'); | |
13371 assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2'); | |
13372 assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2'); | |
13373 assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3'); | |
13374 }); | |
13375 | |
13376 test('weeks year starting friday', function (assert) { | |
13377 assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1'); | |
13378 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
13379 assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1'); | |
13380 assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2'); | |
13381 assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2'); | |
13382 assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3'); | |
13383 }); | |
13384 | |
13385 test('weeks year starting saturday', function (assert) { | |
13386 assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1'); | |
13387 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
13388 assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2'); | |
13389 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2'); | |
13390 assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3'); | |
13391 }); | |
13392 | |
13393 test('weeks year starting sunday formatted', function (assert) { | |
13394 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '१ ०१ १', 'Jan 1 2012 should be week 1'); | |
13395 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '१ ०१ १', 'Jan 7 2012 should be week 1'); | |
13396 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '२ ०२ २', 'Jan 8 2012 should be week 2'); | |
13397 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '२ ०२ २', 'Jan 14 2012 should be week 2'); | |
13398 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '३ ०३ ३', 'Jan 15 2012 should be week 3'); | |
13399 }); | |
13400 | |
13401 test('lenient ordinal parsing', function (assert) { | |
13402 var i, ordinalStr, testMoment; | |
13403 for (i = 1; i <= 31; ++i) { | |
13404 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
13405 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
13406 assert.equal(testMoment.year(), 2014, | |
13407 'lenient ordinal parsing ' + i + ' year check'); | |
13408 assert.equal(testMoment.month(), 0, | |
13409 'lenient ordinal parsing ' + i + ' month check'); | |
13410 assert.equal(testMoment.date(), i, | |
13411 'lenient ordinal parsing ' + i + ' date check'); | |
13412 } | |
13413 }); | |
13414 | |
13415 test('lenient ordinal parsing of number', function (assert) { | |
13416 var i, testMoment; | |
13417 for (i = 1; i <= 31; ++i) { | |
13418 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
13419 assert.equal(testMoment.year(), 2014, | |
13420 'lenient ordinal parsing of number ' + i + ' year check'); | |
13421 assert.equal(testMoment.month(), 0, | |
13422 'lenient ordinal parsing of number ' + i + ' month check'); | |
13423 assert.equal(testMoment.date(), i, | |
13424 'lenient ordinal parsing of number ' + i + ' date check'); | |
13425 } | |
13426 }); | |
13427 | |
13428 test('meridiem', function (assert) { | |
13429 var h, m, t1, t2; | |
13430 for (h = 0; h < 24; ++h) { | |
13431 for (m = 0; m < 60; m += 15) { | |
13432 t1 = moment.utc([2000, 0, 1, h, m]); | |
13433 t2 = moment(t1.format('A h:mm'), 'A h:mm'); | |
13434 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'), | |
13435 'meridiem at ' + t1.format('HH:mm')); | |
13436 } | |
13437 } | |
13438 }); | |
13439 | |
13440 test('strict ordinal parsing', function (assert) { | |
13441 var i, ordinalStr, testMoment; | |
13442 for (i = 1; i <= 31; ++i) { | |
13443 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
13444 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
13445 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
13446 } | |
13447 }); | |
13448 | |
13449 })); | |
13450 | |
13451 (function (global, factory) { | |
13452 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
13453 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
13454 factory(global.moment) | |
13455 }(this, function (moment) { 'use strict'; | |
13456 | |
13457 /*global QUnit:false*/ | |
13458 | |
13459 var test = QUnit.test; | |
13460 | |
13461 function module (name, lifecycle) { | |
13462 QUnit.module(name, { | |
13463 setup : function () { | |
13464 moment.locale('en'); | |
13465 moment.createFromInputFallback = function () { | |
13466 throw new Error('input not handled by moment'); | |
13467 }; | |
13468 if (lifecycle && lifecycle.setup) { | |
13469 lifecycle.setup(); | |
13470 } | |
13471 }, | |
13472 teardown : function () { | |
13473 if (lifecycle && lifecycle.teardown) { | |
13474 lifecycle.teardown(); | |
13475 } | |
13476 } | |
13477 }); | |
13478 } | |
13479 | |
13480 function localeModule (name, lifecycle) { | |
13481 QUnit.module('locale:' + name, { | |
13482 setup : function () { | |
13483 moment.locale(name); | |
13484 moment.createFromInputFallback = function () { | |
13485 throw new Error('input not handled by moment'); | |
13486 }; | |
13487 if (lifecycle && lifecycle.setup) { | |
13488 lifecycle.setup(); | |
13489 } | |
13490 }, | |
13491 teardown : function () { | |
13492 moment.locale('en'); | |
13493 if (lifecycle && lifecycle.teardown) { | |
13494 lifecycle.teardown(); | |
13495 } | |
13496 } | |
13497 }); | |
13498 } | |
13499 | |
13500 localeModule('hr'); | |
13501 | |
13502 test('parse', function (assert) { | |
13503 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; | |
13504 function equalTest(input, mmm, i) { | |
13505 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
13506 } | |
13507 for (i = 0; i < 12; i++) { | |
13508 tests[i] = tests[i].split(' '); | |
13509 equalTest(tests[i][0], 'MMM', i); | |
13510 equalTest(tests[i][1], 'MMM', i); | |
13511 equalTest(tests[i][0], 'MMMM', i); | |
13512 equalTest(tests[i][1], 'MMMM', i); | |
13513 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
13514 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
13515 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
13516 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
13517 } | |
13518 }); | |
13519 | |
13520 test('format', function (assert) { | |
13521 var a = [ | |
13522 ['dddd, Do MMMM YYYY, h:mm:ss a', 'nedjelja, 14. veljača 2010, 3:25:50 pm'], | |
13523 ['ddd, hA', 'ned., 3PM'], | |
13524 ['M Mo MM MMMM MMM', '2 2. 02 veljača velj.'], | |
13525 ['YYYY YY', '2010 10'], | |
13526 ['D Do DD', '14 14. 14'], | |
13527 ['d do dddd ddd dd', '0 0. nedjelja ned. ne'], | |
13528 ['DDD DDDo DDDD', '45 45. 045'], | |
13529 ['w wo ww', '7 7. 07'], | |
13530 ['h hh', '3 03'], | |
13531 ['H HH', '15 15'], | |
13532 ['m mm', '25 25'], | |
13533 ['s ss', '50 50'], | |
13534 ['a A', 'pm PM'], | |
13535 ['[the] DDDo [day of the year]', 'the 45. day of the year'], | |
13536 ['LTS', '15:25:50'], | |
13537 ['L', '14. 02. 2010'], | |
13538 ['LL', '14. veljača 2010'], | |
13539 ['LLL', '14. veljača 2010 15:25'], | |
13540 ['LLLL', 'nedjelja, 14. veljača 2010 15:25'], | |
13541 ['l', '14. 2. 2010'], | |
13542 ['ll', '14. velj. 2010'], | |
13543 ['lll', '14. velj. 2010 15:25'], | |
13544 ['llll', 'ned., 14. velj. 2010 15:25'] | |
13545 ], | |
13546 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
13547 i; | |
13548 for (i = 0; i < a.length; i++) { | |
13549 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
13550 } | |
13551 }); | |
13552 | |
13553 test('format ordinal', function (assert) { | |
13554 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.'); | |
13555 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.'); | |
13556 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.'); | |
13557 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.'); | |
13558 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.'); | |
13559 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.'); | |
13560 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.'); | |
13561 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.'); | |
13562 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.'); | |
13563 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.'); | |
13564 | |
13565 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.'); | |
13566 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.'); | |
13567 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.'); | |
13568 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.'); | |
13569 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.'); | |
13570 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.'); | |
13571 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.'); | |
13572 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.'); | |
13573 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.'); | |
13574 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.'); | |
13575 | |
13576 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.'); | |
13577 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.'); | |
13578 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.'); | |
13579 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.'); | |
13580 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.'); | |
13581 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.'); | |
13582 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.'); | |
13583 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.'); | |
13584 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.'); | |
13585 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.'); | |
13586 | |
13587 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.'); | |
13588 }); | |
13589 | |
13590 test('format month', function (assert) { | |
13591 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; | |
13592 for (i = 0; i < expected.length; i++) { | |
13593 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
13594 } | |
13595 }); | |
13596 | |
13597 test('format week', function (assert) { | |
13598 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; | |
13599 for (i = 0; i < expected.length; i++) { | |
13600 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
13601 } | |
13602 }); | |
13603 | |
13604 test('from', function (assert) { | |
13605 var start = moment([2007, 1, 28]); | |
13606 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'par sekundi', '44 seconds = a few seconds'); | |
13607 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'jedna minuta', '45 seconds = a minute'); | |
13608 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'jedna minuta', '89 seconds = a minute'); | |
13609 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minute', '90 seconds = 2 minutes'); | |
13610 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuta', '44 minutes = 44 minutes'); | |
13611 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'jedan sat', '45 minutes = an hour'); | |
13612 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'jedan sat', '89 minutes = an hour'); | |
13613 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 sata', '90 minutes = 2 hours'); | |
13614 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 sati', '5 hours = 5 hours'); | |
13615 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 sati', '21 hours = 21 hours'); | |
13616 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'dan', '22 hours = a day'); | |
13617 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'dan', '35 hours = a day'); | |
13618 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dana', '36 hours = 2 days'); | |
13619 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'dan', '1 day = a day'); | |
13620 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dana', '5 days = 5 days'); | |
13621 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dana', '25 days = 25 days'); | |
13622 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mjesec', '26 days = a month'); | |
13623 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mjesec', '30 days = a month'); | |
13624 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mjesec', '43 days = a month'); | |
13625 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mjeseca', '46 days = 2 months'); | |
13626 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mjeseca', '75 days = 2 months'); | |
13627 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mjeseca', '76 days = 3 months'); | |
13628 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mjesec', '1 month = a month'); | |
13629 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mjeseci', '5 months = 5 months'); | |
13630 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'godinu', '345 days = a year'); | |
13631 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 godine', '548 days = 2 years'); | |
13632 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'godinu', '1 year = a year'); | |
13633 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 godina', '5 years = 5 years'); | |
13634 }); | |
13635 | |
13636 test('suffix', function (assert) { | |
13637 assert.equal(moment(30000).from(0), 'za par sekundi', 'prefix'); | |
13638 assert.equal(moment(0).from(30000), 'prije par sekundi', 'prefix'); | |
13639 }); | |
13640 | |
13641 test('now from now', function (assert) { | |
13642 assert.equal(moment().fromNow(), 'prije par sekundi', 'now from now should display as in the past'); | |
13643 }); | |
13644 | |
13645 test('fromNow', function (assert) { | |
13646 assert.equal(moment().add({s: 30}).fromNow(), 'za par sekundi', 'in a few seconds'); | |
13647 assert.equal(moment().add({d: 5}).fromNow(), 'za 5 dana', 'in 5 days'); | |
13648 }); | |
13649 | |
13650 test('calendar day', function (assert) { | |
13651 var a = moment().hours(2).minutes(0).seconds(0); | |
13652 | |
13653 assert.equal(moment(a).calendar(), 'danas u 2:00', 'today at the same time'); | |
13654 assert.equal(moment(a).add({m: 25}).calendar(), 'danas u 2:25', 'Now plus 25 min'); | |
13655 assert.equal(moment(a).add({h: 1}).calendar(), 'danas u 3:00', 'Now plus 1 hour'); | |
13656 assert.equal(moment(a).add({d: 1}).calendar(), 'sutra u 2:00', 'tomorrow at the same time'); | |
13657 assert.equal(moment(a).subtract({h: 1}).calendar(), 'danas u 1:00', 'Now minus 1 hour'); | |
13658 assert.equal(moment(a).subtract({d: 1}).calendar(), 'jučer u 2:00', 'yesterday at the same time'); | |
13659 }); | |
13660 | |
13661 test('calendar next week', function (assert) { | |
13662 var i, m; | |
13663 | |
13664 function makeFormat(d) { | |
13665 switch (d.day()) { | |
13666 case 0: | |
13667 return '[u] [nedjelju] [u] LT'; | |
13668 case 3: | |
13669 return '[u] [srijedu] [u] LT'; | |
13670 case 6: | |
13671 return '[u] [subotu] [u] LT'; | |
13672 case 1: | |
13673 case 2: | |
13674 case 4: | |
13675 case 5: | |
13676 return '[u] dddd [u] LT'; | |
13677 } | |
13678 } | |
13679 | |
13680 for (i = 2; i < 7; i++) { | |
13681 m = moment().add({d: i}); | |
13682 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time'); | |
13683 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
13684 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day'); | |
13685 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
13686 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day'); | |
13687 } | |
13688 }); | |
13689 | |
13690 test('calendar last week', function (assert) { | |
13691 var i, m; | |
13692 | |
13693 function makeFormat(d) { | |
13694 switch (d.day()) { | |
13695 case 0: | |
13696 case 3: | |
13697 return '[prošlu] dddd [u] LT'; | |
13698 case 6: | |
13699 return '[prošle] [subote] [u] LT'; | |
13700 case 1: | |
13701 case 2: | |
13702 case 4: | |
13703 case 5: | |
13704 return '[prošli] dddd [u] LT'; | |
13705 } | |
13706 } | |
13707 | |
13708 for (i = 2; i < 7; i++) { | |
13709 m = moment().subtract({d: i}); | |
13710 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time'); | |
13711 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
13712 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day'); | |
13713 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
13714 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day'); | |
13715 } | |
13716 }); | |
13717 | |
13718 test('calendar all else', function (assert) { | |
13719 var weeksAgo = moment().subtract({w: 1}), | |
13720 weeksFromNow = moment().add({w: 1}); | |
13721 | |
13722 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
13723 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
13724 | |
13725 weeksAgo = moment().subtract({w: 2}); | |
13726 weeksFromNow = moment().add({w: 2}); | |
13727 | |
13728 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
13729 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
13730 }); | |
13731 | |
13732 test('weeks year starting sunday', function (assert) { | |
13733 assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1'); | |
13734 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
13735 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2'); | |
13736 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
13737 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3'); | |
13738 }); | |
13739 | |
13740 test('weeks year starting monday', function (assert) { | |
13741 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
13742 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
13743 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
13744 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
13745 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
13746 }); | |
13747 | |
13748 test('weeks year starting tuesday', function (assert) { | |
13749 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
13750 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
13751 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
13752 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
13753 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
13754 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
13755 }); | |
13756 | |
13757 test('weeks year starting wednesday', function (assert) { | |
13758 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
13759 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
13760 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
13761 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
13762 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
13763 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
13764 }); | |
13765 | |
13766 test('weeks year starting thursday', function (assert) { | |
13767 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
13768 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
13769 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
13770 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
13771 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
13772 assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3'); | |
13773 }); | |
13774 | |
13775 test('weeks year starting friday', function (assert) { | |
13776 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1'); | |
13777 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
13778 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1'); | |
13779 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2'); | |
13780 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2'); | |
13781 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3'); | |
13782 }); | |
13783 | |
13784 test('weeks year starting saturday', function (assert) { | |
13785 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1'); | |
13786 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
13787 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1'); | |
13788 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2'); | |
13789 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2'); | |
13790 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3'); | |
13791 }); | |
13792 | |
13793 test('weeks year starting sunday formatted', function (assert) { | |
13794 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', 'Dec 26 2011 should be week 1'); | |
13795 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1.', 'Jan 1 2012 should be week 1'); | |
13796 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2.', 'Jan 2 2012 should be week 2'); | |
13797 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2.', 'Jan 8 2012 should be week 2'); | |
13798 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3.', 'Jan 9 2012 should be week 3'); | |
13799 }); | |
13800 | |
13801 test('lenient ordinal parsing', function (assert) { | |
13802 var i, ordinalStr, testMoment; | |
13803 for (i = 1; i <= 31; ++i) { | |
13804 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
13805 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
13806 assert.equal(testMoment.year(), 2014, | |
13807 'lenient ordinal parsing ' + i + ' year check'); | |
13808 assert.equal(testMoment.month(), 0, | |
13809 'lenient ordinal parsing ' + i + ' month check'); | |
13810 assert.equal(testMoment.date(), i, | |
13811 'lenient ordinal parsing ' + i + ' date check'); | |
13812 } | |
13813 }); | |
13814 | |
13815 test('lenient ordinal parsing of number', function (assert) { | |
13816 var i, testMoment; | |
13817 for (i = 1; i <= 31; ++i) { | |
13818 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
13819 assert.equal(testMoment.year(), 2014, | |
13820 'lenient ordinal parsing of number ' + i + ' year check'); | |
13821 assert.equal(testMoment.month(), 0, | |
13822 'lenient ordinal parsing of number ' + i + ' month check'); | |
13823 assert.equal(testMoment.date(), i, | |
13824 'lenient ordinal parsing of number ' + i + ' date check'); | |
13825 } | |
13826 }); | |
13827 | |
13828 test('strict ordinal parsing', function (assert) { | |
13829 var i, ordinalStr, testMoment; | |
13830 for (i = 1; i <= 31; ++i) { | |
13831 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
13832 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
13833 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
13834 } | |
13835 }); | |
13836 | |
13837 })); | |
13838 | |
13839 (function (global, factory) { | |
13840 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
13841 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
13842 factory(global.moment) | |
13843 }(this, function (moment) { 'use strict'; | |
13844 | |
13845 /*global QUnit:false*/ | |
13846 | |
13847 var test = QUnit.test; | |
13848 | |
13849 function module (name, lifecycle) { | |
13850 QUnit.module(name, { | |
13851 setup : function () { | |
13852 moment.locale('en'); | |
13853 moment.createFromInputFallback = function () { | |
13854 throw new Error('input not handled by moment'); | |
13855 }; | |
13856 if (lifecycle && lifecycle.setup) { | |
13857 lifecycle.setup(); | |
13858 } | |
13859 }, | |
13860 teardown : function () { | |
13861 if (lifecycle && lifecycle.teardown) { | |
13862 lifecycle.teardown(); | |
13863 } | |
13864 } | |
13865 }); | |
13866 } | |
13867 | |
13868 function localeModule (name, lifecycle) { | |
13869 QUnit.module('locale:' + name, { | |
13870 setup : function () { | |
13871 moment.locale(name); | |
13872 moment.createFromInputFallback = function () { | |
13873 throw new Error('input not handled by moment'); | |
13874 }; | |
13875 if (lifecycle && lifecycle.setup) { | |
13876 lifecycle.setup(); | |
13877 } | |
13878 }, | |
13879 teardown : function () { | |
13880 moment.locale('en'); | |
13881 if (lifecycle && lifecycle.teardown) { | |
13882 lifecycle.teardown(); | |
13883 } | |
13884 } | |
13885 }); | |
13886 } | |
13887 | |
13888 localeModule('hu'); | |
13889 | |
13890 test('parse', function (assert) { | |
13891 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('_'), | |
13892 i; | |
13893 function equalTest(input, mmm, i) { | |
13894 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
13895 } | |
13896 for (i = 0; i < 12; i++) { | |
13897 tests[i] = tests[i].split(' '); | |
13898 equalTest(tests[i][0], 'MMM', i); | |
13899 equalTest(tests[i][1], 'MMM', i); | |
13900 equalTest(tests[i][0], 'MMMM', i); | |
13901 equalTest(tests[i][1], 'MMMM', i); | |
13902 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
13903 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
13904 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
13905 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
13906 } | |
13907 }); | |
13908 | |
13909 test('format', function (assert) { | |
13910 var a = [ | |
13911 ['dddd, MMMM Do YYYY, HH:mm:ss', 'vasárnap, február 14. 2010, 15:25:50'], | |
13912 ['ddd, HH', 'vas, 15'], | |
13913 ['M Mo MM MMMM MMM', '2 2. 02 február feb'], | |
13914 ['YYYY YY', '2010 10'], | |
13915 ['D Do DD', '14 14. 14'], | |
13916 ['d do dddd ddd dd', '0 0. vasárnap vas v'], | |
13917 ['DDD DDDo DDDD', '45 45. 045'], | |
13918 ['w wo ww', '7 7. 07'], | |
13919 ['H HH', '15 15'], | |
13920 ['m mm', '25 25'], | |
13921 ['s ss', '50 50'], | |
13922 ['[az év] DDDo [napja]', 'az év 45. napja'], | |
13923 ['LTS', '15:25:50'], | |
13924 ['L', '2010.02.14.'], | |
13925 ['LL', '2010. február 14.'], | |
13926 ['LLL', '2010. február 14. 15:25'], | |
13927 ['LLLL', '2010. február 14., vasárnap 15:25'], | |
13928 ['l', '2010.2.14.'], | |
13929 ['ll', '2010. feb 14.'], | |
13930 ['lll', '2010. feb 14. 15:25'], | |
13931 ['llll', '2010. feb 14., vas 15:25'] | |
13932 ], | |
13933 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
13934 i; | |
13935 for (i = 0; i < a.length; i++) { | |
13936 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
13937 } | |
13938 }); | |
13939 | |
13940 test('meridiem', function (assert) { | |
13941 assert.equal(moment([2011, 2, 23, 0, 0]).format('a'), 'de', 'am'); | |
13942 assert.equal(moment([2011, 2, 23, 11, 59]).format('a'), 'de', 'am'); | |
13943 assert.equal(moment([2011, 2, 23, 12, 0]).format('a'), 'du', 'pm'); | |
13944 assert.equal(moment([2011, 2, 23, 23, 59]).format('a'), 'du', 'pm'); | |
13945 | |
13946 assert.equal(moment([2011, 2, 23, 0, 0]).format('A'), 'DE', 'AM'); | |
13947 assert.equal(moment([2011, 2, 23, 11, 59]).format('A'), 'DE', 'AM'); | |
13948 assert.equal(moment([2011, 2, 23, 12, 0]).format('A'), 'DU', 'PM'); | |
13949 assert.equal(moment([2011, 2, 23, 23, 59]).format('A'), 'DU', 'PM'); | |
13950 }); | |
13951 | |
13952 test('format ordinal', function (assert) { | |
13953 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.'); | |
13954 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.'); | |
13955 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.'); | |
13956 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.'); | |
13957 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.'); | |
13958 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.'); | |
13959 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.'); | |
13960 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.'); | |
13961 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.'); | |
13962 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.'); | |
13963 | |
13964 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.'); | |
13965 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.'); | |
13966 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.'); | |
13967 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.'); | |
13968 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.'); | |
13969 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.'); | |
13970 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.'); | |
13971 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.'); | |
13972 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.'); | |
13973 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.'); | |
13974 | |
13975 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.'); | |
13976 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.'); | |
13977 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.'); | |
13978 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.'); | |
13979 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.'); | |
13980 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.'); | |
13981 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.'); | |
13982 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.'); | |
13983 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.'); | |
13984 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.'); | |
13985 | |
13986 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.'); | |
13987 }); | |
13988 | |
13989 test('format month', function (assert) { | |
13990 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('_'), | |
13991 i; | |
13992 for (i = 0; i < expected.length; i++) { | |
13993 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
13994 } | |
13995 }); | |
13996 | |
13997 test('format week', function (assert) { | |
13998 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('_'), | |
13999 i; | |
14000 for (i = 0; i < expected.length; i++) { | |
14001 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd'), expected[i], expected[i]); | |
14002 } | |
14003 }); | |
14004 | |
14005 test('from', function (assert) { | |
14006 var start = moment([2007, 1, 28]); | |
14007 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'); | |
14008 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'egy perc', '45 másodperc = egy perc'); | |
14009 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'egy perc', '89 másodperc = egy perc'); | |
14010 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 perc', '90 másodperc = 2 perc'); | |
14011 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 perc', '44 perc = 44 perc'); | |
14012 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'egy óra', '45 perc = egy óra'); | |
14013 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'egy óra', '89 perc = egy óra'); | |
14014 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 óra', '90 perc = 2 óra'); | |
14015 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 óra', '5 óra = 5 óra'); | |
14016 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 óra', '21 óra = 21 óra'); | |
14017 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'egy nap', '22 óra = egy nap'); | |
14018 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'egy nap', '35 óra = egy nap'); | |
14019 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 nap', '36 óra = 2 nap'); | |
14020 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'egy nap', '1 nap = egy nap'); | |
14021 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 nap', '5 nap = 5 nap'); | |
14022 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 nap', '25 nap = 25 nap'); | |
14023 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'egy hónap', '26 nap = egy hónap'); | |
14024 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'egy hónap', '30 nap = egy hónap'); | |
14025 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'egy hónap', '45 nap = egy hónap'); | |
14026 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 hónap', '46 nap = 2 hónap'); | |
14027 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 hónap', '75 nap = 2 hónap'); | |
14028 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 hónap', '76 nap = 3 hónap'); | |
14029 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'egy hónap', '1 hónap = egy hónap'); | |
14030 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 hónap', '5 hónap = 5 hónap'); | |
14031 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'egy év', '345 nap = egy év'); | |
14032 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 év', '548 nap = 2 év'); | |
14033 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'egy év', '1 év = egy év'); | |
14034 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 év', '5 év = 5 év'); | |
14035 }); | |
14036 | |
14037 test('suffix', function (assert) { | |
14038 assert.equal(moment(30000).from(0), 'néhány másodperc múlva', 'prefix'); | |
14039 assert.equal(moment(0).from(30000), 'néhány másodperce', 'suffix'); | |
14040 }); | |
14041 | |
14042 test('now from now', function (assert) { | |
14043 assert.equal(moment().fromNow(), 'néhány másodperce', 'now from now should display as in the past'); | |
14044 }); | |
14045 | |
14046 test('fromNow', function (assert) { | |
14047 assert.equal(moment().add({s: 30}).fromNow(), 'néhány másodperc múlva', 'néhány másodperc múlva'); | |
14048 assert.equal(moment().add({d: 5}).fromNow(), '5 nap múlva', '5 nap múlva'); | |
14049 }); | |
14050 | |
14051 test('calendar day', function (assert) { | |
14052 var a = moment().hours(2).minutes(0).seconds(0); | |
14053 | |
14054 assert.equal(moment(a).calendar(), 'ma 2:00-kor', 'today at the same time'); | |
14055 assert.equal(moment(a).add({m: 25}).calendar(), 'ma 2:25-kor', 'Now plus 25 min'); | |
14056 assert.equal(moment(a).add({h: 1}).calendar(), 'ma 3:00-kor', 'Now plus 1 hour'); | |
14057 assert.equal(moment(a).add({d: 1}).calendar(), 'holnap 2:00-kor', 'tomorrow at the same time'); | |
14058 assert.equal(moment(a).subtract({h: 1}).calendar(), 'ma 1:00-kor', 'Now minus 1 hour'); | |
14059 assert.equal(moment(a).subtract({d: 1}).calendar(), 'tegnap 2:00-kor', 'yesterday at the same time'); | |
14060 }); | |
14061 | |
14062 test('calendar next week', function (assert) { | |
14063 var i, m, days = 'vasárnap_hétfőn_kedden_szerdán_csütörtökön_pénteken_szombaton'.split('_'); | |
14064 for (i = 2; i < 7; i++) { | |
14065 m = moment().add({d: i}); | |
14066 assert.equal(m.calendar(), m.format('[' + days[m.day()] + '] LT[-kor]'), 'today + ' + i + ' days current time'); | |
14067 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
14068 assert.equal(m.calendar(), m.format('[' + days[m.day()] + '] LT[-kor]'), 'today + ' + i + ' days beginning of day'); | |
14069 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
14070 assert.equal(m.calendar(), m.format('[' + days[m.day()] + '] LT[-kor]'), 'today + ' + i + ' days end of day'); | |
14071 } | |
14072 }); | |
14073 | |
14074 test('calendar last week', function (assert) { | |
14075 var i, m, days = 'vasárnap_hétfőn_kedden_szerdán_csütörtökön_pénteken_szombaton'.split('_'); | |
14076 | |
14077 for (i = 2; i < 7; i++) { | |
14078 m = moment().subtract({d: i}); | |
14079 assert.equal(m.calendar(), m.format('[múlt ' + days[m.day()] + '] LT[-kor]'), 'today - ' + i + ' days current time'); | |
14080 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
14081 assert.equal(m.calendar(), m.format('[múlt ' + days[m.day()] + '] LT[-kor]'), 'today - ' + i + ' days beginning of day'); | |
14082 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
14083 assert.equal(m.calendar(), m.format('[múlt ' + days[m.day()] + '] LT[-kor]'), 'today - ' + i + ' days end of day'); | |
14084 } | |
14085 }); | |
14086 | |
14087 test('calendar all else', function (assert) { | |
14088 var weeksAgo = moment().subtract({w: 1}), | |
14089 weeksFromNow = moment().add({w: 1}); | |
14090 | |
14091 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), 'egy héte'); | |
14092 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'egy hét múlva'); | |
14093 | |
14094 weeksAgo = moment().subtract({w: 2}); | |
14095 weeksFromNow = moment().add({w: 2}); | |
14096 | |
14097 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 hete'); | |
14098 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), '2 hét múlva'); | |
14099 }); | |
14100 | |
14101 test('weeks year starting sunday', function (assert) { | |
14102 assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1'); | |
14103 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
14104 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2'); | |
14105 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
14106 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3'); | |
14107 }); | |
14108 | |
14109 test('weeks year starting monday', function (assert) { | |
14110 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
14111 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
14112 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
14113 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
14114 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
14115 }); | |
14116 | |
14117 test('weeks year starting tuesday', function (assert) { | |
14118 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
14119 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
14120 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
14121 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
14122 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
14123 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
14124 }); | |
14125 | |
14126 test('weeks year starting wednesday', function (assert) { | |
14127 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
14128 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
14129 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
14130 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
14131 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
14132 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
14133 }); | |
14134 | |
14135 test('weeks year starting thursday', function (assert) { | |
14136 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
14137 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
14138 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
14139 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
14140 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
14141 assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3'); | |
14142 }); | |
14143 | |
14144 test('weeks year starting friday', function (assert) { | |
14145 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1'); | |
14146 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
14147 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1'); | |
14148 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2'); | |
14149 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2'); | |
14150 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3'); | |
14151 }); | |
14152 | |
14153 test('weeks year starting saturday', function (assert) { | |
14154 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1'); | |
14155 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
14156 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1'); | |
14157 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2'); | |
14158 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2'); | |
14159 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3'); | |
14160 }); | |
14161 | |
14162 test('weeks year starting sunday formatted', function (assert) { | |
14163 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', 'Dec 26 2011 should be week 1'); | |
14164 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1.', 'Jan 1 2012 should be week 1'); | |
14165 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2.', 'Jan 2 2012 should be week 2'); | |
14166 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2.', 'Jan 8 2012 should be week 2'); | |
14167 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3.', 'Jan 9 2012 should be week 3'); | |
14168 }); | |
14169 | |
14170 test('lenient ordinal parsing', function (assert) { | |
14171 var i, ordinalStr, testMoment; | |
14172 for (i = 1; i <= 31; ++i) { | |
14173 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
14174 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
14175 assert.equal(testMoment.year(), 2014, | |
14176 'lenient ordinal parsing ' + i + ' year check'); | |
14177 assert.equal(testMoment.month(), 0, | |
14178 'lenient ordinal parsing ' + i + ' month check'); | |
14179 assert.equal(testMoment.date(), i, | |
14180 'lenient ordinal parsing ' + i + ' date check'); | |
14181 } | |
14182 }); | |
14183 | |
14184 test('lenient ordinal parsing of number', function (assert) { | |
14185 var i, testMoment; | |
14186 for (i = 1; i <= 31; ++i) { | |
14187 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
14188 assert.equal(testMoment.year(), 2014, | |
14189 'lenient ordinal parsing of number ' + i + ' year check'); | |
14190 assert.equal(testMoment.month(), 0, | |
14191 'lenient ordinal parsing of number ' + i + ' month check'); | |
14192 assert.equal(testMoment.date(), i, | |
14193 'lenient ordinal parsing of number ' + i + ' date check'); | |
14194 } | |
14195 }); | |
14196 | |
14197 test('strict ordinal parsing', function (assert) { | |
14198 var i, ordinalStr, testMoment; | |
14199 for (i = 1; i <= 31; ++i) { | |
14200 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
14201 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
14202 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
14203 } | |
14204 }); | |
14205 | |
14206 })); | |
14207 | |
14208 (function (global, factory) { | |
14209 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
14210 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
14211 factory(global.moment) | |
14212 }(this, function (moment) { 'use strict'; | |
14213 | |
14214 /*global QUnit:false*/ | |
14215 | |
14216 var test = QUnit.test; | |
14217 | |
14218 function module (name, lifecycle) { | |
14219 QUnit.module(name, { | |
14220 setup : function () { | |
14221 moment.locale('en'); | |
14222 moment.createFromInputFallback = function () { | |
14223 throw new Error('input not handled by moment'); | |
14224 }; | |
14225 if (lifecycle && lifecycle.setup) { | |
14226 lifecycle.setup(); | |
14227 } | |
14228 }, | |
14229 teardown : function () { | |
14230 if (lifecycle && lifecycle.teardown) { | |
14231 lifecycle.teardown(); | |
14232 } | |
14233 } | |
14234 }); | |
14235 } | |
14236 | |
14237 function localeModule (name, lifecycle) { | |
14238 QUnit.module('locale:' + name, { | |
14239 setup : function () { | |
14240 moment.locale(name); | |
14241 moment.createFromInputFallback = function () { | |
14242 throw new Error('input not handled by moment'); | |
14243 }; | |
14244 if (lifecycle && lifecycle.setup) { | |
14245 lifecycle.setup(); | |
14246 } | |
14247 }, | |
14248 teardown : function () { | |
14249 moment.locale('en'); | |
14250 if (lifecycle && lifecycle.teardown) { | |
14251 lifecycle.teardown(); | |
14252 } | |
14253 } | |
14254 }); | |
14255 } | |
14256 | |
14257 localeModule('hy-am'); | |
14258 | |
14259 test('parse', function (assert) { | |
14260 var tests = 'հունվար հնվ_փետրվար փտր_մարտ մրտ_ապրիլ ապր_մայիս մյս_հունիս հնս_հուլիս հլս_օգոստոս օգս_սեպտեմբեր սպտ_հոկտեմբեր հկտ_նոյեմբեր նմբ_դեկտեմբեր դկտ'.split('_'), i; | |
14261 function equalTest(input, mmm, i) { | |
14262 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
14263 } | |
14264 for (i = 0; i < 12; i++) { | |
14265 tests[i] = tests[i].split(' '); | |
14266 equalTest(tests[i][0], 'MMM', i); | |
14267 equalTest(tests[i][1], 'MMM', i); | |
14268 equalTest(tests[i][0], 'MMMM', i); | |
14269 equalTest(tests[i][1], 'MMMM', i); | |
14270 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
14271 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
14272 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
14273 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
14274 } | |
14275 }); | |
14276 | |
14277 test('parse exceptional case', function (assert) { | |
14278 assert.equal(moment('11 մայիսի 1989', ['DD MMMM YYYY']).format('DD-MM-YYYY'), '11-05-1989'); | |
14279 }); | |
14280 | |
14281 test('format', function (assert) { | |
14282 var a = [ | |
14283 ['dddd, Do MMMM YYYY, HH:mm:ss', 'կիրակի, 14 փետրվարի 2010, 15:25:50'], | |
14284 ['ddd, h A', 'կրկ, 3 ցերեկվա'], | |
14285 ['M Mo MM MMMM MMM', '2 2 02 փետրվար փտր'], | |
14286 ['YYYY YY', '2010 10'], | |
14287 ['D Do DD', '14 14 14'], | |
14288 ['d do dddd ddd dd', '0 0 կիրակի կրկ կրկ'], | |
14289 ['DDD DDDo DDDD', '45 45-րդ 045'], | |
14290 ['w wo ww', '7 7-րդ 07'], | |
14291 ['h hh', '3 03'], | |
14292 ['H HH', '15 15'], | |
14293 ['m mm', '25 25'], | |
14294 ['s ss', '50 50'], | |
14295 ['a A', 'ցերեկվա ցերեկվա'], | |
14296 ['[տարվա] DDDo [օրը]', 'տարվա 45-րդ օրը'], | |
14297 ['LTS', '15:25:50'], | |
14298 ['L', '14.02.2010'], | |
14299 ['LL', '14 փետրվարի 2010 թ.'], | |
14300 ['LLL', '14 փետրվարի 2010 թ., 15:25'], | |
14301 ['LLLL', 'կիրակի, 14 փետրվարի 2010 թ., 15:25'], | |
14302 ['l', '14.2.2010'], | |
14303 ['ll', '14 փտր 2010 թ.'], | |
14304 ['lll', '14 փտր 2010 թ., 15:25'], | |
14305 ['llll', 'կրկ, 14 փտր 2010 թ., 15:25'] | |
14306 ], | |
14307 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
14308 i; | |
14309 for (i = 0; i < a.length; i++) { | |
14310 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
14311 } | |
14312 }); | |
14313 | |
14314 test('format meridiem', function (assert) { | |
14315 assert.equal(moment([2012, 11, 28, 0, 0]).format('A'), 'գիշերվա', 'night'); | |
14316 assert.equal(moment([2012, 11, 28, 3, 59]).format('A'), 'գիշերվա', 'night'); | |
14317 assert.equal(moment([2012, 11, 28, 4, 0]).format('A'), 'առավոտվա', 'morning'); | |
14318 assert.equal(moment([2012, 11, 28, 11, 59]).format('A'), 'առավոտվա', 'morning'); | |
14319 assert.equal(moment([2012, 11, 28, 12, 0]).format('A'), 'ցերեկվա', 'afternoon'); | |
14320 assert.equal(moment([2012, 11, 28, 16, 59]).format('A'), 'ցերեկվա', 'afternoon'); | |
14321 assert.equal(moment([2012, 11, 28, 17, 0]).format('A'), 'երեկոյան', 'evening'); | |
14322 assert.equal(moment([2012, 11, 28, 23, 59]).format('A'), 'երեկոյան', 'evening'); | |
14323 }); | |
14324 | |
14325 test('format ordinal', function (assert) { | |
14326 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-ին', '1-ին'); | |
14327 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-րդ', '2-րդ'); | |
14328 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-րդ', '3-րդ'); | |
14329 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-րդ', '4-րդ'); | |
14330 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-րդ', '5-րդ'); | |
14331 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-րդ', '6-րդ'); | |
14332 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-րդ', '7-րդ'); | |
14333 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-րդ', '8-րդ'); | |
14334 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-րդ', '9-րդ'); | |
14335 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-րդ', '10-րդ'); | |
14336 | |
14337 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-րդ', '11-րդ'); | |
14338 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-րդ', '12-րդ'); | |
14339 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-րդ', '13-րդ'); | |
14340 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-րդ', '14-րդ'); | |
14341 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-րդ', '15-րդ'); | |
14342 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-րդ', '16-րդ'); | |
14343 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-րդ', '17-րդ'); | |
14344 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-րդ', '18-րդ'); | |
14345 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-րդ', '19-րդ'); | |
14346 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-րդ', '20-րդ'); | |
14347 | |
14348 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-րդ', '21-րդ'); | |
14349 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-րդ', '22-րդ'); | |
14350 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-րդ', '23-րդ'); | |
14351 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-րդ', '24-րդ'); | |
14352 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-րդ', '25-րդ'); | |
14353 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-րդ', '26-րդ'); | |
14354 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-րդ', '27-րդ'); | |
14355 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-րդ', '28-րդ'); | |
14356 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-րդ', '29-րդ'); | |
14357 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-րդ', '30-րդ'); | |
14358 | |
14359 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-րդ', '31-րդ'); | |
14360 }); | |
14361 | |
14362 test('format month', function (assert) { | |
14363 var expected = 'հունվար հնվ_փետրվար փտր_մարտ մրտ_ապրիլ ապր_մայիս մյս_հունիս հնս_հուլիս հլս_օգոստոս օգս_սեպտեմբեր սպտ_հոկտեմբեր հկտ_նոյեմբեր նմբ_դեկտեմբեր դկտ'.split('_'), i; | |
14364 for (i = 0; i < expected.length; i++) { | |
14365 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
14366 } | |
14367 }); | |
14368 | |
14369 test('format month case', function (assert) { | |
14370 var months = { | |
14371 'nominative': 'հունվար_փետրվար_մարտ_ապրիլ_մայիս_հունիս_հուլիս_օգոստոս_սեպտեմբեր_հոկտեմբեր_նոյեմբեր_դեկտեմբեր'.split('_'), | |
14372 'accusative': 'հունվարի_փետրվարի_մարտի_ապրիլի_մայիսի_հունիսի_հուլիսի_օգոստոսի_սեպտեմբերի_հոկտեմբերի_նոյեմբերի_դեկտեմբերի'.split('_') | |
14373 }, i; | |
14374 for (i = 0; i < 12; i++) { | |
14375 assert.equal(moment([2011, i, 1]).format('D MMMM'), '1 ' + months.accusative[i], '1 ' + months.accusative[i]); | |
14376 assert.equal(moment([2011, i, 1]).format('MMMM'), months.nominative[i], '1 ' + months.nominative[i]); | |
14377 } | |
14378 }); | |
14379 | |
14380 test('format month short case', function (assert) { | |
14381 var monthsShort = { | |
14382 'nominative': 'հնվ_փտր_մրտ_ապր_մյս_հնս_հլս_օգս_սպտ_հկտ_նմբ_դկտ'.split('_'), | |
14383 'accusative': 'հնվ_փտր_մրտ_ապր_մյս_հնս_հլս_օգս_սպտ_հկտ_նմբ_դկտ'.split('_') | |
14384 }, i; | |
14385 for (i = 0; i < 12; i++) { | |
14386 assert.equal(moment([2011, i, 1]).format('D MMM'), '1 ' + monthsShort.accusative[i], '1 ' + monthsShort.accusative[i]); | |
14387 assert.equal(moment([2011, i, 1]).format('MMM'), monthsShort.nominative[i], '1 ' + monthsShort.nominative[i]); | |
14388 } | |
14389 }); | |
14390 | |
14391 test('format month case with escaped symbols', function (assert) { | |
14392 var months = { | |
14393 'nominative': 'հունվար_փետրվար_մարտ_ապրիլ_մայիս_հունիս_հուլիս_օգոստոս_սեպտեմբեր_հոկտեմբեր_նոյեմբեր_դեկտեմբեր'.split('_'), | |
14394 'accusative': 'հունվարի_փետրվարի_մարտի_ապրիլի_մայիսի_հունիսի_հուլիսի_օգոստոսի_սեպտեմբերի_հոկտեմբերի_նոյեմբերի_դեկտեմբերի'.split('_') | |
14395 }, i; | |
14396 for (i = 0; i < 12; i++) { | |
14397 assert.equal(moment([2013, i, 1]).format('D[] MMMM'), '1 ' + months.accusative[i], '1 ' + months.accusative[i]); | |
14398 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>'); | |
14399 assert.equal(moment([2013, i, 1]).format('D[-ին օրը] MMMM'), '1-ին օրը ' + months.accusative[i], '1-ին օրը ' + months.accusative[i]); | |
14400 assert.equal(moment([2013, i, 1]).format('D, MMMM'), '1, ' + months.nominative[i], '1, ' + months.nominative[i]); | |
14401 } | |
14402 }); | |
14403 | |
14404 test('format month short case with escaped symbols', function (assert) { | |
14405 var monthsShort = { | |
14406 'nominative': 'հնվ_փտր_մրտ_ապր_մյս_հնս_հլս_օգս_սպտ_հկտ_նմբ_դկտ'.split('_'), | |
14407 'accusative': 'հնվ_փտր_մրտ_ապր_մյս_հնս_հլս_օգս_սպտ_հկտ_նմբ_դկտ'.split('_') | |
14408 }, i; | |
14409 for (i = 0; i < 12; i++) { | |
14410 assert.equal(moment([2013, i, 1]).format('D[] MMM'), '1 ' + monthsShort.accusative[i], '1 ' + monthsShort.accusative[i]); | |
14411 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>'); | |
14412 assert.equal(moment([2013, i, 1]).format('D[-ին օրը] MMM'), '1-ին օրը ' + monthsShort.accusative[i], '1-ին օրը ' + monthsShort.accusative[i]); | |
14413 assert.equal(moment([2013, i, 1]).format('D, MMM'), '1, ' + monthsShort.nominative[i], '1, ' + monthsShort.nominative[i]); | |
14414 } | |
14415 }); | |
14416 | |
14417 test('format week', function (assert) { | |
14418 var expected = 'կիրակի կրկ կրկ_երկուշաբթի երկ երկ_երեքշաբթի երք երք_չորեքշաբթի չրք չրք_հինգշաբթի հնգ հնգ_ուրբաթ ուրբ ուրբ_շաբաթ շբթ շբթ'.split('_'), i; | |
14419 for (i = 0; i < expected.length; i++) { | |
14420 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
14421 } | |
14422 }); | |
14423 | |
14424 test('from', function (assert) { | |
14425 var start = moment([2007, 1, 28]); | |
14426 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'մի քանի վայրկյան', '44 seconds = seconds'); | |
14427 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'րոպե', '45 seconds = a minute'); | |
14428 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'րոպե', '89 seconds = a minute'); | |
14429 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 րոպե', '90 seconds = 2 minutes'); | |
14430 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 րոպե', '44 minutes = 44 minutes'); | |
14431 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ժամ', '45 minutes = an hour'); | |
14432 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ժամ', '89 minutes = an hour'); | |
14433 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ժամ', '90 minutes = 2 hours'); | |
14434 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ժամ', '5 hours = 5 hours'); | |
14435 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ժամ', '21 hours = 21 hours'); | |
14436 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'օր', '22 hours = a day'); | |
14437 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'օր', '35 hours = a day'); | |
14438 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 օր', '36 hours = 2 days'); | |
14439 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'օր', '1 day = a day'); | |
14440 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 օր', '5 days = 5 days'); | |
14441 assert.equal(start.from(moment([2007, 1, 28]).add({d: 11}), true), '11 օր', '11 days = 11 days'); | |
14442 assert.equal(start.from(moment([2007, 1, 28]).add({d: 21}), true), '21 օր', '21 days = 21 days'); | |
14443 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 օր', '25 days = 25 days'); | |
14444 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ամիս', '26 days = a month'); | |
14445 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ամիս', '30 days = a month'); | |
14446 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ամիս', '43 days = a month'); | |
14447 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 ամիս', '46 days = 2 months'); | |
14448 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 ամիս', '75 days = 2 months'); | |
14449 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 ամիս', '76 days = 3 months'); | |
14450 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ամիս', '1 month = a month'); | |
14451 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 ամիս', '5 months = 5 months'); | |
14452 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'տարի', '345 days = a year'); | |
14453 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 տարի', '548 days = 2 years'); | |
14454 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'տարի', '1 year = a year'); | |
14455 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 տարի', '5 years = 5 years'); | |
14456 }); | |
14457 | |
14458 test('suffix', function (assert) { | |
14459 assert.equal(moment(30000).from(0), 'մի քանի վայրկյան հետո', 'prefix'); | |
14460 assert.equal(moment(0).from(30000), 'մի քանի վայրկյան առաջ', 'suffix'); | |
14461 }); | |
14462 | |
14463 test('fromNow', function (assert) { | |
14464 assert.equal(moment().add({s: 30}).fromNow(), 'մի քանի վայրկյան հետո', 'in seconds'); | |
14465 assert.equal(moment().add({d: 5}).fromNow(), '5 օր հետո', 'in 5 days'); | |
14466 }); | |
14467 | |
14468 test('calendar day', function (assert) { | |
14469 var a = moment().hours(2).minutes(0).seconds(0); | |
14470 | |
14471 assert.equal(moment(a).calendar(), 'այսօր 02:00', 'today at the same time'); | |
14472 assert.equal(moment(a).add({m: 25}).calendar(), 'այսօր 02:25', 'Now plus 25 min'); | |
14473 assert.equal(moment(a).add({h: 1}).calendar(), 'այսօր 03:00', 'Now plus 1 hour'); | |
14474 assert.equal(moment(a).add({d: 1}).calendar(), 'վաղը 02:00', 'tomorrow at the same time'); | |
14475 assert.equal(moment(a).subtract({h: 1}).calendar(), 'այսօր 01:00', 'Now minus 1 hour'); | |
14476 assert.equal(moment(a).subtract({d: 1}).calendar(), 'երեկ 02:00', 'yesterday at the same time'); | |
14477 }); | |
14478 | |
14479 test('calendar next week', function (assert) { | |
14480 var i, m; | |
14481 function makeFormat(d) { | |
14482 return 'dddd [օրը ժամը] LT'; | |
14483 } | |
14484 | |
14485 for (i = 2; i < 7; i++) { | |
14486 m = moment().add({d: i}); | |
14487 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time'); | |
14488 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
14489 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day'); | |
14490 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
14491 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day'); | |
14492 } | |
14493 }); | |
14494 | |
14495 test('calendar last week', function (assert) { | |
14496 var i, m; | |
14497 | |
14498 function makeFormat(d) { | |
14499 return '[անցած] dddd [օրը ժամը] LT'; | |
14500 } | |
14501 | |
14502 for (i = 2; i < 7; i++) { | |
14503 m = moment().subtract({d: i}); | |
14504 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time'); | |
14505 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
14506 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day'); | |
14507 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
14508 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day'); | |
14509 } | |
14510 }); | |
14511 | |
14512 test('calendar all else', function (assert) { | |
14513 var weeksAgo = moment().subtract({w: 1}), | |
14514 weeksFromNow = moment().add({w: 1}); | |
14515 | |
14516 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
14517 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
14518 | |
14519 weeksAgo = moment().subtract({w: 2}); | |
14520 weeksFromNow = moment().add({w: 2}); | |
14521 | |
14522 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
14523 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
14524 }); | |
14525 | |
14526 test('weeks year starting sunday', function (assert) { | |
14527 assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1'); | |
14528 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
14529 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2'); | |
14530 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
14531 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3'); | |
14532 }); | |
14533 | |
14534 test('weeks year starting monday', function (assert) { | |
14535 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
14536 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
14537 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
14538 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
14539 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
14540 }); | |
14541 | |
14542 test('weeks year starting tuesday', function (assert) { | |
14543 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
14544 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
14545 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
14546 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
14547 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
14548 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
14549 }); | |
14550 | |
14551 test('weeks year starting wednesday', function (assert) { | |
14552 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
14553 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
14554 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
14555 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
14556 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
14557 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
14558 }); | |
14559 | |
14560 test('weeks year starting thursday', function (assert) { | |
14561 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
14562 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
14563 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
14564 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
14565 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
14566 assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3'); | |
14567 }); | |
14568 | |
14569 test('weeks year starting friday', function (assert) { | |
14570 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1'); | |
14571 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
14572 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1'); | |
14573 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2'); | |
14574 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2'); | |
14575 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3'); | |
14576 }); | |
14577 | |
14578 test('weeks year starting saturday', function (assert) { | |
14579 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1'); | |
14580 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
14581 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1'); | |
14582 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2'); | |
14583 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2'); | |
14584 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3'); | |
14585 }); | |
14586 | |
14587 test('weeks year starting sunday formatted', function (assert) { | |
14588 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-ին', 'Dec 26 2011 should be week 1'); | |
14589 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-ին', 'Jan 1 2012 should be week 1'); | |
14590 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-րդ', 'Jan 2 2012 should be week 2'); | |
14591 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-րդ', 'Jan 8 2012 should be week 2'); | |
14592 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-րդ', 'Jan 9 2012 should be week 3'); | |
14593 }); | |
14594 | |
14595 test('lenient ordinal parsing', function (assert) { | |
14596 var i, ordinalStr, testMoment; | |
14597 for (i = 1; i <= 31; ++i) { | |
14598 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
14599 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
14600 assert.equal(testMoment.year(), 2014, | |
14601 'lenient ordinal parsing ' + i + ' year check'); | |
14602 assert.equal(testMoment.month(), 0, | |
14603 'lenient ordinal parsing ' + i + ' month check'); | |
14604 assert.equal(testMoment.date(), i, | |
14605 'lenient ordinal parsing ' + i + ' date check'); | |
14606 } | |
14607 }); | |
14608 | |
14609 test('lenient ordinal parsing of number', function (assert) { | |
14610 var i, testMoment; | |
14611 for (i = 1; i <= 31; ++i) { | |
14612 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
14613 assert.equal(testMoment.year(), 2014, | |
14614 'lenient ordinal parsing of number ' + i + ' year check'); | |
14615 assert.equal(testMoment.month(), 0, | |
14616 'lenient ordinal parsing of number ' + i + ' month check'); | |
14617 assert.equal(testMoment.date(), i, | |
14618 'lenient ordinal parsing of number ' + i + ' date check'); | |
14619 } | |
14620 }); | |
14621 | |
14622 test('strict ordinal parsing', function (assert) { | |
14623 var i, ordinalStr, testMoment; | |
14624 for (i = 1; i <= 31; ++i) { | |
14625 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
14626 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
14627 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
14628 } | |
14629 }); | |
14630 | |
14631 })); | |
14632 | |
14633 (function (global, factory) { | |
14634 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
14635 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
14636 factory(global.moment) | |
14637 }(this, function (moment) { 'use strict'; | |
14638 | |
14639 /*global QUnit:false*/ | |
14640 | |
14641 var test = QUnit.test; | |
14642 | |
14643 function module (name, lifecycle) { | |
14644 QUnit.module(name, { | |
14645 setup : function () { | |
14646 moment.locale('en'); | |
14647 moment.createFromInputFallback = function () { | |
14648 throw new Error('input not handled by moment'); | |
14649 }; | |
14650 if (lifecycle && lifecycle.setup) { | |
14651 lifecycle.setup(); | |
14652 } | |
14653 }, | |
14654 teardown : function () { | |
14655 if (lifecycle && lifecycle.teardown) { | |
14656 lifecycle.teardown(); | |
14657 } | |
14658 } | |
14659 }); | |
14660 } | |
14661 | |
14662 function localeModule (name, lifecycle) { | |
14663 QUnit.module('locale:' + name, { | |
14664 setup : function () { | |
14665 moment.locale(name); | |
14666 moment.createFromInputFallback = function () { | |
14667 throw new Error('input not handled by moment'); | |
14668 }; | |
14669 if (lifecycle && lifecycle.setup) { | |
14670 lifecycle.setup(); | |
14671 } | |
14672 }, | |
14673 teardown : function () { | |
14674 moment.locale('en'); | |
14675 if (lifecycle && lifecycle.teardown) { | |
14676 lifecycle.teardown(); | |
14677 } | |
14678 } | |
14679 }); | |
14680 } | |
14681 | |
14682 localeModule('id'); | |
14683 | |
14684 test('parse', function (assert) { | |
14685 var tests = 'Januari Jan_Februari Feb_Maret Mar_April Apr_Mei Mei_Juni Jun_Juli Jul_Agustus Ags_September Sep_Oktober Okt_November Nov_Desember Des'.split('_'), i; | |
14686 function equalTest(input, mmm, i) { | |
14687 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
14688 } | |
14689 for (i = 0; i < 12; i++) { | |
14690 tests[i] = tests[i].split(' '); | |
14691 equalTest(tests[i][0], 'MMM', i); | |
14692 equalTest(tests[i][1], 'MMM', i); | |
14693 equalTest(tests[i][0], 'MMMM', i); | |
14694 equalTest(tests[i][1], 'MMMM', i); | |
14695 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
14696 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
14697 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
14698 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
14699 } | |
14700 }); | |
14701 | |
14702 test('format', function (assert) { | |
14703 var a = [ | |
14704 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Minggu, Februari 14 2010, 3:25:50 sore'], | |
14705 ['ddd, hA', 'Min, 3sore'], | |
14706 ['M Mo MM MMMM MMM', '2 2 02 Februari Feb'], | |
14707 ['YYYY YY', '2010 10'], | |
14708 ['D Do DD', '14 14 14'], | |
14709 ['d do dddd ddd dd', '0 0 Minggu Min Mg'], | |
14710 ['DDD DDDo DDDD', '45 45 045'], | |
14711 ['w wo ww', '7 7 07'], | |
14712 ['h hh', '3 03'], | |
14713 ['H HH', '15 15'], | |
14714 ['m mm', '25 25'], | |
14715 ['s ss', '50 50'], | |
14716 ['a A', 'sore sore'], | |
14717 ['[the] DDDo [day of the year]', 'the 45 day of the year'], | |
14718 ['LTS', '15.25.50'], | |
14719 ['L', '14/02/2010'], | |
14720 ['LL', '14 Februari 2010'], | |
14721 ['LLL', '14 Februari 2010 pukul 15.25'], | |
14722 ['LLLL', 'Minggu, 14 Februari 2010 pukul 15.25'], | |
14723 ['l', '14/2/2010'], | |
14724 ['ll', '14 Feb 2010'], | |
14725 ['lll', '14 Feb 2010 pukul 15.25'], | |
14726 ['llll', 'Min, 14 Feb 2010 pukul 15.25'] | |
14727 ], | |
14728 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
14729 i; | |
14730 for (i = 0; i < a.length; i++) { | |
14731 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
14732 } | |
14733 }); | |
14734 | |
14735 test('format month', function (assert) { | |
14736 var expected = 'Januari Jan_Februari Feb_Maret Mar_April Apr_Mei Mei_Juni Jun_Juli Jul_Agustus Ags_September Sep_Oktober Okt_November Nov_Desember Des'.split('_'), i; | |
14737 for (i = 0; i < expected.length; i++) { | |
14738 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
14739 } | |
14740 }); | |
14741 | |
14742 test('format week', function (assert) { | |
14743 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; | |
14744 for (i = 0; i < expected.length; i++) { | |
14745 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
14746 } | |
14747 }); | |
14748 | |
14749 test('from', function (assert) { | |
14750 var start = moment([2007, 1, 28]); | |
14751 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'beberapa detik', '44 seconds = a few seconds'); | |
14752 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'semenit', '45 seconds = a minute'); | |
14753 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'semenit', '89 seconds = a minute'); | |
14754 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 menit', '90 seconds = 2 minutes'); | |
14755 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 menit', '44 minutes = 44 minutes'); | |
14756 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'sejam', '45 minutes = an hour'); | |
14757 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'sejam', '89 minutes = an hour'); | |
14758 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 jam', '90 minutes = 2 hours'); | |
14759 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 jam', '5 hours = 5 hours'); | |
14760 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 jam', '21 hours = 21 hours'); | |
14761 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'sehari', '22 hours = a day'); | |
14762 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'sehari', '35 hours = a day'); | |
14763 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 hari', '36 hours = 2 days'); | |
14764 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'sehari', '1 day = a day'); | |
14765 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 hari', '5 days = 5 days'); | |
14766 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 hari', '25 days = 25 days'); | |
14767 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'sebulan', '26 days = a month'); | |
14768 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'sebulan', '30 days = a month'); | |
14769 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'sebulan', '43 days = a month'); | |
14770 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 bulan', '46 days = 2 months'); | |
14771 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 bulan', '75 days = 2 months'); | |
14772 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 bulan', '76 days = 3 months'); | |
14773 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'sebulan', '1 month = a month'); | |
14774 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 bulan', '5 months = 5 months'); | |
14775 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'setahun', '345 days = a year'); | |
14776 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 tahun', '548 days = 2 years'); | |
14777 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'setahun', '1 year = a year'); | |
14778 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 tahun', '5 years = 5 years'); | |
14779 }); | |
14780 | |
14781 test('suffix', function (assert) { | |
14782 assert.equal(moment(30000).from(0), 'dalam beberapa detik', 'prefix'); | |
14783 assert.equal(moment(0).from(30000), 'beberapa detik yang lalu', 'suffix'); | |
14784 }); | |
14785 | |
14786 test('now from now', function (assert) { | |
14787 assert.equal(moment().fromNow(), 'beberapa detik yang lalu', 'now from now should display as in the past'); | |
14788 }); | |
14789 | |
14790 test('fromNow', function (assert) { | |
14791 assert.equal(moment().add({s: 30}).fromNow(), 'dalam beberapa detik', 'in a few seconds'); | |
14792 assert.equal(moment().add({d: 5}).fromNow(), 'dalam 5 hari', 'in 5 days'); | |
14793 }); | |
14794 | |
14795 test('calendar day', function (assert) { | |
14796 var a = moment().hours(2).minutes(0).seconds(0); | |
14797 | |
14798 assert.equal(moment(a).calendar(), 'Hari ini pukul 02.00', 'today at the same time'); | |
14799 assert.equal(moment(a).add({m: 25}).calendar(), 'Hari ini pukul 02.25', 'Now plus 25 min'); | |
14800 assert.equal(moment(a).add({h: 1}).calendar(), 'Hari ini pukul 03.00', 'Now plus 1 hour'); | |
14801 assert.equal(moment(a).add({d: 1}).calendar(), 'Besok pukul 02.00', 'tomorrow at the same time'); | |
14802 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Hari ini pukul 01.00', 'Now minus 1 hour'); | |
14803 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Kemarin pukul 02.00', 'yesterday at the same time'); | |
14804 }); | |
14805 | |
14806 test('calendar next week', function (assert) { | |
14807 var i, m; | |
14808 for (i = 2; i < 7; i++) { | |
14809 m = moment().add({d: i}); | |
14810 assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Today + ' + i + ' days current time'); | |
14811 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
14812 assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Today + ' + i + ' days beginning of day'); | |
14813 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
14814 assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Today + ' + i + ' days end of day'); | |
14815 } | |
14816 }); | |
14817 | |
14818 test('calendar last week', function (assert) { | |
14819 var i, m; | |
14820 for (i = 2; i < 7; i++) { | |
14821 m = moment().subtract({d: i}); | |
14822 assert.equal(m.calendar(), m.format('dddd [lalu pukul] LT'), 'Today - ' + i + ' days current time'); | |
14823 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
14824 assert.equal(m.calendar(), m.format('dddd [lalu pukul] LT'), 'Today - ' + i + ' days beginning of day'); | |
14825 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
14826 assert.equal(m.calendar(), m.format('dddd [lalu pukul] LT'), 'Today - ' + i + ' days end of day'); | |
14827 } | |
14828 }); | |
14829 | |
14830 test('calendar all else', function (assert) { | |
14831 var weeksAgo = moment().subtract({w: 1}), | |
14832 weeksFromNow = moment().add({w: 1}); | |
14833 | |
14834 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
14835 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
14836 | |
14837 weeksAgo = moment().subtract({w: 2}); | |
14838 weeksFromNow = moment().add({w: 2}); | |
14839 | |
14840 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
14841 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
14842 }); | |
14843 | |
14844 test('weeks year starting sunday', function (assert) { | |
14845 assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1'); | |
14846 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
14847 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2'); | |
14848 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
14849 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3'); | |
14850 }); | |
14851 | |
14852 test('weeks year starting monday', function (assert) { | |
14853 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
14854 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
14855 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
14856 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
14857 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
14858 }); | |
14859 | |
14860 test('weeks year starting tuesday', function (assert) { | |
14861 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
14862 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
14863 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
14864 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
14865 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
14866 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
14867 }); | |
14868 | |
14869 test('weeks year starting wednesday', function (assert) { | |
14870 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
14871 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
14872 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
14873 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
14874 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
14875 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
14876 }); | |
14877 | |
14878 test('weeks year starting thursday', function (assert) { | |
14879 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
14880 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
14881 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
14882 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
14883 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
14884 assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3'); | |
14885 }); | |
14886 | |
14887 test('weeks year starting friday', function (assert) { | |
14888 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1'); | |
14889 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
14890 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1'); | |
14891 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2'); | |
14892 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2'); | |
14893 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3'); | |
14894 }); | |
14895 | |
14896 test('weeks year starting saturday', function (assert) { | |
14897 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1'); | |
14898 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
14899 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1'); | |
14900 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2'); | |
14901 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2'); | |
14902 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3'); | |
14903 }); | |
14904 | |
14905 test('weeks year starting sunday formatted', function (assert) { | |
14906 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1', 'Dec 26 2011 should be week 1'); | |
14907 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1'); | |
14908 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2', 'Jan 2 2012 should be week 2'); | |
14909 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2'); | |
14910 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3', 'Jan 9 2012 should be week 3'); | |
14911 }); | |
14912 | |
14913 test('lenient ordinal parsing', function (assert) { | |
14914 var i, ordinalStr, testMoment; | |
14915 for (i = 1; i <= 31; ++i) { | |
14916 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
14917 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
14918 assert.equal(testMoment.year(), 2014, | |
14919 'lenient ordinal parsing ' + i + ' year check'); | |
14920 assert.equal(testMoment.month(), 0, | |
14921 'lenient ordinal parsing ' + i + ' month check'); | |
14922 assert.equal(testMoment.date(), i, | |
14923 'lenient ordinal parsing ' + i + ' date check'); | |
14924 } | |
14925 }); | |
14926 | |
14927 test('lenient ordinal parsing of number', function (assert) { | |
14928 var i, testMoment; | |
14929 for (i = 1; i <= 31; ++i) { | |
14930 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
14931 assert.equal(testMoment.year(), 2014, | |
14932 'lenient ordinal parsing of number ' + i + ' year check'); | |
14933 assert.equal(testMoment.month(), 0, | |
14934 'lenient ordinal parsing of number ' + i + ' month check'); | |
14935 assert.equal(testMoment.date(), i, | |
14936 'lenient ordinal parsing of number ' + i + ' date check'); | |
14937 } | |
14938 }); | |
14939 | |
14940 test('meridiem invariant', function (assert) { | |
14941 var h, m, t1, t2; | |
14942 for (h = 0; h < 24; ++h) { | |
14943 for (m = 0; m < 60; m += 15) { | |
14944 t1 = moment.utc([2000, 0, 1, h, m]); | |
14945 t2 = moment(t1.format('A h:mm'), 'A h:mm'); | |
14946 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'), | |
14947 'meridiem at ' + t1.format('HH:mm')); | |
14948 } | |
14949 } | |
14950 }); | |
14951 | |
14952 test('strict ordinal parsing', function (assert) { | |
14953 var i, ordinalStr, testMoment; | |
14954 for (i = 1; i <= 31; ++i) { | |
14955 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
14956 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
14957 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
14958 } | |
14959 }); | |
14960 | |
14961 })); | |
14962 | |
14963 (function (global, factory) { | |
14964 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
14965 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
14966 factory(global.moment) | |
14967 }(this, function (moment) { 'use strict'; | |
14968 | |
14969 /*global QUnit:false*/ | |
14970 | |
14971 var test = QUnit.test; | |
14972 | |
14973 function module (name, lifecycle) { | |
14974 QUnit.module(name, { | |
14975 setup : function () { | |
14976 moment.locale('en'); | |
14977 moment.createFromInputFallback = function () { | |
14978 throw new Error('input not handled by moment'); | |
14979 }; | |
14980 if (lifecycle && lifecycle.setup) { | |
14981 lifecycle.setup(); | |
14982 } | |
14983 }, | |
14984 teardown : function () { | |
14985 if (lifecycle && lifecycle.teardown) { | |
14986 lifecycle.teardown(); | |
14987 } | |
14988 } | |
14989 }); | |
14990 } | |
14991 | |
14992 function localeModule (name, lifecycle) { | |
14993 QUnit.module('locale:' + name, { | |
14994 setup : function () { | |
14995 moment.locale(name); | |
14996 moment.createFromInputFallback = function () { | |
14997 throw new Error('input not handled by moment'); | |
14998 }; | |
14999 if (lifecycle && lifecycle.setup) { | |
15000 lifecycle.setup(); | |
15001 } | |
15002 }, | |
15003 teardown : function () { | |
15004 moment.locale('en'); | |
15005 if (lifecycle && lifecycle.teardown) { | |
15006 lifecycle.teardown(); | |
15007 } | |
15008 } | |
15009 }); | |
15010 } | |
15011 | |
15012 localeModule('is'); | |
15013 | |
15014 test('parse', function (assert) { | |
15015 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; | |
15016 function equalTest(input, mmm, i) { | |
15017 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
15018 } | |
15019 for (i = 0; i < 12; i++) { | |
15020 tests[i] = tests[i].split(' '); | |
15021 equalTest(tests[i][0], 'MMM', i); | |
15022 equalTest(tests[i][1], 'MMM', i); | |
15023 equalTest(tests[i][0], 'MMMM', i); | |
15024 equalTest(tests[i][1], 'MMMM', i); | |
15025 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
15026 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
15027 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
15028 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
15029 } | |
15030 }); | |
15031 | |
15032 test('format', function (assert) { | |
15033 var a = [ | |
15034 ['dddd, Do MMMM YYYY, h:mm:ss a', 'sunnudagur, 14. febrúar 2010, 3:25:50 pm'], | |
15035 ['ddd, hA', 'sun, 3PM'], | |
15036 ['M Mo MM MMMM MMM', '2 2. 02 febrúar feb'], | |
15037 ['YYYY YY', '2010 10'], | |
15038 ['D Do DD', '14 14. 14'], | |
15039 ['d do dddd ddd dd', '0 0. sunnudagur sun Su'], | |
15040 ['DDD DDDo DDDD', '45 45. 045'], | |
15041 ['w wo ww', '6 6. 06'], | |
15042 ['h hh', '3 03'], | |
15043 ['H HH', '15 15'], | |
15044 ['m mm', '25 25'], | |
15045 ['s ss', '50 50'], | |
15046 ['a A', 'pm PM'], | |
15047 ['[the] DDDo [day of the year]', 'the 45. day of the year'], | |
15048 ['LTS', '15:25:50'], | |
15049 ['L', '14/02/2010'], | |
15050 ['LL', '14. febrúar 2010'], | |
15051 ['LLL', '14. febrúar 2010 kl. 15:25'], | |
15052 ['LLLL', 'sunnudagur, 14. febrúar 2010 kl. 15:25'], | |
15053 ['l', '14/2/2010'], | |
15054 ['ll', '14. feb 2010'], | |
15055 ['lll', '14. feb 2010 kl. 15:25'], | |
15056 ['llll', 'sun, 14. feb 2010 kl. 15:25'] | |
15057 ], | |
15058 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
15059 i; | |
15060 for (i = 0; i < a.length; i++) { | |
15061 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
15062 } | |
15063 }); | |
15064 | |
15065 test('format ordinal', function (assert) { | |
15066 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.'); | |
15067 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.'); | |
15068 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.'); | |
15069 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.'); | |
15070 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.'); | |
15071 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.'); | |
15072 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.'); | |
15073 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.'); | |
15074 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.'); | |
15075 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.'); | |
15076 | |
15077 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.'); | |
15078 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.'); | |
15079 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.'); | |
15080 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.'); | |
15081 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.'); | |
15082 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.'); | |
15083 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.'); | |
15084 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.'); | |
15085 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.'); | |
15086 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.'); | |
15087 | |
15088 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.'); | |
15089 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.'); | |
15090 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.'); | |
15091 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.'); | |
15092 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.'); | |
15093 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.'); | |
15094 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.'); | |
15095 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.'); | |
15096 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.'); | |
15097 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.'); | |
15098 | |
15099 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.'); | |
15100 }); | |
15101 | |
15102 test('format month', function (assert) { | |
15103 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; | |
15104 for (i = 0; i < expected.length; i++) { | |
15105 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
15106 } | |
15107 }); | |
15108 | |
15109 test('format week', function (assert) { | |
15110 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; | |
15111 for (i = 0; i < expected.length; i++) { | |
15112 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
15113 } | |
15114 }); | |
15115 | |
15116 test('from', function (assert) { | |
15117 var start = moment([2007, 1, 28]); | |
15118 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'nokkrar sekúndur', '44 seconds = a few seconds'); | |
15119 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'mínúta', '45 seconds = a minute'); | |
15120 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'mínúta', '89 seconds = a minute'); | |
15121 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 mínútur', '90 seconds = 2 minutes'); | |
15122 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 mínútur', '44 minutes = 44 minutes'); | |
15123 assert.equal(start.from(moment([2007, 1, 28]).add({m: 21}), true), '21 mínúta', '21 minutes = 21 minutes'); | |
15124 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'klukkustund', '45 minutes = an hour'); | |
15125 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'klukkustund', '89 minutes = an hour'); | |
15126 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 klukkustundir', '90 minutes = 2 hours'); | |
15127 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 klukkustundir', '5 hours = 5 hours'); | |
15128 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 klukkustund', '21 hours = 21 hours'); | |
15129 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'dagur', '22 hours = a day'); | |
15130 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'dagur', '35 hours = a day'); | |
15131 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dagar', '36 hours = 2 days'); | |
15132 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'dagur', '1 day = a day'); | |
15133 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dagar', '5 days = 5 days'); | |
15134 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dagar', '25 days = 25 days'); | |
15135 assert.equal(start.from(moment([2007, 1, 28]).add({d: 11}), true), '11 dagar', '11 days = 11 days'); | |
15136 assert.equal(start.from(moment([2007, 1, 28]).add({d: 21}), true), '21 dagur', '21 days = 21 days'); | |
15137 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mánuður', '26 days = a month'); | |
15138 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mánuður', '30 days = a month'); | |
15139 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mánuður', '43 days = a month'); | |
15140 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mánuðir', '46 days = 2 months'); | |
15141 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mánuðir', '75 days = 2 months'); | |
15142 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mánuðir', '76 days = 3 months'); | |
15143 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mánuður', '1 month = a month'); | |
15144 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mánuðir', '5 months = 5 months'); | |
15145 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ár', '345 days = a year'); | |
15146 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ár', '548 days = 2 years'); | |
15147 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ár', '1 year = a year'); | |
15148 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ár', '5 years = 5 years'); | |
15149 assert.equal(start.from(moment([2007, 1, 28]).add({y: 21}), true), '21 ár', '21 years = 21 years'); | |
15150 }); | |
15151 | |
15152 test('suffix', function (assert) { | |
15153 assert.equal(moment(30000).from(0), 'eftir nokkrar sekúndur', 'prefix'); | |
15154 assert.equal(moment(0).from(30000), 'fyrir nokkrum sekúndum síðan', 'suffix'); | |
15155 assert.equal(moment().subtract({m: 1}).fromNow(), 'fyrir mínútu síðan', 'a minute ago'); | |
15156 }); | |
15157 | |
15158 test('now from now', function (assert) { | |
15159 assert.equal(moment().fromNow(), 'fyrir nokkrum sekúndum síðan', 'now from now should display as in the past'); | |
15160 }); | |
15161 | |
15162 test('fromNow', function (assert) { | |
15163 assert.equal(moment().add({s: 30}).fromNow(), 'eftir nokkrar sekúndur', 'in a few seconds'); | |
15164 assert.equal(moment().add({m: 1}).fromNow(), 'eftir mínútu', 'in a minute'); | |
15165 assert.equal(moment().add({d: 5}).fromNow(), 'eftir 5 daga', 'in 5 days'); | |
15166 }); | |
15167 | |
15168 test('calendar day', function (assert) { | |
15169 var a = moment().hours(2).minutes(0).seconds(0); | |
15170 | |
15171 assert.equal(moment(a).calendar(), 'í dag kl. 2:00', 'today at the same time'); | |
15172 assert.equal(moment(a).add({m: 25}).calendar(), 'í dag kl. 2:25', 'Now plus 25 min'); | |
15173 assert.equal(moment(a).add({h: 1}).calendar(), 'í dag kl. 3:00', 'Now plus 1 hour'); | |
15174 assert.equal(moment(a).add({d: 1}).calendar(), 'á morgun kl. 2:00', 'tomorrow at the same time'); | |
15175 assert.equal(moment(a).subtract({h: 1}).calendar(), 'í dag kl. 1:00', 'Now minus 1 hour'); | |
15176 assert.equal(moment(a).subtract({d: 1}).calendar(), 'í gær kl. 2:00', 'yesterday at the same time'); | |
15177 }); | |
15178 | |
15179 test('calendar next week', function (assert) { | |
15180 var i, m; | |
15181 for (i = 2; i < 7; i++) { | |
15182 m = moment().add({d: i}); | |
15183 assert.equal(m.calendar(), m.format('dddd [kl.] LT'), 'Today + ' + i + ' days current time'); | |
15184 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
15185 assert.equal(m.calendar(), m.format('dddd [kl.] LT'), 'Today + ' + i + ' days beginning of day'); | |
15186 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
15187 assert.equal(m.calendar(), m.format('dddd [kl.] LT'), 'Today + ' + i + ' days end of day'); | |
15188 } | |
15189 }); | |
15190 | |
15191 test('calendar last week', function (assert) { | |
15192 var i, m; | |
15193 | |
15194 for (i = 2; i < 7; i++) { | |
15195 m = moment().subtract({d: i}); | |
15196 assert.equal(m.calendar(), m.format('[síðasta] dddd [kl.] LT'), 'Today - ' + i + ' days current time'); | |
15197 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
15198 assert.equal(m.calendar(), m.format('[síðasta] dddd [kl.] LT'), 'Today - ' + i + ' days beginning of day'); | |
15199 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
15200 assert.equal(m.calendar(), m.format('[síðasta] dddd [kl.] LT'), 'Today - ' + i + ' days end of day'); | |
15201 } | |
15202 }); | |
15203 | |
15204 test('calendar all else', function (assert) { | |
15205 var weeksAgo = moment().subtract({w: 1}), | |
15206 weeksFromNow = moment().add({w: 1}); | |
15207 | |
15208 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
15209 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
15210 | |
15211 weeksAgo = moment().subtract({w: 2}); | |
15212 weeksFromNow = moment().add({w: 2}); | |
15213 | |
15214 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
15215 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
15216 }); | |
15217 | |
15218 test('weeks year starting sunday', function (assert) { | |
15219 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
15220 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
15221 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
15222 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
15223 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
15224 }); | |
15225 | |
15226 test('weeks year starting monday', function (assert) { | |
15227 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
15228 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
15229 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
15230 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
15231 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
15232 }); | |
15233 | |
15234 test('weeks year starting tuesday', function (assert) { | |
15235 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
15236 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
15237 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
15238 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
15239 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
15240 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
15241 }); | |
15242 | |
15243 test('weeks year starting wednesday', function (assert) { | |
15244 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
15245 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
15246 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
15247 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
15248 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
15249 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
15250 }); | |
15251 | |
15252 test('weeks year starting thursday', function (assert) { | |
15253 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
15254 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
15255 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
15256 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
15257 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
15258 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
15259 }); | |
15260 | |
15261 test('weeks year starting friday', function (assert) { | |
15262 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
15263 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
15264 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
15265 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
15266 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
15267 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
15268 }); | |
15269 | |
15270 test('weeks year starting saturday', function (assert) { | |
15271 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
15272 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
15273 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
15274 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
15275 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
15276 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
15277 }); | |
15278 | |
15279 test('weeks year starting sunday formatted', function (assert) { | |
15280 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52'); | |
15281 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1'); | |
15282 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1'); | |
15283 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2'); | |
15284 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2'); | |
15285 }); | |
15286 | |
15287 test('lenient ordinal parsing', function (assert) { | |
15288 var i, ordinalStr, testMoment; | |
15289 for (i = 1; i <= 31; ++i) { | |
15290 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
15291 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
15292 assert.equal(testMoment.year(), 2014, | |
15293 'lenient ordinal parsing ' + i + ' year check'); | |
15294 assert.equal(testMoment.month(), 0, | |
15295 'lenient ordinal parsing ' + i + ' month check'); | |
15296 assert.equal(testMoment.date(), i, | |
15297 'lenient ordinal parsing ' + i + ' date check'); | |
15298 } | |
15299 }); | |
15300 | |
15301 test('lenient ordinal parsing of number', function (assert) { | |
15302 var i, testMoment; | |
15303 for (i = 1; i <= 31; ++i) { | |
15304 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
15305 assert.equal(testMoment.year(), 2014, | |
15306 'lenient ordinal parsing of number ' + i + ' year check'); | |
15307 assert.equal(testMoment.month(), 0, | |
15308 'lenient ordinal parsing of number ' + i + ' month check'); | |
15309 assert.equal(testMoment.date(), i, | |
15310 'lenient ordinal parsing of number ' + i + ' date check'); | |
15311 } | |
15312 }); | |
15313 | |
15314 test('strict ordinal parsing', function (assert) { | |
15315 var i, ordinalStr, testMoment; | |
15316 for (i = 1; i <= 31; ++i) { | |
15317 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
15318 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
15319 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
15320 } | |
15321 }); | |
15322 | |
15323 })); | |
15324 | |
15325 (function (global, factory) { | |
15326 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
15327 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
15328 factory(global.moment) | |
15329 }(this, function (moment) { 'use strict'; | |
15330 | |
15331 /*global QUnit:false*/ | |
15332 | |
15333 var test = QUnit.test; | |
15334 | |
15335 function module (name, lifecycle) { | |
15336 QUnit.module(name, { | |
15337 setup : function () { | |
15338 moment.locale('en'); | |
15339 moment.createFromInputFallback = function () { | |
15340 throw new Error('input not handled by moment'); | |
15341 }; | |
15342 if (lifecycle && lifecycle.setup) { | |
15343 lifecycle.setup(); | |
15344 } | |
15345 }, | |
15346 teardown : function () { | |
15347 if (lifecycle && lifecycle.teardown) { | |
15348 lifecycle.teardown(); | |
15349 } | |
15350 } | |
15351 }); | |
15352 } | |
15353 | |
15354 function localeModule (name, lifecycle) { | |
15355 QUnit.module('locale:' + name, { | |
15356 setup : function () { | |
15357 moment.locale(name); | |
15358 moment.createFromInputFallback = function () { | |
15359 throw new Error('input not handled by moment'); | |
15360 }; | |
15361 if (lifecycle && lifecycle.setup) { | |
15362 lifecycle.setup(); | |
15363 } | |
15364 }, | |
15365 teardown : function () { | |
15366 moment.locale('en'); | |
15367 if (lifecycle && lifecycle.teardown) { | |
15368 lifecycle.teardown(); | |
15369 } | |
15370 } | |
15371 }); | |
15372 } | |
15373 | |
15374 localeModule('it'); | |
15375 | |
15376 test('parse', function (assert) { | |
15377 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; | |
15378 function equalTest(input, mmm, i) { | |
15379 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
15380 } | |
15381 for (i = 0; i < 12; i++) { | |
15382 tests[i] = tests[i].split(' '); | |
15383 equalTest(tests[i][0], 'MMM', i); | |
15384 equalTest(tests[i][1], 'MMM', i); | |
15385 equalTest(tests[i][0], 'MMMM', i); | |
15386 equalTest(tests[i][1], 'MMMM', i); | |
15387 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
15388 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
15389 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
15390 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
15391 } | |
15392 }); | |
15393 | |
15394 test('format', function (assert) { | |
15395 var a = [ | |
15396 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Domenica, febbraio 14º 2010, 3:25:50 pm'], | |
15397 ['ddd, hA', 'Dom, 3PM'], | |
15398 ['M Mo MM MMMM MMM', '2 2º 02 febbraio feb'], | |
15399 ['YYYY YY', '2010 10'], | |
15400 ['D Do DD', '14 14º 14'], | |
15401 ['d do dddd ddd dd', '0 0º Domenica Dom D'], | |
15402 ['DDD DDDo DDDD', '45 45º 045'], | |
15403 ['w wo ww', '6 6º 06'], | |
15404 ['h hh', '3 03'], | |
15405 ['H HH', '15 15'], | |
15406 ['m mm', '25 25'], | |
15407 ['s ss', '50 50'], | |
15408 ['a A', 'pm PM'], | |
15409 ['[the] DDDo [day of the year]', 'the 45º day of the year'], | |
15410 ['LTS', '15:25:50'], | |
15411 ['L', '14/02/2010'], | |
15412 ['LL', '14 febbraio 2010'], | |
15413 ['LLL', '14 febbraio 2010 15:25'], | |
15414 ['LLLL', 'Domenica, 14 febbraio 2010 15:25'], | |
15415 ['l', '14/2/2010'], | |
15416 ['ll', '14 feb 2010'], | |
15417 ['lll', '14 feb 2010 15:25'], | |
15418 ['llll', 'Dom, 14 feb 2010 15:25'] | |
15419 ], | |
15420 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
15421 i; | |
15422 for (i = 0; i < a.length; i++) { | |
15423 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
15424 } | |
15425 }); | |
15426 | |
15427 test('format ordinal', function (assert) { | |
15428 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1º', '1º'); | |
15429 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2º', '2º'); | |
15430 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3º', '3º'); | |
15431 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4º', '4º'); | |
15432 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5º', '5º'); | |
15433 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6º', '6º'); | |
15434 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7º', '7º'); | |
15435 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8º', '8º'); | |
15436 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9º', '9º'); | |
15437 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10º', '10º'); | |
15438 | |
15439 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11º', '11º'); | |
15440 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12º', '12º'); | |
15441 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13º', '13º'); | |
15442 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14º', '14º'); | |
15443 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15º', '15º'); | |
15444 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16º', '16º'); | |
15445 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17º', '17º'); | |
15446 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18º', '18º'); | |
15447 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19º', '19º'); | |
15448 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20º', '20º'); | |
15449 | |
15450 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21º', '21º'); | |
15451 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22º', '22º'); | |
15452 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23º', '23º'); | |
15453 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24º', '24º'); | |
15454 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25º', '25º'); | |
15455 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26º', '26º'); | |
15456 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27º', '27º'); | |
15457 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28º', '28º'); | |
15458 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29º', '29º'); | |
15459 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30º', '30º'); | |
15460 | |
15461 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31º', '31º'); | |
15462 }); | |
15463 | |
15464 test('format month', function (assert) { | |
15465 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; | |
15466 for (i = 0; i < expected.length; i++) { | |
15467 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
15468 } | |
15469 }); | |
15470 | |
15471 test('format week', function (assert) { | |
15472 var expected = 'Domenica Dom D_Lunedì Lun L_Martedì Mar Ma_Mercoledì Mer Me_Giovedì Gio G_Venerdì Ven V_Sabato Sab S'.split('_'), i; | |
15473 for (i = 0; i < expected.length; i++) { | |
15474 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
15475 } | |
15476 }); | |
15477 | |
15478 test('from', function (assert) { | |
15479 var start = moment([2007, 1, 28]); | |
15480 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'alcuni secondi', '44 seconds = seconds'); | |
15481 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'un minuto', '45 seconds = a minute'); | |
15482 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'un minuto', '89 seconds = a minute'); | |
15483 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuti', '90 seconds = 2 minutes'); | |
15484 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuti', '44 minutes = 44 minutes'); | |
15485 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'un\'ora', '45 minutes = an hour'); | |
15486 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'un\'ora', '89 minutes = an hour'); | |
15487 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ore', '90 minutes = 2 hours'); | |
15488 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ore', '5 hours = 5 hours'); | |
15489 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ore', '21 hours = 21 hours'); | |
15490 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'un giorno', '22 hours = a day'); | |
15491 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'un giorno', '35 hours = a day'); | |
15492 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 giorni', '36 hours = 2 days'); | |
15493 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'un giorno', '1 day = a day'); | |
15494 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 giorni', '5 days = 5 days'); | |
15495 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 giorni', '25 days = 25 days'); | |
15496 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'un mese', '26 days = a month'); | |
15497 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'un mese', '30 days = a month'); | |
15498 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'un mese', '43 days = a month'); | |
15499 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mesi', '46 days = 2 months'); | |
15500 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mesi', '75 days = 2 months'); | |
15501 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mesi', '76 days = 3 months'); | |
15502 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'un mese', '1 month = a month'); | |
15503 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mesi', '5 months = 5 months'); | |
15504 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un anno', '345 days = a year'); | |
15505 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 anni', '548 days = 2 years'); | |
15506 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un anno', '1 year = a year'); | |
15507 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 anni', '5 years = 5 years'); | |
15508 }); | |
15509 | |
15510 test('suffix', function (assert) { | |
15511 assert.equal(moment(30000).from(0), 'in alcuni secondi', 'prefix'); | |
15512 assert.equal(moment(0).from(30000), 'alcuni secondi fa', 'suffix'); | |
15513 }); | |
15514 | |
15515 test('fromNow', function (assert) { | |
15516 assert.equal(moment().add({s: 30}).fromNow(), 'in alcuni secondi', 'in seconds'); | |
15517 assert.equal(moment().add({d: 5}).fromNow(), 'tra 5 giorni', 'in 5 days'); | |
15518 }); | |
15519 | |
15520 test('calendar day', function (assert) { | |
15521 var a = moment().hours(2).minutes(0).seconds(0); | |
15522 | |
15523 assert.equal(moment(a).calendar(), 'Oggi alle 02:00', 'today at the same time'); | |
15524 assert.equal(moment(a).add({m: 25}).calendar(), 'Oggi alle 02:25', 'Now plus 25 min'); | |
15525 assert.equal(moment(a).add({h: 1}).calendar(), 'Oggi alle 03:00', 'Now plus 1 hour'); | |
15526 assert.equal(moment(a).add({d: 1}).calendar(), 'Domani alle 02:00', 'tomorrow at the same time'); | |
15527 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Oggi alle 01:00', 'Now minus 1 hour'); | |
15528 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Ieri alle 02:00', 'yesterday at the same time'); | |
15529 }); | |
15530 | |
15531 test('calendar next week', function (assert) { | |
15532 var i, m; | |
15533 for (i = 2; i < 7; i++) { | |
15534 m = moment().add({d: i}); | |
15535 assert.equal(m.calendar(), m.format('dddd [alle] LT'), 'Today + ' + i + ' days current time'); | |
15536 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
15537 assert.equal(m.calendar(), m.format('dddd [alle] LT'), 'Today + ' + i + ' days beginning of day'); | |
15538 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
15539 assert.equal(m.calendar(), m.format('dddd [alle] LT'), 'Today + ' + i + ' days end of day'); | |
15540 } | |
15541 }); | |
15542 | |
15543 test('calendar last week', function (assert) { | |
15544 var i, m, weekday, datestring; | |
15545 for (i = 2; i < 7; i++) { | |
15546 m = moment().subtract({d: i}); | |
15547 // Different date string | |
15548 weekday = parseInt(m.format('d'), 10); | |
15549 datestring = (weekday === 0) ? '[la scorsa] dddd [alle] LT' : '[lo scorso] dddd [alle] LT'; | |
15550 assert.equal(m.calendar(), m.format(datestring), 'Today - ' + i + ' days current time'); | |
15551 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
15552 assert.equal(m.calendar(), m.format(datestring), 'Today - ' + i + ' days beginning of day'); | |
15553 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
15554 assert.equal(m.calendar(), m.format(datestring), 'Today - ' + i + ' days end of day'); | |
15555 } | |
15556 }); | |
15557 | |
15558 test('calendar all else', function (assert) { | |
15559 var weeksAgo = moment().subtract({w: 1}), | |
15560 weeksFromNow = moment().add({w: 1}); | |
15561 | |
15562 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
15563 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
15564 | |
15565 weeksAgo = moment().subtract({w: 2}); | |
15566 weeksFromNow = moment().add({w: 2}); | |
15567 | |
15568 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
15569 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
15570 }); | |
15571 | |
15572 test('weeks year starting sunday', function (assert) { | |
15573 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
15574 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
15575 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
15576 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
15577 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
15578 }); | |
15579 | |
15580 test('weeks year starting monday', function (assert) { | |
15581 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
15582 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
15583 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
15584 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
15585 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
15586 }); | |
15587 | |
15588 test('weeks year starting tuesday', function (assert) { | |
15589 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
15590 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
15591 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
15592 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
15593 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
15594 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
15595 }); | |
15596 | |
15597 test('weeks year starting wednesday', function (assert) { | |
15598 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
15599 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
15600 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
15601 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
15602 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
15603 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
15604 }); | |
15605 | |
15606 test('weeks year starting thursday', function (assert) { | |
15607 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
15608 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
15609 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
15610 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
15611 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
15612 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
15613 }); | |
15614 | |
15615 test('weeks year starting friday', function (assert) { | |
15616 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
15617 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
15618 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
15619 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
15620 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
15621 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
15622 }); | |
15623 | |
15624 test('weeks year starting saturday', function (assert) { | |
15625 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
15626 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
15627 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
15628 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
15629 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
15630 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
15631 }); | |
15632 | |
15633 test('weeks year starting sunday formatted', function (assert) { | |
15634 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52º', 'Jan 1 2012 should be week 52'); | |
15635 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1º', 'Jan 2 2012 should be week 1'); | |
15636 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1º', 'Jan 8 2012 should be week 1'); | |
15637 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2º', 'Jan 9 2012 should be week 2'); | |
15638 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2º', 'Jan 15 2012 should be week 2'); | |
15639 }); | |
15640 | |
15641 test('lenient ordinal parsing', function (assert) { | |
15642 var i, ordinalStr, testMoment; | |
15643 for (i = 1; i <= 31; ++i) { | |
15644 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
15645 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
15646 assert.equal(testMoment.year(), 2014, | |
15647 'lenient ordinal parsing ' + i + ' year check'); | |
15648 assert.equal(testMoment.month(), 0, | |
15649 'lenient ordinal parsing ' + i + ' month check'); | |
15650 assert.equal(testMoment.date(), i, | |
15651 'lenient ordinal parsing ' + i + ' date check'); | |
15652 } | |
15653 }); | |
15654 | |
15655 test('lenient ordinal parsing of number', function (assert) { | |
15656 var i, testMoment; | |
15657 for (i = 1; i <= 31; ++i) { | |
15658 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
15659 assert.equal(testMoment.year(), 2014, | |
15660 'lenient ordinal parsing of number ' + i + ' year check'); | |
15661 assert.equal(testMoment.month(), 0, | |
15662 'lenient ordinal parsing of number ' + i + ' month check'); | |
15663 assert.equal(testMoment.date(), i, | |
15664 'lenient ordinal parsing of number ' + i + ' date check'); | |
15665 } | |
15666 }); | |
15667 | |
15668 test('strict ordinal parsing', function (assert) { | |
15669 var i, ordinalStr, testMoment; | |
15670 for (i = 1; i <= 31; ++i) { | |
15671 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
15672 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
15673 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
15674 } | |
15675 }); | |
15676 | |
15677 })); | |
15678 | |
15679 (function (global, factory) { | |
15680 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
15681 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
15682 factory(global.moment) | |
15683 }(this, function (moment) { 'use strict'; | |
15684 | |
15685 /*global QUnit:false*/ | |
15686 | |
15687 var test = QUnit.test; | |
15688 | |
15689 function module (name, lifecycle) { | |
15690 QUnit.module(name, { | |
15691 setup : function () { | |
15692 moment.locale('en'); | |
15693 moment.createFromInputFallback = function () { | |
15694 throw new Error('input not handled by moment'); | |
15695 }; | |
15696 if (lifecycle && lifecycle.setup) { | |
15697 lifecycle.setup(); | |
15698 } | |
15699 }, | |
15700 teardown : function () { | |
15701 if (lifecycle && lifecycle.teardown) { | |
15702 lifecycle.teardown(); | |
15703 } | |
15704 } | |
15705 }); | |
15706 } | |
15707 | |
15708 function localeModule (name, lifecycle) { | |
15709 QUnit.module('locale:' + name, { | |
15710 setup : function () { | |
15711 moment.locale(name); | |
15712 moment.createFromInputFallback = function () { | |
15713 throw new Error('input not handled by moment'); | |
15714 }; | |
15715 if (lifecycle && lifecycle.setup) { | |
15716 lifecycle.setup(); | |
15717 } | |
15718 }, | |
15719 teardown : function () { | |
15720 moment.locale('en'); | |
15721 if (lifecycle && lifecycle.teardown) { | |
15722 lifecycle.teardown(); | |
15723 } | |
15724 } | |
15725 }); | |
15726 } | |
15727 | |
15728 localeModule('ja'); | |
15729 | |
15730 test('parse', function (assert) { | |
15731 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; | |
15732 function equalTest(input, mmm, i) { | |
15733 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
15734 } | |
15735 for (i = 0; i < 12; i++) { | |
15736 tests[i] = tests[i].split(' '); | |
15737 equalTest(tests[i][0], 'MMM', i); | |
15738 equalTest(tests[i][1], 'MMM', i); | |
15739 equalTest(tests[i][0], 'MMMM', i); | |
15740 equalTest(tests[i][1], 'MMMM', i); | |
15741 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
15742 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
15743 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
15744 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
15745 } | |
15746 }); | |
15747 | |
15748 test('format', function (assert) { | |
15749 var a = [ | |
15750 ['dddd, MMMM Do YYYY, a h:mm:ss', '日曜日, 2月 14 2010, 午後 3:25:50'], | |
15751 ['ddd, Ah', '日, 午後3'], | |
15752 ['M Mo MM MMMM MMM', '2 2 02 2月 2月'], | |
15753 ['YYYY YY', '2010 10'], | |
15754 ['D Do DD', '14 14 14'], | |
15755 ['d do dddd ddd dd', '0 0 日曜日 日 日'], | |
15756 ['DDD DDDo DDDD', '45 45 045'], | |
15757 ['w wo ww', '8 8 08'], | |
15758 ['h hh', '3 03'], | |
15759 ['H HH', '15 15'], | |
15760 ['m mm', '25 25'], | |
15761 ['s ss', '50 50'], | |
15762 ['a A', '午後 午後'], | |
15763 ['[the] DDDo [day of the year]', 'the 45 day of the year'], | |
15764 ['LTS', '午後3時25分50秒'], | |
15765 ['L', '2010/02/14'], | |
15766 ['LL', '2010年2月14日'], | |
15767 ['LLL', '2010年2月14日午後3時25分'], | |
15768 ['LLLL', '2010年2月14日午後3時25分 日曜日'], | |
15769 ['l', '2010/2/14'], | |
15770 ['ll', '2010年2月14日'], | |
15771 ['lll', '2010年2月14日午後3時25分'], | |
15772 ['llll', '2010年2月14日午後3時25分 日'] | |
15773 ], | |
15774 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
15775 i; | |
15776 for (i = 0; i < a.length; i++) { | |
15777 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
15778 } | |
15779 }); | |
15780 | |
15781 test('format month', function (assert) { | |
15782 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; | |
15783 for (i = 0; i < expected.length; i++) { | |
15784 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
15785 } | |
15786 }); | |
15787 | |
15788 test('format week', function (assert) { | |
15789 var expected = '日曜日 日 日_月曜日 月 月_火曜日 火 火_水曜日 水 水_木曜日 木 木_金曜日 金 金_土曜日 土 土'.split('_'), i; | |
15790 for (i = 0; i < expected.length; i++) { | |
15791 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
15792 } | |
15793 }); | |
15794 | |
15795 test('from', function (assert) { | |
15796 var start = moment([2007, 1, 28]); | |
15797 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), '数秒', '44 seconds = a few seconds'); | |
15798 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '1分', '45 seconds = a minute'); | |
15799 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '1分', '89 seconds = a minute'); | |
15800 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2分', '90 seconds = 2 minutes'); | |
15801 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44分', '44 minutes = 44 minutes'); | |
15802 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '1時間', '45 minutes = an hour'); | |
15803 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '1時間', '89 minutes = an hour'); | |
15804 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2時間', '90 minutes = 2 hours'); | |
15805 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5時間', '5 hours = 5 hours'); | |
15806 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21時間', '21 hours = 21 hours'); | |
15807 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '1日', '22 hours = a day'); | |
15808 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '1日', '35 hours = a day'); | |
15809 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2日', '36 hours = 2 days'); | |
15810 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '1日', '1 day = a day'); | |
15811 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5日', '5 days = 5 days'); | |
15812 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25日', '25 days = 25 days'); | |
15813 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '1ヶ月', '26 days = a month'); | |
15814 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '1ヶ月', '30 days = a month'); | |
15815 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '1ヶ月', '43 days = a month'); | |
15816 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2ヶ月', '46 days = 2 months'); | |
15817 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2ヶ月', '75 days = 2 months'); | |
15818 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3ヶ月', '76 days = 3 months'); | |
15819 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '1ヶ月', '1 month = a month'); | |
15820 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5ヶ月', '5 months = 5 months'); | |
15821 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '1年', '345 days = a year'); | |
15822 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2年', '548 days = 2 years'); | |
15823 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '1年', '1 year = a year'); | |
15824 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5年', '5 years = 5 years'); | |
15825 }); | |
15826 | |
15827 test('suffix', function (assert) { | |
15828 assert.equal(moment(30000).from(0), '数秒後', 'prefix'); | |
15829 assert.equal(moment(0).from(30000), '数秒前', 'suffix'); | |
15830 }); | |
15831 | |
15832 test('now from now', function (assert) { | |
15833 assert.equal(moment().fromNow(), '数秒前', 'now from now should display as in the past'); | |
15834 }); | |
15835 | |
15836 test('fromNow', function (assert) { | |
15837 assert.equal(moment().add({s: 30}).fromNow(), '数秒後', 'in a few seconds'); | |
15838 assert.equal(moment().add({d: 5}).fromNow(), '5日後', 'in 5 days'); | |
15839 }); | |
15840 | |
15841 test('calendar day', function (assert) { | |
15842 var a = moment().hours(2).minutes(0).seconds(0); | |
15843 | |
15844 assert.equal(moment(a).calendar(), '今日 午前2時0分', 'today at the same time'); | |
15845 assert.equal(moment(a).add({m: 25}).calendar(), '今日 午前2時25分', 'Now plus 25 min'); | |
15846 assert.equal(moment(a).add({h: 1}).calendar(), '今日 午前3時0分', 'Now plus 1 hour'); | |
15847 assert.equal(moment(a).add({d: 1}).calendar(), '明日 午前2時0分', 'tomorrow at the same time'); | |
15848 assert.equal(moment(a).subtract({h: 1}).calendar(), '今日 午前1時0分', 'Now minus 1 hour'); | |
15849 assert.equal(moment(a).subtract({d: 1}).calendar(), '昨日 午前2時0分', 'yesterday at the same time'); | |
15850 }); | |
15851 | |
15852 test('calendar next week', function (assert) { | |
15853 var i, m; | |
15854 for (i = 2; i < 7; i++) { | |
15855 m = moment().add({d: i}); | |
15856 assert.equal(m.calendar(), m.format('[来週]dddd LT'), 'Today + ' + i + ' days current time'); | |
15857 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
15858 assert.equal(m.calendar(), m.format('[来週]dddd LT'), 'Today + ' + i + ' days beginning of day'); | |
15859 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
15860 assert.equal(m.calendar(), m.format('[来週]dddd LT'), 'Today + ' + i + ' days end of day'); | |
15861 } | |
15862 }); | |
15863 | |
15864 test('calendar last week', function (assert) { | |
15865 var i, m; | |
15866 for (i = 2; i < 7; i++) { | |
15867 m = moment().subtract({d: i}); | |
15868 assert.equal(m.calendar(), m.format('[前週]dddd LT'), 'Today - ' + i + ' days current time'); | |
15869 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
15870 assert.equal(m.calendar(), m.format('[前週]dddd LT'), 'Today - ' + i + ' days beginning of day'); | |
15871 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
15872 assert.equal(m.calendar(), m.format('[前週]dddd LT'), 'Today - ' + i + ' days end of day'); | |
15873 } | |
15874 }); | |
15875 | |
15876 test('calendar all else', function (assert) { | |
15877 var weeksAgo = moment().subtract({w: 1}), | |
15878 weeksFromNow = moment().add({w: 1}); | |
15879 | |
15880 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
15881 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
15882 | |
15883 weeksAgo = moment().subtract({w: 2}); | |
15884 weeksFromNow = moment().add({w: 2}); | |
15885 | |
15886 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
15887 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
15888 }); | |
15889 | |
15890 test('weeks year starting sunday', function (assert) { | |
15891 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
15892 assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1'); | |
15893 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
15894 assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2'); | |
15895 assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3'); | |
15896 }); | |
15897 | |
15898 test('weeks year starting monday', function (assert) { | |
15899 assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1'); | |
15900 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
15901 assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1'); | |
15902 assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2'); | |
15903 assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2'); | |
15904 assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3'); | |
15905 }); | |
15906 | |
15907 test('weeks year starting tuesday', function (assert) { | |
15908 assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52'); | |
15909 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
15910 assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1'); | |
15911 assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2'); | |
15912 assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2'); | |
15913 assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3'); | |
15914 }); | |
15915 | |
15916 test('weeks year starting wednesday', function (assert) { | |
15917 assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1'); | |
15918 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
15919 assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1'); | |
15920 assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2'); | |
15921 assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2'); | |
15922 assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3'); | |
15923 }); | |
15924 | |
15925 test('weeks year starting thursday', function (assert) { | |
15926 assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1'); | |
15927 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
15928 assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1'); | |
15929 assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2'); | |
15930 assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2'); | |
15931 assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3'); | |
15932 }); | |
15933 | |
15934 test('weeks year starting friday', function (assert) { | |
15935 assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1'); | |
15936 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
15937 assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1'); | |
15938 assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2'); | |
15939 assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2'); | |
15940 assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3'); | |
15941 }); | |
15942 | |
15943 test('weeks year starting saturday', function (assert) { | |
15944 assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1'); | |
15945 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
15946 assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2'); | |
15947 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2'); | |
15948 assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3'); | |
15949 }); | |
15950 | |
15951 test('weeks year starting sunday format', function (assert) { | |
15952 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1'); | |
15953 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1', 'Jan 7 2012 should be week 1'); | |
15954 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2'); | |
15955 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2', 'Jan 14 2012 should be week 2'); | |
15956 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', 'Jan 15 2012 should be week 3'); | |
15957 }); | |
15958 | |
15959 test('lenient ordinal parsing', function (assert) { | |
15960 var i, ordinalStr, testMoment; | |
15961 for (i = 1; i <= 31; ++i) { | |
15962 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
15963 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
15964 assert.equal(testMoment.year(), 2014, | |
15965 'lenient ordinal parsing ' + i + ' year check'); | |
15966 assert.equal(testMoment.month(), 0, | |
15967 'lenient ordinal parsing ' + i + ' month check'); | |
15968 assert.equal(testMoment.date(), i, | |
15969 'lenient ordinal parsing ' + i + ' date check'); | |
15970 } | |
15971 }); | |
15972 | |
15973 test('lenient ordinal parsing of number', function (assert) { | |
15974 var i, testMoment; | |
15975 for (i = 1; i <= 31; ++i) { | |
15976 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
15977 assert.equal(testMoment.year(), 2014, | |
15978 'lenient ordinal parsing of number ' + i + ' year check'); | |
15979 assert.equal(testMoment.month(), 0, | |
15980 'lenient ordinal parsing of number ' + i + ' month check'); | |
15981 assert.equal(testMoment.date(), i, | |
15982 'lenient ordinal parsing of number ' + i + ' date check'); | |
15983 } | |
15984 }); | |
15985 | |
15986 test('strict ordinal parsing', function (assert) { | |
15987 var i, ordinalStr, testMoment; | |
15988 for (i = 1; i <= 31; ++i) { | |
15989 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
15990 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
15991 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
15992 } | |
15993 }); | |
15994 | |
15995 })); | |
15996 | |
15997 (function (global, factory) { | |
15998 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
15999 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
16000 factory(global.moment) | |
16001 }(this, function (moment) { 'use strict'; | |
16002 | |
16003 /*global QUnit:false*/ | |
16004 | |
16005 var test = QUnit.test; | |
16006 | |
16007 function module (name, lifecycle) { | |
16008 QUnit.module(name, { | |
16009 setup : function () { | |
16010 moment.locale('en'); | |
16011 moment.createFromInputFallback = function () { | |
16012 throw new Error('input not handled by moment'); | |
16013 }; | |
16014 if (lifecycle && lifecycle.setup) { | |
16015 lifecycle.setup(); | |
16016 } | |
16017 }, | |
16018 teardown : function () { | |
16019 if (lifecycle && lifecycle.teardown) { | |
16020 lifecycle.teardown(); | |
16021 } | |
16022 } | |
16023 }); | |
16024 } | |
16025 | |
16026 function localeModule (name, lifecycle) { | |
16027 QUnit.module('locale:' + name, { | |
16028 setup : function () { | |
16029 moment.locale(name); | |
16030 moment.createFromInputFallback = function () { | |
16031 throw new Error('input not handled by moment'); | |
16032 }; | |
16033 if (lifecycle && lifecycle.setup) { | |
16034 lifecycle.setup(); | |
16035 } | |
16036 }, | |
16037 teardown : function () { | |
16038 moment.locale('en'); | |
16039 if (lifecycle && lifecycle.teardown) { | |
16040 lifecycle.teardown(); | |
16041 } | |
16042 } | |
16043 }); | |
16044 } | |
16045 | |
16046 localeModule('jv'); | |
16047 | |
16048 | |
16049 test('parse', function (assert) { | |
16050 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; | |
16051 function equalTest(input, mmm, i) { | |
16052 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
16053 } | |
16054 for (i = 0; i < 12; i++) { | |
16055 tests[i] = tests[i].split(' '); | |
16056 equalTest(tests[i][0], 'MMM', i); | |
16057 equalTest(tests[i][1], 'MMM', i); | |
16058 equalTest(tests[i][0], 'MMMM', i); | |
16059 equalTest(tests[i][1], 'MMMM', i); | |
16060 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
16061 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
16062 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
16063 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
16064 } | |
16065 }); | |
16066 | |
16067 test('format', function (assert) { | |
16068 var a = [ | |
16069 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Minggu, Februari 14 2010, 3:25:50 sonten'], | |
16070 ['ddd, hA', 'Min, 3sonten'], | |
16071 ['M Mo MM MMMM MMM', '2 2 02 Februari Feb'], | |
16072 ['YYYY YY', '2010 10'], | |
16073 ['D Do DD', '14 14 14'], | |
16074 ['d do dddd ddd dd', '0 0 Minggu Min Mg'], | |
16075 ['DDD DDDo DDDD', '45 45 045'], | |
16076 ['w wo ww', '7 7 07'], | |
16077 ['h hh', '3 03'], | |
16078 ['H HH', '15 15'], | |
16079 ['m mm', '25 25'], | |
16080 ['s ss', '50 50'], | |
16081 ['a A', 'sonten sonten'], | |
16082 ['[the] DDDo [day of the year]', 'the 45 day of the year'], | |
16083 ['LTS', '15.25.50'], | |
16084 ['L', '14/02/2010'], | |
16085 ['LL', '14 Februari 2010'], | |
16086 ['LLL', '14 Februari 2010 pukul 15.25'], | |
16087 ['LLLL', 'Minggu, 14 Februari 2010 pukul 15.25'], | |
16088 ['l', '14/2/2010'], | |
16089 ['ll', '14 Feb 2010'], | |
16090 ['lll', '14 Feb 2010 pukul 15.25'], | |
16091 ['llll', 'Min, 14 Feb 2010 pukul 15.25'] | |
16092 ], | |
16093 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
16094 i; | |
16095 for (i = 0; i < a.length; i++) { | |
16096 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
16097 } | |
16098 }); | |
16099 | |
16100 test('format month', function (assert) { | |
16101 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; | |
16102 for (i = 0; i < expected.length; i++) { | |
16103 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
16104 } | |
16105 }); | |
16106 | |
16107 test('format week', function (assert) { | |
16108 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; | |
16109 for (i = 0; i < expected.length; i++) { | |
16110 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
16111 } | |
16112 }); | |
16113 | |
16114 test('from', function (assert) { | |
16115 var start = moment([2007, 1, 28]); | |
16116 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'sawetawis detik', '44 seconds = a few seconds'); | |
16117 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'setunggal menit', '45 seconds = a minute'); | |
16118 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'setunggal menit', '89 seconds = a minute'); | |
16119 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 menit', '90 seconds = 2 minutes'); | |
16120 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 menit', '44 minutes = 44 minutes'); | |
16121 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'setunggal jam', '45 minutes = an hour'); | |
16122 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'setunggal jam', '89 minutes = an hour'); | |
16123 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 jam', '90 minutes = 2 hours'); | |
16124 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 jam', '5 hours = 5 hours'); | |
16125 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 jam', '21 hours = 21 hours'); | |
16126 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'sedinten', '22 hours = a day'); | |
16127 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'sedinten', '35 hours = a day'); | |
16128 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dinten', '36 hours = 2 days'); | |
16129 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'sedinten', '1 day = a day'); | |
16130 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dinten', '5 days = 5 days'); | |
16131 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dinten', '25 days = 25 days'); | |
16132 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'sewulan', '26 days = a month'); | |
16133 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'sewulan', '30 days = a month'); | |
16134 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'sewulan', '43 days = a month'); | |
16135 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 wulan', '46 days = 2 months'); | |
16136 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 wulan', '75 days = 2 months'); | |
16137 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 wulan', '76 days = 3 months'); | |
16138 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'sewulan', '1 month = a month'); | |
16139 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 wulan', '5 months = 5 months'); | |
16140 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'setaun', '345 days = a year'); | |
16141 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 taun', '548 days = 2 years'); | |
16142 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'setaun', '1 year = a year'); | |
16143 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 taun', '5 years = 5 years'); | |
16144 }); | |
16145 | |
16146 test('suffix', function (assert) { | |
16147 assert.equal(moment(30000).from(0), 'wonten ing sawetawis detik', 'prefix'); | |
16148 assert.equal(moment(0).from(30000), 'sawetawis detik ingkang kepengker', 'suffix'); | |
16149 }); | |
16150 | |
16151 test('now from now', function (assert) { | |
16152 assert.equal(moment().fromNow(), 'sawetawis detik ingkang kepengker', 'now from now should display as in the past'); | |
16153 }); | |
16154 | |
16155 test('fromNow', function (assert) { | |
16156 assert.equal(moment().add({s: 30}).fromNow(), 'wonten ing sawetawis detik', 'in a few seconds'); | |
16157 assert.equal(moment().add({d: 5}).fromNow(), 'wonten ing 5 dinten', 'in 5 days'); | |
16158 }); | |
16159 | |
16160 test('calendar day', function (assert) { | |
16161 var a = moment().hours(2).minutes(0).seconds(0); | |
16162 | |
16163 assert.equal(moment(a).calendar(), 'Dinten puniko pukul 02.00', 'today at the same time'); | |
16164 assert.equal(moment(a).add({m: 25}).calendar(), 'Dinten puniko pukul 02.25', 'Now plus 25 min'); | |
16165 assert.equal(moment(a).add({h: 1}).calendar(), 'Dinten puniko pukul 03.00', 'Now plus 1 hour'); | |
16166 assert.equal(moment(a).add({d: 1}).calendar(), 'Mbenjang pukul 02.00', 'tomorrow at the same time'); | |
16167 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Dinten puniko pukul 01.00', 'Now minus 1 hour'); | |
16168 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Kala wingi pukul 02.00', 'yesterday at the same time'); | |
16169 }); | |
16170 | |
16171 test('calendar next week', function (assert) { | |
16172 var i, m; | |
16173 for (i = 2; i < 7; i++) { | |
16174 m = moment().add({d: i}); | |
16175 assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Today + ' + i + ' days current time'); | |
16176 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
16177 assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Today + ' + i + ' days beginning of day'); | |
16178 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
16179 assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Today + ' + i + ' days end of day'); | |
16180 } | |
16181 }); | |
16182 | |
16183 test('calendar last week', function (assert) { | |
16184 var i, m; | |
16185 for (i = 2; i < 7; i++) { | |
16186 m = moment().subtract({d: i}); | |
16187 assert.equal(m.calendar(), m.format('dddd [kepengker pukul] LT'), 'Today - ' + i + ' days current time'); | |
16188 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
16189 assert.equal(m.calendar(), m.format('dddd [kepengker pukul] LT'), 'Today - ' + i + ' days beginning of day'); | |
16190 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
16191 assert.equal(m.calendar(), m.format('dddd [kepengker pukul] LT'), 'Today - ' + i + ' days end of day'); | |
16192 } | |
16193 }); | |
16194 | |
16195 test('calendar all else', function (assert) { | |
16196 var weeksAgo = moment().subtract({w: 1}), | |
16197 weeksFromNow = moment().add({w: 1}); | |
16198 | |
16199 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
16200 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
16201 | |
16202 weeksAgo = moment().subtract({w: 2}); | |
16203 weeksFromNow = moment().add({w: 2}); | |
16204 | |
16205 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
16206 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
16207 }); | |
16208 | |
16209 // Monday is the first day of the week. | |
16210 // The week that contains Jan 1st is the first week of the year. | |
16211 | |
16212 test('weeks year starting sunday', function (assert) { | |
16213 assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1'); | |
16214 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
16215 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2'); | |
16216 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
16217 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3'); | |
16218 }); | |
16219 | |
16220 test('weeks year starting monday', function (assert) { | |
16221 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
16222 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
16223 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
16224 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
16225 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
16226 }); | |
16227 | |
16228 test('weeks year starting tuesday', function (assert) { | |
16229 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
16230 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
16231 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
16232 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
16233 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
16234 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
16235 }); | |
16236 | |
16237 test('weeks year starting wednesday', function (assert) { | |
16238 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
16239 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
16240 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
16241 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
16242 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
16243 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
16244 }); | |
16245 | |
16246 test('weeks year starting thursday', function (assert) { | |
16247 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
16248 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
16249 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
16250 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
16251 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
16252 assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3'); | |
16253 }); | |
16254 | |
16255 test('weeks year starting friday', function (assert) { | |
16256 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1'); | |
16257 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
16258 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1'); | |
16259 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2'); | |
16260 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2'); | |
16261 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3'); | |
16262 }); | |
16263 | |
16264 test('weeks year starting saturday', function (assert) { | |
16265 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1'); | |
16266 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
16267 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1'); | |
16268 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2'); | |
16269 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2'); | |
16270 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3'); | |
16271 }); | |
16272 | |
16273 test('weeks year starting sunday formatted', function (assert) { | |
16274 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1', 'Dec 26 2011 should be week 1'); | |
16275 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1'); | |
16276 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2', 'Jan 2 2012 should be week 2'); | |
16277 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2'); | |
16278 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3', 'Jan 9 2012 should be week 3'); | |
16279 }); | |
16280 | |
16281 test('lenient ordinal parsing', function (assert) { | |
16282 var i, ordinalStr, testMoment; | |
16283 for (i = 1; i <= 31; ++i) { | |
16284 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
16285 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
16286 assert.equal(testMoment.year(), 2014, | |
16287 'lenient ordinal parsing ' + i + ' year check'); | |
16288 assert.equal(testMoment.month(), 0, | |
16289 'lenient ordinal parsing ' + i + ' month check'); | |
16290 assert.equal(testMoment.date(), i, | |
16291 'lenient ordinal parsing ' + i + ' date check'); | |
16292 } | |
16293 }); | |
16294 | |
16295 test('lenient ordinal parsing of number', function (assert) { | |
16296 var i, testMoment; | |
16297 for (i = 1; i <= 31; ++i) { | |
16298 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
16299 assert.equal(testMoment.year(), 2014, | |
16300 'lenient ordinal parsing of number ' + i + ' year check'); | |
16301 assert.equal(testMoment.month(), 0, | |
16302 'lenient ordinal parsing of number ' + i + ' month check'); | |
16303 assert.equal(testMoment.date(), i, | |
16304 'lenient ordinal parsing of number ' + i + ' date check'); | |
16305 } | |
16306 }); | |
16307 | |
16308 test('meridiem invariant', function (assert) { | |
16309 var h, m, t1, t2; | |
16310 for (h = 0; h < 24; ++h) { | |
16311 for (m = 0; m < 60; m += 15) { | |
16312 t1 = moment.utc([2000, 0, 1, h, m]); | |
16313 t2 = moment(t1.format('A h:mm'), 'A h:mm'); | |
16314 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'), | |
16315 'meridiem at ' + t1.format('HH:mm')); | |
16316 } | |
16317 } | |
16318 }); | |
16319 | |
16320 test('strict ordinal parsing', function (assert) { | |
16321 var i, ordinalStr, testMoment; | |
16322 for (i = 1; i <= 31; ++i) { | |
16323 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
16324 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
16325 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
16326 } | |
16327 }); | |
16328 | |
16329 })); | |
16330 | |
16331 (function (global, factory) { | |
16332 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
16333 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
16334 factory(global.moment) | |
16335 }(this, function (moment) { 'use strict'; | |
16336 | |
16337 /*global QUnit:false*/ | |
16338 | |
16339 var test = QUnit.test; | |
16340 | |
16341 function module (name, lifecycle) { | |
16342 QUnit.module(name, { | |
16343 setup : function () { | |
16344 moment.locale('en'); | |
16345 moment.createFromInputFallback = function () { | |
16346 throw new Error('input not handled by moment'); | |
16347 }; | |
16348 if (lifecycle && lifecycle.setup) { | |
16349 lifecycle.setup(); | |
16350 } | |
16351 }, | |
16352 teardown : function () { | |
16353 if (lifecycle && lifecycle.teardown) { | |
16354 lifecycle.teardown(); | |
16355 } | |
16356 } | |
16357 }); | |
16358 } | |
16359 | |
16360 function localeModule (name, lifecycle) { | |
16361 QUnit.module('locale:' + name, { | |
16362 setup : function () { | |
16363 moment.locale(name); | |
16364 moment.createFromInputFallback = function () { | |
16365 throw new Error('input not handled by moment'); | |
16366 }; | |
16367 if (lifecycle && lifecycle.setup) { | |
16368 lifecycle.setup(); | |
16369 } | |
16370 }, | |
16371 teardown : function () { | |
16372 moment.locale('en'); | |
16373 if (lifecycle && lifecycle.teardown) { | |
16374 lifecycle.teardown(); | |
16375 } | |
16376 } | |
16377 }); | |
16378 } | |
16379 | |
16380 localeModule('ka'); | |
16381 | |
16382 test('parse', function (assert) { | |
16383 var i, | |
16384 tests = 'იანვარი იან_თებერვალი თებ_მარტი მარ_აპრილი აპრ_მაისი მაი_ივნისი ივნ_ივლისი ივლ_აგვისტო აგვ_სექტემბერი სექ_ოქტომბერი ოქტ_ნოემბერი ნოე_დეკემბერი დეკ'.split('_'); | |
16385 | |
16386 function equalTest(input, mmm, i) { | |
16387 assert.equal(moment(input, mmm).month(), i, input + ' უნდა იყოს თვე ' + (i + 1)); | |
16388 } | |
16389 | |
16390 for (i = 0; i < 12; i++) { | |
16391 tests[i] = tests[i].split(' '); | |
16392 equalTest(tests[i][0], 'MMM', i); | |
16393 equalTest(tests[i][1], 'MMM', i); | |
16394 equalTest(tests[i][0], 'MMMM', i); | |
16395 equalTest(tests[i][1], 'MMMM', i); | |
16396 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
16397 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
16398 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
16399 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
16400 } | |
16401 }); | |
16402 | |
16403 test('format', function (assert) { | |
16404 var a = [ | |
16405 ['dddd, MMMM Do YYYY, h:mm:ss a', 'კვირა, თებერვალი მე-14 2010, 3:25:50 pm'], | |
16406 ['ddd, hA', 'კვი, 3PM'], | |
16407 ['M Mo MM MMMM MMM', '2 მე-2 02 თებერვალი თებ'], | |
16408 ['YYYY YY', '2010 10'], | |
16409 ['D Do DD', '14 მე-14 14'], | |
16410 ['d do dddd ddd dd', '0 0 კვირა კვი კვ'], | |
16411 ['DDD DDDo DDDD', '45 45-ე 045'], | |
16412 ['w wo ww', '7 მე-7 07'], | |
16413 ['h hh', '3 03'], | |
16414 ['H HH', '15 15'], | |
16415 ['m mm', '25 25'], | |
16416 ['s ss', '50 50'], | |
16417 ['a A', 'pm PM'], | |
16418 ['წლის DDDo დღე', 'წლის 45-ე დღე'], | |
16419 ['LTS', '3:25:50 PM'], | |
16420 ['L', '14/02/2010'], | |
16421 ['LL', '14 თებერვალი 2010'], | |
16422 ['LLL', '14 თებერვალი 2010 3:25 PM'], | |
16423 ['LLLL', 'კვირა, 14 თებერვალი 2010 3:25 PM'], | |
16424 ['l', '14/2/2010'], | |
16425 ['ll', '14 თებ 2010'], | |
16426 ['lll', '14 თებ 2010 3:25 PM'], | |
16427 ['llll', 'კვი, 14 თებ 2010 3:25 PM'] | |
16428 ], | |
16429 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
16430 i; | |
16431 | |
16432 for (i = 0; i < a.length; i++) { | |
16433 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
16434 } | |
16435 }); | |
16436 | |
16437 test('format ordinal', function (assert) { | |
16438 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-ლი', '1-ლი'); | |
16439 assert.equal(moment([2011, 0, 2]).format('DDDo'), 'მე-2', 'მე-2'); | |
16440 assert.equal(moment([2011, 0, 3]).format('DDDo'), 'მე-3', 'მე-3'); | |
16441 assert.equal(moment([2011, 0, 4]).format('DDDo'), 'მე-4', 'მე-4'); | |
16442 assert.equal(moment([2011, 0, 5]).format('DDDo'), 'მე-5', 'მე-5'); | |
16443 assert.equal(moment([2011, 0, 6]).format('DDDo'), 'მე-6', 'მე-6'); | |
16444 assert.equal(moment([2011, 0, 7]).format('DDDo'), 'მე-7', 'მე-7'); | |
16445 assert.equal(moment([2011, 0, 8]).format('DDDo'), 'მე-8', 'მე-8'); | |
16446 assert.equal(moment([2011, 0, 9]).format('DDDo'), 'მე-9', 'მე-9'); | |
16447 assert.equal(moment([2011, 0, 10]).format('DDDo'), 'მე-10', 'მე-10'); | |
16448 | |
16449 assert.equal(moment([2011, 0, 11]).format('DDDo'), 'მე-11', 'მე-11'); | |
16450 assert.equal(moment([2011, 0, 12]).format('DDDo'), 'მე-12', 'მე-12'); | |
16451 assert.equal(moment([2011, 0, 13]).format('DDDo'), 'მე-13', 'მე-13'); | |
16452 assert.equal(moment([2011, 0, 14]).format('DDDo'), 'მე-14', 'მე-14'); | |
16453 assert.equal(moment([2011, 0, 15]).format('DDDo'), 'მე-15', 'მე-15'); | |
16454 assert.equal(moment([2011, 0, 16]).format('DDDo'), 'მე-16', 'მე-16'); | |
16455 assert.equal(moment([2011, 0, 17]).format('DDDo'), 'მე-17', 'მე-17'); | |
16456 assert.equal(moment([2011, 0, 18]).format('DDDo'), 'მე-18', 'მე-18'); | |
16457 assert.equal(moment([2011, 0, 19]).format('DDDo'), 'მე-19', 'მე-19'); | |
16458 assert.equal(moment([2011, 0, 20]).format('DDDo'), 'მე-20', 'მე-20'); | |
16459 | |
16460 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-ე', '21-ე'); | |
16461 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-ე', '22-ე'); | |
16462 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-ე', '23-ე'); | |
16463 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-ე', '24-ე'); | |
16464 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-ე', '25-ე'); | |
16465 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-ე', '26-ე'); | |
16466 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-ე', '27-ე'); | |
16467 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-ე', '28-ე'); | |
16468 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-ე', '29-ე'); | |
16469 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-ე', '30-ე'); | |
16470 | |
16471 assert.equal(moment('2011 40', 'YYYY DDD').format('DDDo'), 'მე-40', 'მე-40'); | |
16472 assert.equal(moment('2011 50', 'YYYY DDD').format('DDDo'), '50-ე', '50-ე'); | |
16473 assert.equal(moment('2011 60', 'YYYY DDD').format('DDDo'), 'მე-60', 'მე-60'); | |
16474 assert.equal(moment('2011 100', 'YYYY DDD').format('DDDo'), 'მე-100', 'მე-100'); | |
16475 assert.equal(moment('2011 101', 'YYYY DDD').format('DDDo'), '101-ე', '101-ე'); | |
16476 }); | |
16477 | |
16478 test('format month', function (assert) { | |
16479 var i, | |
16480 expected = 'იანვარი იან_თებერვალი თებ_მარტი მარ_აპრილი აპრ_მაისი მაი_ივნისი ივნ_ივლისი ივლ_აგვისტო აგვ_სექტემბერი სექ_ოქტომბერი ოქტ_ნოემბერი ნოე_დეკემბერი დეკ'.split('_'); | |
16481 | |
16482 for (i = 0; i < expected.length; i++) { | |
16483 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
16484 } | |
16485 }); | |
16486 | |
16487 test('format week', function (assert) { | |
16488 var i, | |
16489 expected = 'კვირა კვი კვ_ორშაბათი ორშ ორ_სამშაბათი სამ სა_ოთხშაბათი ოთხ ოთ_ხუთშაბათი ხუთ ხუ_პარასკევი პარ პა_შაბათი შაბ შა'.split('_'); | |
16490 | |
16491 for (i = 0; i < expected.length; i++) { | |
16492 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
16493 } | |
16494 }); | |
16495 | |
16496 test('from', function (assert) { | |
16497 var start = moment([2007, 1, 28]); | |
16498 | |
16499 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'რამდენიმე წამი', '44 წამი = რამდენიმე წამი'); | |
16500 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'წუთი', '45 წამი = წუთი'); | |
16501 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'წუთი', '89 წამი = წუთი'); | |
16502 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 წუთი', '90 წამი = 2 წუთი'); | |
16503 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 წუთი', '44 წამი = 44 წუთი'); | |
16504 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'საათი', '45 წამი = საათი'); | |
16505 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'საათი', '89 წამი = საათი'); | |
16506 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 საათი', '90 წამი = 2 საათი'); | |
16507 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 საათი', '5 საათი = 5 საათი'); | |
16508 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 საათი', '21 საათი = 21 საათი'); | |
16509 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'დღე', '22 საათი = დღე'); | |
16510 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'დღე', '35 საათი = დღე'); | |
16511 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 დღე', '36 საათი = 2 დღე'); | |
16512 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'დღე', '1 დღე = დღე'); | |
16513 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 დღე', '5 დღე = 5 დღე'); | |
16514 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 დღე', '25 დღე = 25 დღე'); | |
16515 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'თვე', '26 დღე = თვე'); | |
16516 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'თვე', '30 დღე = თვე'); | |
16517 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'თვე', '45 დღე = თვე'); | |
16518 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 თვე', '46 დღე = 2 თვე'); | |
16519 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 თვე', '75 დღე = 2 თვე'); | |
16520 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 თვე', '76 დღე = 3 თვე'); | |
16521 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'თვე', '1 თვე = თვე'); | |
16522 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 თვე', '5 თვე = 5 თვე'); | |
16523 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'წელი', '345 დღე = წელი'); | |
16524 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 წელი', '548 დღე = 2 წელი'); | |
16525 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'წელი', '1 წელი = წელი'); | |
16526 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 წელი', '5 წელი = 5 წელი'); | |
16527 }); | |
16528 | |
16529 test('suffix', function (assert) { | |
16530 assert.equal(moment(30000).from(0), 'რამდენიმე წამში', 'ში სუფიქსი'); | |
16531 assert.equal(moment(0).from(30000), 'რამდენიმე წამის წინ', 'წინ სუფიქსი'); | |
16532 }); | |
16533 | |
16534 test('now from now', function (assert) { | |
16535 assert.equal(moment().fromNow(), 'რამდენიმე წამის წინ', 'უნდა აჩვენოს როგორც წარსული'); | |
16536 }); | |
16537 | |
16538 test('fromNow', function (assert) { | |
16539 assert.equal(moment().add({s: 30}).fromNow(), 'რამდენიმე წამში', 'რამდენიმე წამში'); | |
16540 assert.equal(moment().add({d: 5}).fromNow(), '5 დღეში', '5 დღეში'); | |
16541 }); | |
16542 | |
16543 test('calendar day', function (assert) { | |
16544 var a = moment().hours(2).minutes(0).seconds(0); | |
16545 | |
16546 assert.equal(moment(a).calendar(), 'დღეს 2:00 AM-ზე', 'დღეს ამავე დროს'); | |
16547 assert.equal(moment(a).add({m: 25}).calendar(), 'დღეს 2:25 AM-ზე', 'ახლანდელ დროს დამატებული 25 წუთი'); | |
16548 assert.equal(moment(a).add({h: 1}).calendar(), 'დღეს 3:00 AM-ზე', 'ახლანდელ დროს დამატებული 1 საათი'); | |
16549 assert.equal(moment(a).add({d: 1}).calendar(), 'ხვალ 2:00 AM-ზე', 'ხვალ ამავე დროს'); | |
16550 assert.equal(moment(a).subtract({h: 1}).calendar(), 'დღეს 1:00 AM-ზე', 'ახლანდელ დროს გამოკლებული 1 საათი'); | |
16551 assert.equal(moment(a).subtract({d: 1}).calendar(), 'გუშინ 2:00 AM-ზე', 'გუშინ ამავე დროს'); | |
16552 }); | |
16553 | |
16554 test('calendar next week', function (assert) { | |
16555 var i, m; | |
16556 for (i = 2; i < 7; i++) { | |
16557 m = moment().add({d: i}); | |
16558 assert.equal(m.calendar(), m.format('[შემდეგ] dddd LT[-ზე]'), 'დღეს + ' + i + ' დღე ახლანდელ დროს'); | |
16559 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
16560 assert.equal(m.calendar(), m.format('[შემდეგ] dddd LT[-ზე]'), 'დღეს + ' + i + ' დღე დღის დასაწყისში'); | |
16561 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
16562 assert.equal(m.calendar(), m.format('[შემდეგ] dddd LT[-ზე]'), 'დღეს + ' + i + ' დღე დღის დასასრულს'); | |
16563 } | |
16564 }); | |
16565 | |
16566 test('calendar last week', function (assert) { | |
16567 var i, m; | |
16568 for (i = 2; i < 7; i++) { | |
16569 m = moment().subtract({d: i}); | |
16570 assert.equal(m.calendar(), m.format('[წინა] dddd LT[-ზე]'), 'დღეს - ' + i + ' დღე ახლანდელ დროს'); | |
16571 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
16572 assert.equal(m.calendar(), m.format('[წინა] dddd LT[-ზე]'), 'დღეს - ' + i + ' დღე დღის დასაწყისში'); | |
16573 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
16574 assert.equal(m.calendar(), m.format('[წინა] dddd LT[-ზე]'), 'დღეს - ' + i + ' დღე დღის დასასრულს'); | |
16575 } | |
16576 }); | |
16577 | |
16578 test('calendar all else', function (assert) { | |
16579 var weeksAgo = moment().subtract({w: 1}), | |
16580 weeksFromNow = moment().add({w: 1}); | |
16581 | |
16582 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 კვირის წინ'); | |
16583 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), '1 კვირაში'); | |
16584 | |
16585 weeksAgo = moment().subtract({w: 2}); | |
16586 weeksFromNow = moment().add({w: 2}); | |
16587 | |
16588 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 კვირის წინ'); | |
16589 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), '2 კვირაში'); | |
16590 }); | |
16591 | |
16592 test('weeks year starting sunday', function (assert) { | |
16593 assert.equal(moment([2011, 11, 26]).week(), 1, 'დეკ 26 2011 უნდა იყოს კვირა 1'); | |
16594 assert.equal(moment([2012, 0, 1]).week(), 1, 'იან 1 2012 უნდა იყოს კვირა 1'); | |
16595 assert.equal(moment([2012, 0, 2]).week(), 2, 'იან 2 2012 უნდა იყოს კვირა 2'); | |
16596 assert.equal(moment([2012, 0, 8]).week(), 2, 'იან 8 2012 უნდა იყოს კვირა 2'); | |
16597 assert.equal(moment([2012, 0, 9]).week(), 3, 'იან 9 2012 უნდა იყოს კვირა 3'); | |
16598 }); | |
16599 | |
16600 test('weeks year starting monday', function (assert) { | |
16601 assert.equal(moment([2007, 0, 1]).week(), 1, 'იან 1 2007 უნდა იყოს კვირა 1'); | |
16602 assert.equal(moment([2007, 0, 7]).week(), 1, 'იან 7 2007 უნდა იყოს კვირა 1'); | |
16603 assert.equal(moment([2007, 0, 8]).week(), 2, 'იან 8 2007 უნდა იყოს კვირა 2'); | |
16604 assert.equal(moment([2007, 0, 14]).week(), 2, 'იან 14 2007 უნდა იყოს კვირა 2'); | |
16605 assert.equal(moment([2007, 0, 15]).week(), 3, 'იან 15 2007 უნდა იყოს კვირა 3'); | |
16606 }); | |
16607 | |
16608 test('weeks year starting tuesday', function (assert) { | |
16609 assert.equal(moment([2007, 11, 31]).week(), 1, 'დეკ 31 2007 უნდა იყოს კვირა 1'); | |
16610 assert.equal(moment([2008, 0, 1]).week(), 1, 'იან 1 2008 უნდა იყოს კვირა 1'); | |
16611 assert.equal(moment([2008, 0, 6]).week(), 1, 'იან 6 2008 უნდა იყოს კვირა 1'); | |
16612 assert.equal(moment([2008, 0, 7]).week(), 2, 'იან 7 2008 უნდა იყოს კვირა 2'); | |
16613 assert.equal(moment([2008, 0, 13]).week(), 2, 'იან 13 2008 უნდა იყოს კვირა 2'); | |
16614 assert.equal(moment([2008, 0, 14]).week(), 3, 'იან 14 2008 უნდა იყოს კვირა 3'); | |
16615 }); | |
16616 | |
16617 test('weeks year starting wednesday', function (assert) { | |
16618 assert.equal(moment([2002, 11, 30]).week(), 1, 'დეკ 30 2002 უნდა იყოს კვირა 1'); | |
16619 assert.equal(moment([2003, 0, 1]).week(), 1, 'იან 1 2003 უნდა იყოს კვირა 1'); | |
16620 assert.equal(moment([2003, 0, 5]).week(), 1, 'იან 5 2003 უნდა იყოს კვირა 1'); | |
16621 assert.equal(moment([2003, 0, 6]).week(), 2, 'იან 6 2003 უნდა იყოს კვირა 2'); | |
16622 assert.equal(moment([2003, 0, 12]).week(), 2, 'იან 12 2003 უნდა იყოს კვირა 2'); | |
16623 assert.equal(moment([2003, 0, 13]).week(), 3, 'იან 13 2003 უნდა იყოს კვირა 3'); | |
16624 }); | |
16625 | |
16626 test('weeks year starting thursday', function (assert) { | |
16627 assert.equal(moment([2008, 11, 29]).week(), 1, 'დეკ 29 2008 უნდა იყოს კვირა 1'); | |
16628 assert.equal(moment([2009, 0, 1]).week(), 1, 'იან 1 2009 უნდა იყოს კვირა 1'); | |
16629 assert.equal(moment([2009, 0, 4]).week(), 1, 'იან 4 2009 უნდა იყოს კვირა 1'); | |
16630 assert.equal(moment([2009, 0, 5]).week(), 2, 'იან 5 2009 უნდა იყოს კვირა 2'); | |
16631 assert.equal(moment([2009, 0, 11]).week(), 2, 'იან 11 2009 უნდა იყოს კვირა 2'); | |
16632 assert.equal(moment([2009, 0, 12]).week(), 3, 'იან 12 2009 უნდა იყოს კვირა 3'); | |
16633 }); | |
16634 | |
16635 test('weeks year starting friday', function (assert) { | |
16636 assert.equal(moment([2009, 11, 28]).week(), 1, 'დეკ 28 2009 უნდა იყოს კვირა 1'); | |
16637 assert.equal(moment([2010, 0, 1]).week(), 1, 'იან 1 2010 უნდა იყოს კვირა 1'); | |
16638 assert.equal(moment([2010, 0, 3]).week(), 1, 'იან 3 2010 უნდა იყოს კვირა 1'); | |
16639 assert.equal(moment([2010, 0, 4]).week(), 2, 'იან 4 2010 უნდა იყოს კვირა 2'); | |
16640 assert.equal(moment([2010, 0, 10]).week(), 2, 'იან 10 2010 უნდა იყოს კვირა 2'); | |
16641 assert.equal(moment([2010, 0, 11]).week(), 3, 'იან 11 2010 უნდა იყოს კვირა 3'); | |
16642 }); | |
16643 | |
16644 test('weeks year starting saturday', function (assert) { | |
16645 assert.equal(moment([2010, 11, 27]).week(), 1, 'დეკ 27 2010 უნდა იყოს კვირა 1'); | |
16646 assert.equal(moment([2011, 0, 1]).week(), 1, 'იან 1 2011 უნდა იყოს კვირა 1'); | |
16647 assert.equal(moment([2011, 0, 2]).week(), 1, 'იან 2 2011 უნდა იყოს კვირა 1'); | |
16648 assert.equal(moment([2011, 0, 3]).week(), 2, 'იან 3 2011 უნდა იყოს კვირა 2'); | |
16649 assert.equal(moment([2011, 0, 9]).week(), 2, 'იან 9 2011 უნდა იყოს კვირა 2'); | |
16650 assert.equal(moment([2011, 0, 10]).week(), 3, 'იან 10 2011 უნდა იყოს კვირა 3'); | |
16651 }); | |
16652 | |
16653 test('weeks year starting sunday formatted', function (assert) { | |
16654 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-ლი', 'დეკ 26 2011 უნდა იყოს კვირა 1'); | |
16655 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-ლი', 'იან 1 2012 უნდა იყოს კვირა 1'); | |
16656 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 მე-2', 'იან 2 2012 უნდა იყოს კვირა 2'); | |
16657 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 მე-2', 'იან 8 2012 უნდა იყოს კვირა 2'); | |
16658 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 მე-3', 'იან 9 2012 უნდა იყოს კვირა 3'); | |
16659 }); | |
16660 | |
16661 test('lenient ordinal parsing', function (assert) { | |
16662 var i, ordinalStr, testMoment; | |
16663 for (i = 1; i <= 31; ++i) { | |
16664 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
16665 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
16666 assert.equal(testMoment.year(), 2014, | |
16667 'lenient ordinal parsing ' + i + ' year check'); | |
16668 assert.equal(testMoment.month(), 0, | |
16669 'lenient ordinal parsing ' + i + ' month check'); | |
16670 assert.equal(testMoment.date(), i, | |
16671 'lenient ordinal parsing ' + i + ' date check'); | |
16672 } | |
16673 }); | |
16674 | |
16675 test('lenient ordinal parsing of number', function (assert) { | |
16676 var i, testMoment; | |
16677 for (i = 1; i <= 31; ++i) { | |
16678 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
16679 assert.equal(testMoment.year(), 2014, | |
16680 'lenient ordinal parsing of number ' + i + ' year check'); | |
16681 assert.equal(testMoment.month(), 0, | |
16682 'lenient ordinal parsing of number ' + i + ' month check'); | |
16683 assert.equal(testMoment.date(), i, | |
16684 'lenient ordinal parsing of number ' + i + ' date check'); | |
16685 } | |
16686 }); | |
16687 | |
16688 test('strict ordinal parsing', function (assert) { | |
16689 var i, ordinalStr, testMoment; | |
16690 for (i = 1; i <= 31; ++i) { | |
16691 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
16692 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
16693 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
16694 } | |
16695 }); | |
16696 | |
16697 })); | |
16698 | |
16699 (function (global, factory) { | |
16700 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
16701 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
16702 factory(global.moment) | |
16703 }(this, function (moment) { 'use strict'; | |
16704 | |
16705 /*global QUnit:false*/ | |
16706 | |
16707 var test = QUnit.test; | |
16708 | |
16709 function module (name, lifecycle) { | |
16710 QUnit.module(name, { | |
16711 setup : function () { | |
16712 moment.locale('en'); | |
16713 moment.createFromInputFallback = function () { | |
16714 throw new Error('input not handled by moment'); | |
16715 }; | |
16716 if (lifecycle && lifecycle.setup) { | |
16717 lifecycle.setup(); | |
16718 } | |
16719 }, | |
16720 teardown : function () { | |
16721 if (lifecycle && lifecycle.teardown) { | |
16722 lifecycle.teardown(); | |
16723 } | |
16724 } | |
16725 }); | |
16726 } | |
16727 | |
16728 function localeModule (name, lifecycle) { | |
16729 QUnit.module('locale:' + name, { | |
16730 setup : function () { | |
16731 moment.locale(name); | |
16732 moment.createFromInputFallback = function () { | |
16733 throw new Error('input not handled by moment'); | |
16734 }; | |
16735 if (lifecycle && lifecycle.setup) { | |
16736 lifecycle.setup(); | |
16737 } | |
16738 }, | |
16739 teardown : function () { | |
16740 moment.locale('en'); | |
16741 if (lifecycle && lifecycle.teardown) { | |
16742 lifecycle.teardown(); | |
16743 } | |
16744 } | |
16745 }); | |
16746 } | |
16747 | |
16748 localeModule('km'); | |
16749 | |
16750 test('parse', function (assert) { | |
16751 var tests = 'មករា មករា_កុម្ភៈ កុម្ភៈ_មិនា មិនា_មេសា មេសា_ឧសភា ឧសភា_មិថុនា មិថុនា_កក្កដា កក្កដា_សីហា សីហា_កញ្ញា កញ្ញា_តុលា តុលា_វិច្ឆិកា វិច្ឆិកា_ធ្នូ ធ្នូ'.split('_'), | |
16752 i; | |
16753 | |
16754 function equalTest(input, mmm, i) { | |
16755 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
16756 } | |
16757 for (i = 0; i < 12; i++) { | |
16758 tests[i] = tests[i].split(' '); | |
16759 equalTest(tests[i][0], 'MMM', i); | |
16760 equalTest(tests[i][1], 'MMM', i); | |
16761 equalTest(tests[i][0], 'MMMM', i); | |
16762 equalTest(tests[i][1], 'MMMM', i); | |
16763 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
16764 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
16765 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
16766 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
16767 } | |
16768 }); | |
16769 | |
16770 test('format', function (assert) { | |
16771 var a = [ | |
16772 ['dddd, MMMM Do YYYY, h:mm:ss a', 'អាទិត្យ, កុម្ភៈ 14 2010, 3:25:50 pm'], | |
16773 ['ddd, hA', 'អាទិត្យ, 3PM'], | |
16774 ['M Mo MM MMMM MMM', '2 2 02 កុម្ភៈ កុម្ភៈ'], | |
16775 ['YYYY YY', '2010 10'], | |
16776 ['D Do DD', '14 14 14'], | |
16777 ['d do dddd ddd dd', '0 0 អាទិត្យ អាទិត្យ អាទិត្យ'], | |
16778 ['DDD DDDo DDDD', '45 45 045'], | |
16779 ['w wo ww', '6 6 06'], | |
16780 ['h hh', '3 03'], | |
16781 ['H HH', '15 15'], | |
16782 ['m mm', '25 25'], | |
16783 ['s ss', '50 50'], | |
16784 ['a A', 'pm PM'], | |
16785 ['[the] DDDo [day of the year]', 'the 45 day of the year'], | |
16786 ['LTS', '15:25:50'], | |
16787 ['L', '14/02/2010'], | |
16788 ['LL', '14 កុម្ភៈ 2010'], | |
16789 ['LLL', '14 កុម្ភៈ 2010 15:25'], | |
16790 ['LLLL', 'អាទិត្យ, 14 កុម្ភៈ 2010 15:25'], | |
16791 ['l', '14/2/2010'], | |
16792 ['ll', '14 កុម្ភៈ 2010'], | |
16793 ['lll', '14 កុម្ភៈ 2010 15:25'], | |
16794 ['llll', 'អាទិត្យ, 14 កុម្ភៈ 2010 15:25'] | |
16795 ], | |
16796 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
16797 i; | |
16798 for (i = 0; i < a.length; i++) { | |
16799 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
16800 } | |
16801 }); | |
16802 | |
16803 test('format ordinal', function (assert) { | |
16804 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1st'); | |
16805 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2nd'); | |
16806 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3rd'); | |
16807 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4th'); | |
16808 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5th'); | |
16809 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6th'); | |
16810 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7th'); | |
16811 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8th'); | |
16812 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9th'); | |
16813 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10th'); | |
16814 | |
16815 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11th'); | |
16816 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12th'); | |
16817 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13th'); | |
16818 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14th'); | |
16819 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15th'); | |
16820 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16th'); | |
16821 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17th'); | |
16822 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18th'); | |
16823 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19th'); | |
16824 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20th'); | |
16825 | |
16826 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21st'); | |
16827 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22nd'); | |
16828 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23rd'); | |
16829 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24th'); | |
16830 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25th'); | |
16831 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26th'); | |
16832 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27th'); | |
16833 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28th'); | |
16834 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29th'); | |
16835 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30th'); | |
16836 | |
16837 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31st'); | |
16838 }); | |
16839 | |
16840 test('format month', function (assert) { | |
16841 var expected = 'មករា មករា_កុម្ភៈ កុម្ភៈ_មិនា មិនា_មេសា មេសា_ឧសភា ឧសភា_មិថុនា មិថុនា_កក្កដា កក្កដា_សីហា សីហា_កញ្ញា កញ្ញា_តុលា តុលា_វិច្ឆិកា វិច្ឆិកា_ធ្នូ ធ្នូ'.split('_'), | |
16842 i; | |
16843 for (i = 0; i < expected.length; i++) { | |
16844 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
16845 } | |
16846 }); | |
16847 | |
16848 test('format week', function (assert) { | |
16849 var expected = 'អាទិត្យ អាទិត្យ អាទិត្យ_ច័ន្ទ ច័ន្ទ ច័ន្ទ_អង្គារ អង្គារ អង្គារ_ពុធ ពុធ ពុធ_ព្រហស្បតិ៍ ព្រហស្បតិ៍ ព្រហស្បតិ៍_សុក្រ សុក្រ សុក្រ_សៅរ៍ សៅរ៍ សៅរ៍'.split('_'), | |
16850 i; | |
16851 for (i = 0; i < expected.length; i++) { | |
16852 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
16853 } | |
16854 }); | |
16855 | |
16856 test('from', function (assert) { | |
16857 var start = moment([2007, 1, 28]); | |
16858 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ប៉ុន្មានវិនាទី', '44 seconds = ប៉ុន្មានវិនាទី'); | |
16859 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'មួយនាទី', '45 seconds = មួយនាទី'); | |
16860 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'មួយនាទី', '89 seconds = មួយនាទី'); | |
16861 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 នាទី', '90 seconds = 2 នាទី'); | |
16862 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 នាទី', '44 minutes = 44 នាទី'); | |
16863 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'មួយម៉ោង', '45 minutes = មួយម៉ោង'); | |
16864 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'មួយម៉ោង', '89 minutes = មួយម៉ោង'); | |
16865 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ម៉ោង', '90 minutes = 2 ម៉ោង'); | |
16866 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ម៉ោង', '5 hours = 5 ម៉ោង'); | |
16867 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ម៉ោង', '21 hours = 21 ម៉ោង'); | |
16868 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'មួយថ្ងៃ', '22 hours = មួយថ្ងៃ'); | |
16869 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'មួយថ្ងៃ', '35 hours = មួយថ្ងៃ'); | |
16870 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 ថ្ងៃ', '36 hours = 2 ថ្ងៃ'); | |
16871 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'មួយថ្ងៃ', '1 day = មួយថ្ងៃ'); | |
16872 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ថ្ងៃ', '5 days = 5 ថ្ងៃ'); | |
16873 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ថ្ងៃ', '25 days = 25 ថ្ងៃ'); | |
16874 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'មួយខែ', '26 days = មួយខែ'); | |
16875 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'មួយខែ', '30 days = មួយខែ'); | |
16876 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'មួយខែ', '43 days = មួយខែ'); | |
16877 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 ខែ', '46 days = 2 ខែ'); | |
16878 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 ខែ', '75 days = 2 ខែ'); | |
16879 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 ខែ', '76 days = 3 ខែ'); | |
16880 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'មួយខែ', '1 month = មួយខែ'); | |
16881 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 ខែ', '5 months = 5 ខែ'); | |
16882 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'មួយឆ្នាំ', '345 days = មួយឆ្នាំ'); | |
16883 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ឆ្នាំ', '548 days = 2 ឆ្នាំ'); | |
16884 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'មួយឆ្នាំ', '1 year = មួយឆ្នាំ'); | |
16885 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ឆ្នាំ', '5 years = 5 ឆ្នាំ'); | |
16886 }); | |
16887 | |
16888 test('suffix', function (assert) { | |
16889 assert.equal(moment(30000).from(0), 'ប៉ុន្មានវិនាទីទៀត', 'prefix'); | |
16890 assert.equal(moment(0).from(30000), 'ប៉ុន្មានវិនាទីមុន', 'suffix'); | |
16891 }); | |
16892 | |
16893 test('now from now', function (assert) { | |
16894 assert.equal(moment().fromNow(), 'ប៉ុន្មានវិនាទីមុន', 'now from now should display as in the past'); | |
16895 }); | |
16896 | |
16897 test('fromNow', function (assert) { | |
16898 assert.equal(moment().add({ | |
16899 s: 30 | |
16900 }).fromNow(), 'ប៉ុន្មានវិនាទីទៀត', 'in a few seconds'); | |
16901 assert.equal(moment().add({ | |
16902 d: 5 | |
16903 }).fromNow(), '5 ថ្ងៃទៀត', 'in 5 days'); | |
16904 }); | |
16905 | |
16906 test('calendar day', function (assert) { | |
16907 var a = moment().hours(2).minutes(0).seconds(0); | |
16908 | |
16909 assert.equal(moment(a).calendar(), 'ថ្ងៃនៈ ម៉ោង 02:00', 'today at the same time'); | |
16910 assert.equal(moment(a).add({ | |
16911 m: 25 | |
16912 }).calendar(), 'ថ្ងៃនៈ ម៉ោង 02:25', 'Now plus 25 min'); | |
16913 assert.equal(moment(a).add({ | |
16914 h: 1 | |
16915 }).calendar(), 'ថ្ងៃនៈ ម៉ោង 03:00', 'Now plus 1 hour'); | |
16916 assert.equal(moment(a).add({ | |
16917 d: 1 | |
16918 }).calendar(), 'ស្អែក ម៉ោង 02:00', 'tomorrow at the same time'); | |
16919 assert.equal(moment(a).subtract({ | |
16920 h: 1 | |
16921 }).calendar(), 'ថ្ងៃនៈ ម៉ោង 01:00', 'Now minus 1 hour'); | |
16922 assert.equal(moment(a).subtract({ | |
16923 d: 1 | |
16924 }).calendar(), 'ម្សិលមិញ ម៉ោង 02:00', 'yesterday at the same time'); | |
16925 }); | |
16926 | |
16927 test('calendar next week', function (assert) { | |
16928 var i, m; | |
16929 for (i = 2; i < 7; i++) { | |
16930 m = moment().add({ | |
16931 d: i | |
16932 }); | |
16933 assert.equal(m.calendar(), m.format('dddd [ម៉ោង] LT'), 'Today + ' + i + ' days current time'); | |
16934 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
16935 assert.equal(m.calendar(), m.format('dddd [ម៉ោង] LT'), 'Today + ' + i + ' days beginning of day'); | |
16936 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
16937 assert.equal(m.calendar(), m.format('dddd [ម៉ោង] LT'), 'Today + ' + i + ' days end of day'); | |
16938 } | |
16939 }); | |
16940 | |
16941 test('calendar last week', function (assert) { | |
16942 var i, m; | |
16943 | |
16944 for (i = 2; i < 7; i++) { | |
16945 m = moment().subtract({ | |
16946 d: i | |
16947 }); | |
16948 assert.equal(m.calendar(), m.format('dddd [សប្តាហ៍មុន] [ម៉ោង] LT'), 'Today - ' + i + ' days current time'); | |
16949 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
16950 assert.equal(m.calendar(), m.format('dddd [សប្តាហ៍មុន] [ម៉ោង] LT'), 'Today - ' + i + ' days beginning of day'); | |
16951 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
16952 assert.equal(m.calendar(), m.format('dddd [សប្តាហ៍មុន] [ម៉ោង] LT'), 'Today - ' + i + ' days end of day'); | |
16953 } | |
16954 }); | |
16955 | |
16956 test('calendar all else', function (assert) { | |
16957 var weeksAgo = moment().subtract({ | |
16958 w: 1 | |
16959 }), | |
16960 weeksFromNow = moment().add({ | |
16961 w: 1 | |
16962 }); | |
16963 | |
16964 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
16965 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
16966 | |
16967 weeksAgo = moment().subtract({ | |
16968 w: 2 | |
16969 }); | |
16970 weeksFromNow = moment().add({ | |
16971 w: 2 | |
16972 }); | |
16973 | |
16974 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
16975 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
16976 }); | |
16977 | |
16978 test('weeks year starting sunday', function (assert) { | |
16979 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
16980 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
16981 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
16982 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
16983 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
16984 }); | |
16985 | |
16986 test('weeks year starting monday', function (assert) { | |
16987 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
16988 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
16989 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
16990 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
16991 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
16992 }); | |
16993 | |
16994 test('weeks year starting tuesday', function (assert) { | |
16995 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
16996 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
16997 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
16998 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
16999 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
17000 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
17001 }); | |
17002 | |
17003 test('weeks year starting wednesday', function (assert) { | |
17004 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
17005 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
17006 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
17007 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
17008 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
17009 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
17010 }); | |
17011 | |
17012 test('weeks year starting thursday', function (assert) { | |
17013 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
17014 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
17015 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
17016 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
17017 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
17018 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
17019 }); | |
17020 | |
17021 test('weeks year starting friday', function (assert) { | |
17022 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
17023 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
17024 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
17025 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
17026 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
17027 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
17028 }); | |
17029 | |
17030 test('weeks year starting saturday', function (assert) { | |
17031 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
17032 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
17033 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
17034 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
17035 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
17036 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
17037 }); | |
17038 | |
17039 test('weeks year starting sunday formatted', function (assert) { | |
17040 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52', 'Jan 1 2012 should be week 52'); | |
17041 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1', 'Jan 2 2012 should be week 1'); | |
17042 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1', 'Jan 8 2012 should be week 1'); | |
17043 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2', 'Jan 9 2012 should be week 2'); | |
17044 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2', 'Jan 15 2012 should be week 2'); | |
17045 }); | |
17046 | |
17047 test('lenient ordinal parsing', function (assert) { | |
17048 var i, ordinalStr, testMoment; | |
17049 for (i = 1; i <= 31; ++i) { | |
17050 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
17051 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
17052 assert.equal(testMoment.year(), 2014, | |
17053 'lenient ordinal parsing ' + i + ' year check'); | |
17054 assert.equal(testMoment.month(), 0, | |
17055 'lenient ordinal parsing ' + i + ' month check'); | |
17056 assert.equal(testMoment.date(), i, | |
17057 'lenient ordinal parsing ' + i + ' date check'); | |
17058 } | |
17059 }); | |
17060 | |
17061 test('lenient ordinal parsing of number', function (assert) { | |
17062 var i, testMoment; | |
17063 for (i = 1; i <= 31; ++i) { | |
17064 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
17065 assert.equal(testMoment.year(), 2014, | |
17066 'lenient ordinal parsing of number ' + i + ' year check'); | |
17067 assert.equal(testMoment.month(), 0, | |
17068 'lenient ordinal parsing of number ' + i + ' month check'); | |
17069 assert.equal(testMoment.date(), i, | |
17070 'lenient ordinal parsing of number ' + i + ' date check'); | |
17071 } | |
17072 }); | |
17073 | |
17074 test('strict ordinal parsing', function (assert) { | |
17075 var i, ordinalStr, testMoment; | |
17076 for (i = 1; i <= 31; ++i) { | |
17077 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
17078 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
17079 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
17080 } | |
17081 }); | |
17082 | |
17083 })); | |
17084 | |
17085 (function (global, factory) { | |
17086 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
17087 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
17088 factory(global.moment) | |
17089 }(this, function (moment) { 'use strict'; | |
17090 | |
17091 /*global QUnit:false*/ | |
17092 | |
17093 var test = QUnit.test; | |
17094 | |
17095 function module (name, lifecycle) { | |
17096 QUnit.module(name, { | |
17097 setup : function () { | |
17098 moment.locale('en'); | |
17099 moment.createFromInputFallback = function () { | |
17100 throw new Error('input not handled by moment'); | |
17101 }; | |
17102 if (lifecycle && lifecycle.setup) { | |
17103 lifecycle.setup(); | |
17104 } | |
17105 }, | |
17106 teardown : function () { | |
17107 if (lifecycle && lifecycle.teardown) { | |
17108 lifecycle.teardown(); | |
17109 } | |
17110 } | |
17111 }); | |
17112 } | |
17113 | |
17114 function localeModule (name, lifecycle) { | |
17115 QUnit.module('locale:' + name, { | |
17116 setup : function () { | |
17117 moment.locale(name); | |
17118 moment.createFromInputFallback = function () { | |
17119 throw new Error('input not handled by moment'); | |
17120 }; | |
17121 if (lifecycle && lifecycle.setup) { | |
17122 lifecycle.setup(); | |
17123 } | |
17124 }, | |
17125 teardown : function () { | |
17126 moment.locale('en'); | |
17127 if (lifecycle && lifecycle.teardown) { | |
17128 lifecycle.teardown(); | |
17129 } | |
17130 } | |
17131 }); | |
17132 } | |
17133 | |
17134 localeModule('ko'); | |
17135 | |
17136 test('parse', function (assert) { | |
17137 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; | |
17138 function equalTest(input, mmm, i) { | |
17139 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
17140 } | |
17141 for (i = 0; i < 12; i++) { | |
17142 tests[i] = tests[i].split(' '); | |
17143 equalTest(tests[i][0], 'MMM', i); | |
17144 equalTest(tests[i][1], 'MMM', i); | |
17145 equalTest(tests[i][0], 'MMMM', i); | |
17146 equalTest(tests[i][1], 'MMMM', i); | |
17147 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
17148 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
17149 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
17150 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
17151 } | |
17152 }); | |
17153 | |
17154 test('parse meridiem', function (assert) { | |
17155 var elements = [{ | |
17156 expression : '1981년 9월 8일 오후 2시 30분', | |
17157 inputFormat : 'YYYY[년] M[월] D[일] A h[시] m[분]', | |
17158 outputFormat : 'A', | |
17159 expected : '오후' | |
17160 }, { | |
17161 expression : '1981년 9월 8일 오전 2시 30분', | |
17162 inputFormat : 'YYYY[년] M[월] D[일] A h[시] m[분]', | |
17163 outputFormat : 'A h시', | |
17164 expected : '오전 2시' | |
17165 }, { | |
17166 expression : '14시 30분', | |
17167 inputFormat : 'H[시] m[분]', | |
17168 outputFormat : 'A', | |
17169 expected : '오후' | |
17170 }, { | |
17171 expression : '오후 4시', | |
17172 inputFormat : 'A h[시]', | |
17173 outputFormat : 'H', | |
17174 expected : '16' | |
17175 }], i, l, it, actual; | |
17176 | |
17177 | |
17178 for (i = 0, l = elements.length; i < l; ++i) { | |
17179 it = elements[i]; | |
17180 actual = moment(it.expression, it.inputFormat).format(it.outputFormat); | |
17181 | |
17182 assert.equal( | |
17183 actual, | |
17184 it.expected, | |
17185 '\'' + it.outputFormat + '\' of \'' + it.expression + '\' must be \'' + it.expected + '\' but was \'' + actual + '\'.' | |
17186 ); | |
17187 } | |
17188 }); | |
17189 | |
17190 test('format', function (assert) { | |
17191 var a = [ | |
17192 ['YYYY년 MMMM Do dddd a h:mm:ss', '2010년 2월 14일 일요일 오후 3:25:50'], | |
17193 ['ddd A h', '일 오후 3'], | |
17194 ['M Mo MM MMMM MMM', '2 2일 02 2월 2월'], | |
17195 ['YYYY YY', '2010 10'], | |
17196 ['D Do DD', '14 14일 14'], | |
17197 ['d do dddd ddd dd', '0 0일 일요일 일 일'], | |
17198 ['DDD DDDo DDDD', '45 45일 045'], | |
17199 ['w wo ww', '8 8일 08'], | |
17200 ['h hh', '3 03'], | |
17201 ['H HH', '15 15'], | |
17202 ['m mm', '25 25'], | |
17203 ['s ss', '50 50'], | |
17204 ['a A', '오후 오후'], | |
17205 ['일년 중 DDDo째 되는 날', '일년 중 45일째 되는 날'], | |
17206 ['LTS', '오후 3시 25분 50초'], | |
17207 ['L', '2010.02.14'], | |
17208 ['LL', '2010년 2월 14일'], | |
17209 ['LLL', '2010년 2월 14일 오후 3시 25분'], | |
17210 ['LLLL', '2010년 2월 14일 일요일 오후 3시 25분'], | |
17211 ['l', '2010.2.14'], | |
17212 ['ll', '2010년 2월 14일'], | |
17213 ['lll', '2010년 2월 14일 오후 3시 25분'], | |
17214 ['llll', '2010년 2월 14일 일 오후 3시 25분'] | |
17215 ], | |
17216 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
17217 i; | |
17218 for (i = 0; i < a.length; i++) { | |
17219 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
17220 } | |
17221 }); | |
17222 | |
17223 test('format ordinal', function (assert) { | |
17224 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1일', '1일'); | |
17225 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2일', '2일'); | |
17226 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3일', '3일'); | |
17227 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4일', '4일'); | |
17228 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5일', '5일'); | |
17229 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6일', '6일'); | |
17230 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7일', '7일'); | |
17231 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8일', '8일'); | |
17232 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9일', '9일'); | |
17233 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10일', '10일'); | |
17234 | |
17235 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11일', '11일'); | |
17236 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12일', '12일'); | |
17237 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13일', '13일'); | |
17238 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14일', '14일'); | |
17239 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15일', '15일'); | |
17240 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16일', '16일'); | |
17241 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17일', '17일'); | |
17242 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18일', '18일'); | |
17243 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19일', '19일'); | |
17244 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20일', '20일'); | |
17245 | |
17246 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21일', '21일'); | |
17247 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22일', '22일'); | |
17248 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23일', '23일'); | |
17249 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24일', '24일'); | |
17250 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25일', '25일'); | |
17251 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26일', '26일'); | |
17252 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27일', '27일'); | |
17253 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28일', '28일'); | |
17254 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29일', '29일'); | |
17255 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30일', '30일'); | |
17256 | |
17257 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31일', '31일'); | |
17258 }); | |
17259 | |
17260 test('format month', function (assert) { | |
17261 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; | |
17262 for (i = 0; i < expected.length; i++) { | |
17263 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
17264 } | |
17265 }); | |
17266 | |
17267 test('format week', function (assert) { | |
17268 var expected = '일요일 일 일_월요일 월 월_화요일 화 화_수요일 수 수_목요일 목 목_금요일 금 금_토요일 토 토'.split('_'), i; | |
17269 for (i = 0; i < expected.length; i++) { | |
17270 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
17271 } | |
17272 }); | |
17273 | |
17274 test('from', function (assert) { | |
17275 var start = moment([2007, 1, 28]); | |
17276 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), '몇초', '44초 = 몇초'); | |
17277 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '일분', '45초 = 일분'); | |
17278 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '일분', '89초 = 일분'); | |
17279 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2분', '90초 = 2분'); | |
17280 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44분', '44분 = 44분'); | |
17281 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '한시간', '45분 = 한시간'); | |
17282 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '한시간', '89분 = 한시간'); | |
17283 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2시간', '90분 = 2시간'); | |
17284 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5시간', '5시간 = 5시간'); | |
17285 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21시간', '21시간 = 21시간'); | |
17286 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '하루', '22시간 = 하루'); | |
17287 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '하루', '35시간 = 하루'); | |
17288 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2일', '36시간 = 2일'); | |
17289 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '하루', '하루 = 하루'); | |
17290 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5일', '5일 = 5일'); | |
17291 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25일', '25일 = 25일'); | |
17292 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '한달', '26일 = 한달'); | |
17293 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '한달', '30일 = 한달'); | |
17294 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '한달', '45일 = 한달'); | |
17295 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2달', '46일 = 2달'); | |
17296 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2달', '75일 = 2달'); | |
17297 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3달', '76일 = 3달'); | |
17298 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '한달', '1달 = 한달'); | |
17299 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5달', '5달 = 5달'); | |
17300 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '일년', '345일 = 일년'); | |
17301 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2년', '548일 = 2년'); | |
17302 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '일년', '일년 = 일년'); | |
17303 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5년', '5년 = 5년'); | |
17304 }); | |
17305 | |
17306 test('suffix', function (assert) { | |
17307 assert.equal(moment(30000).from(0), '몇초 후', 'prefix'); | |
17308 assert.equal(moment(0).from(30000), '몇초 전', 'suffix'); | |
17309 }); | |
17310 | |
17311 test('now from now', function (assert) { | |
17312 assert.equal(moment().fromNow(), '몇초 전', 'now from now should display as in the past'); | |
17313 }); | |
17314 | |
17315 test('fromNow', function (assert) { | |
17316 assert.equal(moment().add({s: 30}).fromNow(), '몇초 후', 'in a few seconds'); | |
17317 assert.equal(moment().add({d: 5}).fromNow(), '5일 후', 'in 5 days'); | |
17318 }); | |
17319 | |
17320 test('calendar day', function (assert) { | |
17321 var a = moment().hours(2).minutes(0).seconds(0); | |
17322 | |
17323 assert.equal(moment(a).calendar(), '오늘 오전 2시 0분', 'today at the same time'); | |
17324 assert.equal(moment(a).add({m: 25}).calendar(), '오늘 오전 2시 25분', 'Now plus 25 min'); | |
17325 assert.equal(moment(a).add({h: 1}).calendar(), '오늘 오전 3시 0분', 'Now plus 1 hour'); | |
17326 assert.equal(moment(a).add({d: 1}).calendar(), '내일 오전 2시 0분', 'tomorrow at the same time'); | |
17327 assert.equal(moment(a).subtract({h: 1}).calendar(), '오늘 오전 1시 0분', 'Now minus 1 hour'); | |
17328 assert.equal(moment(a).subtract({d: 1}).calendar(), '어제 오전 2시 0분', 'yesterday at the same time'); | |
17329 }); | |
17330 | |
17331 test('calendar next week', function (assert) { | |
17332 var i, m; | |
17333 for (i = 2; i < 7; i++) { | |
17334 m = moment().add({d: i}); | |
17335 assert.equal(m.calendar(), m.format('dddd LT'), 'Today + ' + i + ' days current time'); | |
17336 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
17337 assert.equal(m.calendar(), m.format('dddd LT'), 'Today + ' + i + ' days beginning of day'); | |
17338 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
17339 assert.equal(m.calendar(), m.format('dddd LT'), 'Today + ' + i + ' days end of day'); | |
17340 } | |
17341 }); | |
17342 | |
17343 test('calendar last week', function (assert) { | |
17344 var i, m; | |
17345 for (i = 2; i < 7; i++) { | |
17346 m = moment().subtract({d: i}); | |
17347 assert.equal(m.calendar(), m.format('지난주 dddd LT'), 'Today - ' + i + ' days current time'); | |
17348 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
17349 assert.equal(m.calendar(), m.format('지난주 dddd LT'), 'Today - ' + i + ' days beginning of day'); | |
17350 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
17351 assert.equal(m.calendar(), m.format('지난주 dddd LT'), 'Today - ' + i + ' days end of day'); | |
17352 } | |
17353 }); | |
17354 | |
17355 test('calendar all else', function (assert) { | |
17356 var weeksAgo = moment().subtract({w: 1}), | |
17357 weeksFromNow = moment().add({w: 1}); | |
17358 | |
17359 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
17360 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
17361 | |
17362 weeksAgo = moment().subtract({w: 2}); | |
17363 weeksFromNow = moment().add({w: 2}); | |
17364 | |
17365 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
17366 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
17367 }); | |
17368 | |
17369 test('weeks year starting sunday', function (assert) { | |
17370 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
17371 assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1'); | |
17372 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
17373 assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2'); | |
17374 assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3'); | |
17375 }); | |
17376 | |
17377 test('weeks year starting monday', function (assert) { | |
17378 assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1'); | |
17379 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
17380 assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1'); | |
17381 assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2'); | |
17382 assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2'); | |
17383 assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3'); | |
17384 }); | |
17385 | |
17386 test('weeks year starting tuesday', function (assert) { | |
17387 assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52'); | |
17388 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
17389 assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1'); | |
17390 assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2'); | |
17391 assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2'); | |
17392 assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3'); | |
17393 }); | |
17394 | |
17395 test('weeks year starting wednesday', function (assert) { | |
17396 assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1'); | |
17397 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
17398 assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1'); | |
17399 assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2'); | |
17400 assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2'); | |
17401 assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3'); | |
17402 }); | |
17403 | |
17404 test('weeks year starting thursday', function (assert) { | |
17405 assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1'); | |
17406 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
17407 assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1'); | |
17408 assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2'); | |
17409 assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2'); | |
17410 assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3'); | |
17411 }); | |
17412 | |
17413 test('weeks year starting friday', function (assert) { | |
17414 assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1'); | |
17415 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
17416 assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1'); | |
17417 assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2'); | |
17418 assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2'); | |
17419 assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3'); | |
17420 }); | |
17421 | |
17422 test('weeks year starting saturday', function (assert) { | |
17423 assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1'); | |
17424 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
17425 assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2'); | |
17426 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2'); | |
17427 assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3'); | |
17428 }); | |
17429 | |
17430 test('weeks year starting sunday format', function (assert) { | |
17431 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1일', 'Jan 1 2012 should be week 1'); | |
17432 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1일', 'Jan 7 2012 should be week 1'); | |
17433 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2일', 'Jan 8 2012 should be week 2'); | |
17434 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2일', 'Jan 14 2012 should be week 2'); | |
17435 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3일', 'Jan 15 2012 should be week 3'); | |
17436 }); | |
17437 | |
17438 test('lenient ordinal parsing', function (assert) { | |
17439 var i, ordinalStr, testMoment; | |
17440 for (i = 1; i <= 31; ++i) { | |
17441 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
17442 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
17443 assert.equal(testMoment.year(), 2014, | |
17444 'lenient ordinal parsing ' + i + ' year check'); | |
17445 assert.equal(testMoment.month(), 0, | |
17446 'lenient ordinal parsing ' + i + ' month check'); | |
17447 assert.equal(testMoment.date(), i, | |
17448 'lenient ordinal parsing ' + i + ' date check'); | |
17449 } | |
17450 }); | |
17451 | |
17452 test('lenient ordinal parsing of number', function (assert) { | |
17453 var i, testMoment; | |
17454 for (i = 1; i <= 31; ++i) { | |
17455 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
17456 assert.equal(testMoment.year(), 2014, | |
17457 'lenient ordinal parsing of number ' + i + ' year check'); | |
17458 assert.equal(testMoment.month(), 0, | |
17459 'lenient ordinal parsing of number ' + i + ' month check'); | |
17460 assert.equal(testMoment.date(), i, | |
17461 'lenient ordinal parsing of number ' + i + ' date check'); | |
17462 } | |
17463 }); | |
17464 | |
17465 test('strict ordinal parsing', function (assert) { | |
17466 var i, ordinalStr, testMoment; | |
17467 for (i = 1; i <= 31; ++i) { | |
17468 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
17469 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
17470 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
17471 } | |
17472 }); | |
17473 | |
17474 })); | |
17475 | |
17476 (function (global, factory) { | |
17477 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
17478 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
17479 factory(global.moment) | |
17480 }(this, function (moment) { 'use strict'; | |
17481 | |
17482 /*global QUnit:false*/ | |
17483 | |
17484 var test = QUnit.test; | |
17485 | |
17486 function module (name, lifecycle) { | |
17487 QUnit.module(name, { | |
17488 setup : function () { | |
17489 moment.locale('en'); | |
17490 moment.createFromInputFallback = function () { | |
17491 throw new Error('input not handled by moment'); | |
17492 }; | |
17493 if (lifecycle && lifecycle.setup) { | |
17494 lifecycle.setup(); | |
17495 } | |
17496 }, | |
17497 teardown : function () { | |
17498 if (lifecycle && lifecycle.teardown) { | |
17499 lifecycle.teardown(); | |
17500 } | |
17501 } | |
17502 }); | |
17503 } | |
17504 | |
17505 function localeModule (name, lifecycle) { | |
17506 QUnit.module('locale:' + name, { | |
17507 setup : function () { | |
17508 moment.locale(name); | |
17509 moment.createFromInputFallback = function () { | |
17510 throw new Error('input not handled by moment'); | |
17511 }; | |
17512 if (lifecycle && lifecycle.setup) { | |
17513 lifecycle.setup(); | |
17514 } | |
17515 }, | |
17516 teardown : function () { | |
17517 moment.locale('en'); | |
17518 if (lifecycle && lifecycle.teardown) { | |
17519 lifecycle.teardown(); | |
17520 } | |
17521 } | |
17522 }); | |
17523 } | |
17524 | |
17525 localeModule('lb'); | |
17526 | |
17527 test('parse', function (assert) { | |
17528 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; | |
17529 | |
17530 function equalTest(input, mmm, i) { | |
17531 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
17532 } | |
17533 | |
17534 for (i = 0; i < 12; i++) { | |
17535 tests[i] = tests[i].split(' '); | |
17536 equalTest(tests[i][0], 'MMM', i); | |
17537 equalTest(tests[i][1], 'MMM', i); | |
17538 equalTest(tests[i][0], 'MMMM', i); | |
17539 equalTest(tests[i][1], 'MMMM', i); | |
17540 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
17541 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
17542 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
17543 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
17544 } | |
17545 }); | |
17546 | |
17547 test('format', function (assert) { | |
17548 var a = [ | |
17549 ['dddd, Do MMMM YYYY, HH:mm:ss', 'Sonndeg, 14. Februar 2010, 15:25:50'], | |
17550 ['ddd, HH:mm', 'So., 15:25'], | |
17551 ['M Mo MM MMMM MMM', '2 2. 02 Februar Febr.'], | |
17552 ['YYYY YY', '2010 10'], | |
17553 ['D Do DD', '14 14. 14'], | |
17554 ['d do dddd ddd dd', '0 0. Sonndeg So. So'], | |
17555 ['DDD DDDo DDDD', '45 45. 045'], | |
17556 ['w wo ww', '6 6. 06'], | |
17557 ['h hh', '3 03'], | |
17558 ['H HH', '15 15'], | |
17559 ['m mm', '25 25'], | |
17560 ['s ss', '50 50'], | |
17561 ['a A', 'pm PM'], | |
17562 ['[the] DDDo [day of the year]', 'the 45. day of the year'], | |
17563 ['LTS', '15:25:50 Auer'], | |
17564 ['L', '14.02.2010'], | |
17565 ['LL', '14. Februar 2010'], | |
17566 ['LLL', '14. Februar 2010 15:25 Auer'], | |
17567 ['LLLL', 'Sonndeg, 14. Februar 2010 15:25 Auer'], | |
17568 ['l', '14.2.2010'], | |
17569 ['ll', '14. Febr. 2010'], | |
17570 ['lll', '14. Febr. 2010 15:25 Auer'], | |
17571 ['llll', 'So., 14. Febr. 2010 15:25 Auer'] | |
17572 ], | |
17573 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
17574 i; | |
17575 for (i = 0; i < a.length; i++) { | |
17576 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
17577 } | |
17578 }); | |
17579 | |
17580 test('format month', function (assert) { | |
17581 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; | |
17582 for (i = 0; i < expected.length; i++) { | |
17583 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
17584 } | |
17585 }); | |
17586 | |
17587 test('format week', function (assert) { | |
17588 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; | |
17589 for (i = 0; i < expected.length; i++) { | |
17590 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
17591 } | |
17592 }); | |
17593 | |
17594 test('from', function (assert) { | |
17595 var start = moment([2007, 1, 28]); | |
17596 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'e puer Sekonnen', '44 seconds = a few seconds'); | |
17597 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'eng Minutt', '45 seconds = a minute'); | |
17598 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'eng Minutt', '89 seconds = a minute'); | |
17599 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 Minutten', '90 seconds = 2 minutes'); | |
17600 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 Minutten', '44 minutes = 44 minutes'); | |
17601 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'eng Stonn', '45 minutes = an hour'); | |
17602 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'eng Stonn', '89 minutes = an hour'); | |
17603 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 Stonnen', '90 minutes = 2 hours'); | |
17604 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 Stonnen', '5 hours = 5 hours'); | |
17605 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 Stonnen', '21 hours = 21 hours'); | |
17606 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'een Dag', '22 hours = a day'); | |
17607 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'een Dag', '35 hours = a day'); | |
17608 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 Deeg', '36 hours = 2 days'); | |
17609 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'een Dag', '1 day = a day'); | |
17610 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 Deeg', '5 days = 5 days'); | |
17611 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 Deeg', '25 days = 25 days'); | |
17612 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ee Mount', '26 days = a month'); | |
17613 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ee Mount', '30 days = a month'); | |
17614 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ee Mount', '43 days = a month'); | |
17615 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 Méint', '46 days = 2 months'); | |
17616 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 Méint', '75 days = 2 months'); | |
17617 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 Méint', '76 days = 3 months'); | |
17618 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ee Mount', '1 month = a month'); | |
17619 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 Méint', '5 months = 5 months'); | |
17620 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ee Joer', '345 days = a year'); | |
17621 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 Joer', '548 days = 2 years'); | |
17622 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ee Joer', '1 year = a year'); | |
17623 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 Joer', '5 years = 5 years'); | |
17624 }); | |
17625 | |
17626 test('suffix', function (assert) { | |
17627 assert.equal(moment(30000).from(0), 'an e puer Sekonnen', 'prefix'); | |
17628 assert.equal(moment(0).from(30000), 'virun e puer Sekonnen', 'suffix'); | |
17629 }); | |
17630 | |
17631 test('fromNow', function (assert) { | |
17632 assert.equal(moment().add({s: 30}).fromNow(), 'an e puer Sekonnen', 'in a few seconds'); | |
17633 assert.equal(moment().add({d: 1}).fromNow(), 'an engem Dag', 'in one day'); | |
17634 assert.equal(moment().add({d: 2}).fromNow(), 'an 2 Deeg', 'in 2 days'); | |
17635 assert.equal(moment().add({d: 3}).fromNow(), 'an 3 Deeg', 'in 3 days'); | |
17636 assert.equal(moment().add({d: 4}).fromNow(), 'a 4 Deeg', 'in 4 days'); | |
17637 assert.equal(moment().add({d: 5}).fromNow(), 'a 5 Deeg', 'in 5 days'); | |
17638 assert.equal(moment().add({d: 6}).fromNow(), 'a 6 Deeg', 'in 6 days'); | |
17639 assert.equal(moment().add({d: 7}).fromNow(), 'a 7 Deeg', 'in 7 days'); | |
17640 assert.equal(moment().add({d: 8}).fromNow(), 'an 8 Deeg', 'in 8 days'); | |
17641 assert.equal(moment().add({d: 9}).fromNow(), 'an 9 Deeg', 'in 9 days'); | |
17642 assert.equal(moment().add({d: 10}).fromNow(), 'an 10 Deeg', 'in 10 days'); | |
17643 assert.equal(moment().add({y: 100}).fromNow(), 'an 100 Joer', 'in 100 years'); | |
17644 assert.equal(moment().add({y: 400}).fromNow(), 'a 400 Joer', 'in 400 years'); | |
17645 }); | |
17646 | |
17647 test('calendar last week', function (assert) { | |
17648 var i, m, weekday, datestring; | |
17649 for (i = 2; i < 7; i++) { | |
17650 m = moment().subtract({d: i}); | |
17651 | |
17652 // Different date string for 'Dënschdeg' (Tuesday) and 'Donneschdeg' (Thursday) | |
17653 weekday = parseInt(m.format('d'), 10); | |
17654 datestring = (weekday === 2 || weekday === 4 ? '[Leschten] dddd [um] LT' : '[Leschte] dddd [um] LT'); | |
17655 | |
17656 assert.equal(m.calendar(), m.format(datestring), 'Today + ' + i + ' days current time'); | |
17657 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
17658 assert.equal(m.calendar(), m.format(datestring), 'Today + ' + i + ' days beginning of day'); | |
17659 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
17660 assert.equal(m.calendar(), m.format(datestring), 'Today + ' + i + ' days end of day'); | |
17661 } | |
17662 }); | |
17663 | |
17664 test('lenient ordinal parsing', function (assert) { | |
17665 var i, ordinalStr, testMoment; | |
17666 for (i = 1; i <= 31; ++i) { | |
17667 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
17668 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
17669 assert.equal(testMoment.year(), 2014, | |
17670 'lenient ordinal parsing ' + i + ' year check'); | |
17671 assert.equal(testMoment.month(), 0, | |
17672 'lenient ordinal parsing ' + i + ' month check'); | |
17673 assert.equal(testMoment.date(), i, | |
17674 'lenient ordinal parsing ' + i + ' date check'); | |
17675 } | |
17676 }); | |
17677 | |
17678 test('lenient ordinal parsing of number', function (assert) { | |
17679 var i, testMoment; | |
17680 for (i = 1; i <= 31; ++i) { | |
17681 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
17682 assert.equal(testMoment.year(), 2014, | |
17683 'lenient ordinal parsing of number ' + i + ' year check'); | |
17684 assert.equal(testMoment.month(), 0, | |
17685 'lenient ordinal parsing of number ' + i + ' month check'); | |
17686 assert.equal(testMoment.date(), i, | |
17687 'lenient ordinal parsing of number ' + i + ' date check'); | |
17688 } | |
17689 }); | |
17690 | |
17691 test('strict ordinal parsing', function (assert) { | |
17692 var i, ordinalStr, testMoment; | |
17693 for (i = 1; i <= 31; ++i) { | |
17694 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
17695 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
17696 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
17697 } | |
17698 }); | |
17699 | |
17700 })); | |
17701 | |
17702 (function (global, factory) { | |
17703 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
17704 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
17705 factory(global.moment) | |
17706 }(this, function (moment) { 'use strict'; | |
17707 | |
17708 /*global QUnit:false*/ | |
17709 | |
17710 var test = QUnit.test; | |
17711 | |
17712 function module (name, lifecycle) { | |
17713 QUnit.module(name, { | |
17714 setup : function () { | |
17715 moment.locale('en'); | |
17716 moment.createFromInputFallback = function () { | |
17717 throw new Error('input not handled by moment'); | |
17718 }; | |
17719 if (lifecycle && lifecycle.setup) { | |
17720 lifecycle.setup(); | |
17721 } | |
17722 }, | |
17723 teardown : function () { | |
17724 if (lifecycle && lifecycle.teardown) { | |
17725 lifecycle.teardown(); | |
17726 } | |
17727 } | |
17728 }); | |
17729 } | |
17730 | |
17731 function localeModule (name, lifecycle) { | |
17732 QUnit.module('locale:' + name, { | |
17733 setup : function () { | |
17734 moment.locale(name); | |
17735 moment.createFromInputFallback = function () { | |
17736 throw new Error('input not handled by moment'); | |
17737 }; | |
17738 if (lifecycle && lifecycle.setup) { | |
17739 lifecycle.setup(); | |
17740 } | |
17741 }, | |
17742 teardown : function () { | |
17743 moment.locale('en'); | |
17744 if (lifecycle && lifecycle.teardown) { | |
17745 lifecycle.teardown(); | |
17746 } | |
17747 } | |
17748 }); | |
17749 } | |
17750 | |
17751 localeModule('lt'); | |
17752 | |
17753 test('parse', function (assert) { | |
17754 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; | |
17755 function equalTest(input, mmm, i) { | |
17756 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
17757 } | |
17758 for (i = 0; i < 12; i++) { | |
17759 tests[i] = tests[i].split(' '); | |
17760 equalTest(tests[i][0], 'MMM', i); | |
17761 equalTest(tests[i][1], 'MMM', i); | |
17762 equalTest(tests[i][0], 'MMMM', i); | |
17763 equalTest(tests[i][1], 'MMMM', i); | |
17764 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
17765 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
17766 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
17767 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
17768 } | |
17769 }); | |
17770 | |
17771 test('format', function (assert) { | |
17772 var a = [ | |
17773 ['dddd, Do MMMM YYYY, h:mm:ss a', 'sekmadienis, 14-oji vasario 2010, 3:25:50 pm'], | |
17774 ['ddd, hA', 'Sek, 3PM'], | |
17775 ['M Mo MM MMMM MMM', '2 2-oji 02 vasaris vas'], | |
17776 ['YYYY YY', '2010 10'], | |
17777 ['D Do DD', '14 14-oji 14'], | |
17778 ['d do dddd ddd dd', '0 0-oji sekmadienis Sek S'], | |
17779 ['DDD DDDo DDDD', '45 45-oji 045'], | |
17780 ['w wo ww', '6 6-oji 06'], | |
17781 ['h hh', '3 03'], | |
17782 ['H HH', '15 15'], | |
17783 ['m mm', '25 25'], | |
17784 ['s ss', '50 50'], | |
17785 ['a A', 'pm PM'], | |
17786 ['DDDo [metų diena]', '45-oji metų diena'], | |
17787 ['LTS', '15:25:50'], | |
17788 ['L', '2010-02-14'], | |
17789 ['LL', '2010 m. vasaris 14 d.'], | |
17790 ['LLL', '2010 m. vasaris 14 d., 15:25 val.'], | |
17791 ['LLLL', '2010 m. vasaris 14 d., sekmadienis, 15:25 val.'], | |
17792 ['l', '2010-02-14'], | |
17793 ['ll', '2010 m. vasaris 14 d.'], | |
17794 ['lll', '2010 m. vasaris 14 d., 15:25 val.'], | |
17795 ['llll', '2010 m. vasaris 14 d., Sek, 15:25 val.'] | |
17796 ], | |
17797 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
17798 i; | |
17799 for (i = 0; i < a.length; i++) { | |
17800 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
17801 } | |
17802 }); | |
17803 | |
17804 test('format ordinal', function (assert) { | |
17805 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-oji', '1-oji'); | |
17806 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-oji', '2-oji'); | |
17807 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-oji', '3-oji'); | |
17808 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-oji', '4-oji'); | |
17809 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-oji', '5-oji'); | |
17810 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-oji', '6-oji'); | |
17811 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-oji', '7-oji'); | |
17812 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-oji', '8-oji'); | |
17813 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-oji', '9-oji'); | |
17814 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-oji', '10-oji'); | |
17815 | |
17816 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-oji', '11-oji'); | |
17817 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-oji', '12-oji'); | |
17818 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-oji', '13-oji'); | |
17819 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-oji', '14-oji'); | |
17820 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-oji', '15-oji'); | |
17821 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-oji', '16-oji'); | |
17822 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-oji', '17-oji'); | |
17823 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-oji', '18-oji'); | |
17824 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-oji', '19-oji'); | |
17825 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-oji', '20-oji'); | |
17826 | |
17827 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-oji', '21-oji'); | |
17828 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-oji', '22-oji'); | |
17829 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-oji', '23-oji'); | |
17830 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-oji', '24-oji'); | |
17831 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-oji', '25-oji'); | |
17832 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-oji', '26-oji'); | |
17833 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-oji', '27-oji'); | |
17834 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-oji', '28-oji'); | |
17835 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-oji', '29-oji'); | |
17836 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-oji', '30-oji'); | |
17837 | |
17838 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-oji', '31-oji'); | |
17839 }); | |
17840 | |
17841 test('format month', function (assert) { | |
17842 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; | |
17843 for (i = 0; i < expected.length; i++) { | |
17844 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
17845 } | |
17846 }); | |
17847 | |
17848 test('format week', function (assert) { | |
17849 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; | |
17850 for (i = 0; i < expected.length; i++) { | |
17851 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
17852 } | |
17853 }); | |
17854 | |
17855 test('format week on US calendar', function (assert) { | |
17856 // Tests, whether the weekday names are correct, even if the week does not start on Monday | |
17857 moment.locale('lt', {week: {dow: 0, doy: 6}}); | |
17858 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; | |
17859 for (i = 0; i < expected.length; i++) { | |
17860 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
17861 } | |
17862 moment.locale('lt', {week: {dow: 1, doy: 4}}); | |
17863 }); | |
17864 | |
17865 test('from', function (assert) { | |
17866 var start = moment([2007, 1, 28]); | |
17867 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'kelios sekundės', '44 seconds = seconds'); | |
17868 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minutė', '45 seconds = a minute'); | |
17869 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minutė', '89 seconds = a minute'); | |
17870 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutės', '90 seconds = 2 minutes'); | |
17871 assert.equal(start.from(moment([2007, 1, 28]).add({m: 10}), true), '10 minučių', '10 minutes = 10 minutes'); | |
17872 assert.equal(start.from(moment([2007, 1, 28]).add({m: 11}), true), '11 minučių', '11 minutes = 11 minutes'); | |
17873 assert.equal(start.from(moment([2007, 1, 28]).add({m: 19}), true), '19 minučių', '19 minutes = 19 minutes'); | |
17874 assert.equal(start.from(moment([2007, 1, 28]).add({m: 20}), true), '20 minučių', '20 minutes = 20 minutes'); | |
17875 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutės', '44 minutes = 44 minutes'); | |
17876 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'valanda', '45 minutes = an hour'); | |
17877 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'valanda', '89 minutes = an hour'); | |
17878 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 valandos', '90 minutes = 2 hours'); | |
17879 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 valandos', '5 hours = 5 hours'); | |
17880 assert.equal(start.from(moment([2007, 1, 28]).add({h: 10}), true), '10 valandų', '10 hours = 10 hours'); | |
17881 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 valandos', '21 hours = 21 hours'); | |
17882 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'diena', '22 hours = a day'); | |
17883 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'diena', '35 hours = a day'); | |
17884 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dienos', '36 hours = 2 days'); | |
17885 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'diena', '1 day = a day'); | |
17886 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dienos', '5 days = 5 days'); | |
17887 assert.equal(start.from(moment([2007, 1, 28]).add({d: 10}), true), '10 dienų', '10 days = 10 days'); | |
17888 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dienos', '25 days = 25 days'); | |
17889 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mėnuo', '26 days = a month'); | |
17890 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mėnuo', '30 days = a month'); | |
17891 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mėnuo', '43 days = a month'); | |
17892 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mėnesiai', '46 days = 2 months'); | |
17893 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mėnesiai', '75 days = 2 months'); | |
17894 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mėnesiai', '76 days = 3 months'); | |
17895 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mėnuo', '1 month = a month'); | |
17896 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mėnesiai', '5 months = 5 months'); | |
17897 assert.equal(start.from(moment([2007, 1, 28]).add({M: 10}), true), '10 mėnesių', '10 months = 10 months'); | |
17898 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'metai', '345 days = a year'); | |
17899 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 metai', '548 days = 2 years'); | |
17900 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'metai', '1 year = a year'); | |
17901 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 metai', '5 years = 5 years'); | |
17902 }); | |
17903 | |
17904 test('suffix', function (assert) { | |
17905 assert.equal(moment(30000).from(0), 'po kelių sekundžių', 'prefix'); | |
17906 assert.equal(moment(0).from(30000), 'prieš kelias sekundes', 'suffix'); | |
17907 }); | |
17908 | |
17909 test('now from now', function (assert) { | |
17910 assert.equal(moment().fromNow(), 'prieš kelias sekundes', 'now from now should display as in the past'); | |
17911 }); | |
17912 | |
17913 test('fromNow', function (assert) { | |
17914 assert.equal(moment().add({s: 30}).fromNow(), 'po kelių sekundžių', 'in seconds'); | |
17915 assert.equal(moment().add({d: 5}).fromNow(), 'po 5 dienų', 'in 5 days'); | |
17916 }); | |
17917 | |
17918 test('calendar day', function (assert) { | |
17919 var a = moment().hours(2).minutes(0).seconds(0); | |
17920 | |
17921 assert.equal(moment(a).calendar(), 'Šiandien 02:00', 'today at the same time'); | |
17922 assert.equal(moment(a).add({m: 25}).calendar(), 'Šiandien 02:25', 'Now plus 25 min'); | |
17923 assert.equal(moment(a).add({h: 1}).calendar(), 'Šiandien 03:00', 'Now plus 1 hour'); | |
17924 assert.equal(moment(a).add({d: 1}).calendar(), 'Rytoj 02:00', 'tomorrow at the same time'); | |
17925 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Šiandien 01:00', 'Now minus 1 hour'); | |
17926 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Vakar 02:00', 'yesterday at the same time'); | |
17927 }); | |
17928 | |
17929 test('calendar next week', function (assert) { | |
17930 var i, m; | |
17931 for (i = 2; i < 7; i++) { | |
17932 m = moment().add({d: i}); | |
17933 assert.equal(m.calendar(), m.format('dddd LT'), 'Today + ' + i + ' days current time'); | |
17934 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
17935 assert.equal(m.calendar(), m.format('dddd LT'), 'Today + ' + i + ' days beginning of day'); | |
17936 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
17937 assert.equal(m.calendar(), m.format('dddd LT'), 'Today + ' + i + ' days end of day'); | |
17938 } | |
17939 }); | |
17940 | |
17941 test('calendar last week', function (assert) { | |
17942 var i, m; | |
17943 for (i = 2; i < 7; i++) { | |
17944 m = moment().subtract({d: i}); | |
17945 assert.equal(m.calendar(), m.format('[Praėjusį] dddd LT'), 'Today - ' + i + ' days current time'); | |
17946 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
17947 assert.equal(m.calendar(), m.format('[Praėjusį] dddd LT'), 'Today - ' + i + ' days beginning of day'); | |
17948 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
17949 assert.equal(m.calendar(), m.format('[Praėjusį] dddd LT'), 'Today - ' + i + ' days end of day'); | |
17950 } | |
17951 }); | |
17952 | |
17953 test('calendar all else', function (assert) { | |
17954 var weeksAgo = moment().subtract({w: 1}), | |
17955 weeksFromNow = moment().add({w: 1}); | |
17956 | |
17957 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
17958 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
17959 | |
17960 weeksAgo = moment().subtract({w: 2}); | |
17961 weeksFromNow = moment().add({w: 2}); | |
17962 | |
17963 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
17964 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
17965 }); | |
17966 | |
17967 test('weeks year starting sunday', function (assert) { | |
17968 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
17969 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
17970 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
17971 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
17972 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
17973 }); | |
17974 | |
17975 test('weeks year starting monday', function (assert) { | |
17976 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
17977 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
17978 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
17979 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
17980 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
17981 }); | |
17982 | |
17983 test('weeks year starting tuesday', function (assert) { | |
17984 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
17985 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
17986 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
17987 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
17988 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
17989 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
17990 }); | |
17991 | |
17992 test('weeks year starting wednesday', function (assert) { | |
17993 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
17994 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
17995 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
17996 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
17997 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
17998 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
17999 }); | |
18000 | |
18001 test('weeks year starting thursday', function (assert) { | |
18002 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
18003 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
18004 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
18005 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
18006 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
18007 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
18008 }); | |
18009 | |
18010 test('weeks year starting friday', function (assert) { | |
18011 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
18012 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
18013 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
18014 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
18015 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
18016 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
18017 }); | |
18018 | |
18019 test('weeks year starting saturday', function (assert) { | |
18020 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
18021 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
18022 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
18023 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
18024 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
18025 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
18026 }); | |
18027 | |
18028 test('weeks year starting sunday formatted', function (assert) { | |
18029 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52-oji', 'Jan 1 2012 should be week 52'); | |
18030 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1-oji', 'Jan 2 2012 should be week 1'); | |
18031 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1-oji', 'Jan 8 2012 should be week 1'); | |
18032 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2-oji', 'Jan 9 2012 should be week 2'); | |
18033 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2-oji', 'Jan 15 2012 should be week 2'); | |
18034 }); | |
18035 | |
18036 test('lenient ordinal parsing', function (assert) { | |
18037 var i, ordinalStr, testMoment; | |
18038 for (i = 1; i <= 31; ++i) { | |
18039 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
18040 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
18041 assert.equal(testMoment.year(), 2014, | |
18042 'lenient ordinal parsing ' + i + ' year check'); | |
18043 assert.equal(testMoment.month(), 0, | |
18044 'lenient ordinal parsing ' + i + ' month check'); | |
18045 assert.equal(testMoment.date(), i, | |
18046 'lenient ordinal parsing ' + i + ' date check'); | |
18047 } | |
18048 }); | |
18049 | |
18050 test('lenient ordinal parsing of number', function (assert) { | |
18051 var i, testMoment; | |
18052 for (i = 1; i <= 31; ++i) { | |
18053 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
18054 assert.equal(testMoment.year(), 2014, | |
18055 'lenient ordinal parsing of number ' + i + ' year check'); | |
18056 assert.equal(testMoment.month(), 0, | |
18057 'lenient ordinal parsing of number ' + i + ' month check'); | |
18058 assert.equal(testMoment.date(), i, | |
18059 'lenient ordinal parsing of number ' + i + ' date check'); | |
18060 } | |
18061 }); | |
18062 | |
18063 test('strict ordinal parsing', function (assert) { | |
18064 var i, ordinalStr, testMoment; | |
18065 for (i = 1; i <= 31; ++i) { | |
18066 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
18067 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
18068 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
18069 } | |
18070 }); | |
18071 | |
18072 })); | |
18073 | |
18074 (function (global, factory) { | |
18075 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
18076 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
18077 factory(global.moment) | |
18078 }(this, function (moment) { 'use strict'; | |
18079 | |
18080 /*global QUnit:false*/ | |
18081 | |
18082 var test = QUnit.test; | |
18083 | |
18084 function module (name, lifecycle) { | |
18085 QUnit.module(name, { | |
18086 setup : function () { | |
18087 moment.locale('en'); | |
18088 moment.createFromInputFallback = function () { | |
18089 throw new Error('input not handled by moment'); | |
18090 }; | |
18091 if (lifecycle && lifecycle.setup) { | |
18092 lifecycle.setup(); | |
18093 } | |
18094 }, | |
18095 teardown : function () { | |
18096 if (lifecycle && lifecycle.teardown) { | |
18097 lifecycle.teardown(); | |
18098 } | |
18099 } | |
18100 }); | |
18101 } | |
18102 | |
18103 function localeModule (name, lifecycle) { | |
18104 QUnit.module('locale:' + name, { | |
18105 setup : function () { | |
18106 moment.locale(name); | |
18107 moment.createFromInputFallback = function () { | |
18108 throw new Error('input not handled by moment'); | |
18109 }; | |
18110 if (lifecycle && lifecycle.setup) { | |
18111 lifecycle.setup(); | |
18112 } | |
18113 }, | |
18114 teardown : function () { | |
18115 moment.locale('en'); | |
18116 if (lifecycle && lifecycle.teardown) { | |
18117 lifecycle.teardown(); | |
18118 } | |
18119 } | |
18120 }); | |
18121 } | |
18122 | |
18123 localeModule('lv'); | |
18124 | |
18125 test('parse', function (assert) { | |
18126 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; | |
18127 function equalTest(input, mmm, i) { | |
18128 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
18129 } | |
18130 for (i = 0; i < 12; i++) { | |
18131 tests[i] = tests[i].split(' '); | |
18132 equalTest(tests[i][0], 'MMM', i); | |
18133 equalTest(tests[i][1], 'MMM', i); | |
18134 equalTest(tests[i][0], 'MMMM', i); | |
18135 equalTest(tests[i][1], 'MMMM', i); | |
18136 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
18137 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
18138 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
18139 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
18140 } | |
18141 }); | |
18142 | |
18143 test('format', function (assert) { | |
18144 var a = [ | |
18145 ['dddd, Do MMMM YYYY, h:mm:ss a', 'svētdiena, 14. februāris 2010, 3:25:50 pm'], | |
18146 ['ddd, hA', 'Sv, 3PM'], | |
18147 ['M Mo MM MMMM MMM', '2 2. 02 februāris feb'], | |
18148 ['YYYY YY', '2010 10'], | |
18149 ['D Do DD', '14 14. 14'], | |
18150 ['d do dddd ddd dd', '0 0. svētdiena Sv Sv'], | |
18151 ['DDD DDDo DDDD', '45 45. 045'], | |
18152 ['w wo ww', '6 6. 06'], | |
18153 ['h hh', '3 03'], | |
18154 ['H HH', '15 15'], | |
18155 ['m mm', '25 25'], | |
18156 ['s ss', '50 50'], | |
18157 ['a A', 'pm PM'], | |
18158 ['[the] DDDo [day of the year]', 'the 45. day of the year'], | |
18159 ['LTS', '15:25:50'], | |
18160 ['L', '14.02.2010.'], | |
18161 ['LL', '2010. gada 14. februāris'], | |
18162 ['LLL', '2010. gada 14. februāris, 15:25'], | |
18163 ['LLLL', '2010. gada 14. februāris, svētdiena, 15:25'], | |
18164 ['l', '14.2.2010.'], | |
18165 ['ll', '2010. gada 14. feb'], | |
18166 ['lll', '2010. gada 14. feb, 15:25'], | |
18167 ['llll', '2010. gada 14. feb, Sv, 15:25'] | |
18168 ], | |
18169 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
18170 i; | |
18171 for (i = 0; i < a.length; i++) { | |
18172 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
18173 } | |
18174 }); | |
18175 | |
18176 test('format ordinal', function (assert) { | |
18177 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.'); | |
18178 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.'); | |
18179 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.'); | |
18180 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.'); | |
18181 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.'); | |
18182 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.'); | |
18183 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.'); | |
18184 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.'); | |
18185 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.'); | |
18186 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.'); | |
18187 | |
18188 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.'); | |
18189 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.'); | |
18190 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.'); | |
18191 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.'); | |
18192 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.'); | |
18193 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.'); | |
18194 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.'); | |
18195 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.'); | |
18196 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.'); | |
18197 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.'); | |
18198 | |
18199 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.'); | |
18200 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.'); | |
18201 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.'); | |
18202 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.'); | |
18203 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.'); | |
18204 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.'); | |
18205 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.'); | |
18206 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.'); | |
18207 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.'); | |
18208 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.'); | |
18209 | |
18210 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.'); | |
18211 }); | |
18212 | |
18213 test('format month', function (assert) { | |
18214 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; | |
18215 for (i = 0; i < expected.length; i++) { | |
18216 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
18217 } | |
18218 }); | |
18219 | |
18220 test('format week', function (assert) { | |
18221 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; | |
18222 for (i = 0; i < expected.length; i++) { | |
18223 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
18224 } | |
18225 }); | |
18226 | |
18227 // Includes testing the cases of withoutSuffix = true and false. | |
18228 test('from', function (assert) { | |
18229 var start = moment([2007, 1, 28]); | |
18230 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'dažas sekundes', '44 seconds = seconds'); | |
18231 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), false), 'pirms dažām sekundēm', '44 seconds with suffix = seconds ago'); | |
18232 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minūte', '45 seconds = a minute'); | |
18233 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), false), 'pirms minūtes', '45 seconds with suffix = a minute ago'); | |
18234 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minūte', '89 seconds = a minute'); | |
18235 assert.equal(start.from(moment([2007, 1, 28]).add({s: -89}), false), 'pēc minūtes', '89 seconds with suffix/prefix = in a minute'); | |
18236 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minūtes', '90 seconds = 2 minutes'); | |
18237 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), false), 'pirms 2 minūtēm', '90 seconds with suffix = 2 minutes ago'); | |
18238 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minūtes', '44 minutes = 44 minutes'); | |
18239 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), false), 'pirms 44 minūtēm', '44 minutes with suffix = 44 minutes ago'); | |
18240 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'stunda', '45 minutes = an hour'); | |
18241 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), false), 'pirms stundas', '45 minutes with suffix = an hour ago'); | |
18242 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'stunda', '89 minutes = an hour'); | |
18243 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 stundas', '90 minutes = 2 hours'); | |
18244 assert.equal(start.from(moment([2007, 1, 28]).add({m: -90}), false), 'pēc 2 stundām', '90 minutes with suffix = in 2 hours'); | |
18245 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 stundas', '5 hours = 5 hours'); | |
18246 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), false), 'pirms 5 stundām', '5 hours with suffix = 5 hours ago'); | |
18247 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 stunda', '21 hours = 21 hours'); | |
18248 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), false), 'pirms 21 stundas', '21 hours with suffix = 21 hours ago'); | |
18249 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'diena', '22 hours = a day'); | |
18250 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), false), 'pirms dienas', '22 hours with suffix = a day ago'); | |
18251 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'diena', '35 hours = a day'); | |
18252 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dienas', '36 hours = 2 days'); | |
18253 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), false), 'pirms 2 dienām', '36 hours with suffix = 2 days ago'); | |
18254 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'diena', '1 day = a day'); | |
18255 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dienas', '5 days = 5 days'); | |
18256 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), false), 'pirms 5 dienām', '5 days with suffix = 5 days ago'); | |
18257 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dienas', '25 days = 25 days'); | |
18258 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), false), 'pirms 25 dienām', '25 days with suffix = 25 days ago'); | |
18259 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mēnesis', '26 days = a month'); | |
18260 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), false), 'pirms mēneša', '26 days with suffix = a month ago'); | |
18261 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mēnesis', '30 days = a month'); | |
18262 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mēnesis', '43 days = a month'); | |
18263 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mēneši', '46 days = 2 months'); | |
18264 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), false), 'pirms 2 mēnešiem', '46 days with suffix = 2 months ago'); | |
18265 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mēneši', '75 days = 2 months'); | |
18266 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mēneši', '76 days = 3 months'); | |
18267 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), false), 'pirms 3 mēnešiem', '76 days with suffix = 3 months ago'); | |
18268 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mēnesis', '1 month = a month'); | |
18269 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mēneši', '5 months = 5 months'); | |
18270 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), false), 'pirms 5 mēnešiem', '5 months with suffix = 5 months ago'); | |
18271 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'gads', '345 days = a year'); | |
18272 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), false), 'pirms gada', '345 days with suffix = a year ago'); | |
18273 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 gadi', '548 days = 2 years'); | |
18274 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), false), 'pirms 2 gadiem', '548 days with suffix = 2 years ago'); | |
18275 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'gads', '1 year = a year'); | |
18276 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 gadi', '5 years = 5 years'); | |
18277 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), false), 'pirms 5 gadiem', '5 years with suffix = 5 years ago'); | |
18278 }); | |
18279 | |
18280 test('suffix', function (assert) { | |
18281 assert.equal(moment(30000).from(0), 'pēc dažām sekundēm', 'prefix'); | |
18282 assert.equal(moment(0).from(30000), 'pirms dažām sekundēm', 'suffix'); | |
18283 }); | |
18284 | |
18285 test('now from now', function (assert) { | |
18286 assert.equal(moment().fromNow(), 'pirms dažām sekundēm', 'now from now should display as in the past'); | |
18287 }); | |
18288 | |
18289 test('fromNow', function (assert) { | |
18290 assert.equal(moment().add({s: 30}).fromNow(), 'pēc dažām sekundēm', 'in seconds'); | |
18291 assert.equal(moment().add({d: 5}).fromNow(), 'pēc 5 dienām', 'in 5 days'); | |
18292 }); | |
18293 | |
18294 test('calendar day', function (assert) { | |
18295 var a = moment().hours(2).minutes(0).seconds(0); | |
18296 | |
18297 assert.equal(moment(a).calendar(), 'Šodien pulksten 02:00', 'today at the same time'); | |
18298 assert.equal(moment(a).add({m: 25}).calendar(), 'Šodien pulksten 02:25', 'Now plus 25 min'); | |
18299 assert.equal(moment(a).add({h: 1}).calendar(), 'Šodien pulksten 03:00', 'Now plus 1 hour'); | |
18300 assert.equal(moment(a).add({d: 1}).calendar(), 'Rīt pulksten 02:00', 'tomorrow at the same time'); | |
18301 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Šodien pulksten 01:00', 'Now minus 1 hour'); | |
18302 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Vakar pulksten 02:00', 'yesterday at the same time'); | |
18303 }); | |
18304 | |
18305 test('calendar next week', function (assert) { | |
18306 var i, m; | |
18307 for (i = 2; i < 7; i++) { | |
18308 m = moment().add({d: i}); | |
18309 assert.equal(m.calendar(), m.format('dddd [pulksten] LT'), 'Today + ' + i + ' days current time'); | |
18310 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
18311 assert.equal(m.calendar(), m.format('dddd [pulksten] LT'), 'Today + ' + i + ' days beginning of day'); | |
18312 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
18313 assert.equal(m.calendar(), m.format('dddd [pulksten] LT'), 'Today + ' + i + ' days end of day'); | |
18314 } | |
18315 }); | |
18316 | |
18317 test('calendar last week', function (assert) { | |
18318 var i, m; | |
18319 for (i = 2; i < 7; i++) { | |
18320 m = moment().subtract({d: i}); | |
18321 assert.equal(m.calendar(), m.format('[Pagājušā] dddd [pulksten] LT'), 'Today - ' + i + ' days current time'); | |
18322 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
18323 assert.equal(m.calendar(), m.format('[Pagājušā] dddd [pulksten] LT'), 'Today - ' + i + ' days beginning of day'); | |
18324 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
18325 assert.equal(m.calendar(), m.format('[Pagājušā] dddd [pulksten] LT'), 'Today - ' + i + ' days end of day'); | |
18326 } | |
18327 }); | |
18328 | |
18329 test('calendar all else', function (assert) { | |
18330 var weeksAgo = moment().subtract({w: 1}), | |
18331 weeksFromNow = moment().add({w: 1}); | |
18332 | |
18333 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
18334 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
18335 | |
18336 weeksAgo = moment().subtract({w: 2}); | |
18337 weeksFromNow = moment().add({w: 2}); | |
18338 | |
18339 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
18340 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
18341 }); | |
18342 | |
18343 test('weeks year starting sunday', function (assert) { | |
18344 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
18345 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
18346 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
18347 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
18348 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
18349 }); | |
18350 | |
18351 test('weeks year starting monday', function (assert) { | |
18352 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
18353 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
18354 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
18355 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
18356 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
18357 }); | |
18358 | |
18359 test('weeks year starting tuesday', function (assert) { | |
18360 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
18361 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
18362 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
18363 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
18364 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
18365 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
18366 }); | |
18367 | |
18368 test('weeks year starting wednesday', function (assert) { | |
18369 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
18370 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
18371 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
18372 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
18373 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
18374 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
18375 }); | |
18376 | |
18377 test('weeks year starting thursday', function (assert) { | |
18378 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
18379 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
18380 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
18381 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
18382 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
18383 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
18384 }); | |
18385 | |
18386 test('weeks year starting friday', function (assert) { | |
18387 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
18388 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
18389 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
18390 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
18391 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
18392 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
18393 }); | |
18394 | |
18395 test('weeks year starting saturday', function (assert) { | |
18396 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
18397 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
18398 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
18399 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
18400 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
18401 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
18402 }); | |
18403 | |
18404 test('weeks year starting sunday formatted', function (assert) { | |
18405 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52'); | |
18406 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1'); | |
18407 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1'); | |
18408 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2'); | |
18409 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2'); | |
18410 }); | |
18411 | |
18412 test('lenient ordinal parsing', function (assert) { | |
18413 var i, ordinalStr, testMoment; | |
18414 for (i = 1; i <= 31; ++i) { | |
18415 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
18416 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
18417 assert.equal(testMoment.year(), 2014, | |
18418 'lenient ordinal parsing ' + i + ' year check'); | |
18419 assert.equal(testMoment.month(), 0, | |
18420 'lenient ordinal parsing ' + i + ' month check'); | |
18421 assert.equal(testMoment.date(), i, | |
18422 'lenient ordinal parsing ' + i + ' date check'); | |
18423 } | |
18424 }); | |
18425 | |
18426 test('lenient ordinal parsing of number', function (assert) { | |
18427 var i, testMoment; | |
18428 for (i = 1; i <= 31; ++i) { | |
18429 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
18430 assert.equal(testMoment.year(), 2014, | |
18431 'lenient ordinal parsing of number ' + i + ' year check'); | |
18432 assert.equal(testMoment.month(), 0, | |
18433 'lenient ordinal parsing of number ' + i + ' month check'); | |
18434 assert.equal(testMoment.date(), i, | |
18435 'lenient ordinal parsing of number ' + i + ' date check'); | |
18436 } | |
18437 }); | |
18438 | |
18439 test('strict ordinal parsing', function (assert) { | |
18440 var i, ordinalStr, testMoment; | |
18441 for (i = 1; i <= 31; ++i) { | |
18442 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
18443 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
18444 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
18445 } | |
18446 }); | |
18447 | |
18448 })); | |
18449 | |
18450 (function (global, factory) { | |
18451 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
18452 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
18453 factory(global.moment) | |
18454 }(this, function (moment) { 'use strict'; | |
18455 | |
18456 /*global QUnit:false*/ | |
18457 | |
18458 var test = QUnit.test; | |
18459 | |
18460 function module (name, lifecycle) { | |
18461 QUnit.module(name, { | |
18462 setup : function () { | |
18463 moment.locale('en'); | |
18464 moment.createFromInputFallback = function () { | |
18465 throw new Error('input not handled by moment'); | |
18466 }; | |
18467 if (lifecycle && lifecycle.setup) { | |
18468 lifecycle.setup(); | |
18469 } | |
18470 }, | |
18471 teardown : function () { | |
18472 if (lifecycle && lifecycle.teardown) { | |
18473 lifecycle.teardown(); | |
18474 } | |
18475 } | |
18476 }); | |
18477 } | |
18478 | |
18479 function localeModule (name, lifecycle) { | |
18480 QUnit.module('locale:' + name, { | |
18481 setup : function () { | |
18482 moment.locale(name); | |
18483 moment.createFromInputFallback = function () { | |
18484 throw new Error('input not handled by moment'); | |
18485 }; | |
18486 if (lifecycle && lifecycle.setup) { | |
18487 lifecycle.setup(); | |
18488 } | |
18489 }, | |
18490 teardown : function () { | |
18491 moment.locale('en'); | |
18492 if (lifecycle && lifecycle.teardown) { | |
18493 lifecycle.teardown(); | |
18494 } | |
18495 } | |
18496 }); | |
18497 } | |
18498 | |
18499 localeModule('me'); | |
18500 | |
18501 test('parse', function (assert) { | |
18502 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('_'), | |
18503 i; | |
18504 function equalTest(input, mmm, i) { | |
18505 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
18506 } | |
18507 for (i = 0; i < 12; i++) { | |
18508 tests[i] = tests[i].split(' '); | |
18509 equalTest(tests[i][0], 'MMM', i); | |
18510 equalTest(tests[i][1], 'MMM', i); | |
18511 equalTest(tests[i][0], 'MMMM', i); | |
18512 equalTest(tests[i][1], 'MMMM', i); | |
18513 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
18514 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
18515 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
18516 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
18517 } | |
18518 }); | |
18519 | |
18520 test('format', function (assert) { | |
18521 var a = [ | |
18522 ['dddd, Do MMMM YYYY, h:mm:ss a', 'nedjelja, 14. februar 2010, 3:25:50 pm'], | |
18523 ['ddd, hA', 'ned., 3PM'], | |
18524 ['M Mo MM MMMM MMM', '2 2. 02 februar feb.'], | |
18525 ['YYYY YY', '2010 10'], | |
18526 ['D Do DD', '14 14. 14'], | |
18527 ['d do dddd ddd dd', '0 0. nedjelja ned. ne'], | |
18528 ['DDD DDDo DDDD', '45 45. 045'], | |
18529 ['w wo ww', '7 7. 07'], | |
18530 ['h hh', '3 03'], | |
18531 ['H HH', '15 15'], | |
18532 ['m mm', '25 25'], | |
18533 ['s ss', '50 50'], | |
18534 ['a A', 'pm PM'], | |
18535 ['[the] DDDo [day of the year]', 'the 45. day of the year'], | |
18536 ['LTS', '15:25:50'], | |
18537 ['L', '14. 02. 2010'], | |
18538 ['LL', '14. februar 2010'], | |
18539 ['LLL', '14. februar 2010 15:25'], | |
18540 ['LLLL', 'nedjelja, 14. februar 2010 15:25'], | |
18541 ['l', '14. 2. 2010'], | |
18542 ['ll', '14. feb. 2010'], | |
18543 ['lll', '14. feb. 2010 15:25'], | |
18544 ['llll', 'ned., 14. feb. 2010 15:25'] | |
18545 ], | |
18546 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
18547 i; | |
18548 for (i = 0; i < a.length; i++) { | |
18549 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
18550 } | |
18551 }); | |
18552 | |
18553 test('format ordinal', function (assert) { | |
18554 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.'); | |
18555 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.'); | |
18556 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.'); | |
18557 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.'); | |
18558 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.'); | |
18559 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.'); | |
18560 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.'); | |
18561 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.'); | |
18562 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.'); | |
18563 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.'); | |
18564 | |
18565 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.'); | |
18566 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.'); | |
18567 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.'); | |
18568 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.'); | |
18569 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.'); | |
18570 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.'); | |
18571 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.'); | |
18572 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.'); | |
18573 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.'); | |
18574 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.'); | |
18575 | |
18576 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.'); | |
18577 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.'); | |
18578 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.'); | |
18579 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.'); | |
18580 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.'); | |
18581 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.'); | |
18582 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.'); | |
18583 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.'); | |
18584 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.'); | |
18585 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.'); | |
18586 | |
18587 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.'); | |
18588 }); | |
18589 | |
18590 test('format month', function (assert) { | |
18591 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('_'), | |
18592 i; | |
18593 for (i = 0; i < expected.length; i++) { | |
18594 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
18595 } | |
18596 }); | |
18597 | |
18598 test('format week', function (assert) { | |
18599 var expected = 'nedjelja ned. ne_ponedjeljak pon. po_utorak uto. ut_srijeda sri. sr_četvrtak čet. če_petak pet. pe_subota sub. su'.split('_'), | |
18600 i; | |
18601 for (i = 0; i < expected.length; i++) { | |
18602 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
18603 } | |
18604 }); | |
18605 | |
18606 test('from', function (assert) { | |
18607 var start = moment([2007, 1, 28]); | |
18608 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'nekoliko sekundi', '44 seconds = a few seconds'); | |
18609 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'jedan minut', '45 seconds = a minute'); | |
18610 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'jedan minut', '89 seconds = a minute'); | |
18611 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuta', '90 seconds = 2 minutes'); | |
18612 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuta', '44 minutes = 44 minutes'); | |
18613 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'jedan sat', '45 minutes = an hour'); | |
18614 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'jedan sat', '89 minutes = an hour'); | |
18615 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 sata', '90 minutes = 2 hours'); | |
18616 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 sati', '5 hours = 5 hours'); | |
18617 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 sati', '21 hours = 21 hours'); | |
18618 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'dan', '22 hours = a day'); | |
18619 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'dan', '35 hours = a day'); | |
18620 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dana', '36 hours = 2 days'); | |
18621 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'dan', '1 day = a day'); | |
18622 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dana', '5 days = 5 days'); | |
18623 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dana', '25 days = 25 days'); | |
18624 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mjesec', '26 days = a month'); | |
18625 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mjesec', '30 days = a month'); | |
18626 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mjesec', '43 days = a month'); | |
18627 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mjeseca', '46 days = 2 months'); | |
18628 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mjeseca', '75 days = 2 months'); | |
18629 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mjeseca', '76 days = 3 months'); | |
18630 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mjesec', '1 month = a month'); | |
18631 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mjeseci', '5 months = 5 months'); | |
18632 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'godinu', '345 days = a year'); | |
18633 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 godine', '548 days = 2 years'); | |
18634 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'godinu', '1 year = a year'); | |
18635 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 godina', '5 years = 5 years'); | |
18636 }); | |
18637 | |
18638 test('suffix', function (assert) { | |
18639 assert.equal(moment(30000).from(0), 'za nekoliko sekundi', 'prefix'); | |
18640 assert.equal(moment(0).from(30000), 'prije nekoliko sekundi', 'prefix'); | |
18641 }); | |
18642 | |
18643 test('now from now', function (assert) { | |
18644 assert.equal(moment().fromNow(), 'prije nekoliko sekundi', 'now from now should display as in the past'); | |
18645 }); | |
18646 | |
18647 test('fromNow', function (assert) { | |
18648 assert.equal(moment().add({s: 30}).fromNow(), 'za nekoliko sekundi', 'in a few seconds'); | |
18649 assert.equal(moment().add({d: 5}).fromNow(), 'za 5 dana', 'in 5 days'); | |
18650 }); | |
18651 | |
18652 test('calendar day', function (assert) { | |
18653 var a = moment().hours(2).minutes(0).seconds(0); | |
18654 | |
18655 assert.equal(moment(a).calendar(), 'danas u 2:00', 'today at the same time'); | |
18656 assert.equal(moment(a).add({m: 25}).calendar(), 'danas u 2:25', 'Now plus 25 min'); | |
18657 assert.equal(moment(a).add({h: 1}).calendar(), 'danas u 3:00', 'Now plus 1 hour'); | |
18658 assert.equal(moment(a).add({d: 1}).calendar(), 'sjutra u 2:00', 'tomorrow at the same time'); | |
18659 assert.equal(moment(a).subtract({h: 1}).calendar(), 'danas u 1:00', 'Now minus 1 hour'); | |
18660 assert.equal(moment(a).subtract({d: 1}).calendar(), 'juče u 2:00', 'yesterday at the same time'); | |
18661 }); | |
18662 | |
18663 test('calendar next week', function (assert) { | |
18664 var i, m; | |
18665 | |
18666 function makeFormat(d) { | |
18667 switch (d.day()) { | |
18668 case 0: | |
18669 return '[u] [nedjelju] [u] LT'; | |
18670 case 3: | |
18671 return '[u] [srijedu] [u] LT'; | |
18672 case 6: | |
18673 return '[u] [subotu] [u] LT'; | |
18674 case 1: | |
18675 case 2: | |
18676 case 4: | |
18677 case 5: | |
18678 return '[u] dddd [u] LT'; | |
18679 } | |
18680 } | |
18681 | |
18682 for (i = 2; i < 7; i++) { | |
18683 m = moment().add({d: i}); | |
18684 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time'); | |
18685 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
18686 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day'); | |
18687 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
18688 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day'); | |
18689 } | |
18690 }); | |
18691 | |
18692 test('calendar last week', function (assert) { | |
18693 var i, m; | |
18694 | |
18695 function makeFormat(d) { | |
18696 var lastWeekDay = [ | |
18697 '[prošle] [nedjelje] [u] LT', | |
18698 '[prošlog] [ponedjeljka] [u] LT', | |
18699 '[prošlog] [utorka] [u] LT', | |
18700 '[prošle] [srijede] [u] LT', | |
18701 '[prošlog] [četvrtka] [u] LT', | |
18702 '[prošlog] [petka] [u] LT', | |
18703 '[prošle] [subote] [u] LT' | |
18704 ]; | |
18705 | |
18706 return lastWeekDay[d.day()]; | |
18707 } | |
18708 | |
18709 for (i = 2; i < 7; i++) { | |
18710 m = moment().subtract({d: i}); | |
18711 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time'); | |
18712 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
18713 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day'); | |
18714 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
18715 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day'); | |
18716 } | |
18717 }); | |
18718 | |
18719 test('calendar all else', function (assert) { | |
18720 var weeksAgo = moment().subtract({w: 1}), | |
18721 weeksFromNow = moment().add({w: 1}); | |
18722 | |
18723 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
18724 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
18725 | |
18726 weeksAgo = moment().subtract({w: 2}); | |
18727 weeksFromNow = moment().add({w: 2}); | |
18728 | |
18729 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
18730 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
18731 }); | |
18732 | |
18733 // Monday is the first day of the week. | |
18734 // The week that contains Jan 1st is the first week of the year. | |
18735 | |
18736 test('weeks year starting sunday', function (assert) { | |
18737 assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1'); | |
18738 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
18739 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2'); | |
18740 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
18741 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3'); | |
18742 }); | |
18743 | |
18744 test('weeks year starting monday', function (assert) { | |
18745 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
18746 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
18747 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
18748 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
18749 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
18750 }); | |
18751 | |
18752 test('weeks year starting tuesday', function (assert) { | |
18753 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
18754 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
18755 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
18756 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
18757 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
18758 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
18759 }); | |
18760 | |
18761 test('weeks year starting wednesday', function (assert) { | |
18762 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
18763 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
18764 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
18765 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
18766 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
18767 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
18768 }); | |
18769 | |
18770 test('weeks year starting thursday', function (assert) { | |
18771 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
18772 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
18773 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
18774 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
18775 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
18776 assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3'); | |
18777 }); | |
18778 | |
18779 test('weeks year starting friday', function (assert) { | |
18780 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1'); | |
18781 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
18782 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1'); | |
18783 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2'); | |
18784 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2'); | |
18785 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3'); | |
18786 }); | |
18787 | |
18788 test('weeks year starting saturday', function (assert) { | |
18789 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1'); | |
18790 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
18791 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1'); | |
18792 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2'); | |
18793 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2'); | |
18794 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3'); | |
18795 }); | |
18796 | |
18797 test('weeks year starting sunday formatted', function (assert) { | |
18798 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', 'Dec 26 2011 should be week 1'); | |
18799 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1.', 'Jan 1 2012 should be week 1'); | |
18800 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2.', 'Jan 2 2012 should be week 2'); | |
18801 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2.', 'Jan 8 2012 should be week 2'); | |
18802 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3.', 'Jan 9 2012 should be week 3'); | |
18803 }); | |
18804 | |
18805 test('lenient ordinal parsing', function (assert) { | |
18806 var i, ordinalStr, testMoment; | |
18807 for (i = 1; i <= 31; ++i) { | |
18808 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
18809 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
18810 assert.equal(testMoment.year(), 2014, | |
18811 'lenient ordinal parsing ' + i + ' year check'); | |
18812 assert.equal(testMoment.month(), 0, | |
18813 'lenient ordinal parsing ' + i + ' month check'); | |
18814 assert.equal(testMoment.date(), i, | |
18815 'lenient ordinal parsing ' + i + ' date check'); | |
18816 } | |
18817 }); | |
18818 | |
18819 test('lenient ordinal parsing of number', function (assert) { | |
18820 var i, testMoment; | |
18821 for (i = 1; i <= 31; ++i) { | |
18822 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
18823 assert.equal(testMoment.year(), 2014, | |
18824 'lenient ordinal parsing of number ' + i + ' year check'); | |
18825 assert.equal(testMoment.month(), 0, | |
18826 'lenient ordinal parsing of number ' + i + ' month check'); | |
18827 assert.equal(testMoment.date(), i, | |
18828 'lenient ordinal parsing of number ' + i + ' date check'); | |
18829 } | |
18830 }); | |
18831 | |
18832 test('strict ordinal parsing', function (assert) { | |
18833 var i, ordinalStr, testMoment; | |
18834 for (i = 1; i <= 31; ++i) { | |
18835 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
18836 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
18837 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
18838 } | |
18839 }); | |
18840 | |
18841 })); | |
18842 | |
18843 (function (global, factory) { | |
18844 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
18845 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
18846 factory(global.moment) | |
18847 }(this, function (moment) { 'use strict'; | |
18848 | |
18849 /*global QUnit:false*/ | |
18850 | |
18851 var test = QUnit.test; | |
18852 | |
18853 function module (name, lifecycle) { | |
18854 QUnit.module(name, { | |
18855 setup : function () { | |
18856 moment.locale('en'); | |
18857 moment.createFromInputFallback = function () { | |
18858 throw new Error('input not handled by moment'); | |
18859 }; | |
18860 if (lifecycle && lifecycle.setup) { | |
18861 lifecycle.setup(); | |
18862 } | |
18863 }, | |
18864 teardown : function () { | |
18865 if (lifecycle && lifecycle.teardown) { | |
18866 lifecycle.teardown(); | |
18867 } | |
18868 } | |
18869 }); | |
18870 } | |
18871 | |
18872 function localeModule (name, lifecycle) { | |
18873 QUnit.module('locale:' + name, { | |
18874 setup : function () { | |
18875 moment.locale(name); | |
18876 moment.createFromInputFallback = function () { | |
18877 throw new Error('input not handled by moment'); | |
18878 }; | |
18879 if (lifecycle && lifecycle.setup) { | |
18880 lifecycle.setup(); | |
18881 } | |
18882 }, | |
18883 teardown : function () { | |
18884 moment.locale('en'); | |
18885 if (lifecycle && lifecycle.teardown) { | |
18886 lifecycle.teardown(); | |
18887 } | |
18888 } | |
18889 }); | |
18890 } | |
18891 | |
18892 localeModule('mk'); | |
18893 | |
18894 test('parse', function (assert) { | |
18895 var tests = 'јануари јан_февруари фев_март мар_април апр_мај мај_јуни јун_јули јул_август авг_септември сеп_октомври окт_ноември ное_декември дек'.split('_'), i; | |
18896 function equalTest(input, mmm, i) { | |
18897 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
18898 } | |
18899 for (i = 0; i < 12; i++) { | |
18900 tests[i] = tests[i].split(' '); | |
18901 equalTest(tests[i][0], 'MMM', i); | |
18902 equalTest(tests[i][1], 'MMM', i); | |
18903 equalTest(tests[i][0], 'MMMM', i); | |
18904 equalTest(tests[i][1], 'MMMM', i); | |
18905 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
18906 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
18907 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
18908 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
18909 } | |
18910 }); | |
18911 | |
18912 test('format', function (assert) { | |
18913 var a = [ | |
18914 ['dddd, MMMM Do YYYY, H:mm:ss', 'недела, февруари 14-ти 2010, 15:25:50'], | |
18915 ['ddd, hA', 'нед, 3PM'], | |
18916 ['M Mo MM MMMM MMM', '2 2-ри 02 февруари фев'], | |
18917 ['YYYY YY', '2010 10'], | |
18918 ['D Do DD', '14 14-ти 14'], | |
18919 ['d do dddd ddd dd', '0 0-ев недела нед нe'], | |
18920 ['DDD DDDo DDDD', '45 45-ти 045'], | |
18921 ['w wo ww', '7 7-ми 07'], | |
18922 ['h hh', '3 03'], | |
18923 ['H HH', '15 15'], | |
18924 ['m mm', '25 25'], | |
18925 ['s ss', '50 50'], | |
18926 ['a A', 'pm PM'], | |
18927 ['[the] DDDo [day of the year]', 'the 45-ти day of the year'], | |
18928 ['LTS', '15:25:50'], | |
18929 ['L', '14.02.2010'], | |
18930 ['LL', '14 февруари 2010'], | |
18931 ['LLL', '14 февруари 2010 15:25'], | |
18932 ['LLLL', 'недела, 14 февруари 2010 15:25'], | |
18933 ['l', '14.2.2010'], | |
18934 ['ll', '14 фев 2010'], | |
18935 ['lll', '14 фев 2010 15:25'], | |
18936 ['llll', 'нед, 14 фев 2010 15:25'] | |
18937 ], | |
18938 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
18939 i; | |
18940 for (i = 0; i < a.length; i++) { | |
18941 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
18942 } | |
18943 }); | |
18944 | |
18945 test('format ordinal', function (assert) { | |
18946 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-ви', '1-ви'); | |
18947 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-ри', '2-ри'); | |
18948 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-ти', '3-ти'); | |
18949 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-ти', '4-ти'); | |
18950 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-ти', '5-ти'); | |
18951 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-ти', '6-ти'); | |
18952 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-ми', '7-ми'); | |
18953 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-ми', '8-ми'); | |
18954 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-ти', '9-ти'); | |
18955 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-ти', '10-ти'); | |
18956 | |
18957 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-ти', '11-ти'); | |
18958 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-ти', '12-ти'); | |
18959 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-ти', '13-ти'); | |
18960 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-ти', '14-ти'); | |
18961 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-ти', '15-ти'); | |
18962 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-ти', '16-ти'); | |
18963 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-ти', '17-ти'); | |
18964 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-ти', '18-ти'); | |
18965 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-ти', '19-ти'); | |
18966 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-ти', '20-ти'); | |
18967 | |
18968 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-ви', '21-ви'); | |
18969 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-ри', '22-ри'); | |
18970 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-ти', '23-ти'); | |
18971 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-ти', '24-ти'); | |
18972 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-ти', '25-ти'); | |
18973 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-ти', '26-ти'); | |
18974 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-ми', '27-ми'); | |
18975 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-ми', '28-ми'); | |
18976 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-ти', '29-ти'); | |
18977 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-ти', '30-ти'); | |
18978 | |
18979 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-ви', '31-ви'); | |
18980 }); | |
18981 | |
18982 test('format month', function (assert) { | |
18983 var expected = 'јануари јан_февруари фев_март мар_април апр_мај мај_јуни јун_јули јул_август авг_септември сеп_октомври окт_ноември ное_декември дек'.split('_'), i; | |
18984 for (i = 0; i < expected.length; i++) { | |
18985 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
18986 } | |
18987 }); | |
18988 | |
18989 test('format week', function (assert) { | |
18990 var expected = 'недела нед нe_понеделник пон пo_вторник вто вт_среда сре ср_четврток чет че_петок пет пе_сабота саб сa'.split('_'), i; | |
18991 for (i = 0; i < expected.length; i++) { | |
18992 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
18993 } | |
18994 }); | |
18995 | |
18996 test('from', function (assert) { | |
18997 var start = moment([2007, 1, 28]); | |
18998 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'неколку секунди', '44 seconds = a few seconds'); | |
18999 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'минута', '45 seconds = a minute'); | |
19000 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'минута', '89 seconds = a minute'); | |
19001 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 минути', '90 seconds = 2 minutes'); | |
19002 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 минути', '44 minutes = 44 minutes'); | |
19003 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'час', '45 minutes = an hour'); | |
19004 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'час', '89 minutes = an hour'); | |
19005 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 часа', '90 minutes = 2 hours'); | |
19006 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 часа', '5 hours = 5 hours'); | |
19007 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 часа', '21 hours = 21 hours'); | |
19008 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ден', '22 hours = a day'); | |
19009 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ден', '35 hours = a day'); | |
19010 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 дена', '36 hours = 2 days'); | |
19011 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ден', '1 day = a day'); | |
19012 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 дена', '5 days = 5 days'); | |
19013 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 дена', '25 days = 25 days'); | |
19014 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'месец', '26 days = a month'); | |
19015 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'месец', '30 days = a month'); | |
19016 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'месец', '43 days = a month'); | |
19017 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 месеци', '46 days = 2 months'); | |
19018 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 месеци', '75 days = 2 months'); | |
19019 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 месеци', '76 days = 3 months'); | |
19020 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'месец', '1 month = a month'); | |
19021 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 месеци', '5 months = 5 months'); | |
19022 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'година', '345 days = a year'); | |
19023 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 години', '548 days = 2 years'); | |
19024 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'година', '1 year = a year'); | |
19025 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 години', '5 years = 5 years'); | |
19026 }); | |
19027 | |
19028 test('suffix', function (assert) { | |
19029 assert.equal(moment(30000).from(0), 'после неколку секунди', 'prefix'); | |
19030 assert.equal(moment(0).from(30000), 'пред неколку секунди', 'suffix'); | |
19031 }); | |
19032 | |
19033 test('now from now', function (assert) { | |
19034 assert.equal(moment().fromNow(), 'пред неколку секунди', 'now from now should display as in the past'); | |
19035 }); | |
19036 | |
19037 test('fromNow', function (assert) { | |
19038 assert.equal(moment().add({s: 30}).fromNow(), 'после неколку секунди', 'in a few seconds'); | |
19039 assert.equal(moment().add({d: 5}).fromNow(), 'после 5 дена', 'in 5 days'); | |
19040 }); | |
19041 | |
19042 test('calendar day', function (assert) { | |
19043 var a = moment().hours(2).minutes(0).seconds(0); | |
19044 | |
19045 assert.equal(moment(a).calendar(), 'Денес во 2:00', 'today at the same time'); | |
19046 assert.equal(moment(a).add({m: 25}).calendar(), 'Денес во 2:25', 'Now plus 25 min'); | |
19047 assert.equal(moment(a).add({h: 1}).calendar(), 'Денес во 3:00', 'Now plus 1 hour'); | |
19048 assert.equal(moment(a).add({d: 1}).calendar(), 'Утре во 2:00', 'tomorrow at the same time'); | |
19049 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Денес во 1:00', 'Now minus 1 hour'); | |
19050 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Вчера во 2:00', 'yesterday at the same time'); | |
19051 }); | |
19052 | |
19053 test('calendar next week', function (assert) { | |
19054 var i, m; | |
19055 for (i = 2; i < 7; i++) { | |
19056 m = moment().add({d: i}); | |
19057 assert.equal(m.calendar(), m.format('dddd [во] LT'), 'Today + ' + i + ' days current time'); | |
19058 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
19059 assert.equal(m.calendar(), m.format('dddd [во] LT'), 'Today + ' + i + ' days beginning of day'); | |
19060 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
19061 assert.equal(m.calendar(), m.format('dddd [во] LT'), 'Today + ' + i + ' days end of day'); | |
19062 } | |
19063 }); | |
19064 | |
19065 test('calendar last week', function (assert) { | |
19066 var i, m; | |
19067 | |
19068 function makeFormat(d) { | |
19069 switch (d.day()) { | |
19070 case 0: | |
19071 case 3: | |
19072 case 6: | |
19073 return '[Во изминатата] dddd [во] LT'; | |
19074 case 1: | |
19075 case 2: | |
19076 case 4: | |
19077 case 5: | |
19078 return '[Во изминатиот] dddd [во] LT'; | |
19079 } | |
19080 } | |
19081 | |
19082 for (i = 2; i < 7; i++) { | |
19083 m = moment().subtract({d: i}); | |
19084 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time'); | |
19085 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
19086 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day'); | |
19087 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
19088 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day'); | |
19089 } | |
19090 }); | |
19091 | |
19092 test('calendar all else', function (assert) { | |
19093 var weeksAgo = moment().subtract({w: 1}), | |
19094 weeksFromNow = moment().add({w: 1}); | |
19095 | |
19096 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
19097 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
19098 | |
19099 weeksAgo = moment().subtract({w: 2}); | |
19100 weeksFromNow = moment().add({w: 2}); | |
19101 | |
19102 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
19103 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
19104 }); | |
19105 | |
19106 test('weeks year starting sunday', function (assert) { | |
19107 assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1'); | |
19108 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
19109 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2'); | |
19110 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
19111 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3'); | |
19112 }); | |
19113 | |
19114 test('weeks year starting monday', function (assert) { | |
19115 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
19116 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
19117 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
19118 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
19119 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
19120 }); | |
19121 | |
19122 test('weeks year starting tuesday', function (assert) { | |
19123 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
19124 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
19125 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
19126 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
19127 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
19128 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
19129 }); | |
19130 | |
19131 test('weeks year starting wednesday', function (assert) { | |
19132 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
19133 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
19134 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
19135 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
19136 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
19137 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
19138 }); | |
19139 | |
19140 test('weeks year starting thursday', function (assert) { | |
19141 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
19142 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
19143 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
19144 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
19145 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
19146 assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3'); | |
19147 }); | |
19148 | |
19149 test('weeks year starting friday', function (assert) { | |
19150 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1'); | |
19151 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
19152 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1'); | |
19153 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2'); | |
19154 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2'); | |
19155 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3'); | |
19156 }); | |
19157 | |
19158 test('weeks year starting saturday', function (assert) { | |
19159 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1'); | |
19160 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
19161 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1'); | |
19162 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2'); | |
19163 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2'); | |
19164 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3'); | |
19165 }); | |
19166 | |
19167 test('weeks year starting sunday formatted', function (assert) { | |
19168 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-ви', 'Dec 26 2011 should be week 1'); | |
19169 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-ви', 'Jan 1 2012 should be week 1'); | |
19170 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-ри', 'Jan 2 2012 should be week 2'); | |
19171 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-ри', 'Jan 8 2012 should be week 2'); | |
19172 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-ти', 'Jan 9 2012 should be week 3'); | |
19173 }); | |
19174 | |
19175 test('lenient ordinal parsing', function (assert) { | |
19176 var i, ordinalStr, testMoment; | |
19177 for (i = 1; i <= 31; ++i) { | |
19178 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
19179 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
19180 assert.equal(testMoment.year(), 2014, | |
19181 'lenient ordinal parsing ' + i + ' year check'); | |
19182 assert.equal(testMoment.month(), 0, | |
19183 'lenient ordinal parsing ' + i + ' month check'); | |
19184 assert.equal(testMoment.date(), i, | |
19185 'lenient ordinal parsing ' + i + ' date check'); | |
19186 } | |
19187 }); | |
19188 | |
19189 test('lenient ordinal parsing of number', function (assert) { | |
19190 var i, testMoment; | |
19191 for (i = 1; i <= 31; ++i) { | |
19192 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
19193 assert.equal(testMoment.year(), 2014, | |
19194 'lenient ordinal parsing of number ' + i + ' year check'); | |
19195 assert.equal(testMoment.month(), 0, | |
19196 'lenient ordinal parsing of number ' + i + ' month check'); | |
19197 assert.equal(testMoment.date(), i, | |
19198 'lenient ordinal parsing of number ' + i + ' date check'); | |
19199 } | |
19200 }); | |
19201 | |
19202 test('strict ordinal parsing', function (assert) { | |
19203 var i, ordinalStr, testMoment; | |
19204 for (i = 1; i <= 31; ++i) { | |
19205 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
19206 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
19207 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
19208 } | |
19209 }); | |
19210 | |
19211 })); | |
19212 | |
19213 (function (global, factory) { | |
19214 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
19215 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
19216 factory(global.moment) | |
19217 }(this, function (moment) { 'use strict'; | |
19218 | |
19219 /*global QUnit:false*/ | |
19220 | |
19221 var test = QUnit.test; | |
19222 | |
19223 function module (name, lifecycle) { | |
19224 QUnit.module(name, { | |
19225 setup : function () { | |
19226 moment.locale('en'); | |
19227 moment.createFromInputFallback = function () { | |
19228 throw new Error('input not handled by moment'); | |
19229 }; | |
19230 if (lifecycle && lifecycle.setup) { | |
19231 lifecycle.setup(); | |
19232 } | |
19233 }, | |
19234 teardown : function () { | |
19235 if (lifecycle && lifecycle.teardown) { | |
19236 lifecycle.teardown(); | |
19237 } | |
19238 } | |
19239 }); | |
19240 } | |
19241 | |
19242 function localeModule (name, lifecycle) { | |
19243 QUnit.module('locale:' + name, { | |
19244 setup : function () { | |
19245 moment.locale(name); | |
19246 moment.createFromInputFallback = function () { | |
19247 throw new Error('input not handled by moment'); | |
19248 }; | |
19249 if (lifecycle && lifecycle.setup) { | |
19250 lifecycle.setup(); | |
19251 } | |
19252 }, | |
19253 teardown : function () { | |
19254 moment.locale('en'); | |
19255 if (lifecycle && lifecycle.teardown) { | |
19256 lifecycle.teardown(); | |
19257 } | |
19258 } | |
19259 }); | |
19260 } | |
19261 | |
19262 localeModule('ml'); | |
19263 | |
19264 test('parse', function (assert) { | |
19265 var tests = 'ജനുവരി ജനു._ഫെബ്രുവരി ഫെബ്രു._മാർച്ച് മാർ._ഏപ്രിൽ ഏപ്രി._മേയ് മേയ്_ജൂൺ ജൂൺ_ജൂലൈ ജൂലൈ._ഓഗസ്റ്റ് ഓഗ._സെപ്റ്റംബർ സെപ്റ്റ._ഒക്ടോബർ ഒക്ടോ._നവംബർ നവം._ഡിസംബർ ഡിസം.'.split('_'), i; | |
19266 function equalTest(input, mmm, i) { | |
19267 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
19268 } | |
19269 for (i = 0; i < 12; i++) { | |
19270 tests[i] = tests[i].split(' '); | |
19271 equalTest(tests[i][0], 'MMM', i); | |
19272 equalTest(tests[i][1], 'MMM', i); | |
19273 equalTest(tests[i][0], 'MMMM', i); | |
19274 equalTest(tests[i][1], 'MMMM', i); | |
19275 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
19276 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
19277 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
19278 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
19279 } | |
19280 }); | |
19281 | |
19282 test('format', function (assert) { | |
19283 var a = [ | |
19284 ['dddd, Do MMMM YYYY, a h:mm:ss -നു', 'ഞായറാഴ്ച, 14 ഫെബ്രുവരി 2010, ഉച്ച കഴിഞ്ഞ് 3:25:50 -നു'], | |
19285 ['ddd, a h -നു', 'ഞായർ, ഉച്ച കഴിഞ്ഞ് 3 -നു'], | |
19286 ['M Mo MM MMMM MMM', '2 2 02 ഫെബ്രുവരി ഫെബ്രു.'], | |
19287 ['YYYY YY', '2010 10'], | |
19288 ['D Do DD', '14 14 14'], | |
19289 ['d do dddd ddd dd', '0 0 ഞായറാഴ്ച ഞായർ ഞാ'], | |
19290 ['DDD DDDo DDDD', '45 45 045'], | |
19291 ['w wo ww', '8 8 08'], | |
19292 ['h hh', '3 03'], | |
19293 ['H HH', '15 15'], | |
19294 ['m mm', '25 25'], | |
19295 ['s ss', '50 50'], | |
19296 ['a A', 'ഉച്ച കഴിഞ്ഞ് ഉച്ച കഴിഞ്ഞ്'], | |
19297 ['LTS', 'ഉച്ച കഴിഞ്ഞ് 3:25:50 -നു'], | |
19298 ['L', '14/02/2010'], | |
19299 ['LL', '14 ഫെബ്രുവരി 2010'], | |
19300 ['LLL', '14 ഫെബ്രുവരി 2010, ഉച്ച കഴിഞ്ഞ് 3:25 -നു'], | |
19301 ['LLLL', 'ഞായറാഴ്ച, 14 ഫെബ്രുവരി 2010, ഉച്ച കഴിഞ്ഞ് 3:25 -നു'], | |
19302 ['l', '14/2/2010'], | |
19303 ['ll', '14 ഫെബ്രു. 2010'], | |
19304 ['lll', '14 ഫെബ്രു. 2010, ഉച്ച കഴിഞ്ഞ് 3:25 -നു'], | |
19305 ['llll', 'ഞായർ, 14 ഫെബ്രു. 2010, ഉച്ച കഴിഞ്ഞ് 3:25 -നു'] | |
19306 ], | |
19307 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
19308 i; | |
19309 for (i = 0; i < a.length; i++) { | |
19310 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
19311 } | |
19312 }); | |
19313 | |
19314 test('format ordinal', function (assert) { | |
19315 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1'); | |
19316 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2'); | |
19317 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3'); | |
19318 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4'); | |
19319 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5'); | |
19320 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6'); | |
19321 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7'); | |
19322 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8'); | |
19323 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9'); | |
19324 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10'); | |
19325 | |
19326 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11'); | |
19327 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12'); | |
19328 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13'); | |
19329 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14'); | |
19330 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15'); | |
19331 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16'); | |
19332 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17'); | |
19333 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18'); | |
19334 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19'); | |
19335 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20'); | |
19336 | |
19337 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21'); | |
19338 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22'); | |
19339 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23'); | |
19340 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24'); | |
19341 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25'); | |
19342 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26'); | |
19343 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27'); | |
19344 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28'); | |
19345 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29'); | |
19346 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30'); | |
19347 | |
19348 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31'); | |
19349 }); | |
19350 | |
19351 test('format month', function (assert) { | |
19352 var expected = 'ജനുവരി ജനു._ഫെബ്രുവരി ഫെബ്രു._മാർച്ച് മാർ._ഏപ്രിൽ ഏപ്രി._മേയ് മേയ്_ജൂൺ ജൂൺ_ജൂലൈ ജൂലൈ._ഓഗസ്റ്റ് ഓഗ._സെപ്റ്റംബർ സെപ്റ്റ._ഒക്ടോബർ ഒക്ടോ._നവംബർ നവം._ഡിസംബർ ഡിസം.'.split('_'), i; | |
19353 for (i = 0; i < expected.length; i++) { | |
19354 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
19355 } | |
19356 }); | |
19357 | |
19358 test('format week', function (assert) { | |
19359 var expected = 'ഞായറാഴ്ച ഞായർ ഞാ_തിങ്കളാഴ്ച തിങ്കൾ തി_ചൊവ്വാഴ്ച ചൊവ്വ ചൊ_ബുധനാഴ്ച ബുധൻ ബു_വ്യാഴാഴ്ച വ്യാഴം വ്യാ_വെള്ളിയാഴ്ച വെള്ളി വെ_ശനിയാഴ്ച ശനി ശ'.split('_'), i; | |
19360 for (i = 0; i < expected.length; i++) { | |
19361 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
19362 } | |
19363 }); | |
19364 | |
19365 test('from', function (assert) { | |
19366 var start = moment([2007, 1, 28]); | |
19367 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'അൽപ നിമിഷങ്ങൾ', '44 seconds = a few seconds'); | |
19368 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ഒരു മിനിറ്റ്', '45 seconds = a minute'); | |
19369 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ഒരു മിനിറ്റ്', '89 seconds = a minute'); | |
19370 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 മിനിറ്റ്', '90 seconds = 2 minutes'); | |
19371 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 മിനിറ്റ്', '44 minutes = 44 minutes'); | |
19372 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ഒരു മണിക്കൂർ', '45 minutes = an hour'); | |
19373 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ഒരു മണിക്കൂർ', '89 minutes = an hour'); | |
19374 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 മണിക്കൂർ', '90 minutes = 2 hours'); | |
19375 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 മണിക്കൂർ', '5 hours = 5 hours'); | |
19376 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 മണിക്കൂർ', '21 hours = 21 hours'); | |
19377 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ഒരു ദിവസം', '22 hours = a day'); | |
19378 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ഒരു ദിവസം', '35 hours = a day'); | |
19379 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 ദിവസം', '36 hours = 2 days'); | |
19380 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ഒരു ദിവസം', '1 day = a day'); | |
19381 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ദിവസം', '5 days = 5 days'); | |
19382 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ദിവസം', '25 days = 25 days'); | |
19383 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ഒരു മാസം', '26 days = a month'); | |
19384 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ഒരു മാസം', '30 days = a month'); | |
19385 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ഒരു മാസം', '43 days = a month'); | |
19386 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 മാസം', '46 days = 2 months'); | |
19387 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 മാസം', '75 days = 2 months'); | |
19388 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 മാസം', '76 days = 3 months'); | |
19389 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ഒരു മാസം', '1 month = a month'); | |
19390 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 മാസം', '5 months = 5 months'); | |
19391 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ഒരു വർഷം', '345 days = a year'); | |
19392 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 വർഷം', '548 days = 2 years'); | |
19393 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ഒരു വർഷം', '1 year = a year'); | |
19394 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 വർഷം', '5 years = 5 years'); | |
19395 }); | |
19396 | |
19397 test('suffix', function (assert) { | |
19398 assert.equal(moment(30000).from(0), 'അൽപ നിമിഷങ്ങൾ കഴിഞ്ഞ്', 'prefix'); | |
19399 assert.equal(moment(0).from(30000), 'അൽപ നിമിഷങ്ങൾ മുൻപ്', 'suffix'); | |
19400 }); | |
19401 | |
19402 test('now from now', function (assert) { | |
19403 assert.equal(moment().fromNow(), 'അൽപ നിമിഷങ്ങൾ മുൻപ്', 'now from now should display as in the past'); | |
19404 }); | |
19405 | |
19406 test('fromNow', function (assert) { | |
19407 assert.equal(moment().add({s: 30}).fromNow(), 'അൽപ നിമിഷങ്ങൾ കഴിഞ്ഞ്', 'അൽപ നിമിഷങ്ങൾ കഴിഞ്ഞ്'); | |
19408 assert.equal(moment().add({d: 5}).fromNow(), '5 ദിവസം കഴിഞ്ഞ്', '5 ദിവസം കഴിഞ്ഞ്'); | |
19409 }); | |
19410 | |
19411 test('calendar day', function (assert) { | |
19412 var a = moment().hours(2).minutes(0).seconds(0); | |
19413 | |
19414 assert.equal(moment(a).calendar(), 'ഇന്ന് രാത്രി 2:00 -നു', 'today at the same time'); | |
19415 assert.equal(moment(a).add({m: 25}).calendar(), 'ഇന്ന് രാത്രി 2:25 -നു', 'Now plus 25 min'); | |
19416 assert.equal(moment(a).add({h: 3}).calendar(), 'ഇന്ന് രാവിലെ 5:00 -നു', 'Now plus 3 hour'); | |
19417 assert.equal(moment(a).add({d: 1}).calendar(), 'നാളെ രാത്രി 2:00 -നു', 'tomorrow at the same time'); | |
19418 assert.equal(moment(a).subtract({h: 1}).calendar(), 'ഇന്ന് രാത്രി 1:00 -നു', 'Now minus 1 hour'); | |
19419 assert.equal(moment(a).subtract({d: 1}).calendar(), 'ഇന്നലെ രാത്രി 2:00 -നു', 'yesterday at the same time'); | |
19420 }); | |
19421 | |
19422 test('calendar next week', function (assert) { | |
19423 var i, m; | |
19424 for (i = 2; i < 7; i++) { | |
19425 m = moment().add({d: i}); | |
19426 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days current time'); | |
19427 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
19428 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days beginning of day'); | |
19429 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
19430 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days end of day'); | |
19431 } | |
19432 }); | |
19433 | |
19434 test('calendar last week', function (assert) { | |
19435 var i, m; | |
19436 | |
19437 for (i = 2; i < 7; i++) { | |
19438 m = moment().subtract({d: i}); | |
19439 assert.equal(m.calendar(), m.format('[കഴിഞ്ഞ] dddd[,] LT'), 'Today - ' + i + ' days current time'); | |
19440 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
19441 assert.equal(m.calendar(), m.format('[കഴിഞ്ഞ] dddd[,] LT'), 'Today - ' + i + ' days beginning of day'); | |
19442 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
19443 assert.equal(m.calendar(), m.format('[കഴിഞ്ഞ] dddd[,] LT'), 'Today - ' + i + ' days end of day'); | |
19444 } | |
19445 }); | |
19446 | |
19447 test('calendar all else', function (assert) { | |
19448 var weeksAgo = moment().subtract({w: 1}), | |
19449 weeksFromNow = moment().add({w: 1}); | |
19450 | |
19451 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
19452 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
19453 | |
19454 weeksAgo = moment().subtract({w: 2}); | |
19455 weeksFromNow = moment().add({w: 2}); | |
19456 | |
19457 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
19458 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
19459 }); | |
19460 | |
19461 test('meridiem', function (assert) { | |
19462 assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), 'രാത്രി', 'before dawn'); | |
19463 assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), 'രാവിലെ', 'morning'); | |
19464 assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), 'ഉച്ച കഴിഞ്ഞ്', 'during day'); | |
19465 assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), 'വൈകുന്നേരം', 'evening'); | |
19466 assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), 'വൈകുന്നേരം', 'late evening'); | |
19467 assert.equal(moment([2011, 2, 23, 21, 20]).format('a'), 'രാത്രി', 'night'); | |
19468 | |
19469 assert.equal(moment([2011, 2, 23, 2, 30]).format('A'), 'രാത്രി', 'before dawn'); | |
19470 assert.equal(moment([2011, 2, 23, 9, 30]).format('A'), 'രാവിലെ', 'morning'); | |
19471 assert.equal(moment([2011, 2, 23, 14, 30]).format('A'), 'ഉച്ച കഴിഞ്ഞ്', ' during day'); | |
19472 assert.equal(moment([2011, 2, 23, 17, 30]).format('A'), 'വൈകുന്നേരം', 'evening'); | |
19473 assert.equal(moment([2011, 2, 23, 19, 30]).format('A'), 'വൈകുന്നേരം', 'late evening'); | |
19474 assert.equal(moment([2011, 2, 23, 21, 20]).format('A'), 'രാത്രി', 'night'); | |
19475 }); | |
19476 | |
19477 test('weeks year starting sunday', function (assert) { | |
19478 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
19479 assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1'); | |
19480 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
19481 assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2'); | |
19482 assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3'); | |
19483 }); | |
19484 | |
19485 test('weeks year starting monday', function (assert) { | |
19486 assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1'); | |
19487 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
19488 assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1'); | |
19489 assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2'); | |
19490 assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2'); | |
19491 assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3'); | |
19492 }); | |
19493 | |
19494 test('weeks year starting tuesday', function (assert) { | |
19495 assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52'); | |
19496 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
19497 assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1'); | |
19498 assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2'); | |
19499 assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2'); | |
19500 assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3'); | |
19501 }); | |
19502 | |
19503 test('weeks year starting wednesday', function (assert) { | |
19504 assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1'); | |
19505 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
19506 assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1'); | |
19507 assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2'); | |
19508 assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2'); | |
19509 assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3'); | |
19510 }); | |
19511 | |
19512 test('weeks year starting thursday', function (assert) { | |
19513 assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1'); | |
19514 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
19515 assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1'); | |
19516 assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2'); | |
19517 assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2'); | |
19518 assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3'); | |
19519 }); | |
19520 | |
19521 test('weeks year starting friday', function (assert) { | |
19522 assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1'); | |
19523 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
19524 assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1'); | |
19525 assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2'); | |
19526 assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2'); | |
19527 assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3'); | |
19528 }); | |
19529 | |
19530 test('weeks year starting saturday', function (assert) { | |
19531 assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1'); | |
19532 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
19533 assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2'); | |
19534 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2'); | |
19535 assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3'); | |
19536 }); | |
19537 | |
19538 test('weeks year starting sunday formatted', function (assert) { | |
19539 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1'); | |
19540 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1', 'Jan 7 2012 should be week 1'); | |
19541 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2'); | |
19542 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2', 'Jan 14 2012 should be week 2'); | |
19543 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', 'Jan 15 2012 should be week 3'); | |
19544 }); | |
19545 | |
19546 test('lenient ordinal parsing', function (assert) { | |
19547 var i, ordinalStr, testMoment; | |
19548 for (i = 1; i <= 31; ++i) { | |
19549 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
19550 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
19551 assert.equal(testMoment.year(), 2014, | |
19552 'lenient ordinal parsing ' + i + ' year check'); | |
19553 assert.equal(testMoment.month(), 0, | |
19554 'lenient ordinal parsing ' + i + ' month check'); | |
19555 assert.equal(testMoment.date(), i, | |
19556 'lenient ordinal parsing ' + i + ' date check'); | |
19557 } | |
19558 }); | |
19559 | |
19560 test('lenient ordinal parsing of number', function (assert) { | |
19561 var i, testMoment; | |
19562 for (i = 1; i <= 31; ++i) { | |
19563 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
19564 assert.equal(testMoment.year(), 2014, | |
19565 'lenient ordinal parsing of number ' + i + ' year check'); | |
19566 assert.equal(testMoment.month(), 0, | |
19567 'lenient ordinal parsing of number ' + i + ' month check'); | |
19568 assert.equal(testMoment.date(), i, | |
19569 'lenient ordinal parsing of number ' + i + ' date check'); | |
19570 } | |
19571 }); | |
19572 | |
19573 test('strict ordinal parsing', function (assert) { | |
19574 var i, ordinalStr, testMoment; | |
19575 for (i = 1; i <= 31; ++i) { | |
19576 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
19577 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
19578 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
19579 } | |
19580 }); | |
19581 | |
19582 })); | |
19583 | |
19584 (function (global, factory) { | |
19585 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
19586 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
19587 factory(global.moment) | |
19588 }(this, function (moment) { 'use strict'; | |
19589 | |
19590 /*global QUnit:false*/ | |
19591 | |
19592 var test = QUnit.test; | |
19593 | |
19594 function module (name, lifecycle) { | |
19595 QUnit.module(name, { | |
19596 setup : function () { | |
19597 moment.locale('en'); | |
19598 moment.createFromInputFallback = function () { | |
19599 throw new Error('input not handled by moment'); | |
19600 }; | |
19601 if (lifecycle && lifecycle.setup) { | |
19602 lifecycle.setup(); | |
19603 } | |
19604 }, | |
19605 teardown : function () { | |
19606 if (lifecycle && lifecycle.teardown) { | |
19607 lifecycle.teardown(); | |
19608 } | |
19609 } | |
19610 }); | |
19611 } | |
19612 | |
19613 function localeModule (name, lifecycle) { | |
19614 QUnit.module('locale:' + name, { | |
19615 setup : function () { | |
19616 moment.locale(name); | |
19617 moment.createFromInputFallback = function () { | |
19618 throw new Error('input not handled by moment'); | |
19619 }; | |
19620 if (lifecycle && lifecycle.setup) { | |
19621 lifecycle.setup(); | |
19622 } | |
19623 }, | |
19624 teardown : function () { | |
19625 moment.locale('en'); | |
19626 if (lifecycle && lifecycle.teardown) { | |
19627 lifecycle.teardown(); | |
19628 } | |
19629 } | |
19630 }); | |
19631 } | |
19632 | |
19633 localeModule('mr'); | |
19634 | |
19635 test('parse', function (assert) { | |
19636 var tests = 'जानेवारी जाने._फेब्रुवारी फेब्रु._मार्च मार्च._एप्रिल एप्रि._मे मे._जून जून._जुलै जुलै._ऑगस्ट ऑग._सप्टेंबर सप्टें._ऑक्टोबर ऑक्टो._नोव्हेंबर नोव्हें._डिसेंबर डिसें.'.split('_'), i; | |
19637 function equalTest(input, mmm, i) { | |
19638 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
19639 } | |
19640 for (i = 0; i < 12; i++) { | |
19641 tests[i] = tests[i].split(' '); | |
19642 equalTest(tests[i][0], 'MMM', i); | |
19643 equalTest(tests[i][1], 'MMM', i); | |
19644 equalTest(tests[i][0], 'MMMM', i); | |
19645 equalTest(tests[i][1], 'MMMM', i); | |
19646 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
19647 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
19648 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
19649 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
19650 } | |
19651 }); | |
19652 | |
19653 test('format', function (assert) { | |
19654 var a = [ | |
19655 ['dddd, Do MMMM YYYY, a h:mm:ss वाजता', 'रविवार, १४ फेब्रुवारी २०१०, दुपारी ३:२५:५० वाजता'], | |
19656 ['ddd, a h वाजता', 'रवि, दुपारी ३ वाजता'], | |
19657 ['M Mo MM MMMM MMM', '२ २ ०२ फेब्रुवारी फेब्रु.'], | |
19658 ['YYYY YY', '२०१० १०'], | |
19659 ['D Do DD', '१४ १४ १४'], | |
19660 ['d do dddd ddd dd', '० ० रविवार रवि र'], | |
19661 ['DDD DDDo DDDD', '४५ ४५ ०४५'], | |
19662 ['w wo ww', '८ ८ ०८'], | |
19663 ['h hh', '३ ०३'], | |
19664 ['H HH', '१५ १५'], | |
19665 ['m mm', '२५ २५'], | |
19666 ['s ss', '५० ५०'], | |
19667 ['a A', 'दुपारी दुपारी'], | |
19668 ['LTS', 'दुपारी ३:२५:५० वाजता'], | |
19669 ['L', '१४/०२/२०१०'], | |
19670 ['LL', '१४ फेब्रुवारी २०१०'], | |
19671 ['LLL', '१४ फेब्रुवारी २०१०, दुपारी ३:२५ वाजता'], | |
19672 ['LLLL', 'रविवार, १४ फेब्रुवारी २०१०, दुपारी ३:२५ वाजता'], | |
19673 ['l', '१४/२/२०१०'], | |
19674 ['ll', '१४ फेब्रु. २०१०'], | |
19675 ['lll', '१४ फेब्रु. २०१०, दुपारी ३:२५ वाजता'], | |
19676 ['llll', 'रवि, १४ फेब्रु. २०१०, दुपारी ३:२५ वाजता'] | |
19677 ], | |
19678 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
19679 i; | |
19680 for (i = 0; i < a.length; i++) { | |
19681 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
19682 } | |
19683 }); | |
19684 | |
19685 test('format ordinal', function (assert) { | |
19686 assert.equal(moment([2011, 0, 1]).format('DDDo'), '१', '१'); | |
19687 assert.equal(moment([2011, 0, 2]).format('DDDo'), '२', '२'); | |
19688 assert.equal(moment([2011, 0, 3]).format('DDDo'), '३', '३'); | |
19689 assert.equal(moment([2011, 0, 4]).format('DDDo'), '४', '४'); | |
19690 assert.equal(moment([2011, 0, 5]).format('DDDo'), '५', '५'); | |
19691 assert.equal(moment([2011, 0, 6]).format('DDDo'), '६', '६'); | |
19692 assert.equal(moment([2011, 0, 7]).format('DDDo'), '७', '७'); | |
19693 assert.equal(moment([2011, 0, 8]).format('DDDo'), '८', '८'); | |
19694 assert.equal(moment([2011, 0, 9]).format('DDDo'), '९', '९'); | |
19695 assert.equal(moment([2011, 0, 10]).format('DDDo'), '१०', '१०'); | |
19696 | |
19697 assert.equal(moment([2011, 0, 11]).format('DDDo'), '११', '११'); | |
19698 assert.equal(moment([2011, 0, 12]).format('DDDo'), '१२', '१२'); | |
19699 assert.equal(moment([2011, 0, 13]).format('DDDo'), '१३', '१३'); | |
19700 assert.equal(moment([2011, 0, 14]).format('DDDo'), '१४', '१४'); | |
19701 assert.equal(moment([2011, 0, 15]).format('DDDo'), '१५', '१५'); | |
19702 assert.equal(moment([2011, 0, 16]).format('DDDo'), '१६', '१६'); | |
19703 assert.equal(moment([2011, 0, 17]).format('DDDo'), '१७', '१७'); | |
19704 assert.equal(moment([2011, 0, 18]).format('DDDo'), '१८', '१८'); | |
19705 assert.equal(moment([2011, 0, 19]).format('DDDo'), '१९', '१९'); | |
19706 assert.equal(moment([2011, 0, 20]).format('DDDo'), '२०', '२०'); | |
19707 | |
19708 assert.equal(moment([2011, 0, 21]).format('DDDo'), '२१', '२१'); | |
19709 assert.equal(moment([2011, 0, 22]).format('DDDo'), '२२', '२२'); | |
19710 assert.equal(moment([2011, 0, 23]).format('DDDo'), '२३', '२३'); | |
19711 assert.equal(moment([2011, 0, 24]).format('DDDo'), '२४', '२४'); | |
19712 assert.equal(moment([2011, 0, 25]).format('DDDo'), '२५', '२५'); | |
19713 assert.equal(moment([2011, 0, 26]).format('DDDo'), '२६', '२६'); | |
19714 assert.equal(moment([2011, 0, 27]).format('DDDo'), '२७', '२७'); | |
19715 assert.equal(moment([2011, 0, 28]).format('DDDo'), '२८', '२८'); | |
19716 assert.equal(moment([2011, 0, 29]).format('DDDo'), '२९', '२९'); | |
19717 assert.equal(moment([2011, 0, 30]).format('DDDo'), '३०', '३०'); | |
19718 | |
19719 assert.equal(moment([2011, 0, 31]).format('DDDo'), '३१', '३१'); | |
19720 }); | |
19721 | |
19722 test('format month', function (assert) { | |
19723 var expected = 'जानेवारी जाने._फेब्रुवारी फेब्रु._मार्च मार्च._एप्रिल एप्रि._मे मे._जून जून._जुलै जुलै._ऑगस्ट ऑग._सप्टेंबर सप्टें._ऑक्टोबर ऑक्टो._नोव्हेंबर नोव्हें._डिसेंबर डिसें.'.split('_'), i; | |
19724 for (i = 0; i < expected.length; i++) { | |
19725 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
19726 } | |
19727 }); | |
19728 | |
19729 test('format week', function (assert) { | |
19730 var expected = 'रविवार रवि र_सोमवार सोम सो_मंगळवार मंगळ मं_बुधवार बुध बु_गुरूवार गुरू गु_शुक्रवार शुक्र शु_शनिवार शनि श'.split('_'), i; | |
19731 for (i = 0; i < expected.length; i++) { | |
19732 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
19733 } | |
19734 }); | |
19735 | |
19736 test('from', function (assert) { | |
19737 var start = moment([2007, 1, 28]); | |
19738 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'सेकंद', '44 seconds = a few seconds'); | |
19739 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'एक मिनिट', '45 seconds = a minute'); | |
19740 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'एक मिनिट', '89 seconds = a minute'); | |
19741 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '२ मिनिटे', '90 seconds = 2 minutes'); | |
19742 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '४४ मिनिटे', '44 minutes = 44 minutes'); | |
19743 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'एक तास', '45 minutes = an hour'); | |
19744 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'एक तास', '89 minutes = an hour'); | |
19745 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '२ तास', '90 minutes = 2 hours'); | |
19746 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '५ तास', '5 hours = 5 hours'); | |
19747 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '२१ तास', '21 hours = 21 hours'); | |
19748 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'एक दिवस', '22 hours = a day'); | |
19749 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'एक दिवस', '35 hours = a day'); | |
19750 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '२ दिवस', '36 hours = 2 days'); | |
19751 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'एक दिवस', '1 day = a day'); | |
19752 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '५ दिवस', '5 days = 5 days'); | |
19753 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '२५ दिवस', '25 days = 25 days'); | |
19754 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'एक महिना', '26 days = a month'); | |
19755 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'एक महिना', '30 days = a month'); | |
19756 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'एक महिना', '43 days = a month'); | |
19757 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '२ महिने', '46 days = 2 months'); | |
19758 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '२ महिने', '75 days = 2 months'); | |
19759 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '३ महिने', '76 days = 3 months'); | |
19760 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'एक महिना', '1 month = a month'); | |
19761 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '५ महिने', '5 months = 5 months'); | |
19762 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'एक वर्ष', '345 days = a year'); | |
19763 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '२ वर्षे', '548 days = 2 years'); | |
19764 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'एक वर्ष', '1 year = a year'); | |
19765 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '५ वर्षे', '5 years = 5 years'); | |
19766 }); | |
19767 | |
19768 test('suffix', function (assert) { | |
19769 assert.equal(moment(30000).from(0), 'सेकंद नंतर', 'prefix'); | |
19770 assert.equal(moment(0).from(30000), 'सेकंद पूर्वी', 'suffix'); | |
19771 }); | |
19772 | |
19773 test('now from now', function (assert) { | |
19774 assert.equal(moment().fromNow(), 'सेकंद पूर्वी', 'now from now should display as in the past'); | |
19775 }); | |
19776 | |
19777 test('fromNow', function (assert) { | |
19778 assert.equal(moment().add({s: 30}).fromNow(), 'सेकंद नंतर', 'सेकंद नंतर'); | |
19779 assert.equal(moment().add({d: 5}).fromNow(), '५ दिवस नंतर', '५ दिवस नंतर'); | |
19780 }); | |
19781 | |
19782 test('calendar day', function (assert) { | |
19783 var a = moment().hours(2).minutes(0).seconds(0); | |
19784 | |
19785 assert.equal(moment(a).calendar(), 'आज रात्री २:०० वाजता', 'today at the same time'); | |
19786 assert.equal(moment(a).add({m: 25}).calendar(), 'आज रात्री २:२५ वाजता', 'Now plus 25 min'); | |
19787 assert.equal(moment(a).add({h: 3}).calendar(), 'आज सकाळी ५:०० वाजता', 'Now plus 3 hour'); | |
19788 assert.equal(moment(a).add({d: 1}).calendar(), 'उद्या रात्री २:०० वाजता', 'tomorrow at the same time'); | |
19789 assert.equal(moment(a).subtract({h: 1}).calendar(), 'आज रात्री १:०० वाजता', 'Now minus 1 hour'); | |
19790 assert.equal(moment(a).subtract({d: 1}).calendar(), 'काल रात्री २:०० वाजता', 'yesterday at the same time'); | |
19791 }); | |
19792 | |
19793 test('calendar next week', function (assert) { | |
19794 var i, m; | |
19795 for (i = 2; i < 7; i++) { | |
19796 m = moment().add({d: i}); | |
19797 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days current time'); | |
19798 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
19799 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days beginning of day'); | |
19800 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
19801 assert.equal(m.calendar(), m.format('dddd[,] LT'), 'Today + ' + i + ' days end of day'); | |
19802 } | |
19803 }); | |
19804 | |
19805 test('calendar last week', function (assert) { | |
19806 var i, m; | |
19807 | |
19808 for (i = 2; i < 7; i++) { | |
19809 m = moment().subtract({d: i}); | |
19810 assert.equal(m.calendar(), m.format('[मागील] dddd[,] LT'), 'Today - ' + i + ' days current time'); | |
19811 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
19812 assert.equal(m.calendar(), m.format('[मागील] dddd[,] LT'), 'Today - ' + i + ' days beginning of day'); | |
19813 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
19814 assert.equal(m.calendar(), m.format('[मागील] dddd[,] LT'), 'Today - ' + i + ' days end of day'); | |
19815 } | |
19816 }); | |
19817 | |
19818 test('calendar all else', function (assert) { | |
19819 var weeksAgo = moment().subtract({w: 1}), | |
19820 weeksFromNow = moment().add({w: 1}); | |
19821 | |
19822 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
19823 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
19824 | |
19825 weeksAgo = moment().subtract({w: 2}); | |
19826 weeksFromNow = moment().add({w: 2}); | |
19827 | |
19828 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
19829 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
19830 }); | |
19831 | |
19832 test('meridiem', function (assert) { | |
19833 assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), 'रात्री', 'before dawn'); | |
19834 assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), 'सकाळी', 'morning'); | |
19835 assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), 'दुपारी', 'during day'); | |
19836 assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), 'सायंकाळी', 'evening'); | |
19837 assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), 'सायंकाळी', 'late evening'); | |
19838 assert.equal(moment([2011, 2, 23, 21, 20]).format('a'), 'रात्री', 'night'); | |
19839 | |
19840 assert.equal(moment([2011, 2, 23, 2, 30]).format('A'), 'रात्री', 'before dawn'); | |
19841 assert.equal(moment([2011, 2, 23, 9, 30]).format('A'), 'सकाळी', 'morning'); | |
19842 assert.equal(moment([2011, 2, 23, 14, 30]).format('A'), 'दुपारी', ' during day'); | |
19843 assert.equal(moment([2011, 2, 23, 17, 30]).format('A'), 'सायंकाळी', 'evening'); | |
19844 assert.equal(moment([2011, 2, 23, 19, 30]).format('A'), 'सायंकाळी', 'late evening'); | |
19845 assert.equal(moment([2011, 2, 23, 21, 20]).format('A'), 'रात्री', 'night'); | |
19846 }); | |
19847 | |
19848 test('weeks year starting sunday', function (assert) { | |
19849 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
19850 assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1'); | |
19851 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
19852 assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2'); | |
19853 assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3'); | |
19854 }); | |
19855 | |
19856 test('weeks year starting monday', function (assert) { | |
19857 assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1'); | |
19858 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
19859 assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1'); | |
19860 assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2'); | |
19861 assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2'); | |
19862 assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3'); | |
19863 }); | |
19864 | |
19865 test('weeks year starting tuesday', function (assert) { | |
19866 assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52'); | |
19867 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
19868 assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1'); | |
19869 assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2'); | |
19870 assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2'); | |
19871 assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3'); | |
19872 }); | |
19873 | |
19874 test('weeks year starting wednesday', function (assert) { | |
19875 assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1'); | |
19876 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
19877 assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1'); | |
19878 assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2'); | |
19879 assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2'); | |
19880 assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3'); | |
19881 }); | |
19882 | |
19883 test('weeks year starting thursday', function (assert) { | |
19884 assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1'); | |
19885 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
19886 assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1'); | |
19887 assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2'); | |
19888 assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2'); | |
19889 assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3'); | |
19890 }); | |
19891 | |
19892 test('weeks year starting friday', function (assert) { | |
19893 assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1'); | |
19894 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
19895 assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1'); | |
19896 assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2'); | |
19897 assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2'); | |
19898 assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3'); | |
19899 }); | |
19900 | |
19901 test('weeks year starting saturday', function (assert) { | |
19902 assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1'); | |
19903 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
19904 assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2'); | |
19905 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2'); | |
19906 assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3'); | |
19907 }); | |
19908 | |
19909 test('weeks year starting sunday formatted', function (assert) { | |
19910 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '१ ०१ १', 'Jan 1 2012 should be week 1'); | |
19911 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '१ ०१ १', 'Jan 7 2012 should be week 1'); | |
19912 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '२ ०२ २', 'Jan 8 2012 should be week 2'); | |
19913 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '२ ०२ २', 'Jan 14 2012 should be week 2'); | |
19914 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '३ ०३ ३', 'Jan 15 2012 should be week 3'); | |
19915 }); | |
19916 | |
19917 test('lenient ordinal parsing', function (assert) { | |
19918 var i, ordinalStr, testMoment; | |
19919 for (i = 1; i <= 31; ++i) { | |
19920 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
19921 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
19922 assert.equal(testMoment.year(), 2014, | |
19923 'lenient ordinal parsing ' + i + ' year check'); | |
19924 assert.equal(testMoment.month(), 0, | |
19925 'lenient ordinal parsing ' + i + ' month check'); | |
19926 assert.equal(testMoment.date(), i, | |
19927 'lenient ordinal parsing ' + i + ' date check'); | |
19928 } | |
19929 }); | |
19930 | |
19931 test('lenient ordinal parsing of number', function (assert) { | |
19932 var i, testMoment; | |
19933 for (i = 1; i <= 31; ++i) { | |
19934 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
19935 assert.equal(testMoment.year(), 2014, | |
19936 'lenient ordinal parsing of number ' + i + ' year check'); | |
19937 assert.equal(testMoment.month(), 0, | |
19938 'lenient ordinal parsing of number ' + i + ' month check'); | |
19939 assert.equal(testMoment.date(), i, | |
19940 'lenient ordinal parsing of number ' + i + ' date check'); | |
19941 } | |
19942 }); | |
19943 | |
19944 test('meridiem invariant', function (assert) { | |
19945 var h, m, t1, t2; | |
19946 for (h = 0; h < 24; ++h) { | |
19947 for (m = 0; m < 60; m += 15) { | |
19948 t1 = moment.utc([2000, 0, 1, h, m]); | |
19949 t2 = moment(t1.format('A h:mm'), 'A h:mm'); | |
19950 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'), | |
19951 'meridiem at ' + t1.format('HH:mm')); | |
19952 } | |
19953 } | |
19954 }); | |
19955 | |
19956 test('strict ordinal parsing', function (assert) { | |
19957 var i, ordinalStr, testMoment; | |
19958 for (i = 1; i <= 31; ++i) { | |
19959 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
19960 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
19961 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
19962 } | |
19963 }); | |
19964 | |
19965 })); | |
19966 | |
19967 (function (global, factory) { | |
19968 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
19969 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
19970 factory(global.moment) | |
19971 }(this, function (moment) { 'use strict'; | |
19972 | |
19973 /*global QUnit:false*/ | |
19974 | |
19975 var test = QUnit.test; | |
19976 | |
19977 function module (name, lifecycle) { | |
19978 QUnit.module(name, { | |
19979 setup : function () { | |
19980 moment.locale('en'); | |
19981 moment.createFromInputFallback = function () { | |
19982 throw new Error('input not handled by moment'); | |
19983 }; | |
19984 if (lifecycle && lifecycle.setup) { | |
19985 lifecycle.setup(); | |
19986 } | |
19987 }, | |
19988 teardown : function () { | |
19989 if (lifecycle && lifecycle.teardown) { | |
19990 lifecycle.teardown(); | |
19991 } | |
19992 } | |
19993 }); | |
19994 } | |
19995 | |
19996 function localeModule (name, lifecycle) { | |
19997 QUnit.module('locale:' + name, { | |
19998 setup : function () { | |
19999 moment.locale(name); | |
20000 moment.createFromInputFallback = function () { | |
20001 throw new Error('input not handled by moment'); | |
20002 }; | |
20003 if (lifecycle && lifecycle.setup) { | |
20004 lifecycle.setup(); | |
20005 } | |
20006 }, | |
20007 teardown : function () { | |
20008 moment.locale('en'); | |
20009 if (lifecycle && lifecycle.teardown) { | |
20010 lifecycle.teardown(); | |
20011 } | |
20012 } | |
20013 }); | |
20014 } | |
20015 | |
20016 localeModule('ms-my'); | |
20017 | |
20018 test('parse', function (assert) { | |
20019 var i, | |
20020 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('_'); | |
20021 | |
20022 function equalTest(input, mmm, i) { | |
20023 assert.equal(moment(input, mmm).month(), i, input + ' sepatutnya bulan ' + (i + 1)); | |
20024 } | |
20025 | |
20026 for (i = 0; i < 12; i++) { | |
20027 tests[i] = tests[i].split(' '); | |
20028 equalTest(tests[i][0], 'MMM', i); | |
20029 equalTest(tests[i][1], 'MMM', i); | |
20030 equalTest(tests[i][0], 'MMMM', i); | |
20031 equalTest(tests[i][1], 'MMMM', i); | |
20032 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
20033 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
20034 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
20035 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
20036 } | |
20037 }); | |
20038 | |
20039 test('format', function (assert) { | |
20040 var a = [ | |
20041 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Ahad, Februari 14 2010, 3:25:50 petang'], | |
20042 ['ddd, hA', 'Ahd, 3petang'], | |
20043 ['M Mo MM MMMM MMM', '2 2 02 Februari Feb'], | |
20044 ['YYYY YY', '2010 10'], | |
20045 ['D Do DD', '14 14 14'], | |
20046 ['d do dddd ddd dd', '0 0 Ahad Ahd Ah'], | |
20047 ['DDD DDDo DDDD', '45 45 045'], | |
20048 ['w wo ww', '7 7 07'], | |
20049 ['h hh', '3 03'], | |
20050 ['H HH', '15 15'], | |
20051 ['m mm', '25 25'], | |
20052 ['s ss', '50 50'], | |
20053 ['a A', 'petang petang'], | |
20054 ['[hari] [ke] DDDo [tahun] ini', 'hari ke 45 tahun ini'], | |
20055 ['LTS', '15.25.50'], | |
20056 ['L', '14/02/2010'], | |
20057 ['LL', '14 Februari 2010'], | |
20058 ['LLL', '14 Februari 2010 pukul 15.25'], | |
20059 ['LLLL', 'Ahad, 14 Februari 2010 pukul 15.25'], | |
20060 ['l', '14/2/2010'], | |
20061 ['ll', '14 Feb 2010'], | |
20062 ['lll', '14 Feb 2010 pukul 15.25'], | |
20063 ['llll', 'Ahd, 14 Feb 2010 pukul 15.25'] | |
20064 ], | |
20065 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
20066 i; | |
20067 | |
20068 for (i = 0; i < a.length; i++) { | |
20069 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
20070 } | |
20071 }); | |
20072 | |
20073 test('format ordinal', function (assert) { | |
20074 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1'); | |
20075 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2'); | |
20076 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3'); | |
20077 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4'); | |
20078 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5'); | |
20079 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6'); | |
20080 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7'); | |
20081 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8'); | |
20082 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9'); | |
20083 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10'); | |
20084 | |
20085 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11'); | |
20086 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12'); | |
20087 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13'); | |
20088 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14'); | |
20089 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15'); | |
20090 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16'); | |
20091 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17'); | |
20092 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18'); | |
20093 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19'); | |
20094 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20'); | |
20095 | |
20096 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21'); | |
20097 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22'); | |
20098 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23'); | |
20099 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24'); | |
20100 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25'); | |
20101 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26'); | |
20102 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27'); | |
20103 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28'); | |
20104 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29'); | |
20105 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30'); | |
20106 | |
20107 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31'); | |
20108 }); | |
20109 | |
20110 test('format month', function (assert) { | |
20111 var i, | |
20112 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('_'); | |
20113 | |
20114 for (i = 0; i < expected.length; i++) { | |
20115 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
20116 } | |
20117 }); | |
20118 | |
20119 test('format week', function (assert) { | |
20120 var i, | |
20121 expected = 'Ahad Ahd Ah_Isnin Isn Is_Selasa Sel Sl_Rabu Rab Rb_Khamis Kha Km_Jumaat Jum Jm_Sabtu Sab Sb'.split('_'); | |
20122 | |
20123 for (i = 0; i < expected.length; i++) { | |
20124 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
20125 } | |
20126 }); | |
20127 | |
20128 test('from', function (assert) { | |
20129 var start = moment([2007, 1, 28]); | |
20130 | |
20131 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'beberapa saat', '44 saat = beberapa saat'); | |
20132 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'seminit', '45 saat = seminit'); | |
20133 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'seminit', '89 saat = seminit'); | |
20134 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minit', '90 saat = 2 minit'); | |
20135 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minit', '44 minit = 44 minit'); | |
20136 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'sejam', '45 minit = sejam'); | |
20137 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'sejam', '89 minit = sejam'); | |
20138 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 jam', '90 minit = 2 jam'); | |
20139 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 jam', '5 jam = 5 jam'); | |
20140 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 jam', '21 jam = 21 jam'); | |
20141 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'sehari', '22 jam = sehari'); | |
20142 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'sehari', '35 jam = sehari'); | |
20143 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 hari', '36 jam = 2 hari'); | |
20144 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'sehari', '1 hari = sehari'); | |
20145 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 hari', '5 hari = 5 hari'); | |
20146 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 hari', '25 hari = 25 hari'); | |
20147 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'sebulan', '26 hari = sebulan'); | |
20148 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'sebulan', '30 hari = sebulan'); | |
20149 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'sebulan', '45 hari = sebulan'); | |
20150 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 bulan', '46 hari = 2 bulan'); | |
20151 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 bulan', '75 hari = 2 bulan'); | |
20152 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 bulan', '76 hari = 3 bulan'); | |
20153 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'sebulan', '1 bulan = sebulan'); | |
20154 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 bulan', '5 bulan = 5 bulan'); | |
20155 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'setahun', '345 hari = setahun'); | |
20156 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 tahun', '548 hari = 2 tahun'); | |
20157 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'setahun', '1 tahun = setahun'); | |
20158 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 tahun', '5 tahun = 5 tahun'); | |
20159 }); | |
20160 | |
20161 test('suffix', function (assert) { | |
20162 assert.equal(moment(30000).from(0), 'dalam beberapa saat', 'prefix'); | |
20163 assert.equal(moment(0).from(30000), 'beberapa saat yang lepas', 'suffix'); | |
20164 }); | |
20165 | |
20166 test('now from now', function (assert) { | |
20167 assert.equal(moment().fromNow(), 'beberapa saat yang lepas', 'waktu sekarang dari sekarang sepatutnya menunjukkan sebagai telah lepas'); | |
20168 }); | |
20169 | |
20170 test('fromNow', function (assert) { | |
20171 assert.equal(moment().add({s: 30}).fromNow(), 'dalam beberapa saat', 'dalam beberapa saat'); | |
20172 assert.equal(moment().add({d: 5}).fromNow(), 'dalam 5 hari', 'dalam 5 hari'); | |
20173 }); | |
20174 | |
20175 test('calendar day', function (assert) { | |
20176 var a = moment().hours(2).minutes(0).seconds(0); | |
20177 | |
20178 assert.equal(moment(a).calendar(), 'Hari ini pukul 02.00', 'hari ini pada waktu yang sama'); | |
20179 assert.equal(moment(a).add({m: 25}).calendar(), 'Hari ini pukul 02.25', 'Sekarang tambah 25 minit'); | |
20180 assert.equal(moment(a).add({h: 1}).calendar(), 'Hari ini pukul 03.00', 'Sekarang tambah 1 jam'); | |
20181 assert.equal(moment(a).add({d: 1}).calendar(), 'Esok pukul 02.00', 'esok pada waktu yang sama'); | |
20182 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Hari ini pukul 01.00', 'Sekarang tolak 1 jam'); | |
20183 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Kelmarin pukul 02.00', 'kelmarin pada waktu yang sama'); | |
20184 }); | |
20185 | |
20186 test('calendar next week', function (assert) { | |
20187 var i, m; | |
20188 for (i = 2; i < 7; i++) { | |
20189 m = moment().add({d: i}); | |
20190 assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Hari ini + ' + i + ' hari waktu sekarang'); | |
20191 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
20192 assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Hari ini + ' + i + ' hari permulaan hari'); | |
20193 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
20194 assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Hari ini + ' + i + ' hari tamat hari'); | |
20195 } | |
20196 }); | |
20197 | |
20198 test('calendar last week', function (assert) { | |
20199 var i, m; | |
20200 for (i = 2; i < 7; i++) { | |
20201 m = moment().subtract({d: i}); | |
20202 assert.equal(m.calendar(), m.format('dddd [lepas] [pukul] LT'), 'Hari ini - ' + i + ' hari waktu sekarang'); | |
20203 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
20204 assert.equal(m.calendar(), m.format('dddd [lepas] [pukul] LT'), 'Hari ini - ' + i + ' hari permulaan hari'); | |
20205 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
20206 assert.equal(m.calendar(), m.format('dddd [lepas] [pukul] LT'), 'Hari ini - ' + i + ' hari tamat hari'); | |
20207 } | |
20208 }); | |
20209 | |
20210 test('calendar all else', function (assert) { | |
20211 var weeksAgo = moment().subtract({w: 1}), | |
20212 weeksFromNow = moment().add({w: 1}); | |
20213 | |
20214 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 minggu lepas'); | |
20215 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'dalam 1 minggu'); | |
20216 | |
20217 weeksAgo = moment().subtract({w: 2}); | |
20218 weeksFromNow = moment().add({w: 2}); | |
20219 | |
20220 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 minggu lepas'); | |
20221 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'dalam 2 minggu'); | |
20222 }); | |
20223 | |
20224 test('weeks year starting sunday', function (assert) { | |
20225 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 sepatutnya minggu 1'); | |
20226 assert.equal(moment([2012, 0, 7]).week(), 2, 'Jan 7 2012 sepatutnya minggu 2'); | |
20227 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 sepatutnya minggu 2'); | |
20228 assert.equal(moment([2012, 0, 14]).week(), 3, 'Jan 14 2012 sepatutnya minggu 3'); | |
20229 assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 sepatutnya minggu 3'); | |
20230 }); | |
20231 | |
20232 test('weeks year starting monday', function (assert) { | |
20233 assert.equal(moment([2006, 11, 31]).week(), 53, 'Dec 31 2006 sepatutnya minggu 53'); | |
20234 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 sepatutnya minggu 1'); | |
20235 assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 sepatutnya minggu 1'); | |
20236 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 sepatutnya minggu 1'); | |
20237 assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 sepatutnya minggu 2'); | |
20238 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 sepatutnya minggu 2'); | |
20239 }); | |
20240 | |
20241 test('weeks year starting tuesday', function (assert) { | |
20242 assert.equal(moment([2007, 11, 30]).week(), 52, 'Dec 30 2007 sepatutnya minggu 52'); | |
20243 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 sepatutnya minggu 1'); | |
20244 assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 sepatutnya minggu 1'); | |
20245 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 sepatutnya minggu 1'); | |
20246 assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 sepatutnya minggu 2'); | |
20247 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 sepatutnya minggu 2'); | |
20248 }); | |
20249 | |
20250 test('weeks year starting wednesday', function (assert) { | |
20251 assert.equal(moment([2002, 11, 29]).week(), 52, 'Dec 29 2002 sepatutnya minggu 52'); | |
20252 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 sepatutnya minggu 1'); | |
20253 assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 sepatutnya minggu 1'); | |
20254 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 sepatutnya minggu 1'); | |
20255 assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 sepatutnya minggu 2'); | |
20256 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 sepatutnya minggu 2'); | |
20257 }); | |
20258 | |
20259 test('weeks year starting thursday', function (assert) { | |
20260 assert.equal(moment([2008, 11, 28]).week(), 52, 'Dec 28 2008 sepatutnya minggu 52'); | |
20261 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 sepatutnya minggu 1'); | |
20262 assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 sepatutnya minggu 1'); | |
20263 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 sepatutnya minggu 1'); | |
20264 assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 sepatutnya minggu 2'); | |
20265 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 sepatutnya minggu 2'); | |
20266 }); | |
20267 | |
20268 test('weeks year starting friday', function (assert) { | |
20269 assert.equal(moment([2009, 11, 27]).week(), 52, 'Dec 27 2009 sepatutnya minggu 52'); | |
20270 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 sepatutnya minggu 1'); | |
20271 assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 sepatutnya minggu 1'); | |
20272 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 sepatutnya minggu 1'); | |
20273 assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 sepatutnya minggu 2'); | |
20274 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 sepatutnya minggu 2'); | |
20275 }); | |
20276 | |
20277 test('weeks year starting saturday', function (assert) { | |
20278 assert.equal(moment([2010, 11, 26]).week(), 52, 'Dec 26 2010 sepatutnya minggu 52'); | |
20279 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 sepatutnya minggu 1'); | |
20280 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 sepatutnya minggu 1'); | |
20281 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 sepatutnya minggu 2'); | |
20282 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 sepatutnya minggu 2'); | |
20283 }); | |
20284 | |
20285 test('weeks year starting sunday format', function (assert) { | |
20286 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 sepatutnya minggu 1'); | |
20287 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '2 02 2', 'Jan 7 2012 sepatutnya minggu 2'); | |
20288 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 sepatutnya minggu 2'); | |
20289 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '3 03 3', 'Jan 14 2012 sepatutnya minggu 3'); | |
20290 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', 'Jan 15 2012 sepatutnya minggu 3'); | |
20291 }); | |
20292 | |
20293 test('lenient ordinal parsing', function (assert) { | |
20294 var i, ordinalStr, testMoment; | |
20295 for (i = 1; i <= 31; ++i) { | |
20296 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
20297 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
20298 assert.equal(testMoment.year(), 2014, | |
20299 'lenient ordinal parsing ' + i + ' year check'); | |
20300 assert.equal(testMoment.month(), 0, | |
20301 'lenient ordinal parsing ' + i + ' month check'); | |
20302 assert.equal(testMoment.date(), i, | |
20303 'lenient ordinal parsing ' + i + ' date check'); | |
20304 } | |
20305 }); | |
20306 | |
20307 test('meridiem invariant', function (assert) { | |
20308 var h, m, t1, t2; | |
20309 for (h = 0; h < 24; ++h) { | |
20310 for (m = 0; m < 60; m += 15) { | |
20311 t1 = moment.utc([2000, 0, 1, h, m]); | |
20312 t2 = moment(t1.format('A h:mm'), 'A h:mm'); | |
20313 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'), | |
20314 'meridiem at ' + t1.format('HH:mm')); | |
20315 } | |
20316 } | |
20317 }); | |
20318 | |
20319 test('lenient ordinal parsing of number', function (assert) { | |
20320 var i, testMoment; | |
20321 for (i = 1; i <= 31; ++i) { | |
20322 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
20323 assert.equal(testMoment.year(), 2014, | |
20324 'lenient ordinal parsing of number ' + i + ' year check'); | |
20325 assert.equal(testMoment.month(), 0, | |
20326 'lenient ordinal parsing of number ' + i + ' month check'); | |
20327 assert.equal(testMoment.date(), i, | |
20328 'lenient ordinal parsing of number ' + i + ' date check'); | |
20329 } | |
20330 }); | |
20331 | |
20332 test('strict ordinal parsing', function (assert) { | |
20333 var i, ordinalStr, testMoment; | |
20334 for (i = 1; i <= 31; ++i) { | |
20335 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
20336 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
20337 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
20338 } | |
20339 }); | |
20340 | |
20341 })); | |
20342 | |
20343 (function (global, factory) { | |
20344 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
20345 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
20346 factory(global.moment) | |
20347 }(this, function (moment) { 'use strict'; | |
20348 | |
20349 /*global QUnit:false*/ | |
20350 | |
20351 var test = QUnit.test; | |
20352 | |
20353 function module (name, lifecycle) { | |
20354 QUnit.module(name, { | |
20355 setup : function () { | |
20356 moment.locale('en'); | |
20357 moment.createFromInputFallback = function () { | |
20358 throw new Error('input not handled by moment'); | |
20359 }; | |
20360 if (lifecycle && lifecycle.setup) { | |
20361 lifecycle.setup(); | |
20362 } | |
20363 }, | |
20364 teardown : function () { | |
20365 if (lifecycle && lifecycle.teardown) { | |
20366 lifecycle.teardown(); | |
20367 } | |
20368 } | |
20369 }); | |
20370 } | |
20371 | |
20372 function localeModule (name, lifecycle) { | |
20373 QUnit.module('locale:' + name, { | |
20374 setup : function () { | |
20375 moment.locale(name); | |
20376 moment.createFromInputFallback = function () { | |
20377 throw new Error('input not handled by moment'); | |
20378 }; | |
20379 if (lifecycle && lifecycle.setup) { | |
20380 lifecycle.setup(); | |
20381 } | |
20382 }, | |
20383 teardown : function () { | |
20384 moment.locale('en'); | |
20385 if (lifecycle && lifecycle.teardown) { | |
20386 lifecycle.teardown(); | |
20387 } | |
20388 } | |
20389 }); | |
20390 } | |
20391 | |
20392 localeModule('ms'); | |
20393 | |
20394 test('parse', function (assert) { | |
20395 var i, | |
20396 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('_'); | |
20397 | |
20398 function equalTest(input, mmm, i) { | |
20399 assert.equal(moment(input, mmm).month(), i, input + ' sepatutnya bulan ' + (i + 1)); | |
20400 } | |
20401 | |
20402 for (i = 0; i < 12; i++) { | |
20403 tests[i] = tests[i].split(' '); | |
20404 equalTest(tests[i][0], 'MMM', i); | |
20405 equalTest(tests[i][1], 'MMM', i); | |
20406 equalTest(tests[i][0], 'MMMM', i); | |
20407 equalTest(tests[i][1], 'MMMM', i); | |
20408 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
20409 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
20410 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
20411 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
20412 } | |
20413 }); | |
20414 | |
20415 test('format', function (assert) { | |
20416 var a = [ | |
20417 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Ahad, Februari 14 2010, 3:25:50 petang'], | |
20418 ['ddd, hA', 'Ahd, 3petang'], | |
20419 ['M Mo MM MMMM MMM', '2 2 02 Februari Feb'], | |
20420 ['YYYY YY', '2010 10'], | |
20421 ['D Do DD', '14 14 14'], | |
20422 ['d do dddd ddd dd', '0 0 Ahad Ahd Ah'], | |
20423 ['DDD DDDo DDDD', '45 45 045'], | |
20424 ['w wo ww', '7 7 07'], | |
20425 ['h hh', '3 03'], | |
20426 ['H HH', '15 15'], | |
20427 ['m mm', '25 25'], | |
20428 ['s ss', '50 50'], | |
20429 ['a A', 'petang petang'], | |
20430 ['[hari] [ke] DDDo [tahun] ini', 'hari ke 45 tahun ini'], | |
20431 ['LTS', '15.25.50'], | |
20432 ['L', '14/02/2010'], | |
20433 ['LL', '14 Februari 2010'], | |
20434 ['LLL', '14 Februari 2010 pukul 15.25'], | |
20435 ['LLLL', 'Ahad, 14 Februari 2010 pukul 15.25'], | |
20436 ['l', '14/2/2010'], | |
20437 ['ll', '14 Feb 2010'], | |
20438 ['lll', '14 Feb 2010 pukul 15.25'], | |
20439 ['llll', 'Ahd, 14 Feb 2010 pukul 15.25'] | |
20440 ], | |
20441 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
20442 i; | |
20443 | |
20444 for (i = 0; i < a.length; i++) { | |
20445 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
20446 } | |
20447 }); | |
20448 | |
20449 test('format ordinal', function (assert) { | |
20450 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1'); | |
20451 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2'); | |
20452 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3'); | |
20453 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4'); | |
20454 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5'); | |
20455 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6'); | |
20456 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7'); | |
20457 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8'); | |
20458 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9'); | |
20459 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10'); | |
20460 | |
20461 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11'); | |
20462 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12'); | |
20463 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13'); | |
20464 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14'); | |
20465 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15'); | |
20466 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16'); | |
20467 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17'); | |
20468 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18'); | |
20469 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19'); | |
20470 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20'); | |
20471 | |
20472 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21'); | |
20473 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22'); | |
20474 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23'); | |
20475 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24'); | |
20476 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25'); | |
20477 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26'); | |
20478 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27'); | |
20479 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28'); | |
20480 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29'); | |
20481 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30'); | |
20482 | |
20483 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31'); | |
20484 }); | |
20485 | |
20486 test('format month', function (assert) { | |
20487 var i, | |
20488 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('_'); | |
20489 | |
20490 for (i = 0; i < expected.length; i++) { | |
20491 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
20492 } | |
20493 }); | |
20494 | |
20495 test('format week', function (assert) { | |
20496 var i, | |
20497 expected = 'Ahad Ahd Ah_Isnin Isn Is_Selasa Sel Sl_Rabu Rab Rb_Khamis Kha Km_Jumaat Jum Jm_Sabtu Sab Sb'.split('_'); | |
20498 | |
20499 for (i = 0; i < expected.length; i++) { | |
20500 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
20501 } | |
20502 }); | |
20503 | |
20504 test('from', function (assert) { | |
20505 var start = moment([2007, 1, 28]); | |
20506 | |
20507 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'beberapa saat', '44 saat = beberapa saat'); | |
20508 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'seminit', '45 saat = seminit'); | |
20509 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'seminit', '89 saat = seminit'); | |
20510 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minit', '90 saat = 2 minit'); | |
20511 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minit', '44 minit = 44 minit'); | |
20512 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'sejam', '45 minit = sejam'); | |
20513 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'sejam', '89 minit = sejam'); | |
20514 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 jam', '90 minit = 2 jam'); | |
20515 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 jam', '5 jam = 5 jam'); | |
20516 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 jam', '21 jam = 21 jam'); | |
20517 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'sehari', '22 jam = sehari'); | |
20518 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'sehari', '35 jam = sehari'); | |
20519 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 hari', '36 jam = 2 hari'); | |
20520 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'sehari', '1 hari = sehari'); | |
20521 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 hari', '5 hari = 5 hari'); | |
20522 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 hari', '25 hari = 25 hari'); | |
20523 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'sebulan', '26 hari = sebulan'); | |
20524 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'sebulan', '30 hari = sebulan'); | |
20525 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'sebulan', '45 hari = sebulan'); | |
20526 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 bulan', '46 hari = 2 bulan'); | |
20527 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 bulan', '75 hari = 2 bulan'); | |
20528 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 bulan', '76 hari = 3 bulan'); | |
20529 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'sebulan', '1 bulan = sebulan'); | |
20530 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 bulan', '5 bulan = 5 bulan'); | |
20531 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'setahun', '345 hari = setahun'); | |
20532 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 tahun', '548 hari = 2 tahun'); | |
20533 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'setahun', '1 tahun = setahun'); | |
20534 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 tahun', '5 tahun = 5 tahun'); | |
20535 }); | |
20536 | |
20537 test('suffix', function (assert) { | |
20538 assert.equal(moment(30000).from(0), 'dalam beberapa saat', 'prefix'); | |
20539 assert.equal(moment(0).from(30000), 'beberapa saat yang lepas', 'suffix'); | |
20540 }); | |
20541 | |
20542 test('now from now', function (assert) { | |
20543 assert.equal(moment().fromNow(), 'beberapa saat yang lepas', 'waktu sekarang dari sekarang sepatutnya menunjukkan sebagai telah lepas'); | |
20544 }); | |
20545 | |
20546 test('fromNow', function (assert) { | |
20547 assert.equal(moment().add({s: 30}).fromNow(), 'dalam beberapa saat', 'dalam beberapa saat'); | |
20548 assert.equal(moment().add({d: 5}).fromNow(), 'dalam 5 hari', 'dalam 5 hari'); | |
20549 }); | |
20550 | |
20551 test('calendar day', function (assert) { | |
20552 var a = moment().hours(2).minutes(0).seconds(0); | |
20553 | |
20554 assert.equal(moment(a).calendar(), 'Hari ini pukul 02.00', 'hari ini pada waktu yang sama'); | |
20555 assert.equal(moment(a).add({m: 25}).calendar(), 'Hari ini pukul 02.25', 'Sekarang tambah 25 minit'); | |
20556 assert.equal(moment(a).add({h: 1}).calendar(), 'Hari ini pukul 03.00', 'Sekarang tambah 1 jam'); | |
20557 assert.equal(moment(a).add({d: 1}).calendar(), 'Esok pukul 02.00', 'esok pada waktu yang sama'); | |
20558 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Hari ini pukul 01.00', 'Sekarang tolak 1 jam'); | |
20559 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Kelmarin pukul 02.00', 'kelmarin pada waktu yang sama'); | |
20560 }); | |
20561 | |
20562 test('calendar next week', function (assert) { | |
20563 var i, m; | |
20564 for (i = 2; i < 7; i++) { | |
20565 m = moment().add({d: i}); | |
20566 assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Hari ini + ' + i + ' hari waktu sekarang'); | |
20567 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
20568 assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Hari ini + ' + i + ' hari permulaan hari'); | |
20569 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
20570 assert.equal(m.calendar(), m.format('dddd [pukul] LT'), 'Hari ini + ' + i + ' hari tamat hari'); | |
20571 } | |
20572 }); | |
20573 | |
20574 test('calendar last week', function (assert) { | |
20575 var i, m; | |
20576 for (i = 2; i < 7; i++) { | |
20577 m = moment().subtract({d: i}); | |
20578 assert.equal(m.calendar(), m.format('dddd [lepas] [pukul] LT'), 'Hari ini - ' + i + ' hari waktu sekarang'); | |
20579 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
20580 assert.equal(m.calendar(), m.format('dddd [lepas] [pukul] LT'), 'Hari ini - ' + i + ' hari permulaan hari'); | |
20581 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
20582 assert.equal(m.calendar(), m.format('dddd [lepas] [pukul] LT'), 'Hari ini - ' + i + ' hari tamat hari'); | |
20583 } | |
20584 }); | |
20585 | |
20586 test('calendar all else', function (assert) { | |
20587 var weeksAgo = moment().subtract({w: 1}), | |
20588 weeksFromNow = moment().add({w: 1}); | |
20589 | |
20590 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 minggu lepas'); | |
20591 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'dalam 1 minggu'); | |
20592 | |
20593 weeksAgo = moment().subtract({w: 2}); | |
20594 weeksFromNow = moment().add({w: 2}); | |
20595 | |
20596 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 minggu lepas'); | |
20597 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'dalam 2 minggu'); | |
20598 }); | |
20599 | |
20600 test('weeks year starting sunday', function (assert) { | |
20601 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 sepatutnya minggu 1'); | |
20602 assert.equal(moment([2012, 0, 7]).week(), 2, 'Jan 7 2012 sepatutnya minggu 2'); | |
20603 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 sepatutnya minggu 2'); | |
20604 assert.equal(moment([2012, 0, 14]).week(), 3, 'Jan 14 2012 sepatutnya minggu 3'); | |
20605 assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 sepatutnya minggu 3'); | |
20606 }); | |
20607 | |
20608 test('weeks year starting monday', function (assert) { | |
20609 assert.equal(moment([2006, 11, 31]).week(), 53, 'Dec 31 2006 sepatutnya minggu 53'); | |
20610 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 sepatutnya minggu 1'); | |
20611 assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 sepatutnya minggu 1'); | |
20612 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 sepatutnya minggu 1'); | |
20613 assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 sepatutnya minggu 2'); | |
20614 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 sepatutnya minggu 2'); | |
20615 }); | |
20616 | |
20617 test('weeks year starting tuesday', function (assert) { | |
20618 assert.equal(moment([2007, 11, 30]).week(), 52, 'Dec 30 2007 sepatutnya minggu 52'); | |
20619 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 sepatutnya minggu 1'); | |
20620 assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 sepatutnya minggu 1'); | |
20621 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 sepatutnya minggu 1'); | |
20622 assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 sepatutnya minggu 2'); | |
20623 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 sepatutnya minggu 2'); | |
20624 }); | |
20625 | |
20626 test('weeks year starting wednesday', function (assert) { | |
20627 assert.equal(moment([2002, 11, 29]).week(), 52, 'Dec 29 2002 sepatutnya minggu 52'); | |
20628 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 sepatutnya minggu 1'); | |
20629 assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 sepatutnya minggu 1'); | |
20630 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 sepatutnya minggu 1'); | |
20631 assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 sepatutnya minggu 2'); | |
20632 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 sepatutnya minggu 2'); | |
20633 }); | |
20634 | |
20635 test('weeks year starting thursday', function (assert) { | |
20636 assert.equal(moment([2008, 11, 28]).week(), 52, 'Dec 28 2008 sepatutnya minggu 52'); | |
20637 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 sepatutnya minggu 1'); | |
20638 assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 sepatutnya minggu 1'); | |
20639 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 sepatutnya minggu 1'); | |
20640 assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 sepatutnya minggu 2'); | |
20641 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 sepatutnya minggu 2'); | |
20642 }); | |
20643 | |
20644 test('weeks year starting friday', function (assert) { | |
20645 assert.equal(moment([2009, 11, 27]).week(), 52, 'Dec 27 2009 sepatutnya minggu 52'); | |
20646 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 sepatutnya minggu 1'); | |
20647 assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 sepatutnya minggu 1'); | |
20648 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 sepatutnya minggu 1'); | |
20649 assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 sepatutnya minggu 2'); | |
20650 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 sepatutnya minggu 2'); | |
20651 }); | |
20652 | |
20653 test('weeks year starting saturday', function (assert) { | |
20654 assert.equal(moment([2010, 11, 26]).week(), 52, 'Dec 26 2010 sepatutnya minggu 52'); | |
20655 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 sepatutnya minggu 1'); | |
20656 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 sepatutnya minggu 1'); | |
20657 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 sepatutnya minggu 2'); | |
20658 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 sepatutnya minggu 2'); | |
20659 }); | |
20660 | |
20661 test('weeks year starting sunday format', function (assert) { | |
20662 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 sepatutnya minggu 1'); | |
20663 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '2 02 2', 'Jan 7 2012 sepatutnya minggu 2'); | |
20664 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 sepatutnya minggu 2'); | |
20665 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '3 03 3', 'Jan 14 2012 sepatutnya minggu 3'); | |
20666 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', 'Jan 15 2012 sepatutnya minggu 3'); | |
20667 }); | |
20668 | |
20669 test('lenient ordinal parsing', function (assert) { | |
20670 var i, ordinalStr, testMoment; | |
20671 for (i = 1; i <= 31; ++i) { | |
20672 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
20673 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
20674 assert.equal(testMoment.year(), 2014, | |
20675 'lenient ordinal parsing ' + i + ' year check'); | |
20676 assert.equal(testMoment.month(), 0, | |
20677 'lenient ordinal parsing ' + i + ' month check'); | |
20678 assert.equal(testMoment.date(), i, | |
20679 'lenient ordinal parsing ' + i + ' date check'); | |
20680 } | |
20681 }); | |
20682 | |
20683 test('meridiem invariant', function (assert) { | |
20684 var h, m, t1, t2; | |
20685 for (h = 0; h < 24; ++h) { | |
20686 for (m = 0; m < 60; m += 15) { | |
20687 t1 = moment.utc([2000, 0, 1, h, m]); | |
20688 t2 = moment(t1.format('A h:mm'), 'A h:mm'); | |
20689 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'), | |
20690 'meridiem at ' + t1.format('HH:mm')); | |
20691 } | |
20692 } | |
20693 }); | |
20694 | |
20695 test('lenient ordinal parsing of number', function (assert) { | |
20696 var i, testMoment; | |
20697 for (i = 1; i <= 31; ++i) { | |
20698 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
20699 assert.equal(testMoment.year(), 2014, | |
20700 'lenient ordinal parsing of number ' + i + ' year check'); | |
20701 assert.equal(testMoment.month(), 0, | |
20702 'lenient ordinal parsing of number ' + i + ' month check'); | |
20703 assert.equal(testMoment.date(), i, | |
20704 'lenient ordinal parsing of number ' + i + ' date check'); | |
20705 } | |
20706 }); | |
20707 | |
20708 test('strict ordinal parsing', function (assert) { | |
20709 var i, ordinalStr, testMoment; | |
20710 for (i = 1; i <= 31; ++i) { | |
20711 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
20712 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
20713 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
20714 } | |
20715 }); | |
20716 | |
20717 })); | |
20718 | |
20719 (function (global, factory) { | |
20720 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
20721 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
20722 factory(global.moment) | |
20723 }(this, function (moment) { 'use strict'; | |
20724 | |
20725 /*global QUnit:false*/ | |
20726 | |
20727 var test = QUnit.test; | |
20728 | |
20729 function module (name, lifecycle) { | |
20730 QUnit.module(name, { | |
20731 setup : function () { | |
20732 moment.locale('en'); | |
20733 moment.createFromInputFallback = function () { | |
20734 throw new Error('input not handled by moment'); | |
20735 }; | |
20736 if (lifecycle && lifecycle.setup) { | |
20737 lifecycle.setup(); | |
20738 } | |
20739 }, | |
20740 teardown : function () { | |
20741 if (lifecycle && lifecycle.teardown) { | |
20742 lifecycle.teardown(); | |
20743 } | |
20744 } | |
20745 }); | |
20746 } | |
20747 | |
20748 function localeModule (name, lifecycle) { | |
20749 QUnit.module('locale:' + name, { | |
20750 setup : function () { | |
20751 moment.locale(name); | |
20752 moment.createFromInputFallback = function () { | |
20753 throw new Error('input not handled by moment'); | |
20754 }; | |
20755 if (lifecycle && lifecycle.setup) { | |
20756 lifecycle.setup(); | |
20757 } | |
20758 }, | |
20759 teardown : function () { | |
20760 moment.locale('en'); | |
20761 if (lifecycle && lifecycle.teardown) { | |
20762 lifecycle.teardown(); | |
20763 } | |
20764 } | |
20765 }); | |
20766 } | |
20767 | |
20768 localeModule('my'); | |
20769 | |
20770 test('parse', function (assert) { | |
20771 var tests = 'ဇန်နဝါရီ ဇန်_ဖေဖော်ဝါရီ ဖေ_မတ် မတ်_ဧပြီ ပြီ_မေ မေ_ဇွန် ဇွန်_ဇူလိုင် လိုင်_သြဂုတ် သြ_စက်တင်ဘာ စက်_အောက်တိုဘာ အောက်_နိုဝင်ဘာ နို_ဒီဇင်ဘာ ဒီ'.split('_'), | |
20772 i; | |
20773 | |
20774 function equalTest (input, mmm, i) { | |
20775 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
20776 } | |
20777 for (i = 0; i < 12; i++) { | |
20778 tests[i] = tests[i].split(' '); | |
20779 equalTest(tests[i][0], 'MMM', i); | |
20780 equalTest(tests[i][1], 'MMM', i); | |
20781 equalTest(tests[i][0], 'MMMM', i); | |
20782 equalTest(tests[i][1], 'MMMM', i); | |
20783 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
20784 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
20785 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
20786 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
20787 } | |
20788 }); | |
20789 | |
20790 test('format', function (assert) { | |
20791 var a = [ | |
20792 ['dddd, MMMM Do YYYY, h:mm:ss a', 'တနင်္ဂနွေ, ဖေဖော်ဝါရီ ၁၄ ၂၀၁၀, ၃:၂၅:၅၀ pm'], | |
20793 ['ddd, hA', 'နွေ, ၃PM'], | |
20794 ['M Mo MM MMMM MMM', '၂ ၂ ၀၂ ဖေဖော်ဝါရီ ဖေ'], | |
20795 ['YYYY YY', '၂၀၁၀ ၁၀'], | |
20796 ['D Do DD', '၁၄ ၁၄ ၁၄'], | |
20797 ['d do dddd ddd dd', '၀ ၀ တနင်္ဂနွေ နွေ နွေ'], | |
20798 ['DDD DDDo DDDD', '၄၅ ၄၅ ၀၄၅'], | |
20799 ['w wo ww', '၆ ၆ ၀၆'], | |
20800 ['h hh', '၃ ၀၃'], | |
20801 ['H HH', '၁၅ ၁၅'], | |
20802 ['m mm', '၂၅ ၂၅'], | |
20803 ['s ss', '၅၀ ၅၀'], | |
20804 ['a A', 'pm PM'], | |
20805 ['[နှစ်၏] DDDo [ရက်မြောက်]', 'နှစ်၏ ၄၅ ရက်မြောက်'], | |
20806 ['LTS', '၁၅:၂၅:၅၀'], | |
20807 ['L', '၁၄/၀၂/၂၀၁၀'], | |
20808 ['LL', '၁၄ ဖေဖော်ဝါရီ ၂၀၁၀'], | |
20809 ['LLL', '၁၄ ဖေဖော်ဝါရီ ၂၀၁၀ ၁၅:၂၅'], | |
20810 ['LLLL', 'တနင်္ဂနွေ ၁၄ ဖေဖော်ဝါရီ ၂၀၁၀ ၁၅:၂၅'], | |
20811 ['l', '၁၄/၂/၂၀၁၀'], | |
20812 ['ll', '၁၄ ဖေ ၂၀၁၀'], | |
20813 ['lll', '၁၄ ဖေ ၂၀၁၀ ၁၅:၂၅'], | |
20814 ['llll', 'နွေ ၁၄ ဖေ ၂၀၁၀ ၁၅:၂၅'] | |
20815 ], | |
20816 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
20817 i; | |
20818 for (i = 0; i < a.length; i++) { | |
20819 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
20820 } | |
20821 }); | |
20822 | |
20823 test('format ordinal', function (assert) { | |
20824 assert.equal(moment([2011, 0, 1]).format('DDDo'), '၁', '၁'); | |
20825 assert.equal(moment([2011, 0, 2]).format('DDDo'), '၂', '၂'); | |
20826 assert.equal(moment([2011, 0, 3]).format('DDDo'), '၃', '၃'); | |
20827 assert.equal(moment([2011, 0, 4]).format('DDDo'), '၄', '၄'); | |
20828 assert.equal(moment([2011, 0, 5]).format('DDDo'), '၅', '၅'); | |
20829 assert.equal(moment([2011, 0, 6]).format('DDDo'), '၆', '၆'); | |
20830 assert.equal(moment([2011, 0, 7]).format('DDDo'), '၇', '၇'); | |
20831 assert.equal(moment([2011, 0, 8]).format('DDDo'), '၈', '၈'); | |
20832 assert.equal(moment([2011, 0, 9]).format('DDDo'), '၉', '၉'); | |
20833 assert.equal(moment([2011, 0, 10]).format('DDDo'), '၁၀', '၁၀'); | |
20834 | |
20835 assert.equal(moment([2011, 0, 11]).format('DDDo'), '၁၁', '၁၁'); | |
20836 assert.equal(moment([2011, 0, 12]).format('DDDo'), '၁၂', '၁၂'); | |
20837 assert.equal(moment([2011, 0, 13]).format('DDDo'), '၁၃', '၁၃'); | |
20838 assert.equal(moment([2011, 0, 14]).format('DDDo'), '၁၄', '၁၄'); | |
20839 assert.equal(moment([2011, 0, 15]).format('DDDo'), '၁၅', '၁၅'); | |
20840 assert.equal(moment([2011, 0, 16]).format('DDDo'), '၁၆', '၁၆'); | |
20841 assert.equal(moment([2011, 0, 17]).format('DDDo'), '၁၇', '၁၇'); | |
20842 assert.equal(moment([2011, 0, 18]).format('DDDo'), '၁၈', '၁၈'); | |
20843 assert.equal(moment([2011, 0, 19]).format('DDDo'), '၁၉', '၁၉'); | |
20844 assert.equal(moment([2011, 0, 20]).format('DDDo'), '၂၀', '၂၀'); | |
20845 | |
20846 assert.equal(moment([2011, 0, 21]).format('DDDo'), '၂၁', '၂၁'); | |
20847 assert.equal(moment([2011, 0, 22]).format('DDDo'), '၂၂', '၂၂'); | |
20848 assert.equal(moment([2011, 0, 23]).format('DDDo'), '၂၃', '၂၃'); | |
20849 assert.equal(moment([2011, 0, 24]).format('DDDo'), '၂၄', '၂၄'); | |
20850 assert.equal(moment([2011, 0, 25]).format('DDDo'), '၂၅', '၂၅'); | |
20851 assert.equal(moment([2011, 0, 26]).format('DDDo'), '၂၆', '၂၆'); | |
20852 assert.equal(moment([2011, 0, 27]).format('DDDo'), '၂၇', '၂၇'); | |
20853 assert.equal(moment([2011, 0, 28]).format('DDDo'), '၂၈', '၂၈'); | |
20854 assert.equal(moment([2011, 0, 29]).format('DDDo'), '၂၉', '၂၉'); | |
20855 assert.equal(moment([2011, 0, 30]).format('DDDo'), '၃၀', '၃၀'); | |
20856 | |
20857 assert.equal(moment([2011, 0, 31]).format('DDDo'), '၃၁', '၃၁'); | |
20858 }); | |
20859 | |
20860 test('format month', function (assert) { | |
20861 var expected = 'ဇန်နဝါရီ ဇန်_ဖေဖော်ဝါရီ ဖေ_မတ် မတ်_ဧပြီ ပြီ_မေ မေ_ဇွန် ဇွန်_ဇူလိုင် လိုင်_သြဂုတ် သြ_စက်တင်ဘာ စက်_အောက်တိုဘာ အောက်_နိုဝင်ဘာ နို_ဒီဇင်ဘာ ဒီ'.split('_'), | |
20862 i; | |
20863 for (i = 0; i < expected.length; i++) { | |
20864 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
20865 } | |
20866 }); | |
20867 | |
20868 test('format week', function (assert) { | |
20869 var expected = 'တနင်္ဂနွေ နွေ နွေ_တနင်္လာ လာ လာ_အင်္ဂါ ဂါ ဂါ_ဗုဒ္ဓဟူး ဟူး ဟူး_ကြာသပတေး ကြာ ကြာ_သောကြာ သော သော_စနေ နေ နေ'.split('_'), | |
20870 i; | |
20871 | |
20872 for (i = 0; i < expected.length; i++) { | |
20873 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
20874 } | |
20875 }); | |
20876 | |
20877 test('from', function (assert) { | |
20878 var start = moment([2007, 1, 28]); | |
20879 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20880 s: 44 | |
20881 }), true), 'စက္ကန်.အနည်းငယ်', '၄၄ စက္ကန်. = စက္ကန်.အနည်းငယ်'); | |
20882 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20883 s: 45 | |
20884 }), true), 'တစ်မိနစ်', '၄၅ စက္ကန်. = တစ်မိနစ်'); | |
20885 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20886 s: 89 | |
20887 }), true), 'တစ်မိနစ်', '၈၉ စက္ကန်. = တစ်မိနစ်'); | |
20888 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20889 s: 90 | |
20890 }), true), '၂ မိနစ်', '၉၀ စက္ကန်. = ၂ မိနစ်'); | |
20891 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20892 m: 44 | |
20893 }), true), '၄၄ မိနစ်', '၄၄ မိနစ် = ၄၄ မိနစ်'); | |
20894 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20895 m: 45 | |
20896 }), true), 'တစ်နာရီ', '၄၅ မိနစ် = ၁ နာရီ'); | |
20897 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20898 m: 89 | |
20899 }), true), 'တစ်နာရီ', '၈၉ မိနစ် = တစ်နာရီ'); | |
20900 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20901 m: 90 | |
20902 }), true), '၂ နာရီ', 'မိနစ် ၉၀= ၂ နာရီ'); | |
20903 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20904 h: 5 | |
20905 }), true), '၅ နာရီ', '၅ နာရီ= ၅ နာရီ'); | |
20906 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20907 h: 21 | |
20908 }), true), '၂၁ နာရီ', '၂၁ နာရီ =၂၁ နာရီ'); | |
20909 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20910 h: 22 | |
20911 }), true), 'တစ်ရက်', '၂၂ နာရီ =တစ်ရက်'); | |
20912 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20913 h: 35 | |
20914 }), true), 'တစ်ရက်', '၃၅ နာရီ =တစ်ရက်'); | |
20915 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20916 h: 36 | |
20917 }), true), '၂ ရက်', '၃၆ နာရီ = ၂ ရက်'); | |
20918 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20919 d: 1 | |
20920 }), true), 'တစ်ရက်', '၁ ရက်= တစ်ရက်'); | |
20921 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20922 d: 5 | |
20923 }), true), '၅ ရက်', '၅ ရက် = ၅ ရက်'); | |
20924 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20925 d: 25 | |
20926 }), true), '၂၅ ရက်', '၂၅ ရက်= ၂၅ ရက်'); | |
20927 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20928 d: 26 | |
20929 }), true), 'တစ်လ', '၂၆ ရက် = တစ်လ'); | |
20930 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20931 d: 30 | |
20932 }), true), 'တစ်လ', 'ရက် ၃၀ = တစ်လ'); | |
20933 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20934 d: 43 | |
20935 }), true), 'တစ်လ', '၄၃ ရက် = တစ်လ'); | |
20936 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20937 d: 46 | |
20938 }), true), '၂ လ', '၄၆ ရက် = ၂ လ'); | |
20939 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20940 d: 74 | |
20941 }), true), '၂ လ', '၇၅ ရက်= ၂ လ'); | |
20942 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20943 d: 76 | |
20944 }), true), '၃ လ', '၇၆ ရက် = ၃ လ'); | |
20945 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20946 M: 1 | |
20947 }), true), 'တစ်လ', '၁ လ = တစ်လ'); | |
20948 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20949 M: 5 | |
20950 }), true), '၅ လ', '၅ လ = ၅ လ'); | |
20951 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20952 d: 345 | |
20953 }), true), 'တစ်နှစ်', '၃၄၅ ရက် = တစ်နှစ်'); | |
20954 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20955 d: 548 | |
20956 }), true), '၂ နှစ်', '၅၄၈ ရက် = ၂ နှစ်'); | |
20957 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20958 y: 1 | |
20959 }), true), 'တစ်နှစ်', '၁ နှစ် = တစ်နှစ်'); | |
20960 assert.equal(start.from(moment([2007, 1, 28]).add({ | |
20961 y: 5 | |
20962 }), true), '၅ နှစ်', '၅ နှစ် = ၅ နှစ်'); | |
20963 }); | |
20964 | |
20965 test('suffix', function (assert) { | |
20966 assert.equal(moment(30000).from(0), 'လာမည့် စက္ကန်.အနည်းငယ် မှာ', 'prefix'); | |
20967 assert.equal(moment(0).from(30000), 'လွန်ခဲ့သော စက္ကန်.အနည်းငယ် က', 'suffix'); | |
20968 }); | |
20969 | |
20970 test('now from now', function (assert) { | |
20971 assert.equal(moment().fromNow(), 'လွန်ခဲ့သော စက္ကန်.အနည်းငယ် က', 'ယခုမှစပြီး အတိတ်တွင်ဖော်ပြသလိုဖော်ပြမည်'); | |
20972 }); | |
20973 | |
20974 test('fromNow', function (assert) { | |
20975 assert.equal(moment().add({ | |
20976 s: 30 | |
20977 }).fromNow(), 'လာမည့် စက္ကန်.အနည်းငယ် မှာ', 'လာမည့် စက္ကန်.အနည်းငယ် မှာ'); | |
20978 assert.equal(moment().add({ | |
20979 d: 5 | |
20980 }).fromNow(), 'လာမည့် ၅ ရက် မှာ', 'လာမည့် ၅ ရက် မှာ'); | |
20981 }); | |
20982 | |
20983 test('calendar day', function (assert) { | |
20984 var a = moment().hours(2).minutes(0).seconds(0); | |
20985 | |
20986 assert.equal(moment(a).calendar(), 'ယနေ. ၀၂:၀၀ မှာ', 'ယနေ. ဒီအချိန်'); | |
20987 assert.equal(moment(a).add({ | |
20988 m: 25 | |
20989 }).calendar(), 'ယနေ. ၀၂:၂၅ မှာ', 'ယခုမှ ၂၅ မိနစ်ပေါင်းထည့်'); | |
20990 assert.equal(moment(a).add({ | |
20991 h: 1 | |
20992 }).calendar(), 'ယနေ. ၀၃:၀၀ မှာ', 'ယခုမှ ၁ နာရီပေါင်းထည့်'); | |
20993 assert.equal(moment(a).add({ | |
20994 d: 1 | |
20995 }).calendar(), 'မနက်ဖြန် ၀၂:၀၀ မှာ', 'မနက်ဖြန် ဒီအချိန်'); | |
20996 assert.equal(moment(a).subtract({ | |
20997 h: 1 | |
20998 }).calendar(), 'ယနေ. ၀၁:၀၀ မှာ', 'ယခုမှ ၁ နာရီနှုတ်'); | |
20999 assert.equal(moment(a).subtract({ | |
21000 d: 1 | |
21001 }).calendar(), 'မနေ.က ၀၂:၀၀ မှာ', 'မနေ.က ဒီအချိန်'); | |
21002 }); | |
21003 | |
21004 test('calendar next week', function (assert) { | |
21005 var i, m; | |
21006 for (i = 2; i < 7; i++) { | |
21007 m = moment().add({ | |
21008 d: i | |
21009 }); | |
21010 assert.equal(m.calendar(), m.format('dddd LT [မှာ]'), 'Today + ' + i + ' days current time'); | |
21011 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
21012 assert.equal(m.calendar(), m.format('dddd LT [မှာ]'), 'Today + ' + i + ' days beginning of day'); | |
21013 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
21014 assert.equal(m.calendar(), m.format('dddd LT [မှာ]'), 'Today + ' + i + ' days end of day'); | |
21015 } | |
21016 }); | |
21017 | |
21018 test('calendar last week', function (assert) { | |
21019 var i, m; | |
21020 | |
21021 for (i = 2; i < 7; i++) { | |
21022 m = moment().subtract({ | |
21023 d: i | |
21024 }); | |
21025 assert.equal(m.calendar(), m.format('[ပြီးခဲ့သော] dddd LT [မှာ]'), 'Today - ' + i + ' days current time'); | |
21026 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
21027 assert.equal(m.calendar(), m.format('[ပြီးခဲ့သော] dddd LT [မှာ]'), 'Today - ' + i + ' days beginning of day'); | |
21028 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
21029 assert.equal(m.calendar(), m.format('[ပြီးခဲ့သော] dddd LT [မှာ]'), 'Today - ' + i + ' days end of day'); | |
21030 } | |
21031 }); | |
21032 | |
21033 test('calendar all else', function (assert) { | |
21034 var weeksAgo = moment().subtract({ | |
21035 w: 1 | |
21036 }), | |
21037 weeksFromNow = moment().add({ | |
21038 w: 1 | |
21039 }); | |
21040 | |
21041 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), 'လွန်ခဲ့သော ၁ ပတ်က'); | |
21042 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), '၁ ပတ်အတွင်း'); | |
21043 | |
21044 weeksAgo = moment().subtract({ | |
21045 w: 2 | |
21046 }); | |
21047 weeksFromNow = moment().add({ | |
21048 w: 2 | |
21049 }); | |
21050 | |
21051 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '၂ ပတ် အရင်က'); | |
21052 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), '၂ ပတ် အတွင်း'); | |
21053 }); | |
21054 | |
21055 test('weeks year starting sunday', function (assert) { | |
21056 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
21057 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
21058 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
21059 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
21060 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
21061 }); | |
21062 | |
21063 test('weeks year starting monday', function (assert) { | |
21064 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
21065 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
21066 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
21067 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
21068 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
21069 }); | |
21070 | |
21071 test('weeks year starting tuesday', function (assert) { | |
21072 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
21073 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
21074 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
21075 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
21076 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
21077 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
21078 }); | |
21079 | |
21080 test('weeks year starting wednesday', function (assert) { | |
21081 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
21082 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
21083 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
21084 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
21085 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
21086 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
21087 }); | |
21088 | |
21089 test('weeks year starting thursday', function (assert) { | |
21090 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
21091 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
21092 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
21093 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
21094 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
21095 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
21096 }); | |
21097 | |
21098 test('weeks year starting friday', function (assert) { | |
21099 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
21100 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
21101 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
21102 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
21103 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
21104 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
21105 }); | |
21106 | |
21107 test('weeks year starting saturday', function (assert) { | |
21108 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
21109 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
21110 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
21111 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
21112 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
21113 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
21114 }); | |
21115 | |
21116 test('weeks year starting sunday formatted', function (assert) { | |
21117 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '၅၂ ၅၂ ၅၂', 'Jan 1 2012 should be week 52'); | |
21118 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '၁ ၀၁ ၁', 'Jan 2 2012 should be week 1'); | |
21119 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '၁ ၀၁ ၁', 'Jan 8 2012 should be week 1'); | |
21120 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '၂ ၀၂ ၂', 'Jan 9 2012 should be week 2'); | |
21121 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '၂ ၀၂ ၂', 'Jan 15 2012 should be week 2'); | |
21122 }); | |
21123 | |
21124 test('lenient ordinal parsing', function (assert) { | |
21125 var i, ordinalStr, testMoment; | |
21126 for (i = 1; i <= 31; ++i) { | |
21127 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
21128 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
21129 assert.equal(testMoment.year(), 2014, | |
21130 'lenient ordinal parsing ' + i + ' year check'); | |
21131 assert.equal(testMoment.month(), 0, | |
21132 'lenient ordinal parsing ' + i + ' month check'); | |
21133 assert.equal(testMoment.date(), i, | |
21134 'lenient ordinal parsing ' + i + ' date check'); | |
21135 } | |
21136 }); | |
21137 | |
21138 test('lenient ordinal parsing of number', function (assert) { | |
21139 var i, testMoment; | |
21140 for (i = 1; i <= 31; ++i) { | |
21141 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
21142 assert.equal(testMoment.year(), 2014, | |
21143 'lenient ordinal parsing of number ' + i + ' year check'); | |
21144 assert.equal(testMoment.month(), 0, | |
21145 'lenient ordinal parsing of number ' + i + ' month check'); | |
21146 assert.equal(testMoment.date(), i, | |
21147 'lenient ordinal parsing of number ' + i + ' date check'); | |
21148 } | |
21149 }); | |
21150 | |
21151 test('strict ordinal parsing', function (assert) { | |
21152 var i, ordinalStr, testMoment; | |
21153 for (i = 1; i <= 31; ++i) { | |
21154 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
21155 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
21156 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
21157 } | |
21158 }); | |
21159 | |
21160 })); | |
21161 | |
21162 (function (global, factory) { | |
21163 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
21164 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
21165 factory(global.moment) | |
21166 }(this, function (moment) { 'use strict'; | |
21167 | |
21168 /*global QUnit:false*/ | |
21169 | |
21170 var test = QUnit.test; | |
21171 | |
21172 function module (name, lifecycle) { | |
21173 QUnit.module(name, { | |
21174 setup : function () { | |
21175 moment.locale('en'); | |
21176 moment.createFromInputFallback = function () { | |
21177 throw new Error('input not handled by moment'); | |
21178 }; | |
21179 if (lifecycle && lifecycle.setup) { | |
21180 lifecycle.setup(); | |
21181 } | |
21182 }, | |
21183 teardown : function () { | |
21184 if (lifecycle && lifecycle.teardown) { | |
21185 lifecycle.teardown(); | |
21186 } | |
21187 } | |
21188 }); | |
21189 } | |
21190 | |
21191 function localeModule (name, lifecycle) { | |
21192 QUnit.module('locale:' + name, { | |
21193 setup : function () { | |
21194 moment.locale(name); | |
21195 moment.createFromInputFallback = function () { | |
21196 throw new Error('input not handled by moment'); | |
21197 }; | |
21198 if (lifecycle && lifecycle.setup) { | |
21199 lifecycle.setup(); | |
21200 } | |
21201 }, | |
21202 teardown : function () { | |
21203 moment.locale('en'); | |
21204 if (lifecycle && lifecycle.teardown) { | |
21205 lifecycle.teardown(); | |
21206 } | |
21207 } | |
21208 }); | |
21209 } | |
21210 | |
21211 localeModule('nb'); | |
21212 | |
21213 test('parse', function (assert) { | |
21214 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('_'), | |
21215 i; | |
21216 function equalTest(input, mmm, i) { | |
21217 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
21218 } | |
21219 for (i = 0; i < 12; i++) { | |
21220 tests[i] = tests[i].split(' '); | |
21221 equalTest(tests[i][0], 'MMM', i); | |
21222 equalTest(tests[i][1], 'MMM', i); | |
21223 equalTest(tests[i][0], 'MMMM', i); | |
21224 equalTest(tests[i][1], 'MMMM', i); | |
21225 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
21226 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
21227 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
21228 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
21229 } | |
21230 }); | |
21231 | |
21232 test('format', function (assert) { | |
21233 var a = [ | |
21234 ['dddd, MMMM Do YYYY, h:mm:ss a', 'søndag, februar 14. 2010, 3:25:50 pm'], | |
21235 ['ddd, hA', 'søn, 3PM'], | |
21236 ['M Mo MM MMMM MMM', '2 2. 02 februar feb'], | |
21237 ['YYYY YY', '2010 10'], | |
21238 ['D Do DD', '14 14. 14'], | |
21239 ['d do dddd ddd dd', '0 0. søndag søn sø'], | |
21240 ['DDD DDDo DDDD', '45 45. 045'], | |
21241 ['w wo ww', '6 6. 06'], | |
21242 ['h hh', '3 03'], | |
21243 ['H HH', '15 15'], | |
21244 ['m mm', '25 25'], | |
21245 ['s ss', '50 50'], | |
21246 ['a A', 'pm PM'], | |
21247 ['[den] DDDo [dagen i året]', 'den 45. dagen i året'], | |
21248 ['LTS', '15.25.50'], | |
21249 ['L', '14.02.2010'], | |
21250 ['LL', '14. februar 2010'], | |
21251 ['LLL', '14. februar 2010 kl. 15.25'], | |
21252 ['LLLL', 'søndag 14. februar 2010 kl. 15.25'], | |
21253 ['l', '14.2.2010'], | |
21254 ['ll', '14. feb 2010'], | |
21255 ['lll', '14. feb 2010 kl. 15.25'], | |
21256 ['llll', 'søn 14. feb 2010 kl. 15.25'] | |
21257 ], | |
21258 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
21259 i; | |
21260 for (i = 0; i < a.length; i++) { | |
21261 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
21262 } | |
21263 }); | |
21264 | |
21265 test('format ordinal', function (assert) { | |
21266 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.'); | |
21267 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.'); | |
21268 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.'); | |
21269 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.'); | |
21270 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.'); | |
21271 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.'); | |
21272 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.'); | |
21273 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.'); | |
21274 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.'); | |
21275 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.'); | |
21276 | |
21277 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.'); | |
21278 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.'); | |
21279 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.'); | |
21280 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.'); | |
21281 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.'); | |
21282 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.'); | |
21283 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.'); | |
21284 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.'); | |
21285 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.'); | |
21286 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.'); | |
21287 | |
21288 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.'); | |
21289 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.'); | |
21290 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.'); | |
21291 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.'); | |
21292 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.'); | |
21293 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.'); | |
21294 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.'); | |
21295 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.'); | |
21296 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.'); | |
21297 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.'); | |
21298 | |
21299 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.'); | |
21300 }); | |
21301 | |
21302 test('format month', function (assert) { | |
21303 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; | |
21304 for (i = 0; i < expected.length; i++) { | |
21305 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
21306 } | |
21307 }); | |
21308 | |
21309 test('format week', function (assert) { | |
21310 var expected = 'søndag søn sø_mandag man ma_tirsdag tirs ti_onsdag ons on_torsdag tors to_fredag fre fr_lørdag lør lø'.split('_'), i; | |
21311 for (i = 0; i < expected.length; i++) { | |
21312 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
21313 } | |
21314 }); | |
21315 | |
21316 test('from', function (assert) { | |
21317 var start = moment([2007, 1, 28]); | |
21318 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'noen sekunder', '44 sekunder = a few seconds'); | |
21319 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ett minutt', '45 seconds = a minute'); | |
21320 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ett minutt', '89 seconds = a minute'); | |
21321 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutter', '90 seconds = 2 minutes'); | |
21322 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutter', '44 minutes = 44 minutes'); | |
21323 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'en time', '45 minutes = an hour'); | |
21324 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'en time', '89 minutes = an hour'); | |
21325 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 timer', '90 minutes = 2 hours'); | |
21326 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 timer', '5 hours = 5 hours'); | |
21327 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 timer', '21 hours = 21 hours'); | |
21328 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'en dag', '22 hours = a day'); | |
21329 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'en dag', '35 hours = a day'); | |
21330 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dager', '36 hours = 2 days'); | |
21331 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'en dag', '1 day = a day'); | |
21332 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dager', '5 days = 5 days'); | |
21333 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dager', '25 days = 25 days'); | |
21334 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'en måned', '26 days = a month'); | |
21335 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'en måned', '30 days = a month'); | |
21336 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'en måned', '43 days = a month'); | |
21337 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 måneder', '46 days = 2 months'); | |
21338 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 måneder', '75 days = 2 months'); | |
21339 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 måneder', '76 days = 3 months'); | |
21340 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'en måned', '1 month = a month'); | |
21341 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 måneder', '5 months = 5 months'); | |
21342 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ett år', '345 days = a year'); | |
21343 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 år', '548 days = 2 years'); | |
21344 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ett år', '1 year = a year'); | |
21345 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 år', '5 years = 5 years'); | |
21346 }); | |
21347 | |
21348 test('suffix', function (assert) { | |
21349 assert.equal(moment(30000).from(0), 'om noen sekunder', 'prefix'); | |
21350 assert.equal(moment(0).from(30000), 'for noen sekunder siden', 'suffix'); | |
21351 }); | |
21352 | |
21353 test('now from now', function (assert) { | |
21354 assert.equal(moment().fromNow(), 'for noen sekunder siden', 'now from now should display as in the past'); | |
21355 }); | |
21356 | |
21357 test('fromNow', function (assert) { | |
21358 assert.equal(moment().add({s: 30}).fromNow(), 'om noen sekunder', 'in a few seconds'); | |
21359 assert.equal(moment().add({d: 5}).fromNow(), 'om 5 dager', 'in 5 days'); | |
21360 }); | |
21361 | |
21362 test('calendar day', function (assert) { | |
21363 var a = moment().hours(2).minutes(0).seconds(0); | |
21364 | |
21365 assert.equal(moment(a).calendar(), 'i dag kl. 2.00', 'today at the same time'); | |
21366 assert.equal(moment(a).add({m: 25}).calendar(), 'i dag kl. 2.25', 'Now plus 25 min'); | |
21367 assert.equal(moment(a).add({h: 1}).calendar(), 'i dag kl. 3.00', 'Now plus 1 hour'); | |
21368 assert.equal(moment(a).add({d: 1}).calendar(), 'i morgen kl. 2.00', 'tomorrow at the same time'); | |
21369 assert.equal(moment(a).subtract({h: 1}).calendar(), 'i dag kl. 1.00', 'Now minus 1 hour'); | |
21370 assert.equal(moment(a).subtract({d: 1}).calendar(), 'i går kl. 2.00', 'yesterday at the same time'); | |
21371 }); | |
21372 | |
21373 test('calendar next week', function (assert) { | |
21374 var i, m; | |
21375 for (i = 2; i < 7; i++) { | |
21376 m = moment().add({d: i}); | |
21377 assert.equal(m.calendar(), m.format('dddd [kl.] LT'), 'Today + ' + i + ' days current time'); | |
21378 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
21379 assert.equal(m.calendar(), m.format('dddd [kl.] LT'), 'Today + ' + i + ' days beginning of day'); | |
21380 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
21381 assert.equal(m.calendar(), m.format('dddd [kl.] LT'), 'Today + ' + i + ' days end of day'); | |
21382 } | |
21383 }); | |
21384 | |
21385 test('calendar last week', function (assert) { | |
21386 var i, m; | |
21387 for (i = 2; i < 7; i++) { | |
21388 m = moment().subtract({d: i}); | |
21389 assert.equal(m.calendar(), m.format('[forrige] dddd [kl.] LT'), 'Today - ' + i + ' days current time'); | |
21390 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
21391 assert.equal(m.calendar(), m.format('[forrige] dddd [kl.] LT'), 'Today - ' + i + ' days beginning of day'); | |
21392 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
21393 assert.equal(m.calendar(), m.format('[forrige] dddd [kl.] LT'), 'Today - ' + i + ' days end of day'); | |
21394 } | |
21395 }); | |
21396 | |
21397 test('calendar all else', function (assert) { | |
21398 var weeksAgo = moment().subtract({w: 1}), | |
21399 weeksFromNow = moment().add({w: 1}); | |
21400 | |
21401 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
21402 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
21403 | |
21404 weeksAgo = moment().subtract({w: 2}); | |
21405 weeksFromNow = moment().add({w: 2}); | |
21406 | |
21407 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
21408 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
21409 }); | |
21410 | |
21411 test('weeks year starting sunday', function (assert) { | |
21412 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
21413 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
21414 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
21415 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
21416 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
21417 }); | |
21418 | |
21419 test('weeks year starting monday', function (assert) { | |
21420 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
21421 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
21422 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
21423 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
21424 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
21425 }); | |
21426 | |
21427 test('weeks year starting tuesday', function (assert) { | |
21428 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
21429 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
21430 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
21431 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
21432 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
21433 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
21434 }); | |
21435 | |
21436 test('weeks year starting wednesday', function (assert) { | |
21437 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
21438 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
21439 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
21440 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
21441 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
21442 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
21443 }); | |
21444 | |
21445 test('weeks year starting thursday', function (assert) { | |
21446 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
21447 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
21448 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
21449 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
21450 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
21451 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
21452 }); | |
21453 | |
21454 test('weeks year starting friday', function (assert) { | |
21455 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
21456 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
21457 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
21458 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
21459 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
21460 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
21461 }); | |
21462 | |
21463 test('weeks year starting saturday', function (assert) { | |
21464 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
21465 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
21466 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
21467 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
21468 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
21469 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
21470 }); | |
21471 | |
21472 test('weeks year starting sunday formatted', function (assert) { | |
21473 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52'); | |
21474 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1'); | |
21475 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1'); | |
21476 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2'); | |
21477 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2'); | |
21478 }); | |
21479 | |
21480 test('lenient ordinal parsing', function (assert) { | |
21481 var i, ordinalStr, testMoment; | |
21482 for (i = 1; i <= 31; ++i) { | |
21483 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
21484 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
21485 assert.equal(testMoment.year(), 2014, | |
21486 'lenient ordinal parsing ' + i + ' year check'); | |
21487 assert.equal(testMoment.month(), 0, | |
21488 'lenient ordinal parsing ' + i + ' month check'); | |
21489 assert.equal(testMoment.date(), i, | |
21490 'lenient ordinal parsing ' + i + ' date check'); | |
21491 } | |
21492 }); | |
21493 | |
21494 test('lenient ordinal parsing of number', function (assert) { | |
21495 var i, testMoment; | |
21496 for (i = 1; i <= 31; ++i) { | |
21497 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
21498 assert.equal(testMoment.year(), 2014, | |
21499 'lenient ordinal parsing of number ' + i + ' year check'); | |
21500 assert.equal(testMoment.month(), 0, | |
21501 'lenient ordinal parsing of number ' + i + ' month check'); | |
21502 assert.equal(testMoment.date(), i, | |
21503 'lenient ordinal parsing of number ' + i + ' date check'); | |
21504 } | |
21505 }); | |
21506 | |
21507 test('strict ordinal parsing', function (assert) { | |
21508 var i, ordinalStr, testMoment; | |
21509 for (i = 1; i <= 31; ++i) { | |
21510 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
21511 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
21512 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
21513 } | |
21514 }); | |
21515 | |
21516 })); | |
21517 | |
21518 (function (global, factory) { | |
21519 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
21520 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
21521 factory(global.moment) | |
21522 }(this, function (moment) { 'use strict'; | |
21523 | |
21524 /*global QUnit:false*/ | |
21525 | |
21526 var test = QUnit.test; | |
21527 | |
21528 function module (name, lifecycle) { | |
21529 QUnit.module(name, { | |
21530 setup : function () { | |
21531 moment.locale('en'); | |
21532 moment.createFromInputFallback = function () { | |
21533 throw new Error('input not handled by moment'); | |
21534 }; | |
21535 if (lifecycle && lifecycle.setup) { | |
21536 lifecycle.setup(); | |
21537 } | |
21538 }, | |
21539 teardown : function () { | |
21540 if (lifecycle && lifecycle.teardown) { | |
21541 lifecycle.teardown(); | |
21542 } | |
21543 } | |
21544 }); | |
21545 } | |
21546 | |
21547 function localeModule (name, lifecycle) { | |
21548 QUnit.module('locale:' + name, { | |
21549 setup : function () { | |
21550 moment.locale(name); | |
21551 moment.createFromInputFallback = function () { | |
21552 throw new Error('input not handled by moment'); | |
21553 }; | |
21554 if (lifecycle && lifecycle.setup) { | |
21555 lifecycle.setup(); | |
21556 } | |
21557 }, | |
21558 teardown : function () { | |
21559 moment.locale('en'); | |
21560 if (lifecycle && lifecycle.teardown) { | |
21561 lifecycle.teardown(); | |
21562 } | |
21563 } | |
21564 }); | |
21565 } | |
21566 | |
21567 localeModule('ne'); | |
21568 | |
21569 test('parse', function (assert) { | |
21570 var tests = 'जनवरी जन._फेब्रुवरी फेब्रु._मार्च मार्च_अप्रिल अप्रि._मई मई_जुन जुन_जुलाई जुलाई._अगष्ट अग._सेप्टेम्बर सेप्ट._अक्टोबर अक्टो._नोभेम्बर नोभे._डिसेम्बर डिसे.'.split('_'), i; | |
21571 function equalTest(input, mmm, i) { | |
21572 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
21573 } | |
21574 for (i = 0; i < 12; i++) { | |
21575 tests[i] = tests[i].split(' '); | |
21576 equalTest(tests[i][0], 'MMM', i); | |
21577 equalTest(tests[i][1], 'MMM', i); | |
21578 equalTest(tests[i][0], 'MMMM', i); | |
21579 equalTest(tests[i][1], 'MMMM', i); | |
21580 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
21581 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
21582 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
21583 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
21584 } | |
21585 }); | |
21586 | |
21587 test('format', function (assert) { | |
21588 var a = [ | |
21589 ['dddd, Do MMMM YYYY, aको h:mm:ss बजे', 'आइतबार, १४ फेब्रुवरी २०१०, बेलुकाको ३:२५:५० बजे'], | |
21590 ['ddd, aको h बजे', 'आइत., बेलुकाको ३ बजे'], | |
21591 ['M Mo MM MMMM MMM', '२ २ ०२ फेब्रुवरी फेब्रु.'], | |
21592 ['YYYY YY', '२०१० १०'], | |
21593 ['D Do DD', '१४ १४ १४'], | |
21594 ['d do dddd ddd dd', '० ० आइतबार आइत. आइ.'], | |
21595 ['DDD DDDo DDDD', '४५ ४५ ०४५'], | |
21596 ['w wo ww', '७ ७ ०७'], | |
21597 ['h hh', '३ ०३'], | |
21598 ['H HH', '१५ १५'], | |
21599 ['m mm', '२५ २५'], | |
21600 ['s ss', '५० ५०'], | |
21601 ['a A', 'बेलुका बेलुका'], | |
21602 ['LTS', 'बेलुकाको ३:२५:५० बजे'], | |
21603 ['L', '१४/०२/२०१०'], | |
21604 ['LL', '१४ फेब्रुवरी २०१०'], | |
21605 ['LLL', '१४ फेब्रुवरी २०१०, बेलुकाको ३:२५ बजे'], | |
21606 ['LLLL', 'आइतबार, १४ फेब्रुवरी २०१०, बेलुकाको ३:२५ बजे'], | |
21607 ['l', '१४/२/२०१०'], | |
21608 ['ll', '१४ फेब्रु. २०१०'], | |
21609 ['lll', '१४ फेब्रु. २०१०, बेलुकाको ३:२५ बजे'], | |
21610 ['llll', 'आइत., १४ फेब्रु. २०१०, बेलुकाको ३:२५ बजे'] | |
21611 ], | |
21612 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
21613 i; | |
21614 for (i = 0; i < a.length; i++) { | |
21615 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
21616 } | |
21617 }); | |
21618 | |
21619 test('format ordinal', function (assert) { | |
21620 assert.equal(moment([2011, 0, 1]).format('DDDo'), '१', '१'); | |
21621 assert.equal(moment([2011, 0, 2]).format('DDDo'), '२', '२'); | |
21622 assert.equal(moment([2011, 0, 3]).format('DDDo'), '३', '३'); | |
21623 assert.equal(moment([2011, 0, 4]).format('DDDo'), '४', '४'); | |
21624 assert.equal(moment([2011, 0, 5]).format('DDDo'), '५', '५'); | |
21625 assert.equal(moment([2011, 0, 6]).format('DDDo'), '६', '६'); | |
21626 assert.equal(moment([2011, 0, 7]).format('DDDo'), '७', '७'); | |
21627 assert.equal(moment([2011, 0, 8]).format('DDDo'), '८', '८'); | |
21628 assert.equal(moment([2011, 0, 9]).format('DDDo'), '९', '९'); | |
21629 assert.equal(moment([2011, 0, 10]).format('DDDo'), '१०', '१०'); | |
21630 | |
21631 assert.equal(moment([2011, 0, 11]).format('DDDo'), '११', '११'); | |
21632 assert.equal(moment([2011, 0, 12]).format('DDDo'), '१२', '१२'); | |
21633 assert.equal(moment([2011, 0, 13]).format('DDDo'), '१३', '१३'); | |
21634 assert.equal(moment([2011, 0, 14]).format('DDDo'), '१४', '१४'); | |
21635 assert.equal(moment([2011, 0, 15]).format('DDDo'), '१५', '१५'); | |
21636 assert.equal(moment([2011, 0, 16]).format('DDDo'), '१६', '१६'); | |
21637 assert.equal(moment([2011, 0, 17]).format('DDDo'), '१७', '१७'); | |
21638 assert.equal(moment([2011, 0, 18]).format('DDDo'), '१८', '१८'); | |
21639 assert.equal(moment([2011, 0, 19]).format('DDDo'), '१९', '१९'); | |
21640 assert.equal(moment([2011, 0, 20]).format('DDDo'), '२०', '२०'); | |
21641 | |
21642 assert.equal(moment([2011, 0, 21]).format('DDDo'), '२१', '२१'); | |
21643 assert.equal(moment([2011, 0, 22]).format('DDDo'), '२२', '२२'); | |
21644 assert.equal(moment([2011, 0, 23]).format('DDDo'), '२३', '२३'); | |
21645 assert.equal(moment([2011, 0, 24]).format('DDDo'), '२४', '२४'); | |
21646 assert.equal(moment([2011, 0, 25]).format('DDDo'), '२५', '२५'); | |
21647 assert.equal(moment([2011, 0, 26]).format('DDDo'), '२६', '२६'); | |
21648 assert.equal(moment([2011, 0, 27]).format('DDDo'), '२७', '२७'); | |
21649 assert.equal(moment([2011, 0, 28]).format('DDDo'), '२८', '२८'); | |
21650 assert.equal(moment([2011, 0, 29]).format('DDDo'), '२९', '२९'); | |
21651 assert.equal(moment([2011, 0, 30]).format('DDDo'), '३०', '३०'); | |
21652 | |
21653 assert.equal(moment([2011, 0, 31]).format('DDDo'), '३१', '३१'); | |
21654 }); | |
21655 | |
21656 test('format month', function (assert) { | |
21657 var expected = 'जनवरी जन._फेब्रुवरी फेब्रु._मार्च मार्च_अप्रिल अप्रि._मई मई_जुन जुन_जुलाई जुलाई._अगष्ट अग._सेप्टेम्बर सेप्ट._अक्टोबर अक्टो._नोभेम्बर नोभे._डिसेम्बर डिसे.'.split('_'), i; | |
21658 for (i = 0; i < expected.length; i++) { | |
21659 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
21660 } | |
21661 }); | |
21662 | |
21663 test('format week', function (assert) { | |
21664 var expected = 'आइतबार आइत. आइ._सोमबार सोम. सो._मङ्गलबार मङ्गल. मङ्_बुधबार बुध. बु._बिहिबार बिहि. बि._शुक्रबार शुक्र. शु._शनिबार शनि. श.'.split('_'), i; | |
21665 for (i = 0; i < expected.length; i++) { | |
21666 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
21667 } | |
21668 }); | |
21669 | |
21670 test('from', function (assert) { | |
21671 var start = moment([2007, 1, 28]); | |
21672 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'केही समय', '44 seconds = a few seconds'); | |
21673 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'एक मिनेट', '45 seconds = a minute'); | |
21674 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'एक मिनेट', '89 seconds = a minute'); | |
21675 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '२ मिनेट', '90 seconds = 2 minutes'); | |
21676 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '४४ मिनेट', '44 minutes = 44 minutes'); | |
21677 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'एक घण्टा', '45 minutes = an hour'); | |
21678 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'एक घण्टा', '89 minutes = an hour'); | |
21679 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '२ घण्टा', '90 minutes = 2 hours'); | |
21680 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '५ घण्टा', '5 hours = 5 hours'); | |
21681 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '२१ घण्टा', '21 hours = 21 hours'); | |
21682 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'एक दिन', '22 hours = a day'); | |
21683 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'एक दिन', '35 hours = a day'); | |
21684 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '२ दिन', '36 hours = 2 days'); | |
21685 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'एक दिन', '1 day = a day'); | |
21686 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '५ दिन', '5 days = 5 days'); | |
21687 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '२५ दिन', '25 days = 25 days'); | |
21688 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'एक महिना', '26 days = a month'); | |
21689 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'एक महिना', '30 days = a month'); | |
21690 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'एक महिना', '43 days = a month'); | |
21691 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '२ महिना', '46 days = 2 months'); | |
21692 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '२ महिना', '75 days = 2 months'); | |
21693 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '३ महिना', '76 days = 3 months'); | |
21694 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'एक महिना', '1 month = a month'); | |
21695 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '५ महिना', '5 months = 5 months'); | |
21696 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'एक बर्ष', '345 days = a year'); | |
21697 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '२ बर्ष', '548 days = 2 years'); | |
21698 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'एक बर्ष', '1 year = a year'); | |
21699 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '५ बर्ष', '5 years = 5 years'); | |
21700 }); | |
21701 | |
21702 test('suffix', function (assert) { | |
21703 assert.equal(moment(30000).from(0), 'केही समयमा', 'prefix'); | |
21704 assert.equal(moment(0).from(30000), 'केही समय अगाडी', 'suffix'); | |
21705 }); | |
21706 | |
21707 test('now from now', function (assert) { | |
21708 assert.equal(moment().fromNow(), 'केही समय अगाडी', 'now from now should display as in the past'); | |
21709 }); | |
21710 | |
21711 test('fromNow', function (assert) { | |
21712 assert.equal(moment().add({s: 30}).fromNow(), 'केही समयमा', 'केही समयमा'); | |
21713 assert.equal(moment().add({d: 5}).fromNow(), '५ दिनमा', '५ दिनमा'); | |
21714 }); | |
21715 | |
21716 test('calendar day', function (assert) { | |
21717 var a = moment().hours(2).minutes(0).seconds(0); | |
21718 | |
21719 assert.equal(moment(a).calendar(), 'आज रातीको २:०० बजे', 'today at the same time'); | |
21720 assert.equal(moment(a).add({m: 25}).calendar(), 'आज रातीको २:२५ बजे', 'Now plus 25 min'); | |
21721 assert.equal(moment(a).add({h: 1}).calendar(), 'आज बिहानको ३:०० बजे', 'Now plus 1 hour'); | |
21722 assert.equal(moment(a).add({d: 1}).calendar(), 'भोली रातीको २:०० बजे', 'tomorrow at the same time'); | |
21723 assert.equal(moment(a).subtract({h: 1}).calendar(), 'आज रातीको १:०० बजे', 'Now minus 1 hour'); | |
21724 assert.equal(moment(a).subtract({d: 1}).calendar(), 'हिजो रातीको २:०० बजे', 'yesterday at the same time'); | |
21725 }); | |
21726 | |
21727 test('calendar next week', function (assert) { | |
21728 var i, m; | |
21729 for (i = 2; i < 7; i++) { | |
21730 m = moment().add({d: i}); | |
21731 assert.equal(m.calendar(), m.format('[आउँदो] dddd[,] LT'), 'Today + ' + i + ' days current time'); | |
21732 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
21733 assert.equal(m.calendar(), m.format('[आउँदो] dddd[,] LT'), 'Today + ' + i + ' days beginning of day'); | |
21734 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
21735 assert.equal(m.calendar(), m.format('[आउँदो] dddd[,] LT'), 'Today + ' + i + ' days end of day'); | |
21736 } | |
21737 }); | |
21738 | |
21739 test('calendar last week', function (assert) { | |
21740 var i, m; | |
21741 for (i = 2; i < 7; i++) { | |
21742 m = moment().subtract({d: i}); | |
21743 assert.equal(m.calendar(), m.format('[गएको] dddd[,] LT'), 'Today - ' + i + ' days current time'); | |
21744 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
21745 assert.equal(m.calendar(), m.format('[गएको] dddd[,] LT'), 'Today - ' + i + ' days beginning of day'); | |
21746 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
21747 assert.equal(m.calendar(), m.format('[गएको] dddd[,] LT'), 'Today - ' + i + ' days end of day'); | |
21748 } | |
21749 }); | |
21750 | |
21751 test('calendar all else', function (assert) { | |
21752 var weeksAgo = moment().subtract({w: 1}), | |
21753 weeksFromNow = moment().add({w: 1}); | |
21754 | |
21755 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
21756 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
21757 | |
21758 weeksAgo = moment().subtract({w: 2}); | |
21759 weeksFromNow = moment().add({w: 2}); | |
21760 | |
21761 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
21762 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
21763 }); | |
21764 | |
21765 test('meridiem', function (assert) { | |
21766 assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), 'राती', 'before dawn'); | |
21767 assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), 'बिहान', 'morning'); | |
21768 assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), 'दिउँसो', 'during day'); | |
21769 assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), 'बेलुका', 'evening'); | |
21770 assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), 'साँझ', 'late evening'); | |
21771 assert.equal(moment([2011, 2, 23, 21, 20]).format('a'), 'राती', 'night'); | |
21772 | |
21773 assert.equal(moment([2011, 2, 23, 2, 30]).format('A'), 'राती', 'before dawn'); | |
21774 assert.equal(moment([2011, 2, 23, 9, 30]).format('A'), 'बिहान', 'morning'); | |
21775 assert.equal(moment([2011, 2, 23, 14, 30]).format('A'), 'दिउँसो', 'during day'); | |
21776 assert.equal(moment([2011, 2, 23, 17, 30]).format('A'), 'बेलुका', 'evening'); | |
21777 assert.equal(moment([2011, 2, 23, 19, 30]).format('A'), 'साँझ', 'late evening'); | |
21778 assert.equal(moment([2011, 2, 23, 21, 20]).format('A'), 'राती', 'night'); | |
21779 }); | |
21780 | |
21781 test('weeks year starting sunday', function (assert) { | |
21782 assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1'); | |
21783 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
21784 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2'); | |
21785 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
21786 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3'); | |
21787 }); | |
21788 | |
21789 test('weeks year starting monday', function (assert) { | |
21790 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
21791 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
21792 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
21793 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
21794 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
21795 }); | |
21796 | |
21797 test('weeks year starting tuesday', function (assert) { | |
21798 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
21799 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
21800 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
21801 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
21802 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
21803 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
21804 }); | |
21805 | |
21806 test('weeks year starting wednesday', function (assert) { | |
21807 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
21808 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
21809 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
21810 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
21811 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
21812 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
21813 }); | |
21814 | |
21815 test('weeks year starting thursday', function (assert) { | |
21816 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
21817 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
21818 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
21819 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
21820 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
21821 assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3'); | |
21822 }); | |
21823 | |
21824 test('weeks year starting friday', function (assert) { | |
21825 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1'); | |
21826 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
21827 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1'); | |
21828 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2'); | |
21829 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2'); | |
21830 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3'); | |
21831 }); | |
21832 | |
21833 test('weeks year starting saturday', function (assert) { | |
21834 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1'); | |
21835 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
21836 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1'); | |
21837 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2'); | |
21838 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2'); | |
21839 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3'); | |
21840 }); | |
21841 | |
21842 test('weeks year starting sunday formatted', function (assert) { | |
21843 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '१ ०१ १', 'Dec 26 2011 should be week 1'); | |
21844 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '१ ०१ १', 'Jan 1 2012 should be week 1'); | |
21845 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '२ ०२ २', 'Jan 2 2012 should be week 2'); | |
21846 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '२ ०२ २', 'Jan 8 2012 should be week 2'); | |
21847 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '३ ०३ ३', 'Jan 9 2012 should be week 3'); | |
21848 }); | |
21849 | |
21850 test('lenient ordinal parsing', function (assert) { | |
21851 var i, ordinalStr, testMoment; | |
21852 for (i = 1; i <= 31; ++i) { | |
21853 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
21854 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
21855 assert.equal(testMoment.year(), 2014, | |
21856 'lenient ordinal parsing ' + i + ' year check'); | |
21857 assert.equal(testMoment.month(), 0, | |
21858 'lenient ordinal parsing ' + i + ' month check'); | |
21859 assert.equal(testMoment.date(), i, | |
21860 'lenient ordinal parsing ' + i + ' date check'); | |
21861 } | |
21862 }); | |
21863 | |
21864 test('lenient ordinal parsing of number', function (assert) { | |
21865 var i, testMoment; | |
21866 for (i = 1; i <= 31; ++i) { | |
21867 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
21868 assert.equal(testMoment.year(), 2014, | |
21869 'lenient ordinal parsing of number ' + i + ' year check'); | |
21870 assert.equal(testMoment.month(), 0, | |
21871 'lenient ordinal parsing of number ' + i + ' month check'); | |
21872 assert.equal(testMoment.date(), i, | |
21873 'lenient ordinal parsing of number ' + i + ' date check'); | |
21874 } | |
21875 }); | |
21876 | |
21877 test('meridiem invariant', function (assert) { | |
21878 var h, m, t1, t2; | |
21879 for (h = 0; h < 24; ++h) { | |
21880 for (m = 0; m < 60; m += 15) { | |
21881 t1 = moment.utc([2000, 0, 1, h, m]); | |
21882 t2 = moment(t1.format('A h:mm'), 'A h:mm'); | |
21883 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'), | |
21884 'meridiem at ' + t1.format('HH:mm')); | |
21885 } | |
21886 } | |
21887 }); | |
21888 | |
21889 test('strict ordinal parsing', function (assert) { | |
21890 var i, ordinalStr, testMoment; | |
21891 for (i = 1; i <= 31; ++i) { | |
21892 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
21893 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
21894 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
21895 } | |
21896 }); | |
21897 | |
21898 })); | |
21899 | |
21900 (function (global, factory) { | |
21901 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
21902 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
21903 factory(global.moment) | |
21904 }(this, function (moment) { 'use strict'; | |
21905 | |
21906 /*global QUnit:false*/ | |
21907 | |
21908 var test = QUnit.test; | |
21909 | |
21910 function module (name, lifecycle) { | |
21911 QUnit.module(name, { | |
21912 setup : function () { | |
21913 moment.locale('en'); | |
21914 moment.createFromInputFallback = function () { | |
21915 throw new Error('input not handled by moment'); | |
21916 }; | |
21917 if (lifecycle && lifecycle.setup) { | |
21918 lifecycle.setup(); | |
21919 } | |
21920 }, | |
21921 teardown : function () { | |
21922 if (lifecycle && lifecycle.teardown) { | |
21923 lifecycle.teardown(); | |
21924 } | |
21925 } | |
21926 }); | |
21927 } | |
21928 | |
21929 function localeModule (name, lifecycle) { | |
21930 QUnit.module('locale:' + name, { | |
21931 setup : function () { | |
21932 moment.locale(name); | |
21933 moment.createFromInputFallback = function () { | |
21934 throw new Error('input not handled by moment'); | |
21935 }; | |
21936 if (lifecycle && lifecycle.setup) { | |
21937 lifecycle.setup(); | |
21938 } | |
21939 }, | |
21940 teardown : function () { | |
21941 moment.locale('en'); | |
21942 if (lifecycle && lifecycle.teardown) { | |
21943 lifecycle.teardown(); | |
21944 } | |
21945 } | |
21946 }); | |
21947 } | |
21948 | |
21949 localeModule('nl'); | |
21950 | |
21951 test('parse', function (assert) { | |
21952 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; | |
21953 function equalTest(input, mmm, i) { | |
21954 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
21955 } | |
21956 for (i = 0; i < 12; i++) { | |
21957 tests[i] = tests[i].split(' '); | |
21958 equalTest(tests[i][0], 'MMM', i); | |
21959 equalTest(tests[i][1], 'MMM', i); | |
21960 equalTest(tests[i][0], 'MMMM', i); | |
21961 equalTest(tests[i][1], 'MMMM', i); | |
21962 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
21963 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
21964 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
21965 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
21966 } | |
21967 }); | |
21968 | |
21969 test('format', function (assert) { | |
21970 var a = [ | |
21971 ['dddd, MMMM Do YYYY, HH:mm:ss', 'zondag, februari 14de 2010, 15:25:50'], | |
21972 ['ddd, HH', 'zo., 15'], | |
21973 ['M Mo MM MMMM MMM', '2 2de 02 februari feb.'], | |
21974 ['YYYY YY', '2010 10'], | |
21975 ['D Do DD', '14 14de 14'], | |
21976 ['d do dddd ddd dd', '0 0de zondag zo. Zo'], | |
21977 ['DDD DDDo DDDD', '45 45ste 045'], | |
21978 ['w wo ww', '6 6de 06'], | |
21979 ['h hh', '3 03'], | |
21980 ['H HH', '15 15'], | |
21981 ['m mm', '25 25'], | |
21982 ['s ss', '50 50'], | |
21983 ['a A', 'pm PM'], | |
21984 ['[the] DDDo [day of the year]', 'the 45ste day of the year'], | |
21985 ['LTS', '15:25:50'], | |
21986 ['L', '14-02-2010'], | |
21987 ['LL', '14 februari 2010'], | |
21988 ['LLL', '14 februari 2010 15:25'], | |
21989 ['LLLL', 'zondag 14 februari 2010 15:25'], | |
21990 ['l', '14-2-2010'], | |
21991 ['ll', '14 feb. 2010'], | |
21992 ['lll', '14 feb. 2010 15:25'], | |
21993 ['llll', 'zo. 14 feb. 2010 15:25'] | |
21994 ], | |
21995 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
21996 i; | |
21997 for (i = 0; i < a.length; i++) { | |
21998 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
21999 } | |
22000 }); | |
22001 | |
22002 test('format ordinal', function (assert) { | |
22003 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1ste', '1ste'); | |
22004 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2de', '2de'); | |
22005 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3de', '3de'); | |
22006 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4de', '4de'); | |
22007 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5de', '5de'); | |
22008 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6de', '6de'); | |
22009 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7de', '7de'); | |
22010 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8ste', '8ste'); | |
22011 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9de', '9de'); | |
22012 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10de', '10de'); | |
22013 | |
22014 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11de', '11de'); | |
22015 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12de', '12de'); | |
22016 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13de', '13de'); | |
22017 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14de', '14de'); | |
22018 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15de', '15de'); | |
22019 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16de', '16de'); | |
22020 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17de', '17de'); | |
22021 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18de', '18de'); | |
22022 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19de', '19de'); | |
22023 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20ste', '20ste'); | |
22024 | |
22025 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21ste', '21ste'); | |
22026 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22ste', '22ste'); | |
22027 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23ste', '23ste'); | |
22028 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24ste', '24ste'); | |
22029 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25ste', '25ste'); | |
22030 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26ste', '26ste'); | |
22031 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27ste', '27ste'); | |
22032 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28ste', '28ste'); | |
22033 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29ste', '29ste'); | |
22034 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30ste', '30ste'); | |
22035 | |
22036 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31ste', '31ste'); | |
22037 }); | |
22038 | |
22039 test('format month', function (assert) { | |
22040 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; | |
22041 for (i = 0; i < expected.length; i++) { | |
22042 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
22043 } | |
22044 }); | |
22045 | |
22046 test('format week', function (assert) { | |
22047 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; | |
22048 for (i = 0; i < expected.length; i++) { | |
22049 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
22050 } | |
22051 }); | |
22052 | |
22053 test('from', function (assert) { | |
22054 var start = moment([2007, 1, 28]); | |
22055 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'een paar seconden', '44 seconds = a few seconds'); | |
22056 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'één minuut', '45 seconds = a minute'); | |
22057 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'één minuut', '89 seconds = a minute'); | |
22058 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuten', '90 seconds = 2 minutes'); | |
22059 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuten', '44 minutes = 44 minutes'); | |
22060 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'één uur', '45 minutes = an hour'); | |
22061 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'één uur', '89 minutes = an hour'); | |
22062 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 uur', '90 minutes = 2 hours'); | |
22063 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 uur', '5 hours = 5 hours'); | |
22064 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 uur', '21 hours = 21 hours'); | |
22065 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'één dag', '22 hours = a day'); | |
22066 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'één dag', '35 hours = a day'); | |
22067 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dagen', '36 hours = 2 days'); | |
22068 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'één dag', '1 day = a day'); | |
22069 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dagen', '5 days = 5 days'); | |
22070 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dagen', '25 days = 25 days'); | |
22071 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'één maand', '26 days = a month'); | |
22072 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'één maand', '30 days = a month'); | |
22073 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'één maand', '43 days = a month'); | |
22074 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 maanden', '46 days = 2 months'); | |
22075 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 maanden', '75 days = 2 months'); | |
22076 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 maanden', '76 days = 3 months'); | |
22077 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'één maand', '1 month = a month'); | |
22078 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 maanden', '5 months = 5 months'); | |
22079 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'één jaar', '345 days = a year'); | |
22080 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 jaar', '548 days = 2 years'); | |
22081 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'één jaar', '1 year = a year'); | |
22082 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 jaar', '5 years = 5 years'); | |
22083 }); | |
22084 | |
22085 test('suffix', function (assert) { | |
22086 assert.equal(moment(30000).from(0), 'over een paar seconden', 'prefix'); | |
22087 assert.equal(moment(0).from(30000), 'een paar seconden geleden', 'suffix'); | |
22088 }); | |
22089 | |
22090 test('now from now', function (assert) { | |
22091 assert.equal(moment().fromNow(), 'een paar seconden geleden', 'now from now should display as in the past'); | |
22092 }); | |
22093 | |
22094 test('fromNow', function (assert) { | |
22095 assert.equal(moment().add({s: 30}).fromNow(), 'over een paar seconden', 'in a few seconds'); | |
22096 assert.equal(moment().add({d: 5}).fromNow(), 'over 5 dagen', 'in 5 days'); | |
22097 }); | |
22098 | |
22099 test('calendar day', function (assert) { | |
22100 var a = moment().hours(2).minutes(0).seconds(0); | |
22101 | |
22102 assert.equal(moment(a).calendar(), 'vandaag om 02:00', 'today at the same time'); | |
22103 assert.equal(moment(a).add({m: 25}).calendar(), 'vandaag om 02:25', 'Now plus 25 min'); | |
22104 assert.equal(moment(a).add({h: 1}).calendar(), 'vandaag om 03:00', 'Now plus 1 hour'); | |
22105 assert.equal(moment(a).add({d: 1}).calendar(), 'morgen om 02:00', 'tomorrow at the same time'); | |
22106 assert.equal(moment(a).subtract({h: 1}).calendar(), 'vandaag om 01:00', 'Now minus 1 hour'); | |
22107 assert.equal(moment(a).subtract({d: 1}).calendar(), 'gisteren om 02:00', 'yesterday at the same time'); | |
22108 }); | |
22109 | |
22110 test('calendar next week', function (assert) { | |
22111 var i, m; | |
22112 for (i = 2; i < 7; i++) { | |
22113 m = moment().add({d: i}); | |
22114 assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days current time'); | |
22115 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
22116 assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days beginning of day'); | |
22117 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
22118 assert.equal(m.calendar(), m.format('dddd [om] LT'), 'Today + ' + i + ' days end of day'); | |
22119 } | |
22120 }); | |
22121 | |
22122 test('calendar last week', function (assert) { | |
22123 var i, m; | |
22124 for (i = 2; i < 7; i++) { | |
22125 m = moment().subtract({d: i}); | |
22126 assert.equal(m.calendar(), m.format('[afgelopen] dddd [om] LT'), 'Today - ' + i + ' days current time'); | |
22127 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
22128 assert.equal(m.calendar(), m.format('[afgelopen] dddd [om] LT'), 'Today - ' + i + ' days beginning of day'); | |
22129 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
22130 assert.equal(m.calendar(), m.format('[afgelopen] dddd [om] LT'), 'Today - ' + i + ' days end of day'); | |
22131 } | |
22132 }); | |
22133 | |
22134 test('calendar all else', function (assert) { | |
22135 var weeksAgo = moment().subtract({w: 1}), | |
22136 weeksFromNow = moment().add({w: 1}); | |
22137 | |
22138 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
22139 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
22140 | |
22141 weeksAgo = moment().subtract({w: 2}); | |
22142 weeksFromNow = moment().add({w: 2}); | |
22143 | |
22144 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
22145 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
22146 }); | |
22147 | |
22148 test('month abbreviation', function (assert) { | |
22149 assert.equal(moment([2012, 5, 23]).format('D-MMM-YYYY'), '23-jun-2012', 'format month abbreviation surrounded by dashes should not include a dot'); | |
22150 assert.equal(moment([2012, 5, 23]).format('D MMM YYYY'), '23 jun. 2012', 'format month abbreviation not surrounded by dashes should include a dot'); | |
22151 }); | |
22152 | |
22153 test('weeks year starting sunday', function (assert) { | |
22154 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
22155 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
22156 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
22157 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
22158 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
22159 }); | |
22160 | |
22161 test('weeks year starting monday', function (assert) { | |
22162 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
22163 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
22164 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
22165 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
22166 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
22167 }); | |
22168 | |
22169 test('weeks year starting tuesday', function (assert) { | |
22170 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
22171 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
22172 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
22173 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
22174 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
22175 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
22176 }); | |
22177 | |
22178 test('weeks year starting wednesday', function (assert) { | |
22179 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
22180 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
22181 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
22182 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
22183 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
22184 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
22185 }); | |
22186 | |
22187 test('weeks year starting thursday', function (assert) { | |
22188 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
22189 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
22190 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
22191 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
22192 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
22193 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
22194 }); | |
22195 | |
22196 test('weeks year starting friday', function (assert) { | |
22197 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
22198 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
22199 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
22200 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
22201 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
22202 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
22203 }); | |
22204 | |
22205 test('weeks year starting saturday', function (assert) { | |
22206 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
22207 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
22208 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
22209 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
22210 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
22211 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
22212 }); | |
22213 | |
22214 test('weeks year starting sunday formatted', function (assert) { | |
22215 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52ste', 'Jan 1 2012 should be week 52'); | |
22216 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1ste', 'Jan 2 2012 should be week 1'); | |
22217 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1ste', 'Jan 8 2012 should be week 1'); | |
22218 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2de', 'Jan 9 2012 should be week 2'); | |
22219 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2de', 'Jan 15 2012 should be week 2'); | |
22220 }); | |
22221 | |
22222 test('lenient ordinal parsing', function (assert) { | |
22223 var i, ordinalStr, testMoment; | |
22224 for (i = 1; i <= 31; ++i) { | |
22225 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
22226 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
22227 assert.equal(testMoment.year(), 2014, | |
22228 'lenient ordinal parsing ' + i + ' year check'); | |
22229 assert.equal(testMoment.month(), 0, | |
22230 'lenient ordinal parsing ' + i + ' month check'); | |
22231 assert.equal(testMoment.date(), i, | |
22232 'lenient ordinal parsing ' + i + ' date check'); | |
22233 } | |
22234 }); | |
22235 | |
22236 test('lenient ordinal parsing of number', function (assert) { | |
22237 var i, testMoment; | |
22238 for (i = 1; i <= 31; ++i) { | |
22239 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
22240 assert.equal(testMoment.year(), 2014, | |
22241 'lenient ordinal parsing of number ' + i + ' year check'); | |
22242 assert.equal(testMoment.month(), 0, | |
22243 'lenient ordinal parsing of number ' + i + ' month check'); | |
22244 assert.equal(testMoment.date(), i, | |
22245 'lenient ordinal parsing of number ' + i + ' date check'); | |
22246 } | |
22247 }); | |
22248 | |
22249 test('strict ordinal parsing', function (assert) { | |
22250 var i, ordinalStr, testMoment; | |
22251 for (i = 1; i <= 31; ++i) { | |
22252 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
22253 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
22254 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
22255 } | |
22256 }); | |
22257 | |
22258 })); | |
22259 | |
22260 (function (global, factory) { | |
22261 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
22262 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
22263 factory(global.moment) | |
22264 }(this, function (moment) { 'use strict'; | |
22265 | |
22266 /*global QUnit:false*/ | |
22267 | |
22268 var test = QUnit.test; | |
22269 | |
22270 function module (name, lifecycle) { | |
22271 QUnit.module(name, { | |
22272 setup : function () { | |
22273 moment.locale('en'); | |
22274 moment.createFromInputFallback = function () { | |
22275 throw new Error('input not handled by moment'); | |
22276 }; | |
22277 if (lifecycle && lifecycle.setup) { | |
22278 lifecycle.setup(); | |
22279 } | |
22280 }, | |
22281 teardown : function () { | |
22282 if (lifecycle && lifecycle.teardown) { | |
22283 lifecycle.teardown(); | |
22284 } | |
22285 } | |
22286 }); | |
22287 } | |
22288 | |
22289 function localeModule (name, lifecycle) { | |
22290 QUnit.module('locale:' + name, { | |
22291 setup : function () { | |
22292 moment.locale(name); | |
22293 moment.createFromInputFallback = function () { | |
22294 throw new Error('input not handled by moment'); | |
22295 }; | |
22296 if (lifecycle && lifecycle.setup) { | |
22297 lifecycle.setup(); | |
22298 } | |
22299 }, | |
22300 teardown : function () { | |
22301 moment.locale('en'); | |
22302 if (lifecycle && lifecycle.teardown) { | |
22303 lifecycle.teardown(); | |
22304 } | |
22305 } | |
22306 }); | |
22307 } | |
22308 | |
22309 localeModule('nn'); | |
22310 | |
22311 test('parse', function (assert) { | |
22312 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; | |
22313 function equalTest(input, mmm, i) { | |
22314 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
22315 } | |
22316 for (i = 0; i < 12; i++) { | |
22317 tests[i] = tests[i].split(' '); | |
22318 equalTest(tests[i][0], 'MMM', i); | |
22319 equalTest(tests[i][1], 'MMM', i); | |
22320 equalTest(tests[i][0], 'MMMM', i); | |
22321 equalTest(tests[i][1], 'MMMM', i); | |
22322 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
22323 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
22324 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
22325 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
22326 } | |
22327 }); | |
22328 | |
22329 test('format', function (assert) { | |
22330 var a = [ | |
22331 ['dddd, MMMM Do YYYY, h:mm:ss a', 'sundag, februar 14. 2010, 3:25:50 pm'], | |
22332 ['ddd, hA', 'sun, 3PM'], | |
22333 ['M Mo MM MMMM MMM', '2 2. 02 februar feb'], | |
22334 ['YYYY YY', '2010 10'], | |
22335 ['D Do DD', '14 14. 14'], | |
22336 ['d do dddd ddd dd', '0 0. sundag sun su'], | |
22337 ['DDD DDDo DDDD', '45 45. 045'], | |
22338 ['w wo ww', '6 6. 06'], | |
22339 ['h hh', '3 03'], | |
22340 ['H HH', '15 15'], | |
22341 ['m mm', '25 25'], | |
22342 ['s ss', '50 50'], | |
22343 ['a A', 'pm PM'], | |
22344 ['[the] DDDo [day of the year]', 'the 45. day of the year'], | |
22345 ['LTS', '15:25:50'], | |
22346 ['L', '14.02.2010'], | |
22347 ['LL', '14 februar 2010'], | |
22348 ['LLL', '14 februar 2010 15:25'], | |
22349 ['LLLL', 'sundag 14 februar 2010 15:25'], | |
22350 ['l', '14.2.2010'], | |
22351 ['ll', '14 feb 2010'], | |
22352 ['lll', '14 feb 2010 15:25'], | |
22353 ['llll', 'sun 14 feb 2010 15:25'] | |
22354 ], | |
22355 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
22356 i; | |
22357 for (i = 0; i < a.length; i++) { | |
22358 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
22359 } | |
22360 }); | |
22361 | |
22362 test('format ordinal', function (assert) { | |
22363 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.'); | |
22364 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.'); | |
22365 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.'); | |
22366 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.'); | |
22367 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.'); | |
22368 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.'); | |
22369 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.'); | |
22370 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.'); | |
22371 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.'); | |
22372 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.'); | |
22373 | |
22374 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.'); | |
22375 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.'); | |
22376 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.'); | |
22377 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.'); | |
22378 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.'); | |
22379 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.'); | |
22380 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.'); | |
22381 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.'); | |
22382 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.'); | |
22383 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.'); | |
22384 | |
22385 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.'); | |
22386 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.'); | |
22387 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.'); | |
22388 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.'); | |
22389 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.'); | |
22390 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.'); | |
22391 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.'); | |
22392 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.'); | |
22393 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.'); | |
22394 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.'); | |
22395 | |
22396 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.'); | |
22397 }); | |
22398 | |
22399 test('format month', function (assert) { | |
22400 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; | |
22401 for (i = 0; i < expected.length; i++) { | |
22402 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
22403 } | |
22404 }); | |
22405 | |
22406 test('format week', function (assert) { | |
22407 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; | |
22408 for (i = 0; i < expected.length; i++) { | |
22409 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
22410 } | |
22411 }); | |
22412 | |
22413 test('from', function (assert) { | |
22414 var start = moment([2007, 1, 28]); | |
22415 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'nokre sekund', '44 sekunder = a few seconds'); | |
22416 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'eit minutt', '45 seconds = a minute'); | |
22417 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'eit minutt', '89 seconds = a minute'); | |
22418 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutt', '90 seconds = 2 minutes'); | |
22419 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutt', '44 minutes = 44 minutes'); | |
22420 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ein time', '45 minutes = an hour'); | |
22421 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ein time', '89 minutes = an hour'); | |
22422 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 timar', '90 minutes = 2 hours'); | |
22423 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 timar', '5 hours = 5 hours'); | |
22424 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 timar', '21 hours = 21 hours'); | |
22425 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ein dag', '22 hours = a day'); | |
22426 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ein dag', '35 hours = a day'); | |
22427 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dagar', '36 hours = 2 days'); | |
22428 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ein dag', '1 day = a day'); | |
22429 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dagar', '5 days = 5 days'); | |
22430 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dagar', '25 days = 25 days'); | |
22431 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ein månad', '26 days = a month'); | |
22432 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ein månad', '30 days = a month'); | |
22433 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ein månad', '43 days = a month'); | |
22434 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 månader', '46 days = 2 months'); | |
22435 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 månader', '75 days = 2 months'); | |
22436 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 månader', '76 days = 3 months'); | |
22437 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ein månad', '1 month = a month'); | |
22438 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 månader', '5 months = 5 months'); | |
22439 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'eit år', '345 days = a year'); | |
22440 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 år', '548 days = 2 years'); | |
22441 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'eit år', '1 year = a year'); | |
22442 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 år', '5 years = 5 years'); | |
22443 }); | |
22444 | |
22445 test('suffix', function (assert) { | |
22446 assert.equal(moment(30000).from(0), 'om nokre sekund', 'prefix'); | |
22447 assert.equal(moment(0).from(30000), 'for nokre sekund sidan', 'suffix'); | |
22448 }); | |
22449 | |
22450 test('now from now', function (assert) { | |
22451 assert.equal(moment().fromNow(), 'for nokre sekund sidan', 'now from now should display as in the past'); | |
22452 }); | |
22453 | |
22454 test('fromNow', function (assert) { | |
22455 assert.equal(moment().add({s: 30}).fromNow(), 'om nokre sekund', 'in a few seconds'); | |
22456 assert.equal(moment().add({d: 5}).fromNow(), 'om 5 dagar', 'in 5 days'); | |
22457 }); | |
22458 | |
22459 test('calendar day', function (assert) { | |
22460 var a = moment().hours(2).minutes(0).seconds(0); | |
22461 | |
22462 assert.equal(moment(a).calendar(), 'I dag klokka 02:00', 'today at the same time'); | |
22463 assert.equal(moment(a).add({m: 25}).calendar(), 'I dag klokka 02:25', 'Now plus 25 min'); | |
22464 assert.equal(moment(a).add({h: 1}).calendar(), 'I dag klokka 03:00', 'Now plus 1 hour'); | |
22465 assert.equal(moment(a).add({d: 1}).calendar(), 'I morgon klokka 02:00', 'tomorrow at the same time'); | |
22466 assert.equal(moment(a).subtract({h: 1}).calendar(), 'I dag klokka 01:00', 'Now minus 1 hour'); | |
22467 assert.equal(moment(a).subtract({d: 1}).calendar(), 'I går klokka 02:00', 'yesterday at the same time'); | |
22468 }); | |
22469 | |
22470 test('calendar next week', function (assert) { | |
22471 var i, m; | |
22472 for (i = 2; i < 7; i++) { | |
22473 m = moment().add({d: i}); | |
22474 assert.equal(m.calendar(), m.format('dddd [klokka] LT'), 'Today + ' + i + ' days current time'); | |
22475 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
22476 assert.equal(m.calendar(), m.format('dddd [klokka] LT'), 'Today + ' + i + ' days beginning of day'); | |
22477 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
22478 assert.equal(m.calendar(), m.format('dddd [klokka] LT'), 'Today + ' + i + ' days end of day'); | |
22479 } | |
22480 }); | |
22481 | |
22482 test('calendar last week', function (assert) { | |
22483 var i, m; | |
22484 for (i = 2; i < 7; i++) { | |
22485 m = moment().subtract({d: i}); | |
22486 assert.equal(m.calendar(), m.format('[Føregåande] dddd [klokka] LT'), 'Today - ' + i + ' days current time'); | |
22487 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
22488 assert.equal(m.calendar(), m.format('[Føregåande] dddd [klokka] LT'), 'Today - ' + i + ' days beginning of day'); | |
22489 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
22490 assert.equal(m.calendar(), m.format('[Føregåande] dddd [klokka] LT'), 'Today - ' + i + ' days end of day'); | |
22491 } | |
22492 }); | |
22493 | |
22494 test('calendar all else', function (assert) { | |
22495 var weeksAgo = moment().subtract({w: 1}), | |
22496 weeksFromNow = moment().add({w: 1}); | |
22497 | |
22498 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
22499 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
22500 | |
22501 weeksAgo = moment().subtract({w: 2}); | |
22502 weeksFromNow = moment().add({w: 2}); | |
22503 | |
22504 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
22505 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
22506 }); | |
22507 | |
22508 test('weeks year starting sunday', function (assert) { | |
22509 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
22510 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
22511 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
22512 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
22513 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
22514 }); | |
22515 | |
22516 test('weeks year starting monday', function (assert) { | |
22517 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
22518 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
22519 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
22520 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
22521 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
22522 }); | |
22523 | |
22524 test('weeks year starting tuesday', function (assert) { | |
22525 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
22526 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
22527 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
22528 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
22529 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
22530 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
22531 }); | |
22532 | |
22533 test('weeks year starting wednesday', function (assert) { | |
22534 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
22535 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
22536 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
22537 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
22538 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
22539 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
22540 }); | |
22541 | |
22542 test('weeks year starting thursday', function (assert) { | |
22543 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
22544 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
22545 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
22546 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
22547 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
22548 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
22549 }); | |
22550 | |
22551 test('weeks year starting friday', function (assert) { | |
22552 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
22553 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
22554 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
22555 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
22556 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
22557 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
22558 }); | |
22559 | |
22560 test('weeks year starting saturday', function (assert) { | |
22561 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
22562 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
22563 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
22564 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
22565 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
22566 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
22567 }); | |
22568 | |
22569 test('weeks year starting sunday formatted', function (assert) { | |
22570 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52'); | |
22571 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1'); | |
22572 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1'); | |
22573 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2'); | |
22574 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2'); | |
22575 }); | |
22576 | |
22577 test('lenient ordinal parsing', function (assert) { | |
22578 var i, ordinalStr, testMoment; | |
22579 for (i = 1; i <= 31; ++i) { | |
22580 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
22581 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
22582 assert.equal(testMoment.year(), 2014, | |
22583 'lenient ordinal parsing ' + i + ' year check'); | |
22584 assert.equal(testMoment.month(), 0, | |
22585 'lenient ordinal parsing ' + i + ' month check'); | |
22586 assert.equal(testMoment.date(), i, | |
22587 'lenient ordinal parsing ' + i + ' date check'); | |
22588 } | |
22589 }); | |
22590 | |
22591 test('lenient ordinal parsing of number', function (assert) { | |
22592 var i, testMoment; | |
22593 for (i = 1; i <= 31; ++i) { | |
22594 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
22595 assert.equal(testMoment.year(), 2014, | |
22596 'lenient ordinal parsing of number ' + i + ' year check'); | |
22597 assert.equal(testMoment.month(), 0, | |
22598 'lenient ordinal parsing of number ' + i + ' month check'); | |
22599 assert.equal(testMoment.date(), i, | |
22600 'lenient ordinal parsing of number ' + i + ' date check'); | |
22601 } | |
22602 }); | |
22603 | |
22604 test('strict ordinal parsing', function (assert) { | |
22605 var i, ordinalStr, testMoment; | |
22606 for (i = 1; i <= 31; ++i) { | |
22607 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
22608 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
22609 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
22610 } | |
22611 }); | |
22612 | |
22613 })); | |
22614 | |
22615 (function (global, factory) { | |
22616 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
22617 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
22618 factory(global.moment) | |
22619 }(this, function (moment) { 'use strict'; | |
22620 | |
22621 /*global QUnit:false*/ | |
22622 | |
22623 var test = QUnit.test; | |
22624 | |
22625 function module (name, lifecycle) { | |
22626 QUnit.module(name, { | |
22627 setup : function () { | |
22628 moment.locale('en'); | |
22629 moment.createFromInputFallback = function () { | |
22630 throw new Error('input not handled by moment'); | |
22631 }; | |
22632 if (lifecycle && lifecycle.setup) { | |
22633 lifecycle.setup(); | |
22634 } | |
22635 }, | |
22636 teardown : function () { | |
22637 if (lifecycle && lifecycle.teardown) { | |
22638 lifecycle.teardown(); | |
22639 } | |
22640 } | |
22641 }); | |
22642 } | |
22643 | |
22644 function localeModule (name, lifecycle) { | |
22645 QUnit.module('locale:' + name, { | |
22646 setup : function () { | |
22647 moment.locale(name); | |
22648 moment.createFromInputFallback = function () { | |
22649 throw new Error('input not handled by moment'); | |
22650 }; | |
22651 if (lifecycle && lifecycle.setup) { | |
22652 lifecycle.setup(); | |
22653 } | |
22654 }, | |
22655 teardown : function () { | |
22656 moment.locale('en'); | |
22657 if (lifecycle && lifecycle.teardown) { | |
22658 lifecycle.teardown(); | |
22659 } | |
22660 } | |
22661 }); | |
22662 } | |
22663 | |
22664 localeModule('pl'); | |
22665 | |
22666 test('parse', function (assert) { | |
22667 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; | |
22668 function equalTest(input, mmm, i) { | |
22669 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
22670 } | |
22671 for (i = 0; i < 12; i++) { | |
22672 tests[i] = tests[i].split(' '); | |
22673 equalTest(tests[i][0], 'MMM', i); | |
22674 equalTest(tests[i][1], 'MMM', i); | |
22675 equalTest(tests[i][2], 'MMM', i); | |
22676 equalTest(tests[i][0], 'MMMM', i); | |
22677 equalTest(tests[i][1], 'MMMM', i); | |
22678 equalTest(tests[i][2], 'MMMM', i); | |
22679 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
22680 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
22681 equalTest(tests[i][2].toLocaleLowerCase(), 'MMMM', i); | |
22682 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
22683 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
22684 equalTest(tests[i][2].toLocaleUpperCase(), 'MMMM', i); | |
22685 } | |
22686 }); | |
22687 | |
22688 test('parse strict', function (assert) { | |
22689 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; | |
22690 function equalTest(input, mmm, i) { | |
22691 assert.equal(moment(input, mmm, true).month(), i, input + ' should be month ' + (i + 1)); | |
22692 } | |
22693 for (i = 0; i < 12; i++) { | |
22694 tests[i] = tests[i].split(' '); | |
22695 equalTest(tests[i][0], 'MMMM', i); | |
22696 equalTest(tests[i][1], 'MMMM', i); | |
22697 equalTest(tests[i][2], 'MMM', i); | |
22698 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
22699 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
22700 equalTest(tests[i][2].toLocaleLowerCase(), 'MMM', i); | |
22701 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
22702 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
22703 equalTest(tests[i][2].toLocaleUpperCase(), 'MMM', i); | |
22704 } | |
22705 }); | |
22706 | |
22707 test('format', function (assert) { | |
22708 var a = [ | |
22709 ['dddd, MMMM Do YYYY, h:mm:ss a', 'niedziela, luty 14. 2010, 3:25:50 pm'], | |
22710 ['ddd, hA', 'nie, 3PM'], | |
22711 ['M Mo MM MMMM MMM', '2 2. 02 luty lut'], | |
22712 ['YYYY YY', '2010 10'], | |
22713 ['D Do DD', '14 14. 14'], | |
22714 ['d do dddd ddd dd', '0 0. niedziela nie N'], | |
22715 ['DDD DDDo DDDD', '45 45. 045'], | |
22716 ['w wo ww', '6 6. 06'], | |
22717 ['h hh', '3 03'], | |
22718 ['H HH', '15 15'], | |
22719 ['m mm', '25 25'], | |
22720 ['s ss', '50 50'], | |
22721 ['a A', 'pm PM'], | |
22722 ['[the] DDDo [day of the year]', 'the 45. day of the year'], | |
22723 ['LTS', '15:25:50'], | |
22724 ['L', '14.02.2010'], | |
22725 ['LL', '14 lutego 2010'], | |
22726 ['LLL', '14 lutego 2010 15:25'], | |
22727 ['LLLL', 'niedziela, 14 lutego 2010 15:25'], | |
22728 ['l', '14.2.2010'], | |
22729 ['ll', '14 lut 2010'], | |
22730 ['lll', '14 lut 2010 15:25'], | |
22731 ['llll', 'nie, 14 lut 2010 15:25'] | |
22732 ], | |
22733 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
22734 i; | |
22735 for (i = 0; i < a.length; i++) { | |
22736 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
22737 } | |
22738 }); | |
22739 | |
22740 test('format ordinal', function (assert) { | |
22741 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.'); | |
22742 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.'); | |
22743 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.'); | |
22744 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.'); | |
22745 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.'); | |
22746 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.'); | |
22747 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.'); | |
22748 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.'); | |
22749 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.'); | |
22750 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.'); | |
22751 | |
22752 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.'); | |
22753 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.'); | |
22754 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.'); | |
22755 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.'); | |
22756 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.'); | |
22757 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.'); | |
22758 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.'); | |
22759 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.'); | |
22760 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.'); | |
22761 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.'); | |
22762 | |
22763 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.'); | |
22764 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.'); | |
22765 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.'); | |
22766 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.'); | |
22767 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.'); | |
22768 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.'); | |
22769 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.'); | |
22770 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.'); | |
22771 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.'); | |
22772 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.'); | |
22773 | |
22774 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.'); | |
22775 }); | |
22776 | |
22777 test('format month', function (assert) { | |
22778 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; | |
22779 for (i = 0; i < expected.length; i++) { | |
22780 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
22781 } | |
22782 }); | |
22783 | |
22784 test('format week', function (assert) { | |
22785 var expected = 'niedziela nie N_poniedziałek pon Pn_wtorek wt Wt_środa śr Śr_czwartek czw Cz_piątek pt Pt_sobota sb So'.split('_'), i; | |
22786 for (i = 0; i < expected.length; i++) { | |
22787 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
22788 } | |
22789 }); | |
22790 | |
22791 test('from', function (assert) { | |
22792 var start = moment([2007, 1, 28]); | |
22793 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'kilka sekund', '44 seconds = a few seconds'); | |
22794 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minuta', '45 seconds = a minute'); | |
22795 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minuta', '89 seconds = a minute'); | |
22796 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuty', '90 seconds = 2 minutes'); | |
22797 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuty', '44 minutes = 44 minutes'); | |
22798 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'godzina', '45 minutes = an hour'); | |
22799 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'godzina', '89 minutes = an hour'); | |
22800 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 godziny', '90 minutes = 2 hours'); | |
22801 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 godzin', '5 hours = 5 hours'); | |
22802 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 godzin', '21 hours = 21 hours'); | |
22803 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '1 dzień', '22 hours = a day'); | |
22804 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '1 dzień', '35 hours = a day'); | |
22805 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dni', '36 hours = 2 days'); | |
22806 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '1 dzień', '1 day = a day'); | |
22807 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dni', '5 days = 5 days'); | |
22808 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dni', '25 days = 25 days'); | |
22809 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'miesiąc', '26 days = a month'); | |
22810 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'miesiąc', '30 days = a month'); | |
22811 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'miesiąc', '43 days = a month'); | |
22812 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 miesiące', '46 days = 2 months'); | |
22813 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 miesiące', '75 days = 2 months'); | |
22814 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 miesiące', '76 days = 3 months'); | |
22815 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'miesiąc', '1 month = a month'); | |
22816 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 miesięcy', '5 months = 5 months'); | |
22817 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'rok', '345 days = a year'); | |
22818 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 lata', '548 days = 2 years'); | |
22819 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'rok', '1 year = a year'); | |
22820 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 lat', '5 years = 5 years'); | |
22821 assert.equal(start.from(moment([2007, 1, 28]).add({y: 112}), true), '112 lat', '112 years = 112 years'); | |
22822 assert.equal(start.from(moment([2007, 1, 28]).add({y: 122}), true), '122 lata', '122 years = 122 years'); | |
22823 assert.equal(start.from(moment([2007, 1, 28]).add({y: 213}), true), '213 lat', '213 years = 213 years'); | |
22824 assert.equal(start.from(moment([2007, 1, 28]).add({y: 223}), true), '223 lata', '223 years = 223 years'); | |
22825 }); | |
22826 | |
22827 test('suffix', function (assert) { | |
22828 assert.equal(moment(30000).from(0), 'za kilka sekund', 'prefix'); | |
22829 assert.equal(moment(0).from(30000), 'kilka sekund temu', 'suffix'); | |
22830 }); | |
22831 | |
22832 test('now from now', function (assert) { | |
22833 assert.equal(moment().fromNow(), 'kilka sekund temu', 'now from now should display as in the past'); | |
22834 }); | |
22835 | |
22836 test('fromNow', function (assert) { | |
22837 assert.equal(moment().add({s: 30}).fromNow(), 'za kilka sekund', 'in a few seconds'); | |
22838 assert.equal(moment().add({h: 1}).fromNow(), 'za godzinę', 'in an hour'); | |
22839 assert.equal(moment().add({d: 5}).fromNow(), 'za 5 dni', 'in 5 days'); | |
22840 }); | |
22841 | |
22842 test('calendar day', function (assert) { | |
22843 var a = moment().hours(2).minutes(0).seconds(0); | |
22844 | |
22845 assert.equal(moment(a).calendar(), 'Dziś o 02:00', 'today at the same time'); | |
22846 assert.equal(moment(a).add({m: 25}).calendar(), 'Dziś o 02:25', 'Now plus 25 min'); | |
22847 assert.equal(moment(a).add({h: 1}).calendar(), 'Dziś o 03:00', 'Now plus 1 hour'); | |
22848 assert.equal(moment(a).add({d: 1}).calendar(), 'Jutro o 02:00', 'tomorrow at the same time'); | |
22849 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Dziś o 01:00', 'Now minus 1 hour'); | |
22850 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Wczoraj o 02:00', 'yesterday at the same time'); | |
22851 }); | |
22852 | |
22853 test('calendar next week', function (assert) { | |
22854 var i, m; | |
22855 for (i = 2; i < 7; i++) { | |
22856 m = moment().add({d: i}); | |
22857 assert.equal(m.calendar(), m.format('[W] dddd [o] LT'), 'Today + ' + i + ' days current time'); | |
22858 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
22859 assert.equal(m.calendar(), m.format('[W] dddd [o] LT'), 'Today + ' + i + ' days beginning of day'); | |
22860 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
22861 assert.equal(m.calendar(), m.format('[W] dddd [o] LT'), 'Today + ' + i + ' days end of day'); | |
22862 } | |
22863 }); | |
22864 | |
22865 test('calendar last week', function (assert) { | |
22866 var i, m; | |
22867 | |
22868 function makeFormat(d) { | |
22869 switch (d.day()) { | |
22870 case 0: | |
22871 return '[W zeszłą niedzielę o] LT'; | |
22872 case 3: | |
22873 return '[W zeszłą środę o] LT'; | |
22874 case 6: | |
22875 return '[W zeszłą sobotę o] LT'; | |
22876 default: | |
22877 return '[W zeszły] dddd [o] LT'; | |
22878 } | |
22879 } | |
22880 | |
22881 for (i = 2; i < 7; i++) { | |
22882 m = moment().subtract({d: i}); | |
22883 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time'); | |
22884 | |
22885 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
22886 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day'); | |
22887 | |
22888 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
22889 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day'); | |
22890 } | |
22891 }); | |
22892 | |
22893 test('calendar all else', function (assert) { | |
22894 var weeksAgo = moment().subtract({w: 1}), | |
22895 weeksFromNow = moment().add({w: 1}); | |
22896 | |
22897 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
22898 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
22899 | |
22900 weeksAgo = moment().subtract({w: 2}); | |
22901 weeksFromNow = moment().add({w: 2}); | |
22902 | |
22903 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
22904 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
22905 }); | |
22906 | |
22907 test('weeks year starting sunday', function (assert) { | |
22908 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
22909 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
22910 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
22911 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
22912 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
22913 }); | |
22914 | |
22915 test('weeks year starting monday', function (assert) { | |
22916 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
22917 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
22918 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
22919 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
22920 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
22921 }); | |
22922 | |
22923 test('weeks year starting tuesday', function (assert) { | |
22924 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
22925 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
22926 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
22927 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
22928 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
22929 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
22930 }); | |
22931 | |
22932 test('weeks year starting wednesday', function (assert) { | |
22933 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
22934 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
22935 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
22936 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
22937 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
22938 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
22939 }); | |
22940 | |
22941 test('weeks year starting thursday', function (assert) { | |
22942 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
22943 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
22944 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
22945 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
22946 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
22947 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
22948 }); | |
22949 | |
22950 test('weeks year starting friday', function (assert) { | |
22951 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
22952 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
22953 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
22954 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
22955 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
22956 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
22957 }); | |
22958 | |
22959 test('weeks year starting saturday', function (assert) { | |
22960 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
22961 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
22962 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
22963 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
22964 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
22965 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
22966 }); | |
22967 | |
22968 test('weeks year starting sunday formatted', function (assert) { | |
22969 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52'); | |
22970 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1'); | |
22971 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1'); | |
22972 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2'); | |
22973 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2'); | |
22974 }); | |
22975 | |
22976 test('lenient ordinal parsing', function (assert) { | |
22977 var i, ordinalStr, testMoment; | |
22978 for (i = 1; i <= 31; ++i) { | |
22979 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
22980 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
22981 assert.equal(testMoment.year(), 2014, | |
22982 'lenient ordinal parsing ' + i + ' year check'); | |
22983 assert.equal(testMoment.month(), 0, | |
22984 'lenient ordinal parsing ' + i + ' month check'); | |
22985 assert.equal(testMoment.date(), i, | |
22986 'lenient ordinal parsing ' + i + ' date check'); | |
22987 } | |
22988 }); | |
22989 | |
22990 test('lenient ordinal parsing of number', function (assert) { | |
22991 var i, testMoment; | |
22992 for (i = 1; i <= 31; ++i) { | |
22993 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
22994 assert.equal(testMoment.year(), 2014, | |
22995 'lenient ordinal parsing of number ' + i + ' year check'); | |
22996 assert.equal(testMoment.month(), 0, | |
22997 'lenient ordinal parsing of number ' + i + ' month check'); | |
22998 assert.equal(testMoment.date(), i, | |
22999 'lenient ordinal parsing of number ' + i + ' date check'); | |
23000 } | |
23001 }); | |
23002 | |
23003 test('strict ordinal parsing', function (assert) { | |
23004 var i, ordinalStr, testMoment; | |
23005 for (i = 1; i <= 31; ++i) { | |
23006 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
23007 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
23008 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
23009 } | |
23010 }); | |
23011 | |
23012 })); | |
23013 | |
23014 (function (global, factory) { | |
23015 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
23016 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
23017 factory(global.moment) | |
23018 }(this, function (moment) { 'use strict'; | |
23019 | |
23020 /*global QUnit:false*/ | |
23021 | |
23022 var test = QUnit.test; | |
23023 | |
23024 function module (name, lifecycle) { | |
23025 QUnit.module(name, { | |
23026 setup : function () { | |
23027 moment.locale('en'); | |
23028 moment.createFromInputFallback = function () { | |
23029 throw new Error('input not handled by moment'); | |
23030 }; | |
23031 if (lifecycle && lifecycle.setup) { | |
23032 lifecycle.setup(); | |
23033 } | |
23034 }, | |
23035 teardown : function () { | |
23036 if (lifecycle && lifecycle.teardown) { | |
23037 lifecycle.teardown(); | |
23038 } | |
23039 } | |
23040 }); | |
23041 } | |
23042 | |
23043 function localeModule (name, lifecycle) { | |
23044 QUnit.module('locale:' + name, { | |
23045 setup : function () { | |
23046 moment.locale(name); | |
23047 moment.createFromInputFallback = function () { | |
23048 throw new Error('input not handled by moment'); | |
23049 }; | |
23050 if (lifecycle && lifecycle.setup) { | |
23051 lifecycle.setup(); | |
23052 } | |
23053 }, | |
23054 teardown : function () { | |
23055 moment.locale('en'); | |
23056 if (lifecycle && lifecycle.teardown) { | |
23057 lifecycle.teardown(); | |
23058 } | |
23059 } | |
23060 }); | |
23061 } | |
23062 | |
23063 localeModule('pt-br'); | |
23064 | |
23065 test('parse', function (assert) { | |
23066 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; | |
23067 | |
23068 function equalTest(input, mmm, i) { | |
23069 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
23070 } | |
23071 | |
23072 for (i = 0; i < 12; i++) { | |
23073 tests[i] = tests[i].split(' '); | |
23074 equalTest(tests[i][0], 'MMM', i); | |
23075 equalTest(tests[i][1], 'MMM', i); | |
23076 equalTest(tests[i][0], 'MMMM', i); | |
23077 equalTest(tests[i][1], 'MMMM', i); | |
23078 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
23079 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
23080 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
23081 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
23082 } | |
23083 }); | |
23084 | |
23085 test('format', function (assert) { | |
23086 var a = [ | |
23087 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Domingo, Fevereiro 14º 2010, 3:25:50 pm'], | |
23088 ['ddd, hA', 'Dom, 3PM'], | |
23089 ['M Mo MM MMMM MMM', '2 2º 02 Fevereiro Fev'], | |
23090 ['YYYY YY', '2010 10'], | |
23091 ['D Do DD', '14 14º 14'], | |
23092 ['d do dddd ddd', '0 0º Domingo Dom'], | |
23093 ['DDD DDDo DDDD', '45 45º 045'], | |
23094 ['w wo ww', '8 8º 08'], | |
23095 ['h hh', '3 03'], | |
23096 ['H HH', '15 15'], | |
23097 ['m mm', '25 25'], | |
23098 ['s ss', '50 50'], | |
23099 ['a A', 'pm PM'], | |
23100 ['[the] DDDo [day of the year]', 'the 45º day of the year'], | |
23101 ['LTS', '15:25:50'], | |
23102 ['L', '14/02/2010'], | |
23103 ['LL', '14 de Fevereiro de 2010'], | |
23104 ['LLL', '14 de Fevereiro de 2010 às 15:25'], | |
23105 ['LLLL', 'Domingo, 14 de Fevereiro de 2010 às 15:25'], | |
23106 ['l', '14/2/2010'], | |
23107 ['ll', '14 de Fev de 2010'], | |
23108 ['lll', '14 de Fev de 2010 às 15:25'], | |
23109 ['llll', 'Dom, 14 de Fev de 2010 às 15:25'] | |
23110 ], | |
23111 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
23112 i; | |
23113 for (i = 0; i < a.length; i++) { | |
23114 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
23115 } | |
23116 }); | |
23117 | |
23118 test('format ordinal', function (assert) { | |
23119 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1º', '1º'); | |
23120 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2º', '2º'); | |
23121 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3º', '3º'); | |
23122 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4º', '4º'); | |
23123 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5º', '5º'); | |
23124 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6º', '6º'); | |
23125 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7º', '7º'); | |
23126 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8º', '8º'); | |
23127 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9º', '9º'); | |
23128 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10º', '10º'); | |
23129 | |
23130 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11º', '11º'); | |
23131 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12º', '12º'); | |
23132 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13º', '13º'); | |
23133 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14º', '14º'); | |
23134 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15º', '15º'); | |
23135 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16º', '16º'); | |
23136 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17º', '17º'); | |
23137 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18º', '18º'); | |
23138 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19º', '19º'); | |
23139 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20º', '20º'); | |
23140 | |
23141 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21º', '21º'); | |
23142 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22º', '22º'); | |
23143 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23º', '23º'); | |
23144 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24º', '24º'); | |
23145 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25º', '25º'); | |
23146 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26º', '26º'); | |
23147 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27º', '27º'); | |
23148 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28º', '28º'); | |
23149 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29º', '29º'); | |
23150 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30º', '30º'); | |
23151 | |
23152 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31º', '31º'); | |
23153 }); | |
23154 | |
23155 test('format month', function (assert) { | |
23156 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; | |
23157 for (i = 0; i < expected.length; i++) { | |
23158 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
23159 } | |
23160 }); | |
23161 | |
23162 test('format week', function (assert) { | |
23163 var expected = 'Domingo Dom_Segunda-Feira Seg_Terça-Feira Ter_Quarta-Feira Qua_Quinta-Feira Qui_Sexta-Feira Sex_Sábado Sáb'.split('_'), i; | |
23164 for (i = 0; i < expected.length; i++) { | |
23165 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd'), expected[i], expected[i]); | |
23166 } | |
23167 }); | |
23168 | |
23169 test('from', function (assert) { | |
23170 var start = moment([2007, 1, 28]); | |
23171 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'poucos segundos', '44 seconds = seconds'); | |
23172 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'um minuto', '45 seconds = a minute'); | |
23173 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'um minuto', '89 seconds = a minute'); | |
23174 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutos', '90 seconds = 2 minutes'); | |
23175 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutos', '44 minutes = 44 minutes'); | |
23176 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'uma hora', '45 minutes = an hour'); | |
23177 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'uma hora', '89 minutes = an hour'); | |
23178 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 horas', '90 minutes = 2 hours'); | |
23179 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 horas', '5 hours = 5 hours'); | |
23180 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 horas', '21 hours = 21 hours'); | |
23181 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'um dia', '22 hours = a day'); | |
23182 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'um dia', '35 hours = a day'); | |
23183 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dias', '36 hours = 2 days'); | |
23184 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'um dia', '1 day = a day'); | |
23185 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dias', '5 days = 5 days'); | |
23186 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dias', '25 days = 25 days'); | |
23187 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'um mês', '26 days = a month'); | |
23188 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'um mês', '30 days = a month'); | |
23189 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'um mês', '43 days = a month'); | |
23190 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 meses', '46 days = 2 months'); | |
23191 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 meses', '75 days = 2 months'); | |
23192 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 meses', '76 days = 3 months'); | |
23193 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'um mês', '1 month = a month'); | |
23194 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 meses', '5 months = 5 months'); | |
23195 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'um ano', '345 days = a year'); | |
23196 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 anos', '548 days = 2 years'); | |
23197 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'um ano', '1 year = a year'); | |
23198 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 anos', '5 years = 5 years'); | |
23199 }); | |
23200 | |
23201 test('suffix', function (assert) { | |
23202 assert.equal(moment(30000).from(0), 'em poucos segundos', 'prefix'); | |
23203 assert.equal(moment(0).from(30000), 'poucos segundos atrás', 'suffix'); | |
23204 }); | |
23205 | |
23206 test('fromNow', function (assert) { | |
23207 assert.equal(moment().add({s: 30}).fromNow(), 'em poucos segundos', 'in seconds'); | |
23208 assert.equal(moment().add({d: 5}).fromNow(), 'em 5 dias', 'in 5 days'); | |
23209 }); | |
23210 | |
23211 test('calendar day', function (assert) { | |
23212 var a = moment().hours(2).minutes(0).seconds(0); | |
23213 | |
23214 assert.equal(moment(a).calendar(), 'Hoje às 02:00', 'today at the same time'); | |
23215 assert.equal(moment(a).add({m: 25}).calendar(), 'Hoje às 02:25', 'Now plus 25 min'); | |
23216 assert.equal(moment(a).add({h: 1}).calendar(), 'Hoje às 03:00', 'Now plus 1 hour'); | |
23217 assert.equal(moment(a).add({d: 1}).calendar(), 'Amanhã às 02:00', 'tomorrow at the same time'); | |
23218 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Hoje às 01:00', 'Now minus 1 hour'); | |
23219 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Ontem às 02:00', 'yesterday at the same time'); | |
23220 }); | |
23221 | |
23222 test('calendar next week', function (assert) { | |
23223 var i, m; | |
23224 for (i = 2; i < 7; i++) { | |
23225 m = moment().add({d: i}); | |
23226 assert.equal(m.calendar(), m.format('dddd [às] LT'), 'Today + ' + i + ' days current time'); | |
23227 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
23228 assert.equal(m.calendar(), m.format('dddd [às] LT'), 'Today + ' + i + ' days beginning of day'); | |
23229 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
23230 assert.equal(m.calendar(), m.format('dddd [às] LT'), 'Today + ' + i + ' days end of day'); | |
23231 } | |
23232 }); | |
23233 | |
23234 test('calendar last week', function (assert) { | |
23235 var i, m; | |
23236 for (i = 2; i < 7; i++) { | |
23237 m = moment().subtract({d: i}); | |
23238 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'); | |
23239 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
23240 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'); | |
23241 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
23242 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'); | |
23243 } | |
23244 }); | |
23245 | |
23246 test('calendar all else', function (assert) { | |
23247 var weeksAgo = moment().subtract({w: 1}), | |
23248 weeksFromNow = moment().add({w: 1}); | |
23249 | |
23250 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
23251 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
23252 | |
23253 weeksAgo = moment().subtract({w: 2}); | |
23254 weeksFromNow = moment().add({w: 2}); | |
23255 | |
23256 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
23257 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
23258 }); | |
23259 | |
23260 test('weeks year starting sunday', function (assert) { | |
23261 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
23262 assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1'); | |
23263 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
23264 assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2'); | |
23265 assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3'); | |
23266 }); | |
23267 | |
23268 test('weeks year starting monday', function (assert) { | |
23269 assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1'); | |
23270 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
23271 assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1'); | |
23272 assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2'); | |
23273 assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2'); | |
23274 assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3'); | |
23275 }); | |
23276 | |
23277 test('weeks year starting tuesday', function (assert) { | |
23278 assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52'); | |
23279 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
23280 assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1'); | |
23281 assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2'); | |
23282 assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2'); | |
23283 assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3'); | |
23284 }); | |
23285 | |
23286 test('weeks year starting wednesday', function (assert) { | |
23287 assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1'); | |
23288 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
23289 assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1'); | |
23290 assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2'); | |
23291 assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2'); | |
23292 assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3'); | |
23293 }); | |
23294 | |
23295 test('weeks year starting thursday', function (assert) { | |
23296 assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1'); | |
23297 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
23298 assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1'); | |
23299 assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2'); | |
23300 assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2'); | |
23301 assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3'); | |
23302 }); | |
23303 | |
23304 test('weeks year starting friday', function (assert) { | |
23305 assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1'); | |
23306 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
23307 assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1'); | |
23308 assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2'); | |
23309 assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2'); | |
23310 assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3'); | |
23311 }); | |
23312 | |
23313 test('weeks year starting saturday', function (assert) { | |
23314 assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1'); | |
23315 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
23316 assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2'); | |
23317 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2'); | |
23318 assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3'); | |
23319 }); | |
23320 | |
23321 test('weeks year starting sunday format', function (assert) { | |
23322 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1º', 'Jan 1 2012 should be week 1'); | |
23323 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1º', 'Jan 7 2012 should be week 1'); | |
23324 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2º', 'Jan 8 2012 should be week 2'); | |
23325 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2º', 'Jan 14 2012 should be week 2'); | |
23326 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3º', 'Jan 15 2012 should be week 3'); | |
23327 }); | |
23328 | |
23329 test('lenient ordinal parsing', function (assert) { | |
23330 var i, ordinalStr, testMoment; | |
23331 for (i = 1; i <= 31; ++i) { | |
23332 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
23333 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
23334 assert.equal(testMoment.year(), 2014, | |
23335 'lenient ordinal parsing ' + i + ' year check'); | |
23336 assert.equal(testMoment.month(), 0, | |
23337 'lenient ordinal parsing ' + i + ' month check'); | |
23338 assert.equal(testMoment.date(), i, | |
23339 'lenient ordinal parsing ' + i + ' date check'); | |
23340 } | |
23341 }); | |
23342 | |
23343 test('lenient ordinal parsing of number', function (assert) { | |
23344 var i, testMoment; | |
23345 for (i = 1; i <= 31; ++i) { | |
23346 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
23347 assert.equal(testMoment.year(), 2014, | |
23348 'lenient ordinal parsing of number ' + i + ' year check'); | |
23349 assert.equal(testMoment.month(), 0, | |
23350 'lenient ordinal parsing of number ' + i + ' month check'); | |
23351 assert.equal(testMoment.date(), i, | |
23352 'lenient ordinal parsing of number ' + i + ' date check'); | |
23353 } | |
23354 }); | |
23355 | |
23356 test('strict ordinal parsing', function (assert) { | |
23357 var i, ordinalStr, testMoment; | |
23358 for (i = 1; i <= 31; ++i) { | |
23359 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
23360 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
23361 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
23362 } | |
23363 }); | |
23364 | |
23365 })); | |
23366 | |
23367 (function (global, factory) { | |
23368 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
23369 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
23370 factory(global.moment) | |
23371 }(this, function (moment) { 'use strict'; | |
23372 | |
23373 /*global QUnit:false*/ | |
23374 | |
23375 var test = QUnit.test; | |
23376 | |
23377 function module (name, lifecycle) { | |
23378 QUnit.module(name, { | |
23379 setup : function () { | |
23380 moment.locale('en'); | |
23381 moment.createFromInputFallback = function () { | |
23382 throw new Error('input not handled by moment'); | |
23383 }; | |
23384 if (lifecycle && lifecycle.setup) { | |
23385 lifecycle.setup(); | |
23386 } | |
23387 }, | |
23388 teardown : function () { | |
23389 if (lifecycle && lifecycle.teardown) { | |
23390 lifecycle.teardown(); | |
23391 } | |
23392 } | |
23393 }); | |
23394 } | |
23395 | |
23396 function localeModule (name, lifecycle) { | |
23397 QUnit.module('locale:' + name, { | |
23398 setup : function () { | |
23399 moment.locale(name); | |
23400 moment.createFromInputFallback = function () { | |
23401 throw new Error('input not handled by moment'); | |
23402 }; | |
23403 if (lifecycle && lifecycle.setup) { | |
23404 lifecycle.setup(); | |
23405 } | |
23406 }, | |
23407 teardown : function () { | |
23408 moment.locale('en'); | |
23409 if (lifecycle && lifecycle.teardown) { | |
23410 lifecycle.teardown(); | |
23411 } | |
23412 } | |
23413 }); | |
23414 } | |
23415 | |
23416 localeModule('pt'); | |
23417 | |
23418 test('parse', function (assert) { | |
23419 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; | |
23420 function equalTest(input, mmm, i) { | |
23421 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
23422 } | |
23423 for (i = 0; i < 12; i++) { | |
23424 tests[i] = tests[i].split(' '); | |
23425 equalTest(tests[i][0], 'MMM', i); | |
23426 equalTest(tests[i][1], 'MMM', i); | |
23427 equalTest(tests[i][0], 'MMMM', i); | |
23428 equalTest(tests[i][1], 'MMMM', i); | |
23429 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
23430 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
23431 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
23432 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
23433 } | |
23434 }); | |
23435 | |
23436 test('format', function (assert) { | |
23437 var a = [ | |
23438 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Domingo, Fevereiro 14º 2010, 3:25:50 pm'], | |
23439 ['ddd, hA', 'Dom, 3PM'], | |
23440 ['M Mo MM MMMM MMM', '2 2º 02 Fevereiro Fev'], | |
23441 ['YYYY YY', '2010 10'], | |
23442 ['D Do DD', '14 14º 14'], | |
23443 ['d do dddd ddd', '0 0º Domingo Dom'], | |
23444 ['DDD DDDo DDDD', '45 45º 045'], | |
23445 ['w wo ww', '6 6º 06'], | |
23446 ['h hh', '3 03'], | |
23447 ['H HH', '15 15'], | |
23448 ['m mm', '25 25'], | |
23449 ['s ss', '50 50'], | |
23450 ['a A', 'pm PM'], | |
23451 ['[the] DDDo [day of the year]', 'the 45º day of the year'], | |
23452 ['LTS', '15:25:50'], | |
23453 ['L', '14/02/2010'], | |
23454 ['LL', '14 de Fevereiro de 2010'], | |
23455 ['LLL', '14 de Fevereiro de 2010 15:25'], | |
23456 ['LLLL', 'Domingo, 14 de Fevereiro de 2010 15:25'], | |
23457 ['l', '14/2/2010'], | |
23458 ['ll', '14 de Fev de 2010'], | |
23459 ['lll', '14 de Fev de 2010 15:25'], | |
23460 ['llll', 'Dom, 14 de Fev de 2010 15:25'] | |
23461 ], | |
23462 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
23463 i; | |
23464 for (i = 0; i < a.length; i++) { | |
23465 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
23466 } | |
23467 }); | |
23468 | |
23469 test('format ordinal', function (assert) { | |
23470 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1º', '1º'); | |
23471 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2º', '2º'); | |
23472 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3º', '3º'); | |
23473 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4º', '4º'); | |
23474 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5º', '5º'); | |
23475 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6º', '6º'); | |
23476 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7º', '7º'); | |
23477 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8º', '8º'); | |
23478 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9º', '9º'); | |
23479 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10º', '10º'); | |
23480 | |
23481 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11º', '11º'); | |
23482 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12º', '12º'); | |
23483 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13º', '13º'); | |
23484 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14º', '14º'); | |
23485 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15º', '15º'); | |
23486 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16º', '16º'); | |
23487 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17º', '17º'); | |
23488 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18º', '18º'); | |
23489 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19º', '19º'); | |
23490 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20º', '20º'); | |
23491 | |
23492 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21º', '21º'); | |
23493 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22º', '22º'); | |
23494 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23º', '23º'); | |
23495 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24º', '24º'); | |
23496 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25º', '25º'); | |
23497 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26º', '26º'); | |
23498 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27º', '27º'); | |
23499 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28º', '28º'); | |
23500 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29º', '29º'); | |
23501 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30º', '30º'); | |
23502 | |
23503 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31º', '31º'); | |
23504 }); | |
23505 | |
23506 test('format month', function (assert) { | |
23507 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; | |
23508 for (i = 0; i < expected.length; i++) { | |
23509 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
23510 } | |
23511 }); | |
23512 | |
23513 test('format week', function (assert) { | |
23514 var expected = 'Domingo Dom Dom_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áb'.split('_'), i; | |
23515 for (i = 0; i < expected.length; i++) { | |
23516 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
23517 } | |
23518 }); | |
23519 | |
23520 test('from', function (assert) { | |
23521 var start = moment([2007, 1, 28]); | |
23522 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'segundos', '44 seconds = seconds'); | |
23523 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'um minuto', '45 seconds = a minute'); | |
23524 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'um minuto', '89 seconds = a minute'); | |
23525 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minutos', '90 seconds = 2 minutes'); | |
23526 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minutos', '44 minutes = 44 minutes'); | |
23527 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'uma hora', '45 minutes = an hour'); | |
23528 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'uma hora', '89 minutes = an hour'); | |
23529 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 horas', '90 minutes = 2 hours'); | |
23530 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 horas', '5 hours = 5 hours'); | |
23531 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 horas', '21 hours = 21 hours'); | |
23532 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'um dia', '22 hours = a day'); | |
23533 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'um dia', '35 hours = a day'); | |
23534 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dias', '36 hours = 2 days'); | |
23535 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'um dia', '1 day = a day'); | |
23536 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dias', '5 days = 5 days'); | |
23537 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dias', '25 days = 25 days'); | |
23538 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'um mês', '26 days = a month'); | |
23539 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'um mês', '30 days = a month'); | |
23540 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'um mês', '43 days = a month'); | |
23541 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 meses', '46 days = 2 months'); | |
23542 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 meses', '75 days = 2 months'); | |
23543 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 meses', '76 days = 3 months'); | |
23544 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'um mês', '1 month = a month'); | |
23545 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 meses', '5 months = 5 months'); | |
23546 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'um ano', '345 days = a year'); | |
23547 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 anos', '548 days = 2 years'); | |
23548 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'um ano', '1 year = a year'); | |
23549 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 anos', '5 years = 5 years'); | |
23550 }); | |
23551 | |
23552 test('suffix', function (assert) { | |
23553 assert.equal(moment(30000).from(0), 'em segundos', 'prefix'); | |
23554 assert.equal(moment(0).from(30000), 'há segundos', 'suffix'); | |
23555 }); | |
23556 | |
23557 test('fromNow', function (assert) { | |
23558 assert.equal(moment().add({s: 30}).fromNow(), 'em segundos', 'in seconds'); | |
23559 assert.equal(moment().add({d: 5}).fromNow(), 'em 5 dias', 'in 5 days'); | |
23560 }); | |
23561 | |
23562 test('calendar day', function (assert) { | |
23563 var a = moment().hours(2).minutes(0).seconds(0); | |
23564 | |
23565 assert.equal(moment(a).calendar(), 'Hoje às 02:00', 'today at the same time'); | |
23566 assert.equal(moment(a).add({m: 25}).calendar(), 'Hoje às 02:25', 'Now plus 25 min'); | |
23567 assert.equal(moment(a).add({h: 1}).calendar(), 'Hoje às 03:00', 'Now plus 1 hour'); | |
23568 assert.equal(moment(a).add({d: 1}).calendar(), 'Amanhã às 02:00', 'tomorrow at the same time'); | |
23569 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Hoje às 01:00', 'Now minus 1 hour'); | |
23570 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Ontem às 02:00', 'yesterday at the same time'); | |
23571 }); | |
23572 | |
23573 test('calendar next week', function (assert) { | |
23574 var i, m; | |
23575 for (i = 2; i < 7; i++) { | |
23576 m = moment().add({d: i}); | |
23577 assert.equal(m.calendar(), m.format('dddd [às] LT'), 'Today + ' + i + ' days current time'); | |
23578 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
23579 assert.equal(m.calendar(), m.format('dddd [às] LT'), 'Today + ' + i + ' days beginning of day'); | |
23580 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
23581 assert.equal(m.calendar(), m.format('dddd [às] LT'), 'Today + ' + i + ' days end of day'); | |
23582 } | |
23583 }); | |
23584 | |
23585 test('calendar last week', function (assert) { | |
23586 var i, m; | |
23587 for (i = 2; i < 7; i++) { | |
23588 m = moment().subtract({d: i}); | |
23589 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'); | |
23590 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
23591 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'); | |
23592 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
23593 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'); | |
23594 } | |
23595 }); | |
23596 | |
23597 test('calendar all else', function (assert) { | |
23598 var weeksAgo = moment().subtract({w: 1}), | |
23599 weeksFromNow = moment().add({w: 1}); | |
23600 | |
23601 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
23602 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
23603 | |
23604 weeksAgo = moment().subtract({w: 2}); | |
23605 weeksFromNow = moment().add({w: 2}); | |
23606 | |
23607 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
23608 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
23609 }); | |
23610 | |
23611 test('weeks year starting sunday', function (assert) { | |
23612 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
23613 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
23614 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
23615 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
23616 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
23617 }); | |
23618 | |
23619 test('weeks year starting monday', function (assert) { | |
23620 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
23621 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
23622 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
23623 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
23624 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
23625 }); | |
23626 | |
23627 test('weeks year starting tuesday', function (assert) { | |
23628 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
23629 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
23630 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
23631 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
23632 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
23633 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
23634 }); | |
23635 | |
23636 test('weeks year starting wednesday', function (assert) { | |
23637 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
23638 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
23639 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
23640 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
23641 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
23642 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
23643 }); | |
23644 | |
23645 test('weeks year starting thursday', function (assert) { | |
23646 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
23647 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
23648 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
23649 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
23650 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
23651 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
23652 }); | |
23653 | |
23654 test('weeks year starting friday', function (assert) { | |
23655 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
23656 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
23657 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
23658 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
23659 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
23660 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
23661 }); | |
23662 | |
23663 test('weeks year starting saturday', function (assert) { | |
23664 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
23665 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
23666 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
23667 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
23668 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
23669 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
23670 }); | |
23671 | |
23672 test('weeks year starting sunday formatted', function (assert) { | |
23673 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52º', 'Jan 1 2012 should be week 52'); | |
23674 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1º', 'Jan 2 2012 should be week 1'); | |
23675 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1º', 'Jan 8 2012 should be week 1'); | |
23676 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2º', 'Jan 9 2012 should be week 2'); | |
23677 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2º', 'Jan 15 2012 should be week 2'); | |
23678 }); | |
23679 | |
23680 test('lenient ordinal parsing', function (assert) { | |
23681 var i, ordinalStr, testMoment; | |
23682 for (i = 1; i <= 31; ++i) { | |
23683 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
23684 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
23685 assert.equal(testMoment.year(), 2014, | |
23686 'lenient ordinal parsing ' + i + ' year check'); | |
23687 assert.equal(testMoment.month(), 0, | |
23688 'lenient ordinal parsing ' + i + ' month check'); | |
23689 assert.equal(testMoment.date(), i, | |
23690 'lenient ordinal parsing ' + i + ' date check'); | |
23691 } | |
23692 }); | |
23693 | |
23694 test('lenient ordinal parsing of number', function (assert) { | |
23695 var i, testMoment; | |
23696 for (i = 1; i <= 31; ++i) { | |
23697 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
23698 assert.equal(testMoment.year(), 2014, | |
23699 'lenient ordinal parsing of number ' + i + ' year check'); | |
23700 assert.equal(testMoment.month(), 0, | |
23701 'lenient ordinal parsing of number ' + i + ' month check'); | |
23702 assert.equal(testMoment.date(), i, | |
23703 'lenient ordinal parsing of number ' + i + ' date check'); | |
23704 } | |
23705 }); | |
23706 | |
23707 test('strict ordinal parsing', function (assert) { | |
23708 var i, ordinalStr, testMoment; | |
23709 for (i = 1; i <= 31; ++i) { | |
23710 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
23711 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
23712 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
23713 } | |
23714 }); | |
23715 | |
23716 })); | |
23717 | |
23718 (function (global, factory) { | |
23719 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
23720 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
23721 factory(global.moment) | |
23722 }(this, function (moment) { 'use strict'; | |
23723 | |
23724 /*global QUnit:false*/ | |
23725 | |
23726 var test = QUnit.test; | |
23727 | |
23728 function module (name, lifecycle) { | |
23729 QUnit.module(name, { | |
23730 setup : function () { | |
23731 moment.locale('en'); | |
23732 moment.createFromInputFallback = function () { | |
23733 throw new Error('input not handled by moment'); | |
23734 }; | |
23735 if (lifecycle && lifecycle.setup) { | |
23736 lifecycle.setup(); | |
23737 } | |
23738 }, | |
23739 teardown : function () { | |
23740 if (lifecycle && lifecycle.teardown) { | |
23741 lifecycle.teardown(); | |
23742 } | |
23743 } | |
23744 }); | |
23745 } | |
23746 | |
23747 function localeModule (name, lifecycle) { | |
23748 QUnit.module('locale:' + name, { | |
23749 setup : function () { | |
23750 moment.locale(name); | |
23751 moment.createFromInputFallback = function () { | |
23752 throw new Error('input not handled by moment'); | |
23753 }; | |
23754 if (lifecycle && lifecycle.setup) { | |
23755 lifecycle.setup(); | |
23756 } | |
23757 }, | |
23758 teardown : function () { | |
23759 moment.locale('en'); | |
23760 if (lifecycle && lifecycle.teardown) { | |
23761 lifecycle.teardown(); | |
23762 } | |
23763 } | |
23764 }); | |
23765 } | |
23766 | |
23767 localeModule('ro'); | |
23768 | |
23769 test('parse', function (assert) { | |
23770 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; | |
23771 function equalTest(input, mmm, i) { | |
23772 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
23773 } | |
23774 for (i = 0; i < 12; i++) { | |
23775 tests[i] = tests[i].split(' '); | |
23776 equalTest(tests[i][0], 'MMM', i); | |
23777 equalTest(tests[i][1], 'MMM', i); | |
23778 equalTest(tests[i][0], 'MMMM', i); | |
23779 equalTest(tests[i][1], 'MMMM', i); | |
23780 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
23781 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
23782 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
23783 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
23784 } | |
23785 }); | |
23786 | |
23787 test('format', function (assert) { | |
23788 var a = [ | |
23789 ['dddd, MMMM Do YYYY, h:mm:ss A', 'duminică, februarie 14 2010, 3:25:50 PM'], | |
23790 ['ddd, hA', 'Dum, 3PM'], | |
23791 ['M Mo MM MMMM MMM', '2 2 02 februarie febr.'], | |
23792 ['YYYY YY', '2010 10'], | |
23793 ['D Do DD', '14 14 14'], | |
23794 ['d do dddd ddd dd', '0 0 duminică Dum Du'], | |
23795 ['DDD DDDo DDDD', '45 45 045'], | |
23796 ['w wo ww', '7 7 07'], | |
23797 ['h hh', '3 03'], | |
23798 ['H HH', '15 15'], | |
23799 ['m mm', '25 25'], | |
23800 ['s ss', '50 50'], | |
23801 ['a A', 'pm PM'], | |
23802 ['[a] DDDo[a zi a anului]', 'a 45a zi a anului'], | |
23803 ['LTS', '15:25:50'], | |
23804 ['L', '14.02.2010'], | |
23805 ['LL', '14 februarie 2010'], | |
23806 ['LLL', '14 februarie 2010 15:25'], | |
23807 ['LLLL', 'duminică, 14 februarie 2010 15:25'], | |
23808 ['l', '14.2.2010'], | |
23809 ['ll', '14 febr. 2010'], | |
23810 ['lll', '14 febr. 2010 15:25'], | |
23811 ['llll', 'Dum, 14 febr. 2010 15:25'] | |
23812 ], | |
23813 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
23814 i; | |
23815 for (i = 0; i < a.length; i++) { | |
23816 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
23817 } | |
23818 }); | |
23819 | |
23820 test('format ordinal', function (assert) { | |
23821 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1'); | |
23822 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2'); | |
23823 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3'); | |
23824 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4'); | |
23825 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5'); | |
23826 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6'); | |
23827 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7'); | |
23828 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8'); | |
23829 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9'); | |
23830 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10'); | |
23831 | |
23832 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11'); | |
23833 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12'); | |
23834 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13'); | |
23835 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14'); | |
23836 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15'); | |
23837 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16'); | |
23838 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17'); | |
23839 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18'); | |
23840 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19'); | |
23841 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20'); | |
23842 | |
23843 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21'); | |
23844 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22'); | |
23845 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23'); | |
23846 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24'); | |
23847 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25'); | |
23848 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26'); | |
23849 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27'); | |
23850 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28'); | |
23851 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29'); | |
23852 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30'); | |
23853 | |
23854 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31'); | |
23855 }); | |
23856 | |
23857 test('format month', function (assert) { | |
23858 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; | |
23859 for (i = 0; i < expected.length; i++) { | |
23860 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
23861 } | |
23862 }); | |
23863 | |
23864 test('format week', function (assert) { | |
23865 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; | |
23866 for (i = 0; i < expected.length; i++) { | |
23867 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
23868 } | |
23869 }); | |
23870 | |
23871 test('from', function (assert) { | |
23872 var start = moment([2007, 1, 28]); | |
23873 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'câteva secunde', '44 seconds = a few seconds'); | |
23874 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'un minut', '45 seconds = a minute'); | |
23875 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'un minut', '89 seconds = a minute'); | |
23876 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minute', '90 seconds = 2 minutes'); | |
23877 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 de minute', '44 minutes = 44 minutes'); | |
23878 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'o oră', '45 minutes = an hour'); | |
23879 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'o oră', '89 minutes = an hour'); | |
23880 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ore', '90 minutes = 2 hours'); | |
23881 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ore', '5 hours = 5 hours'); | |
23882 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 de ore', '21 hours = 21 hours'); | |
23883 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'o zi', '22 hours = a day'); | |
23884 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'o zi', '35 hours = a day'); | |
23885 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 zile', '36 hours = 2 days'); | |
23886 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'o zi', '1 day = a day'); | |
23887 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 zile', '5 days = 5 days'); | |
23888 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 de zile', '25 days = 25 days'); | |
23889 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'o lună', '26 days = a month'); | |
23890 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'o lună', '30 days = a month'); | |
23891 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'o lună', '43 days = a month'); | |
23892 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 luni', '46 days = 2 months'); | |
23893 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 luni', '75 days = 2 months'); | |
23894 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 luni', '76 days = 3 months'); | |
23895 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'o lună', '1 month = a month'); | |
23896 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 luni', '5 months = 5 months'); | |
23897 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'un an', '345 days = a year'); | |
23898 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ani', '548 days = 2 years'); | |
23899 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'un an', '1 year = a year'); | |
23900 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ani', '5 years = 5 years'); | |
23901 assert.equal(start.from(moment([2007, 1, 28]).add({y: 19}), true), '19 ani', '19 years = 19 years'); | |
23902 assert.equal(start.from(moment([2007, 1, 28]).add({y: 20}), true), '20 de ani', '20 years = 20 years'); | |
23903 assert.equal(start.from(moment([2007, 1, 28]).add({y: 100}), true), '100 de ani', '100 years = 100 years'); | |
23904 assert.equal(start.from(moment([2007, 1, 28]).add({y: 101}), true), '101 ani', '101 years = 101 years'); | |
23905 assert.equal(start.from(moment([2007, 1, 28]).add({y: 119}), true), '119 ani', '119 years = 119 years'); | |
23906 assert.equal(start.from(moment([2007, 1, 28]).add({y: 120}), true), '120 de ani', '120 years = 120 years'); | |
23907 assert.equal(start.from(moment([2007, 1, 28]).add({y: 219}), true), '219 ani', '219 years = 219 years'); | |
23908 assert.equal(start.from(moment([2007, 1, 28]).add({y: 220}), true), '220 de ani', '220 years = 220 years'); | |
23909 }); | |
23910 | |
23911 test('suffix', function (assert) { | |
23912 assert.equal(moment(30000).from(0), 'peste câteva secunde', 'prefix'); | |
23913 assert.equal(moment(0).from(30000), 'câteva secunde în urmă', 'suffix'); | |
23914 }); | |
23915 | |
23916 test('now from now', function (assert) { | |
23917 assert.equal(moment().fromNow(), 'câteva secunde în urmă', 'now from now should display as in the past'); | |
23918 }); | |
23919 | |
23920 test('fromNow', function (assert) { | |
23921 assert.equal(moment().add({s: 30}).fromNow(), 'peste câteva secunde', 'in a few seconds'); | |
23922 assert.equal(moment().add({d: 5}).fromNow(), 'peste 5 zile', 'in 5 days'); | |
23923 }); | |
23924 | |
23925 test('calendar day', function (assert) { | |
23926 var a = moment().hours(2).minutes(0).seconds(0); | |
23927 | |
23928 assert.equal(moment(a).calendar(), 'azi la 2:00', 'today at the same time'); | |
23929 assert.equal(moment(a).add({m: 25}).calendar(), 'azi la 2:25', 'Now plus 25 min'); | |
23930 assert.equal(moment(a).add({h: 1}).calendar(), 'azi la 3:00', 'Now plus 1 hour'); | |
23931 assert.equal(moment(a).add({d: 1}).calendar(), 'mâine la 2:00', 'tomorrow at the same time'); | |
23932 assert.equal(moment(a).subtract({h: 1}).calendar(), 'azi la 1:00', 'Now minus 1 hour'); | |
23933 assert.equal(moment(a).subtract({d: 1}).calendar(), 'ieri la 2:00', 'yesterday at the same time'); | |
23934 }); | |
23935 | |
23936 test('calendar next week', function (assert) { | |
23937 var i, m; | |
23938 for (i = 2; i < 7; i++) { | |
23939 m = moment().add({d: i}); | |
23940 assert.equal(m.calendar(), m.format('dddd [la] LT'), 'Today + ' + i + ' days current time'); | |
23941 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
23942 assert.equal(m.calendar(), m.format('dddd [la] LT'), 'Today + ' + i + ' days beginning of day'); | |
23943 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
23944 assert.equal(m.calendar(), m.format('dddd [la] LT'), 'Today + ' + i + ' days end of day'); | |
23945 } | |
23946 }); | |
23947 | |
23948 test('calendar last week', function (assert) { | |
23949 var i, m; | |
23950 for (i = 2; i < 7; i++) { | |
23951 m = moment().subtract({d: i}); | |
23952 assert.equal(m.calendar(), m.format('[fosta] dddd [la] LT'), 'Today - ' + i + ' days current time'); | |
23953 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
23954 assert.equal(m.calendar(), m.format('[fosta] dddd [la] LT'), 'Today - ' + i + ' days beginning of day'); | |
23955 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
23956 assert.equal(m.calendar(), m.format('[fosta] dddd [la] LT'), 'Today - ' + i + ' days end of day'); | |
23957 } | |
23958 }); | |
23959 | |
23960 test('calendar all else', function (assert) { | |
23961 var weeksAgo = moment().subtract({w: 1}), | |
23962 weeksFromNow = moment().add({w: 1}); | |
23963 | |
23964 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
23965 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
23966 | |
23967 weeksAgo = moment().subtract({w: 2}); | |
23968 weeksFromNow = moment().add({w: 2}); | |
23969 | |
23970 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
23971 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
23972 }); | |
23973 | |
23974 test('weeks year starting sunday', function (assert) { | |
23975 assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1'); | |
23976 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
23977 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2'); | |
23978 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
23979 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3'); | |
23980 }); | |
23981 | |
23982 test('weeks year starting monday', function (assert) { | |
23983 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
23984 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
23985 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
23986 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
23987 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
23988 }); | |
23989 | |
23990 test('weeks year starting tuesday', function (assert) { | |
23991 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
23992 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
23993 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
23994 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
23995 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
23996 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
23997 }); | |
23998 | |
23999 test('weeks year starting wednesday', function (assert) { | |
24000 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
24001 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
24002 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
24003 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
24004 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
24005 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
24006 }); | |
24007 | |
24008 test('weeks year starting thursday', function (assert) { | |
24009 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
24010 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
24011 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
24012 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
24013 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
24014 assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3'); | |
24015 }); | |
24016 | |
24017 test('weeks year starting friday', function (assert) { | |
24018 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1'); | |
24019 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
24020 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1'); | |
24021 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2'); | |
24022 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2'); | |
24023 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3'); | |
24024 }); | |
24025 | |
24026 test('weeks year starting saturday', function (assert) { | |
24027 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1'); | |
24028 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
24029 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1'); | |
24030 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2'); | |
24031 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2'); | |
24032 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3'); | |
24033 }); | |
24034 | |
24035 test('weeks year starting sunday formatted', function (assert) { | |
24036 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1', 'Dec 26 2011 should be week 1'); | |
24037 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1'); | |
24038 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2', 'Jan 2 2012 should be week 2'); | |
24039 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2'); | |
24040 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3', 'Jan 9 2012 should be week 3'); | |
24041 }); | |
24042 | |
24043 test('lenient ordinal parsing', function (assert) { | |
24044 var i, ordinalStr, testMoment; | |
24045 for (i = 1; i <= 31; ++i) { | |
24046 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
24047 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
24048 assert.equal(testMoment.year(), 2014, | |
24049 'lenient ordinal parsing ' + i + ' year check'); | |
24050 assert.equal(testMoment.month(), 0, | |
24051 'lenient ordinal parsing ' + i + ' month check'); | |
24052 assert.equal(testMoment.date(), i, | |
24053 'lenient ordinal parsing ' + i + ' date check'); | |
24054 } | |
24055 }); | |
24056 | |
24057 test('lenient ordinal parsing of number', function (assert) { | |
24058 var i, testMoment; | |
24059 for (i = 1; i <= 31; ++i) { | |
24060 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
24061 assert.equal(testMoment.year(), 2014, | |
24062 'lenient ordinal parsing of number ' + i + ' year check'); | |
24063 assert.equal(testMoment.month(), 0, | |
24064 'lenient ordinal parsing of number ' + i + ' month check'); | |
24065 assert.equal(testMoment.date(), i, | |
24066 'lenient ordinal parsing of number ' + i + ' date check'); | |
24067 } | |
24068 }); | |
24069 | |
24070 test('strict ordinal parsing', function (assert) { | |
24071 var i, ordinalStr, testMoment; | |
24072 for (i = 1; i <= 31; ++i) { | |
24073 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
24074 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
24075 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
24076 } | |
24077 }); | |
24078 | |
24079 })); | |
24080 | |
24081 (function (global, factory) { | |
24082 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
24083 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
24084 factory(global.moment) | |
24085 }(this, function (moment) { 'use strict'; | |
24086 | |
24087 /*global QUnit:false*/ | |
24088 | |
24089 var test = QUnit.test; | |
24090 | |
24091 function module (name, lifecycle) { | |
24092 QUnit.module(name, { | |
24093 setup : function () { | |
24094 moment.locale('en'); | |
24095 moment.createFromInputFallback = function () { | |
24096 throw new Error('input not handled by moment'); | |
24097 }; | |
24098 if (lifecycle && lifecycle.setup) { | |
24099 lifecycle.setup(); | |
24100 } | |
24101 }, | |
24102 teardown : function () { | |
24103 if (lifecycle && lifecycle.teardown) { | |
24104 lifecycle.teardown(); | |
24105 } | |
24106 } | |
24107 }); | |
24108 } | |
24109 | |
24110 function localeModule (name, lifecycle) { | |
24111 QUnit.module('locale:' + name, { | |
24112 setup : function () { | |
24113 moment.locale(name); | |
24114 moment.createFromInputFallback = function () { | |
24115 throw new Error('input not handled by moment'); | |
24116 }; | |
24117 if (lifecycle && lifecycle.setup) { | |
24118 lifecycle.setup(); | |
24119 } | |
24120 }, | |
24121 teardown : function () { | |
24122 moment.locale('en'); | |
24123 if (lifecycle && lifecycle.teardown) { | |
24124 lifecycle.teardown(); | |
24125 } | |
24126 } | |
24127 }); | |
24128 } | |
24129 | |
24130 localeModule('ru'); | |
24131 | |
24132 test('parse', function (assert) { | |
24133 var tests = 'январь янв_февраль фев_март март_апрель апр_май май_июнь июнь_июль июль_август авг_сентябрь сен_октябрь окт_ноябрь ноя_декабрь дек'.split('_'), i; | |
24134 function equalTest(input, mmm, i) { | |
24135 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
24136 } | |
24137 for (i = 0; i < 12; i++) { | |
24138 tests[i] = tests[i].split(' '); | |
24139 equalTest(tests[i][0], 'MMM', i); | |
24140 equalTest(tests[i][1], 'MMM', i); | |
24141 equalTest(tests[i][0], 'MMMM', i); | |
24142 equalTest(tests[i][1], 'MMMM', i); | |
24143 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
24144 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
24145 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
24146 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
24147 } | |
24148 }); | |
24149 | |
24150 test('parse exceptional case', function (assert) { | |
24151 assert.equal(moment('11 мая 1989', ['DD MMMM YYYY']).format('DD-MM-YYYY'), '11-05-1989'); | |
24152 }); | |
24153 | |
24154 test('format', function (assert) { | |
24155 var a = [ | |
24156 ['dddd, Do MMMM YYYY, HH:mm:ss', 'воскресенье, 14-го февраля 2010, 15:25:50'], | |
24157 ['ddd, h A', 'вс, 3 дня'], | |
24158 ['M Mo MM MMMM MMM', '2 2-й 02 февраль фев'], | |
24159 ['YYYY YY', '2010 10'], | |
24160 ['D Do DD', '14 14-го 14'], | |
24161 ['d do dddd ddd dd', '0 0-й воскресенье вс вс'], | |
24162 ['DDD DDDo DDDD', '45 45-й 045'], | |
24163 ['w wo ww', '7 7-я 07'], | |
24164 ['h hh', '3 03'], | |
24165 ['H HH', '15 15'], | |
24166 ['m mm', '25 25'], | |
24167 ['s ss', '50 50'], | |
24168 ['a A', 'дня дня'], | |
24169 ['DDDo [день года]', '45-й день года'], | |
24170 ['LTS', '15:25:50'], | |
24171 ['L', '14.02.2010'], | |
24172 ['LL', '14 февраля 2010 г.'], | |
24173 ['LLL', '14 февраля 2010 г., 15:25'], | |
24174 ['LLLL', 'воскресенье, 14 февраля 2010 г., 15:25'], | |
24175 ['l', '14.2.2010'], | |
24176 ['ll', '14 фев 2010 г.'], | |
24177 ['lll', '14 фев 2010 г., 15:25'], | |
24178 ['llll', 'вс, 14 фев 2010 г., 15:25'] | |
24179 ], | |
24180 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
24181 i; | |
24182 for (i = 0; i < a.length; i++) { | |
24183 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
24184 } | |
24185 }); | |
24186 | |
24187 test('format meridiem', function (assert) { | |
24188 assert.equal(moment([2012, 11, 28, 0, 0]).format('A'), 'ночи', 'night'); | |
24189 assert.equal(moment([2012, 11, 28, 3, 59]).format('A'), 'ночи', 'night'); | |
24190 assert.equal(moment([2012, 11, 28, 4, 0]).format('A'), 'утра', 'morning'); | |
24191 assert.equal(moment([2012, 11, 28, 11, 59]).format('A'), 'утра', 'morning'); | |
24192 assert.equal(moment([2012, 11, 28, 12, 0]).format('A'), 'дня', 'afternoon'); | |
24193 assert.equal(moment([2012, 11, 28, 16, 59]).format('A'), 'дня', 'afternoon'); | |
24194 assert.equal(moment([2012, 11, 28, 17, 0]).format('A'), 'вечера', 'evening'); | |
24195 assert.equal(moment([2012, 11, 28, 23, 59]).format('A'), 'вечера', 'evening'); | |
24196 }); | |
24197 | |
24198 test('format ordinal', function (assert) { | |
24199 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-й', '1-й'); | |
24200 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-й', '2-й'); | |
24201 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-й', '3-й'); | |
24202 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-й', '4-й'); | |
24203 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-й', '5-й'); | |
24204 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-й', '6-й'); | |
24205 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-й', '7-й'); | |
24206 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-й', '8-й'); | |
24207 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-й', '9-й'); | |
24208 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-й', '10-й'); | |
24209 | |
24210 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-й', '11-й'); | |
24211 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-й', '12-й'); | |
24212 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-й', '13-й'); | |
24213 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-й', '14-й'); | |
24214 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-й', '15-й'); | |
24215 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-й', '16-й'); | |
24216 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-й', '17-й'); | |
24217 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-й', '18-й'); | |
24218 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-й', '19-й'); | |
24219 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-й', '20-й'); | |
24220 | |
24221 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-й', '21-й'); | |
24222 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-й', '22-й'); | |
24223 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-й', '23-й'); | |
24224 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-й', '24-й'); | |
24225 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-й', '25-й'); | |
24226 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-й', '26-й'); | |
24227 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-й', '27-й'); | |
24228 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-й', '28-й'); | |
24229 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-й', '29-й'); | |
24230 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-й', '30-й'); | |
24231 | |
24232 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-й', '31-й'); | |
24233 }); | |
24234 | |
24235 test('format month', function (assert) { | |
24236 var expected = 'январь янв_февраль фев_март март_апрель апр_май май_июнь июнь_июль июль_август авг_сентябрь сен_октябрь окт_ноябрь ноя_декабрь дек'.split('_'), i; | |
24237 for (i = 0; i < expected.length; i++) { | |
24238 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
24239 } | |
24240 }); | |
24241 | |
24242 test('format month case', function (assert) { | |
24243 var months = { | |
24244 'nominative': 'январь_февраль_март_апрель_май_июнь_июль_август_сентябрь_октябрь_ноябрь_декабрь'.split('_'), | |
24245 'accusative': 'января_февраля_марта_апреля_мая_июня_июля_августа_сентября_октября_ноября_декабря'.split('_') | |
24246 }, i; | |
24247 for (i = 0; i < 12; i++) { | |
24248 assert.equal(moment([2011, i, 1]).format('D MMMM'), '1 ' + months.accusative[i], '1 ' + months.accusative[i]); | |
24249 assert.equal(moment([2011, i, 1]).format('MMMM'), months.nominative[i], '1 ' + months.nominative[i]); | |
24250 } | |
24251 }); | |
24252 | |
24253 test('format month short case', function (assert) { | |
24254 var monthsShort = { | |
24255 'nominative': 'янв_фев_март_апр_май_июнь_июль_авг_сен_окт_ноя_дек'.split('_'), | |
24256 'accusative': 'янв_фев_мар_апр_мая_июня_июля_авг_сен_окт_ноя_дек'.split('_') | |
24257 }, i; | |
24258 for (i = 0; i < 12; i++) { | |
24259 assert.equal(moment([2011, i, 1]).format('D MMM'), '1 ' + monthsShort.accusative[i], '1 ' + monthsShort.accusative[i]); | |
24260 assert.equal(moment([2011, i, 1]).format('MMM'), monthsShort.nominative[i], '1 ' + monthsShort.nominative[i]); | |
24261 } | |
24262 }); | |
24263 | |
24264 test('format month case with escaped symbols', function (assert) { | |
24265 var months = { | |
24266 'nominative': 'январь_февраль_март_апрель_май_июнь_июль_август_сентябрь_октябрь_ноябрь_декабрь'.split('_'), | |
24267 'accusative': 'января_февраля_марта_апреля_мая_июня_июля_августа_сентября_октября_ноября_декабря'.split('_') | |
24268 }, i; | |
24269 for (i = 0; i < 12; i++) { | |
24270 assert.equal(moment([2013, i, 1]).format('D[] MMMM'), '1 ' + months.accusative[i], '1 ' + months.accusative[i]); | |
24271 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>'); | |
24272 assert.equal(moment([2013, i, 1]).format('D[-й день] MMMM'), '1-й день ' + months.accusative[i], '1-й день ' + months.accusative[i]); | |
24273 assert.equal(moment([2013, i, 1]).format('D, MMMM'), '1, ' + months.nominative[i], '1, ' + months.nominative[i]); | |
24274 } | |
24275 }); | |
24276 | |
24277 test('format month short case with escaped symbols', function (assert) { | |
24278 var monthsShort = { | |
24279 'nominative': 'янв_фев_март_апр_май_июнь_июль_авг_сен_окт_ноя_дек'.split('_'), | |
24280 'accusative': 'янв_фев_мар_апр_мая_июня_июля_авг_сен_окт_ноя_дек'.split('_') | |
24281 }, i; | |
24282 for (i = 0; i < 12; i++) { | |
24283 assert.equal(moment([2013, i, 1]).format('D[] MMM'), '1 ' + monthsShort.accusative[i], '1 ' + monthsShort.accusative[i]); | |
24284 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>'); | |
24285 assert.equal(moment([2013, i, 1]).format('D[-й день] MMM'), '1-й день ' + monthsShort.accusative[i], '1-й день ' + monthsShort.accusative[i]); | |
24286 assert.equal(moment([2013, i, 1]).format('D, MMM'), '1, ' + monthsShort.nominative[i], '1, ' + monthsShort.nominative[i]); | |
24287 } | |
24288 }); | |
24289 | |
24290 test('format week', function (assert) { | |
24291 var expected = 'воскресенье вс вс_понедельник пн пн_вторник вт вт_среда ср ср_четверг чт чт_пятница пт пт_суббота сб сб'.split('_'), i; | |
24292 for (i = 0; i < expected.length; i++) { | |
24293 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
24294 } | |
24295 }); | |
24296 | |
24297 test('from', function (assert) { | |
24298 var start = moment([2007, 1, 28]); | |
24299 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'несколько секунд', '44 seconds = seconds'); | |
24300 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'минута', '45 seconds = a minute'); | |
24301 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'минута', '89 seconds = a minute'); | |
24302 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 минуты', '90 seconds = 2 minutes'); | |
24303 assert.equal(start.from(moment([2007, 1, 28]).add({m: 31}), true), '31 минута', '31 minutes = 31 minutes'); | |
24304 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 минуты', '44 minutes = 44 minutes'); | |
24305 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'час', '45 minutes = an hour'); | |
24306 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'час', '89 minutes = an hour'); | |
24307 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 часа', '90 minutes = 2 hours'); | |
24308 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 часов', '5 hours = 5 hours'); | |
24309 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 час', '21 hours = 21 hours'); | |
24310 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'день', '22 hours = a day'); | |
24311 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'день', '35 hours = a day'); | |
24312 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 дня', '36 hours = 2 days'); | |
24313 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'день', '1 day = a day'); | |
24314 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 дней', '5 days = 5 days'); | |
24315 assert.equal(start.from(moment([2007, 1, 28]).add({d: 11}), true), '11 дней', '11 days = 11 days'); | |
24316 assert.equal(start.from(moment([2007, 1, 28]).add({d: 21}), true), '21 день', '21 days = 21 days'); | |
24317 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 дней', '25 days = 25 days'); | |
24318 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'месяц', '26 days = a month'); | |
24319 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'месяц', '30 days = a month'); | |
24320 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'месяц', '43 days = a month'); | |
24321 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 месяца', '46 days = 2 months'); | |
24322 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 месяца', '75 days = 2 months'); | |
24323 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 месяца', '76 days = 3 months'); | |
24324 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'месяц', '1 month = a month'); | |
24325 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 месяцев', '5 months = 5 months'); | |
24326 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'год', '345 days = a year'); | |
24327 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 года', '548 days = 2 years'); | |
24328 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'год', '1 year = a year'); | |
24329 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 лет', '5 years = 5 years'); | |
24330 }); | |
24331 | |
24332 test('suffix', function (assert) { | |
24333 assert.equal(moment(30000).from(0), 'через несколько секунд', 'prefix'); | |
24334 assert.equal(moment(0).from(30000), 'несколько секунд назад', 'suffix'); | |
24335 }); | |
24336 | |
24337 test('fromNow', function (assert) { | |
24338 assert.equal(moment().add({s: 30}).fromNow(), 'через несколько секунд', 'in seconds'); | |
24339 assert.equal(moment().add({d: 5}).fromNow(), 'через 5 дней', 'in 5 days'); | |
24340 assert.equal(moment().add({m: 31}).fromNow(), 'через 31 минуту', 'in 31 minutes = in 31 minutes'); | |
24341 assert.equal(moment().subtract({m: 31}).fromNow(), '31 минуту назад', '31 minutes ago = 31 minutes ago'); | |
24342 }); | |
24343 | |
24344 test('calendar day', function (assert) { | |
24345 var a = moment().hours(2).minutes(0).seconds(0); | |
24346 | |
24347 assert.equal(moment(a).calendar(), 'Сегодня в 02:00', 'today at the same time'); | |
24348 assert.equal(moment(a).add({m: 25}).calendar(), 'Сегодня в 02:25', 'Now plus 25 min'); | |
24349 assert.equal(moment(a).add({h: 1}).calendar(), 'Сегодня в 03:00', 'Now plus 1 hour'); | |
24350 assert.equal(moment(a).add({d: 1}).calendar(), 'Завтра в 02:00', 'tomorrow at the same time'); | |
24351 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Сегодня в 01:00', 'Now minus 1 hour'); | |
24352 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Вчера в 02:00', 'yesterday at the same time'); | |
24353 }); | |
24354 | |
24355 test('calendar next week', function (assert) { | |
24356 var i, m; | |
24357 function makeFormat(d) { | |
24358 return d.day() === 2 ? '[Во] dddd [в] LT' : '[В] dddd [в] LT'; | |
24359 } | |
24360 | |
24361 for (i = 2; i < 7; i++) { | |
24362 m = moment().add({d: i}); | |
24363 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time'); | |
24364 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
24365 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day'); | |
24366 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
24367 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day'); | |
24368 } | |
24369 }); | |
24370 | |
24371 test('calendar last week', function (assert) { | |
24372 var i, m, now; | |
24373 | |
24374 function makeFormatLast(d) { | |
24375 switch (d.day()) { | |
24376 case 0: | |
24377 return '[В прошлое] dddd [в] LT'; | |
24378 case 1: | |
24379 case 2: | |
24380 case 4: | |
24381 return '[В прошлый] dddd [в] LT'; | |
24382 case 3: | |
24383 case 5: | |
24384 case 6: | |
24385 return '[В прошлую] dddd [в] LT'; | |
24386 } | |
24387 } | |
24388 | |
24389 function makeFormatThis(d) { | |
24390 switch (d.day()) { | |
24391 case 2: | |
24392 return '[Во] dddd [в] LT'; | |
24393 case 0: | |
24394 case 1: | |
24395 case 3: | |
24396 case 4: | |
24397 case 5: | |
24398 case 6: | |
24399 return '[В] dddd [в] LT'; | |
24400 } | |
24401 } | |
24402 | |
24403 now = moment().startOf('week'); | |
24404 for (i = 2; i < 7; i++) { | |
24405 m = moment(now).subtract({d: i}); | |
24406 assert.equal(m.calendar(now), m.format(makeFormatLast(m)), 'Today - ' + i + ' days current time'); | |
24407 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
24408 assert.equal(m.calendar(now), m.format(makeFormatLast(m)), 'Today - ' + i + ' days beginning of day'); | |
24409 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
24410 assert.equal(m.calendar(now), m.format(makeFormatLast(m)), 'Today - ' + i + ' days end of day'); | |
24411 } | |
24412 | |
24413 now = moment().endOf('week'); | |
24414 for (i = 2; i < 7; i++) { | |
24415 m = moment(now).subtract({d: i}); | |
24416 assert.equal(m.calendar(now), m.format(makeFormatThis(m)), 'Today - ' + i + ' days current time'); | |
24417 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
24418 assert.equal(m.calendar(now), m.format(makeFormatThis(m)), 'Today - ' + i + ' days beginning of day'); | |
24419 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
24420 assert.equal(m.calendar(now), m.format(makeFormatThis(m)), 'Today - ' + i + ' days end of day'); | |
24421 } | |
24422 }); | |
24423 | |
24424 test('calendar all else', function (assert) { | |
24425 var weeksAgo = moment().subtract({w: 1}), | |
24426 weeksFromNow = moment().add({w: 1}); | |
24427 | |
24428 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
24429 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
24430 | |
24431 weeksAgo = moment().subtract({w: 2}); | |
24432 weeksFromNow = moment().add({w: 2}); | |
24433 | |
24434 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
24435 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
24436 }); | |
24437 | |
24438 test('weeks year starting sunday', function (assert) { | |
24439 assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1'); | |
24440 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
24441 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2'); | |
24442 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
24443 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3'); | |
24444 }); | |
24445 | |
24446 test('weeks year starting monday', function (assert) { | |
24447 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
24448 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
24449 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
24450 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
24451 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
24452 }); | |
24453 | |
24454 test('weeks year starting tuesday', function (assert) { | |
24455 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
24456 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
24457 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
24458 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
24459 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
24460 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
24461 }); | |
24462 | |
24463 test('weeks year starting wednesday', function (assert) { | |
24464 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
24465 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
24466 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
24467 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
24468 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
24469 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
24470 }); | |
24471 | |
24472 test('weeks year starting thursday', function (assert) { | |
24473 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
24474 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
24475 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
24476 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
24477 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
24478 assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3'); | |
24479 }); | |
24480 | |
24481 test('weeks year starting friday', function (assert) { | |
24482 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1'); | |
24483 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
24484 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1'); | |
24485 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2'); | |
24486 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2'); | |
24487 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3'); | |
24488 }); | |
24489 | |
24490 test('weeks year starting saturday', function (assert) { | |
24491 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1'); | |
24492 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
24493 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1'); | |
24494 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2'); | |
24495 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2'); | |
24496 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3'); | |
24497 }); | |
24498 | |
24499 test('weeks year starting sunday formatted', function (assert) { | |
24500 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-я', 'Dec 26 2011 should be week 1'); | |
24501 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-я', 'Jan 1 2012 should be week 1'); | |
24502 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-я', 'Jan 2 2012 should be week 2'); | |
24503 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-я', 'Jan 8 2012 should be week 2'); | |
24504 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-я', 'Jan 9 2012 should be week 3'); | |
24505 }); | |
24506 | |
24507 test('lenient ordinal parsing', function (assert) { | |
24508 var i, ordinalStr, testMoment; | |
24509 for (i = 1; i <= 31; ++i) { | |
24510 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
24511 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
24512 assert.equal(testMoment.year(), 2014, | |
24513 'lenient ordinal parsing ' + i + ' year check'); | |
24514 assert.equal(testMoment.month(), 0, | |
24515 'lenient ordinal parsing ' + i + ' month check'); | |
24516 assert.equal(testMoment.date(), i, | |
24517 'lenient ordinal parsing ' + i + ' date check'); | |
24518 } | |
24519 }); | |
24520 | |
24521 test('lenient ordinal parsing of number', function (assert) { | |
24522 var i, testMoment; | |
24523 for (i = 1; i <= 31; ++i) { | |
24524 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
24525 assert.equal(testMoment.year(), 2014, | |
24526 'lenient ordinal parsing of number ' + i + ' year check'); | |
24527 assert.equal(testMoment.month(), 0, | |
24528 'lenient ordinal parsing of number ' + i + ' month check'); | |
24529 assert.equal(testMoment.date(), i, | |
24530 'lenient ordinal parsing of number ' + i + ' date check'); | |
24531 } | |
24532 }); | |
24533 | |
24534 test('strict ordinal parsing', function (assert) { | |
24535 var i, ordinalStr, testMoment; | |
24536 for (i = 1; i <= 31; ++i) { | |
24537 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
24538 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
24539 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
24540 } | |
24541 }); | |
24542 | |
24543 })); | |
24544 | |
24545 (function (global, factory) { | |
24546 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
24547 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
24548 factory(global.moment) | |
24549 }(this, function (moment) { 'use strict'; | |
24550 | |
24551 /*global QUnit:false*/ | |
24552 | |
24553 var test = QUnit.test; | |
24554 | |
24555 function module (name, lifecycle) { | |
24556 QUnit.module(name, { | |
24557 setup : function () { | |
24558 moment.locale('en'); | |
24559 moment.createFromInputFallback = function () { | |
24560 throw new Error('input not handled by moment'); | |
24561 }; | |
24562 if (lifecycle && lifecycle.setup) { | |
24563 lifecycle.setup(); | |
24564 } | |
24565 }, | |
24566 teardown : function () { | |
24567 if (lifecycle && lifecycle.teardown) { | |
24568 lifecycle.teardown(); | |
24569 } | |
24570 } | |
24571 }); | |
24572 } | |
24573 | |
24574 function localeModule (name, lifecycle) { | |
24575 QUnit.module('locale:' + name, { | |
24576 setup : function () { | |
24577 moment.locale(name); | |
24578 moment.createFromInputFallback = function () { | |
24579 throw new Error('input not handled by moment'); | |
24580 }; | |
24581 if (lifecycle && lifecycle.setup) { | |
24582 lifecycle.setup(); | |
24583 } | |
24584 }, | |
24585 teardown : function () { | |
24586 moment.locale('en'); | |
24587 if (lifecycle && lifecycle.teardown) { | |
24588 lifecycle.teardown(); | |
24589 } | |
24590 } | |
24591 }); | |
24592 } | |
24593 | |
24594 localeModule('si'); | |
24595 | |
24596 /*jshint -W100*/ | |
24597 test('parse', function (assert) { | |
24598 var tests = 'ජනවාරි ජන_පෙබරවාරි පෙබ_මාර්තු මාර්_අප්රේල් අප්_මැයි මැයි_ජූනි ජූනි_ජූලි ජූලි_අගෝස්තු අගෝ_සැප්තැම්බර් සැප්_ඔක්තෝබර් ඔක්_නොවැම්බර් නොවැ_දෙසැම්බර් දෙසැ'.split('_'), i; | |
24599 function equalTest(input, mmm, i) { | |
24600 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
24601 } | |
24602 for (i = 0; i < 12; i++) { | |
24603 tests[i] = tests[i].split(' '); | |
24604 equalTest(tests[i][0], 'MMM', i); | |
24605 equalTest(tests[i][1], 'MMM', i); | |
24606 equalTest(tests[i][0], 'MMMM', i); | |
24607 equalTest(tests[i][1], 'MMMM', i); | |
24608 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
24609 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
24610 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
24611 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
24612 } | |
24613 }); | |
24614 | |
24615 test('format', function (assert) { | |
24616 var a = [ | |
24617 ['YYYY MMMM Do dddd, a h:mm:ss', '2010 පෙබරවාරි 14 වැනි ඉරිදා, ප.ව. 3:25:50'], | |
24618 ['YYYY MMMM Do dddd, a h:mm:ss', '2010 පෙබරවාරි 14 වැනි ඉරිදා, ප.ව. 3:25:50'], | |
24619 ['ddd, A h', 'ඉරි, පස් වරු 3'], | |
24620 ['M Mo MM MMMM MMM', '2 2 වැනි 02 පෙබරවාරි පෙබ'], | |
24621 ['YYYY YY', '2010 10'], | |
24622 ['D Do DD', '14 14 වැනි 14'], | |
24623 ['d do dddd ddd dd', '0 0 වැනි ඉරිදා ඉරි ඉ'], | |
24624 ['DDD DDDo DDDD', '45 45 වැනි 045'], | |
24625 ['h hh', '3 03'], | |
24626 ['H HH', '15 15'], | |
24627 ['m mm', '25 25'], | |
24628 ['s ss', '50 50'], | |
24629 ['a A', 'ප.ව. පස් වරු'], | |
24630 ['[වසරේ] DDDo [දිනය]', 'වසරේ 45 වැනි දිනය'], | |
24631 ['LTS', 'ප.ව. 3:25:50'], | |
24632 ['LT', 'ප.ව. 3:25'], | |
24633 ['L', '2010/02/14'], | |
24634 ['LL', '2010 පෙබරවාරි 14'], | |
24635 ['LLL', '2010 පෙබරවාරි 14, ප.ව. 3:25'], | |
24636 ['LLLL', '2010 පෙබරවාරි 14 වැනි ඉරිදා, ප.ව. 3:25:50'], | |
24637 ['l', '2010/2/14'], | |
24638 ['ll', '2010 පෙබ 14'], | |
24639 ['lll', '2010 පෙබ 14, ප.ව. 3:25'], | |
24640 ['llll', '2010 පෙබ 14 වැනි ඉරි, ප.ව. 3:25:50'] | |
24641 ], | |
24642 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
24643 i; | |
24644 for (i = 0; i < a.length; i++) { | |
24645 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
24646 } | |
24647 }); | |
24648 | |
24649 test('format ordinal', function (assert) { | |
24650 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1 වැනි', '1 වැනි'); | |
24651 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2 වැනි', '2 වැනි'); | |
24652 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3 වැනි', '3 වැනි'); | |
24653 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4 වැනි', '4 වැනි'); | |
24654 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5 වැනි', '5 වැනි'); | |
24655 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6 වැනි', '6 වැනි'); | |
24656 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7 වැනි', '7 වැනි'); | |
24657 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8 වැනි', '8 වැනි'); | |
24658 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9 වැනි', '9 වැනි'); | |
24659 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10 වැනි', '10 වැනි'); | |
24660 | |
24661 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11 වැනි', '11 වැනි'); | |
24662 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12 වැනි', '12 වැනි'); | |
24663 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13 වැනි', '13 වැනි'); | |
24664 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14 වැනි', '14 වැනි'); | |
24665 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15 වැනි', '15 වැනි'); | |
24666 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16 වැනි', '16 වැනි'); | |
24667 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17 වැනි', '17 වැනි'); | |
24668 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18 වැනි', '18 වැනි'); | |
24669 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19 වැනි', '19 වැනි'); | |
24670 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20 වැනි', '20 වැනි'); | |
24671 | |
24672 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21 වැනි', '21 වැනි'); | |
24673 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22 වැනි', '22 වැනි'); | |
24674 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23 වැනි', '23 වැනි'); | |
24675 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24 වැනි', '24 වැනි'); | |
24676 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25 වැනි', '25 වැනි'); | |
24677 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26 වැනි', '26 වැනි'); | |
24678 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27 වැනි', '27 වැනි'); | |
24679 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28 වැනි', '28 වැනි'); | |
24680 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29 වැනි', '29 වැනි'); | |
24681 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30 වැනි', '30 වැනි'); | |
24682 | |
24683 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31 වැනි', '31 වැනි'); | |
24684 }); | |
24685 | |
24686 test('format month', function (assert) { | |
24687 var expected = 'ජනවාරි ජන_පෙබරවාරි පෙබ_මාර්තු මාර්_අප්රේල් අප්_මැයි මැයි_ජූනි ජූනි_ජූලි ජූලි_අගෝස්තු අගෝ_සැප්තැම්බර් සැප්_ඔක්තෝබර් ඔක්_නොවැම්බර් නොවැ_දෙසැම්බර් දෙසැ'.split('_'), i; | |
24688 for (i = 0; i < expected.length; i++) { | |
24689 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
24690 } | |
24691 }); | |
24692 | |
24693 test('format week', function (assert) { | |
24694 var expected = 'ඉරිදා ඉරි ඉ_සඳුදා සඳු ස_අඟහරුවාදා අඟ අ_බදාදා බදා බ_බ්රහස්පතින්දා බ්රහ බ්ර_සිකුරාදා සිකු සි_සෙනසුරාදා සෙන සෙ'.split('_'), i; | |
24695 for (i = 0; i < expected.length; i++) { | |
24696 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
24697 } | |
24698 }); | |
24699 | |
24700 test('from', function (assert) { | |
24701 var start = moment([2007, 1, 28]); | |
24702 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'තත්පර කිහිපය', '44 seconds = a few seconds'); | |
24703 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'මිනිත්තුව', '45 seconds = a minute'); | |
24704 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'මිනිත්තුව', '89 seconds = a minute'); | |
24705 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), 'මිනිත්තු 2', '90 seconds = 2 minutes'); | |
24706 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), 'මිනිත්තු 44', '44 minutes = 44 minutes'); | |
24707 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'පැය', '45 minutes = an hour'); | |
24708 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'පැය', '89 minutes = an hour'); | |
24709 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), 'පැය 2', '90 minutes = 2 hours'); | |
24710 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), 'පැය 5', '5 hours = 5 hours'); | |
24711 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), 'පැය 21', '21 hours = 21 hours'); | |
24712 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'දිනය', '22 hours = a day'); | |
24713 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'දිනය', '35 hours = a day'); | |
24714 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), 'දින 2', '36 hours = 2 days'); | |
24715 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'දිනය', '1 day = a day'); | |
24716 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), 'දින 5', '5 days = 5 days'); | |
24717 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), 'දින 25', '25 days = 25 days'); | |
24718 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'මාසය', '26 days = a month'); | |
24719 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'මාසය', '30 days = a month'); | |
24720 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'මාසය', '43 days = a month'); | |
24721 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), 'මාස 2', '46 days = 2 months'); | |
24722 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), 'මාස 2', '75 days = 2 months'); | |
24723 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), 'මාස 3', '76 days = 3 months'); | |
24724 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'මාසය', '1 month = a month'); | |
24725 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), 'මාස 5', '5 months = 5 months'); | |
24726 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'වසර', '345 days = a year'); | |
24727 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), 'වසර 2', '548 days = 2 years'); | |
24728 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'වසර', '1 year = a year'); | |
24729 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), 'වසර 5', '5 years = 5 years'); | |
24730 }); | |
24731 | |
24732 test('suffix', function (assert) { | |
24733 assert.equal(moment(30000).from(0), 'තත්පර කිහිපයකින්', 'prefix'); | |
24734 assert.equal(moment(0).from(30000), 'තත්පර කිහිපයකට පෙර', 'suffix'); | |
24735 }); | |
24736 | |
24737 test('now from now', function (assert) { | |
24738 assert.equal(moment().fromNow(), 'තත්පර කිහිපයකට පෙර', 'now from now should display as in the past'); | |
24739 }); | |
24740 | |
24741 test('fromNow', function (assert) { | |
24742 assert.equal(moment().add({s: 30}).fromNow(), 'තත්පර කිහිපයකින්', 'in a few seconds'); | |
24743 assert.equal(moment().add({d: 5}).fromNow(), 'දින 5කින්', 'in 5 days'); | |
24744 }); | |
24745 | |
24746 test('calendar day', function (assert) { | |
24747 var a = moment().hours(2).minutes(0).seconds(0); | |
24748 | |
24749 assert.equal(moment(a).calendar(), 'අද පෙ.ව. 2:00ට', 'today at the same time'); | |
24750 assert.equal(moment(a).add({m: 25}).calendar(), 'අද පෙ.ව. 2:25ට', 'Now plus 25 min'); | |
24751 assert.equal(moment(a).add({h: 1}).calendar(), 'අද පෙ.ව. 3:00ට', 'Now plus 1 hour'); | |
24752 assert.equal(moment(a).add({d: 1}).calendar(), 'හෙට පෙ.ව. 2:00ට', 'tomorrow at the same time'); | |
24753 assert.equal(moment(a).subtract({h: 1}).calendar(), 'අද පෙ.ව. 1:00ට', 'Now minus 1 hour'); | |
24754 assert.equal(moment(a).subtract({d: 1}).calendar(), 'ඊයේ පෙ.ව. 2:00ට', 'yesterday at the same time'); | |
24755 }); | |
24756 | |
24757 test('calendar next week', function (assert) { | |
24758 var i, m; | |
24759 for (i = 2; i < 7; i++) { | |
24760 m = moment().add({d: i}); | |
24761 assert.equal(m.calendar(), m.format('dddd LT[ට]'), 'Today + ' + i + ' days current time'); | |
24762 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
24763 assert.equal(m.calendar(), m.format('dddd LT[ට]'), 'Today + ' + i + ' days beginning of day'); | |
24764 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
24765 assert.equal(m.calendar(), m.format('dddd LT[ට]'), 'Today + ' + i + ' days end of day'); | |
24766 } | |
24767 }); | |
24768 | |
24769 test('calendar last week', function (assert) { | |
24770 var i, m; | |
24771 | |
24772 for (i = 2; i < 7; i++) { | |
24773 m = moment().subtract({d: i}); | |
24774 assert.equal(m.calendar(), m.format('[පසුගිය] dddd LT[ට]'), 'Today - ' + i + ' days current time'); | |
24775 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
24776 assert.equal(m.calendar(), m.format('[පසුගිය] dddd LT[ට]'), 'Today - ' + i + ' days beginning of day'); | |
24777 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
24778 assert.equal(m.calendar(), m.format('[පසුගිය] dddd LT[ට]'), 'Today - ' + i + ' days end of day'); | |
24779 } | |
24780 }); | |
24781 | |
24782 test('calendar all else', function (assert) { | |
24783 var weeksAgo = moment().subtract({w: 1}), | |
24784 weeksFromNow = moment().add({w: 1}); | |
24785 | |
24786 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
24787 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
24788 | |
24789 weeksAgo = moment().subtract({w: 2}); | |
24790 weeksFromNow = moment().add({w: 2}); | |
24791 | |
24792 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
24793 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
24794 }); | |
24795 | |
24796 test('lenient ordinal parsing', function (assert) { | |
24797 var i, ordinalStr, testMoment; | |
24798 for (i = 1; i <= 31; ++i) { | |
24799 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
24800 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
24801 assert.equal(testMoment.year(), 2014, | |
24802 'lenient ordinal parsing ' + i + ' year check'); | |
24803 assert.equal(testMoment.month(), 0, | |
24804 'lenient ordinal parsing ' + i + ' month check'); | |
24805 assert.equal(testMoment.date(), i, | |
24806 'lenient ordinal parsing ' + i + ' date check'); | |
24807 } | |
24808 }); | |
24809 | |
24810 test('lenient ordinal parsing of number', function (assert) { | |
24811 var i, testMoment; | |
24812 for (i = 1; i <= 31; ++i) { | |
24813 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
24814 assert.equal(testMoment.year(), 2014, | |
24815 'lenient ordinal parsing of number ' + i + ' year check'); | |
24816 assert.equal(testMoment.month(), 0, | |
24817 'lenient ordinal parsing of number ' + i + ' month check'); | |
24818 assert.equal(testMoment.date(), i, | |
24819 'lenient ordinal parsing of number ' + i + ' date check'); | |
24820 } | |
24821 }); | |
24822 | |
24823 test('strict ordinal parsing', function (assert) { | |
24824 var i, ordinalStr, testMoment; | |
24825 for (i = 1; i <= 31; ++i) { | |
24826 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
24827 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
24828 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
24829 } | |
24830 }); | |
24831 | |
24832 })); | |
24833 | |
24834 (function (global, factory) { | |
24835 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
24836 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
24837 factory(global.moment) | |
24838 }(this, function (moment) { 'use strict'; | |
24839 | |
24840 /*global QUnit:false*/ | |
24841 | |
24842 var test = QUnit.test; | |
24843 | |
24844 function module (name, lifecycle) { | |
24845 QUnit.module(name, { | |
24846 setup : function () { | |
24847 moment.locale('en'); | |
24848 moment.createFromInputFallback = function () { | |
24849 throw new Error('input not handled by moment'); | |
24850 }; | |
24851 if (lifecycle && lifecycle.setup) { | |
24852 lifecycle.setup(); | |
24853 } | |
24854 }, | |
24855 teardown : function () { | |
24856 if (lifecycle && lifecycle.teardown) { | |
24857 lifecycle.teardown(); | |
24858 } | |
24859 } | |
24860 }); | |
24861 } | |
24862 | |
24863 function localeModule (name, lifecycle) { | |
24864 QUnit.module('locale:' + name, { | |
24865 setup : function () { | |
24866 moment.locale(name); | |
24867 moment.createFromInputFallback = function () { | |
24868 throw new Error('input not handled by moment'); | |
24869 }; | |
24870 if (lifecycle && lifecycle.setup) { | |
24871 lifecycle.setup(); | |
24872 } | |
24873 }, | |
24874 teardown : function () { | |
24875 moment.locale('en'); | |
24876 if (lifecycle && lifecycle.teardown) { | |
24877 lifecycle.teardown(); | |
24878 } | |
24879 } | |
24880 }); | |
24881 } | |
24882 | |
24883 localeModule('sk'); | |
24884 | |
24885 test('parse', function (assert) { | |
24886 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; | |
24887 function equalTest(input, mmm, monthIndex) { | |
24888 assert.equal(moment(input, mmm).month(), monthIndex, input + ' should be month ' + (monthIndex + 1)); | |
24889 } | |
24890 for (i = 0; i < 12; i++) { | |
24891 tests[i] = tests[i].split(' '); | |
24892 equalTest(tests[i][0], 'MMM', i); | |
24893 equalTest(tests[i][1], 'MMM', i); | |
24894 equalTest(tests[i][0], 'MMMM', i); | |
24895 equalTest(tests[i][1], 'MMMM', i); | |
24896 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
24897 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
24898 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
24899 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
24900 } | |
24901 }); | |
24902 | |
24903 test('format', function (assert) { | |
24904 var a = [ | |
24905 ['dddd, MMMM Do YYYY, h:mm:ss', 'nedeľa, február 14. 2010, 3:25:50'], | |
24906 ['ddd, h', 'ne, 3'], | |
24907 ['M Mo MM MMMM MMM', '2 2. 02 február feb'], | |
24908 ['YYYY YY', '2010 10'], | |
24909 ['D Do DD', '14 14. 14'], | |
24910 ['d do dddd ddd dd', '0 0. nedeľa ne ne'], | |
24911 ['DDD DDDo DDDD', '45 45. 045'], | |
24912 ['w wo ww', '6 6. 06'], | |
24913 ['h hh', '3 03'], | |
24914 ['H HH', '15 15'], | |
24915 ['m mm', '25 25'], | |
24916 ['s ss', '50 50'], | |
24917 ['a A', 'pm PM'], | |
24918 ['DDDo [deň v roku]', '45. deň v roku'], | |
24919 ['LTS', '15:25:50'], | |
24920 ['L', '14.02.2010'], | |
24921 ['LL', '14. február 2010'], | |
24922 ['LLL', '14. február 2010 15:25'], | |
24923 ['LLLL', 'nedeľa 14. február 2010 15:25'], | |
24924 ['l', '14.2.2010'], | |
24925 ['ll', '14. feb 2010'], | |
24926 ['lll', '14. feb 2010 15:25'], | |
24927 ['llll', 'ne 14. feb 2010 15:25'] | |
24928 ], | |
24929 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
24930 i; | |
24931 for (i = 0; i < a.length; i++) { | |
24932 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
24933 } | |
24934 }); | |
24935 | |
24936 test('format ordinal', function (assert) { | |
24937 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.'); | |
24938 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.'); | |
24939 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.'); | |
24940 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.'); | |
24941 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.'); | |
24942 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.'); | |
24943 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.'); | |
24944 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.'); | |
24945 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.'); | |
24946 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.'); | |
24947 | |
24948 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.'); | |
24949 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.'); | |
24950 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.'); | |
24951 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.'); | |
24952 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.'); | |
24953 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.'); | |
24954 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.'); | |
24955 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.'); | |
24956 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.'); | |
24957 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.'); | |
24958 | |
24959 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.'); | |
24960 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.'); | |
24961 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.'); | |
24962 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.'); | |
24963 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.'); | |
24964 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.'); | |
24965 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.'); | |
24966 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.'); | |
24967 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.'); | |
24968 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.'); | |
24969 | |
24970 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.'); | |
24971 }); | |
24972 | |
24973 test('format month', function (assert) { | |
24974 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; | |
24975 for (i = 0; i < expected.length; i++) { | |
24976 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
24977 } | |
24978 }); | |
24979 | |
24980 test('format week', function (assert) { | |
24981 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; | |
24982 for (i = 0; i < expected.length; i++) { | |
24983 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
24984 } | |
24985 }); | |
24986 | |
24987 test('from', function (assert) { | |
24988 var start = moment([2007, 1, 28]); | |
24989 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'pár sekúnd', '44 seconds = a few seconds'); | |
24990 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minúta', '45 seconds = a minute'); | |
24991 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minúta', '89 seconds = a minute'); | |
24992 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minúty', '90 seconds = 2 minutes'); | |
24993 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minút', '44 minutes = 44 minutes'); | |
24994 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'hodina', '45 minutes = an hour'); | |
24995 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'hodina', '89 minutes = an hour'); | |
24996 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 hodiny', '90 minutes = 2 hours'); | |
24997 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 hodín', '5 hours = 5 hours'); | |
24998 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 hodín', '21 hours = 21 hours'); | |
24999 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'deň', '22 hours = a day'); | |
25000 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'deň', '35 hours = a day'); | |
25001 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dni', '36 hours = 2 days'); | |
25002 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'deň', '1 day = a day'); | |
25003 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dní', '5 days = 5 days'); | |
25004 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dní', '25 days = 25 days'); | |
25005 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mesiac', '26 days = a month'); | |
25006 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mesiac', '30 days = a month'); | |
25007 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mesiac', '43 days = a month'); | |
25008 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mesiace', '46 days = 2 months'); | |
25009 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mesiace', '75 days = 2 months'); | |
25010 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mesiace', '76 days = 3 months'); | |
25011 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mesiac', '1 month = a month'); | |
25012 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mesiacov', '5 months = 5 months'); | |
25013 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'rok', '345 days = a year'); | |
25014 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 roky', '548 days = 2 years'); | |
25015 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'rok', '1 year = a year'); | |
25016 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 rokov', '5 years = 5 years'); | |
25017 }); | |
25018 | |
25019 test('suffix', function (assert) { | |
25020 assert.equal(moment(30000).from(0), 'za pár sekúnd', 'prefix'); | |
25021 assert.equal(moment(0).from(30000), 'pred pár sekundami', 'suffix'); | |
25022 }); | |
25023 | |
25024 test('now from now', function (assert) { | |
25025 assert.equal(moment().fromNow(), 'pred pár sekundami', 'now from now should display as in the past'); | |
25026 }); | |
25027 | |
25028 test('fromNow (future)', function (assert) { | |
25029 assert.equal(moment().add({s: 30}).fromNow(), 'za pár sekúnd', 'in a few seconds'); | |
25030 assert.equal(moment().add({m: 1}).fromNow(), 'za minútu', 'in a minute'); | |
25031 assert.equal(moment().add({m: 3}).fromNow(), 'za 3 minúty', 'in 3 minutes'); | |
25032 assert.equal(moment().add({m: 10}).fromNow(), 'za 10 minút', 'in 10 minutes'); | |
25033 assert.equal(moment().add({h: 1}).fromNow(), 'za hodinu', 'in an hour'); | |
25034 assert.equal(moment().add({h: 3}).fromNow(), 'za 3 hodiny', 'in 3 hours'); | |
25035 assert.equal(moment().add({h: 10}).fromNow(), 'za 10 hodín', 'in 10 hours'); | |
25036 assert.equal(moment().add({d: 1}).fromNow(), 'za deň', 'in a day'); | |
25037 assert.equal(moment().add({d: 3}).fromNow(), 'za 3 dni', 'in 3 days'); | |
25038 assert.equal(moment().add({d: 10}).fromNow(), 'za 10 dní', 'in 10 days'); | |
25039 assert.equal(moment().add({M: 1}).fromNow(), 'za mesiac', 'in a month'); | |
25040 assert.equal(moment().add({M: 3}).fromNow(), 'za 3 mesiace', 'in 3 months'); | |
25041 assert.equal(moment().add({M: 10}).fromNow(), 'za 10 mesiacov', 'in 10 months'); | |
25042 assert.equal(moment().add({y: 1}).fromNow(), 'za rok', 'in a year'); | |
25043 assert.equal(moment().add({y: 3}).fromNow(), 'za 3 roky', 'in 3 years'); | |
25044 assert.equal(moment().add({y: 10}).fromNow(), 'za 10 rokov', 'in 10 years'); | |
25045 }); | |
25046 | |
25047 test('fromNow (past)', function (assert) { | |
25048 assert.equal(moment().subtract({s: 30}).fromNow(), 'pred pár sekundami', 'a few seconds ago'); | |
25049 assert.equal(moment().subtract({m: 1}).fromNow(), 'pred minútou', 'a minute ago'); | |
25050 assert.equal(moment().subtract({m: 3}).fromNow(), 'pred 3 minútami', '3 minutes ago'); | |
25051 assert.equal(moment().subtract({m: 10}).fromNow(), 'pred 10 minútami', '10 minutes ago'); | |
25052 assert.equal(moment().subtract({h: 1}).fromNow(), 'pred hodinou', 'an hour ago'); | |
25053 assert.equal(moment().subtract({h: 3}).fromNow(), 'pred 3 hodinami', '3 hours ago'); | |
25054 assert.equal(moment().subtract({h: 10}).fromNow(), 'pred 10 hodinami', '10 hours ago'); | |
25055 assert.equal(moment().subtract({d: 1}).fromNow(), 'pred dňom', 'a day ago'); | |
25056 assert.equal(moment().subtract({d: 3}).fromNow(), 'pred 3 dňami', '3 days ago'); | |
25057 assert.equal(moment().subtract({d: 10}).fromNow(), 'pred 10 dňami', '10 days ago'); | |
25058 assert.equal(moment().subtract({M: 1}).fromNow(), 'pred mesiacom', 'a month ago'); | |
25059 assert.equal(moment().subtract({M: 3}).fromNow(), 'pred 3 mesiacmi', '3 months ago'); | |
25060 assert.equal(moment().subtract({M: 10}).fromNow(), 'pred 10 mesiacmi', '10 months ago'); | |
25061 assert.equal(moment().subtract({y: 1}).fromNow(), 'pred rokom', 'a year ago'); | |
25062 assert.equal(moment().subtract({y: 3}).fromNow(), 'pred 3 rokmi', '3 years ago'); | |
25063 assert.equal(moment().subtract({y: 10}).fromNow(), 'pred 10 rokmi', '10 years ago'); | |
25064 }); | |
25065 | |
25066 test('calendar day', function (assert) { | |
25067 var a = moment().hours(2).minutes(0).seconds(0); | |
25068 | |
25069 assert.equal(moment(a).calendar(), 'dnes o 2:00', 'today at the same time'); | |
25070 assert.equal(moment(a).add({m: 25}).calendar(), 'dnes o 2:25', 'Now plus 25 min'); | |
25071 assert.equal(moment(a).add({h: 1}).calendar(), 'dnes o 3:00', 'Now plus 1 hour'); | |
25072 assert.equal(moment(a).add({d: 1}).calendar(), 'zajtra o 2:00', 'tomorrow at the same time'); | |
25073 assert.equal(moment(a).subtract({h: 1}).calendar(), 'dnes o 1:00', 'Now minus 1 hour'); | |
25074 assert.equal(moment(a).subtract({d: 1}).calendar(), 'včera o 2:00', 'yesterday at the same time'); | |
25075 }); | |
25076 | |
25077 test('calendar next week', function (assert) { | |
25078 var i, m, nextDay; | |
25079 for (i = 2; i < 7; i++) { | |
25080 m = moment().add({d: i}); | |
25081 nextDay = ''; | |
25082 switch (m.day()) { | |
25083 case 0: | |
25084 nextDay = 'v nedeľu'; | |
25085 break; | |
25086 case 1: | |
25087 nextDay = 'v pondelok'; | |
25088 break; | |
25089 case 2: | |
25090 nextDay = 'v utorok'; | |
25091 break; | |
25092 case 3: | |
25093 nextDay = 'v stredu'; | |
25094 break; | |
25095 case 4: | |
25096 nextDay = 'vo štvrtok'; | |
25097 break; | |
25098 case 5: | |
25099 nextDay = 'v piatok'; | |
25100 break; | |
25101 case 6: | |
25102 nextDay = 'v sobotu'; | |
25103 break; | |
25104 } | |
25105 assert.equal(m.calendar(), m.format('[' + nextDay + '] [o] LT'), 'Today + ' + i + ' days current time'); | |
25106 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
25107 assert.equal(m.calendar(), m.format('[' + nextDay + '] [o] LT'), 'Today + ' + i + ' days beginning of day'); | |
25108 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
25109 assert.equal(m.calendar(), m.format('[' + nextDay + '] [o] LT'), 'Today + ' + i + ' days end of day'); | |
25110 } | |
25111 }); | |
25112 | |
25113 test('calendar last week', function (assert) { | |
25114 var i, m, lastDay; | |
25115 for (i = 2; i < 7; i++) { | |
25116 m = moment().subtract({d: i}); | |
25117 lastDay = ''; | |
25118 switch (m.day()) { | |
25119 case 0: | |
25120 lastDay = 'minulú nedeľu'; | |
25121 break; | |
25122 case 1: | |
25123 lastDay = 'minulý pondelok'; | |
25124 break; | |
25125 case 2: | |
25126 lastDay = 'minulý utorok'; | |
25127 break; | |
25128 case 3: | |
25129 lastDay = 'minulú stredu'; | |
25130 break; | |
25131 case 4: | |
25132 lastDay = 'minulý štvrtok'; | |
25133 break; | |
25134 case 5: | |
25135 lastDay = 'minulý piatok'; | |
25136 break; | |
25137 case 6: | |
25138 lastDay = 'minulú sobotu'; | |
25139 break; | |
25140 } | |
25141 assert.equal(m.calendar(), m.format('[' + lastDay + '] [o] LT'), 'Today - ' + i + ' days current time'); | |
25142 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
25143 assert.equal(m.calendar(), m.format('[' + lastDay + '] [o] LT'), 'Today - ' + i + ' days beginning of day'); | |
25144 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
25145 assert.equal(m.calendar(), m.format('[' + lastDay + '] [o] LT'), 'Today - ' + i + ' days end of day'); | |
25146 } | |
25147 }); | |
25148 | |
25149 test('calendar all else', function (assert) { | |
25150 var weeksAgo = moment().subtract({w: 1}), | |
25151 weeksFromNow = moment().add({w: 1}); | |
25152 | |
25153 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
25154 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
25155 | |
25156 weeksAgo = moment().subtract({w: 2}); | |
25157 weeksFromNow = moment().add({w: 2}); | |
25158 | |
25159 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
25160 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
25161 }); | |
25162 | |
25163 test('humanize duration', function (assert) { | |
25164 assert.equal(moment.duration(1, 'minutes').humanize(), 'minúta', 'a minute (future)'); | |
25165 assert.equal(moment.duration(1, 'minutes').humanize(true), 'za minútu', 'in a minute'); | |
25166 assert.equal(moment.duration(-1, 'minutes').humanize(), 'minúta', 'a minute (past)'); | |
25167 assert.equal(moment.duration(-1, 'minutes').humanize(true), 'pred minútou', 'a minute ago'); | |
25168 }); | |
25169 | |
25170 test('weeks year starting sunday', function (assert) { | |
25171 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
25172 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
25173 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
25174 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
25175 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
25176 }); | |
25177 | |
25178 test('weeks year starting monday', function (assert) { | |
25179 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
25180 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
25181 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
25182 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
25183 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
25184 }); | |
25185 | |
25186 test('weeks year starting tuesday', function (assert) { | |
25187 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
25188 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
25189 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
25190 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
25191 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
25192 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
25193 }); | |
25194 | |
25195 test('weeks year starting wednesday', function (assert) { | |
25196 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
25197 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
25198 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
25199 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
25200 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
25201 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
25202 }); | |
25203 | |
25204 test('weeks year starting thursday', function (assert) { | |
25205 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
25206 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
25207 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
25208 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
25209 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
25210 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
25211 }); | |
25212 | |
25213 test('weeks year starting friday', function (assert) { | |
25214 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
25215 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
25216 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
25217 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
25218 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
25219 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
25220 }); | |
25221 | |
25222 test('weeks year starting saturday', function (assert) { | |
25223 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
25224 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
25225 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
25226 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
25227 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
25228 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
25229 }); | |
25230 | |
25231 test('weeks year starting sunday formatted', function (assert) { | |
25232 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52'); | |
25233 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1'); | |
25234 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1'); | |
25235 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2'); | |
25236 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2'); | |
25237 }); | |
25238 | |
25239 test('lenient ordinal parsing', function (assert) { | |
25240 var i, ordinalStr, testMoment; | |
25241 for (i = 1; i <= 31; ++i) { | |
25242 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
25243 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
25244 assert.equal(testMoment.year(), 2014, | |
25245 'lenient ordinal parsing ' + i + ' year check'); | |
25246 assert.equal(testMoment.month(), 0, | |
25247 'lenient ordinal parsing ' + i + ' month check'); | |
25248 assert.equal(testMoment.date(), i, | |
25249 'lenient ordinal parsing ' + i + ' date check'); | |
25250 } | |
25251 }); | |
25252 | |
25253 test('lenient ordinal parsing of number', function (assert) { | |
25254 var i, testMoment; | |
25255 for (i = 1; i <= 31; ++i) { | |
25256 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
25257 assert.equal(testMoment.year(), 2014, | |
25258 'lenient ordinal parsing of number ' + i + ' year check'); | |
25259 assert.equal(testMoment.month(), 0, | |
25260 'lenient ordinal parsing of number ' + i + ' month check'); | |
25261 assert.equal(testMoment.date(), i, | |
25262 'lenient ordinal parsing of number ' + i + ' date check'); | |
25263 } | |
25264 }); | |
25265 | |
25266 test('strict ordinal parsing', function (assert) { | |
25267 var i, ordinalStr, testMoment; | |
25268 for (i = 1; i <= 31; ++i) { | |
25269 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
25270 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
25271 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
25272 } | |
25273 }); | |
25274 | |
25275 })); | |
25276 | |
25277 (function (global, factory) { | |
25278 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
25279 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
25280 factory(global.moment) | |
25281 }(this, function (moment) { 'use strict'; | |
25282 | |
25283 /*global QUnit:false*/ | |
25284 | |
25285 var test = QUnit.test; | |
25286 | |
25287 function module (name, lifecycle) { | |
25288 QUnit.module(name, { | |
25289 setup : function () { | |
25290 moment.locale('en'); | |
25291 moment.createFromInputFallback = function () { | |
25292 throw new Error('input not handled by moment'); | |
25293 }; | |
25294 if (lifecycle && lifecycle.setup) { | |
25295 lifecycle.setup(); | |
25296 } | |
25297 }, | |
25298 teardown : function () { | |
25299 if (lifecycle && lifecycle.teardown) { | |
25300 lifecycle.teardown(); | |
25301 } | |
25302 } | |
25303 }); | |
25304 } | |
25305 | |
25306 function localeModule (name, lifecycle) { | |
25307 QUnit.module('locale:' + name, { | |
25308 setup : function () { | |
25309 moment.locale(name); | |
25310 moment.createFromInputFallback = function () { | |
25311 throw new Error('input not handled by moment'); | |
25312 }; | |
25313 if (lifecycle && lifecycle.setup) { | |
25314 lifecycle.setup(); | |
25315 } | |
25316 }, | |
25317 teardown : function () { | |
25318 moment.locale('en'); | |
25319 if (lifecycle && lifecycle.teardown) { | |
25320 lifecycle.teardown(); | |
25321 } | |
25322 } | |
25323 }); | |
25324 } | |
25325 | |
25326 localeModule('sl'); | |
25327 | |
25328 test('parse', function (assert) { | |
25329 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; | |
25330 function equalTest(input, mmm, i) { | |
25331 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
25332 } | |
25333 for (i = 0; i < 12; i++) { | |
25334 tests[i] = tests[i].split(' '); | |
25335 equalTest(tests[i][0], 'MMM', i); | |
25336 equalTest(tests[i][1], 'MMM', i); | |
25337 equalTest(tests[i][0], 'MMMM', i); | |
25338 equalTest(tests[i][1], 'MMMM', i); | |
25339 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
25340 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
25341 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
25342 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
25343 } | |
25344 }); | |
25345 | |
25346 test('format', function (assert) { | |
25347 var a = [ | |
25348 ['dddd, Do MMMM YYYY, h:mm:ss a', 'nedelja, 14. februar 2010, 3:25:50 pm'], | |
25349 ['ddd, hA', 'ned., 3PM'], | |
25350 ['M Mo MM MMMM MMM', '2 2. 02 februar feb.'], | |
25351 ['YYYY YY', '2010 10'], | |
25352 ['D Do DD', '14 14. 14'], | |
25353 ['d do dddd ddd dd', '0 0. nedelja ned. ne'], | |
25354 ['DDD DDDo DDDD', '45 45. 045'], | |
25355 ['w wo ww', '7 7. 07'], | |
25356 ['h hh', '3 03'], | |
25357 ['H HH', '15 15'], | |
25358 ['m mm', '25 25'], | |
25359 ['s ss', '50 50'], | |
25360 ['a A', 'pm PM'], | |
25361 ['[the] DDDo [day of the year]', 'the 45. day of the year'], | |
25362 ['LTS', '15:25:50'], | |
25363 ['L', '14. 02. 2010'], | |
25364 ['LL', '14. februar 2010'], | |
25365 ['LLL', '14. februar 2010 15:25'], | |
25366 ['LLLL', 'nedelja, 14. februar 2010 15:25'], | |
25367 ['l', '14. 2. 2010'], | |
25368 ['ll', '14. feb. 2010'], | |
25369 ['lll', '14. feb. 2010 15:25'], | |
25370 ['llll', 'ned., 14. feb. 2010 15:25'] | |
25371 ], | |
25372 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
25373 i; | |
25374 for (i = 0; i < a.length; i++) { | |
25375 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
25376 } | |
25377 }); | |
25378 | |
25379 test('format ordinal', function (assert) { | |
25380 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.'); | |
25381 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.'); | |
25382 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.'); | |
25383 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.'); | |
25384 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.'); | |
25385 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.'); | |
25386 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.'); | |
25387 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.'); | |
25388 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.'); | |
25389 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.'); | |
25390 | |
25391 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.'); | |
25392 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.'); | |
25393 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.'); | |
25394 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.'); | |
25395 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.'); | |
25396 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.'); | |
25397 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.'); | |
25398 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.'); | |
25399 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.'); | |
25400 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.'); | |
25401 | |
25402 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.'); | |
25403 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.'); | |
25404 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.'); | |
25405 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.'); | |
25406 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.'); | |
25407 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.'); | |
25408 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.'); | |
25409 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.'); | |
25410 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.'); | |
25411 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.'); | |
25412 | |
25413 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.'); | |
25414 }); | |
25415 | |
25416 test('format month', function (assert) { | |
25417 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; | |
25418 for (i = 0; i < expected.length; i++) { | |
25419 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
25420 } | |
25421 }); | |
25422 | |
25423 test('format week', function (assert) { | |
25424 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; | |
25425 for (i = 0; i < expected.length; i++) { | |
25426 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
25427 } | |
25428 }); | |
25429 | |
25430 test('from', function (assert) { | |
25431 var start = moment([2007, 1, 28]); | |
25432 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'nekaj sekund', '44 seconds = a few seconds'); | |
25433 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ena minuta', '45 seconds = a minute'); | |
25434 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ena minuta', '89 seconds = a minute'); | |
25435 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuti', '90 seconds = 2 minutes'); | |
25436 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minut', '44 minutes = 44 minutes'); | |
25437 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ena ura', '45 minutes = an hour'); | |
25438 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ena ura', '89 minutes = an hour'); | |
25439 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 uri', '90 minutes = 2 hours'); | |
25440 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ur', '5 hours = 5 hours'); | |
25441 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ur', '21 hours = 21 hours'); | |
25442 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'en dan', '22 hours = a day'); | |
25443 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'en dan', '35 hours = a day'); | |
25444 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dni', '36 hours = 2 days'); | |
25445 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'en dan', '1 day = a day'); | |
25446 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dni', '5 days = 5 days'); | |
25447 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dni', '25 days = 25 days'); | |
25448 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'en mesec', '26 days = a month'); | |
25449 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'en mesec', '30 days = a month'); | |
25450 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'en mesec', '43 days = a month'); | |
25451 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 meseca', '46 days = 2 months'); | |
25452 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 meseca', '75 days = 2 months'); | |
25453 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mesece', '76 days = 3 months'); | |
25454 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'en mesec', '1 month = a month'); | |
25455 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mesecev', '5 months = 5 months'); | |
25456 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'eno leto', '345 days = a year'); | |
25457 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 leti', '548 days = 2 years'); | |
25458 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'eno leto', '1 year = a year'); | |
25459 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 let', '5 years = 5 years'); | |
25460 | |
25461 assert.equal(start.from(moment([2007, 1, 28]).add({m: 1}), true), 'ena minuta', 'a minute'); | |
25462 assert.equal(start.from(moment([2007, 1, 28]).add({m: 2}), true), '2 minuti', '2 minutes'); | |
25463 assert.equal(start.from(moment([2007, 1, 28]).add({m: 3}), true), '3 minute', '3 minutes'); | |
25464 assert.equal(start.from(moment([2007, 1, 28]).add({m: 4}), true), '4 minute', '4 minutes'); | |
25465 assert.equal(start.from(moment([2007, 1, 28]).add({m: 5}), true), '5 minut', '5 minutes'); | |
25466 | |
25467 assert.equal(start.from(moment([2007, 1, 28]).add({h: 1}), true), 'ena ura', 'an hour'); | |
25468 assert.equal(start.from(moment([2007, 1, 28]).add({h: 2}), true), '2 uri', '2 hours'); | |
25469 assert.equal(start.from(moment([2007, 1, 28]).add({h: 3}), true), '3 ure', '3 hours'); | |
25470 assert.equal(start.from(moment([2007, 1, 28]).add({h: 4}), true), '4 ure', '4 hours'); | |
25471 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ur', '5 hours'); | |
25472 | |
25473 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'en dan', 'a day'); | |
25474 assert.equal(start.from(moment([2007, 1, 28]).add({d: 2}), true), '2 dni', '2 days'); | |
25475 assert.equal(start.from(moment([2007, 1, 28]).add({d: 3}), true), '3 dni', '3 days'); | |
25476 assert.equal(start.from(moment([2007, 1, 28]).add({d: 4}), true), '4 dni', '4 days'); | |
25477 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dni', '5 days'); | |
25478 | |
25479 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'en mesec', 'a month'); | |
25480 assert.equal(start.from(moment([2007, 1, 28]).add({M: 2}), true), '2 meseca', '2 months'); | |
25481 assert.equal(start.from(moment([2007, 1, 28]).add({M: 3}), true), '3 mesece', '3 months'); | |
25482 assert.equal(start.from(moment([2007, 1, 28]).add({M: 4}), true), '4 mesece', '4 months'); | |
25483 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mesecev', '5 months'); | |
25484 | |
25485 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'eno leto', 'a year'); | |
25486 assert.equal(start.from(moment([2007, 1, 28]).add({y: 2}), true), '2 leti', '2 years'); | |
25487 assert.equal(start.from(moment([2007, 1, 28]).add({y: 3}), true), '3 leta', '3 years'); | |
25488 assert.equal(start.from(moment([2007, 1, 28]).add({y: 4}), true), '4 leta', '4 years'); | |
25489 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 let', '5 years'); | |
25490 }); | |
25491 | |
25492 test('suffix', function (assert) { | |
25493 assert.equal(moment(30000).from(0), 'čez nekaj sekund', 'prefix'); | |
25494 assert.equal(moment(0).from(30000), 'pred nekaj sekundami', 'suffix'); | |
25495 }); | |
25496 | |
25497 test('now from now', function (assert) { | |
25498 assert.equal(moment().fromNow(), 'pred nekaj sekundami', 'now from now should display as in the past'); | |
25499 }); | |
25500 | |
25501 test('fromNow (future)', function (assert) { | |
25502 assert.equal(moment().add({s: 30}).fromNow(), 'čez nekaj sekund', 'in a few seconds'); | |
25503 assert.equal(moment().add({m: 1}).fromNow(), 'čez eno minuto', 'in a minute'); | |
25504 assert.equal(moment().add({m: 2}).fromNow(), 'čez 2 minuti', 'in 2 minutes'); | |
25505 assert.equal(moment().add({m: 3}).fromNow(), 'čez 3 minute', 'in 3 minutes'); | |
25506 assert.equal(moment().add({m: 4}).fromNow(), 'čez 4 minute', 'in 4 minutes'); | |
25507 assert.equal(moment().add({m: 5}).fromNow(), 'čez 5 minut', 'in 5 minutes'); | |
25508 | |
25509 assert.equal(moment().add({h: 1}).fromNow(), 'čez eno uro', 'in an hour'); | |
25510 assert.equal(moment().add({h: 2}).fromNow(), 'čez 2 uri', 'in 2 hours'); | |
25511 assert.equal(moment().add({h: 3}).fromNow(), 'čez 3 ure', 'in 3 hours'); | |
25512 assert.equal(moment().add({h: 4}).fromNow(), 'čez 4 ure', 'in 4 hours'); | |
25513 assert.equal(moment().add({h: 5}).fromNow(), 'čez 5 ur', 'in 5 hours'); | |
25514 | |
25515 assert.equal(moment().add({d: 1}).fromNow(), 'čez en dan', 'in a day'); | |
25516 assert.equal(moment().add({d: 2}).fromNow(), 'čez 2 dni', 'in 2 days'); | |
25517 assert.equal(moment().add({d: 3}).fromNow(), 'čez 3 dni', 'in 3 days'); | |
25518 assert.equal(moment().add({d: 4}).fromNow(), 'čez 4 dni', 'in 4 days'); | |
25519 assert.equal(moment().add({d: 5}).fromNow(), 'čez 5 dni', 'in 5 days'); | |
25520 | |
25521 assert.equal(moment().add({M: 1}).fromNow(), 'čez en mesec', 'in a month'); | |
25522 assert.equal(moment().add({M: 2}).fromNow(), 'čez 2 meseca', 'in 2 months'); | |
25523 assert.equal(moment().add({M: 3}).fromNow(), 'čez 3 mesece', 'in 3 months'); | |
25524 assert.equal(moment().add({M: 4}).fromNow(), 'čez 4 mesece', 'in 4 months'); | |
25525 assert.equal(moment().add({M: 5}).fromNow(), 'čez 5 mesecev', 'in 5 months'); | |
25526 | |
25527 assert.equal(moment().add({y: 1}).fromNow(), 'čez eno leto', 'in a year'); | |
25528 assert.equal(moment().add({y: 2}).fromNow(), 'čez 2 leti', 'in 2 years'); | |
25529 assert.equal(moment().add({y: 3}).fromNow(), 'čez 3 leta', 'in 3 years'); | |
25530 assert.equal(moment().add({y: 4}).fromNow(), 'čez 4 leta', 'in 4 years'); | |
25531 assert.equal(moment().add({y: 5}).fromNow(), 'čez 5 let', 'in 5 years'); | |
25532 | |
25533 assert.equal(moment().subtract({s: 30}).fromNow(), 'pred nekaj sekundami', 'a few seconds ago'); | |
25534 | |
25535 assert.equal(moment().subtract({m: 1}).fromNow(), 'pred eno minuto', 'a minute ago'); | |
25536 assert.equal(moment().subtract({m: 2}).fromNow(), 'pred 2 minutama', '2 minutes ago'); | |
25537 assert.equal(moment().subtract({m: 3}).fromNow(), 'pred 3 minutami', '3 minutes ago'); | |
25538 assert.equal(moment().subtract({m: 4}).fromNow(), 'pred 4 minutami', '4 minutes ago'); | |
25539 assert.equal(moment().subtract({m: 5}).fromNow(), 'pred 5 minutami', '5 minutes ago'); | |
25540 | |
25541 assert.equal(moment().subtract({h: 1}).fromNow(), 'pred eno uro', 'an hour ago'); | |
25542 assert.equal(moment().subtract({h: 2}).fromNow(), 'pred 2 urama', '2 hours ago'); | |
25543 assert.equal(moment().subtract({h: 3}).fromNow(), 'pred 3 urami', '3 hours ago'); | |
25544 assert.equal(moment().subtract({h: 4}).fromNow(), 'pred 4 urami', '4 hours ago'); | |
25545 assert.equal(moment().subtract({h: 5}).fromNow(), 'pred 5 urami', '5 hours ago'); | |
25546 | |
25547 assert.equal(moment().subtract({d: 1}).fromNow(), 'pred enim dnem', 'a day ago'); | |
25548 assert.equal(moment().subtract({d: 2}).fromNow(), 'pred 2 dnevoma', '2 days ago'); | |
25549 assert.equal(moment().subtract({d: 3}).fromNow(), 'pred 3 dnevi', '3 days ago'); | |
25550 assert.equal(moment().subtract({d: 4}).fromNow(), 'pred 4 dnevi', '4 days ago'); | |
25551 assert.equal(moment().subtract({d: 5}).fromNow(), 'pred 5 dnevi', '5 days ago'); | |
25552 | |
25553 assert.equal(moment().subtract({M: 1}).fromNow(), 'pred enim mesecem', 'a month ago'); | |
25554 assert.equal(moment().subtract({M: 2}).fromNow(), 'pred 2 mesecema', '2 months ago'); | |
25555 assert.equal(moment().subtract({M: 3}).fromNow(), 'pred 3 meseci', '3 months ago'); | |
25556 assert.equal(moment().subtract({M: 4}).fromNow(), 'pred 4 meseci', '4 months ago'); | |
25557 assert.equal(moment().subtract({M: 5}).fromNow(), 'pred 5 meseci', '5 months ago'); | |
25558 | |
25559 assert.equal(moment().subtract({y: 1}).fromNow(), 'pred enim letom', 'a year ago'); | |
25560 assert.equal(moment().subtract({y: 2}).fromNow(), 'pred 2 letoma', '2 years ago'); | |
25561 assert.equal(moment().subtract({y: 3}).fromNow(), 'pred 3 leti', '3 years ago'); | |
25562 assert.equal(moment().subtract({y: 4}).fromNow(), 'pred 4 leti', '4 years ago'); | |
25563 assert.equal(moment().subtract({y: 5}).fromNow(), 'pred 5 leti', '5 years ago'); | |
25564 }); | |
25565 | |
25566 test('calendar day', function (assert) { | |
25567 var a = moment().hours(2).minutes(0).seconds(0); | |
25568 | |
25569 assert.equal(moment(a).calendar(), 'danes ob 2:00', 'today at the same time'); | |
25570 assert.equal(moment(a).add({m: 25}).calendar(), 'danes ob 2:25', 'Now plus 25 min'); | |
25571 assert.equal(moment(a).add({h: 1}).calendar(), 'danes ob 3:00', 'Now plus 1 hour'); | |
25572 assert.equal(moment(a).add({d: 1}).calendar(), 'jutri ob 2:00', 'tomorrow at the same time'); | |
25573 assert.equal(moment(a).subtract({h: 1}).calendar(), 'danes ob 1:00', 'Now minus 1 hour'); | |
25574 assert.equal(moment(a).subtract({d: 1}).calendar(), 'včeraj ob 2:00', 'yesterday at the same time'); | |
25575 }); | |
25576 | |
25577 test('calendar next week', function (assert) { | |
25578 var i, m; | |
25579 | |
25580 function makeFormat(d) { | |
25581 switch (d.day()) { | |
25582 case 0: | |
25583 return '[v] [nedeljo] [ob] LT'; | |
25584 case 3: | |
25585 return '[v] [sredo] [ob] LT'; | |
25586 case 6: | |
25587 return '[v] [soboto] [ob] LT'; | |
25588 case 1: | |
25589 case 2: | |
25590 case 4: | |
25591 case 5: | |
25592 return '[v] dddd [ob] LT'; | |
25593 } | |
25594 } | |
25595 | |
25596 for (i = 2; i < 7; i++) { | |
25597 m = moment().add({d: i}); | |
25598 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time'); | |
25599 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
25600 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day'); | |
25601 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
25602 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day'); | |
25603 } | |
25604 }); | |
25605 | |
25606 test('calendar last week', function (assert) { | |
25607 var i, m; | |
25608 | |
25609 function makeFormat(d) { | |
25610 switch (d.day()) { | |
25611 case 0: | |
25612 return '[prejšnjo] [nedeljo] [ob] LT'; | |
25613 case 3: | |
25614 return '[prejšnjo] [sredo] [ob] LT'; | |
25615 case 6: | |
25616 return '[prejšnjo] [soboto] [ob] LT'; | |
25617 case 1: | |
25618 case 2: | |
25619 case 4: | |
25620 case 5: | |
25621 return '[prejšnji] dddd [ob] LT'; | |
25622 } | |
25623 } | |
25624 | |
25625 for (i = 2; i < 7; i++) { | |
25626 m = moment().subtract({d: i}); | |
25627 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time'); | |
25628 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
25629 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day'); | |
25630 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
25631 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day'); | |
25632 } | |
25633 }); | |
25634 | |
25635 test('calendar all else', function (assert) { | |
25636 var weeksAgo = moment().subtract({w: 1}), | |
25637 weeksFromNow = moment().add({w: 1}); | |
25638 | |
25639 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
25640 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
25641 | |
25642 weeksAgo = moment().subtract({w: 2}); | |
25643 weeksFromNow = moment().add({w: 2}); | |
25644 | |
25645 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
25646 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
25647 }); | |
25648 | |
25649 test('weeks year starting sunday', function (assert) { | |
25650 assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1'); | |
25651 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
25652 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2'); | |
25653 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
25654 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3'); | |
25655 }); | |
25656 | |
25657 test('weeks year starting monday', function (assert) { | |
25658 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
25659 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
25660 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
25661 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
25662 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
25663 }); | |
25664 | |
25665 test('weeks year starting tuesday', function (assert) { | |
25666 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
25667 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
25668 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
25669 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
25670 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
25671 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
25672 }); | |
25673 | |
25674 test('weeks year starting wednesday', function (assert) { | |
25675 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
25676 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
25677 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
25678 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
25679 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
25680 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
25681 }); | |
25682 | |
25683 test('weeks year starting thursday', function (assert) { | |
25684 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
25685 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
25686 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
25687 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
25688 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
25689 assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3'); | |
25690 }); | |
25691 | |
25692 test('weeks year starting friday', function (assert) { | |
25693 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1'); | |
25694 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
25695 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1'); | |
25696 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2'); | |
25697 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2'); | |
25698 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3'); | |
25699 }); | |
25700 | |
25701 test('weeks year starting saturday', function (assert) { | |
25702 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1'); | |
25703 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
25704 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1'); | |
25705 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2'); | |
25706 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2'); | |
25707 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3'); | |
25708 }); | |
25709 | |
25710 test('weeks year starting sunday formatted', function (assert) { | |
25711 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', 'Dec 26 2011 should be week 1'); | |
25712 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1.', 'Jan 1 2012 should be week 1'); | |
25713 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2.', 'Jan 2 2012 should be week 2'); | |
25714 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2.', 'Jan 8 2012 should be week 2'); | |
25715 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3.', 'Jan 9 2012 should be week 3'); | |
25716 }); | |
25717 | |
25718 test('lenient ordinal parsing', function (assert) { | |
25719 var i, ordinalStr, testMoment; | |
25720 for (i = 1; i <= 31; ++i) { | |
25721 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
25722 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
25723 assert.equal(testMoment.year(), 2014, | |
25724 'lenient ordinal parsing ' + i + ' year check'); | |
25725 assert.equal(testMoment.month(), 0, | |
25726 'lenient ordinal parsing ' + i + ' month check'); | |
25727 assert.equal(testMoment.date(), i, | |
25728 'lenient ordinal parsing ' + i + ' date check'); | |
25729 } | |
25730 }); | |
25731 | |
25732 test('lenient ordinal parsing of number', function (assert) { | |
25733 var i, testMoment; | |
25734 for (i = 1; i <= 31; ++i) { | |
25735 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
25736 assert.equal(testMoment.year(), 2014, | |
25737 'lenient ordinal parsing of number ' + i + ' year check'); | |
25738 assert.equal(testMoment.month(), 0, | |
25739 'lenient ordinal parsing of number ' + i + ' month check'); | |
25740 assert.equal(testMoment.date(), i, | |
25741 'lenient ordinal parsing of number ' + i + ' date check'); | |
25742 } | |
25743 }); | |
25744 | |
25745 test('strict ordinal parsing', function (assert) { | |
25746 var i, ordinalStr, testMoment; | |
25747 for (i = 1; i <= 31; ++i) { | |
25748 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
25749 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
25750 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
25751 } | |
25752 }); | |
25753 | |
25754 })); | |
25755 | |
25756 (function (global, factory) { | |
25757 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
25758 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
25759 factory(global.moment) | |
25760 }(this, function (moment) { 'use strict'; | |
25761 | |
25762 /*global QUnit:false*/ | |
25763 | |
25764 var test = QUnit.test; | |
25765 | |
25766 function module (name, lifecycle) { | |
25767 QUnit.module(name, { | |
25768 setup : function () { | |
25769 moment.locale('en'); | |
25770 moment.createFromInputFallback = function () { | |
25771 throw new Error('input not handled by moment'); | |
25772 }; | |
25773 if (lifecycle && lifecycle.setup) { | |
25774 lifecycle.setup(); | |
25775 } | |
25776 }, | |
25777 teardown : function () { | |
25778 if (lifecycle && lifecycle.teardown) { | |
25779 lifecycle.teardown(); | |
25780 } | |
25781 } | |
25782 }); | |
25783 } | |
25784 | |
25785 function localeModule (name, lifecycle) { | |
25786 QUnit.module('locale:' + name, { | |
25787 setup : function () { | |
25788 moment.locale(name); | |
25789 moment.createFromInputFallback = function () { | |
25790 throw new Error('input not handled by moment'); | |
25791 }; | |
25792 if (lifecycle && lifecycle.setup) { | |
25793 lifecycle.setup(); | |
25794 } | |
25795 }, | |
25796 teardown : function () { | |
25797 moment.locale('en'); | |
25798 if (lifecycle && lifecycle.teardown) { | |
25799 lifecycle.teardown(); | |
25800 } | |
25801 } | |
25802 }); | |
25803 } | |
25804 | |
25805 localeModule('sq'); | |
25806 | |
25807 test('parse', function (assert) { | |
25808 var i, | |
25809 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('_'); | |
25810 | |
25811 function equalTest(input, mmm, i) { | |
25812 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
25813 } | |
25814 | |
25815 for (i = 0; i < 12; i++) { | |
25816 tests[i] = tests[i].split(' '); | |
25817 equalTest(tests[i][0], 'MMM', i); | |
25818 equalTest(tests[i][1], 'MMM', i); | |
25819 equalTest(tests[i][0], 'MMMM', i); | |
25820 equalTest(tests[i][1], 'MMMM', i); | |
25821 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
25822 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
25823 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
25824 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
25825 } | |
25826 }); | |
25827 | |
25828 test('format', function (assert) { | |
25829 var a = [ | |
25830 ['dddd, MMMM Do YYYY, HH:mm:ss', 'E Diel, Shkurt 14. 2010, 15:25:50'], | |
25831 ['ddd, HH', 'Die, 15'], | |
25832 ['M Mo MM MMMM MMM', '2 2. 02 Shkurt Shk'], | |
25833 ['YYYY YY', '2010 10'], | |
25834 ['D Do DD', '14 14. 14'], | |
25835 ['d do dddd ddd dd', '0 0. E Diel Die D'], | |
25836 ['DDD DDDo DDDD', '45 45. 045'], | |
25837 ['w wo ww', '6 6. 06'], | |
25838 ['h hh', '3 03'], | |
25839 ['H HH', '15 15'], | |
25840 ['m mm', '25 25'], | |
25841 ['s ss', '50 50'], | |
25842 ['a A', 'MD MD'], | |
25843 ['[the] DDDo [day of the year]', 'the 45. day of the year'], | |
25844 ['LTS', '15:25:50'], | |
25845 ['L', '14/02/2010'], | |
25846 ['LL', '14 Shkurt 2010'], | |
25847 ['LLL', '14 Shkurt 2010 15:25'], | |
25848 ['LLLL', 'E Diel, 14 Shkurt 2010 15:25'], | |
25849 ['l', '14/2/2010'], | |
25850 ['ll', '14 Shk 2010'], | |
25851 ['lll', '14 Shk 2010 15:25'], | |
25852 ['llll', 'Die, 14 Shk 2010 15:25'] | |
25853 ], | |
25854 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
25855 i; | |
25856 | |
25857 for (i = 0; i < a.length; i++) { | |
25858 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
25859 } | |
25860 }); | |
25861 | |
25862 test('meridiem', function (assert) { | |
25863 assert.equal(moment([2011, 2, 23, 0, 0]).format('A'), 'PD', 'before dawn'); | |
25864 assert.equal(moment([2011, 2, 23, 12, 0]).format('A'), 'MD', 'noon'); | |
25865 }); | |
25866 | |
25867 test('format ordinal', function (assert) { | |
25868 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.'); | |
25869 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.'); | |
25870 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.'); | |
25871 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.'); | |
25872 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.'); | |
25873 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.'); | |
25874 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.'); | |
25875 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.'); | |
25876 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.'); | |
25877 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.'); | |
25878 | |
25879 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.'); | |
25880 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.'); | |
25881 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.'); | |
25882 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.'); | |
25883 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.'); | |
25884 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.'); | |
25885 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.'); | |
25886 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.'); | |
25887 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.'); | |
25888 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.'); | |
25889 | |
25890 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.'); | |
25891 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.'); | |
25892 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.'); | |
25893 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.'); | |
25894 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.'); | |
25895 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.'); | |
25896 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.'); | |
25897 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.'); | |
25898 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.'); | |
25899 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.'); | |
25900 | |
25901 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.'); | |
25902 }); | |
25903 | |
25904 test('format month', function (assert) { | |
25905 var i, | |
25906 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('_'); | |
25907 | |
25908 for (i = 0; i < expected.length; i++) { | |
25909 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
25910 } | |
25911 }); | |
25912 | |
25913 test('format week', function (assert) { | |
25914 var i, | |
25915 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('_'); | |
25916 | |
25917 for (i = 0; i < expected.length; i++) { | |
25918 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
25919 } | |
25920 }); | |
25921 | |
25922 test('from', function (assert) { | |
25923 var start = moment([2007, 1, 28]); | |
25924 | |
25925 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'disa sekonda', '44 seconds = a few seconds'); | |
25926 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'një minutë', '45 seconds = a minute'); | |
25927 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'një minutë', '89 seconds = a minute'); | |
25928 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuta', '90 seconds = 2 minutes'); | |
25929 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuta', '44 minutes = 44 minutes'); | |
25930 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'një orë', '45 minutes = an hour'); | |
25931 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'një orë', '89 minutes = an hour'); | |
25932 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 orë', '90 minutes = 2 hours'); | |
25933 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 orë', '5 hours = 5 hours'); | |
25934 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 orë', '21 hours = 21 hours'); | |
25935 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'një ditë', '22 hours = a day'); | |
25936 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'një ditë', '35 hours = a day'); | |
25937 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 ditë', '36 hours = 2 days'); | |
25938 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'një ditë', '1 day = a day'); | |
25939 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ditë', '5 days = 5 days'); | |
25940 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ditë', '25 days = 25 days'); | |
25941 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'një muaj', '26 days = a month'); | |
25942 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'një muaj', '30 days = a month'); | |
25943 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'një muaj', '43 days = a month'); | |
25944 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 muaj', '46 days = 2 months'); | |
25945 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 muaj', '75 days = 2 months'); | |
25946 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 muaj', '76 days = 3 months'); | |
25947 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'një muaj', '1 month = a month'); | |
25948 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 muaj', '5 months = 5 months'); | |
25949 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'një vit', '345 days = a year'); | |
25950 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 vite', '548 days = 2 years'); | |
25951 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'një vit', '1 year = a year'); | |
25952 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 vite', '5 years = 5 years'); | |
25953 }); | |
25954 | |
25955 test('suffix', function (assert) { | |
25956 assert.equal(moment(30000).from(0), 'në disa sekonda', 'prefix'); | |
25957 assert.equal(moment(0).from(30000), 'disa sekonda më parë', 'suffix'); | |
25958 }); | |
25959 | |
25960 test('now from now', function (assert) { | |
25961 assert.equal(moment().fromNow(), 'disa sekonda më parë', 'now from now should display as in the past'); | |
25962 }); | |
25963 | |
25964 test('fromNow', function (assert) { | |
25965 assert.equal(moment().add({s: 30}).fromNow(), 'në disa sekonda', 'in a few seconds'); | |
25966 assert.equal(moment().add({d: 5}).fromNow(), 'në 5 ditë', 'in 5 days'); | |
25967 }); | |
25968 | |
25969 test('calendar day', function (assert) { | |
25970 var a = moment().hours(2).minutes(0).seconds(0); | |
25971 | |
25972 assert.equal(moment(a).calendar(), 'Sot në 02:00', 'today at the same time'); | |
25973 assert.equal(moment(a).add({m: 25}).calendar(), 'Sot në 02:25', 'Now plus 25 min'); | |
25974 assert.equal(moment(a).add({h: 1}).calendar(), 'Sot në 03:00', 'Now plus 1 hour'); | |
25975 assert.equal(moment(a).add({d: 1}).calendar(), 'Nesër në 02:00', 'tomorrow at the same time'); | |
25976 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Sot në 01:00', 'Now minus 1 hour'); | |
25977 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Dje në 02:00', 'yesterday at the same time'); | |
25978 }); | |
25979 | |
25980 test('calendar next week', function (assert) { | |
25981 var i, m; | |
25982 | |
25983 for (i = 2; i < 7; i++) { | |
25984 m = moment().add({d: i}); | |
25985 assert.equal(m.calendar(), m.format('dddd [në] LT'), 'Today + ' + i + ' days current time'); | |
25986 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
25987 assert.equal(m.calendar(), m.format('dddd [në] LT'), 'Today + ' + i + ' days beginning of day'); | |
25988 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
25989 assert.equal(m.calendar(), m.format('dddd [në] LT'), 'Today + ' + i + ' days end of day'); | |
25990 } | |
25991 }); | |
25992 | |
25993 test('calendar last week', function (assert) { | |
25994 var i, m; | |
25995 | |
25996 for (i = 2; i < 7; i++) { | |
25997 m = moment().subtract({d: i}); | |
25998 assert.equal(m.calendar(), m.format('dddd [e kaluar në] LT'), 'Today - ' + i + ' days current time'); | |
25999 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
26000 assert.equal(m.calendar(), m.format('dddd [e kaluar në] LT'), 'Today - ' + i + ' days beginning of day'); | |
26001 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
26002 assert.equal(m.calendar(), m.format('dddd [e kaluar në] LT'), 'Today - ' + i + ' days end of day'); | |
26003 } | |
26004 }); | |
26005 | |
26006 test('calendar all else', function (assert) { | |
26007 var weeksAgo = moment().subtract({w: 1}), | |
26008 weeksFromNow = moment().add({w: 1}); | |
26009 | |
26010 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
26011 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
26012 | |
26013 weeksAgo = moment().subtract({w: 2}); | |
26014 weeksFromNow = moment().add({w: 2}); | |
26015 | |
26016 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
26017 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
26018 }); | |
26019 | |
26020 test('weeks year starting sunday', function (assert) { | |
26021 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
26022 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
26023 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
26024 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
26025 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
26026 }); | |
26027 | |
26028 test('weeks year starting monday', function (assert) { | |
26029 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
26030 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
26031 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
26032 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
26033 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
26034 }); | |
26035 | |
26036 test('weeks year starting tuesday', function (assert) { | |
26037 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
26038 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
26039 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
26040 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
26041 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
26042 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
26043 }); | |
26044 | |
26045 test('weeks year starting wednesday', function (assert) { | |
26046 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
26047 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
26048 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
26049 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
26050 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
26051 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
26052 }); | |
26053 | |
26054 test('weeks year starting thursday', function (assert) { | |
26055 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
26056 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
26057 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
26058 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
26059 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
26060 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
26061 }); | |
26062 | |
26063 test('weeks year starting friday', function (assert) { | |
26064 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
26065 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
26066 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
26067 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
26068 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
26069 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
26070 }); | |
26071 | |
26072 test('weeks year starting saturday', function (assert) { | |
26073 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
26074 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
26075 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
26076 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
26077 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
26078 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
26079 }); | |
26080 | |
26081 test('weeks year starting sunday formatted', function (assert) { | |
26082 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52'); | |
26083 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1'); | |
26084 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1'); | |
26085 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2'); | |
26086 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2'); | |
26087 }); | |
26088 | |
26089 test('lenient ordinal parsing', function (assert) { | |
26090 var i, ordinalStr, testMoment; | |
26091 for (i = 1; i <= 31; ++i) { | |
26092 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
26093 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
26094 assert.equal(testMoment.year(), 2014, | |
26095 'lenient ordinal parsing ' + i + ' year check'); | |
26096 assert.equal(testMoment.month(), 0, | |
26097 'lenient ordinal parsing ' + i + ' month check'); | |
26098 assert.equal(testMoment.date(), i, | |
26099 'lenient ordinal parsing ' + i + ' date check'); | |
26100 } | |
26101 }); | |
26102 | |
26103 test('lenient ordinal parsing of number', function (assert) { | |
26104 var i, testMoment; | |
26105 for (i = 1; i <= 31; ++i) { | |
26106 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
26107 assert.equal(testMoment.year(), 2014, | |
26108 'lenient ordinal parsing of number ' + i + ' year check'); | |
26109 assert.equal(testMoment.month(), 0, | |
26110 'lenient ordinal parsing of number ' + i + ' month check'); | |
26111 assert.equal(testMoment.date(), i, | |
26112 'lenient ordinal parsing of number ' + i + ' date check'); | |
26113 } | |
26114 }); | |
26115 | |
26116 test('strict ordinal parsing', function (assert) { | |
26117 var i, ordinalStr, testMoment; | |
26118 for (i = 1; i <= 31; ++i) { | |
26119 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
26120 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
26121 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
26122 } | |
26123 }); | |
26124 | |
26125 })); | |
26126 | |
26127 (function (global, factory) { | |
26128 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
26129 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
26130 factory(global.moment) | |
26131 }(this, function (moment) { 'use strict'; | |
26132 | |
26133 /*global QUnit:false*/ | |
26134 | |
26135 var test = QUnit.test; | |
26136 | |
26137 function module (name, lifecycle) { | |
26138 QUnit.module(name, { | |
26139 setup : function () { | |
26140 moment.locale('en'); | |
26141 moment.createFromInputFallback = function () { | |
26142 throw new Error('input not handled by moment'); | |
26143 }; | |
26144 if (lifecycle && lifecycle.setup) { | |
26145 lifecycle.setup(); | |
26146 } | |
26147 }, | |
26148 teardown : function () { | |
26149 if (lifecycle && lifecycle.teardown) { | |
26150 lifecycle.teardown(); | |
26151 } | |
26152 } | |
26153 }); | |
26154 } | |
26155 | |
26156 function localeModule (name, lifecycle) { | |
26157 QUnit.module('locale:' + name, { | |
26158 setup : function () { | |
26159 moment.locale(name); | |
26160 moment.createFromInputFallback = function () { | |
26161 throw new Error('input not handled by moment'); | |
26162 }; | |
26163 if (lifecycle && lifecycle.setup) { | |
26164 lifecycle.setup(); | |
26165 } | |
26166 }, | |
26167 teardown : function () { | |
26168 moment.locale('en'); | |
26169 if (lifecycle && lifecycle.teardown) { | |
26170 lifecycle.teardown(); | |
26171 } | |
26172 } | |
26173 }); | |
26174 } | |
26175 | |
26176 localeModule('sr-cyrl'); | |
26177 | |
26178 test('parse', function (assert) { | |
26179 var tests = 'јануар јан._фебруар феб._март мар._април апр._мај мај_јун јун_јул јул_август авг._септембар сеп._октобар окт._новембар нов._децембар дец.'.split('_'), | |
26180 i; | |
26181 function equalTest(input, mmm, i) { | |
26182 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
26183 } | |
26184 for (i = 0; i < 12; i++) { | |
26185 tests[i] = tests[i].split(' '); | |
26186 equalTest(tests[i][0], 'MMM', i); | |
26187 equalTest(tests[i][1], 'MMM', i); | |
26188 equalTest(tests[i][0], 'MMMM', i); | |
26189 equalTest(tests[i][1], 'MMMM', i); | |
26190 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
26191 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
26192 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
26193 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
26194 } | |
26195 }); | |
26196 | |
26197 test('format', function (assert) { | |
26198 var a = [ | |
26199 ['dddd, Do MMMM YYYY, h:mm:ss a', 'недеља, 14. фебруар 2010, 3:25:50 pm'], | |
26200 ['ddd, hA', 'нед., 3PM'], | |
26201 ['M Mo MM MMMM MMM', '2 2. 02 фебруар феб.'], | |
26202 ['YYYY YY', '2010 10'], | |
26203 ['D Do DD', '14 14. 14'], | |
26204 ['d do dddd ddd dd', '0 0. недеља нед. не'], | |
26205 ['DDD DDDo DDDD', '45 45. 045'], | |
26206 ['w wo ww', '7 7. 07'], | |
26207 ['h hh', '3 03'], | |
26208 ['H HH', '15 15'], | |
26209 ['m mm', '25 25'], | |
26210 ['s ss', '50 50'], | |
26211 ['a A', 'pm PM'], | |
26212 ['[the] DDDo [day of the year]', 'the 45. day of the year'], | |
26213 ['LTS', '15:25:50'], | |
26214 ['L', '14. 02. 2010'], | |
26215 ['LL', '14. фебруар 2010'], | |
26216 ['LLL', '14. фебруар 2010 15:25'], | |
26217 ['LLLL', 'недеља, 14. фебруар 2010 15:25'], | |
26218 ['l', '14. 2. 2010'], | |
26219 ['ll', '14. феб. 2010'], | |
26220 ['lll', '14. феб. 2010 15:25'], | |
26221 ['llll', 'нед., 14. феб. 2010 15:25'] | |
26222 ], | |
26223 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
26224 i; | |
26225 for (i = 0; i < a.length; i++) { | |
26226 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
26227 } | |
26228 }); | |
26229 | |
26230 test('format ordinal', function (assert) { | |
26231 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.'); | |
26232 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.'); | |
26233 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.'); | |
26234 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.'); | |
26235 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.'); | |
26236 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.'); | |
26237 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.'); | |
26238 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.'); | |
26239 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.'); | |
26240 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.'); | |
26241 | |
26242 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.'); | |
26243 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.'); | |
26244 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.'); | |
26245 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.'); | |
26246 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.'); | |
26247 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.'); | |
26248 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.'); | |
26249 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.'); | |
26250 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.'); | |
26251 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.'); | |
26252 | |
26253 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.'); | |
26254 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.'); | |
26255 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.'); | |
26256 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.'); | |
26257 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.'); | |
26258 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.'); | |
26259 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.'); | |
26260 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.'); | |
26261 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.'); | |
26262 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.'); | |
26263 | |
26264 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.'); | |
26265 }); | |
26266 | |
26267 test('format month', function (assert) { | |
26268 var expected = 'јануар јан._фебруар феб._март мар._април апр._мај мај_јун јун_јул јул_август авг._септембар сеп._октобар окт._новембар нов._децембар дец.'.split('_'), | |
26269 i; | |
26270 for (i = 0; i < expected.length; i++) { | |
26271 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
26272 } | |
26273 }); | |
26274 | |
26275 test('format week', function (assert) { | |
26276 var expected = 'недеља нед. не_понедељак пон. по_уторак уто. ут_среда сре. ср_четвртак чет. че_петак пет. пе_субота суб. су'.split('_'), | |
26277 i; | |
26278 for (i = 0; i < expected.length; i++) { | |
26279 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
26280 } | |
26281 }); | |
26282 | |
26283 test('from', function (assert) { | |
26284 var start = moment([2007, 1, 28]); | |
26285 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'неколико секунди', '44 seconds = a few seconds'); | |
26286 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'један минут', '45 seconds = a minute'); | |
26287 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'један минут', '89 seconds = a minute'); | |
26288 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 минуте', '90 seconds = 2 minutes'); | |
26289 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 минута', '44 minutes = 44 minutes'); | |
26290 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'један сат', '45 minutes = an hour'); | |
26291 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'један сат', '89 minutes = an hour'); | |
26292 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 сата', '90 minutes = 2 hours'); | |
26293 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 сати', '5 hours = 5 hours'); | |
26294 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 сати', '21 hours = 21 hours'); | |
26295 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'дан', '22 hours = a day'); | |
26296 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'дан', '35 hours = a day'); | |
26297 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 дана', '36 hours = 2 days'); | |
26298 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'дан', '1 day = a day'); | |
26299 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 дана', '5 days = 5 days'); | |
26300 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 дана', '25 days = 25 days'); | |
26301 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'месец', '26 days = a month'); | |
26302 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'месец', '30 days = a month'); | |
26303 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'месец', '43 days = a month'); | |
26304 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 месеца', '46 days = 2 months'); | |
26305 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 месеца', '75 days = 2 months'); | |
26306 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 месеца', '76 days = 3 months'); | |
26307 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'месец', '1 month = a month'); | |
26308 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 месеци', '5 months = 5 months'); | |
26309 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'годину', '345 days = a year'); | |
26310 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 године', '548 days = 2 years'); | |
26311 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'годину', '1 year = a year'); | |
26312 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 година', '5 years = 5 years'); | |
26313 }); | |
26314 | |
26315 test('suffix', function (assert) { | |
26316 assert.equal(moment(30000).from(0), 'за неколико секунди', 'prefix'); | |
26317 assert.equal(moment(0).from(30000), 'пре неколико секунди', 'prefix'); | |
26318 }); | |
26319 | |
26320 test('now from now', function (assert) { | |
26321 assert.equal(moment().fromNow(), 'пре неколико секунди', 'now from now should display as in the past'); | |
26322 }); | |
26323 | |
26324 test('fromNow', function (assert) { | |
26325 assert.equal(moment().add({s: 30}).fromNow(), 'за неколико секунди', 'in a few seconds'); | |
26326 assert.equal(moment().add({d: 5}).fromNow(), 'за 5 дана', 'in 5 days'); | |
26327 }); | |
26328 | |
26329 test('calendar day', function (assert) { | |
26330 var a = moment().hours(2).minutes(0).seconds(0); | |
26331 | |
26332 assert.equal(moment(a).calendar(), 'данас у 2:00', 'today at the same time'); | |
26333 assert.equal(moment(a).add({m: 25}).calendar(), 'данас у 2:25', 'Now plus 25 min'); | |
26334 assert.equal(moment(a).add({h: 1}).calendar(), 'данас у 3:00', 'Now plus 1 hour'); | |
26335 assert.equal(moment(a).add({d: 1}).calendar(), 'сутра у 2:00', 'tomorrow at the same time'); | |
26336 assert.equal(moment(a).subtract({h: 1}).calendar(), 'данас у 1:00', 'Now minus 1 hour'); | |
26337 assert.equal(moment(a).subtract({d: 1}).calendar(), 'јуче у 2:00', 'yesterday at the same time'); | |
26338 }); | |
26339 | |
26340 test('calendar next week', function (assert) { | |
26341 var i, m; | |
26342 | |
26343 function makeFormat(d) { | |
26344 switch (d.day()) { | |
26345 case 0: | |
26346 return '[у] [недељу] [у] LT'; | |
26347 case 3: | |
26348 return '[у] [среду] [у] LT'; | |
26349 case 6: | |
26350 return '[у] [суботу] [у] LT'; | |
26351 case 1: | |
26352 case 2: | |
26353 case 4: | |
26354 case 5: | |
26355 return '[у] dddd [у] LT'; | |
26356 } | |
26357 } | |
26358 | |
26359 for (i = 2; i < 7; i++) { | |
26360 m = moment().add({d: i}); | |
26361 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time'); | |
26362 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
26363 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day'); | |
26364 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
26365 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day'); | |
26366 } | |
26367 }); | |
26368 | |
26369 test('calendar last week', function (assert) { | |
26370 var i, m; | |
26371 | |
26372 function makeFormat(d) { | |
26373 var lastWeekDay = [ | |
26374 '[прошле] [недеље] [у] LT', | |
26375 '[прошлог] [понедељка] [у] LT', | |
26376 '[прошлог] [уторка] [у] LT', | |
26377 '[прошле] [среде] [у] LT', | |
26378 '[прошлог] [четвртка] [у] LT', | |
26379 '[прошлог] [петка] [у] LT', | |
26380 '[прошле] [суботе] [у] LT' | |
26381 ]; | |
26382 | |
26383 return lastWeekDay[d.day()]; | |
26384 } | |
26385 | |
26386 for (i = 2; i < 7; i++) { | |
26387 m = moment().subtract({d: i}); | |
26388 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time'); | |
26389 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
26390 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day'); | |
26391 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
26392 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day'); | |
26393 } | |
26394 }); | |
26395 | |
26396 test('calendar all else', function (assert) { | |
26397 var weeksAgo = moment().subtract({w: 1}), | |
26398 weeksFromNow = moment().add({w: 1}); | |
26399 | |
26400 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
26401 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
26402 | |
26403 weeksAgo = moment().subtract({w: 2}); | |
26404 weeksFromNow = moment().add({w: 2}); | |
26405 | |
26406 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
26407 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
26408 }); | |
26409 | |
26410 test('weeks year starting sunday', function (assert) { | |
26411 assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1'); | |
26412 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
26413 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2'); | |
26414 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
26415 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3'); | |
26416 }); | |
26417 | |
26418 test('weeks year starting monday', function (assert) { | |
26419 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
26420 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
26421 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
26422 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
26423 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
26424 }); | |
26425 | |
26426 test('weeks year starting tuesday', function (assert) { | |
26427 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
26428 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
26429 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
26430 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
26431 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
26432 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
26433 }); | |
26434 | |
26435 test('weeks year starting wednesday', function (assert) { | |
26436 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
26437 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
26438 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
26439 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
26440 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
26441 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
26442 }); | |
26443 | |
26444 test('weeks year starting thursday', function (assert) { | |
26445 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
26446 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
26447 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
26448 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
26449 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
26450 assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3'); | |
26451 }); | |
26452 | |
26453 test('weeks year starting friday', function (assert) { | |
26454 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1'); | |
26455 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
26456 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1'); | |
26457 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2'); | |
26458 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2'); | |
26459 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3'); | |
26460 }); | |
26461 | |
26462 test('weeks year starting saturday', function (assert) { | |
26463 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1'); | |
26464 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
26465 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1'); | |
26466 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2'); | |
26467 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2'); | |
26468 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3'); | |
26469 }); | |
26470 | |
26471 test('weeks year starting sunday formatted', function (assert) { | |
26472 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', 'Dec 26 2011 should be week 1'); | |
26473 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1.', 'Jan 1 2012 should be week 1'); | |
26474 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2.', 'Jan 2 2012 should be week 2'); | |
26475 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2.', 'Jan 8 2012 should be week 2'); | |
26476 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3.', 'Jan 9 2012 should be week 3'); | |
26477 }); | |
26478 | |
26479 test('lenient ordinal parsing', function (assert) { | |
26480 var i, ordinalStr, testMoment; | |
26481 for (i = 1; i <= 31; ++i) { | |
26482 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
26483 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
26484 assert.equal(testMoment.year(), 2014, | |
26485 'lenient ordinal parsing ' + i + ' year check'); | |
26486 assert.equal(testMoment.month(), 0, | |
26487 'lenient ordinal parsing ' + i + ' month check'); | |
26488 assert.equal(testMoment.date(), i, | |
26489 'lenient ordinal parsing ' + i + ' date check'); | |
26490 } | |
26491 }); | |
26492 | |
26493 test('lenient ordinal parsing of number', function (assert) { | |
26494 var i, testMoment; | |
26495 for (i = 1; i <= 31; ++i) { | |
26496 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
26497 assert.equal(testMoment.year(), 2014, | |
26498 'lenient ordinal parsing of number ' + i + ' year check'); | |
26499 assert.equal(testMoment.month(), 0, | |
26500 'lenient ordinal parsing of number ' + i + ' month check'); | |
26501 assert.equal(testMoment.date(), i, | |
26502 'lenient ordinal parsing of number ' + i + ' date check'); | |
26503 } | |
26504 }); | |
26505 | |
26506 test('strict ordinal parsing', function (assert) { | |
26507 var i, ordinalStr, testMoment; | |
26508 for (i = 1; i <= 31; ++i) { | |
26509 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
26510 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
26511 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
26512 } | |
26513 }); | |
26514 | |
26515 })); | |
26516 | |
26517 (function (global, factory) { | |
26518 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
26519 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
26520 factory(global.moment) | |
26521 }(this, function (moment) { 'use strict'; | |
26522 | |
26523 /*global QUnit:false*/ | |
26524 | |
26525 var test = QUnit.test; | |
26526 | |
26527 function module (name, lifecycle) { | |
26528 QUnit.module(name, { | |
26529 setup : function () { | |
26530 moment.locale('en'); | |
26531 moment.createFromInputFallback = function () { | |
26532 throw new Error('input not handled by moment'); | |
26533 }; | |
26534 if (lifecycle && lifecycle.setup) { | |
26535 lifecycle.setup(); | |
26536 } | |
26537 }, | |
26538 teardown : function () { | |
26539 if (lifecycle && lifecycle.teardown) { | |
26540 lifecycle.teardown(); | |
26541 } | |
26542 } | |
26543 }); | |
26544 } | |
26545 | |
26546 function localeModule (name, lifecycle) { | |
26547 QUnit.module('locale:' + name, { | |
26548 setup : function () { | |
26549 moment.locale(name); | |
26550 moment.createFromInputFallback = function () { | |
26551 throw new Error('input not handled by moment'); | |
26552 }; | |
26553 if (lifecycle && lifecycle.setup) { | |
26554 lifecycle.setup(); | |
26555 } | |
26556 }, | |
26557 teardown : function () { | |
26558 moment.locale('en'); | |
26559 if (lifecycle && lifecycle.teardown) { | |
26560 lifecycle.teardown(); | |
26561 } | |
26562 } | |
26563 }); | |
26564 } | |
26565 | |
26566 localeModule('sr'); | |
26567 | |
26568 test('parse', function (assert) { | |
26569 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('_'), | |
26570 i; | |
26571 function equalTest(input, mmm, i) { | |
26572 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
26573 } | |
26574 for (i = 0; i < 12; i++) { | |
26575 tests[i] = tests[i].split(' '); | |
26576 equalTest(tests[i][0], 'MMM', i); | |
26577 equalTest(tests[i][1], 'MMM', i); | |
26578 equalTest(tests[i][0], 'MMMM', i); | |
26579 equalTest(tests[i][1], 'MMMM', i); | |
26580 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
26581 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
26582 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
26583 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
26584 } | |
26585 }); | |
26586 | |
26587 test('format', function (assert) { | |
26588 var a = [ | |
26589 ['dddd, Do MMMM YYYY, h:mm:ss a', 'nedelja, 14. februar 2010, 3:25:50 pm'], | |
26590 ['ddd, hA', 'ned., 3PM'], | |
26591 ['M Mo MM MMMM MMM', '2 2. 02 februar feb.'], | |
26592 ['YYYY YY', '2010 10'], | |
26593 ['D Do DD', '14 14. 14'], | |
26594 ['d do dddd ddd dd', '0 0. nedelja ned. ne'], | |
26595 ['DDD DDDo DDDD', '45 45. 045'], | |
26596 ['w wo ww', '7 7. 07'], | |
26597 ['h hh', '3 03'], | |
26598 ['H HH', '15 15'], | |
26599 ['m mm', '25 25'], | |
26600 ['s ss', '50 50'], | |
26601 ['a A', 'pm PM'], | |
26602 ['[the] DDDo [day of the year]', 'the 45. day of the year'], | |
26603 ['LTS', '15:25:50'], | |
26604 ['L', '14. 02. 2010'], | |
26605 ['LL', '14. februar 2010'], | |
26606 ['LLL', '14. februar 2010 15:25'], | |
26607 ['LLLL', 'nedelja, 14. februar 2010 15:25'], | |
26608 ['l', '14. 2. 2010'], | |
26609 ['ll', '14. feb. 2010'], | |
26610 ['lll', '14. feb. 2010 15:25'], | |
26611 ['llll', 'ned., 14. feb. 2010 15:25'] | |
26612 ], | |
26613 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
26614 i; | |
26615 for (i = 0; i < a.length; i++) { | |
26616 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
26617 } | |
26618 }); | |
26619 | |
26620 test('format ordinal', function (assert) { | |
26621 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.'); | |
26622 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.'); | |
26623 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.'); | |
26624 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.'); | |
26625 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.'); | |
26626 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.'); | |
26627 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.'); | |
26628 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.'); | |
26629 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.'); | |
26630 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.'); | |
26631 | |
26632 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.'); | |
26633 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.'); | |
26634 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.'); | |
26635 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.'); | |
26636 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.'); | |
26637 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.'); | |
26638 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.'); | |
26639 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.'); | |
26640 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.'); | |
26641 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.'); | |
26642 | |
26643 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.'); | |
26644 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.'); | |
26645 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.'); | |
26646 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.'); | |
26647 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.'); | |
26648 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.'); | |
26649 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.'); | |
26650 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.'); | |
26651 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.'); | |
26652 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.'); | |
26653 | |
26654 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.'); | |
26655 }); | |
26656 | |
26657 test('format month', function (assert) { | |
26658 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('_'), | |
26659 i; | |
26660 for (i = 0; i < expected.length; i++) { | |
26661 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
26662 } | |
26663 }); | |
26664 | |
26665 test('format week', function (assert) { | |
26666 var expected = 'nedelja ned. ne_ponedeljak pon. po_utorak uto. ut_sreda sre. sr_četvrtak čet. če_petak pet. pe_subota sub. su'.split('_'), | |
26667 i; | |
26668 for (i = 0; i < expected.length; i++) { | |
26669 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
26670 } | |
26671 }); | |
26672 | |
26673 test('from', function (assert) { | |
26674 var start = moment([2007, 1, 28]); | |
26675 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'nekoliko sekundi', '44 seconds = a few seconds'); | |
26676 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'jedan minut', '45 seconds = a minute'); | |
26677 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'jedan minut', '89 seconds = a minute'); | |
26678 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minute', '90 seconds = 2 minutes'); | |
26679 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuta', '44 minutes = 44 minutes'); | |
26680 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'jedan sat', '45 minutes = an hour'); | |
26681 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'jedan sat', '89 minutes = an hour'); | |
26682 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 sata', '90 minutes = 2 hours'); | |
26683 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 sati', '5 hours = 5 hours'); | |
26684 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 sati', '21 hours = 21 hours'); | |
26685 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'dan', '22 hours = a day'); | |
26686 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'dan', '35 hours = a day'); | |
26687 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dana', '36 hours = 2 days'); | |
26688 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'dan', '1 day = a day'); | |
26689 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dana', '5 days = 5 days'); | |
26690 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dana', '25 days = 25 days'); | |
26691 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'mesec', '26 days = a month'); | |
26692 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'mesec', '30 days = a month'); | |
26693 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'mesec', '43 days = a month'); | |
26694 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 meseca', '46 days = 2 months'); | |
26695 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 meseca', '75 days = 2 months'); | |
26696 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 meseca', '76 days = 3 months'); | |
26697 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'mesec', '1 month = a month'); | |
26698 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 meseci', '5 months = 5 months'); | |
26699 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'godinu', '345 days = a year'); | |
26700 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 godine', '548 days = 2 years'); | |
26701 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'godinu', '1 year = a year'); | |
26702 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 godina', '5 years = 5 years'); | |
26703 }); | |
26704 | |
26705 test('suffix', function (assert) { | |
26706 assert.equal(moment(30000).from(0), 'za nekoliko sekundi', 'prefix'); | |
26707 assert.equal(moment(0).from(30000), 'pre nekoliko sekundi', 'prefix'); | |
26708 }); | |
26709 | |
26710 test('now from now', function (assert) { | |
26711 assert.equal(moment().fromNow(), 'pre nekoliko sekundi', 'now from now should display as in the past'); | |
26712 }); | |
26713 | |
26714 test('fromNow', function (assert) { | |
26715 assert.equal(moment().add({s: 30}).fromNow(), 'za nekoliko sekundi', 'in a few seconds'); | |
26716 assert.equal(moment().add({d: 5}).fromNow(), 'za 5 dana', 'in 5 days'); | |
26717 }); | |
26718 | |
26719 test('calendar day', function (assert) { | |
26720 var a = moment().hours(2).minutes(0).seconds(0); | |
26721 | |
26722 assert.equal(moment(a).calendar(), 'danas u 2:00', 'today at the same time'); | |
26723 assert.equal(moment(a).add({m: 25}).calendar(), 'danas u 2:25', 'Now plus 25 min'); | |
26724 assert.equal(moment(a).add({h: 1}).calendar(), 'danas u 3:00', 'Now plus 1 hour'); | |
26725 assert.equal(moment(a).add({d: 1}).calendar(), 'sutra u 2:00', 'tomorrow at the same time'); | |
26726 assert.equal(moment(a).subtract({h: 1}).calendar(), 'danas u 1:00', 'Now minus 1 hour'); | |
26727 assert.equal(moment(a).subtract({d: 1}).calendar(), 'juče u 2:00', 'yesterday at the same time'); | |
26728 }); | |
26729 | |
26730 test('calendar next week', function (assert) { | |
26731 var i, m; | |
26732 | |
26733 function makeFormat(d) { | |
26734 switch (d.day()) { | |
26735 case 0: | |
26736 return '[u] [nedelju] [u] LT'; | |
26737 case 3: | |
26738 return '[u] [sredu] [u] LT'; | |
26739 case 6: | |
26740 return '[u] [subotu] [u] LT'; | |
26741 case 1: | |
26742 case 2: | |
26743 case 4: | |
26744 case 5: | |
26745 return '[u] dddd [u] LT'; | |
26746 } | |
26747 } | |
26748 | |
26749 for (i = 2; i < 7; i++) { | |
26750 m = moment().add({d: i}); | |
26751 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days current time'); | |
26752 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
26753 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days beginning of day'); | |
26754 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
26755 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today + ' + i + ' days end of day'); | |
26756 } | |
26757 }); | |
26758 | |
26759 test('calendar last week', function (assert) { | |
26760 var i, m; | |
26761 | |
26762 function makeFormat(d) { | |
26763 var lastWeekDay = [ | |
26764 '[prošle] [nedelje] [u] LT', | |
26765 '[prošlog] [ponedeljka] [u] LT', | |
26766 '[prošlog] [utorka] [u] LT', | |
26767 '[prošle] [srede] [u] LT', | |
26768 '[prošlog] [četvrtka] [u] LT', | |
26769 '[prošlog] [petka] [u] LT', | |
26770 '[prošle] [subote] [u] LT' | |
26771 ]; | |
26772 | |
26773 return lastWeekDay[d.day()]; | |
26774 } | |
26775 | |
26776 for (i = 2; i < 7; i++) { | |
26777 m = moment().subtract({d: i}); | |
26778 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time'); | |
26779 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
26780 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day'); | |
26781 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
26782 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day'); | |
26783 } | |
26784 }); | |
26785 | |
26786 test('calendar all else', function (assert) { | |
26787 var weeksAgo = moment().subtract({w: 1}), | |
26788 weeksFromNow = moment().add({w: 1}); | |
26789 | |
26790 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
26791 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
26792 | |
26793 weeksAgo = moment().subtract({w: 2}); | |
26794 weeksFromNow = moment().add({w: 2}); | |
26795 | |
26796 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
26797 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
26798 }); | |
26799 | |
26800 test('weeks year starting sunday', function (assert) { | |
26801 assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1'); | |
26802 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
26803 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2'); | |
26804 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
26805 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3'); | |
26806 }); | |
26807 | |
26808 test('weeks year starting monday', function (assert) { | |
26809 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
26810 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
26811 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
26812 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
26813 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
26814 }); | |
26815 | |
26816 test('weeks year starting tuesday', function (assert) { | |
26817 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
26818 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
26819 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
26820 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
26821 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
26822 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
26823 }); | |
26824 | |
26825 test('weeks year starting wednesday', function (assert) { | |
26826 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
26827 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
26828 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
26829 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
26830 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
26831 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
26832 }); | |
26833 | |
26834 test('weeks year starting thursday', function (assert) { | |
26835 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
26836 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
26837 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
26838 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
26839 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
26840 assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3'); | |
26841 }); | |
26842 | |
26843 test('weeks year starting friday', function (assert) { | |
26844 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1'); | |
26845 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
26846 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1'); | |
26847 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2'); | |
26848 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2'); | |
26849 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3'); | |
26850 }); | |
26851 | |
26852 test('weeks year starting saturday', function (assert) { | |
26853 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1'); | |
26854 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
26855 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1'); | |
26856 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2'); | |
26857 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2'); | |
26858 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3'); | |
26859 }); | |
26860 | |
26861 test('weeks year starting sunday formatted', function (assert) { | |
26862 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1.', 'Dec 26 2011 should be week 1'); | |
26863 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1.', 'Jan 1 2012 should be week 1'); | |
26864 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2.', 'Jan 2 2012 should be week 2'); | |
26865 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2.', 'Jan 8 2012 should be week 2'); | |
26866 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3.', 'Jan 9 2012 should be week 3'); | |
26867 }); | |
26868 | |
26869 test('lenient ordinal parsing', function (assert) { | |
26870 var i, ordinalStr, testMoment; | |
26871 for (i = 1; i <= 31; ++i) { | |
26872 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
26873 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
26874 assert.equal(testMoment.year(), 2014, | |
26875 'lenient ordinal parsing ' + i + ' year check'); | |
26876 assert.equal(testMoment.month(), 0, | |
26877 'lenient ordinal parsing ' + i + ' month check'); | |
26878 assert.equal(testMoment.date(), i, | |
26879 'lenient ordinal parsing ' + i + ' date check'); | |
26880 } | |
26881 }); | |
26882 | |
26883 test('lenient ordinal parsing of number', function (assert) { | |
26884 var i, testMoment; | |
26885 for (i = 1; i <= 31; ++i) { | |
26886 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
26887 assert.equal(testMoment.year(), 2014, | |
26888 'lenient ordinal parsing of number ' + i + ' year check'); | |
26889 assert.equal(testMoment.month(), 0, | |
26890 'lenient ordinal parsing of number ' + i + ' month check'); | |
26891 assert.equal(testMoment.date(), i, | |
26892 'lenient ordinal parsing of number ' + i + ' date check'); | |
26893 } | |
26894 }); | |
26895 | |
26896 test('strict ordinal parsing', function (assert) { | |
26897 var i, ordinalStr, testMoment; | |
26898 for (i = 1; i <= 31; ++i) { | |
26899 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
26900 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
26901 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
26902 } | |
26903 }); | |
26904 | |
26905 })); | |
26906 | |
26907 (function (global, factory) { | |
26908 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
26909 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
26910 factory(global.moment) | |
26911 }(this, function (moment) { 'use strict'; | |
26912 | |
26913 /*global QUnit:false*/ | |
26914 | |
26915 var test = QUnit.test; | |
26916 | |
26917 function module (name, lifecycle) { | |
26918 QUnit.module(name, { | |
26919 setup : function () { | |
26920 moment.locale('en'); | |
26921 moment.createFromInputFallback = function () { | |
26922 throw new Error('input not handled by moment'); | |
26923 }; | |
26924 if (lifecycle && lifecycle.setup) { | |
26925 lifecycle.setup(); | |
26926 } | |
26927 }, | |
26928 teardown : function () { | |
26929 if (lifecycle && lifecycle.teardown) { | |
26930 lifecycle.teardown(); | |
26931 } | |
26932 } | |
26933 }); | |
26934 } | |
26935 | |
26936 function localeModule (name, lifecycle) { | |
26937 QUnit.module('locale:' + name, { | |
26938 setup : function () { | |
26939 moment.locale(name); | |
26940 moment.createFromInputFallback = function () { | |
26941 throw new Error('input not handled by moment'); | |
26942 }; | |
26943 if (lifecycle && lifecycle.setup) { | |
26944 lifecycle.setup(); | |
26945 } | |
26946 }, | |
26947 teardown : function () { | |
26948 moment.locale('en'); | |
26949 if (lifecycle && lifecycle.teardown) { | |
26950 lifecycle.teardown(); | |
26951 } | |
26952 } | |
26953 }); | |
26954 } | |
26955 | |
26956 localeModule('sv'); | |
26957 | |
26958 test('parse', function (assert) { | |
26959 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; | |
26960 function equalTest(input, mmm, i) { | |
26961 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
26962 } | |
26963 for (i = 0; i < 12; i++) { | |
26964 tests[i] = tests[i].split(' '); | |
26965 equalTest(tests[i][0], 'MMM', i); | |
26966 equalTest(tests[i][1], 'MMM', i); | |
26967 equalTest(tests[i][0], 'MMMM', i); | |
26968 equalTest(tests[i][1], 'MMMM', i); | |
26969 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
26970 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
26971 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
26972 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
26973 } | |
26974 }); | |
26975 | |
26976 test('format', function (assert) { | |
26977 var a = [ | |
26978 ['dddd, MMMM Do YYYY, h:mm:ss a', 'söndag, februari 14e 2010, 3:25:50 pm'], | |
26979 ['ddd, hA', 'sön, 3PM'], | |
26980 ['M Mo MM MMMM MMM', '2 2a 02 februari feb'], | |
26981 ['YYYY YY', '2010 10'], | |
26982 ['D Do DD', '14 14e 14'], | |
26983 ['d do dddd ddd dd', '0 0e söndag sön sö'], | |
26984 ['DDD DDDo DDDD', '45 45e 045'], | |
26985 ['w wo ww', '6 6e 06'], | |
26986 ['h hh', '3 03'], | |
26987 ['H HH', '15 15'], | |
26988 ['m mm', '25 25'], | |
26989 ['s ss', '50 50'], | |
26990 ['a A', 'pm PM'], | |
26991 ['[the] DDDo [day of the year]', 'the 45e day of the year'], | |
26992 ['LTS', '15:25:50'], | |
26993 ['L', '2010-02-14'], | |
26994 ['LL', '14 februari 2010'], | |
26995 ['LLL', '14 februari 2010 15:25'], | |
26996 ['LLLL', 'söndag 14 februari 2010 15:25'], | |
26997 ['l', '2010-2-14'], | |
26998 ['ll', '14 feb 2010'], | |
26999 ['lll', '14 feb 2010 15:25'], | |
27000 ['llll', 'sön 14 feb 2010 15:25'] | |
27001 ], | |
27002 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
27003 i; | |
27004 for (i = 0; i < a.length; i++) { | |
27005 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
27006 } | |
27007 }); | |
27008 | |
27009 test('format ordinal', function (assert) { | |
27010 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1a', '1a'); | |
27011 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2a', '2a'); | |
27012 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3e', '3e'); | |
27013 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4e', '4e'); | |
27014 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5e', '5e'); | |
27015 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6e', '6e'); | |
27016 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7e', '7e'); | |
27017 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8e', '8e'); | |
27018 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9e', '9e'); | |
27019 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10e', '10e'); | |
27020 | |
27021 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11e', '11e'); | |
27022 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12e', '12e'); | |
27023 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13e', '13e'); | |
27024 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14e', '14e'); | |
27025 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15e', '15e'); | |
27026 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16e', '16e'); | |
27027 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17e', '17e'); | |
27028 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18e', '18e'); | |
27029 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19e', '19e'); | |
27030 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20e', '20e'); | |
27031 | |
27032 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21a', '21a'); | |
27033 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22a', '22a'); | |
27034 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23e', '23e'); | |
27035 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24e', '24e'); | |
27036 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25e', '25e'); | |
27037 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26e', '26e'); | |
27038 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27e', '27e'); | |
27039 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28e', '28e'); | |
27040 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29e', '29e'); | |
27041 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30e', '30e'); | |
27042 | |
27043 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31a', '31a'); | |
27044 }); | |
27045 | |
27046 test('format month', function (assert) { | |
27047 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; | |
27048 for (i = 0; i < expected.length; i++) { | |
27049 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
27050 } | |
27051 }); | |
27052 | |
27053 test('format week', function (assert) { | |
27054 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; | |
27055 for (i = 0; i < expected.length; i++) { | |
27056 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
27057 } | |
27058 }); | |
27059 | |
27060 test('from', function (assert) { | |
27061 var start = moment([2007, 1, 28]); | |
27062 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'några sekunder', '44 seconds = a few seconds'); | |
27063 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'en minut', '45 seconds = a minute'); | |
27064 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'en minut', '89 seconds = a minute'); | |
27065 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuter', '90 seconds = 2 minutes'); | |
27066 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuter', '44 minutes = 44 minutes'); | |
27067 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'en timme', '45 minutes = an hour'); | |
27068 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'en timme', '89 minutes = an hour'); | |
27069 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 timmar', '90 minutes = 2 hours'); | |
27070 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 timmar', '5 hours = 5 hours'); | |
27071 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 timmar', '21 hours = 21 hours'); | |
27072 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'en dag', '22 hours = a day'); | |
27073 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'en dag', '35 hours = a day'); | |
27074 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 dagar', '36 hours = 2 days'); | |
27075 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'en dag', '1 day = a day'); | |
27076 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 dagar', '5 days = 5 days'); | |
27077 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 dagar', '25 days = 25 days'); | |
27078 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'en månad', '26 days = a month'); | |
27079 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'en månad', '30 days = a month'); | |
27080 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'en månad', '43 days = a month'); | |
27081 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 månader', '46 days = 2 months'); | |
27082 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 månader', '75 days = 2 months'); | |
27083 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 månader', '76 days = 3 months'); | |
27084 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'en månad', '1 month = a month'); | |
27085 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 månader', '5 months = 5 months'); | |
27086 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ett år', '345 days = a year'); | |
27087 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 år', '548 days = 2 years'); | |
27088 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ett år', '1 year = a year'); | |
27089 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 år', '5 years = 5 years'); | |
27090 }); | |
27091 | |
27092 test('suffix', function (assert) { | |
27093 assert.equal(moment(30000).from(0), 'om några sekunder', 'prefix'); | |
27094 assert.equal(moment(0).from(30000), 'för några sekunder sedan', 'suffix'); | |
27095 }); | |
27096 | |
27097 test('now from now', function (assert) { | |
27098 assert.equal(moment().fromNow(), 'för några sekunder sedan', 'now from now should display as in the past'); | |
27099 }); | |
27100 | |
27101 test('fromNow', function (assert) { | |
27102 assert.equal(moment().add({s: 30}).fromNow(), 'om några sekunder', 'in a few seconds'); | |
27103 assert.equal(moment().add({d: 5}).fromNow(), 'om 5 dagar', 'in 5 days'); | |
27104 }); | |
27105 | |
27106 test('calendar day', function (assert) { | |
27107 var a = moment().hours(2).minutes(0).seconds(0); | |
27108 | |
27109 assert.equal(moment(a).calendar(), 'Idag 02:00', 'today at the same time'); | |
27110 assert.equal(moment(a).add({m: 25}).calendar(), 'Idag 02:25', 'Now plus 25 min'); | |
27111 assert.equal(moment(a).add({h: 1}).calendar(), 'Idag 03:00', 'Now plus 1 hour'); | |
27112 assert.equal(moment(a).add({d: 1}).calendar(), 'Imorgon 02:00', 'tomorrow at the same time'); | |
27113 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Idag 01:00', 'Now minus 1 hour'); | |
27114 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Igår 02:00', 'yesterday at the same time'); | |
27115 }); | |
27116 | |
27117 test('calendar next week', function (assert) { | |
27118 var i, m; | |
27119 for (i = 2; i < 7; i++) { | |
27120 m = moment().add({d: i}); | |
27121 assert.equal(m.calendar(), m.format('[På] dddd LT'), 'Today + ' + i + ' days current time'); | |
27122 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
27123 assert.equal(m.calendar(), m.format('[På] dddd LT'), 'Today + ' + i + ' days beginning of day'); | |
27124 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
27125 assert.equal(m.calendar(), m.format('[På] dddd LT'), 'Today + ' + i + ' days end of day'); | |
27126 } | |
27127 }); | |
27128 | |
27129 test('calendar last week', function (assert) { | |
27130 var i, m; | |
27131 for (i = 2; i < 7; i++) { | |
27132 m = moment().subtract({d: i}); | |
27133 assert.equal(m.calendar(), m.format('[I] dddd[s] LT'), 'Today - ' + i + ' days current time'); | |
27134 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
27135 assert.equal(m.calendar(), m.format('[I] dddd[s] LT'), 'Today - ' + i + ' days beginning of day'); | |
27136 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
27137 assert.equal(m.calendar(), m.format('[I] dddd[s] LT'), 'Today - ' + i + ' days end of day'); | |
27138 } | |
27139 }); | |
27140 | |
27141 test('calendar all else', function (assert) { | |
27142 var weeksAgo = moment().subtract({w: 1}), | |
27143 weeksFromNow = moment().add({w: 1}); | |
27144 | |
27145 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
27146 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
27147 | |
27148 weeksAgo = moment().subtract({w: 2}); | |
27149 weeksFromNow = moment().add({w: 2}); | |
27150 | |
27151 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
27152 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
27153 }); | |
27154 | |
27155 test('weeks year starting sunday', function (assert) { | |
27156 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
27157 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
27158 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
27159 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
27160 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
27161 }); | |
27162 | |
27163 test('weeks year starting monday', function (assert) { | |
27164 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
27165 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
27166 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
27167 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
27168 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
27169 }); | |
27170 | |
27171 test('weeks year starting tuesday', function (assert) { | |
27172 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
27173 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
27174 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
27175 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
27176 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
27177 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
27178 }); | |
27179 | |
27180 test('weeks year starting wednesday', function (assert) { | |
27181 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
27182 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
27183 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
27184 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
27185 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
27186 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
27187 }); | |
27188 | |
27189 test('weeks year starting thursday', function (assert) { | |
27190 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
27191 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
27192 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
27193 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
27194 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
27195 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
27196 }); | |
27197 | |
27198 test('weeks year starting friday', function (assert) { | |
27199 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
27200 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
27201 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
27202 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
27203 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
27204 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
27205 }); | |
27206 | |
27207 test('weeks year starting saturday', function (assert) { | |
27208 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
27209 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
27210 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
27211 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
27212 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
27213 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
27214 }); | |
27215 | |
27216 test('weeks year starting sunday formatted', function (assert) { | |
27217 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52a', 'Jan 1 2012 should be week 52'); | |
27218 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1a', 'Jan 2 2012 should be week 1'); | |
27219 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1a', 'Jan 8 2012 should be week 1'); | |
27220 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2a', 'Jan 9 2012 should be week 2'); | |
27221 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2a', 'Jan 15 2012 should be week 2'); | |
27222 }); | |
27223 | |
27224 test('lenient ordinal parsing', function (assert) { | |
27225 var i, ordinalStr, testMoment; | |
27226 for (i = 1; i <= 31; ++i) { | |
27227 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
27228 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
27229 assert.equal(testMoment.year(), 2014, | |
27230 'lenient ordinal parsing ' + i + ' year check'); | |
27231 assert.equal(testMoment.month(), 0, | |
27232 'lenient ordinal parsing ' + i + ' month check'); | |
27233 assert.equal(testMoment.date(), i, | |
27234 'lenient ordinal parsing ' + i + ' date check'); | |
27235 } | |
27236 }); | |
27237 | |
27238 test('lenient ordinal parsing of number', function (assert) { | |
27239 var i, testMoment; | |
27240 for (i = 1; i <= 31; ++i) { | |
27241 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
27242 assert.equal(testMoment.year(), 2014, | |
27243 'lenient ordinal parsing of number ' + i + ' year check'); | |
27244 assert.equal(testMoment.month(), 0, | |
27245 'lenient ordinal parsing of number ' + i + ' month check'); | |
27246 assert.equal(testMoment.date(), i, | |
27247 'lenient ordinal parsing of number ' + i + ' date check'); | |
27248 } | |
27249 }); | |
27250 | |
27251 test('strict ordinal parsing', function (assert) { | |
27252 var i, ordinalStr, testMoment; | |
27253 for (i = 1; i <= 31; ++i) { | |
27254 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
27255 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
27256 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
27257 } | |
27258 }); | |
27259 | |
27260 })); | |
27261 | |
27262 (function (global, factory) { | |
27263 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
27264 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
27265 factory(global.moment) | |
27266 }(this, function (moment) { 'use strict'; | |
27267 | |
27268 /*global QUnit:false*/ | |
27269 | |
27270 var test = QUnit.test; | |
27271 | |
27272 function module (name, lifecycle) { | |
27273 QUnit.module(name, { | |
27274 setup : function () { | |
27275 moment.locale('en'); | |
27276 moment.createFromInputFallback = function () { | |
27277 throw new Error('input not handled by moment'); | |
27278 }; | |
27279 if (lifecycle && lifecycle.setup) { | |
27280 lifecycle.setup(); | |
27281 } | |
27282 }, | |
27283 teardown : function () { | |
27284 if (lifecycle && lifecycle.teardown) { | |
27285 lifecycle.teardown(); | |
27286 } | |
27287 } | |
27288 }); | |
27289 } | |
27290 | |
27291 function localeModule (name, lifecycle) { | |
27292 QUnit.module('locale:' + name, { | |
27293 setup : function () { | |
27294 moment.locale(name); | |
27295 moment.createFromInputFallback = function () { | |
27296 throw new Error('input not handled by moment'); | |
27297 }; | |
27298 if (lifecycle && lifecycle.setup) { | |
27299 lifecycle.setup(); | |
27300 } | |
27301 }, | |
27302 teardown : function () { | |
27303 moment.locale('en'); | |
27304 if (lifecycle && lifecycle.teardown) { | |
27305 lifecycle.teardown(); | |
27306 } | |
27307 } | |
27308 }); | |
27309 } | |
27310 | |
27311 localeModule('ta'); | |
27312 | |
27313 test('parse', function (assert) { | |
27314 var tests = 'ஜனவரி ஜனவரி_பிப்ரவரி பிப்ரவரி_மார்ச் மார்ச்_ஏப்ரல் ஏப்ரல்_மே மே_ஜூன் ஜூன்_ஜூலை ஜூலை_ஆகஸ்ட் ஆகஸ்ட்_செப்டெம்பர் செப்டெம்பர்_அக்டோபர் அக்டோபர்_நவம்பர் நவம்பர்_டிசம்பர் டிசம்பர்'.split('_'), i; | |
27315 function equalTest(input, mmm, i) { | |
27316 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
27317 } | |
27318 for (i = 0; i < 12; i++) { | |
27319 tests[i] = tests[i].split(' '); | |
27320 equalTest(tests[i][0], 'MMM', i); | |
27321 equalTest(tests[i][1], 'MMM', i); | |
27322 equalTest(tests[i][0], 'MMMM', i); | |
27323 equalTest(tests[i][1], 'MMMM', i); | |
27324 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
27325 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
27326 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
27327 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
27328 } | |
27329 }); | |
27330 | |
27331 test('format', function (assert) { | |
27332 var a = [ | |
27333 ['dddd, MMMM Do YYYY, h:mm:ss a', 'ஞாயிற்றுக்கிழமை, பிப்ரவரி 14வது 2010, 3:25:50 எற்பாடு'], | |
27334 ['ddd, hA', 'ஞாயிறு, 3 எற்பாடு'], | |
27335 ['M Mo MM MMMM MMM', '2 2வது 02 பிப்ரவரி பிப்ரவரி'], | |
27336 ['YYYY YY', '2010 10'], | |
27337 ['D Do DD', '14 14வது 14'], | |
27338 ['d do dddd ddd dd', '0 0வது ஞாயிற்றுக்கிழமை ஞாயிறு ஞா'], | |
27339 ['DDD DDDo DDDD', '45 45வது 045'], | |
27340 ['w wo ww', '8 8வது 08'], | |
27341 ['h hh', '3 03'], | |
27342 ['H HH', '15 15'], | |
27343 ['m mm', '25 25'], | |
27344 ['s ss', '50 50'], | |
27345 ['a A', ' எற்பாடு எற்பாடு'], | |
27346 ['[ஆண்டின்] DDDo [நாள்]', 'ஆண்டின் 45வது நாள்'], | |
27347 ['LTS', '15:25:50'], | |
27348 ['L', '14/02/2010'], | |
27349 ['LL', '14 பிப்ரவரி 2010'], | |
27350 ['LLL', '14 பிப்ரவரி 2010, 15:25'], | |
27351 ['LLLL', 'ஞாயிற்றுக்கிழமை, 14 பிப்ரவரி 2010, 15:25'], | |
27352 ['l', '14/2/2010'], | |
27353 ['ll', '14 பிப்ரவரி 2010'], | |
27354 ['lll', '14 பிப்ரவரி 2010, 15:25'], | |
27355 ['llll', 'ஞாயிறு, 14 பிப்ரவரி 2010, 15:25'] | |
27356 ], | |
27357 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
27358 i; | |
27359 for (i = 0; i < a.length; i++) { | |
27360 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
27361 } | |
27362 }); | |
27363 | |
27364 test('format ordinal', function (assert) { | |
27365 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1வது', '1வது'); | |
27366 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2வது', '2வது'); | |
27367 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3வது', '3வது'); | |
27368 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4வது', '4வது'); | |
27369 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5வது', '5வது'); | |
27370 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6வது', '6வது'); | |
27371 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7வது', '7வது'); | |
27372 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8வது', '8வது'); | |
27373 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9வது', '9வது'); | |
27374 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10வது', '10வது'); | |
27375 | |
27376 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11வது', '11வது'); | |
27377 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12வது', '12வது'); | |
27378 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13வது', '13வது'); | |
27379 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14வது', '14வது'); | |
27380 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15வது', '15வது'); | |
27381 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16வது', '16வது'); | |
27382 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17வது', '17வது'); | |
27383 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18வது', '18வது'); | |
27384 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19வது', '19வது'); | |
27385 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20வது', '20வது'); | |
27386 | |
27387 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21வது', '21வது'); | |
27388 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22வது', '22வது'); | |
27389 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23வது', '23வது'); | |
27390 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24வது', '24வது'); | |
27391 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25வது', '25வது'); | |
27392 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26வது', '26வது'); | |
27393 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27வது', '27வது'); | |
27394 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28வது', '28வது'); | |
27395 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29வது', '29வது'); | |
27396 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30வது', '30வது'); | |
27397 | |
27398 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31வது', '31வது'); | |
27399 }); | |
27400 | |
27401 test('format month', function (assert) { | |
27402 var expected = 'ஜனவரி ஜனவரி_பிப்ரவரி பிப்ரவரி_மார்ச் மார்ச்_ஏப்ரல் ஏப்ரல்_மே மே_ஜூன் ஜூன்_ஜூலை ஜூலை_ஆகஸ்ட் ஆகஸ்ட்_செப்டெம்பர் செப்டெம்பர்_அக்டோபர் அக்டோபர்_நவம்பர் நவம்பர்_டிசம்பர் டிசம்பர்'.split('_'), i; | |
27403 for (i = 0; i < expected.length; i++) { | |
27404 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
27405 } | |
27406 }); | |
27407 | |
27408 test('format week', function (assert) { | |
27409 var expected = 'ஞாயிற்றுக்கிழமை ஞாயிறு ஞா_திங்கட்கிழமை திங்கள் தி_செவ்வாய்கிழமை செவ்வாய் செ_புதன்கிழமை புதன் பு_வியாழக்கிழமை வியாழன் வி_வெள்ளிக்கிழமை வெள்ளி வெ_சனிக்கிழமை சனி ச'.split('_'), i; | |
27410 for (i = 0; i < expected.length; i++) { | |
27411 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
27412 } | |
27413 }); | |
27414 | |
27415 test('from', function (assert) { | |
27416 var start = moment([2007, 1, 28]); | |
27417 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ஒரு சில விநாடிகள்', '44 விநாடிகள் = ஒரு சில விநாடிகள்'); | |
27418 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ஒரு நிமிடம்', '45 விநாடிகள் = ஒரு நிமிடம்'); | |
27419 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ஒரு நிமிடம்', '89 விநாடிகள் = ஒரு நிமிடம்'); | |
27420 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 நிமிடங்கள்', '90 விநாடிகள் = 2 நிமிடங்கள்'); | |
27421 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 நிமிடங்கள்', '44 நிமிடங்கள் = 44 நிமிடங்கள்'); | |
27422 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ஒரு மணி நேரம்', '45 நிமிடங்கள் = ஒரு மணி நேரம்'); | |
27423 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ஒரு மணி நேரம்', '89 நிமிடங்கள் = ஒரு மணி நேரம்'); | |
27424 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 மணி நேரம்', '90 நிமிடங்கள் = 2 மணி நேரம்'); | |
27425 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 மணி நேரம்', '5 மணி நேரம் = 5 மணி நேரம்'); | |
27426 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 மணி நேரம்', '21 மணி நேரம் = 21 மணி நேரம்'); | |
27427 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ஒரு நாள்', '22 மணி நேரம் = ஒரு நாள்'); | |
27428 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ஒரு நாள்', '35 மணி நேரம் = ஒரு நாள்'); | |
27429 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 நாட்கள்', '36 மணி நேரம் = 2 days'); | |
27430 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ஒரு நாள்', '1 நாள் = ஒரு நாள்'); | |
27431 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 நாட்கள்', '5 நாட்கள் = 5 நாட்கள்'); | |
27432 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 நாட்கள்', '25 நாட்கள் = 25 நாட்கள்'); | |
27433 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ஒரு மாதம்', '26 நாட்கள் = ஒரு மாதம்'); | |
27434 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ஒரு மாதம்', '30 நாட்கள் = ஒரு மாதம்'); | |
27435 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ஒரு மாதம்', '45 நாட்கள் = ஒரு மாதம்'); | |
27436 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 மாதங்கள்', '46 நாட்கள் = 2 மாதங்கள்'); | |
27437 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 மாதங்கள்', '75 நாட்கள் = 2 மாதங்கள்'); | |
27438 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 மாதங்கள்', '76 நாட்கள் = 3 மாதங்கள்'); | |
27439 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ஒரு மாதம்', '1 மாதம் = ஒரு மாதம்'); | |
27440 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 மாதங்கள்', '5 மாதங்கள் = 5 மாதங்கள்'); | |
27441 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ஒரு வருடம்', '345 நாட்கள் = ஒரு வருடம்'); | |
27442 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ஆண்டுகள்', '548 நாட்கள் = 2 ஆண்டுகள்'); | |
27443 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ஒரு வருடம்', '1 வருடம் = ஒரு வருடம்'); | |
27444 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ஆண்டுகள்', '5 ஆண்டுகள் = 5 ஆண்டுகள்'); | |
27445 }); | |
27446 | |
27447 test('suffix', function (assert) { | |
27448 assert.equal(moment(30000).from(0), 'ஒரு சில விநாடிகள் இல்', 'prefix'); | |
27449 assert.equal(moment(0).from(30000), 'ஒரு சில விநாடிகள் முன்', 'suffix'); | |
27450 }); | |
27451 | |
27452 test('now from now', function (assert) { | |
27453 assert.equal(moment().fromNow(), 'ஒரு சில விநாடிகள் முன்', 'இப்போது இருந்து கடந்த காலத்தில் காட்ட வேண்டும்'); | |
27454 }); | |
27455 | |
27456 test('fromNow', function (assert) { | |
27457 assert.equal(moment().add({s: 30}).fromNow(), 'ஒரு சில விநாடிகள் இல்', 'ஒரு சில விநாடிகள் இல்'); | |
27458 assert.equal(moment().add({d: 5}).fromNow(), '5 நாட்கள் இல்', '5 நாட்கள் இல்'); | |
27459 }); | |
27460 | |
27461 test('calendar day', function (assert) { | |
27462 var a = moment().hours(2).minutes(0).seconds(0); | |
27463 | |
27464 assert.equal(moment(a).calendar(), 'இன்று 02:00', 'இன்று 02:00'); | |
27465 assert.equal(moment(a).add({m: 25}).calendar(), 'இன்று 02:25', 'இன்று 02:25'); | |
27466 assert.equal(moment(a).add({h: 1}).calendar(), 'இன்று 03:00', 'இன்று 03:00'); | |
27467 assert.equal(moment(a).add({d: 1}).calendar(), 'நாளை 02:00', 'நாளை 02:00'); | |
27468 assert.equal(moment(a).subtract({h: 1}).calendar(), 'இன்று 01:00', 'இன்று 01:00'); | |
27469 assert.equal(moment(a).subtract({d: 1}).calendar(), 'நேற்று 02:00', 'நேற்று 02:00'); | |
27470 }); | |
27471 | |
27472 test('calendar next week', function (assert) { | |
27473 var i, m; | |
27474 for (i = 2; i < 7; i++) { | |
27475 m = moment().add({d: i}); | |
27476 assert.equal(m.calendar(), m.format('dddd, LT'), 'Today + ' + i + ' days current time'); | |
27477 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
27478 assert.equal(m.calendar(), m.format('dddd, LT'), 'Today + ' + i + ' days beginning of day'); | |
27479 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
27480 assert.equal(m.calendar(), m.format('dddd, LT'), 'Today + ' + i + ' days end of day'); | |
27481 } | |
27482 }); | |
27483 | |
27484 test('calendar last week', function (assert) { | |
27485 var i, m; | |
27486 | |
27487 for (i = 2; i < 7; i++) { | |
27488 m = moment().subtract({d: i}); | |
27489 assert.equal(m.calendar(), m.format('[கடந்த வாரம்] dddd, LT'), 'Today - ' + i + ' days current time'); | |
27490 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
27491 assert.equal(m.calendar(), m.format('[கடந்த வாரம்] dddd, LT'), 'Today - ' + i + ' days beginning of day'); | |
27492 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
27493 assert.equal(m.calendar(), m.format('[கடந்த வாரம்] dddd, LT'), 'Today - ' + i + ' days end of day'); | |
27494 } | |
27495 }); | |
27496 | |
27497 test('calendar all else', function (assert) { | |
27498 var weeksAgo = moment().subtract({w: 1}), | |
27499 weeksFromNow = moment().add({w: 1}); | |
27500 | |
27501 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
27502 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
27503 | |
27504 weeksAgo = moment().subtract({w: 2}); | |
27505 weeksFromNow = moment().add({w: 2}); | |
27506 | |
27507 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
27508 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
27509 }); | |
27510 | |
27511 test('weeks year starting sunday', function (assert) { | |
27512 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
27513 assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1'); | |
27514 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
27515 assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2'); | |
27516 assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3'); | |
27517 }); | |
27518 | |
27519 test('weeks year starting monday', function (assert) { | |
27520 assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1'); | |
27521 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
27522 assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1'); | |
27523 assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2'); | |
27524 assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2'); | |
27525 assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3'); | |
27526 }); | |
27527 | |
27528 test('weeks year starting tuesday', function (assert) { | |
27529 assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52'); | |
27530 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
27531 assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1'); | |
27532 assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2'); | |
27533 assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2'); | |
27534 assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3'); | |
27535 }); | |
27536 | |
27537 test('weeks year starting wednesday', function (assert) { | |
27538 assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1'); | |
27539 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
27540 assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1'); | |
27541 assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2'); | |
27542 assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2'); | |
27543 assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3'); | |
27544 }); | |
27545 | |
27546 test('weeks year starting thursday', function (assert) { | |
27547 assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1'); | |
27548 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
27549 assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1'); | |
27550 assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2'); | |
27551 assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2'); | |
27552 assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3'); | |
27553 }); | |
27554 | |
27555 test('weeks year starting friday', function (assert) { | |
27556 assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1'); | |
27557 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
27558 assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1'); | |
27559 assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2'); | |
27560 assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2'); | |
27561 assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3'); | |
27562 }); | |
27563 | |
27564 test('weeks year starting saturday', function (assert) { | |
27565 assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1'); | |
27566 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
27567 assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2'); | |
27568 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2'); | |
27569 assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3'); | |
27570 }); | |
27571 | |
27572 test('meridiem', function (assert) { | |
27573 assert.equal(moment([2011, 2, 23, 0, 30]).format('a'), ' யாமம்', '(after) midnight'); | |
27574 assert.equal(moment([2011, 2, 23, 2, 30]).format('a'), ' வைகறை', 'before dawn'); | |
27575 assert.equal(moment([2011, 2, 23, 9, 30]).format('a'), ' காலை', 'morning'); | |
27576 assert.equal(moment([2011, 2, 23, 14, 30]).format('a'), ' எற்பாடு', 'during day'); | |
27577 assert.equal(moment([2011, 2, 23, 17, 30]).format('a'), ' எற்பாடு', 'evening'); | |
27578 assert.equal(moment([2011, 2, 23, 19, 30]).format('a'), ' மாலை', 'late evening'); | |
27579 assert.equal(moment([2011, 2, 23, 23, 30]).format('a'), ' யாமம்', '(before) midnight'); | |
27580 }); | |
27581 | |
27582 test('lenient ordinal parsing', function (assert) { | |
27583 var i, ordinalStr, testMoment; | |
27584 for (i = 1; i <= 31; ++i) { | |
27585 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
27586 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
27587 assert.equal(testMoment.year(), 2014, | |
27588 'lenient ordinal parsing ' + i + ' year check'); | |
27589 assert.equal(testMoment.month(), 0, | |
27590 'lenient ordinal parsing ' + i + ' month check'); | |
27591 assert.equal(testMoment.date(), i, | |
27592 'lenient ordinal parsing ' + i + ' date check'); | |
27593 } | |
27594 }); | |
27595 | |
27596 test('lenient ordinal parsing of number', function (assert) { | |
27597 var i, testMoment; | |
27598 for (i = 1; i <= 31; ++i) { | |
27599 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
27600 assert.equal(testMoment.year(), 2014, | |
27601 'lenient ordinal parsing of number ' + i + ' year check'); | |
27602 assert.equal(testMoment.month(), 0, | |
27603 'lenient ordinal parsing of number ' + i + ' month check'); | |
27604 assert.equal(testMoment.date(), i, | |
27605 'lenient ordinal parsing of number ' + i + ' date check'); | |
27606 } | |
27607 }); | |
27608 | |
27609 test('meridiem invariant', function (assert) { | |
27610 var h, m, t1, t2; | |
27611 for (h = 0; h < 24; ++h) { | |
27612 for (m = 0; m < 60; m += 15) { | |
27613 t1 = moment.utc([2000, 0, 1, h, m]); | |
27614 t2 = moment(t1.format('A h:mm'), 'A h:mm'); | |
27615 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'), | |
27616 'meridiem at ' + t1.format('HH:mm')); | |
27617 } | |
27618 } | |
27619 }); | |
27620 | |
27621 test('strict ordinal parsing', function (assert) { | |
27622 var i, ordinalStr, testMoment; | |
27623 for (i = 1; i <= 31; ++i) { | |
27624 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
27625 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
27626 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
27627 } | |
27628 }); | |
27629 | |
27630 })); | |
27631 | |
27632 (function (global, factory) { | |
27633 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
27634 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
27635 factory(global.moment) | |
27636 }(this, function (moment) { 'use strict'; | |
27637 | |
27638 /*global QUnit:false*/ | |
27639 | |
27640 var test = QUnit.test; | |
27641 | |
27642 function module (name, lifecycle) { | |
27643 QUnit.module(name, { | |
27644 setup : function () { | |
27645 moment.locale('en'); | |
27646 moment.createFromInputFallback = function () { | |
27647 throw new Error('input not handled by moment'); | |
27648 }; | |
27649 if (lifecycle && lifecycle.setup) { | |
27650 lifecycle.setup(); | |
27651 } | |
27652 }, | |
27653 teardown : function () { | |
27654 if (lifecycle && lifecycle.teardown) { | |
27655 lifecycle.teardown(); | |
27656 } | |
27657 } | |
27658 }); | |
27659 } | |
27660 | |
27661 function localeModule (name, lifecycle) { | |
27662 QUnit.module('locale:' + name, { | |
27663 setup : function () { | |
27664 moment.locale(name); | |
27665 moment.createFromInputFallback = function () { | |
27666 throw new Error('input not handled by moment'); | |
27667 }; | |
27668 if (lifecycle && lifecycle.setup) { | |
27669 lifecycle.setup(); | |
27670 } | |
27671 }, | |
27672 teardown : function () { | |
27673 moment.locale('en'); | |
27674 if (lifecycle && lifecycle.teardown) { | |
27675 lifecycle.teardown(); | |
27676 } | |
27677 } | |
27678 }); | |
27679 } | |
27680 | |
27681 localeModule('th'); | |
27682 | |
27683 test('parse', function (assert) { | |
27684 var tests = 'มกราคม มกรา_กุมภาพันธ์ กุมภา_มีนาคม มีนา_เมษายน เมษา_พฤษภาคม พฤษภา_มิถุนายน มิถุนา_กรกฎาคม กรกฎา_สิงหาคม สิงหา_กันยายน กันยา_ตุลาคม ตุลา_พฤศจิกายน พฤศจิกา_ธันวาคม ธันวา'.split('_'), i; | |
27685 function equalTest(input, mmm, i) { | |
27686 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
27687 } | |
27688 for (i = 0; i < 12; i++) { | |
27689 tests[i] = tests[i].split(' '); | |
27690 equalTest(tests[i][0], 'MMM', i); | |
27691 equalTest(tests[i][1], 'MMM', i); | |
27692 equalTest(tests[i][0], 'MMMM', i); | |
27693 equalTest(tests[i][1], 'MMMM', i); | |
27694 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
27695 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
27696 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
27697 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
27698 } | |
27699 }); | |
27700 | |
27701 test('format', function (assert) { | |
27702 var a = [ | |
27703 ['dddd, Do MMMM YYYY, h:mm:ss a', 'อาทิตย์, 14 กุมภาพันธ์ 2010, 3:25:50 หลังเที่ยง'], | |
27704 ['ddd, h A', 'อาทิตย์, 3 หลังเที่ยง'], | |
27705 ['M Mo MM MMMM MMM', '2 2 02 กุมภาพันธ์ กุมภา'], | |
27706 ['YYYY YY', '2010 10'], | |
27707 ['D Do DD', '14 14 14'], | |
27708 ['d do dddd ddd dd', '0 0 อาทิตย์ อาทิตย์ อา.'], | |
27709 ['DDD DDDo DDDD', '45 45 045'], | |
27710 ['w wo ww', '8 8 08'], | |
27711 ['h hh', '3 03'], | |
27712 ['H HH', '15 15'], | |
27713 ['m mm', '25 25'], | |
27714 ['s ss', '50 50'], | |
27715 ['a A', 'หลังเที่ยง หลังเที่ยง'], | |
27716 ['[the] DDDo [day of the year]', 'the 45 day of the year'], | |
27717 ['LTS', '15 นาฬิกา 25 นาที 50 วินาที'], | |
27718 ['L', '2010/02/14'], | |
27719 ['LL', '14 กุมภาพันธ์ 2010'], | |
27720 ['LLL', '14 กุมภาพันธ์ 2010 เวลา 15 นาฬิกา 25 นาที'], | |
27721 ['LLLL', 'วันอาทิตย์ที่ 14 กุมภาพันธ์ 2010 เวลา 15 นาฬิกา 25 นาที'], | |
27722 ['l', '2010/2/14'], | |
27723 ['ll', '14 กุมภา 2010'], | |
27724 ['lll', '14 กุมภา 2010 เวลา 15 นาฬิกา 25 นาที'], | |
27725 ['llll', 'วันอาทิตย์ที่ 14 กุมภา 2010 เวลา 15 นาฬิกา 25 นาที'] | |
27726 ], | |
27727 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
27728 i; | |
27729 for (i = 0; i < a.length; i++) { | |
27730 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
27731 } | |
27732 }); | |
27733 | |
27734 test('format month', function (assert) { | |
27735 var expected = 'มกราคม มกรา_กุมภาพันธ์ กุมภา_มีนาคม มีนา_เมษายน เมษา_พฤษภาคม พฤษภา_มิถุนายน มิถุนา_กรกฎาคม กรกฎา_สิงหาคม สิงหา_กันยายน กันยา_ตุลาคม ตุลา_พฤศจิกายน พฤศจิกา_ธันวาคม ธันวา'.split('_'), i; | |
27736 for (i = 0; i < expected.length; i++) { | |
27737 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
27738 } | |
27739 }); | |
27740 | |
27741 test('format week', function (assert) { | |
27742 var expected = 'อาทิตย์ อาทิตย์ อา._จันทร์ จันทร์ จ._อังคาร อังคาร อ._พุธ พุธ พ._พฤหัสบดี พฤหัส พฤ._ศุกร์ ศุกร์ ศ._เสาร์ เสาร์ ส.'.split('_'), i; | |
27743 for (i = 0; i < expected.length; i++) { | |
27744 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
27745 } | |
27746 }); | |
27747 | |
27748 test('from', function (assert) { | |
27749 var start = moment([2007, 1, 28]); | |
27750 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ไม่กี่วินาที', '44 seconds = a few seconds'); | |
27751 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '1 นาที', '45 seconds = a minute'); | |
27752 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '1 นาที', '89 seconds = a minute'); | |
27753 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 นาที', '90 seconds = 2 minutes'); | |
27754 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 นาที', '44 minutes = 44 minutes'); | |
27755 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '1 ชั่วโมง', '45 minutes = an hour'); | |
27756 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '1 ชั่วโมง', '89 minutes = an hour'); | |
27757 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ชั่วโมง', '90 minutes = 2 hours'); | |
27758 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ชั่วโมง', '5 hours = 5 hours'); | |
27759 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ชั่วโมง', '21 hours = 21 hours'); | |
27760 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '1 วัน', '22 hours = a day'); | |
27761 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '1 วัน', '35 hours = a day'); | |
27762 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 วัน', '36 hours = 2 days'); | |
27763 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '1 วัน', '1 day = a day'); | |
27764 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 วัน', '5 days = 5 days'); | |
27765 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 วัน', '25 days = 25 days'); | |
27766 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '1 เดือน', '26 days = a month'); | |
27767 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '1 เดือน', '30 days = a month'); | |
27768 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '1 เดือน', '43 days = a month'); | |
27769 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 เดือน', '46 days = 2 months'); | |
27770 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 เดือน', '75 days = 2 months'); | |
27771 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 เดือน', '76 days = 3 months'); | |
27772 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '1 เดือน', '1 month = a month'); | |
27773 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 เดือน', '5 months = 5 months'); | |
27774 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '1 ปี', '345 days = a year'); | |
27775 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ปี', '548 days = 2 years'); | |
27776 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '1 ปี', '1 year = a year'); | |
27777 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ปี', '5 years = 5 years'); | |
27778 }); | |
27779 | |
27780 test('suffix', function (assert) { | |
27781 assert.equal(moment(30000).from(0), 'อีก ไม่กี่วินาที', 'prefix'); | |
27782 assert.equal(moment(0).from(30000), 'ไม่กี่วินาทีที่แล้ว', 'suffix'); | |
27783 }); | |
27784 | |
27785 test('now from now', function (assert) { | |
27786 assert.equal(moment().fromNow(), 'ไม่กี่วินาทีที่แล้ว', 'now from now should display as in the past'); | |
27787 }); | |
27788 | |
27789 test('fromNow', function (assert) { | |
27790 assert.equal(moment().add({s: 30}).fromNow(), 'อีก ไม่กี่วินาที', 'in a few seconds'); | |
27791 assert.equal(moment().add({d: 5}).fromNow(), 'อีก 5 วัน', 'in 5 days'); | |
27792 }); | |
27793 | |
27794 test('calendar day', function (assert) { | |
27795 var a = moment().hours(2).minutes(0).seconds(0); | |
27796 | |
27797 assert.equal(moment(a).calendar(), 'วันนี้ เวลา 2 นาฬิกา 0 นาที', 'today at the same time'); | |
27798 assert.equal(moment(a).add({m: 25}).calendar(), 'วันนี้ เวลา 2 นาฬิกา 25 นาที', 'Now plus 25 min'); | |
27799 assert.equal(moment(a).add({h: 1}).calendar(), 'วันนี้ เวลา 3 นาฬิกา 0 นาที', 'Now plus 1 hour'); | |
27800 assert.equal(moment(a).add({d: 1}).calendar(), 'พรุ่งนี้ เวลา 2 นาฬิกา 0 นาที', 'tomorrow at the same time'); | |
27801 assert.equal(moment(a).subtract({h: 1}).calendar(), 'วันนี้ เวลา 1 นาฬิกา 0 นาที', 'Now minus 1 hour'); | |
27802 assert.equal(moment(a).subtract({d: 1}).calendar(), 'เมื่อวานนี้ เวลา 2 นาฬิกา 0 นาที', 'yesterday at the same time'); | |
27803 }); | |
27804 | |
27805 test('calendar next week', function (assert) { | |
27806 var i, m; | |
27807 for (i = 2; i < 7; i++) { | |
27808 m = moment().add({d: i}); | |
27809 assert.equal(m.calendar(), m.format('dddd[หน้า เวลา] LT'), 'Today + ' + i + ' days current time'); | |
27810 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
27811 assert.equal(m.calendar(), m.format('dddd[หน้า เวลา] LT'), 'Today + ' + i + ' days beginning of day'); | |
27812 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
27813 assert.equal(m.calendar(), m.format('dddd[หน้า เวลา] LT'), 'Today + ' + i + ' days end of day'); | |
27814 } | |
27815 }); | |
27816 | |
27817 test('calendar last week', function (assert) { | |
27818 var i, m; | |
27819 for (i = 2; i < 7; i++) { | |
27820 m = moment().subtract({d: i}); | |
27821 assert.equal(m.calendar(), m.format('[วัน]dddd[ที่แล้ว เวลา] LT'), 'Today - ' + i + ' days current time'); | |
27822 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
27823 assert.equal(m.calendar(), m.format('[วัน]dddd[ที่แล้ว เวลา] LT'), 'Today - ' + i + ' days beginning of day'); | |
27824 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
27825 assert.equal(m.calendar(), m.format('[วัน]dddd[ที่แล้ว เวลา] LT'), 'Today - ' + i + ' days end of day'); | |
27826 } | |
27827 }); | |
27828 | |
27829 test('calendar all else', function (assert) { | |
27830 var weeksAgo = moment().subtract({w: 1}), | |
27831 weeksFromNow = moment().add({w: 1}); | |
27832 | |
27833 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
27834 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
27835 | |
27836 weeksAgo = moment().subtract({w: 2}); | |
27837 weeksFromNow = moment().add({w: 2}); | |
27838 | |
27839 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
27840 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
27841 }); | |
27842 | |
27843 test('weeks year starting sunday', function (assert) { | |
27844 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
27845 assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1'); | |
27846 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
27847 assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2'); | |
27848 assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3'); | |
27849 }); | |
27850 | |
27851 test('weeks year starting monday', function (assert) { | |
27852 assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1'); | |
27853 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
27854 assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1'); | |
27855 assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2'); | |
27856 assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2'); | |
27857 assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3'); | |
27858 }); | |
27859 | |
27860 test('weeks year starting tuesday', function (assert) { | |
27861 assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52'); | |
27862 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
27863 assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1'); | |
27864 assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2'); | |
27865 assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2'); | |
27866 assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3'); | |
27867 }); | |
27868 | |
27869 test('weeks year starting wednesday', function (assert) { | |
27870 assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1'); | |
27871 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
27872 assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1'); | |
27873 assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2'); | |
27874 assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2'); | |
27875 assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3'); | |
27876 }); | |
27877 | |
27878 test('weeks year starting thursday', function (assert) { | |
27879 assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1'); | |
27880 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
27881 assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1'); | |
27882 assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2'); | |
27883 assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2'); | |
27884 assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3'); | |
27885 }); | |
27886 | |
27887 test('weeks year starting friday', function (assert) { | |
27888 assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1'); | |
27889 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
27890 assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1'); | |
27891 assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2'); | |
27892 assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2'); | |
27893 assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3'); | |
27894 }); | |
27895 | |
27896 test('weeks year starting saturday', function (assert) { | |
27897 assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1'); | |
27898 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
27899 assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2'); | |
27900 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2'); | |
27901 assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3'); | |
27902 }); | |
27903 | |
27904 test('weeks year starting sunday format', function (assert) { | |
27905 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 1'); | |
27906 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1', 'Jan 7 2012 should be week 1'); | |
27907 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 2'); | |
27908 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2', 'Jan 14 2012 should be week 2'); | |
27909 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', 'Jan 15 2012 should be week 3'); | |
27910 }); | |
27911 | |
27912 test('lenient ordinal parsing', function (assert) { | |
27913 var i, ordinalStr, testMoment; | |
27914 for (i = 1; i <= 31; ++i) { | |
27915 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
27916 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
27917 assert.equal(testMoment.year(), 2014, | |
27918 'lenient ordinal parsing ' + i + ' year check'); | |
27919 assert.equal(testMoment.month(), 0, | |
27920 'lenient ordinal parsing ' + i + ' month check'); | |
27921 assert.equal(testMoment.date(), i, | |
27922 'lenient ordinal parsing ' + i + ' date check'); | |
27923 } | |
27924 }); | |
27925 | |
27926 test('lenient ordinal parsing of number', function (assert) { | |
27927 var i, testMoment; | |
27928 for (i = 1; i <= 31; ++i) { | |
27929 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
27930 assert.equal(testMoment.year(), 2014, | |
27931 'lenient ordinal parsing of number ' + i + ' year check'); | |
27932 assert.equal(testMoment.month(), 0, | |
27933 'lenient ordinal parsing of number ' + i + ' month check'); | |
27934 assert.equal(testMoment.date(), i, | |
27935 'lenient ordinal parsing of number ' + i + ' date check'); | |
27936 } | |
27937 }); | |
27938 | |
27939 test('strict ordinal parsing', function (assert) { | |
27940 var i, ordinalStr, testMoment; | |
27941 for (i = 1; i <= 31; ++i) { | |
27942 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
27943 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
27944 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
27945 } | |
27946 }); | |
27947 | |
27948 })); | |
27949 | |
27950 (function (global, factory) { | |
27951 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
27952 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
27953 factory(global.moment) | |
27954 }(this, function (moment) { 'use strict'; | |
27955 | |
27956 /*global QUnit:false*/ | |
27957 | |
27958 var test = QUnit.test; | |
27959 | |
27960 function module (name, lifecycle) { | |
27961 QUnit.module(name, { | |
27962 setup : function () { | |
27963 moment.locale('en'); | |
27964 moment.createFromInputFallback = function () { | |
27965 throw new Error('input not handled by moment'); | |
27966 }; | |
27967 if (lifecycle && lifecycle.setup) { | |
27968 lifecycle.setup(); | |
27969 } | |
27970 }, | |
27971 teardown : function () { | |
27972 if (lifecycle && lifecycle.teardown) { | |
27973 lifecycle.teardown(); | |
27974 } | |
27975 } | |
27976 }); | |
27977 } | |
27978 | |
27979 function localeModule (name, lifecycle) { | |
27980 QUnit.module('locale:' + name, { | |
27981 setup : function () { | |
27982 moment.locale(name); | |
27983 moment.createFromInputFallback = function () { | |
27984 throw new Error('input not handled by moment'); | |
27985 }; | |
27986 if (lifecycle && lifecycle.setup) { | |
27987 lifecycle.setup(); | |
27988 } | |
27989 }, | |
27990 teardown : function () { | |
27991 moment.locale('en'); | |
27992 if (lifecycle && lifecycle.teardown) { | |
27993 lifecycle.teardown(); | |
27994 } | |
27995 } | |
27996 }); | |
27997 } | |
27998 | |
27999 localeModule('tl-ph'); | |
28000 | |
28001 test('parse', function (assert) { | |
28002 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('_'), | |
28003 i; | |
28004 function equalTest(input, mmm, i) { | |
28005 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
28006 } | |
28007 for (i = 0; i < 12; i++) { | |
28008 tests[i] = tests[i].split(' '); | |
28009 equalTest(tests[i][0], 'MMM', i); | |
28010 equalTest(tests[i][1], 'MMM', i); | |
28011 equalTest(tests[i][0], 'MMMM', i); | |
28012 equalTest(tests[i][1], 'MMMM', i); | |
28013 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
28014 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
28015 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
28016 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
28017 } | |
28018 }); | |
28019 | |
28020 test('format', function (assert) { | |
28021 var a = [ | |
28022 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Linggo, Pebrero 14 2010, 3:25:50 pm'], | |
28023 ['ddd, hA', 'Lin, 3PM'], | |
28024 ['M Mo MM MMMM MMM', '2 2 02 Pebrero Peb'], | |
28025 ['YYYY YY', '2010 10'], | |
28026 ['D Do DD', '14 14 14'], | |
28027 ['d do dddd ddd dd', '0 0 Linggo Lin Li'], | |
28028 ['DDD DDDo DDDD', '45 45 045'], | |
28029 ['w wo ww', '6 6 06'], | |
28030 ['h hh', '3 03'], | |
28031 ['H HH', '15 15'], | |
28032 ['m mm', '25 25'], | |
28033 ['s ss', '50 50'], | |
28034 ['a A', 'pm PM'], | |
28035 ['[the] DDDo [day of the year]', 'the 45 day of the year'], | |
28036 ['LTS', '15:25:50'], | |
28037 ['L', '02/14/2010'], | |
28038 ['LL', 'Pebrero 14, 2010'], | |
28039 ['LLL', 'Pebrero 14, 2010 15:25'], | |
28040 ['LLLL', 'Linggo, Pebrero 14, 2010 15:25'], | |
28041 ['l', '2/14/2010'], | |
28042 ['ll', 'Peb 14, 2010'], | |
28043 ['lll', 'Peb 14, 2010 15:25'], | |
28044 ['llll', 'Lin, Peb 14, 2010 15:25'] | |
28045 ], | |
28046 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
28047 i; | |
28048 for (i = 0; i < a.length; i++) { | |
28049 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
28050 } | |
28051 }); | |
28052 | |
28053 test('format ordinal', function (assert) { | |
28054 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1'); | |
28055 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2'); | |
28056 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3'); | |
28057 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4'); | |
28058 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5'); | |
28059 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6'); | |
28060 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7'); | |
28061 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8'); | |
28062 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9'); | |
28063 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10'); | |
28064 | |
28065 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11'); | |
28066 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12'); | |
28067 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13'); | |
28068 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14'); | |
28069 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15'); | |
28070 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16'); | |
28071 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17'); | |
28072 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18'); | |
28073 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19'); | |
28074 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20'); | |
28075 | |
28076 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21'); | |
28077 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22'); | |
28078 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23'); | |
28079 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24'); | |
28080 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25'); | |
28081 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26'); | |
28082 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27'); | |
28083 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28'); | |
28084 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29'); | |
28085 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30'); | |
28086 | |
28087 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31'); | |
28088 }); | |
28089 | |
28090 test('format month', function (assert) { | |
28091 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; | |
28092 for (i = 0; i < expected.length; i++) { | |
28093 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
28094 } | |
28095 }); | |
28096 | |
28097 test('format week', function (assert) { | |
28098 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; | |
28099 for (i = 0; i < expected.length; i++) { | |
28100 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
28101 } | |
28102 }); | |
28103 | |
28104 test('from', function (assert) { | |
28105 var start = moment([2007, 1, 28]); | |
28106 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ilang segundo', '44 seconds = a few seconds'); | |
28107 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'isang minuto', '45 seconds = a minute'); | |
28108 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'isang minuto', '89 seconds = a minute'); | |
28109 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuto', '90 seconds = 2 minutes'); | |
28110 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuto', '44 minutes = 44 minutes'); | |
28111 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'isang oras', '45 minutes = an hour'); | |
28112 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'isang oras', '89 minutes = an hour'); | |
28113 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 oras', '90 minutes = 2 hours'); | |
28114 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 oras', '5 hours = 5 hours'); | |
28115 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 oras', '21 hours = 21 hours'); | |
28116 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'isang araw', '22 hours = a day'); | |
28117 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'isang araw', '35 hours = a day'); | |
28118 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 araw', '36 hours = 2 days'); | |
28119 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'isang araw', '1 day = a day'); | |
28120 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 araw', '5 days = 5 days'); | |
28121 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 araw', '25 days = 25 days'); | |
28122 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'isang buwan', '26 days = a month'); | |
28123 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'isang buwan', '30 days = a month'); | |
28124 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'isang buwan', '43 days = a month'); | |
28125 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 buwan', '46 days = 2 months'); | |
28126 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 buwan', '75 days = 2 months'); | |
28127 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 buwan', '76 days = 3 months'); | |
28128 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'isang buwan', '1 month = a month'); | |
28129 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 buwan', '5 months = 5 months'); | |
28130 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'isang taon', '345 days = a year'); | |
28131 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 taon', '548 days = 2 years'); | |
28132 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'isang taon', '1 year = a year'); | |
28133 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 taon', '5 years = 5 years'); | |
28134 }); | |
28135 | |
28136 test('suffix', function (assert) { | |
28137 assert.equal(moment(30000).from(0), 'sa loob ng ilang segundo', 'prefix'); | |
28138 assert.equal(moment(0).from(30000), 'ilang segundo ang nakalipas', 'suffix'); | |
28139 }); | |
28140 | |
28141 test('fromNow', function (assert) { | |
28142 assert.equal(moment().add({s: 30}).fromNow(), 'sa loob ng ilang segundo', 'in a few seconds'); | |
28143 assert.equal(moment().add({d: 5}).fromNow(), 'sa loob ng 5 araw', 'in 5 days'); | |
28144 }); | |
28145 | |
28146 test('same day', function (assert) { | |
28147 var a = moment().hours(2).minutes(0).seconds(0); | |
28148 | |
28149 assert.equal(moment(a).calendar(), 'Ngayon sa 02:00', 'today at the same time'); | |
28150 assert.equal(moment(a).add({m: 25}).calendar(), 'Ngayon sa 02:25', 'Now plus 25 min'); | |
28151 assert.equal(moment(a).add({h: 1}).calendar(), 'Ngayon sa 03:00', 'Now plus 1 hour'); | |
28152 assert.equal(moment(a).add({d: 1}).calendar(), 'Bukas sa 02:00', 'tomorrow at the same time'); | |
28153 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Ngayon sa 01:00', 'Now minus 1 hour'); | |
28154 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Kahapon sa 02:00', 'yesterday at the same time'); | |
28155 }); | |
28156 | |
28157 test('same next week', function (assert) { | |
28158 var i, m; | |
28159 | |
28160 for (i = 2; i < 7; i++) { | |
28161 m = moment().add({d: i}); | |
28162 assert.equal(m.calendar(), m.format('dddd [sa] LT'), 'Today + ' + i + ' days current time'); | |
28163 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
28164 assert.equal(m.calendar(), m.format('dddd [sa] LT'), 'Today + ' + i + ' days beginning of day'); | |
28165 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
28166 assert.equal(m.calendar(), m.format('dddd [sa] LT'), 'Today + ' + i + ' days end of day'); | |
28167 } | |
28168 }); | |
28169 | |
28170 test('same last week', function (assert) { | |
28171 var i, m; | |
28172 | |
28173 for (i = 2; i < 7; i++) { | |
28174 m = moment().subtract({d: i}); | |
28175 assert.equal(m.calendar(), m.format('dddd [huling linggo] LT'), 'Today - ' + i + ' days current time'); | |
28176 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
28177 assert.equal(m.calendar(), m.format('dddd [huling linggo] LT'), 'Today - ' + i + ' days beginning of day'); | |
28178 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
28179 assert.equal(m.calendar(), m.format('dddd [huling linggo] LT'), 'Today - ' + i + ' days end of day'); | |
28180 } | |
28181 }); | |
28182 | |
28183 test('same all else', function (assert) { | |
28184 var weeksAgo = moment().subtract({w: 1}), | |
28185 weeksFromNow = moment().add({w: 1}); | |
28186 | |
28187 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
28188 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
28189 | |
28190 weeksAgo = moment().subtract({w: 2}); | |
28191 weeksFromNow = moment().add({w: 2}); | |
28192 | |
28193 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
28194 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
28195 }); | |
28196 | |
28197 test('weeks year starting sunday', function (assert) { | |
28198 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
28199 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
28200 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
28201 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
28202 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
28203 }); | |
28204 | |
28205 test('weeks year starting monday', function (assert) { | |
28206 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
28207 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
28208 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
28209 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
28210 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
28211 }); | |
28212 | |
28213 test('weeks year starting tuesday', function (assert) { | |
28214 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
28215 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
28216 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
28217 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
28218 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
28219 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
28220 }); | |
28221 | |
28222 test('weeks year starting wednesday', function (assert) { | |
28223 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
28224 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
28225 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
28226 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
28227 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
28228 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
28229 }); | |
28230 | |
28231 test('weeks year starting thursday', function (assert) { | |
28232 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
28233 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
28234 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
28235 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
28236 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
28237 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
28238 }); | |
28239 | |
28240 test('weeks year starting friday', function (assert) { | |
28241 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
28242 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
28243 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
28244 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
28245 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
28246 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
28247 }); | |
28248 | |
28249 test('weeks year starting saturday', function (assert) { | |
28250 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
28251 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
28252 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
28253 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
28254 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
28255 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
28256 }); | |
28257 | |
28258 test('weeks year starting sunday formatted', function (assert) { | |
28259 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52', 'Jan 1 2012 should be week 52'); | |
28260 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1', 'Jan 2 2012 should be week 1'); | |
28261 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1', 'Jan 8 2012 should be week 1'); | |
28262 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2', 'Jan 9 2012 should be week 2'); | |
28263 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2', 'Jan 15 2012 should be week 2'); | |
28264 }); | |
28265 | |
28266 test('lenient ordinal parsing', function (assert) { | |
28267 var i, ordinalStr, testMoment; | |
28268 for (i = 1; i <= 31; ++i) { | |
28269 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
28270 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
28271 assert.equal(testMoment.year(), 2014, | |
28272 'lenient ordinal parsing ' + i + ' year check'); | |
28273 assert.equal(testMoment.month(), 0, | |
28274 'lenient ordinal parsing ' + i + ' month check'); | |
28275 assert.equal(testMoment.date(), i, | |
28276 'lenient ordinal parsing ' + i + ' date check'); | |
28277 } | |
28278 }); | |
28279 | |
28280 test('lenient ordinal parsing of number', function (assert) { | |
28281 var i, testMoment; | |
28282 for (i = 1; i <= 31; ++i) { | |
28283 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
28284 assert.equal(testMoment.year(), 2014, | |
28285 'lenient ordinal parsing of number ' + i + ' year check'); | |
28286 assert.equal(testMoment.month(), 0, | |
28287 'lenient ordinal parsing of number ' + i + ' month check'); | |
28288 assert.equal(testMoment.date(), i, | |
28289 'lenient ordinal parsing of number ' + i + ' date check'); | |
28290 } | |
28291 }); | |
28292 | |
28293 test('strict ordinal parsing', function (assert) { | |
28294 var i, ordinalStr, testMoment; | |
28295 for (i = 1; i <= 31; ++i) { | |
28296 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
28297 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
28298 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
28299 } | |
28300 }); | |
28301 | |
28302 })); | |
28303 | |
28304 (function (global, factory) { | |
28305 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
28306 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
28307 factory(global.moment) | |
28308 }(this, function (moment) { 'use strict'; | |
28309 | |
28310 /*global QUnit:false*/ | |
28311 | |
28312 var test = QUnit.test; | |
28313 | |
28314 function module (name, lifecycle) { | |
28315 QUnit.module(name, { | |
28316 setup : function () { | |
28317 moment.locale('en'); | |
28318 moment.createFromInputFallback = function () { | |
28319 throw new Error('input not handled by moment'); | |
28320 }; | |
28321 if (lifecycle && lifecycle.setup) { | |
28322 lifecycle.setup(); | |
28323 } | |
28324 }, | |
28325 teardown : function () { | |
28326 if (lifecycle && lifecycle.teardown) { | |
28327 lifecycle.teardown(); | |
28328 } | |
28329 } | |
28330 }); | |
28331 } | |
28332 | |
28333 function localeModule (name, lifecycle) { | |
28334 QUnit.module('locale:' + name, { | |
28335 setup : function () { | |
28336 moment.locale(name); | |
28337 moment.createFromInputFallback = function () { | |
28338 throw new Error('input not handled by moment'); | |
28339 }; | |
28340 if (lifecycle && lifecycle.setup) { | |
28341 lifecycle.setup(); | |
28342 } | |
28343 }, | |
28344 teardown : function () { | |
28345 moment.locale('en'); | |
28346 if (lifecycle && lifecycle.teardown) { | |
28347 lifecycle.teardown(); | |
28348 } | |
28349 } | |
28350 }); | |
28351 } | |
28352 | |
28353 localeModule('tr'); | |
28354 | |
28355 test('parse', function (assert) { | |
28356 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; | |
28357 function equalTest(input, mmm, i) { | |
28358 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
28359 } | |
28360 for (i = 0; i < 12; i++) { | |
28361 tests[i] = tests[i].split(' '); | |
28362 equalTest(tests[i][0], 'MMM', i); | |
28363 equalTest(tests[i][1], 'MMM', i); | |
28364 equalTest(tests[i][0], 'MMMM', i); | |
28365 equalTest(tests[i][1], 'MMMM', i); | |
28366 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
28367 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
28368 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
28369 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
28370 } | |
28371 }); | |
28372 | |
28373 test('format', function (assert) { | |
28374 var a = [ | |
28375 ['dddd, MMMM Do YYYY, h:mm:ss a', 'Pazar, Şubat 14\'üncü 2010, 3:25:50 pm'], | |
28376 ['ddd, hA', 'Paz, 3PM'], | |
28377 ['M Mo MM MMMM MMM', '2 2\'nci 02 Şubat Şub'], | |
28378 ['YYYY YY', '2010 10'], | |
28379 ['D Do DD', '14 14\'üncü 14'], | |
28380 ['d do dddd ddd dd', '0 0\'ıncı Pazar Paz Pz'], | |
28381 ['DDD DDDo DDDD', '45 45\'inci 045'], | |
28382 ['w wo ww', '7 7\'nci 07'], | |
28383 ['h hh', '3 03'], | |
28384 ['H HH', '15 15'], | |
28385 ['m mm', '25 25'], | |
28386 ['s ss', '50 50'], | |
28387 ['a A', 'pm PM'], | |
28388 ['[yılın] DDDo [günü]', 'yılın 45\'inci günü'], | |
28389 ['LTS', '15:25:50'], | |
28390 ['L', '14.02.2010'], | |
28391 ['LL', '14 Şubat 2010'], | |
28392 ['LLL', '14 Şubat 2010 15:25'], | |
28393 ['LLLL', 'Pazar, 14 Şubat 2010 15:25'], | |
28394 ['l', '14.2.2010'], | |
28395 ['ll', '14 Şub 2010'], | |
28396 ['lll', '14 Şub 2010 15:25'], | |
28397 ['llll', 'Paz, 14 Şub 2010 15:25'] | |
28398 ], | |
28399 DDDo = [ | |
28400 [359, '360\'ıncı'], | |
28401 [199, '200\'üncü'], | |
28402 [149, '150\'nci'] | |
28403 ], | |
28404 dt = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
28405 DDDoDt, | |
28406 i; | |
28407 | |
28408 for (i = 0; i < a.length; i++) { | |
28409 assert.equal(dt.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
28410 } | |
28411 for (i = 0; i < DDDo.length; i++) { | |
28412 DDDoDt = moment([2010]); | |
28413 assert.equal(DDDoDt.add(DDDo[i][0], 'days').format('DDDo'), DDDo[i][1], DDDo[i][0] + ' ---> ' + DDDo[i][1]); | |
28414 } | |
28415 }); | |
28416 | |
28417 test('format ordinal', function (assert) { | |
28418 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1\'inci', '1st'); | |
28419 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2\'nci', '2nd'); | |
28420 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3\'üncü', '3rd'); | |
28421 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4\'üncü', '4th'); | |
28422 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5\'inci', '5th'); | |
28423 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6\'ncı', '6th'); | |
28424 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7\'nci', '7th'); | |
28425 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8\'inci', '8th'); | |
28426 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9\'uncu', '9th'); | |
28427 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10\'uncu', '10th'); | |
28428 | |
28429 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11\'inci', '11th'); | |
28430 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12\'nci', '12th'); | |
28431 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13\'üncü', '13th'); | |
28432 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14\'üncü', '14th'); | |
28433 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15\'inci', '15th'); | |
28434 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16\'ncı', '16th'); | |
28435 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17\'nci', '17th'); | |
28436 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18\'inci', '18th'); | |
28437 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19\'uncu', '19th'); | |
28438 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20\'nci', '20th'); | |
28439 | |
28440 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21\'inci', '21th'); | |
28441 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22\'nci', '22th'); | |
28442 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23\'üncü', '23th'); | |
28443 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24\'üncü', '24th'); | |
28444 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25\'inci', '25th'); | |
28445 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26\'ncı', '26th'); | |
28446 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27\'nci', '27th'); | |
28447 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28\'inci', '28th'); | |
28448 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29\'uncu', '29th'); | |
28449 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30\'uncu', '30th'); | |
28450 | |
28451 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31\'inci', '31st'); | |
28452 }); | |
28453 | |
28454 test('format month', function (assert) { | |
28455 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; | |
28456 for (i = 0; i < expected.length; i++) { | |
28457 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
28458 } | |
28459 }); | |
28460 | |
28461 test('format week', function (assert) { | |
28462 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; | |
28463 for (i = 0; i < expected.length; i++) { | |
28464 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
28465 } | |
28466 }); | |
28467 | |
28468 test('from', function (assert) { | |
28469 var start = moment([2007, 1, 28]); | |
28470 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'birkaç saniye', '44 seconds = a few seconds'); | |
28471 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'bir dakika', '45 seconds = a minute'); | |
28472 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'bir dakika', '89 seconds = a minute'); | |
28473 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 dakika', '90 seconds = 2 minutes'); | |
28474 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 dakika', '44 minutes = 44 minutes'); | |
28475 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'bir saat', '45 minutes = an hour'); | |
28476 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'bir saat', '89 minutes = an hour'); | |
28477 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 saat', '90 minutes = 2 hours'); | |
28478 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 saat', '5 hours = 5 hours'); | |
28479 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 saat', '21 hours = 21 hours'); | |
28480 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'bir gün', '22 hours = a day'); | |
28481 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'bir gün', '35 hours = a day'); | |
28482 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 gün', '36 hours = 2 days'); | |
28483 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'bir gün', '1 day = a day'); | |
28484 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 gün', '5 days = 5 days'); | |
28485 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 gün', '25 days = 25 days'); | |
28486 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'bir ay', '26 days = a month'); | |
28487 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'bir ay', '30 days = a month'); | |
28488 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'bir ay', '43 days = a month'); | |
28489 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 ay', '46 days = 2 months'); | |
28490 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 ay', '75 days = 2 months'); | |
28491 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 ay', '76 days = 3 months'); | |
28492 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'bir ay', '1 month = a month'); | |
28493 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 ay', '5 months = 5 months'); | |
28494 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'bir yıl', '345 days = a year'); | |
28495 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 yıl', '548 days = 2 years'); | |
28496 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'bir yıl', '1 year = a year'); | |
28497 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 yıl', '5 years = 5 years'); | |
28498 }); | |
28499 | |
28500 test('suffix', function (assert) { | |
28501 assert.equal(moment(30000).from(0), 'birkaç saniye sonra', 'prefix'); | |
28502 assert.equal(moment(0).from(30000), 'birkaç saniye önce', 'suffix'); | |
28503 }); | |
28504 | |
28505 test('now from now', function (assert) { | |
28506 assert.equal(moment().fromNow(), 'birkaç saniye önce', 'now from now should display as in the past'); | |
28507 }); | |
28508 | |
28509 test('fromNow', function (assert) { | |
28510 assert.equal(moment().add({s: 30}).fromNow(), 'birkaç saniye sonra', 'in a few seconds'); | |
28511 assert.equal(moment().add({d: 5}).fromNow(), '5 gün sonra', 'in 5 days'); | |
28512 }); | |
28513 | |
28514 test('calendar day', function (assert) { | |
28515 var a = moment().hours(2).minutes(0).seconds(0); | |
28516 | |
28517 assert.equal(moment(a).calendar(), 'bugün saat 02:00', 'today at the same time'); | |
28518 assert.equal(moment(a).add({m: 25}).calendar(), 'bugün saat 02:25', 'Now plus 25 min'); | |
28519 assert.equal(moment(a).add({h: 1}).calendar(), 'bugün saat 03:00', 'Now plus 1 hour'); | |
28520 assert.equal(moment(a).add({d: 1}).calendar(), 'yarın saat 02:00', 'tomorrow at the same time'); | |
28521 assert.equal(moment(a).subtract({h: 1}).calendar(), 'bugün saat 01:00', 'Now minus 1 hour'); | |
28522 assert.equal(moment(a).subtract({d: 1}).calendar(), 'dün 02:00', 'yesterday at the same time'); | |
28523 }); | |
28524 | |
28525 test('calendar next week', function (assert) { | |
28526 var i, m; | |
28527 for (i = 2; i < 7; i++) { | |
28528 m = moment().add({d: i}); | |
28529 assert.equal(m.calendar(), m.format('[haftaya] dddd [saat] LT'), 'Today + ' + i + ' days current time'); | |
28530 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
28531 assert.equal(m.calendar(), m.format('[haftaya] dddd [saat] LT'), 'Today + ' + i + ' days beginning of day'); | |
28532 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
28533 assert.equal(m.calendar(), m.format('[haftaya] dddd [saat] LT'), 'Today + ' + i + ' days end of day'); | |
28534 } | |
28535 }); | |
28536 | |
28537 test('calendar last week', function (assert) { | |
28538 var i, m; | |
28539 for (i = 2; i < 7; i++) { | |
28540 m = moment().subtract({d: i}); | |
28541 assert.equal(m.calendar(), m.format('[geçen hafta] dddd [saat] LT'), 'Today - ' + i + ' days current time'); | |
28542 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
28543 assert.equal(m.calendar(), m.format('[geçen hafta] dddd [saat] LT'), 'Today - ' + i + ' days beginning of day'); | |
28544 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
28545 assert.equal(m.calendar(), m.format('[geçen hafta] dddd [saat] LT'), 'Today - ' + i + ' days end of day'); | |
28546 } | |
28547 }); | |
28548 | |
28549 test('calendar all else', function (assert) { | |
28550 var weeksAgo = moment().subtract({w: 1}), | |
28551 weeksFromNow = moment().add({w: 1}); | |
28552 | |
28553 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
28554 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
28555 | |
28556 weeksAgo = moment().subtract({w: 2}); | |
28557 weeksFromNow = moment().add({w: 2}); | |
28558 | |
28559 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
28560 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
28561 }); | |
28562 | |
28563 test('weeks year starting sunday', function (assert) { | |
28564 assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1'); | |
28565 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
28566 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2'); | |
28567 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
28568 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3'); | |
28569 }); | |
28570 | |
28571 test('weeks year starting monday', function (assert) { | |
28572 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
28573 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
28574 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
28575 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
28576 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
28577 }); | |
28578 | |
28579 test('weeks year starting tuesday', function (assert) { | |
28580 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
28581 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
28582 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
28583 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
28584 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
28585 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
28586 }); | |
28587 | |
28588 test('weeks year starting wednesday', function (assert) { | |
28589 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
28590 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
28591 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
28592 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
28593 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
28594 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
28595 }); | |
28596 | |
28597 test('weeks year starting thursday', function (assert) { | |
28598 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
28599 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
28600 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
28601 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
28602 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
28603 assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3'); | |
28604 }); | |
28605 | |
28606 test('weeks year starting friday', function (assert) { | |
28607 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1'); | |
28608 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
28609 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1'); | |
28610 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2'); | |
28611 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2'); | |
28612 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3'); | |
28613 }); | |
28614 | |
28615 test('weeks year starting saturday', function (assert) { | |
28616 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1'); | |
28617 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
28618 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1'); | |
28619 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2'); | |
28620 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2'); | |
28621 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3'); | |
28622 }); | |
28623 | |
28624 test('weeks year starting sunday formatted', function (assert) { | |
28625 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1\'inci', 'Dec 26 2011 should be week 1'); | |
28626 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1\'inci', 'Jan 1 2012 should be week 1'); | |
28627 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2\'nci', 'Jan 2 2012 should be week 2'); | |
28628 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2\'nci', 'Jan 8 2012 should be week 2'); | |
28629 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3\'üncü', 'Jan 9 2012 should be week 3'); | |
28630 }); | |
28631 | |
28632 test('lenient ordinal parsing', function (assert) { | |
28633 var i, ordinalStr, testMoment; | |
28634 for (i = 1; i <= 31; ++i) { | |
28635 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
28636 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
28637 assert.equal(testMoment.year(), 2014, | |
28638 'lenient ordinal parsing ' + i + ' year check'); | |
28639 assert.equal(testMoment.month(), 0, | |
28640 'lenient ordinal parsing ' + i + ' month check'); | |
28641 assert.equal(testMoment.date(), i, | |
28642 'lenient ordinal parsing ' + i + ' date check'); | |
28643 } | |
28644 }); | |
28645 | |
28646 test('lenient ordinal parsing of number', function (assert) { | |
28647 var i, testMoment; | |
28648 for (i = 1; i <= 31; ++i) { | |
28649 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
28650 assert.equal(testMoment.year(), 2014, | |
28651 'lenient ordinal parsing of number ' + i + ' year check'); | |
28652 assert.equal(testMoment.month(), 0, | |
28653 'lenient ordinal parsing of number ' + i + ' month check'); | |
28654 assert.equal(testMoment.date(), i, | |
28655 'lenient ordinal parsing of number ' + i + ' date check'); | |
28656 } | |
28657 }); | |
28658 | |
28659 test('strict ordinal parsing', function (assert) { | |
28660 var i, ordinalStr, testMoment; | |
28661 for (i = 1; i <= 31; ++i) { | |
28662 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
28663 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
28664 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
28665 } | |
28666 }); | |
28667 | |
28668 })); | |
28669 | |
28670 (function (global, factory) { | |
28671 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
28672 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
28673 factory(global.moment) | |
28674 }(this, function (moment) { 'use strict'; | |
28675 | |
28676 /*global QUnit:false*/ | |
28677 | |
28678 var test = QUnit.test; | |
28679 | |
28680 function module (name, lifecycle) { | |
28681 QUnit.module(name, { | |
28682 setup : function () { | |
28683 moment.locale('en'); | |
28684 moment.createFromInputFallback = function () { | |
28685 throw new Error('input not handled by moment'); | |
28686 }; | |
28687 if (lifecycle && lifecycle.setup) { | |
28688 lifecycle.setup(); | |
28689 } | |
28690 }, | |
28691 teardown : function () { | |
28692 if (lifecycle && lifecycle.teardown) { | |
28693 lifecycle.teardown(); | |
28694 } | |
28695 } | |
28696 }); | |
28697 } | |
28698 | |
28699 function localeModule (name, lifecycle) { | |
28700 QUnit.module('locale:' + name, { | |
28701 setup : function () { | |
28702 moment.locale(name); | |
28703 moment.createFromInputFallback = function () { | |
28704 throw new Error('input not handled by moment'); | |
28705 }; | |
28706 if (lifecycle && lifecycle.setup) { | |
28707 lifecycle.setup(); | |
28708 } | |
28709 }, | |
28710 teardown : function () { | |
28711 moment.locale('en'); | |
28712 if (lifecycle && lifecycle.teardown) { | |
28713 lifecycle.teardown(); | |
28714 } | |
28715 } | |
28716 }); | |
28717 } | |
28718 | |
28719 localeModule('tzl'); | |
28720 | |
28721 test('parse', function (assert) { | |
28722 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; | |
28723 function equalTest(input, mmm, i) { | |
28724 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
28725 } | |
28726 for (i = 0; i < 12; i++) { | |
28727 tests[i] = tests[i].split(' '); | |
28728 equalTest(tests[i][0], 'MMM', i); | |
28729 equalTest(tests[i][1], 'MMM', i); | |
28730 equalTest(tests[i][0], 'MMMM', i); | |
28731 equalTest(tests[i][1], 'MMMM', i); | |
28732 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
28733 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
28734 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
28735 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
28736 } | |
28737 }); | |
28738 | |
28739 test('format', function (assert) { | |
28740 var a = [ | |
28741 ['dddd, MMMM Do YYYY, h.mm.ss a', 'Súladi, Fevraglh 14. 2010, 3.25.50 d\'o'], | |
28742 ['ddd, hA', 'Súl, 3D\'O'], | |
28743 ['M Mo MM MMMM MMM', '2 2. 02 Fevraglh Fev'], | |
28744 ['YYYY YY', '2010 10'], | |
28745 ['D Do DD', '14 14. 14'], | |
28746 ['d do dddd ddd dd', '0 0. Súladi Súl Sú'], | |
28747 ['DDD DDDo DDDD', '45 45. 045'], | |
28748 ['w wo ww', '6 6. 06'], | |
28749 ['h hh', '3 03'], | |
28750 ['H HH', '15 15'], | |
28751 ['m mm', '25 25'], | |
28752 ['s ss', '50 50'], | |
28753 ['a A', 'd\'o D\'O'], | |
28754 ['[the] DDDo [day of the year]', 'the 45. day of the year'], | |
28755 ['LTS', '15.25.50'], | |
28756 ['L', '14.02.2010'], | |
28757 ['LL', '14. Fevraglh dallas 2010'], | |
28758 ['LLL', '14. Fevraglh dallas 2010 15.25'], | |
28759 ['LLLL', 'Súladi, li 14. Fevraglh dallas 2010 15.25'], | |
28760 ['l', '14.2.2010'], | |
28761 ['ll', '14. Fev dallas 2010'], | |
28762 ['lll', '14. Fev dallas 2010 15.25'], | |
28763 ['llll', 'Súl, li 14. Fev dallas 2010 15.25'] | |
28764 ], | |
28765 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
28766 i; | |
28767 for (i = 0; i < a.length; i++) { | |
28768 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
28769 } | |
28770 }); | |
28771 | |
28772 test('format ordinal', function (assert) { | |
28773 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1.', '1.'); | |
28774 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2.', '2.'); | |
28775 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3.', '3.'); | |
28776 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4.', '4.'); | |
28777 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5.', '5.'); | |
28778 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6.', '6.'); | |
28779 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7.', '7.'); | |
28780 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8.', '8.'); | |
28781 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9.', '9.'); | |
28782 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10.', '10.'); | |
28783 | |
28784 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11.', '11.'); | |
28785 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12.', '12.'); | |
28786 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13.', '13.'); | |
28787 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14.', '14.'); | |
28788 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15.', '15.'); | |
28789 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16.', '16.'); | |
28790 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17.', '17.'); | |
28791 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18.', '18.'); | |
28792 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19.', '19.'); | |
28793 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20.', '20.'); | |
28794 | |
28795 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21.', '21.'); | |
28796 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22.', '22.'); | |
28797 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23.', '23.'); | |
28798 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24.', '24.'); | |
28799 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25.', '25.'); | |
28800 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26.', '26.'); | |
28801 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27.', '27.'); | |
28802 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28.', '28.'); | |
28803 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29.', '29.'); | |
28804 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30.', '30.'); | |
28805 | |
28806 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31.', '31.'); | |
28807 }); | |
28808 | |
28809 test('format month', function (assert) { | |
28810 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; | |
28811 for (i = 0; i < expected.length; i++) { | |
28812 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
28813 } | |
28814 }); | |
28815 | |
28816 test('format week', function (assert) { | |
28817 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; | |
28818 for (i = 0; i < expected.length; i++) { | |
28819 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
28820 } | |
28821 }); | |
28822 | |
28823 test('from', function (assert) { | |
28824 var start = moment([2007, 1, 28]); | |
28825 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'viensas secunds', '44 seconds = a few seconds'); | |
28826 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '\'n míut', '45 seconds = a minute'); | |
28827 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '\'n míut', '89 seconds = a minute'); | |
28828 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 míuts', '90 seconds = 2 minutes'); | |
28829 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 míuts', '44 minutes = 44 minutes'); | |
28830 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '\'n þora', '45 minutes = an hour'); | |
28831 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '\'n þora', '89 minutes = an hour'); | |
28832 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 þoras', '90 minutes = 2 hours'); | |
28833 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 þoras', '5 hours = 5 hours'); | |
28834 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 þoras', '21 hours = 21 hours'); | |
28835 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '\'n ziua', '22 hours = a day'); | |
28836 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '\'n ziua', '35 hours = a day'); | |
28837 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 ziuas', '36 hours = 2 days'); | |
28838 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '\'n ziua', '1 day = a day'); | |
28839 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ziuas', '5 days = 5 days'); | |
28840 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ziuas', '25 days = 25 days'); | |
28841 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '\'n mes', '26 days = a month'); | |
28842 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '\'n mes', '30 days = a month'); | |
28843 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '\'n mes', '43 days = a month'); | |
28844 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 mesen', '46 days = 2 months'); | |
28845 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 mesen', '75 days = 2 months'); | |
28846 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 mesen', '76 days = 3 months'); | |
28847 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '\'n mes', '1 month = a month'); | |
28848 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 mesen', '5 months = 5 months'); | |
28849 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '\'n ar', '345 days = a year'); | |
28850 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ars', '548 days = 2 years'); | |
28851 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '\'n ar', '1 year = a year'); | |
28852 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ars', '5 years = 5 years'); | |
28853 }); | |
28854 | |
28855 test('suffix', function (assert) { | |
28856 assert.equal(moment(30000).from(0), 'osprei viensas secunds', 'prefix'); | |
28857 assert.equal(moment(0).from(30000), 'ja\'iensas secunds', 'suffix'); | |
28858 }); | |
28859 | |
28860 test('now from now', function (assert) { | |
28861 assert.equal(moment().fromNow(), 'ja\'iensas secunds', 'now from now should display as in the past'); | |
28862 }); | |
28863 | |
28864 test('fromNow', function (assert) { | |
28865 assert.equal(moment().add({s: 30}).fromNow(), 'osprei viensas secunds', 'in a few seconds'); | |
28866 assert.equal(moment().add({d: 5}).fromNow(), 'osprei 5 ziuas', 'in 5 days'); | |
28867 }); | |
28868 | |
28869 test('calendar day', function (assert) { | |
28870 var a = moment().hours(2).minutes(0).seconds(0); | |
28871 | |
28872 assert.equal(moment(a).calendar(), 'oxhi à 02.00', 'today at the same time'); | |
28873 assert.equal(moment(a).add({m: 25}).calendar(), 'oxhi à 02.25', 'Now plus 25 min'); | |
28874 assert.equal(moment(a).add({h: 1}).calendar(), 'oxhi à 03.00', 'Now plus 1 hour'); | |
28875 assert.equal(moment(a).add({d: 1}).calendar(), 'demà à 02.00', 'tomorrow at the same time'); | |
28876 assert.equal(moment(a).subtract({h: 1}).calendar(), 'oxhi à 01.00', 'Now minus 1 hour'); | |
28877 assert.equal(moment(a).subtract({d: 1}).calendar(), 'ieiri à 02.00', 'yesterday at the same time'); | |
28878 }); | |
28879 | |
28880 test('calendar next week', function (assert) { | |
28881 var i, m; | |
28882 for (i = 2; i < 7; i++) { | |
28883 m = moment().add({d: i}); | |
28884 assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days current time'); | |
28885 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
28886 assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days beginning of day'); | |
28887 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
28888 assert.equal(m.calendar(), m.format('dddd [à] LT'), 'Today + ' + i + ' days end of day'); | |
28889 } | |
28890 }); | |
28891 | |
28892 test('calendar last week', function (assert) { | |
28893 var i, m; | |
28894 | |
28895 for (i = 2; i < 7; i++) { | |
28896 m = moment().subtract({d: i}); | |
28897 assert.equal(m.calendar(), m.format('[sür el] dddd [lasteu à] LT'), 'Today - ' + i + ' days current time'); | |
28898 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
28899 assert.equal(m.calendar(), m.format('[sür el] dddd [lasteu à] LT'), 'Today - ' + i + ' days beginning of day'); | |
28900 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
28901 assert.equal(m.calendar(), m.format('[sür el] dddd [lasteu à] LT'), 'Today - ' + i + ' days end of day'); | |
28902 } | |
28903 }); | |
28904 | |
28905 test('calendar all else', function (assert) { | |
28906 var weeksAgo = moment().subtract({w: 1}), | |
28907 weeksFromNow = moment().add({w: 1}); | |
28908 | |
28909 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
28910 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
28911 | |
28912 weeksAgo = moment().subtract({w: 2}); | |
28913 weeksFromNow = moment().add({w: 2}); | |
28914 | |
28915 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
28916 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
28917 }); | |
28918 | |
28919 // Monday is the first day of the week. | |
28920 // The week that contains Jan 4th is the first week of the year. | |
28921 | |
28922 test('weeks year starting sunday', function (assert) { | |
28923 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
28924 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
28925 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
28926 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
28927 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
28928 }); | |
28929 | |
28930 test('weeks year starting monday', function (assert) { | |
28931 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
28932 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
28933 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
28934 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
28935 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
28936 }); | |
28937 | |
28938 test('weeks year starting tuesday', function (assert) { | |
28939 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
28940 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
28941 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
28942 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
28943 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
28944 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
28945 }); | |
28946 | |
28947 test('weeks year starting wednesday', function (assert) { | |
28948 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
28949 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
28950 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
28951 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
28952 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
28953 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
28954 }); | |
28955 | |
28956 test('weeks year starting thursday', function (assert) { | |
28957 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
28958 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
28959 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
28960 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
28961 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
28962 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
28963 }); | |
28964 | |
28965 test('weeks year starting friday', function (assert) { | |
28966 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
28967 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
28968 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
28969 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
28970 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
28971 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
28972 }); | |
28973 | |
28974 test('weeks year starting saturday', function (assert) { | |
28975 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
28976 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
28977 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
28978 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
28979 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
28980 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
28981 }); | |
28982 | |
28983 test('weeks year starting sunday formatted', function (assert) { | |
28984 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52.', 'Jan 1 2012 should be week 52'); | |
28985 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1.', 'Jan 2 2012 should be week 1'); | |
28986 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1.', 'Jan 8 2012 should be week 1'); | |
28987 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2.', 'Jan 9 2012 should be week 2'); | |
28988 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2.', 'Jan 15 2012 should be week 2'); | |
28989 }); | |
28990 | |
28991 test('lenient ordinal parsing', function (assert) { | |
28992 var i, ordinalStr, testMoment; | |
28993 for (i = 1; i <= 31; ++i) { | |
28994 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
28995 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
28996 assert.equal(testMoment.year(), 2014, | |
28997 'lenient ordinal parsing ' + i + ' year check'); | |
28998 assert.equal(testMoment.month(), 0, | |
28999 'lenient ordinal parsing ' + i + ' month check'); | |
29000 assert.equal(testMoment.date(), i, | |
29001 'lenient ordinal parsing ' + i + ' date check'); | |
29002 } | |
29003 }); | |
29004 | |
29005 test('lenient ordinal parsing of number', function (assert) { | |
29006 var i, testMoment; | |
29007 for (i = 1; i <= 31; ++i) { | |
29008 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
29009 assert.equal(testMoment.year(), 2014, | |
29010 'lenient ordinal parsing of number ' + i + ' year check'); | |
29011 assert.equal(testMoment.month(), 0, | |
29012 'lenient ordinal parsing of number ' + i + ' month check'); | |
29013 assert.equal(testMoment.date(), i, | |
29014 'lenient ordinal parsing of number ' + i + ' date check'); | |
29015 } | |
29016 }); | |
29017 | |
29018 test('strict ordinal parsing', function (assert) { | |
29019 var i, ordinalStr, testMoment; | |
29020 for (i = 1; i <= 31; ++i) { | |
29021 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
29022 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
29023 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
29024 } | |
29025 }); | |
29026 | |
29027 })); | |
29028 | |
29029 (function (global, factory) { | |
29030 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
29031 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
29032 factory(global.moment) | |
29033 }(this, function (moment) { 'use strict'; | |
29034 | |
29035 /*global QUnit:false*/ | |
29036 | |
29037 var test = QUnit.test; | |
29038 | |
29039 function module (name, lifecycle) { | |
29040 QUnit.module(name, { | |
29041 setup : function () { | |
29042 moment.locale('en'); | |
29043 moment.createFromInputFallback = function () { | |
29044 throw new Error('input not handled by moment'); | |
29045 }; | |
29046 if (lifecycle && lifecycle.setup) { | |
29047 lifecycle.setup(); | |
29048 } | |
29049 }, | |
29050 teardown : function () { | |
29051 if (lifecycle && lifecycle.teardown) { | |
29052 lifecycle.teardown(); | |
29053 } | |
29054 } | |
29055 }); | |
29056 } | |
29057 | |
29058 function localeModule (name, lifecycle) { | |
29059 QUnit.module('locale:' + name, { | |
29060 setup : function () { | |
29061 moment.locale(name); | |
29062 moment.createFromInputFallback = function () { | |
29063 throw new Error('input not handled by moment'); | |
29064 }; | |
29065 if (lifecycle && lifecycle.setup) { | |
29066 lifecycle.setup(); | |
29067 } | |
29068 }, | |
29069 teardown : function () { | |
29070 moment.locale('en'); | |
29071 if (lifecycle && lifecycle.teardown) { | |
29072 lifecycle.teardown(); | |
29073 } | |
29074 } | |
29075 }); | |
29076 } | |
29077 | |
29078 localeModule('tzm-latn'); | |
29079 | |
29080 test('parse', function (assert) { | |
29081 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; | |
29082 function equalTest(input, mmm, i) { | |
29083 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
29084 } | |
29085 for (i = 0; i < 12; i++) { | |
29086 tests[i] = tests[i].split(' '); | |
29087 equalTest(tests[i][0], 'MMM', i); | |
29088 equalTest(tests[i][1], 'MMM', i); | |
29089 equalTest(tests[i][0], 'MMMM', i); | |
29090 equalTest(tests[i][1], 'MMMM', i); | |
29091 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
29092 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
29093 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
29094 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
29095 } | |
29096 }); | |
29097 | |
29098 test('format', function (assert) { | |
29099 var a = [ | |
29100 ['dddd, MMMM Do YYYY, h:mm:ss a', 'asamas, brˤayrˤ 14 2010, 3:25:50 pm'], | |
29101 ['ddd, hA', 'asamas, 3PM'], | |
29102 ['M Mo MM MMMM MMM', '2 2 02 brˤayrˤ brˤayrˤ'], | |
29103 ['YYYY YY', '2010 10'], | |
29104 ['D Do DD', '14 14 14'], | |
29105 ['d do dddd ddd dd', '0 0 asamas asamas asamas'], | |
29106 ['DDD DDDo DDDD', '45 45 045'], | |
29107 ['w wo ww', '8 8 08'], | |
29108 ['h hh', '3 03'], | |
29109 ['H HH', '15 15'], | |
29110 ['m mm', '25 25'], | |
29111 ['s ss', '50 50'], | |
29112 ['a A', 'pm PM'], | |
29113 ['[the] DDDo [day of the year]', 'the 45 day of the year'], | |
29114 ['LTS', '15:25:50'], | |
29115 ['L', '14/02/2010'], | |
29116 ['LL', '14 brˤayrˤ 2010'], | |
29117 ['LLL', '14 brˤayrˤ 2010 15:25'], | |
29118 ['LLLL', 'asamas 14 brˤayrˤ 2010 15:25'], | |
29119 ['l', '14/2/2010'], | |
29120 ['ll', '14 brˤayrˤ 2010'], | |
29121 ['lll', '14 brˤayrˤ 2010 15:25'], | |
29122 ['llll', 'asamas 14 brˤayrˤ 2010 15:25'] | |
29123 ], | |
29124 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
29125 i; | |
29126 for (i = 0; i < a.length; i++) { | |
29127 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
29128 } | |
29129 }); | |
29130 | |
29131 test('format ordinal', function (assert) { | |
29132 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1'); | |
29133 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2'); | |
29134 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3'); | |
29135 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4'); | |
29136 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5'); | |
29137 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6'); | |
29138 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7'); | |
29139 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8'); | |
29140 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9'); | |
29141 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10'); | |
29142 | |
29143 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11'); | |
29144 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12'); | |
29145 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13'); | |
29146 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14'); | |
29147 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15'); | |
29148 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16'); | |
29149 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17'); | |
29150 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18'); | |
29151 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19'); | |
29152 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20'); | |
29153 | |
29154 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21'); | |
29155 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22'); | |
29156 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23'); | |
29157 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24'); | |
29158 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25'); | |
29159 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26'); | |
29160 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27'); | |
29161 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28'); | |
29162 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29'); | |
29163 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30'); | |
29164 | |
29165 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31'); | |
29166 }); | |
29167 | |
29168 test('format month', function (assert) { | |
29169 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; | |
29170 for (i = 0; i < expected.length; i++) { | |
29171 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
29172 } | |
29173 }); | |
29174 | |
29175 test('format week', function (assert) { | |
29176 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; | |
29177 for (i = 0; i < expected.length; i++) { | |
29178 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
29179 } | |
29180 }); | |
29181 | |
29182 test('from', function (assert) { | |
29183 var start = moment([2007, 1, 28]); | |
29184 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'imik', '44 seconds = a few seconds'); | |
29185 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'minuḍ', '45 seconds = a minute'); | |
29186 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'minuḍ', '89 seconds = a minute'); | |
29187 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 minuḍ', '90 seconds = 2 minutes'); | |
29188 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 minuḍ', '44 minutes = 44 minutes'); | |
29189 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'saɛa', '45 minutes = an hour'); | |
29190 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'saɛa', '89 minutes = an hour'); | |
29191 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 tassaɛin', '90 minutes = 2 hours'); | |
29192 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 tassaɛin', '5 hours = 5 hours'); | |
29193 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 tassaɛin', '21 hours = 21 hours'); | |
29194 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ass', '22 hours = a day'); | |
29195 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ass', '35 hours = a day'); | |
29196 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 ossan', '36 hours = 2 days'); | |
29197 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ass', '1 day = a day'); | |
29198 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ossan', '5 days = 5 days'); | |
29199 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ossan', '25 days = 25 days'); | |
29200 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ayowr', '26 days = a month'); | |
29201 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ayowr', '30 days = a month'); | |
29202 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ayowr', '43 days = a month'); | |
29203 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 iyyirn', '46 days = 2 months'); | |
29204 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 iyyirn', '75 days = 2 months'); | |
29205 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 iyyirn', '76 days = 3 months'); | |
29206 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ayowr', '1 month = a month'); | |
29207 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 iyyirn', '5 months = 5 months'); | |
29208 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'asgas', '345 days = a year'); | |
29209 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 isgasn', '548 days = 2 years'); | |
29210 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'asgas', '1 year = a year'); | |
29211 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 isgasn', '5 years = 5 years'); | |
29212 }); | |
29213 | |
29214 test('suffix', function (assert) { | |
29215 assert.equal(moment(30000).from(0), 'dadkh s yan imik', 'prefix'); | |
29216 assert.equal(moment(0).from(30000), 'yan imik', 'suffix'); | |
29217 }); | |
29218 | |
29219 test('now from now', function (assert) { | |
29220 assert.equal(moment().fromNow(), 'yan imik', 'now from now should display as in the past'); | |
29221 }); | |
29222 | |
29223 test('fromNow', function (assert) { | |
29224 assert.equal(moment().add({s: 30}).fromNow(), 'dadkh s yan imik', 'in a few seconds'); | |
29225 assert.equal(moment().add({d: 5}).fromNow(), 'dadkh s yan 5 ossan', 'in 5 days'); | |
29226 }); | |
29227 | |
29228 test('calendar day', function (assert) { | |
29229 var a = moment().hours(2).minutes(0).seconds(0); | |
29230 | |
29231 assert.equal(moment(a).calendar(), 'asdkh g 02:00', 'today at the same time'); | |
29232 assert.equal(moment(a).add({m: 25}).calendar(), 'asdkh g 02:25', 'Now plus 25 min'); | |
29233 assert.equal(moment(a).add({h: 1}).calendar(), 'asdkh g 03:00', 'Now plus 1 hour'); | |
29234 assert.equal(moment(a).add({d: 1}).calendar(), 'aska g 02:00', 'tomorrow at the same time'); | |
29235 assert.equal(moment(a).subtract({h: 1}).calendar(), 'asdkh g 01:00', 'Now minus 1 hour'); | |
29236 assert.equal(moment(a).subtract({d: 1}).calendar(), 'assant g 02:00', 'yesterday at the same time'); | |
29237 }); | |
29238 | |
29239 test('calendar next week', function (assert) { | |
29240 var i, m; | |
29241 for (i = 2; i < 7; i++) { | |
29242 m = moment().add({d: i}); | |
29243 assert.equal(m.calendar(), m.format('dddd [g] LT'), 'Today + ' + i + ' days current time'); | |
29244 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
29245 assert.equal(m.calendar(), m.format('dddd [g] LT'), 'Today + ' + i + ' days beginning of day'); | |
29246 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
29247 assert.equal(m.calendar(), m.format('dddd [g] LT'), 'Today + ' + i + ' days end of day'); | |
29248 } | |
29249 }); | |
29250 | |
29251 test('calendar last week', function (assert) { | |
29252 var i, m; | |
29253 for (i = 2; i < 7; i++) { | |
29254 m = moment().subtract({d: i}); | |
29255 assert.equal(m.calendar(), m.format('dddd [g] LT'), 'Today - ' + i + ' days current time'); | |
29256 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
29257 assert.equal(m.calendar(), m.format('dddd [g] LT'), 'Today - ' + i + ' days beginning of day'); | |
29258 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
29259 assert.equal(m.calendar(), m.format('dddd [g] LT'), 'Today - ' + i + ' days end of day'); | |
29260 } | |
29261 }); | |
29262 | |
29263 test('calendar all else', function (assert) { | |
29264 var weeksAgo = moment().subtract({w: 1}), | |
29265 weeksFromNow = moment().add({w: 1}); | |
29266 | |
29267 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
29268 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
29269 | |
29270 weeksAgo = moment().subtract({w: 2}); | |
29271 weeksFromNow = moment().add({w: 2}); | |
29272 | |
29273 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
29274 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
29275 }); | |
29276 | |
29277 test('weeks year starting sunday', function (assert) { | |
29278 assert.equal(moment([2011, 11, 31]).week(), 1, 'Dec 31 2011 should be week 1'); | |
29279 assert.equal(moment([2012, 0, 6]).week(), 1, 'Jan 6 2012 should be week 1'); | |
29280 assert.equal(moment([2012, 0, 7]).week(), 2, 'Jan 7 2012 should be week 2'); | |
29281 assert.equal(moment([2012, 0, 13]).week(), 2, 'Jan 13 2012 should be week 2'); | |
29282 assert.equal(moment([2012, 0, 14]).week(), 3, 'Jan 14 2012 should be week 3'); | |
29283 }); | |
29284 | |
29285 test('weeks year starting monday', function (assert) { | |
29286 assert.equal(moment([2006, 11, 30]).week(), 1, 'Dec 30 2006 should be week 1'); | |
29287 assert.equal(moment([2007, 0, 5]).week(), 1, 'Jan 5 2007 should be week 1'); | |
29288 assert.equal(moment([2007, 0, 6]).week(), 2, 'Jan 6 2007 should be week 2'); | |
29289 assert.equal(moment([2007, 0, 12]).week(), 2, 'Jan 12 2007 should be week 2'); | |
29290 assert.equal(moment([2007, 0, 13]).week(), 3, 'Jan 13 2007 should be week 3'); | |
29291 }); | |
29292 | |
29293 test('weeks year starting tuesday', function (assert) { | |
29294 assert.equal(moment([2007, 11, 29]).week(), 1, 'Dec 29 2007 should be week 1'); | |
29295 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
29296 assert.equal(moment([2008, 0, 4]).week(), 1, 'Jan 4 2008 should be week 1'); | |
29297 assert.equal(moment([2008, 0, 5]).week(), 2, 'Jan 5 2008 should be week 2'); | |
29298 assert.equal(moment([2008, 0, 11]).week(), 2, 'Jan 11 2008 should be week 2'); | |
29299 assert.equal(moment([2008, 0, 12]).week(), 3, 'Jan 12 2008 should be week 3'); | |
29300 }); | |
29301 | |
29302 test('weeks year starting wednesday', function (assert) { | |
29303 assert.equal(moment([2002, 11, 28]).week(), 1, 'Dec 28 2002 should be week 1'); | |
29304 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
29305 assert.equal(moment([2003, 0, 3]).week(), 1, 'Jan 3 2003 should be week 1'); | |
29306 assert.equal(moment([2003, 0, 4]).week(), 2, 'Jan 4 2003 should be week 2'); | |
29307 assert.equal(moment([2003, 0, 10]).week(), 2, 'Jan 10 2003 should be week 2'); | |
29308 assert.equal(moment([2003, 0, 11]).week(), 3, 'Jan 11 2003 should be week 3'); | |
29309 }); | |
29310 | |
29311 test('weeks year starting thursday', function (assert) { | |
29312 assert.equal(moment([2008, 11, 27]).week(), 1, 'Dec 27 2008 should be week 1'); | |
29313 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
29314 assert.equal(moment([2009, 0, 2]).week(), 1, 'Jan 2 2009 should be week 1'); | |
29315 assert.equal(moment([2009, 0, 3]).week(), 2, 'Jan 3 2009 should be week 2'); | |
29316 assert.equal(moment([2009, 0, 9]).week(), 2, 'Jan 9 2009 should be week 2'); | |
29317 assert.equal(moment([2009, 0, 10]).week(), 3, 'Jan 10 2009 should be week 3'); | |
29318 }); | |
29319 | |
29320 test('weeks year starting friday', function (assert) { | |
29321 assert.equal(moment([2009, 11, 26]).week(), 1, 'Dec 26 2009 should be week 1'); | |
29322 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
29323 assert.equal(moment([2010, 0, 2]).week(), 2, 'Jan 2 2010 should be week 2'); | |
29324 assert.equal(moment([2010, 0, 8]).week(), 2, 'Jan 8 2010 should be week 2'); | |
29325 assert.equal(moment([2010, 0, 9]).week(), 3, 'Jan 9 2010 should be week 3'); | |
29326 }); | |
29327 | |
29328 test('weeks year starting saturday', function (assert) { | |
29329 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
29330 assert.equal(moment([2011, 0, 7]).week(), 1, 'Jan 7 2011 should be week 1'); | |
29331 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2'); | |
29332 assert.equal(moment([2011, 0, 14]).week(), 2, 'Jan 14 2011 should be week 2'); | |
29333 assert.equal(moment([2011, 0, 15]).week(), 3, 'Jan 15 2011 should be week 3'); | |
29334 }); | |
29335 | |
29336 test('weeks year starting sunday formatted', function (assert) { | |
29337 assert.equal(moment([2011, 11, 31]).format('w ww wo'), '1 01 1', 'Dec 31 2011 should be week 1'); | |
29338 assert.equal(moment([2012, 0, 6]).format('w ww wo'), '1 01 1', 'Jan 6 2012 should be week 1'); | |
29339 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '2 02 2', 'Jan 7 2012 should be week 2'); | |
29340 assert.equal(moment([2012, 0, 13]).format('w ww wo'), '2 02 2', 'Jan 13 2012 should be week 2'); | |
29341 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '3 03 3', 'Jan 14 2012 should be week 3'); | |
29342 }); | |
29343 | |
29344 test('lenient ordinal parsing', function (assert) { | |
29345 var i, ordinalStr, testMoment; | |
29346 for (i = 1; i <= 31; ++i) { | |
29347 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
29348 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
29349 assert.equal(testMoment.year(), 2014, | |
29350 'lenient ordinal parsing ' + i + ' year check'); | |
29351 assert.equal(testMoment.month(), 0, | |
29352 'lenient ordinal parsing ' + i + ' month check'); | |
29353 assert.equal(testMoment.date(), i, | |
29354 'lenient ordinal parsing ' + i + ' date check'); | |
29355 } | |
29356 }); | |
29357 | |
29358 test('lenient ordinal parsing of number', function (assert) { | |
29359 var i, testMoment; | |
29360 for (i = 1; i <= 31; ++i) { | |
29361 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
29362 assert.equal(testMoment.year(), 2014, | |
29363 'lenient ordinal parsing of number ' + i + ' year check'); | |
29364 assert.equal(testMoment.month(), 0, | |
29365 'lenient ordinal parsing of number ' + i + ' month check'); | |
29366 assert.equal(testMoment.date(), i, | |
29367 'lenient ordinal parsing of number ' + i + ' date check'); | |
29368 } | |
29369 }); | |
29370 | |
29371 test('strict ordinal parsing', function (assert) { | |
29372 var i, ordinalStr, testMoment; | |
29373 for (i = 1; i <= 31; ++i) { | |
29374 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
29375 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
29376 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
29377 } | |
29378 }); | |
29379 | |
29380 })); | |
29381 | |
29382 (function (global, factory) { | |
29383 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
29384 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
29385 factory(global.moment) | |
29386 }(this, function (moment) { 'use strict'; | |
29387 | |
29388 /*global QUnit:false*/ | |
29389 | |
29390 var test = QUnit.test; | |
29391 | |
29392 function module (name, lifecycle) { | |
29393 QUnit.module(name, { | |
29394 setup : function () { | |
29395 moment.locale('en'); | |
29396 moment.createFromInputFallback = function () { | |
29397 throw new Error('input not handled by moment'); | |
29398 }; | |
29399 if (lifecycle && lifecycle.setup) { | |
29400 lifecycle.setup(); | |
29401 } | |
29402 }, | |
29403 teardown : function () { | |
29404 if (lifecycle && lifecycle.teardown) { | |
29405 lifecycle.teardown(); | |
29406 } | |
29407 } | |
29408 }); | |
29409 } | |
29410 | |
29411 function localeModule (name, lifecycle) { | |
29412 QUnit.module('locale:' + name, { | |
29413 setup : function () { | |
29414 moment.locale(name); | |
29415 moment.createFromInputFallback = function () { | |
29416 throw new Error('input not handled by moment'); | |
29417 }; | |
29418 if (lifecycle && lifecycle.setup) { | |
29419 lifecycle.setup(); | |
29420 } | |
29421 }, | |
29422 teardown : function () { | |
29423 moment.locale('en'); | |
29424 if (lifecycle && lifecycle.teardown) { | |
29425 lifecycle.teardown(); | |
29426 } | |
29427 } | |
29428 }); | |
29429 } | |
29430 | |
29431 localeModule('tzm'); | |
29432 | |
29433 test('parse', function (assert) { | |
29434 var tests = 'ⵉⵏⵏⴰⵢⵔ ⵉⵏⵏⴰⵢⵔ_ⴱⵕⴰⵢⵕ ⴱⵕⴰⵢⵕ_ⵎⴰⵕⵚ ⵎⴰⵕⵚ_ⵉⴱⵔⵉⵔ ⵉⴱⵔⵉⵔ_ⵎⴰⵢⵢⵓ ⵎⴰⵢⵢⵓ_ⵢⵓⵏⵢⵓ ⵢⵓⵏⵢⵓ_ⵢⵓⵍⵢⵓⵣ ⵢⵓⵍⵢⵓⵣ_ⵖⵓⵛⵜ ⵖⵓⵛⵜ_ⵛⵓⵜⴰⵏⴱⵉⵔ ⵛⵓⵜⴰⵏⴱⵉⵔ_ⴽⵟⵓⴱⵕ ⴽⵟⵓⴱⵕ_ⵏⵓⵡⴰⵏⴱⵉⵔ ⵏⵓⵡⴰⵏⴱⵉⵔ_ⴷⵓⵊⵏⴱⵉⵔ ⴷⵓⵊⵏⴱⵉⵔ'.split('_'), i; | |
29435 function equalTest(input, mmm, i) { | |
29436 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
29437 } | |
29438 for (i = 0; i < 12; i++) { | |
29439 tests[i] = tests[i].split(' '); | |
29440 equalTest(tests[i][0], 'MMM', i); | |
29441 equalTest(tests[i][1], 'MMM', i); | |
29442 equalTest(tests[i][0], 'MMMM', i); | |
29443 equalTest(tests[i][1], 'MMMM', i); | |
29444 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
29445 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
29446 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
29447 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
29448 } | |
29449 }); | |
29450 | |
29451 test('format', function (assert) { | |
29452 var a = [ | |
29453 ['dddd, MMMM Do YYYY, h:mm:ss a', 'ⴰⵙⴰⵎⴰⵙ, ⴱⵕⴰⵢⵕ 14 2010, 3:25:50 pm'], | |
29454 ['ddd, hA', 'ⴰⵙⴰⵎⴰⵙ, 3PM'], | |
29455 ['M Mo MM MMMM MMM', '2 2 02 ⴱⵕⴰⵢⵕ ⴱⵕⴰⵢⵕ'], | |
29456 ['YYYY YY', '2010 10'], | |
29457 ['D Do DD', '14 14 14'], | |
29458 ['d do dddd ddd dd', '0 0 ⴰⵙⴰⵎⴰⵙ ⴰⵙⴰⵎⴰⵙ ⴰⵙⴰⵎⴰⵙ'], | |
29459 ['DDD DDDo DDDD', '45 45 045'], | |
29460 ['w wo ww', '8 8 08'], | |
29461 ['h hh', '3 03'], | |
29462 ['H HH', '15 15'], | |
29463 ['m mm', '25 25'], | |
29464 ['s ss', '50 50'], | |
29465 ['a A', 'pm PM'], | |
29466 ['[the] DDDo [day of the year]', 'the 45 day of the year'], | |
29467 ['LTS', '15:25:50'], | |
29468 ['L', '14/02/2010'], | |
29469 ['LL', '14 ⴱⵕⴰⵢⵕ 2010'], | |
29470 ['LLL', '14 ⴱⵕⴰⵢⵕ 2010 15:25'], | |
29471 ['LLLL', 'ⴰⵙⴰⵎⴰⵙ 14 ⴱⵕⴰⵢⵕ 2010 15:25'], | |
29472 ['l', '14/2/2010'], | |
29473 ['ll', '14 ⴱⵕⴰⵢⵕ 2010'], | |
29474 ['lll', '14 ⴱⵕⴰⵢⵕ 2010 15:25'], | |
29475 ['llll', 'ⴰⵙⴰⵎⴰⵙ 14 ⴱⵕⴰⵢⵕ 2010 15:25'] | |
29476 ], | |
29477 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
29478 i; | |
29479 for (i = 0; i < a.length; i++) { | |
29480 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
29481 } | |
29482 }); | |
29483 | |
29484 test('format ordinal', function (assert) { | |
29485 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1'); | |
29486 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2'); | |
29487 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3'); | |
29488 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4'); | |
29489 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5'); | |
29490 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6'); | |
29491 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7'); | |
29492 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8'); | |
29493 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9'); | |
29494 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10'); | |
29495 | |
29496 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11'); | |
29497 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12'); | |
29498 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13'); | |
29499 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14'); | |
29500 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15'); | |
29501 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16'); | |
29502 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17'); | |
29503 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18'); | |
29504 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19'); | |
29505 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20'); | |
29506 | |
29507 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21'); | |
29508 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22'); | |
29509 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23'); | |
29510 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24'); | |
29511 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25'); | |
29512 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26'); | |
29513 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27'); | |
29514 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28'); | |
29515 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29'); | |
29516 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30'); | |
29517 | |
29518 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31'); | |
29519 }); | |
29520 | |
29521 test('format month', function (assert) { | |
29522 var expected = 'ⵉⵏⵏⴰⵢⵔ ⵉⵏⵏⴰⵢⵔ_ⴱⵕⴰⵢⵕ ⴱⵕⴰⵢⵕ_ⵎⴰⵕⵚ ⵎⴰⵕⵚ_ⵉⴱⵔⵉⵔ ⵉⴱⵔⵉⵔ_ⵎⴰⵢⵢⵓ ⵎⴰⵢⵢⵓ_ⵢⵓⵏⵢⵓ ⵢⵓⵏⵢⵓ_ⵢⵓⵍⵢⵓⵣ ⵢⵓⵍⵢⵓⵣ_ⵖⵓⵛⵜ ⵖⵓⵛⵜ_ⵛⵓⵜⴰⵏⴱⵉⵔ ⵛⵓⵜⴰⵏⴱⵉⵔ_ⴽⵟⵓⴱⵕ ⴽⵟⵓⴱⵕ_ⵏⵓⵡⴰⵏⴱⵉⵔ ⵏⵓⵡⴰⵏⴱⵉⵔ_ⴷⵓⵊⵏⴱⵉⵔ ⴷⵓⵊⵏⴱⵉⵔ'.split('_'), i; | |
29523 for (i = 0; i < expected.length; i++) { | |
29524 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
29525 } | |
29526 }); | |
29527 | |
29528 test('format week', function (assert) { | |
29529 var expected = 'ⴰⵙⴰⵎⴰⵙ ⴰⵙⴰⵎⴰⵙ ⴰⵙⴰⵎⴰⵙ_ⴰⵢⵏⴰⵙ ⴰⵢⵏⴰⵙ ⴰⵢⵏⴰⵙ_ⴰⵙⵉⵏⴰⵙ ⴰⵙⵉⵏⴰⵙ ⴰⵙⵉⵏⴰⵙ_ⴰⴽⵔⴰⵙ ⴰⴽⵔⴰⵙ ⴰⴽⵔⴰⵙ_ⴰⴽⵡⴰⵙ ⴰⴽⵡⴰⵙ ⴰⴽⵡⴰⵙ_ⴰⵙⵉⵎⵡⴰⵙ ⴰⵙⵉⵎⵡⴰⵙ ⴰⵙⵉⵎⵡⴰⵙ_ⴰⵙⵉⴹⵢⴰⵙ ⴰⵙⵉⴹⵢⴰⵙ ⴰⵙⵉⴹⵢⴰⵙ'.split('_'), i; | |
29530 for (i = 0; i < expected.length; i++) { | |
29531 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
29532 } | |
29533 }); | |
29534 | |
29535 test('from', function (assert) { | |
29536 var start = moment([2007, 1, 28]); | |
29537 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'ⵉⵎⵉⴽ', '44 seconds = a few seconds'); | |
29538 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'ⵎⵉⵏⵓⴺ', '45 seconds = a minute'); | |
29539 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'ⵎⵉⵏⵓⴺ', '89 seconds = a minute'); | |
29540 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 ⵎⵉⵏⵓⴺ', '90 seconds = 2 minutes'); | |
29541 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 ⵎⵉⵏⵓⴺ', '44 minutes = 44 minutes'); | |
29542 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'ⵙⴰⵄⴰ', '45 minutes = an hour'); | |
29543 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'ⵙⴰⵄⴰ', '89 minutes = an hour'); | |
29544 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 ⵜⴰⵙⵙⴰⵄⵉⵏ', '90 minutes = 2 hours'); | |
29545 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 ⵜⴰⵙⵙⴰⵄⵉⵏ', '5 hours = 5 hours'); | |
29546 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 ⵜⴰⵙⵙⴰⵄⵉⵏ', '21 hours = 21 hours'); | |
29547 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'ⴰⵙⵙ', '22 hours = a day'); | |
29548 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'ⴰⵙⵙ', '35 hours = a day'); | |
29549 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 oⵙⵙⴰⵏ', '36 hours = 2 days'); | |
29550 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'ⴰⵙⵙ', '1 day = a day'); | |
29551 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 oⵙⵙⴰⵏ', '5 days = 5 days'); | |
29552 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 oⵙⵙⴰⵏ', '25 days = 25 days'); | |
29553 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'ⴰⵢoⵓⵔ', '26 days = a month'); | |
29554 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'ⴰⵢoⵓⵔ', '30 days = a month'); | |
29555 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'ⴰⵢoⵓⵔ', '43 days = a month'); | |
29556 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 ⵉⵢⵢⵉⵔⵏ', '46 days = 2 months'); | |
29557 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 ⵉⵢⵢⵉⵔⵏ', '75 days = 2 months'); | |
29558 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 ⵉⵢⵢⵉⵔⵏ', '76 days = 3 months'); | |
29559 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'ⴰⵢoⵓⵔ', '1 month = a month'); | |
29560 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 ⵉⵢⵢⵉⵔⵏ', '5 months = 5 months'); | |
29561 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'ⴰⵙⴳⴰⵙ', '345 days = a year'); | |
29562 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 ⵉⵙⴳⴰⵙⵏ', '548 days = 2 years'); | |
29563 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'ⴰⵙⴳⴰⵙ', '1 year = a year'); | |
29564 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 ⵉⵙⴳⴰⵙⵏ', '5 years = 5 years'); | |
29565 }); | |
29566 | |
29567 test('suffix', function (assert) { | |
29568 assert.equal(moment(30000).from(0), 'ⴷⴰⴷⵅ ⵙ ⵢⴰⵏ ⵉⵎⵉⴽ', 'prefix'); | |
29569 assert.equal(moment(0).from(30000), 'ⵢⴰⵏ ⵉⵎⵉⴽ', 'suffix'); | |
29570 }); | |
29571 | |
29572 test('now from now', function (assert) { | |
29573 assert.equal(moment().fromNow(), 'ⵢⴰⵏ ⵉⵎⵉⴽ', 'now from now should display as in the past'); | |
29574 }); | |
29575 | |
29576 test('fromNow', function (assert) { | |
29577 assert.equal(moment().add({s: 30}).fromNow(), 'ⴷⴰⴷⵅ ⵙ ⵢⴰⵏ ⵉⵎⵉⴽ', 'in a few seconds'); | |
29578 assert.equal(moment().add({d: 5}).fromNow(), 'ⴷⴰⴷⵅ ⵙ ⵢⴰⵏ 5 oⵙⵙⴰⵏ', 'in 5 days'); | |
29579 }); | |
29580 | |
29581 test('calendar day', function (assert) { | |
29582 var a = moment().hours(2).minutes(0).seconds(0); | |
29583 | |
29584 assert.equal(moment(a).calendar(), 'ⴰⵙⴷⵅ ⴴ 02:00', 'today at the same time'); | |
29585 assert.equal(moment(a).add({m: 25}).calendar(), 'ⴰⵙⴷⵅ ⴴ 02:25', 'Now plus 25 min'); | |
29586 assert.equal(moment(a).add({h: 1}).calendar(), 'ⴰⵙⴷⵅ ⴴ 03:00', 'Now plus 1 hour'); | |
29587 assert.equal(moment(a).add({d: 1}).calendar(), 'ⴰⵙⴽⴰ ⴴ 02:00', 'tomorrow at the same time'); | |
29588 assert.equal(moment(a).subtract({h: 1}).calendar(), 'ⴰⵙⴷⵅ ⴴ 01:00', 'Now minus 1 hour'); | |
29589 assert.equal(moment(a).subtract({d: 1}).calendar(), 'ⴰⵚⴰⵏⵜ ⴴ 02:00', 'yesterday at the same time'); | |
29590 }); | |
29591 | |
29592 test('calendar next week', function (assert) { | |
29593 var i, m; | |
29594 for (i = 2; i < 7; i++) { | |
29595 m = moment().add({d: i}); | |
29596 assert.equal(m.calendar(), m.format('dddd [ⴴ] LT'), 'Today + ' + i + ' days current time'); | |
29597 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
29598 assert.equal(m.calendar(), m.format('dddd [ⴴ] LT'), 'Today + ' + i + ' days beginning of day'); | |
29599 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
29600 assert.equal(m.calendar(), m.format('dddd [ⴴ] LT'), 'Today + ' + i + ' days end of day'); | |
29601 } | |
29602 }); | |
29603 | |
29604 test('calendar last week', function (assert) { | |
29605 var i, m; | |
29606 for (i = 2; i < 7; i++) { | |
29607 m = moment().subtract({d: i}); | |
29608 assert.equal(m.calendar(), m.format('dddd [ⴴ] LT'), 'Today - ' + i + ' days current time'); | |
29609 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
29610 assert.equal(m.calendar(), m.format('dddd [ⴴ] LT'), 'Today - ' + i + ' days beginning of day'); | |
29611 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
29612 assert.equal(m.calendar(), m.format('dddd [ⴴ] LT'), 'Today - ' + i + ' days end of day'); | |
29613 } | |
29614 }); | |
29615 | |
29616 test('calendar all else', function (assert) { | |
29617 var weeksAgo = moment().subtract({w: 1}), | |
29618 weeksFromNow = moment().add({w: 1}); | |
29619 | |
29620 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
29621 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
29622 | |
29623 weeksAgo = moment().subtract({w: 2}); | |
29624 weeksFromNow = moment().add({w: 2}); | |
29625 | |
29626 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
29627 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
29628 }); | |
29629 | |
29630 test('weeks year starting sunday', function (assert) { | |
29631 assert.equal(moment([2011, 11, 31]).week(), 1, 'Dec 31 2011 should be week 1'); | |
29632 assert.equal(moment([2012, 0, 6]).week(), 1, 'Jan 6 2012 should be week 1'); | |
29633 assert.equal(moment([2012, 0, 7]).week(), 2, 'Jan 7 2012 should be week 2'); | |
29634 assert.equal(moment([2012, 0, 13]).week(), 2, 'Jan 13 2012 should be week 2'); | |
29635 assert.equal(moment([2012, 0, 14]).week(), 3, 'Jan 14 2012 should be week 3'); | |
29636 }); | |
29637 | |
29638 test('weeks year starting monday', function (assert) { | |
29639 assert.equal(moment([2006, 11, 30]).week(), 1, 'Dec 30 2006 should be week 1'); | |
29640 assert.equal(moment([2007, 0, 5]).week(), 1, 'Jan 5 2007 should be week 1'); | |
29641 assert.equal(moment([2007, 0, 6]).week(), 2, 'Jan 6 2007 should be week 2'); | |
29642 assert.equal(moment([2007, 0, 12]).week(), 2, 'Jan 12 2007 should be week 2'); | |
29643 assert.equal(moment([2007, 0, 13]).week(), 3, 'Jan 13 2007 should be week 3'); | |
29644 }); | |
29645 | |
29646 test('weeks year starting tuesday', function (assert) { | |
29647 assert.equal(moment([2007, 11, 29]).week(), 1, 'Dec 29 2007 should be week 1'); | |
29648 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
29649 assert.equal(moment([2008, 0, 4]).week(), 1, 'Jan 4 2008 should be week 1'); | |
29650 assert.equal(moment([2008, 0, 5]).week(), 2, 'Jan 5 2008 should be week 2'); | |
29651 assert.equal(moment([2008, 0, 11]).week(), 2, 'Jan 11 2008 should be week 2'); | |
29652 assert.equal(moment([2008, 0, 12]).week(), 3, 'Jan 12 2008 should be week 3'); | |
29653 }); | |
29654 | |
29655 test('weeks year starting wednesday', function (assert) { | |
29656 assert.equal(moment([2002, 11, 28]).week(), 1, 'Dec 28 2002 should be week 1'); | |
29657 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
29658 assert.equal(moment([2003, 0, 3]).week(), 1, 'Jan 3 2003 should be week 1'); | |
29659 assert.equal(moment([2003, 0, 4]).week(), 2, 'Jan 4 2003 should be week 2'); | |
29660 assert.equal(moment([2003, 0, 10]).week(), 2, 'Jan 10 2003 should be week 2'); | |
29661 assert.equal(moment([2003, 0, 11]).week(), 3, 'Jan 11 2003 should be week 3'); | |
29662 }); | |
29663 | |
29664 test('weeks year starting thursday', function (assert) { | |
29665 assert.equal(moment([2008, 11, 27]).week(), 1, 'Dec 27 2008 should be week 1'); | |
29666 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
29667 assert.equal(moment([2009, 0, 2]).week(), 1, 'Jan 2 2009 should be week 1'); | |
29668 assert.equal(moment([2009, 0, 3]).week(), 2, 'Jan 3 2009 should be week 2'); | |
29669 assert.equal(moment([2009, 0, 9]).week(), 2, 'Jan 9 2009 should be week 2'); | |
29670 assert.equal(moment([2009, 0, 10]).week(), 3, 'Jan 10 2009 should be week 3'); | |
29671 }); | |
29672 | |
29673 test('weeks year starting friday', function (assert) { | |
29674 assert.equal(moment([2009, 11, 26]).week(), 1, 'Dec 26 2009 should be week 1'); | |
29675 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
29676 assert.equal(moment([2010, 0, 2]).week(), 2, 'Jan 2 2010 should be week 2'); | |
29677 assert.equal(moment([2010, 0, 8]).week(), 2, 'Jan 8 2010 should be week 2'); | |
29678 assert.equal(moment([2010, 0, 9]).week(), 3, 'Jan 9 2010 should be week 3'); | |
29679 }); | |
29680 | |
29681 test('weeks year starting saturday', function (assert) { | |
29682 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
29683 assert.equal(moment([2011, 0, 7]).week(), 1, 'Jan 7 2011 should be week 1'); | |
29684 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2'); | |
29685 assert.equal(moment([2011, 0, 14]).week(), 2, 'Jan 14 2011 should be week 2'); | |
29686 assert.equal(moment([2011, 0, 15]).week(), 3, 'Jan 15 2011 should be week 3'); | |
29687 }); | |
29688 | |
29689 test('weeks year starting sunday formatted', function (assert) { | |
29690 assert.equal(moment([2011, 11, 31]).format('w ww wo'), '1 01 1', 'Dec 31 2011 should be week 1'); | |
29691 assert.equal(moment([2012, 0, 6]).format('w ww wo'), '1 01 1', 'Jan 6 2012 should be week 1'); | |
29692 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '2 02 2', 'Jan 7 2012 should be week 2'); | |
29693 assert.equal(moment([2012, 0, 13]).format('w ww wo'), '2 02 2', 'Jan 13 2012 should be week 2'); | |
29694 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '3 03 3', 'Jan 14 2012 should be week 3'); | |
29695 }); | |
29696 | |
29697 test('lenient ordinal parsing', function (assert) { | |
29698 var i, ordinalStr, testMoment; | |
29699 for (i = 1; i <= 31; ++i) { | |
29700 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
29701 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
29702 assert.equal(testMoment.year(), 2014, | |
29703 'lenient ordinal parsing ' + i + ' year check'); | |
29704 assert.equal(testMoment.month(), 0, | |
29705 'lenient ordinal parsing ' + i + ' month check'); | |
29706 assert.equal(testMoment.date(), i, | |
29707 'lenient ordinal parsing ' + i + ' date check'); | |
29708 } | |
29709 }); | |
29710 | |
29711 test('lenient ordinal parsing of number', function (assert) { | |
29712 var i, testMoment; | |
29713 for (i = 1; i <= 31; ++i) { | |
29714 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
29715 assert.equal(testMoment.year(), 2014, | |
29716 'lenient ordinal parsing of number ' + i + ' year check'); | |
29717 assert.equal(testMoment.month(), 0, | |
29718 'lenient ordinal parsing of number ' + i + ' month check'); | |
29719 assert.equal(testMoment.date(), i, | |
29720 'lenient ordinal parsing of number ' + i + ' date check'); | |
29721 } | |
29722 }); | |
29723 | |
29724 test('strict ordinal parsing', function (assert) { | |
29725 var i, ordinalStr, testMoment; | |
29726 for (i = 1; i <= 31; ++i) { | |
29727 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
29728 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
29729 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
29730 } | |
29731 }); | |
29732 | |
29733 })); | |
29734 | |
29735 (function (global, factory) { | |
29736 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
29737 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
29738 factory(global.moment) | |
29739 }(this, function (moment) { 'use strict'; | |
29740 | |
29741 /*global QUnit:false*/ | |
29742 | |
29743 var test = QUnit.test; | |
29744 | |
29745 function module (name, lifecycle) { | |
29746 QUnit.module(name, { | |
29747 setup : function () { | |
29748 moment.locale('en'); | |
29749 moment.createFromInputFallback = function () { | |
29750 throw new Error('input not handled by moment'); | |
29751 }; | |
29752 if (lifecycle && lifecycle.setup) { | |
29753 lifecycle.setup(); | |
29754 } | |
29755 }, | |
29756 teardown : function () { | |
29757 if (lifecycle && lifecycle.teardown) { | |
29758 lifecycle.teardown(); | |
29759 } | |
29760 } | |
29761 }); | |
29762 } | |
29763 | |
29764 function localeModule (name, lifecycle) { | |
29765 QUnit.module('locale:' + name, { | |
29766 setup : function () { | |
29767 moment.locale(name); | |
29768 moment.createFromInputFallback = function () { | |
29769 throw new Error('input not handled by moment'); | |
29770 }; | |
29771 if (lifecycle && lifecycle.setup) { | |
29772 lifecycle.setup(); | |
29773 } | |
29774 }, | |
29775 teardown : function () { | |
29776 moment.locale('en'); | |
29777 if (lifecycle && lifecycle.teardown) { | |
29778 lifecycle.teardown(); | |
29779 } | |
29780 } | |
29781 }); | |
29782 } | |
29783 | |
29784 localeModule('uk'); | |
29785 | |
29786 test('parse', function (assert) { | |
29787 var tests = 'січень січ_лютий лют_березень бер_квітень квіт_травень трав_червень черв_липень лип_серпень серп_вересень вер_жовтень жовт_листопад лист_грудень груд'.split('_'), i; | |
29788 function equalTest(input, mmm, i) { | |
29789 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
29790 } | |
29791 for (i = 0; i < 12; i++) { | |
29792 tests[i] = tests[i].split(' '); | |
29793 equalTest(tests[i][0], 'MMM', i); | |
29794 equalTest(tests[i][1], 'MMM', i); | |
29795 equalTest(tests[i][0], 'MMMM', i); | |
29796 equalTest(tests[i][1], 'MMMM', i); | |
29797 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
29798 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
29799 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
29800 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
29801 } | |
29802 }); | |
29803 | |
29804 test('format', function (assert) { | |
29805 var a = [ | |
29806 ['dddd, Do MMMM YYYY, HH:mm:ss', 'неділя, 14-го лютого 2010, 15:25:50'], | |
29807 ['ddd, h A', 'нд, 3 дня'], | |
29808 ['M Mo MM MMMM MMM', '2 2-й 02 лютий лют'], | |
29809 ['YYYY YY', '2010 10'], | |
29810 ['D Do DD', '14 14-го 14'], | |
29811 ['d do dddd ddd dd', '0 0-й неділя нд нд'], | |
29812 ['DDD DDDo DDDD', '45 45-й 045'], | |
29813 ['w wo ww', '7 7-й 07'], | |
29814 ['h hh', '3 03'], | |
29815 ['H HH', '15 15'], | |
29816 ['m mm', '25 25'], | |
29817 ['s ss', '50 50'], | |
29818 ['a A', 'дня дня'], | |
29819 ['DDDo [день року]', '45-й день року'], | |
29820 ['LTS', '15:25:50'], | |
29821 ['L', '14.02.2010'], | |
29822 ['LL', '14 лютого 2010 р.'], | |
29823 ['LLL', '14 лютого 2010 р., 15:25'], | |
29824 ['LLLL', 'неділя, 14 лютого 2010 р., 15:25'] | |
29825 ], | |
29826 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
29827 i; | |
29828 for (i = 0; i < a.length; i++) { | |
29829 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
29830 } | |
29831 }); | |
29832 | |
29833 test('format meridiem', function (assert) { | |
29834 assert.equal(moment([2012, 11, 28, 0, 0]).format('A'), 'ночі', 'night'); | |
29835 assert.equal(moment([2012, 11, 28, 3, 59]).format('A'), 'ночі', 'night'); | |
29836 assert.equal(moment([2012, 11, 28, 4, 0]).format('A'), 'ранку', 'morning'); | |
29837 assert.equal(moment([2012, 11, 28, 11, 59]).format('A'), 'ранку', 'morning'); | |
29838 assert.equal(moment([2012, 11, 28, 12, 0]).format('A'), 'дня', 'afternoon'); | |
29839 assert.equal(moment([2012, 11, 28, 16, 59]).format('A'), 'дня', 'afternoon'); | |
29840 assert.equal(moment([2012, 11, 28, 17, 0]).format('A'), 'вечора', 'evening'); | |
29841 assert.equal(moment([2012, 11, 28, 23, 59]).format('A'), 'вечора', 'evening'); | |
29842 }); | |
29843 | |
29844 test('format ordinal', function (assert) { | |
29845 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1-й', '1-й'); | |
29846 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2-й', '2-й'); | |
29847 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3-й', '3-й'); | |
29848 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4-й', '4-й'); | |
29849 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5-й', '5-й'); | |
29850 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6-й', '6-й'); | |
29851 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7-й', '7-й'); | |
29852 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8-й', '8-й'); | |
29853 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9-й', '9-й'); | |
29854 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10-й', '10-й'); | |
29855 | |
29856 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11-й', '11-й'); | |
29857 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12-й', '12-й'); | |
29858 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13-й', '13-й'); | |
29859 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14-й', '14-й'); | |
29860 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15-й', '15-й'); | |
29861 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16-й', '16-й'); | |
29862 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17-й', '17-й'); | |
29863 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18-й', '18-й'); | |
29864 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19-й', '19-й'); | |
29865 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20-й', '20-й'); | |
29866 | |
29867 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21-й', '21-й'); | |
29868 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22-й', '22-й'); | |
29869 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23-й', '23-й'); | |
29870 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24-й', '24-й'); | |
29871 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25-й', '25-й'); | |
29872 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26-й', '26-й'); | |
29873 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27-й', '27-й'); | |
29874 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28-й', '28-й'); | |
29875 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29-й', '29-й'); | |
29876 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30-й', '30-й'); | |
29877 | |
29878 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31-й', '31-й'); | |
29879 }); | |
29880 | |
29881 test('format month', function (assert) { | |
29882 var expected = 'січень січ_лютий лют_березень бер_квітень квіт_травень трав_червень черв_липень лип_серпень серп_вересень вер_жовтень жовт_листопад лист_грудень груд'.split('_'), i; | |
29883 for (i = 0; i < expected.length; i++) { | |
29884 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
29885 } | |
29886 }); | |
29887 | |
29888 test('format month case', function (assert) { | |
29889 var months = { | |
29890 'nominative': 'січень_лютий_березень_квітень_травень_червень_липень_серпень_вересень_жовтень_листопад_грудень'.split('_'), | |
29891 'accusative': 'січня_лютого_березня_квітня_травня_червня_липня_серпня_вересня_жовтня_листопада_грудня'.split('_') | |
29892 }, i; | |
29893 for (i = 0; i < 12; i++) { | |
29894 assert.equal(moment([2011, i, 1]).format('D MMMM'), '1 ' + months.accusative[i], '1 ' + months.accusative[i]); | |
29895 assert.equal(moment([2011, i, 1]).format('MMMM'), months.nominative[i], '1 ' + months.nominative[i]); | |
29896 } | |
29897 }); | |
29898 | |
29899 test('format week', function (assert) { | |
29900 var expected = 'неділя нд нд_понеділок пн пн_вівторок вт вт_середа ср ср_четвер чт чт_п’ятниця пт пт_субота сб сб'.split('_'), i; | |
29901 for (i = 0; i < expected.length; i++) { | |
29902 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
29903 } | |
29904 }); | |
29905 | |
29906 test('from', function (assert) { | |
29907 var start = moment([2007, 1, 28]); | |
29908 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'декілька секунд', '44 seconds = seconds'); | |
29909 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'хвилина', '45 seconds = a minute'); | |
29910 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'хвилина', '89 seconds = a minute'); | |
29911 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 хвилини', '90 seconds = 2 minutes'); | |
29912 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 хвилини', '44 minutes = 44 minutes'); | |
29913 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'годину', '45 minutes = an hour'); | |
29914 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'годину', '89 minutes = an hour'); | |
29915 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 години', '90 minutes = 2 hours'); | |
29916 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 годин', '5 hours = 5 hours'); | |
29917 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 година', '21 hours = 21 hours'); | |
29918 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'день', '22 hours = a day'); | |
29919 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'день', '35 hours = a day'); | |
29920 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 дні', '36 hours = 2 days'); | |
29921 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'день', '1 day = a day'); | |
29922 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 днів', '5 days = 5 days'); | |
29923 assert.equal(start.from(moment([2007, 1, 28]).add({d: 11}), true), '11 днів', '11 days = 11 days'); | |
29924 assert.equal(start.from(moment([2007, 1, 28]).add({d: 21}), true), '21 день', '21 days = 21 days'); | |
29925 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 днів', '25 days = 25 days'); | |
29926 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'місяць', '26 days = a month'); | |
29927 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'місяць', '30 days = a month'); | |
29928 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'місяць', '43 days = a month'); | |
29929 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 місяці', '46 days = 2 months'); | |
29930 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 місяці', '75 days = 2 months'); | |
29931 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 місяці', '76 days = 3 months'); | |
29932 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'місяць', '1 month = a month'); | |
29933 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 місяців', '5 months = 5 months'); | |
29934 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'рік', '345 days = a year'); | |
29935 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 роки', '548 days = 2 years'); | |
29936 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'рік', '1 year = a year'); | |
29937 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 років', '5 years = 5 years'); | |
29938 }); | |
29939 | |
29940 test('suffix', function (assert) { | |
29941 assert.equal(moment(30000).from(0), 'за декілька секунд', 'prefix'); | |
29942 assert.equal(moment(0).from(30000), 'декілька секунд тому', 'suffix'); | |
29943 }); | |
29944 | |
29945 test('fromNow', function (assert) { | |
29946 assert.equal(moment().add({s: 30}).fromNow(), 'за декілька секунд', 'in seconds'); | |
29947 assert.equal(moment().add({d: 5}).fromNow(), 'за 5 днів', 'in 5 days'); | |
29948 }); | |
29949 | |
29950 test('calendar day', function (assert) { | |
29951 var a = moment().hours(2).minutes(0).seconds(0); | |
29952 | |
29953 assert.equal(moment(a).calendar(), 'Сьогодні о 02:00', 'today at the same time'); | |
29954 assert.equal(moment(a).add({m: 25}).calendar(), 'Сьогодні о 02:25', 'Now plus 25 min'); | |
29955 assert.equal(moment(a).add({h: 1}).calendar(), 'Сьогодні о 03:00', 'Now plus 1 hour'); | |
29956 assert.equal(moment(a).add({d: 1}).calendar(), 'Завтра о 02:00', 'tomorrow at the same time'); | |
29957 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Сьогодні о 01:00', 'Now minus 1 hour'); | |
29958 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Вчора о 02:00', 'yesterday at the same time'); | |
29959 // A special case for Ukrainian since 11 hours have different preposition | |
29960 assert.equal(moment(a).add({h: 9}).calendar(), 'Сьогодні об 11:00', 'same day at 11 o\'clock'); | |
29961 }); | |
29962 | |
29963 test('calendar next week', function (assert) { | |
29964 var i, m; | |
29965 for (i = 2; i < 7; i++) { | |
29966 m = moment().add({d: i}); | |
29967 assert.equal(m.calendar(), m.format('[У] dddd [о' + (m.hours() === 11 ? 'б' : '') + '] LT'), 'Today + ' + i + ' days current time'); | |
29968 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
29969 assert.equal(m.calendar(), m.format('[У] dddd [о] LT'), 'Today + ' + i + ' days beginning of day'); | |
29970 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
29971 assert.equal(m.calendar(), m.format('[У] dddd [о] LT'), 'Today + ' + i + ' days end of day'); | |
29972 } | |
29973 }); | |
29974 | |
29975 test('calendar last week', function (assert) { | |
29976 var i, m; | |
29977 | |
29978 function makeFormat(d) { | |
29979 switch (d.day()) { | |
29980 case 0: | |
29981 case 3: | |
29982 case 5: | |
29983 case 6: | |
29984 return '[Минулої] dddd [о' + (d.hours() === 11 ? 'б' : '') + '] LT'; | |
29985 case 1: | |
29986 case 2: | |
29987 case 4: | |
29988 return '[Минулого] dddd [о' + (d.hours() === 11 ? 'б' : '') + '] LT'; | |
29989 } | |
29990 } | |
29991 | |
29992 for (i = 2; i < 7; i++) { | |
29993 m = moment().subtract({d: i}); | |
29994 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days current time'); | |
29995 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
29996 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days beginning of day'); | |
29997 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
29998 assert.equal(m.calendar(), m.format(makeFormat(m)), 'Today - ' + i + ' days end of day'); | |
29999 } | |
30000 }); | |
30001 | |
30002 test('calendar all else', function (assert) { | |
30003 var weeksAgo = moment().subtract({w: 1}), | |
30004 weeksFromNow = moment().add({w: 1}); | |
30005 | |
30006 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
30007 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
30008 | |
30009 weeksAgo = moment().subtract({w: 2}); | |
30010 weeksFromNow = moment().add({w: 2}); | |
30011 | |
30012 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
30013 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
30014 }); | |
30015 | |
30016 test('weeks year starting sunday', function (assert) { | |
30017 assert.equal(moment([2011, 11, 26]).week(), 1, 'Dec 26 2011 should be week 1'); | |
30018 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
30019 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 2'); | |
30020 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
30021 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 3'); | |
30022 }); | |
30023 | |
30024 test('weeks year starting monday', function (assert) { | |
30025 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
30026 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
30027 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
30028 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
30029 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
30030 }); | |
30031 | |
30032 test('weeks year starting tuesday', function (assert) { | |
30033 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
30034 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
30035 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
30036 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
30037 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
30038 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
30039 }); | |
30040 | |
30041 test('weeks year starting wednesday', function (assert) { | |
30042 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
30043 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
30044 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
30045 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
30046 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
30047 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
30048 }); | |
30049 | |
30050 test('weeks year starting thursday', function (assert) { | |
30051 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
30052 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
30053 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
30054 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
30055 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
30056 assert.equal(moment([2009, 0, 12]).week(), 3, 'Jan 12 2009 should be week 3'); | |
30057 }); | |
30058 | |
30059 test('weeks year starting friday', function (assert) { | |
30060 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 1'); | |
30061 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
30062 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 1'); | |
30063 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 2'); | |
30064 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 2'); | |
30065 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 3'); | |
30066 }); | |
30067 | |
30068 test('weeks year starting saturday', function (assert) { | |
30069 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 1'); | |
30070 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
30071 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 1'); | |
30072 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 2'); | |
30073 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 2'); | |
30074 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 3'); | |
30075 }); | |
30076 | |
30077 test('weeks year starting sunday formatted', function (assert) { | |
30078 assert.equal(moment([2011, 11, 26]).format('w ww wo'), '1 01 1-й', 'Dec 26 2011 should be week 1'); | |
30079 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1-й', 'Jan 1 2012 should be week 1'); | |
30080 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2-й', 'Jan 2 2012 should be week 2'); | |
30081 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2-й', 'Jan 8 2012 should be week 2'); | |
30082 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-й', 'Jan 9 2012 should be week 3'); | |
30083 }); | |
30084 | |
30085 test('lenient ordinal parsing', function (assert) { | |
30086 var i, ordinalStr, testMoment; | |
30087 for (i = 1; i <= 31; ++i) { | |
30088 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
30089 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
30090 assert.equal(testMoment.year(), 2014, | |
30091 'lenient ordinal parsing ' + i + ' year check'); | |
30092 assert.equal(testMoment.month(), 0, | |
30093 'lenient ordinal parsing ' + i + ' month check'); | |
30094 assert.equal(testMoment.date(), i, | |
30095 'lenient ordinal parsing ' + i + ' date check'); | |
30096 } | |
30097 }); | |
30098 | |
30099 test('lenient ordinal parsing of number', function (assert) { | |
30100 var i, testMoment; | |
30101 for (i = 1; i <= 31; ++i) { | |
30102 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
30103 assert.equal(testMoment.year(), 2014, | |
30104 'lenient ordinal parsing of number ' + i + ' year check'); | |
30105 assert.equal(testMoment.month(), 0, | |
30106 'lenient ordinal parsing of number ' + i + ' month check'); | |
30107 assert.equal(testMoment.date(), i, | |
30108 'lenient ordinal parsing of number ' + i + ' date check'); | |
30109 } | |
30110 }); | |
30111 | |
30112 test('strict ordinal parsing', function (assert) { | |
30113 var i, ordinalStr, testMoment; | |
30114 for (i = 1; i <= 31; ++i) { | |
30115 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
30116 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
30117 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
30118 } | |
30119 }); | |
30120 | |
30121 })); | |
30122 | |
30123 (function (global, factory) { | |
30124 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
30125 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
30126 factory(global.moment) | |
30127 }(this, function (moment) { 'use strict'; | |
30128 | |
30129 /*global QUnit:false*/ | |
30130 | |
30131 var test = QUnit.test; | |
30132 | |
30133 function module (name, lifecycle) { | |
30134 QUnit.module(name, { | |
30135 setup : function () { | |
30136 moment.locale('en'); | |
30137 moment.createFromInputFallback = function () { | |
30138 throw new Error('input not handled by moment'); | |
30139 }; | |
30140 if (lifecycle && lifecycle.setup) { | |
30141 lifecycle.setup(); | |
30142 } | |
30143 }, | |
30144 teardown : function () { | |
30145 if (lifecycle && lifecycle.teardown) { | |
30146 lifecycle.teardown(); | |
30147 } | |
30148 } | |
30149 }); | |
30150 } | |
30151 | |
30152 function localeModule (name, lifecycle) { | |
30153 QUnit.module('locale:' + name, { | |
30154 setup : function () { | |
30155 moment.locale(name); | |
30156 moment.createFromInputFallback = function () { | |
30157 throw new Error('input not handled by moment'); | |
30158 }; | |
30159 if (lifecycle && lifecycle.setup) { | |
30160 lifecycle.setup(); | |
30161 } | |
30162 }, | |
30163 teardown : function () { | |
30164 moment.locale('en'); | |
30165 if (lifecycle && lifecycle.teardown) { | |
30166 lifecycle.teardown(); | |
30167 } | |
30168 } | |
30169 }); | |
30170 } | |
30171 | |
30172 localeModule('uz'); | |
30173 | |
30174 test('parse', function (assert) { | |
30175 var tests = 'январь янв_февраль фев_март мар_апрель апр_май май_июнь июнь_июль июль_август авг_сентябрь сен_октябрь окт_ноябрь ноя_декабрь дек'.split('_'), i; | |
30176 function equalTest(input, mmm, i) { | |
30177 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
30178 } | |
30179 for (i = 0; i < 12; i++) { | |
30180 tests[i] = tests[i].split(' '); | |
30181 equalTest(tests[i][0], 'MMM', i); | |
30182 equalTest(tests[i][1], 'MMM', i); | |
30183 equalTest(tests[i][0], 'MMMM', i); | |
30184 equalTest(tests[i][1], 'MMMM', i); | |
30185 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
30186 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
30187 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
30188 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
30189 } | |
30190 }); | |
30191 | |
30192 test('format', function (assert) { | |
30193 var a = [ | |
30194 ['dddd, Do-MMMM YYYY, h:mm:ss', 'Якшанба, 14-февраль 2010, 3:25:50'], | |
30195 ['ddd, h:mm', 'Якш, 3:25'], | |
30196 ['M Mo MM MMMM MMM', '2 2 02 февраль фев'], | |
30197 ['YYYY YY', '2010 10'], | |
30198 ['D Do DD', '14 14 14'], | |
30199 ['d do dddd ddd dd', '0 0 Якшанба Якш Як'], | |
30200 ['DDD DDDo DDDD', '45 45 045'], | |
30201 ['w wo ww', '7 7 07'], | |
30202 ['h hh', '3 03'], | |
30203 ['H HH', '15 15'], | |
30204 ['m mm', '25 25'], | |
30205 ['s ss', '50 50'], | |
30206 ['a A', 'pm PM'], | |
30207 ['[йилнинг] DDDo-[куни]', 'йилнинг 45-куни'], | |
30208 ['LTS', '15:25:50'], | |
30209 ['L', '14/02/2010'], | |
30210 ['LL', '14 февраль 2010'], | |
30211 ['LLL', '14 февраль 2010 15:25'], | |
30212 ['LLLL', '14 февраль 2010, Якшанба 15:25'], | |
30213 ['l', '14/2/2010'], | |
30214 ['ll', '14 фев 2010'], | |
30215 ['lll', '14 фев 2010 15:25'], | |
30216 ['llll', '14 фев 2010, Якш 15:25'] | |
30217 ], | |
30218 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
30219 i; | |
30220 for (i = 0; i < a.length; i++) { | |
30221 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
30222 } | |
30223 }); | |
30224 | |
30225 test('format ordinal', function (assert) { | |
30226 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1'); | |
30227 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2'); | |
30228 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3'); | |
30229 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4'); | |
30230 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5'); | |
30231 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6'); | |
30232 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7'); | |
30233 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8'); | |
30234 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9'); | |
30235 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10'); | |
30236 | |
30237 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11'); | |
30238 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12'); | |
30239 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13'); | |
30240 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14'); | |
30241 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15'); | |
30242 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16'); | |
30243 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17'); | |
30244 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18'); | |
30245 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19'); | |
30246 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20'); | |
30247 | |
30248 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21'); | |
30249 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22'); | |
30250 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23'); | |
30251 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24'); | |
30252 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25'); | |
30253 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26'); | |
30254 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27'); | |
30255 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28'); | |
30256 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29'); | |
30257 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30'); | |
30258 | |
30259 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31'); | |
30260 }); | |
30261 | |
30262 test('format month', function (assert) { | |
30263 var expected = 'январь янв_февраль фев_март мар_апрель апр_май май_июнь июн_июль июл_август авг_сентябрь сен_октябрь окт_ноябрь ноя_декабрь дек'.split('_'), i; | |
30264 for (i = 0; i < expected.length; i++) { | |
30265 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
30266 } | |
30267 }); | |
30268 | |
30269 test('format week', function (assert) { | |
30270 var expected = 'Якшанба Якш Як_Душанба Душ Ду_Сешанба Сеш Се_Чоршанба Чор Чо_Пайшанба Пай Па_Жума Жум Жу_Шанба Шан Ша'.split('_'), i; | |
30271 for (i = 0; i < expected.length; i++) { | |
30272 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
30273 } | |
30274 }); | |
30275 | |
30276 test('from', function (assert) { | |
30277 var start = moment([2007, 1, 28]); | |
30278 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'фурсат', '44 секунд = фурсат'); | |
30279 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'бир дакика', '45 секунд = бир дакика'); | |
30280 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'бир дакика', '89 секунд = бир дакика'); | |
30281 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 дакика', '90 секунд = 2 дакика'); | |
30282 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 дакика', '44 дакика = 44 дакика'); | |
30283 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'бир соат', '45 минут = бир соат'); | |
30284 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'бир соат', '89 minutes = an hour'); | |
30285 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 соат', '90 минут = 2 соат'); | |
30286 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 соат', '5 соат = 5 соат'); | |
30287 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 соат', '21 соат = 21 соат'); | |
30288 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'бир кун', '22 соат = бир кун'); | |
30289 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'бир кун', '35 соат = бир кун'); | |
30290 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 кун', '36 соат = 2 кун'); | |
30291 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'бир кун', '1 кун = 1 кун'); | |
30292 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 кун', '5 кун = 5 кун'); | |
30293 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 кун', '25 кун = 25 кун'); | |
30294 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'бир ой', '26 кун = бир ой'); | |
30295 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'бир ой', '30 кун = бир ой'); | |
30296 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'бир ой', '45 кун = бир ой'); | |
30297 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 ой', '46 кун = 2 ой'); | |
30298 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 ой', '75 кун = 2 ой'); | |
30299 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 ой', '76 кун = 3 ой'); | |
30300 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'бир ой', 'бир ой = бир ой'); | |
30301 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 ой', '5 ой = 5 ой'); | |
30302 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'бир йил', '345 кун = бир йил'); | |
30303 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 йил', '548 кун = 2 йил'); | |
30304 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'бир йил', '1 йил = бир йил'); | |
30305 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 йил', '5 йил = 5 йил'); | |
30306 }); | |
30307 | |
30308 test('suffix', function (assert) { | |
30309 assert.equal(moment(30000).from(0), 'Якин фурсат ичида', 'prefix'); | |
30310 assert.equal(moment(0).from(30000), 'Бир неча фурсат олдин', 'suffix'); | |
30311 }); | |
30312 | |
30313 test('now from now', function (assert) { | |
30314 assert.equal(moment().fromNow(), 'Бир неча фурсат олдин', 'now from now should display as in the past'); | |
30315 }); | |
30316 | |
30317 test('fromNow', function (assert) { | |
30318 assert.equal(moment().add({s: 30}).fromNow(), 'Якин фурсат ичида', 'in a few seconds'); | |
30319 assert.equal(moment().add({d: 5}).fromNow(), 'Якин 5 кун ичида', 'in 5 days'); | |
30320 }); | |
30321 | |
30322 test('calendar day', function (assert) { | |
30323 var a = moment().hours(2).minutes(0).seconds(0); | |
30324 | |
30325 assert.equal(moment(a).calendar(), 'Бугун соат 02:00 да', 'today at the same time'); | |
30326 assert.equal(moment(a).add({m: 25}).calendar(), 'Бугун соат 02:25 да', 'Now plus 25 min'); | |
30327 assert.equal(moment(a).add({h: 1}).calendar(), 'Бугун соат 03:00 да', 'Now plus 1 hour'); | |
30328 assert.equal(moment(a).add({d: 1}).calendar(), 'Эртага 02:00 да', 'tomorrow at the same time'); | |
30329 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Бугун соат 01:00 да', 'Now minus 1 hour'); | |
30330 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Кеча соат 02:00 да', 'yesterday at the same time'); | |
30331 }); | |
30332 | |
30333 test('calendar next week', function (assert) { | |
30334 var i, m; | |
30335 for (i = 2; i < 7; i++) { | |
30336 m = moment().add({d: i}); | |
30337 assert.equal(m.calendar(), m.format('dddd [куни соат] LT [да]'), 'Today + ' + i + ' days current time'); | |
30338 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
30339 assert.equal(m.calendar(), m.format('dddd [куни соат] LT [да]'), 'Today + ' + i + ' days beginning of day'); | |
30340 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
30341 assert.equal(m.calendar(), m.format('dddd [куни соат] LT [да]'), 'Today + ' + i + ' days end of day'); | |
30342 } | |
30343 }); | |
30344 | |
30345 test('calendar last week', function (assert) { | |
30346 var i, m; | |
30347 | |
30348 for (i = 2; i < 7; i++) { | |
30349 m = moment().subtract({d: i}); | |
30350 assert.equal(m.calendar(), m.format('[Утган] dddd [куни соат] LT [да]'), 'Today - ' + i + ' days current time'); | |
30351 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
30352 assert.equal(m.calendar(), m.format('[Утган] dddd [куни соат] LT [да]'), 'Today - ' + i + ' days beginning of day'); | |
30353 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
30354 assert.equal(m.calendar(), m.format('[Утган] dddd [куни соат] LT [да]'), 'Today - ' + i + ' days end of day'); | |
30355 } | |
30356 }); | |
30357 | |
30358 test('calendar all else', function (assert) { | |
30359 var weeksAgo = moment().subtract({w: 1}), | |
30360 weeksFromNow = moment().add({w: 1}); | |
30361 | |
30362 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
30363 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
30364 | |
30365 weeksAgo = moment().subtract({w: 2}); | |
30366 weeksFromNow = moment().add({w: 2}); | |
30367 | |
30368 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
30369 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
30370 }); | |
30371 | |
30372 test('weeks year starting sunday', function (assert) { | |
30373 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 52'); | |
30374 assert.equal(moment([2012, 0, 2]).week(), 2, 'Jan 2 2012 should be week 1'); | |
30375 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 1'); | |
30376 assert.equal(moment([2012, 0, 9]).week(), 3, 'Jan 9 2012 should be week 2'); | |
30377 assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 2'); | |
30378 }); | |
30379 | |
30380 test('weeks year starting monday', function (assert) { | |
30381 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
30382 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
30383 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
30384 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
30385 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
30386 }); | |
30387 | |
30388 test('weeks year starting tuesday', function (assert) { | |
30389 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
30390 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
30391 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
30392 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
30393 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
30394 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
30395 }); | |
30396 | |
30397 test('weeks year starting wednesday', function (assert) { | |
30398 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
30399 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
30400 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
30401 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
30402 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
30403 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
30404 }); | |
30405 | |
30406 test('weeks year starting thursday', function (assert) { | |
30407 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
30408 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
30409 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
30410 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
30411 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
30412 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
30413 }); | |
30414 | |
30415 test('weeks year starting friday', function (assert) { | |
30416 assert.equal(moment([2009, 11, 28]).week(), 1, 'Dec 28 2009 should be week 53'); | |
30417 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 53'); | |
30418 assert.equal(moment([2010, 0, 3]).week(), 1, 'Jan 3 2010 should be week 53'); | |
30419 assert.equal(moment([2010, 0, 4]).week(), 2, 'Jan 4 2010 should be week 1'); | |
30420 assert.equal(moment([2010, 0, 10]).week(), 2, 'Jan 10 2010 should be week 1'); | |
30421 assert.equal(moment([2010, 0, 11]).week(), 3, 'Jan 11 2010 should be week 2'); | |
30422 }); | |
30423 | |
30424 test('weeks year starting saturday', function (assert) { | |
30425 assert.equal(moment([2010, 11, 27]).week(), 1, 'Dec 27 2010 should be week 52'); | |
30426 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 52'); | |
30427 assert.equal(moment([2011, 0, 2]).week(), 1, 'Jan 2 2011 should be week 52'); | |
30428 assert.equal(moment([2011, 0, 3]).week(), 2, 'Jan 3 2011 should be week 1'); | |
30429 assert.equal(moment([2011, 0, 9]).week(), 2, 'Jan 9 2011 should be week 1'); | |
30430 assert.equal(moment([2011, 0, 10]).week(), 3, 'Jan 10 2011 should be week 2'); | |
30431 }); | |
30432 | |
30433 test('weeks year starting sunday formatted', function (assert) { | |
30434 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1', 'Jan 1 2012 should be week 52'); | |
30435 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '2 02 2', 'Jan 2 2012 should be week 1'); | |
30436 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2', 'Jan 8 2012 should be week 1'); | |
30437 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3', 'Jan 9 2012 should be week 2'); | |
30438 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3', 'Jan 15 2012 should be week 2'); | |
30439 }); | |
30440 | |
30441 test('lenient ordinal parsing', function (assert) { | |
30442 var i, ordinalStr, testMoment; | |
30443 for (i = 1; i <= 31; ++i) { | |
30444 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
30445 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
30446 assert.equal(testMoment.year(), 2014, | |
30447 'lenient ordinal parsing ' + i + ' year check'); | |
30448 assert.equal(testMoment.month(), 0, | |
30449 'lenient ordinal parsing ' + i + ' month check'); | |
30450 assert.equal(testMoment.date(), i, | |
30451 'lenient ordinal parsing ' + i + ' date check'); | |
30452 } | |
30453 }); | |
30454 | |
30455 test('lenient ordinal parsing of number', function (assert) { | |
30456 var i, testMoment; | |
30457 for (i = 1; i <= 31; ++i) { | |
30458 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
30459 assert.equal(testMoment.year(), 2014, | |
30460 'lenient ordinal parsing of number ' + i + ' year check'); | |
30461 assert.equal(testMoment.month(), 0, | |
30462 'lenient ordinal parsing of number ' + i + ' month check'); | |
30463 assert.equal(testMoment.date(), i, | |
30464 'lenient ordinal parsing of number ' + i + ' date check'); | |
30465 } | |
30466 }); | |
30467 | |
30468 test('strict ordinal parsing', function (assert) { | |
30469 var i, ordinalStr, testMoment; | |
30470 for (i = 1; i <= 31; ++i) { | |
30471 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
30472 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
30473 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
30474 } | |
30475 }); | |
30476 | |
30477 })); | |
30478 | |
30479 (function (global, factory) { | |
30480 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
30481 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
30482 factory(global.moment) | |
30483 }(this, function (moment) { 'use strict'; | |
30484 | |
30485 /*global QUnit:false*/ | |
30486 | |
30487 var test = QUnit.test; | |
30488 | |
30489 function module (name, lifecycle) { | |
30490 QUnit.module(name, { | |
30491 setup : function () { | |
30492 moment.locale('en'); | |
30493 moment.createFromInputFallback = function () { | |
30494 throw new Error('input not handled by moment'); | |
30495 }; | |
30496 if (lifecycle && lifecycle.setup) { | |
30497 lifecycle.setup(); | |
30498 } | |
30499 }, | |
30500 teardown : function () { | |
30501 if (lifecycle && lifecycle.teardown) { | |
30502 lifecycle.teardown(); | |
30503 } | |
30504 } | |
30505 }); | |
30506 } | |
30507 | |
30508 function localeModule (name, lifecycle) { | |
30509 QUnit.module('locale:' + name, { | |
30510 setup : function () { | |
30511 moment.locale(name); | |
30512 moment.createFromInputFallback = function () { | |
30513 throw new Error('input not handled by moment'); | |
30514 }; | |
30515 if (lifecycle && lifecycle.setup) { | |
30516 lifecycle.setup(); | |
30517 } | |
30518 }, | |
30519 teardown : function () { | |
30520 moment.locale('en'); | |
30521 if (lifecycle && lifecycle.teardown) { | |
30522 lifecycle.teardown(); | |
30523 } | |
30524 } | |
30525 }); | |
30526 } | |
30527 | |
30528 localeModule('vi'); | |
30529 | |
30530 test('parse', function (assert) { | |
30531 var i, | |
30532 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('_'); | |
30533 | |
30534 function equalTest(input, mmm, i) { | |
30535 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + i); | |
30536 } | |
30537 | |
30538 for (i = 0; i < 12; i++) { | |
30539 tests[i] = tests[i].split(','); | |
30540 equalTest(tests[i][0], '[tháng] M', i); | |
30541 equalTest(tests[i][1], '[Th]M', i); | |
30542 equalTest(tests[i][0], '[tháng] MM', i); | |
30543 equalTest(tests[i][1], '[Th]MM', i); | |
30544 equalTest(tests[i][0].toLocaleLowerCase(), '[THÁNG] M', i); | |
30545 equalTest(tests[i][1].toLocaleLowerCase(), '[TH]M', i); | |
30546 equalTest(tests[i][0].toLocaleUpperCase(), '[THÁNG] MM', i); | |
30547 equalTest(tests[i][1].toLocaleUpperCase(), '[TH]MM', i); | |
30548 } | |
30549 }); | |
30550 | |
30551 test('format', function (assert) { | |
30552 var a = [ | |
30553 ['dddd, MMMM Do YYYY, h:mm:ss a', 'chủ nhật, tháng 2 14 2010, 3:25:50 pm'], | |
30554 ['ddd, hA', 'CN, 3PM'], | |
30555 ['M Mo MM MMMM MMM', '2 2 02 tháng 2 Th02'], | |
30556 ['YYYY YY', '2010 10'], | |
30557 ['D Do DD', '14 14 14'], | |
30558 ['d do dddd ddd dd', '0 0 chủ nhật CN CN'], | |
30559 ['DDD DDDo DDDD', '45 45 045'], | |
30560 ['w wo ww', '6 6 06'], | |
30561 ['h hh', '3 03'], | |
30562 ['H HH', '15 15'], | |
30563 ['m mm', '25 25'], | |
30564 ['s ss', '50 50'], | |
30565 ['a A', 'pm PM'], | |
30566 ['[ngày thứ] DDDo [của năm]', 'ngày thứ 45 của năm'], | |
30567 ['LTS', '15:25:50'], | |
30568 ['L', '14/02/2010'], | |
30569 ['LL', '14 tháng 2 năm 2010'], | |
30570 ['LLL', '14 tháng 2 năm 2010 15:25'], | |
30571 ['LLLL', 'chủ nhật, 14 tháng 2 năm 2010 15:25'], | |
30572 ['l', '14/2/2010'], | |
30573 ['ll', '14 Th02 2010'], | |
30574 ['lll', '14 Th02 2010 15:25'], | |
30575 ['llll', 'CN, 14 Th02 2010 15:25'] | |
30576 ], | |
30577 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
30578 i; | |
30579 | |
30580 for (i = 0; i < a.length; i++) { | |
30581 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
30582 } | |
30583 }); | |
30584 | |
30585 test('format ordinal', function (assert) { | |
30586 assert.equal(moment([2011, 0, 1]).format('DDDo'), '1', '1'); | |
30587 assert.equal(moment([2011, 0, 2]).format('DDDo'), '2', '2'); | |
30588 assert.equal(moment([2011, 0, 3]).format('DDDo'), '3', '3'); | |
30589 assert.equal(moment([2011, 0, 4]).format('DDDo'), '4', '4'); | |
30590 assert.equal(moment([2011, 0, 5]).format('DDDo'), '5', '5'); | |
30591 assert.equal(moment([2011, 0, 6]).format('DDDo'), '6', '6'); | |
30592 assert.equal(moment([2011, 0, 7]).format('DDDo'), '7', '7'); | |
30593 assert.equal(moment([2011, 0, 8]).format('DDDo'), '8', '8'); | |
30594 assert.equal(moment([2011, 0, 9]).format('DDDo'), '9', '9'); | |
30595 assert.equal(moment([2011, 0, 10]).format('DDDo'), '10', '10'); | |
30596 | |
30597 assert.equal(moment([2011, 0, 11]).format('DDDo'), '11', '11'); | |
30598 assert.equal(moment([2011, 0, 12]).format('DDDo'), '12', '12'); | |
30599 assert.equal(moment([2011, 0, 13]).format('DDDo'), '13', '13'); | |
30600 assert.equal(moment([2011, 0, 14]).format('DDDo'), '14', '14'); | |
30601 assert.equal(moment([2011, 0, 15]).format('DDDo'), '15', '15'); | |
30602 assert.equal(moment([2011, 0, 16]).format('DDDo'), '16', '16'); | |
30603 assert.equal(moment([2011, 0, 17]).format('DDDo'), '17', '17'); | |
30604 assert.equal(moment([2011, 0, 18]).format('DDDo'), '18', '18'); | |
30605 assert.equal(moment([2011, 0, 19]).format('DDDo'), '19', '19'); | |
30606 assert.equal(moment([2011, 0, 20]).format('DDDo'), '20', '20'); | |
30607 | |
30608 assert.equal(moment([2011, 0, 21]).format('DDDo'), '21', '21'); | |
30609 assert.equal(moment([2011, 0, 22]).format('DDDo'), '22', '22'); | |
30610 assert.equal(moment([2011, 0, 23]).format('DDDo'), '23', '23'); | |
30611 assert.equal(moment([2011, 0, 24]).format('DDDo'), '24', '24'); | |
30612 assert.equal(moment([2011, 0, 25]).format('DDDo'), '25', '25'); | |
30613 assert.equal(moment([2011, 0, 26]).format('DDDo'), '26', '26'); | |
30614 assert.equal(moment([2011, 0, 27]).format('DDDo'), '27', '27'); | |
30615 assert.equal(moment([2011, 0, 28]).format('DDDo'), '28', '28'); | |
30616 assert.equal(moment([2011, 0, 29]).format('DDDo'), '29', '29'); | |
30617 assert.equal(moment([2011, 0, 30]).format('DDDo'), '30', '30'); | |
30618 | |
30619 assert.equal(moment([2011, 0, 31]).format('DDDo'), '31', '31'); | |
30620 }); | |
30621 | |
30622 test('format month', function (assert) { | |
30623 var i, | |
30624 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('_'); | |
30625 | |
30626 for (i = 0; i < expected.length; i++) { | |
30627 assert.equal(moment([2011, i, 1]).format('MMMM,MMM'), expected[i], expected[i]); | |
30628 } | |
30629 }); | |
30630 | |
30631 test('format week', function (assert) { | |
30632 var i, | |
30633 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('_'); | |
30634 | |
30635 for (i = 0; i < expected.length; i++) { | |
30636 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
30637 } | |
30638 }); | |
30639 | |
30640 test('from', function (assert) { | |
30641 var start = moment([2007, 1, 28]); | |
30642 | |
30643 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), 'vài giây', '44 seconds = a few seconds'); | |
30644 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), 'một phút', '45 seconds = a minute'); | |
30645 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), 'một phút', '89 seconds = a minute'); | |
30646 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 phút', '90 seconds = 2 minutes'); | |
30647 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 phút', '44 minutes = 44 minutes'); | |
30648 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), 'một giờ', '45 minutes = an hour'); | |
30649 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), 'một giờ', '89 minutes = an hour'); | |
30650 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 giờ', '90 minutes = 2 hours'); | |
30651 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 giờ', '5 hours = 5 hours'); | |
30652 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 giờ', '21 hours = 21 hours'); | |
30653 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), 'một ngày', '22 hours = a day'); | |
30654 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), 'một ngày', '35 hours = a day'); | |
30655 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 ngày', '36 hours = 2 days'); | |
30656 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), 'một ngày', '1 day = a day'); | |
30657 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 ngày', '5 days = 5 days'); | |
30658 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 ngày', '25 days = 25 days'); | |
30659 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), 'một tháng', '26 days = a month'); | |
30660 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), 'một tháng', '30 days = a month'); | |
30661 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), 'một tháng', '43 days = a month'); | |
30662 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 tháng', '46 days = 2 months'); | |
30663 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 tháng', '75 days = 2 months'); | |
30664 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 tháng', '76 days = 3 months'); | |
30665 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), 'một tháng', '1 month = a month'); | |
30666 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 tháng', '5 months = 5 months'); | |
30667 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), 'một năm', '345 days = a year'); | |
30668 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 năm', '548 days = 2 years'); | |
30669 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), 'một năm', '1 year = a year'); | |
30670 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 năm', '5 years = 5 years'); | |
30671 }); | |
30672 | |
30673 test('suffix', function (assert) { | |
30674 assert.equal(moment(30000).from(0), 'vài giây tới', 'prefix'); | |
30675 assert.equal(moment(0).from(30000), 'vài giây trước', 'suffix'); | |
30676 }); | |
30677 | |
30678 test('now from now', function (assert) { | |
30679 assert.equal(moment().fromNow(), 'vài giây trước', 'now from now should display as in the past'); | |
30680 }); | |
30681 | |
30682 test('fromNow', function (assert) { | |
30683 assert.equal(moment().add({s: 30}).fromNow(), 'vài giây tới', 'in a few seconds'); | |
30684 assert.equal(moment().add({d: 5}).fromNow(), '5 ngày tới', 'in 5 days'); | |
30685 }); | |
30686 | |
30687 test('calendar day', function (assert) { | |
30688 var a = moment().hours(2).minutes(0).seconds(0); | |
30689 | |
30690 assert.equal(moment(a).calendar(), 'Hôm nay lúc 02:00', 'today at the same time'); | |
30691 assert.equal(moment(a).add({m: 25}).calendar(), 'Hôm nay lúc 02:25', 'Now plus 25 min'); | |
30692 assert.equal(moment(a).add({h: 1}).calendar(), 'Hôm nay lúc 03:00', 'Now plus 1 hour'); | |
30693 assert.equal(moment(a).add({d: 1}).calendar(), 'Ngày mai lúc 02:00', 'tomorrow at the same time'); | |
30694 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Hôm nay lúc 01:00', 'Now minus 1 hour'); | |
30695 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Hôm qua lúc 02:00', 'yesterday at the same time'); | |
30696 }); | |
30697 | |
30698 test('calendar next week', function (assert) { | |
30699 var i, m; | |
30700 | |
30701 for (i = 2; i < 7; i++) { | |
30702 m = moment().add({d: i}); | |
30703 assert.equal(m.calendar(), m.format('dddd [tuần tới lúc] LT'), 'Today + ' + i + ' days current time'); | |
30704 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
30705 assert.equal(m.calendar(), m.format('dddd [tuần tới lúc] LT'), 'Today + ' + i + ' days beginning of day'); | |
30706 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
30707 assert.equal(m.calendar(), m.format('dddd [tuần tới lúc] LT'), 'Today + ' + i + ' days end of day'); | |
30708 } | |
30709 }); | |
30710 | |
30711 test('calendar last week', function (assert) { | |
30712 var i, m; | |
30713 | |
30714 for (i = 2; i < 7; i++) { | |
30715 m = moment().subtract({d: i}); | |
30716 assert.equal(m.calendar(), m.format('dddd [tuần rồi lúc] LT'), 'Today - ' + i + ' days current time'); | |
30717 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
30718 assert.equal(m.calendar(), m.format('dddd [tuần rồi lúc] LT'), 'Today - ' + i + ' days beginning of day'); | |
30719 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
30720 assert.equal(m.calendar(), m.format('dddd [tuần rồi lúc] LT'), 'Today - ' + i + ' days end of day'); | |
30721 } | |
30722 }); | |
30723 | |
30724 test('calendar all else', function (assert) { | |
30725 var weeksAgo = moment().subtract({w: 1}), | |
30726 weeksFromNow = moment().add({w: 1}); | |
30727 | |
30728 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
30729 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
30730 | |
30731 weeksAgo = moment().subtract({w: 2}); | |
30732 weeksFromNow = moment().add({w: 2}); | |
30733 | |
30734 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
30735 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
30736 }); | |
30737 | |
30738 test('weeks year starting sunday', function (assert) { | |
30739 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
30740 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 1'); | |
30741 assert.equal(moment([2012, 0, 8]).week(), 1, 'Jan 8 2012 should be week 1'); | |
30742 assert.equal(moment([2012, 0, 9]).week(), 2, 'Jan 9 2012 should be week 2'); | |
30743 assert.equal(moment([2012, 0, 15]).week(), 2, 'Jan 15 2012 should be week 2'); | |
30744 }); | |
30745 | |
30746 test('weeks year starting monday', function (assert) { | |
30747 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
30748 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
30749 assert.equal(moment([2007, 0, 8]).week(), 2, 'Jan 8 2007 should be week 2'); | |
30750 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
30751 assert.equal(moment([2007, 0, 15]).week(), 3, 'Jan 15 2007 should be week 3'); | |
30752 }); | |
30753 | |
30754 test('weeks year starting tuesday', function (assert) { | |
30755 assert.equal(moment([2007, 11, 31]).week(), 1, 'Dec 31 2007 should be week 1'); | |
30756 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
30757 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
30758 assert.equal(moment([2008, 0, 7]).week(), 2, 'Jan 7 2008 should be week 2'); | |
30759 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
30760 assert.equal(moment([2008, 0, 14]).week(), 3, 'Jan 14 2008 should be week 3'); | |
30761 }); | |
30762 | |
30763 test('weeks year starting wednesday', function (assert) { | |
30764 assert.equal(moment([2002, 11, 30]).week(), 1, 'Dec 30 2002 should be week 1'); | |
30765 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
30766 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
30767 assert.equal(moment([2003, 0, 6]).week(), 2, 'Jan 6 2003 should be week 2'); | |
30768 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
30769 assert.equal(moment([2003, 0, 13]).week(), 3, 'Jan 13 2003 should be week 3'); | |
30770 }); | |
30771 | |
30772 test('weeks year starting thursday', function (assert) { | |
30773 assert.equal(moment([2008, 11, 29]).week(), 1, 'Dec 29 2008 should be week 1'); | |
30774 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
30775 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
30776 assert.equal(moment([2009, 0, 5]).week(), 2, 'Jan 5 2009 should be week 2'); | |
30777 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
30778 assert.equal(moment([2009, 0, 13]).week(), 3, 'Jan 12 2009 should be week 3'); | |
30779 }); | |
30780 | |
30781 test('weeks year starting friday', function (assert) { | |
30782 assert.equal(moment([2009, 11, 28]).week(), 53, 'Dec 28 2009 should be week 53'); | |
30783 assert.equal(moment([2010, 0, 1]).week(), 53, 'Jan 1 2010 should be week 53'); | |
30784 assert.equal(moment([2010, 0, 3]).week(), 53, 'Jan 3 2010 should be week 53'); | |
30785 assert.equal(moment([2010, 0, 4]).week(), 1, 'Jan 4 2010 should be week 1'); | |
30786 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
30787 assert.equal(moment([2010, 0, 11]).week(), 2, 'Jan 11 2010 should be week 2'); | |
30788 }); | |
30789 | |
30790 test('weeks year starting saturday', function (assert) { | |
30791 assert.equal(moment([2010, 11, 27]).week(), 52, 'Dec 27 2010 should be week 52'); | |
30792 assert.equal(moment([2011, 0, 1]).week(), 52, 'Jan 1 2011 should be week 52'); | |
30793 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
30794 assert.equal(moment([2011, 0, 3]).week(), 1, 'Jan 3 2011 should be week 1'); | |
30795 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
30796 assert.equal(moment([2011, 0, 10]).week(), 2, 'Jan 10 2011 should be week 2'); | |
30797 }); | |
30798 | |
30799 test('weeks year starting sunday formatted', function (assert) { | |
30800 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52', 'Jan 1 2012 should be week 52'); | |
30801 assert.equal(moment([2012, 0, 2]).format('w ww wo'), '1 01 1', 'Jan 2 2012 should be week 1'); | |
30802 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '1 01 1', 'Jan 8 2012 should be week 1'); | |
30803 assert.equal(moment([2012, 0, 9]).format('w ww wo'), '2 02 2', 'Jan 9 2012 should be week 2'); | |
30804 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '2 02 2', 'Jan 15 2012 should be week 2'); | |
30805 }); | |
30806 | |
30807 test('lenient ordinal parsing', function (assert) { | |
30808 var i, ordinalStr, testMoment; | |
30809 for (i = 1; i <= 31; ++i) { | |
30810 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
30811 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
30812 assert.equal(testMoment.year(), 2014, | |
30813 'lenient ordinal parsing ' + i + ' year check'); | |
30814 assert.equal(testMoment.month(), 0, | |
30815 'lenient ordinal parsing ' + i + ' month check'); | |
30816 assert.equal(testMoment.date(), i, | |
30817 'lenient ordinal parsing ' + i + ' date check'); | |
30818 } | |
30819 }); | |
30820 | |
30821 test('lenient ordinal parsing of number', function (assert) { | |
30822 var i, testMoment; | |
30823 for (i = 1; i <= 31; ++i) { | |
30824 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
30825 assert.equal(testMoment.year(), 2014, | |
30826 'lenient ordinal parsing of number ' + i + ' year check'); | |
30827 assert.equal(testMoment.month(), 0, | |
30828 'lenient ordinal parsing of number ' + i + ' month check'); | |
30829 assert.equal(testMoment.date(), i, | |
30830 'lenient ordinal parsing of number ' + i + ' date check'); | |
30831 } | |
30832 }); | |
30833 | |
30834 test('strict ordinal parsing', function (assert) { | |
30835 var i, ordinalStr, testMoment; | |
30836 for (i = 1; i <= 31; ++i) { | |
30837 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
30838 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
30839 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
30840 } | |
30841 }); | |
30842 | |
30843 })); | |
30844 | |
30845 (function (global, factory) { | |
30846 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
30847 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
30848 factory(global.moment) | |
30849 }(this, function (moment) { 'use strict'; | |
30850 | |
30851 /*global QUnit:false*/ | |
30852 | |
30853 var test = QUnit.test; | |
30854 | |
30855 function module (name, lifecycle) { | |
30856 QUnit.module(name, { | |
30857 setup : function () { | |
30858 moment.locale('en'); | |
30859 moment.createFromInputFallback = function () { | |
30860 throw new Error('input not handled by moment'); | |
30861 }; | |
30862 if (lifecycle && lifecycle.setup) { | |
30863 lifecycle.setup(); | |
30864 } | |
30865 }, | |
30866 teardown : function () { | |
30867 if (lifecycle && lifecycle.teardown) { | |
30868 lifecycle.teardown(); | |
30869 } | |
30870 } | |
30871 }); | |
30872 } | |
30873 | |
30874 function localeModule (name, lifecycle) { | |
30875 QUnit.module('locale:' + name, { | |
30876 setup : function () { | |
30877 moment.locale(name); | |
30878 moment.createFromInputFallback = function () { | |
30879 throw new Error('input not handled by moment'); | |
30880 }; | |
30881 if (lifecycle && lifecycle.setup) { | |
30882 lifecycle.setup(); | |
30883 } | |
30884 }, | |
30885 teardown : function () { | |
30886 moment.locale('en'); | |
30887 if (lifecycle && lifecycle.teardown) { | |
30888 lifecycle.teardown(); | |
30889 } | |
30890 } | |
30891 }); | |
30892 } | |
30893 | |
30894 localeModule('zh-cn'); | |
30895 | |
30896 test('parse', function (assert) { | |
30897 var tests = '一月 1月_二月 2月_三月 3月_四月 4月_五月 5月_六月 6月_七月 7月_八月 8月_九月 9月_十月 10月_十一月 11月_十二月 12月'.split('_'), i; | |
30898 | |
30899 function equalTest(input, mmm, i) { | |
30900 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
30901 } | |
30902 | |
30903 for (i = 0; i < 12; i++) { | |
30904 tests[i] = tests[i].split(' '); | |
30905 equalTest(tests[i][0], 'MMM', i); | |
30906 equalTest(tests[i][1], 'MMM', i); | |
30907 equalTest(tests[i][0], 'MMMM', i); | |
30908 equalTest(tests[i][1], 'MMMM', i); | |
30909 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
30910 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
30911 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
30912 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
30913 } | |
30914 }); | |
30915 | |
30916 test('format', function (assert) { | |
30917 var a = [ | |
30918 ['dddd, MMMM Do YYYY, a h:mm:ss', '星期日, 二月 14日 2010, 下午 3:25:50'], | |
30919 ['ddd, Ah', '周日, 下午3'], | |
30920 ['M Mo MM MMMM MMM', '2 2月 02 二月 2月'], | |
30921 ['YYYY YY', '2010 10'], | |
30922 ['D Do DD', '14 14日 14'], | |
30923 ['d do dddd ddd dd', '0 0日 星期日 周日 日'], | |
30924 ['DDD DDDo DDDD', '45 45日 045'], | |
30925 ['w wo ww', '6 6周 06'], | |
30926 ['h hh', '3 03'], | |
30927 ['H HH', '15 15'], | |
30928 ['m mm', '25 25'], | |
30929 ['s ss', '50 50'], | |
30930 ['a A', '下午 下午'], | |
30931 ['[这年的第] DDDo', '这年的第 45日'], | |
30932 ['LTS', '下午3点25分50秒'], | |
30933 ['L', '2010-02-14'], | |
30934 ['LL', '2010年2月14日'], | |
30935 ['LLL', '2010年2月14日下午3点25分'], | |
30936 ['LLLL', '2010年2月14日星期日下午3点25分'], | |
30937 ['l', '2010-02-14'], | |
30938 ['ll', '2010年2月14日'], | |
30939 ['lll', '2010年2月14日下午3点25分'], | |
30940 ['llll', '2010年2月14日星期日下午3点25分'] | |
30941 ], | |
30942 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
30943 i; | |
30944 | |
30945 for (i = 0; i < a.length; i++) { | |
30946 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
30947 } | |
30948 }); | |
30949 | |
30950 test('format month', function (assert) { | |
30951 var expected = '一月 1月_二月 2月_三月 3月_四月 4月_五月 5月_六月 6月_七月 7月_八月 8月_九月 9月_十月 10月_十一月 11月_十二月 12月'.split('_'), i; | |
30952 | |
30953 for (i = 0; i < expected.length; i++) { | |
30954 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
30955 } | |
30956 }); | |
30957 | |
30958 test('format week', function (assert) { | |
30959 var expected = '星期日 周日 日_星期一 周一 一_星期二 周二 二_星期三 周三 三_星期四 周四 四_星期五 周五 五_星期六 周六 六'.split('_'), i; | |
30960 | |
30961 for (i = 0; i < expected.length; i++) { | |
30962 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
30963 } | |
30964 }); | |
30965 | |
30966 test('from', function (assert) { | |
30967 var start = moment([2007, 1, 28]); | |
30968 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), '几秒', '44 seconds = a few seconds'); | |
30969 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '1 分钟', '45 seconds = a minute'); | |
30970 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '1 分钟', '89 seconds = a minute'); | |
30971 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2 分钟', '90 seconds = 2 minutes'); | |
30972 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44 分钟', '44 minutes = 44 minutes'); | |
30973 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '1 小时', '45 minutes = an hour'); | |
30974 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '1 小时', '89 minutes = an hour'); | |
30975 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2 小时', '90 minutes = 2 hours'); | |
30976 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5 小时', '5 hours = 5 hours'); | |
30977 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21 小时', '21 hours = 21 hours'); | |
30978 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '1 天', '22 hours = a day'); | |
30979 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '1 天', '35 hours = a day'); | |
30980 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2 天', '36 hours = 2 days'); | |
30981 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '1 天', '1 day = a day'); | |
30982 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5 天', '5 days = 5 days'); | |
30983 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25 天', '25 days = 25 days'); | |
30984 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '1 个月', '26 days = a month'); | |
30985 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '1 个月', '30 days = a month'); | |
30986 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '1 个月', '43 days = a month'); | |
30987 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2 个月', '46 days = 2 months'); | |
30988 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2 个月', '75 days = 2 months'); | |
30989 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3 个月', '76 days = 3 months'); | |
30990 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '1 个月', '1 month = a month'); | |
30991 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5 个月', '5 months = 5 months'); | |
30992 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '1 年', '345 days = a year'); | |
30993 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2 年', '548 days = 2 years'); | |
30994 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '1 年', '1 year = a year'); | |
30995 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5 年', '5 years = 5 years'); | |
30996 }); | |
30997 | |
30998 test('suffix', function (assert) { | |
30999 assert.equal(moment(30000).from(0), '几秒内', 'prefix'); | |
31000 assert.equal(moment(0).from(30000), '几秒前', 'suffix'); | |
31001 }); | |
31002 | |
31003 test('now from now', function (assert) { | |
31004 assert.equal(moment().fromNow(), '几秒前', 'now from now should display as in the past'); | |
31005 }); | |
31006 | |
31007 test('fromNow', function (assert) { | |
31008 assert.equal(moment().add({s: 30}).fromNow(), '几秒内', 'in a few seconds'); | |
31009 assert.equal(moment().add({d: 5}).fromNow(), '5 天内', 'in 5 days'); | |
31010 }); | |
31011 | |
31012 test('calendar day', function (assert) { | |
31013 var a = moment().hours(2).minutes(0).seconds(0); | |
31014 | |
31015 assert.equal(moment(a).calendar(), '今天凌晨2点整', 'today at the same time'); | |
31016 assert.equal(moment(a).add({m: 25}).calendar(), '今天凌晨2点25分', 'Now plus 25 min'); | |
31017 assert.equal(moment(a).add({h: 1}).calendar(), '今天凌晨3点整', 'Now plus 1 hour'); | |
31018 assert.equal(moment(a).add({d: 1}).calendar(), '明天凌晨2点整', 'tomorrow at the same time'); | |
31019 assert.equal(moment(a).subtract({h: 1}).calendar(), '今天凌晨1点整', 'Now minus 1 hour'); | |
31020 assert.equal(moment(a).subtract({d: 1}).calendar(), '昨天凌晨2点整', 'yesterday at the same time'); | |
31021 }); | |
31022 | |
31023 test('calendar current week', function (assert) { | |
31024 var i, m, | |
31025 today = moment().startOf('day'); | |
31026 | |
31027 for (i = 0; i < 7; i++) { | |
31028 m = moment().startOf('week').add({d: i}); | |
31029 if (Math.abs(m.diff(today, 'days')) <= 1) { | |
31030 continue; // skip today, yesterday, tomorrow | |
31031 } | |
31032 assert.equal(m.calendar(), m.format('[本]ddd凌晨12点整'), 'Monday + ' + i + ' days current time'); | |
31033 } | |
31034 }); | |
31035 | |
31036 test('calendar next week', function (assert) { | |
31037 var i, m, | |
31038 today = moment().startOf('day'); | |
31039 | |
31040 for (i = 7; i < 14; i++) { | |
31041 m = moment().startOf('week').add({d: i}); | |
31042 if (Math.abs(m.diff(today, 'days')) >= 7) { | |
31043 continue; | |
31044 } | |
31045 if (Math.abs(m.diff(today, 'days')) <= 1) { | |
31046 continue; // skip today, yesterday, tomorrow | |
31047 } | |
31048 assert.equal(m.calendar(), m.format('[下]ddd凌晨12点整'), 'Today + ' + i + ' days beginning of day'); | |
31049 } | |
31050 assert.equal(42, 42, 'at least one assert'); | |
31051 }); | |
31052 | |
31053 test('calendar last week', function (assert) { | |
31054 var i, m, | |
31055 today = moment().startOf('day'); | |
31056 | |
31057 for (i = 1; i < 8; i++) { | |
31058 m = moment().startOf('week').subtract({d: i}); | |
31059 if ((Math.abs(m.diff(today, 'days')) >= 7) || (Math.abs(m.diff(today, 'days')) <= 1)) { | |
31060 continue; | |
31061 } | |
31062 assert.equal(m.calendar(), m.format('[上]ddd凌晨12点整'), 'Monday - ' + i + ' days next week'); | |
31063 } | |
31064 assert.equal(42, 42, 'at least one assert'); | |
31065 }); | |
31066 | |
31067 test('calendar all else', function (assert) { | |
31068 var weeksAgo = moment().subtract({w: 1}), | |
31069 weeksFromNow = moment().add({w: 1}); | |
31070 | |
31071 assert.equal(weeksAgo.calendar(), weeksAgo.format('LL'), '1 week ago'); | |
31072 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('LL'), 'in 1 week'); | |
31073 | |
31074 weeksAgo = moment().subtract({w: 2}); | |
31075 weeksFromNow = moment().add({w: 2}); | |
31076 | |
31077 assert.equal(weeksAgo.calendar(), weeksAgo.format('LL'), '2 weeks ago'); | |
31078 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('LL'), 'in 2 weeks'); | |
31079 }); | |
31080 | |
31081 test('meridiem', function (assert) { | |
31082 assert.equal(moment([2011, 2, 23, 0, 0]).format('A'), '凌晨', 'before dawn'); | |
31083 assert.equal(moment([2011, 2, 23, 6, 0]).format('A'), '早上', 'morning'); | |
31084 assert.equal(moment([2011, 2, 23, 9, 0]).format('A'), '上午', 'before noon'); | |
31085 assert.equal(moment([2011, 2, 23, 12, 0]).format('A'), '中午', 'noon'); | |
31086 assert.equal(moment([2011, 2, 23, 13, 0]).format('A'), '下午', 'afternoon'); | |
31087 assert.equal(moment([2011, 2, 23, 18, 0]).format('A'), '晚上', 'night'); | |
31088 }); | |
31089 | |
31090 test('weeks year starting sunday', function (assert) { | |
31091 assert.equal(moment([2012, 0, 1]).week(), 52, 'Jan 1 2012 should be week 52'); | |
31092 assert.equal(moment([2012, 0, 2]).week(), 1, 'Jan 2 2012 should be week 52'); | |
31093 assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1'); | |
31094 assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2'); | |
31095 }); | |
31096 | |
31097 test('weeks year starting monday', function (assert) { | |
31098 assert.equal(moment([2006, 11, 31]).week(), 52, 'Dec 31 2006 should be week 52'); | |
31099 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
31100 assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1'); | |
31101 assert.equal(moment([2007, 0, 7]).week(), 1, 'Jan 7 2007 should be week 1'); | |
31102 assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2'); | |
31103 assert.equal(moment([2007, 0, 14]).week(), 2, 'Jan 14 2007 should be week 2'); | |
31104 }); | |
31105 | |
31106 test('weeks year starting tuesday', function (assert) { | |
31107 assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52'); | |
31108 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
31109 assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1'); | |
31110 assert.equal(moment([2008, 0, 6]).week(), 1, 'Jan 6 2008 should be week 1'); | |
31111 assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2'); | |
31112 assert.equal(moment([2008, 0, 13]).week(), 2, 'Jan 13 2008 should be week 2'); | |
31113 }); | |
31114 | |
31115 test('weeks year starting wednesday', function (assert) { | |
31116 assert.equal(moment([2002, 11, 29]).week(), 52, 'Dec 29 2002 should be week 52'); | |
31117 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
31118 assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1'); | |
31119 assert.equal(moment([2003, 0, 5]).week(), 1, 'Jan 5 2003 should be week 1'); | |
31120 assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2'); | |
31121 assert.equal(moment([2003, 0, 12]).week(), 2, 'Jan 12 2003 should be week 2'); | |
31122 }); | |
31123 | |
31124 test('weeks year starting thursday', function (assert) { | |
31125 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
31126 assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1'); | |
31127 assert.equal(moment([2009, 0, 4]).week(), 1, 'Jan 4 2009 should be week 1'); | |
31128 assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2'); | |
31129 assert.equal(moment([2009, 0, 11]).week(), 2, 'Jan 11 2009 should be week 2'); | |
31130 }); | |
31131 | |
31132 test('weeks year starting friday', function (assert) { | |
31133 assert.equal(moment([2010, 0, 2]).week(), 53, 'Jan 2 2010 should be week 53'); | |
31134 assert.equal(moment([2010, 0, 10]).week(), 1, 'Jan 10 2010 should be week 1'); | |
31135 }); | |
31136 | |
31137 test('weeks year starting saturday', function (assert) { | |
31138 assert.equal(moment([2011, 0, 2]).week(), 52, 'Jan 2 2011 should be week 52'); | |
31139 assert.equal(moment([2011, 0, 8]).week(), 1, 'Jan 8 2011 should be week 1'); | |
31140 assert.equal(moment([2011, 0, 9]).week(), 1, 'Jan 9 2011 should be week 1'); | |
31141 }); | |
31142 | |
31143 test('weeks year starting sunday format', function (assert) { | |
31144 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '52 52 52周', 'Jan 1 2012 应该是第52周'); | |
31145 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1周', 'Jan 7 2012 应该是第 1周'); | |
31146 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2周', 'Jan 14 2012 应该是第 2周'); | |
31147 }); | |
31148 | |
31149 test('lenient ordinal parsing', function (assert) { | |
31150 var i, ordinalStr, testMoment; | |
31151 for (i = 1; i <= 31; ++i) { | |
31152 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
31153 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
31154 assert.equal(testMoment.year(), 2014, | |
31155 'lenient ordinal parsing ' + i + ' year check'); | |
31156 assert.equal(testMoment.month(), 0, | |
31157 'lenient ordinal parsing ' + i + ' month check'); | |
31158 assert.equal(testMoment.date(), i, | |
31159 'lenient ordinal parsing ' + i + ' date check'); | |
31160 } | |
31161 }); | |
31162 | |
31163 test('lenient ordinal parsing of number', function (assert) { | |
31164 var i, testMoment; | |
31165 for (i = 1; i <= 31; ++i) { | |
31166 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
31167 assert.equal(testMoment.year(), 2014, | |
31168 'lenient ordinal parsing of number ' + i + ' year check'); | |
31169 assert.equal(testMoment.month(), 0, | |
31170 'lenient ordinal parsing of number ' + i + ' month check'); | |
31171 assert.equal(testMoment.date(), i, | |
31172 'lenient ordinal parsing of number ' + i + ' date check'); | |
31173 } | |
31174 }); | |
31175 | |
31176 test('meridiem invariant', function (assert) { | |
31177 var h, m, t1, t2; | |
31178 for (h = 0; h < 24; ++h) { | |
31179 for (m = 0; m < 60; m += 15) { | |
31180 t1 = moment.utc([2000, 0, 1, h, m]); | |
31181 t2 = moment(t1.format('A h:mm'), 'A h:mm'); | |
31182 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'), | |
31183 'meridiem at ' + t1.format('HH:mm')); | |
31184 } | |
31185 } | |
31186 }); | |
31187 | |
31188 test('strict ordinal parsing', function (assert) { | |
31189 var i, ordinalStr, testMoment; | |
31190 for (i = 1; i <= 31; ++i) { | |
31191 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
31192 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
31193 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
31194 } | |
31195 }); | |
31196 | |
31197 })); | |
31198 | |
31199 (function (global, factory) { | |
31200 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
31201 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
31202 factory(global.moment) | |
31203 }(this, function (moment) { 'use strict'; | |
31204 | |
31205 /*global QUnit:false*/ | |
31206 | |
31207 var test = QUnit.test; | |
31208 | |
31209 function module (name, lifecycle) { | |
31210 QUnit.module(name, { | |
31211 setup : function () { | |
31212 moment.locale('en'); | |
31213 moment.createFromInputFallback = function () { | |
31214 throw new Error('input not handled by moment'); | |
31215 }; | |
31216 if (lifecycle && lifecycle.setup) { | |
31217 lifecycle.setup(); | |
31218 } | |
31219 }, | |
31220 teardown : function () { | |
31221 if (lifecycle && lifecycle.teardown) { | |
31222 lifecycle.teardown(); | |
31223 } | |
31224 } | |
31225 }); | |
31226 } | |
31227 | |
31228 function localeModule (name, lifecycle) { | |
31229 QUnit.module('locale:' + name, { | |
31230 setup : function () { | |
31231 moment.locale(name); | |
31232 moment.createFromInputFallback = function () { | |
31233 throw new Error('input not handled by moment'); | |
31234 }; | |
31235 if (lifecycle && lifecycle.setup) { | |
31236 lifecycle.setup(); | |
31237 } | |
31238 }, | |
31239 teardown : function () { | |
31240 moment.locale('en'); | |
31241 if (lifecycle && lifecycle.teardown) { | |
31242 lifecycle.teardown(); | |
31243 } | |
31244 } | |
31245 }); | |
31246 } | |
31247 | |
31248 localeModule('zh-tw'); | |
31249 | |
31250 test('parse', function (assert) { | |
31251 var tests = '一月 1月_二月 2月_三月 3月_四月 4月_五月 5月_六月 6月_七月 7月_八月 8月_九月 9月_十月 10月_十一月 11月_十二月 12月'.split('_'), i; | |
31252 function equalTest(input, mmm, i) { | |
31253 assert.equal(moment(input, mmm).month(), i, input + ' should be month ' + (i + 1)); | |
31254 } | |
31255 for (i = 0; i < 12; i++) { | |
31256 tests[i] = tests[i].split(' '); | |
31257 equalTest(tests[i][0], 'MMM', i); | |
31258 equalTest(tests[i][1], 'MMM', i); | |
31259 equalTest(tests[i][0], 'MMMM', i); | |
31260 equalTest(tests[i][1], 'MMMM', i); | |
31261 equalTest(tests[i][0].toLocaleLowerCase(), 'MMMM', i); | |
31262 equalTest(tests[i][1].toLocaleLowerCase(), 'MMMM', i); | |
31263 equalTest(tests[i][0].toLocaleUpperCase(), 'MMMM', i); | |
31264 equalTest(tests[i][1].toLocaleUpperCase(), 'MMMM', i); | |
31265 } | |
31266 }); | |
31267 | |
31268 test('format', function (assert) { | |
31269 var a = [ | |
31270 ['dddd, MMMM Do YYYY, a h:mm:ss', '星期日, 二月 14日 2010, 下午 3:25:50'], | |
31271 ['ddd, Ah', '週日, 下午3'], | |
31272 ['M Mo MM MMMM MMM', '2 2月 02 二月 2月'], | |
31273 ['YYYY YY', '2010 10'], | |
31274 ['D Do DD', '14 14日 14'], | |
31275 ['d do dddd ddd dd', '0 0日 星期日 週日 日'], | |
31276 ['DDD DDDo DDDD', '45 45日 045'], | |
31277 ['w wo ww', '8 8週 08'], | |
31278 ['h hh', '3 03'], | |
31279 ['H HH', '15 15'], | |
31280 ['m mm', '25 25'], | |
31281 ['s ss', '50 50'], | |
31282 ['a A', '下午 下午'], | |
31283 ['[這年的第] DDDo', '這年的第 45日'], | |
31284 ['LTS', '下午3點25分50秒'], | |
31285 ['L', '2010年2月14日'], | |
31286 ['LL', '2010年2月14日'], | |
31287 ['LLL', '2010年2月14日下午3點25分'], | |
31288 ['LLLL', '2010年2月14日星期日下午3點25分'], | |
31289 ['l', '2010年2月14日'], | |
31290 ['ll', '2010年2月14日'], | |
31291 ['lll', '2010年2月14日下午3點25分'], | |
31292 ['llll', '2010年2月14日星期日下午3點25分'] | |
31293 ], | |
31294 b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)), | |
31295 i; | |
31296 | |
31297 for (i = 0; i < a.length; i++) { | |
31298 assert.equal(b.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
31299 } | |
31300 }); | |
31301 | |
31302 test('format month', function (assert) { | |
31303 var expected = '一月 1月_二月 2月_三月 3月_四月 4月_五月 5月_六月 6月_七月 7月_八月 8月_九月 9月_十月 10月_十一月 11月_十二月 12月'.split('_'), i; | |
31304 | |
31305 for (i = 0; i < expected.length; i++) { | |
31306 assert.equal(moment([2011, i, 1]).format('MMMM MMM'), expected[i], expected[i]); | |
31307 } | |
31308 }); | |
31309 | |
31310 test('format week', function (assert) { | |
31311 var expected = '星期日 週日 日_星期一 週一 一_星期二 週二 二_星期三 週三 三_星期四 週四 四_星期五 週五 五_星期六 週六 六'.split('_'), i; | |
31312 | |
31313 for (i = 0; i < expected.length; i++) { | |
31314 assert.equal(moment([2011, 0, 2 + i]).format('dddd ddd dd'), expected[i], expected[i]); | |
31315 } | |
31316 }); | |
31317 | |
31318 test('from', function (assert) { | |
31319 var start = moment([2007, 1, 28]); | |
31320 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44}), true), '幾秒', '44 seconds = a few seconds'); | |
31321 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45}), true), '一分鐘', '45 seconds = a minute'); | |
31322 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89}), true), '一分鐘', '89 seconds = a minute'); | |
31323 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '2分鐘', '90 seconds = 2 minutes'); | |
31324 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44}), true), '44分鐘', '44 minutes = 44 minutes'); | |
31325 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45}), true), '一小時', '45 minutes = an hour'); | |
31326 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89}), true), '一小時', '89 minutes = an hour'); | |
31327 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90}), true), '2小時', '90 minutes = 2 hours'); | |
31328 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5}), true), '5小時', '5 hours = 5 hours'); | |
31329 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21}), true), '21小時', '21 hours = 21 hours'); | |
31330 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22}), true), '一天', '22 hours = a day'); | |
31331 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35}), true), '一天', '35 hours = a day'); | |
31332 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36}), true), '2天', '36 hours = 2 days'); | |
31333 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1}), true), '一天', '1 day = a day'); | |
31334 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5}), true), '5天', '5 days = 5 days'); | |
31335 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25}), true), '25天', '25 days = 25 days'); | |
31336 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26}), true), '一個月', '26 days = a month'); | |
31337 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30}), true), '一個月', '30 days = a month'); | |
31338 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43}), true), '一個月', '43 days = a month'); | |
31339 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46}), true), '2個月', '46 days = 2 months'); | |
31340 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74}), true), '2個月', '75 days = 2 months'); | |
31341 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76}), true), '3個月', '76 days = 3 months'); | |
31342 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1}), true), '一個月', '1 month = a month'); | |
31343 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5}), true), '5個月', '5 months = 5 months'); | |
31344 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345}), true), '一年', '345 days = a year'); | |
31345 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548}), true), '2年', '548 days = 2 years'); | |
31346 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1}), true), '一年', '1 year = a year'); | |
31347 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5}), true), '5年', '5 years = 5 years'); | |
31348 }); | |
31349 | |
31350 test('suffix', function (assert) { | |
31351 assert.equal(moment(30000).from(0), '幾秒內', 'prefix'); | |
31352 assert.equal(moment(0).from(30000), '幾秒前', 'suffix'); | |
31353 }); | |
31354 | |
31355 test('now from now', function (assert) { | |
31356 assert.equal(moment().fromNow(), '幾秒前', 'now from now should display as in the past'); | |
31357 }); | |
31358 | |
31359 test('fromNow', function (assert) { | |
31360 assert.equal(moment().add({s: 30}).fromNow(), '幾秒內', 'in a few seconds'); | |
31361 assert.equal(moment().add({d: 5}).fromNow(), '5天內', 'in 5 days'); | |
31362 }); | |
31363 | |
31364 test('calendar day', function (assert) { | |
31365 var a = moment().hours(2).minutes(0).seconds(0); | |
31366 | |
31367 assert.equal(moment(a).calendar(), '今天早上2點00分', 'today at the same time'); | |
31368 assert.equal(moment(a).add({m: 25}).calendar(), '今天早上2點25分', 'Now plus 25 min'); | |
31369 assert.equal(moment(a).add({h: 1}).calendar(), '今天早上3點00分', 'Now plus 1 hour'); | |
31370 assert.equal(moment(a).add({d: 1}).calendar(), '明天早上2點00分', 'tomorrow at the same time'); | |
31371 assert.equal(moment(a).subtract({h: 1}).calendar(), '今天早上1點00分', 'Now minus 1 hour'); | |
31372 assert.equal(moment(a).subtract({d: 1}).calendar(), '昨天早上2點00分', 'yesterday at the same time'); | |
31373 }); | |
31374 | |
31375 test('calendar next week', function (assert) { | |
31376 var i, m; | |
31377 for (i = 2; i < 7; i++) { | |
31378 m = moment().add({d: i}); | |
31379 assert.equal(m.calendar(), m.format('[下]ddddLT'), 'Today + ' + i + ' days current time'); | |
31380 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
31381 assert.equal(m.calendar(), m.format('[下]ddddLT'), 'Today + ' + i + ' days beginning of day'); | |
31382 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
31383 assert.equal(m.calendar(), m.format('[下]ddddLT'), 'Today + ' + i + ' days end of day'); | |
31384 } | |
31385 }); | |
31386 | |
31387 test('calendar last week', function (assert) { | |
31388 var i, m; | |
31389 for (i = 2; i < 7; i++) { | |
31390 m = moment().subtract({d: i}); | |
31391 assert.equal(m.calendar(), m.format('[上]ddddLT'), 'Today - ' + i + ' days current time'); | |
31392 m.hours(0).minutes(0).seconds(0).milliseconds(0); | |
31393 assert.equal(m.calendar(), m.format('[上]ddddLT'), 'Today - ' + i + ' days beginning of day'); | |
31394 m.hours(23).minutes(59).seconds(59).milliseconds(999); | |
31395 assert.equal(m.calendar(), m.format('[上]ddddLT'), 'Today - ' + i + ' days end of day'); | |
31396 } | |
31397 }); | |
31398 | |
31399 test('calendar all else', function (assert) { | |
31400 var weeksAgo = moment().subtract({w: 1}), | |
31401 weeksFromNow = moment().add({w: 1}); | |
31402 | |
31403 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '1 week ago'); | |
31404 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 1 week'); | |
31405 | |
31406 weeksAgo = moment().subtract({w: 2}); | |
31407 weeksFromNow = moment().add({w: 2}); | |
31408 | |
31409 assert.equal(weeksAgo.calendar(), weeksAgo.format('L'), '2 weeks ago'); | |
31410 assert.equal(weeksFromNow.calendar(), weeksFromNow.format('L'), 'in 2 weeks'); | |
31411 }); | |
31412 | |
31413 test('meridiem', function (assert) { | |
31414 assert.equal(moment([2011, 2, 23, 0, 0]).format('a'), '早上', 'morning'); | |
31415 assert.equal(moment([2011, 2, 23, 9, 0]).format('a'), '上午', 'before noon'); | |
31416 assert.equal(moment([2011, 2, 23, 12, 0]).format('a'), '中午', 'noon'); | |
31417 assert.equal(moment([2011, 2, 23, 13, 0]).format('a'), '下午', 'after noon'); | |
31418 assert.equal(moment([2011, 2, 23, 18, 0]).format('a'), '晚上', 'night'); | |
31419 | |
31420 assert.equal(moment([2011, 2, 23, 0, 0]).format('A'), '早上', 'morning'); | |
31421 assert.equal(moment([2011, 2, 23, 9, 0]).format('A'), '上午', 'before noon'); | |
31422 assert.equal(moment([2011, 2, 23, 12, 0]).format('A'), '中午', 'noon'); | |
31423 assert.equal(moment([2011, 2, 23, 13, 0]).format('A'), '下午', 'afternoon'); | |
31424 assert.equal(moment([2011, 2, 23, 18, 0]).format('A'), '晚上', 'night'); | |
31425 }); | |
31426 | |
31427 test('weeks year starting sunday', function (assert) { | |
31428 assert.equal(moment([2012, 0, 1]).week(), 1, 'Jan 1 2012 should be week 1'); | |
31429 assert.equal(moment([2012, 0, 7]).week(), 1, 'Jan 7 2012 should be week 1'); | |
31430 assert.equal(moment([2012, 0, 8]).week(), 2, 'Jan 8 2012 should be week 2'); | |
31431 assert.equal(moment([2012, 0, 14]).week(), 2, 'Jan 14 2012 should be week 2'); | |
31432 assert.equal(moment([2012, 0, 15]).week(), 3, 'Jan 15 2012 should be week 3'); | |
31433 }); | |
31434 | |
31435 test('weeks year starting monday', function (assert) { | |
31436 assert.equal(moment([2006, 11, 31]).week(), 1, 'Dec 31 2006 should be week 1'); | |
31437 assert.equal(moment([2007, 0, 1]).week(), 1, 'Jan 1 2007 should be week 1'); | |
31438 assert.equal(moment([2007, 0, 6]).week(), 1, 'Jan 6 2007 should be week 1'); | |
31439 assert.equal(moment([2007, 0, 7]).week(), 2, 'Jan 7 2007 should be week 2'); | |
31440 assert.equal(moment([2007, 0, 13]).week(), 2, 'Jan 13 2007 should be week 2'); | |
31441 assert.equal(moment([2007, 0, 14]).week(), 3, 'Jan 14 2007 should be week 3'); | |
31442 }); | |
31443 | |
31444 test('weeks year starting tuesday', function (assert) { | |
31445 assert.equal(moment([2007, 11, 29]).week(), 52, 'Dec 29 2007 should be week 52'); | |
31446 assert.equal(moment([2008, 0, 1]).week(), 1, 'Jan 1 2008 should be week 1'); | |
31447 assert.equal(moment([2008, 0, 5]).week(), 1, 'Jan 5 2008 should be week 1'); | |
31448 assert.equal(moment([2008, 0, 6]).week(), 2, 'Jan 6 2008 should be week 2'); | |
31449 assert.equal(moment([2008, 0, 12]).week(), 2, 'Jan 12 2008 should be week 2'); | |
31450 assert.equal(moment([2008, 0, 13]).week(), 3, 'Jan 13 2008 should be week 3'); | |
31451 }); | |
31452 | |
31453 test('weeks year starting wednesday', function (assert) { | |
31454 assert.equal(moment([2002, 11, 29]).week(), 1, 'Dec 29 2002 should be week 1'); | |
31455 assert.equal(moment([2003, 0, 1]).week(), 1, 'Jan 1 2003 should be week 1'); | |
31456 assert.equal(moment([2003, 0, 4]).week(), 1, 'Jan 4 2003 should be week 1'); | |
31457 assert.equal(moment([2003, 0, 5]).week(), 2, 'Jan 5 2003 should be week 2'); | |
31458 assert.equal(moment([2003, 0, 11]).week(), 2, 'Jan 11 2003 should be week 2'); | |
31459 assert.equal(moment([2003, 0, 12]).week(), 3, 'Jan 12 2003 should be week 3'); | |
31460 }); | |
31461 | |
31462 test('weeks year starting thursday', function (assert) { | |
31463 assert.equal(moment([2008, 11, 28]).week(), 1, 'Dec 28 2008 should be week 1'); | |
31464 assert.equal(moment([2009, 0, 1]).week(), 1, 'Jan 1 2009 should be week 1'); | |
31465 assert.equal(moment([2009, 0, 3]).week(), 1, 'Jan 3 2009 should be week 1'); | |
31466 assert.equal(moment([2009, 0, 4]).week(), 2, 'Jan 4 2009 should be week 2'); | |
31467 assert.equal(moment([2009, 0, 10]).week(), 2, 'Jan 10 2009 should be week 2'); | |
31468 assert.equal(moment([2009, 0, 11]).week(), 3, 'Jan 11 2009 should be week 3'); | |
31469 }); | |
31470 | |
31471 test('weeks year starting friday', function (assert) { | |
31472 assert.equal(moment([2009, 11, 27]).week(), 1, 'Dec 27 2009 should be week 1'); | |
31473 assert.equal(moment([2010, 0, 1]).week(), 1, 'Jan 1 2010 should be week 1'); | |
31474 assert.equal(moment([2010, 0, 2]).week(), 1, 'Jan 2 2010 should be week 1'); | |
31475 assert.equal(moment([2010, 0, 3]).week(), 2, 'Jan 3 2010 should be week 2'); | |
31476 assert.equal(moment([2010, 0, 9]).week(), 2, 'Jan 9 2010 should be week 2'); | |
31477 assert.equal(moment([2010, 0, 10]).week(), 3, 'Jan 10 2010 should be week 3'); | |
31478 }); | |
31479 | |
31480 test('weeks year starting saturday', function (assert) { | |
31481 assert.equal(moment([2010, 11, 26]).week(), 1, 'Dec 26 2010 should be week 1'); | |
31482 assert.equal(moment([2011, 0, 1]).week(), 1, 'Jan 1 2011 should be week 1'); | |
31483 assert.equal(moment([2011, 0, 2]).week(), 2, 'Jan 2 2011 should be week 2'); | |
31484 assert.equal(moment([2011, 0, 8]).week(), 2, 'Jan 8 2011 should be week 2'); | |
31485 assert.equal(moment([2011, 0, 9]).week(), 3, 'Jan 9 2011 should be week 3'); | |
31486 }); | |
31487 | |
31488 test('weeks year starting sunday format', function (assert) { | |
31489 assert.equal(moment([2012, 0, 1]).format('w ww wo'), '1 01 1週', 'Jan 1 2012 應該是第 1週'); | |
31490 assert.equal(moment([2012, 0, 7]).format('w ww wo'), '1 01 1週', 'Jan 7 2012 應該是第 1週'); | |
31491 assert.equal(moment([2012, 0, 8]).format('w ww wo'), '2 02 2週', 'Jan 8 2012 應該是第 2週'); | |
31492 assert.equal(moment([2012, 0, 14]).format('w ww wo'), '2 02 2週', 'Jan 14 2012 應該是第 2週'); | |
31493 assert.equal(moment([2012, 0, 15]).format('w ww wo'), '3 03 3週', 'Jan 15 2012 應該是第 3週'); | |
31494 }); | |
31495 | |
31496 test('lenient ordinal parsing', function (assert) { | |
31497 var i, ordinalStr, testMoment; | |
31498 for (i = 1; i <= 31; ++i) { | |
31499 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
31500 testMoment = moment(ordinalStr, 'YYYY MM Do'); | |
31501 assert.equal(testMoment.year(), 2014, | |
31502 'lenient ordinal parsing ' + i + ' year check'); | |
31503 assert.equal(testMoment.month(), 0, | |
31504 'lenient ordinal parsing ' + i + ' month check'); | |
31505 assert.equal(testMoment.date(), i, | |
31506 'lenient ordinal parsing ' + i + ' date check'); | |
31507 } | |
31508 }); | |
31509 | |
31510 test('lenient ordinal parsing of number', function (assert) { | |
31511 var i, testMoment; | |
31512 for (i = 1; i <= 31; ++i) { | |
31513 testMoment = moment('2014 01 ' + i, 'YYYY MM Do'); | |
31514 assert.equal(testMoment.year(), 2014, | |
31515 'lenient ordinal parsing of number ' + i + ' year check'); | |
31516 assert.equal(testMoment.month(), 0, | |
31517 'lenient ordinal parsing of number ' + i + ' month check'); | |
31518 assert.equal(testMoment.date(), i, | |
31519 'lenient ordinal parsing of number ' + i + ' date check'); | |
31520 } | |
31521 }); | |
31522 | |
31523 test('meridiem invariant', function (assert) { | |
31524 var h, m, t1, t2; | |
31525 for (h = 0; h < 24; ++h) { | |
31526 for (m = 0; m < 60; m += 15) { | |
31527 t1 = moment.utc([2000, 0, 1, h, m]); | |
31528 t2 = moment(t1.format('A h:mm'), 'A h:mm'); | |
31529 assert.equal(t2.format('HH:mm'), t1.format('HH:mm'), | |
31530 'meridiem at ' + t1.format('HH:mm')); | |
31531 } | |
31532 } | |
31533 }); | |
31534 | |
31535 test('strict ordinal parsing', function (assert) { | |
31536 var i, ordinalStr, testMoment; | |
31537 for (i = 1; i <= 31; ++i) { | |
31538 ordinalStr = moment([2014, 0, i]).format('YYYY MM Do'); | |
31539 testMoment = moment(ordinalStr, 'YYYY MM Do', true); | |
31540 assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i); | |
31541 } | |
31542 }); | |
31543 | |
31544 })); | |
31545 | |
31546 (function (global, factory) { | |
31547 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
31548 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
31549 factory(global.moment) | |
31550 }(this, function (moment) { 'use strict'; | |
31551 | |
31552 /*global QUnit:false*/ | |
31553 | |
31554 var test = QUnit.test; | |
31555 | |
31556 function module (name, lifecycle) { | |
31557 QUnit.module(name, { | |
31558 setup : function () { | |
31559 moment.locale('en'); | |
31560 moment.createFromInputFallback = function () { | |
31561 throw new Error('input not handled by moment'); | |
31562 }; | |
31563 if (lifecycle && lifecycle.setup) { | |
31564 lifecycle.setup(); | |
31565 } | |
31566 }, | |
31567 teardown : function () { | |
31568 if (lifecycle && lifecycle.teardown) { | |
31569 lifecycle.teardown(); | |
31570 } | |
31571 } | |
31572 }); | |
31573 } | |
31574 | |
31575 function localeModule (name, lifecycle) { | |
31576 QUnit.module('locale:' + name, { | |
31577 setup : function () { | |
31578 moment.locale(name); | |
31579 moment.createFromInputFallback = function () { | |
31580 throw new Error('input not handled by moment'); | |
31581 }; | |
31582 if (lifecycle && lifecycle.setup) { | |
31583 lifecycle.setup(); | |
31584 } | |
31585 }, | |
31586 teardown : function () { | |
31587 moment.locale('en'); | |
31588 if (lifecycle && lifecycle.teardown) { | |
31589 lifecycle.teardown(); | |
31590 } | |
31591 } | |
31592 }); | |
31593 } | |
31594 | |
31595 module('add and subtract'); | |
31596 | |
31597 test('add short reverse args', function (assert) { | |
31598 var a = moment(), b, c, d; | |
31599 a.year(2011); | |
31600 a.month(9); | |
31601 a.date(12); | |
31602 a.hours(6); | |
31603 a.minutes(7); | |
31604 a.seconds(8); | |
31605 a.milliseconds(500); | |
31606 | |
31607 assert.equal(a.add({ms: 50}).milliseconds(), 550, 'Add milliseconds'); | |
31608 assert.equal(a.add({s: 1}).seconds(), 9, 'Add seconds'); | |
31609 assert.equal(a.add({m: 1}).minutes(), 8, 'Add minutes'); | |
31610 assert.equal(a.add({h: 1}).hours(), 7, 'Add hours'); | |
31611 assert.equal(a.add({d: 1}).date(), 13, 'Add date'); | |
31612 assert.equal(a.add({w: 1}).date(), 20, 'Add week'); | |
31613 assert.equal(a.add({M: 1}).month(), 10, 'Add month'); | |
31614 assert.equal(a.add({y: 1}).year(), 2012, 'Add year'); | |
31615 assert.equal(a.add({Q: 1}).month(), 1, 'Add quarter'); | |
31616 | |
31617 b = moment([2010, 0, 31]).add({M: 1}); | |
31618 c = moment([2010, 1, 28]).subtract({M: 1}); | |
31619 d = moment([2010, 1, 28]).subtract({Q: 1}); | |
31620 | |
31621 assert.equal(b.month(), 1, 'add month, jan 31st to feb 28th'); | |
31622 assert.equal(b.date(), 28, 'add month, jan 31st to feb 28th'); | |
31623 assert.equal(c.month(), 0, 'subtract month, feb 28th to jan 28th'); | |
31624 assert.equal(c.date(), 28, 'subtract month, feb 28th to jan 28th'); | |
31625 assert.equal(d.month(), 10, 'subtract quarter, feb 28th 2010 to nov 28th 2009'); | |
31626 assert.equal(d.date(), 28, 'subtract quarter, feb 28th 2010 to nov 28th 2009'); | |
31627 assert.equal(d.year(), 2009, 'subtract quarter, feb 28th 2010 to nov 28th 2009'); | |
31628 }); | |
31629 | |
31630 test('add long reverse args', function (assert) { | |
31631 var a = moment(); | |
31632 a.year(2011); | |
31633 a.month(9); | |
31634 a.date(12); | |
31635 a.hours(6); | |
31636 a.minutes(7); | |
31637 a.seconds(8); | |
31638 a.milliseconds(500); | |
31639 | |
31640 assert.equal(a.add({milliseconds: 50}).milliseconds(), 550, 'Add milliseconds'); | |
31641 assert.equal(a.add({seconds: 1}).seconds(), 9, 'Add seconds'); | |
31642 assert.equal(a.add({minutes: 1}).minutes(), 8, 'Add minutes'); | |
31643 assert.equal(a.add({hours: 1}).hours(), 7, 'Add hours'); | |
31644 assert.equal(a.add({days: 1}).date(), 13, 'Add date'); | |
31645 assert.equal(a.add({weeks: 1}).date(), 20, 'Add week'); | |
31646 assert.equal(a.add({months: 1}).month(), 10, 'Add month'); | |
31647 assert.equal(a.add({years: 1}).year(), 2012, 'Add year'); | |
31648 assert.equal(a.add({quarters: 1}).month(), 1, 'Add quarter'); | |
31649 }); | |
31650 | |
31651 test('add long singular reverse args', function (assert) { | |
31652 var a = moment(); | |
31653 a.year(2011); | |
31654 a.month(9); | |
31655 a.date(12); | |
31656 a.hours(6); | |
31657 a.minutes(7); | |
31658 a.seconds(8); | |
31659 a.milliseconds(500); | |
31660 | |
31661 assert.equal(a.add({millisecond: 50}).milliseconds(), 550, 'Add milliseconds'); | |
31662 assert.equal(a.add({second: 1}).seconds(), 9, 'Add seconds'); | |
31663 assert.equal(a.add({minute: 1}).minutes(), 8, 'Add minutes'); | |
31664 assert.equal(a.add({hour: 1}).hours(), 7, 'Add hours'); | |
31665 assert.equal(a.add({day: 1}).date(), 13, 'Add date'); | |
31666 assert.equal(a.add({week: 1}).date(), 20, 'Add week'); | |
31667 assert.equal(a.add({month: 1}).month(), 10, 'Add month'); | |
31668 assert.equal(a.add({year: 1}).year(), 2012, 'Add year'); | |
31669 assert.equal(a.add({quarter: 1}).month(), 1, 'Add quarter'); | |
31670 }); | |
31671 | |
31672 test('add string long reverse args', function (assert) { | |
31673 var a = moment(), b; | |
31674 a.year(2011); | |
31675 a.month(9); | |
31676 a.date(12); | |
31677 a.hours(6); | |
31678 a.minutes(7); | |
31679 a.seconds(8); | |
31680 a.milliseconds(500); | |
31681 | |
31682 b = a.clone(); | |
31683 | |
31684 assert.equal(a.add('millisecond', 50).milliseconds(), 550, 'Add milliseconds'); | |
31685 assert.equal(a.add('second', 1).seconds(), 9, 'Add seconds'); | |
31686 assert.equal(a.add('minute', 1).minutes(), 8, 'Add minutes'); | |
31687 assert.equal(a.add('hour', 1).hours(), 7, 'Add hours'); | |
31688 assert.equal(a.add('day', 1).date(), 13, 'Add date'); | |
31689 assert.equal(a.add('week', 1).date(), 20, 'Add week'); | |
31690 assert.equal(a.add('month', 1).month(), 10, 'Add month'); | |
31691 assert.equal(a.add('year', 1).year(), 2012, 'Add year'); | |
31692 assert.equal(b.add('day', '01').date(), 13, 'Add date'); | |
31693 assert.equal(a.add('quarter', 1).month(), 1, 'Add quarter'); | |
31694 }); | |
31695 | |
31696 test('add string long singular reverse args', function (assert) { | |
31697 var a = moment(), b; | |
31698 a.year(2011); | |
31699 a.month(9); | |
31700 a.date(12); | |
31701 a.hours(6); | |
31702 a.minutes(7); | |
31703 a.seconds(8); | |
31704 a.milliseconds(500); | |
31705 | |
31706 b = a.clone(); | |
31707 | |
31708 assert.equal(a.add('milliseconds', 50).milliseconds(), 550, 'Add milliseconds'); | |
31709 assert.equal(a.add('seconds', 1).seconds(), 9, 'Add seconds'); | |
31710 assert.equal(a.add('minutes', 1).minutes(), 8, 'Add minutes'); | |
31711 assert.equal(a.add('hours', 1).hours(), 7, 'Add hours'); | |
31712 assert.equal(a.add('days', 1).date(), 13, 'Add date'); | |
31713 assert.equal(a.add('weeks', 1).date(), 20, 'Add week'); | |
31714 assert.equal(a.add('months', 1).month(), 10, 'Add month'); | |
31715 assert.equal(a.add('years', 1).year(), 2012, 'Add year'); | |
31716 assert.equal(b.add('days', '01').date(), 13, 'Add date'); | |
31717 assert.equal(a.add('quarters', 1).month(), 1, 'Add quarter'); | |
31718 }); | |
31719 | |
31720 test('add string short reverse args', function (assert) { | |
31721 var a = moment(); | |
31722 a.year(2011); | |
31723 a.month(9); | |
31724 a.date(12); | |
31725 a.hours(6); | |
31726 a.minutes(7); | |
31727 a.seconds(8); | |
31728 a.milliseconds(500); | |
31729 | |
31730 assert.equal(a.add('ms', 50).milliseconds(), 550, 'Add milliseconds'); | |
31731 assert.equal(a.add('s', 1).seconds(), 9, 'Add seconds'); | |
31732 assert.equal(a.add('m', 1).minutes(), 8, 'Add minutes'); | |
31733 assert.equal(a.add('h', 1).hours(), 7, 'Add hours'); | |
31734 assert.equal(a.add('d', 1).date(), 13, 'Add date'); | |
31735 assert.equal(a.add('w', 1).date(), 20, 'Add week'); | |
31736 assert.equal(a.add('M', 1).month(), 10, 'Add month'); | |
31737 assert.equal(a.add('y', 1).year(), 2012, 'Add year'); | |
31738 assert.equal(a.add('Q', 1).month(), 1, 'Add quarter'); | |
31739 }); | |
31740 | |
31741 test('add string long', function (assert) { | |
31742 var a = moment(); | |
31743 a.year(2011); | |
31744 a.month(9); | |
31745 a.date(12); | |
31746 a.hours(6); | |
31747 a.minutes(7); | |
31748 a.seconds(8); | |
31749 a.milliseconds(500); | |
31750 | |
31751 assert.equal(a.add(50, 'millisecond').milliseconds(), 550, 'Add milliseconds'); | |
31752 assert.equal(a.add(1, 'second').seconds(), 9, 'Add seconds'); | |
31753 assert.equal(a.add(1, 'minute').minutes(), 8, 'Add minutes'); | |
31754 assert.equal(a.add(1, 'hour').hours(), 7, 'Add hours'); | |
31755 assert.equal(a.add(1, 'day').date(), 13, 'Add date'); | |
31756 assert.equal(a.add(1, 'week').date(), 20, 'Add week'); | |
31757 assert.equal(a.add(1, 'month').month(), 10, 'Add month'); | |
31758 assert.equal(a.add(1, 'year').year(), 2012, 'Add year'); | |
31759 assert.equal(a.add(1, 'quarter').month(), 1, 'Add quarter'); | |
31760 }); | |
31761 | |
31762 test('add string long singular', function (assert) { | |
31763 var a = moment(); | |
31764 a.year(2011); | |
31765 a.month(9); | |
31766 a.date(12); | |
31767 a.hours(6); | |
31768 a.minutes(7); | |
31769 a.seconds(8); | |
31770 a.milliseconds(500); | |
31771 | |
31772 assert.equal(a.add(50, 'milliseconds').milliseconds(), 550, 'Add milliseconds'); | |
31773 assert.equal(a.add(1, 'seconds').seconds(), 9, 'Add seconds'); | |
31774 assert.equal(a.add(1, 'minutes').minutes(), 8, 'Add minutes'); | |
31775 assert.equal(a.add(1, 'hours').hours(), 7, 'Add hours'); | |
31776 assert.equal(a.add(1, 'days').date(), 13, 'Add date'); | |
31777 assert.equal(a.add(1, 'weeks').date(), 20, 'Add week'); | |
31778 assert.equal(a.add(1, 'months').month(), 10, 'Add month'); | |
31779 assert.equal(a.add(1, 'years').year(), 2012, 'Add year'); | |
31780 assert.equal(a.add(1, 'quarters').month(), 1, 'Add quarter'); | |
31781 }); | |
31782 | |
31783 test('add string short', function (assert) { | |
31784 var a = moment(); | |
31785 a.year(2011); | |
31786 a.month(9); | |
31787 a.date(12); | |
31788 a.hours(6); | |
31789 a.minutes(7); | |
31790 a.seconds(8); | |
31791 a.milliseconds(500); | |
31792 | |
31793 assert.equal(a.add(50, 'ms').milliseconds(), 550, 'Add milliseconds'); | |
31794 assert.equal(a.add(1, 's').seconds(), 9, 'Add seconds'); | |
31795 assert.equal(a.add(1, 'm').minutes(), 8, 'Add minutes'); | |
31796 assert.equal(a.add(1, 'h').hours(), 7, 'Add hours'); | |
31797 assert.equal(a.add(1, 'd').date(), 13, 'Add date'); | |
31798 assert.equal(a.add(1, 'w').date(), 20, 'Add week'); | |
31799 assert.equal(a.add(1, 'M').month(), 10, 'Add month'); | |
31800 assert.equal(a.add(1, 'y').year(), 2012, 'Add year'); | |
31801 assert.equal(a.add(1, 'Q').month(), 1, 'Add quarter'); | |
31802 }); | |
31803 | |
31804 test('add strings string short args', function (assert) { | |
31805 var a = moment(); | |
31806 a.year(2011); | |
31807 a.month(9); | |
31808 a.date(12); | |
31809 a.hours(6); | |
31810 a.minutes(7); | |
31811 a.seconds(8); | |
31812 a.milliseconds(500); | |
31813 | |
31814 assert.equal(a.add('ms', '50').milliseconds(), 550, 'Add milliseconds'); | |
31815 assert.equal(a.add('s', '1').seconds(), 9, 'Add seconds'); | |
31816 assert.equal(a.add('m', '1').minutes(), 8, 'Add minutes'); | |
31817 assert.equal(a.add('h', '1').hours(), 7, 'Add hours'); | |
31818 assert.equal(a.add('d', '1').date(), 13, 'Add date'); | |
31819 assert.equal(a.add('w', '1').date(), 20, 'Add week'); | |
31820 assert.equal(a.add('M', '1').month(), 10, 'Add month'); | |
31821 assert.equal(a.add('y', '1').year(), 2012, 'Add year'); | |
31822 assert.equal(a.add('Q', '1').month(), 1, 'Add quarter'); | |
31823 }); | |
31824 | |
31825 test('subtract strings string short args', function (assert) { | |
31826 var a = moment(); | |
31827 a.year(2011); | |
31828 a.month(9); | |
31829 a.date(12); | |
31830 a.hours(6); | |
31831 a.minutes(7); | |
31832 a.seconds(8); | |
31833 a.milliseconds(500); | |
31834 | |
31835 assert.equal(a.subtract('ms', '50').milliseconds(), 450, 'Subtract milliseconds'); | |
31836 assert.equal(a.subtract('s', '1').seconds(), 7, 'Subtract seconds'); | |
31837 assert.equal(a.subtract('m', '1').minutes(), 6, 'Subtract minutes'); | |
31838 assert.equal(a.subtract('h', '1').hours(), 5, 'Subtract hours'); | |
31839 assert.equal(a.subtract('d', '1').date(), 11, 'Subtract date'); | |
31840 assert.equal(a.subtract('w', '1').date(), 4, 'Subtract week'); | |
31841 assert.equal(a.subtract('M', '1').month(), 8, 'Subtract month'); | |
31842 assert.equal(a.subtract('y', '1').year(), 2010, 'Subtract year'); | |
31843 assert.equal(a.subtract('Q', '1').month(), 5, 'Subtract quarter'); | |
31844 }); | |
31845 | |
31846 test('add strings string short', function (assert) { | |
31847 var a = moment(); | |
31848 a.year(2011); | |
31849 a.month(9); | |
31850 a.date(12); | |
31851 a.hours(6); | |
31852 a.minutes(7); | |
31853 a.seconds(8); | |
31854 a.milliseconds(500); | |
31855 | |
31856 assert.equal(a.add('50', 'ms').milliseconds(), 550, 'Add milliseconds'); | |
31857 assert.equal(a.add('1', 's').seconds(), 9, 'Add seconds'); | |
31858 assert.equal(a.add('1', 'm').minutes(), 8, 'Add minutes'); | |
31859 assert.equal(a.add('1', 'h').hours(), 7, 'Add hours'); | |
31860 assert.equal(a.add('1', 'd').date(), 13, 'Add date'); | |
31861 assert.equal(a.add('1', 'w').date(), 20, 'Add week'); | |
31862 assert.equal(a.add('1', 'M').month(), 10, 'Add month'); | |
31863 assert.equal(a.add('1', 'y').year(), 2012, 'Add year'); | |
31864 assert.equal(a.add('1', 'Q').month(), 1, 'Add quarter'); | |
31865 }); | |
31866 | |
31867 test('subtract strings string short', function (assert) { | |
31868 var a = moment(); | |
31869 a.year(2011); | |
31870 a.month(9); | |
31871 a.date(12); | |
31872 a.hours(6); | |
31873 a.minutes(7); | |
31874 a.seconds(8); | |
31875 a.milliseconds(500); | |
31876 | |
31877 assert.equal(a.subtract('50', 'ms').milliseconds(), 450, 'Subtract milliseconds'); | |
31878 assert.equal(a.subtract('1', 's').seconds(), 7, 'Subtract seconds'); | |
31879 assert.equal(a.subtract('1', 'm').minutes(), 6, 'Subtract minutes'); | |
31880 assert.equal(a.subtract('1', 'h').hours(), 5, 'Subtract hours'); | |
31881 assert.equal(a.subtract('1', 'd').date(), 11, 'Subtract date'); | |
31882 assert.equal(a.subtract('1', 'w').date(), 4, 'Subtract week'); | |
31883 assert.equal(a.subtract('1', 'M').month(), 8, 'Subtract month'); | |
31884 assert.equal(a.subtract('1', 'y').year(), 2010, 'Subtract year'); | |
31885 assert.equal(a.subtract('1', 'Q').month(), 5, 'Subtract quarter'); | |
31886 }); | |
31887 | |
31888 test('add across DST', function (assert) { | |
31889 // Detect Safari bug and bail. Hours on 13th March 2011 are shifted | |
31890 // with 1 ahead. | |
31891 if (new Date(2011, 2, 13, 5, 0, 0).getHours() !== 5) { | |
31892 assert.expect(0); | |
31893 return; | |
31894 } | |
31895 | |
31896 var a = moment(new Date(2011, 2, 12, 5, 0, 0)), | |
31897 b = moment(new Date(2011, 2, 12, 5, 0, 0)), | |
31898 c = moment(new Date(2011, 2, 12, 5, 0, 0)), | |
31899 d = moment(new Date(2011, 2, 12, 5, 0, 0)), | |
31900 e = moment(new Date(2011, 2, 12, 5, 0, 0)); | |
31901 a.add(1, 'days'); | |
31902 b.add(24, 'hours'); | |
31903 c.add(1, 'months'); | |
31904 e.add(1, 'quarter'); | |
31905 | |
31906 assert.equal(a.hours(), 5, 'adding days over DST difference should result in the same hour'); | |
31907 if (b.isDST() && !d.isDST()) { | |
31908 assert.equal(b.hours(), 6, 'adding hours over DST difference should result in a different hour'); | |
31909 } else if (!b.isDST() && d.isDST()) { | |
31910 assert.equal(b.hours(), 4, 'adding hours over DST difference should result in a different hour'); | |
31911 } else { | |
31912 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'); | |
31913 } | |
31914 assert.equal(c.hours(), 5, 'adding months over DST difference should result in the same hour'); | |
31915 assert.equal(e.hours(), 5, 'adding quarters over DST difference should result in the same hour'); | |
31916 }); | |
31917 | |
31918 })); | |
31919 | |
31920 (function (global, factory) { | |
31921 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
31922 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
31923 factory(global.moment) | |
31924 }(this, function (moment) { 'use strict'; | |
31925 | |
31926 /*global QUnit:false*/ | |
31927 | |
31928 var test = QUnit.test; | |
31929 | |
31930 function module (name, lifecycle) { | |
31931 QUnit.module(name, { | |
31932 setup : function () { | |
31933 moment.locale('en'); | |
31934 moment.createFromInputFallback = function () { | |
31935 throw new Error('input not handled by moment'); | |
31936 }; | |
31937 if (lifecycle && lifecycle.setup) { | |
31938 lifecycle.setup(); | |
31939 } | |
31940 }, | |
31941 teardown : function () { | |
31942 if (lifecycle && lifecycle.teardown) { | |
31943 lifecycle.teardown(); | |
31944 } | |
31945 } | |
31946 }); | |
31947 } | |
31948 | |
31949 function localeModule (name, lifecycle) { | |
31950 QUnit.module('locale:' + name, { | |
31951 setup : function () { | |
31952 moment.locale(name); | |
31953 moment.createFromInputFallback = function () { | |
31954 throw new Error('input not handled by moment'); | |
31955 }; | |
31956 if (lifecycle && lifecycle.setup) { | |
31957 lifecycle.setup(); | |
31958 } | |
31959 }, | |
31960 teardown : function () { | |
31961 moment.locale('en'); | |
31962 if (lifecycle && lifecycle.teardown) { | |
31963 lifecycle.teardown(); | |
31964 } | |
31965 } | |
31966 }); | |
31967 } | |
31968 | |
31969 module('create'); | |
31970 | |
31971 test('array', function (assert) { | |
31972 assert.ok(moment([2010]).toDate() instanceof Date, '[2010]'); | |
31973 assert.ok(moment([2010, 1]).toDate() instanceof Date, '[2010, 1]'); | |
31974 assert.ok(moment([2010, 1, 12]).toDate() instanceof Date, '[2010, 1, 12]'); | |
31975 assert.ok(moment([2010, 1, 12, 1]).toDate() instanceof Date, '[2010, 1, 12, 1]'); | |
31976 assert.ok(moment([2010, 1, 12, 1, 1]).toDate() instanceof Date, '[2010, 1, 12, 1, 1]'); | |
31977 assert.ok(moment([2010, 1, 12, 1, 1, 1]).toDate() instanceof Date, '[2010, 1, 12, 1, 1, 1]'); | |
31978 assert.ok(moment([2010, 1, 12, 1, 1, 1, 1]).toDate() instanceof Date, '[2010, 1, 12, 1, 1, 1, 1]'); | |
31979 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()'); | |
31980 }); | |
31981 | |
31982 test('array copying', function (assert) { | |
31983 var importantArray = [2009, 11]; | |
31984 moment(importantArray); | |
31985 assert.deepEqual(importantArray, [2009, 11], 'initializer should not mutate the original array'); | |
31986 }); | |
31987 | |
31988 test('object', function (assert) { | |
31989 var fmt = 'YYYY-MM-DD HH:mm:ss.SSS', | |
31990 tests = [ | |
31991 [{year: 2010}, '2010-01-01 00:00:00.000'], | |
31992 [{year: 2010, month: 1}, '2010-02-01 00:00:00.000'], | |
31993 [{year: 2010, month: 1, day: 12}, '2010-02-12 00:00:00.000'], | |
31994 [{year: 2010, month: 1, date: 12}, '2010-02-12 00:00:00.000'], | |
31995 [{year: 2010, month: 1, day: 12, hours: 1}, '2010-02-12 01:00:00.000'], | |
31996 [{year: 2010, month: 1, date: 12, hours: 1}, '2010-02-12 01:00:00.000'], | |
31997 [{year: 2010, month: 1, day: 12, hours: 1, minutes: 1}, '2010-02-12 01:01:00.000'], | |
31998 [{year: 2010, month: 1, date: 12, hours: 1, minutes: 1}, '2010-02-12 01:01:00.000'], | |
31999 [{year: 2010, month: 1, day: 12, hours: 1, minutes: 1, seconds: 1}, '2010-02-12 01:01:01.000'], | |
32000 [{year: 2010, month: 1, day: 12, hours: 1, minutes: 1, seconds: 1, milliseconds: 1}, '2010-02-12 01:01:01.001'], | |
32001 [{years: 2010, months: 1, days: 14, hours: 15, minutes: 25, seconds: 50, milliseconds: 125}, '2010-02-14 15:25:50.125'], | |
32002 [{year: 2010, month: 1, day: 14, hour: 15, minute: 25, second: 50, millisecond: 125}, '2010-02-14 15:25:50.125'], | |
32003 [{y: 2010, M: 1, d: 14, h: 15, m: 25, s: 50, ms: 125}, '2010-02-14 15:25:50.125'] | |
32004 ], i; | |
32005 for (i = 0; i < tests.length; ++i) { | |
32006 assert.equal(moment(tests[i][0]).format(fmt), tests[i][1]); | |
32007 } | |
32008 }); | |
32009 | |
32010 test('multi format array copying', function (assert) { | |
32011 var importantArray = ['MM/DD/YYYY', 'YYYY-MM-DD', 'MM-DD-YYYY']; | |
32012 moment('1999-02-13', importantArray); | |
32013 assert.deepEqual(importantArray, ['MM/DD/YYYY', 'YYYY-MM-DD', 'MM-DD-YYYY'], 'initializer should not mutate the original array'); | |
32014 }); | |
32015 | |
32016 test('number', function (assert) { | |
32017 assert.ok(moment(1000).toDate() instanceof Date, '1000'); | |
32018 assert.equal(moment(1000).valueOf(), 1000, 'asserting valueOf'); | |
32019 assert.equal(moment.utc(1000).valueOf(), 1000, 'asserting valueOf'); | |
32020 }); | |
32021 | |
32022 test('unix', function (assert) { | |
32023 assert.equal(moment.unix(1).valueOf(), 1000, '1 unix timestamp == 1000 Date.valueOf'); | |
32024 assert.equal(moment(1000).unix(), 1, '1000 Date.valueOf == 1 unix timestamp'); | |
32025 assert.equal(moment.unix(1000).valueOf(), 1000000, '1000 unix timestamp == 1000000 Date.valueOf'); | |
32026 assert.equal(moment(1500).unix(), 1, '1500 Date.valueOf == 1 unix timestamp'); | |
32027 assert.equal(moment(1900).unix(), 1, '1900 Date.valueOf == 1 unix timestamp'); | |
32028 assert.equal(moment(2100).unix(), 2, '2100 Date.valueOf == 2 unix timestamp'); | |
32029 assert.equal(moment(1333129333524).unix(), 1333129333, '1333129333524 Date.valueOf == 1333129333 unix timestamp'); | |
32030 assert.equal(moment(1333129333524000).unix(), 1333129333524, '1333129333524000 Date.valueOf == 1333129333524 unix timestamp'); | |
32031 }); | |
32032 | |
32033 test('date', function (assert) { | |
32034 assert.ok(moment(new Date()).toDate() instanceof Date, 'new Date()'); | |
32035 }); | |
32036 | |
32037 test('date mutation', function (assert) { | |
32038 var a = new Date(); | |
32039 assert.ok(moment(a).toDate() !== a, 'the date moment uses should not be the date passed in'); | |
32040 }); | |
32041 | |
32042 test('moment', function (assert) { | |
32043 assert.ok(moment(moment()).toDate() instanceof Date, 'moment(moment())'); | |
32044 assert.ok(moment(moment(moment())).toDate() instanceof Date, 'moment(moment(moment()))'); | |
32045 }); | |
32046 | |
32047 test('cloning moment should only copy own properties', function (assert) { | |
32048 assert.ok(!moment().clone().hasOwnProperty('month'), 'Should not clone prototype methods'); | |
32049 }); | |
32050 | |
32051 test('cloning moment works with weird clones', function (assert) { | |
32052 var extend = function (a, b) { | |
32053 var i; | |
32054 for (i in b) { | |
32055 a[i] = b[i]; | |
32056 } | |
32057 return a; | |
32058 }, | |
32059 now = moment(), | |
32060 nowu = moment.utc(); | |
32061 | |
32062 assert.equal(+extend({}, now).clone(), +now, 'cloning extend-ed now is now'); | |
32063 assert.equal(+extend({}, nowu).clone(), +nowu, 'cloning extend-ed utc now is utc now'); | |
32064 }); | |
32065 | |
32066 test('cloning respects moment.momentProperties', function (assert) { | |
32067 var m = moment(); | |
32068 | |
32069 assert.equal(m.clone()._special, undefined, 'cloning ignores extra properties'); | |
32070 m._special = 'bacon'; | |
32071 moment.momentProperties.push('_special'); | |
32072 assert.equal(m.clone()._special, 'bacon', 'cloning respects momentProperties'); | |
32073 moment.momentProperties.pop(); | |
32074 }); | |
32075 | |
32076 test('undefined', function (assert) { | |
32077 assert.ok(moment().toDate() instanceof Date, 'undefined'); | |
32078 }); | |
32079 | |
32080 test('iso with bad input', function (assert) { | |
32081 assert.ok(!moment('a', moment.ISO_8601).isValid(), 'iso parsing with invalid string'); | |
32082 assert.ok(!moment('a', moment.ISO_8601, true).isValid(), 'iso parsing with invalid string, strict'); | |
32083 }); | |
32084 | |
32085 test('iso format 24hrs', function (assert) { | |
32086 assert.equal(moment('2014-01-01T24:00:00.000').format('YYYY-MM-DD[T]HH:mm:ss.SSS'), | |
32087 '2014-01-02T00:00:00.000', 'iso format with 24:00 localtime'); | |
32088 assert.equal(moment.utc('2014-01-01T24:00:00.000').format('YYYY-MM-DD[T]HH:mm:ss.SSS'), | |
32089 '2014-01-02T00:00:00.000', 'iso format with 24:00 utc'); | |
32090 }); | |
32091 | |
32092 test('string without format - json', function (assert) { | |
32093 assert.equal(moment('Date(1325132654000)').valueOf(), 1325132654000, 'Date(1325132654000)'); | |
32094 assert.equal(moment('Date(-1325132654000)').valueOf(), -1325132654000, 'Date(-1325132654000)'); | |
32095 assert.equal(moment('/Date(1325132654000)/').valueOf(), 1325132654000, '/Date(1325132654000)/'); | |
32096 assert.equal(moment('/Date(1325132654000+0700)/').valueOf(), 1325132654000, '/Date(1325132654000+0700)/'); | |
32097 assert.equal(moment('/Date(1325132654000-0700)/').valueOf(), 1325132654000, '/Date(1325132654000-0700)/'); | |
32098 }); | |
32099 | |
32100 test('string with format dropped am/pm bug', function (assert) { | |
32101 moment.locale('en'); | |
32102 | |
32103 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'); | |
32104 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'); | |
32105 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'); | |
32106 | |
32107 assert.ok(moment('05/1/2012 12:25:00', 'MM/DD/YYYY h:m:s a').isValid()); | |
32108 assert.ok(moment('05/1/2012 12:25:00 am', 'MM/DD/YYYY h:m:s a').isValid()); | |
32109 assert.ok(moment('05/1/2012 12:25:00 pm', 'MM/DD/YYYY h:m:s a').isValid()); | |
32110 }); | |
32111 | |
32112 test('empty string with formats', function (assert) { | |
32113 assert.equal(moment('', 'MM').format('YYYY-MM-DD HH:mm:ss'), 'Invalid date'); | |
32114 assert.equal(moment(' ', 'MM').format('YYYY-MM-DD HH:mm:ss'), 'Invalid date'); | |
32115 assert.equal(moment(' ', 'DD').format('YYYY-MM-DD HH:mm:ss'), 'Invalid date'); | |
32116 assert.equal(moment(' ', ['MM', 'DD']).format('YYYY-MM-DD HH:mm:ss'), 'Invalid date'); | |
32117 | |
32118 assert.ok(!moment('', 'MM').isValid()); | |
32119 assert.ok(!moment(' ', 'MM').isValid()); | |
32120 assert.ok(!moment(' ', 'DD').isValid()); | |
32121 assert.ok(!moment(' ', ['MM', 'DD']).isValid()); | |
32122 }); | |
32123 | |
32124 test('defaulting to current date', function (assert) { | |
32125 var now = moment(); | |
32126 assert.equal(moment('12:13:14', 'hh:mm:ss').format('YYYY-MM-DD hh:mm:ss'), | |
32127 now.clone().hour(12).minute(13).second(14).format('YYYY-MM-DD hh:mm:ss'), | |
32128 'given only time default to current date'); | |
32129 assert.equal(moment('05', 'DD').format('YYYY-MM-DD'), | |
32130 now.clone().date(5).format('YYYY-MM-DD'), | |
32131 'given day of month default to current month, year'); | |
32132 assert.equal(moment('05', 'MM').format('YYYY-MM-DD'), | |
32133 now.clone().month(4).date(1).format('YYYY-MM-DD'), | |
32134 'given month default to current year'); | |
32135 assert.equal(moment('1996', 'YYYY').format('YYYY-MM-DD'), | |
32136 now.clone().year(1996).month(0).date(1).format('YYYY-MM-DD'), | |
32137 'given year do not default'); | |
32138 }); | |
32139 | |
32140 test('matching am/pm', function (assert) { | |
32141 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'); | |
32142 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.'); | |
32143 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'); | |
32144 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'); | |
32145 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.'); | |
32146 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'); | |
32147 | |
32148 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'); | |
32149 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.'); | |
32150 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'); | |
32151 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'); | |
32152 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.'); | |
32153 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'); | |
32154 | |
32155 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'); | |
32156 }); | |
32157 | |
32158 test('string with format', function (assert) { | |
32159 moment.locale('en'); | |
32160 var a = [ | |
32161 ['YYYY-Q', '2014-4'], | |
32162 ['MM-DD-YYYY', '12-02-1999'], | |
32163 ['DD-MM-YYYY', '12-02-1999'], | |
32164 ['DD/MM/YYYY', '12/02/1999'], | |
32165 ['DD_MM_YYYY', '12_02_1999'], | |
32166 ['DD:MM:YYYY', '12:02:1999'], | |
32167 ['D-M-YY', '2-2-99'], | |
32168 ['YY', '99'], | |
32169 ['DDD-YYYY', '300-1999'], | |
32170 ['DD-MM-YYYY h:m:s', '12-02-1999 2:45:10'], | |
32171 ['DD-MM-YYYY h:m:s a', '12-02-1999 2:45:10 am'], | |
32172 ['DD-MM-YYYY h:m:s a', '12-02-1999 2:45:10 pm'], | |
32173 ['h:mm a', '12:00 pm'], | |
32174 ['h:mm a', '12:30 pm'], | |
32175 ['h:mm a', '12:00 am'], | |
32176 ['h:mm a', '12:30 am'], | |
32177 ['HH:mm', '12:00'], | |
32178 ['YYYY-MM-DDTHH:mm:ss', '2011-11-11T11:11:11'], | |
32179 ['MM-DD-YYYY [M]', '12-02-1999 M'], | |
32180 ['ddd MMM DD HH:mm:ss YYYY', 'Tue Apr 07 22:52:51 2009'], | |
32181 ['HH:mm:ss', '12:00:00'], | |
32182 ['HH:mm:ss', '12:30:00'], | |
32183 ['HH:mm:ss', '00:00:00'], | |
32184 ['HH:mm:ss S', '00:30:00 1'], | |
32185 ['HH:mm:ss SS', '00:30:00 12'], | |
32186 ['HH:mm:ss SSS', '00:30:00 123'], | |
32187 ['HH:mm:ss S', '00:30:00 7'], | |
32188 ['HH:mm:ss SS', '00:30:00 78'], | |
32189 ['HH:mm:ss SSS', '00:30:00 789'], | |
32190 ['X', '1234567890'], | |
32191 ['x', '1234567890123'], | |
32192 ['LT', '12:30 AM'], | |
32193 ['LTS', '12:30:29 AM'], | |
32194 ['L', '09/02/1999'], | |
32195 ['l', '9/2/1999'], | |
32196 ['LL', 'September 2, 1999'], | |
32197 ['ll', 'Sep 2, 1999'], | |
32198 ['LLL', 'September 2, 1999 12:30 AM'], | |
32199 ['lll', 'Sep 2, 1999 12:30 AM'], | |
32200 ['LLLL', 'Thursday, September 2, 1999 12:30 AM'], | |
32201 ['llll', 'Thu, Sep 2, 1999 12:30 AM'] | |
32202 ], | |
32203 m, | |
32204 i; | |
32205 | |
32206 for (i = 0; i < a.length; i++) { | |
32207 m = moment(a[i][1], a[i][0]); | |
32208 assert.ok(m.isValid()); | |
32209 assert.equal(m.format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
32210 } | |
32211 }); | |
32212 | |
32213 test('2 digit year with YYYY format', function (assert) { | |
32214 assert.equal(moment('9/2/99', 'D/M/YYYY').format('DD/MM/YYYY'), '09/02/1999', 'D/M/YYYY ---> 9/2/99'); | |
32215 assert.equal(moment('9/2/1999', 'D/M/YYYY').format('DD/MM/YYYY'), '09/02/1999', 'D/M/YYYY ---> 9/2/1999'); | |
32216 assert.equal(moment('9/2/68', 'D/M/YYYY').format('DD/MM/YYYY'), '09/02/2068', 'D/M/YYYY ---> 9/2/68'); | |
32217 assert.equal(moment('9/2/69', 'D/M/YYYY').format('DD/MM/YYYY'), '09/02/1969', 'D/M/YYYY ---> 9/2/69'); | |
32218 }); | |
32219 | |
32220 test('unix timestamp format', function (assert) { | |
32221 var formats = ['X', 'X.S', 'X.SS', 'X.SSS'], i, format; | |
32222 | |
32223 for (i = 0; i < formats.length; i++) { | |
32224 format = formats[i]; | |
32225 assert.equal(moment('1234567890', format).valueOf(), 1234567890 * 1000, format + ' matches timestamp without milliseconds'); | |
32226 assert.equal(moment('1234567890.1', format).valueOf(), 1234567890 * 1000 + 100, format + ' matches timestamp with deciseconds'); | |
32227 assert.equal(moment('1234567890.12', format).valueOf(), 1234567890 * 1000 + 120, format + ' matches timestamp with centiseconds'); | |
32228 assert.equal(moment('1234567890.123', format).valueOf(), 1234567890 * 1000 + 123, format + ' matches timestamp with milliseconds'); | |
32229 } | |
32230 }); | |
32231 | |
32232 test('unix offset milliseconds', function (assert) { | |
32233 assert.equal(moment('1234567890123', 'x').valueOf(), 1234567890123, 'x matches unix offset in milliseconds'); | |
32234 }); | |
32235 | |
32236 test('milliseconds format', function (assert) { | |
32237 assert.equal(moment('1', 'S').get('ms'), 100, 'deciseconds'); | |
32238 // assert.equal(moment('10', 'S', true).isValid(), false, 'deciseconds with two digits'); | |
32239 // assert.equal(moment('1', 'SS', true).isValid(), false, 'centiseconds with one digits'); | |
32240 assert.equal(moment('12', 'SS').get('ms'), 120, 'centiseconds'); | |
32241 // assert.equal(moment('123', 'SS', true).isValid(), false, 'centiseconds with three digits'); | |
32242 assert.equal(moment('123', 'SSS').get('ms'), 123, 'milliseconds'); | |
32243 assert.equal(moment('1234', 'SSSS').get('ms'), 123, 'milliseconds with SSSS'); | |
32244 assert.equal(moment('123456789101112', 'SSSS').get('ms'), 123, 'milliseconds with SSSS'); | |
32245 }); | |
32246 | |
32247 test('string with format no separators', function (assert) { | |
32248 moment.locale('en'); | |
32249 var a = [ | |
32250 ['MMDDYYYY', '12021999'], | |
32251 ['DDMMYYYY', '12021999'], | |
32252 ['YYYYMMDD', '19991202'], | |
32253 ['DDMMMYYYY', '10Sep2001'] | |
32254 ], i; | |
32255 | |
32256 for (i = 0; i < a.length; i++) { | |
32257 assert.equal(moment(a[i][1], a[i][0]).format(a[i][0]), a[i][1], a[i][0] + ' ---> ' + a[i][1]); | |
32258 } | |
32259 }); | |
32260 | |
32261 test('string with format (timezone)', function (assert) { | |
32262 assert.equal(moment('5 -0700', 'H ZZ').toDate().getUTCHours(), 12, 'parse hours \'5 -0700\' ---> \'H ZZ\''); | |
32263 assert.equal(moment('5 -07:00', 'H Z').toDate().getUTCHours(), 12, 'parse hours \'5 -07:00\' ---> \'H Z\''); | |
32264 assert.equal(moment('5 -0730', 'H ZZ').toDate().getUTCMinutes(), 30, 'parse hours \'5 -0730\' ---> \'H ZZ\''); | |
32265 assert.equal(moment('5 -07:30', 'H Z').toDate().getUTCMinutes(), 30, 'parse hours \'5 -07:0\' ---> \'H Z\''); | |
32266 assert.equal(moment('5 +0100', 'H ZZ').toDate().getUTCHours(), 4, 'parse hours \'5 +0100\' ---> \'H ZZ\''); | |
32267 assert.equal(moment('5 +01:00', 'H Z').toDate().getUTCHours(), 4, 'parse hours \'5 +01:00\' ---> \'H Z\''); | |
32268 assert.equal(moment('5 +0130', 'H ZZ').toDate().getUTCMinutes(), 30, 'parse hours \'5 +0130\' ---> \'H ZZ\''); | |
32269 assert.equal(moment('5 +01:30', 'H Z').toDate().getUTCMinutes(), 30, 'parse hours \'5 +01:30\' ---> \'H Z\''); | |
32270 }); | |
32271 | |
32272 test('string with format (timezone offset)', function (assert) { | |
32273 var a, b, c, d, e, f; | |
32274 a = new Date(Date.UTC(2011, 0, 1, 1)); | |
32275 b = moment('2011 1 1 0 -01:00', 'YYYY MM DD HH Z'); | |
32276 assert.equal(a.getHours(), b.hours(), 'date created with utc == parsed string with timezone offset'); | |
32277 assert.equal(+a, +b, 'date created with utc == parsed string with timezone offset'); | |
32278 c = moment('2011 2 1 10 -05:00', 'YYYY MM DD HH Z'); | |
32279 d = moment('2011 2 1 8 -07:00', 'YYYY MM DD HH Z'); | |
32280 assert.equal(c.hours(), d.hours(), '10 am central time == 8 am pacific time'); | |
32281 e = moment.utc('Fri, 20 Jul 2012 17:15:00', 'ddd, DD MMM YYYY HH:mm:ss'); | |
32282 f = moment.utc('Fri, 20 Jul 2012 10:15:00 -0700', 'ddd, DD MMM YYYY HH:mm:ss ZZ'); | |
32283 assert.equal(e.hours(), f.hours(), 'parse timezone offset in utc'); | |
32284 }); | |
32285 | |
32286 test('string with timezone around start of year', function (assert) { | |
32287 assert.equal(moment('2000-01-01T00:00:00.000+01:00').toISOString(), '1999-12-31T23:00:00.000Z', '+1:00 around 2000'); | |
32288 assert.equal(moment('2000-01-01T00:00:00.000-01:00').toISOString(), '2000-01-01T01:00:00.000Z', '-1:00 around 2000'); | |
32289 assert.equal(moment('1970-01-01T00:00:00.000+01:00').toISOString(), '1969-12-31T23:00:00.000Z', '+1:00 around 1970'); | |
32290 assert.equal(moment('1970-01-01T00:00:00.000-01:00').toISOString(), '1970-01-01T01:00:00.000Z', '-1:00 around 1970'); | |
32291 assert.equal(moment('1200-01-01T00:00:00.000+01:00').toISOString(), '1199-12-31T23:00:00.000Z', '+1:00 around 1200'); | |
32292 assert.equal(moment('1200-01-01T00:00:00.000-01:00').toISOString(), '1200-01-01T01:00:00.000Z', '-1:00 around 1200'); | |
32293 }); | |
32294 | |
32295 test('string with array of formats', function (assert) { | |
32296 assert.equal(moment('11-02-1999', ['MM-DD-YYYY', 'DD-MM-YYYY']).format('MM DD YYYY'), '11 02 1999', 'switching month and day'); | |
32297 assert.equal(moment('02-11-1999', ['MM/DD/YYYY', 'YYYY MM DD', 'MM-DD-YYYY']).format('MM DD YYYY'), '02 11 1999', 'year last'); | |
32298 assert.equal(moment('1999-02-11', ['MM/DD/YYYY', 'YYYY MM DD', 'MM-DD-YYYY']).format('MM DD YYYY'), '02 11 1999', 'year first'); | |
32299 | |
32300 assert.equal(moment('02-11-1999', ['MM/DD/YYYY', 'YYYY MM DD']).format('MM DD YYYY'), '02 11 1999', 'year last'); | |
32301 assert.equal(moment('1999-02-11', ['MM/DD/YYYY', 'YYYY MM DD']).format('MM DD YYYY'), '02 11 1999', 'year first'); | |
32302 assert.equal(moment('02-11-1999', ['YYYY MM DD', 'MM/DD/YYYY']).format('MM DD YYYY'), '02 11 1999', 'year last'); | |
32303 assert.equal(moment('1999-02-11', ['YYYY MM DD', 'MM/DD/YYYY']).format('MM DD YYYY'), '02 11 1999', 'year first'); | |
32304 | |
32305 assert.equal(moment('13-11-1999', ['MM/DD/YYYY', 'DD/MM/YYYY']).format('MM DD YYYY'), '11 13 1999', 'second must be month'); | |
32306 assert.equal(moment('11-13-1999', ['MM/DD/YYYY', 'DD/MM/YYYY']).format('MM DD YYYY'), '11 13 1999', 'first must be month'); | |
32307 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'); | |
32308 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'); | |
32309 | |
32310 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'); | |
32311 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'); | |
32312 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'); | |
32313 assert.equal(moment('11-22-10', ['YY-MM-DD', 'YY-DD-MM']).format('MM DD YYYY'), '10 22 2011', 'prefer valid results'); | |
32314 | |
32315 assert.equal(moment('gibberish', ['YY-MM-DD', 'YY-DD-MM']).format('MM DD YYYY'), 'Invalid date', 'doest throw for invalid strings'); | |
32316 assert.equal(moment('gibberish', []).format('MM DD YYYY'), 'Invalid date', 'doest throw for an empty array'); | |
32317 | |
32318 //https://github.com/moment/moment/issues/1143 | |
32319 assert.equal(moment( | |
32320 '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)', | |
32321 ['MM/DD/YYYY', 'MM-DD-YYYY', 'YYYY-MM-DD', 'YYYY-MM-DDTHH:mm:ssZ']) | |
32322 .format('YYYY-MM-DD'), '2011-07-01', 'Works for long strings'); | |
32323 | |
32324 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'); | |
32325 | |
32326 assert.equal(moment('13-10-98', ['DD MM YY', 'DD MM YYYY'])._f, 'DD MM YY', 'use two digit year'); | |
32327 assert.equal(moment('13-10-1998', ['DD MM YY', 'DD MM YYYY'])._f, 'DD MM YYYY', 'use four digit year'); | |
32328 | |
32329 assert.equal(moment('01', ['MM', 'DD'])._f, 'MM', 'Should use first valid format'); | |
32330 }); | |
32331 | |
32332 test('string with array of formats + ISO', function (assert) { | |
32333 assert.equal(moment('1994', [moment.ISO_8601, 'MM', 'HH:mm', 'YYYY']).year(), 1994, 'iso: assert parse YYYY'); | |
32334 assert.equal(moment('17:15', [moment.ISO_8601, 'MM', 'HH:mm', 'YYYY']).hour(), 17, 'iso: assert parse HH:mm (1)'); | |
32335 assert.equal(moment('17:15', [moment.ISO_8601, 'MM', 'HH:mm', 'YYYY']).minutes(), 15, 'iso: assert parse HH:mm (2)'); | |
32336 assert.equal(moment('06', [moment.ISO_8601, 'MM', 'HH:mm', 'YYYY']).month(), 6 - 1, 'iso: assert parse MM'); | |
32337 assert.equal(moment('2012-06-01', [moment.ISO_8601, 'MM', 'HH:mm', 'YYYY']).parsingFlags().iso, true, 'iso: assert parse iso'); | |
32338 assert.equal(moment('2014-05-05', [moment.ISO_8601, 'YYYY-MM-DD']).parsingFlags().iso, true, 'iso: edge case array precedence iso'); | |
32339 assert.equal(moment('2014-05-05', ['YYYY-MM-DD', moment.ISO_8601]).parsingFlags().iso, false, 'iso: edge case array precedence not iso'); | |
32340 }); | |
32341 | |
32342 test('string with format - years', function (assert) { | |
32343 assert.equal(moment('67', 'YY').format('YYYY'), '2067', '67 > 2067'); | |
32344 assert.equal(moment('68', 'YY').format('YYYY'), '2068', '68 > 2068'); | |
32345 assert.equal(moment('69', 'YY').format('YYYY'), '1969', '69 > 1969'); | |
32346 assert.equal(moment('70', 'YY').format('YYYY'), '1970', '70 > 1970'); | |
32347 }); | |
32348 | |
32349 test('implicit cloning', function (assert) { | |
32350 var momentA = moment([2011, 10, 10]), | |
32351 momentB = moment(momentA); | |
32352 momentA.month(5); | |
32353 assert.equal(momentB.month(), 10, 'Calling moment() on a moment will create a clone'); | |
32354 assert.equal(momentA.month(), 5, 'Calling moment() on a moment will create a clone'); | |
32355 }); | |
32356 | |
32357 test('explicit cloning', function (assert) { | |
32358 var momentA = moment([2011, 10, 10]), | |
32359 momentB = momentA.clone(); | |
32360 momentA.month(5); | |
32361 assert.equal(momentB.month(), 10, 'Calling moment() on a moment will create a clone'); | |
32362 assert.equal(momentA.month(), 5, 'Calling moment() on a moment will create a clone'); | |
32363 }); | |
32364 | |
32365 test('cloning carrying over utc mode', function (assert) { | |
32366 assert.equal(moment().local().clone()._isUTC, false, 'An explicit cloned local moment should have _isUTC == false'); | |
32367 assert.equal(moment().utc().clone()._isUTC, true, 'An cloned utc moment should have _isUTC == true'); | |
32368 assert.equal(moment().clone()._isUTC, false, 'An explicit cloned local moment should have _isUTC == false'); | |
32369 assert.equal(moment.utc().clone()._isUTC, true, 'An explicit cloned utc moment should have _isUTC == true'); | |
32370 assert.equal(moment(moment().local())._isUTC, false, 'An implicit cloned local moment should have _isUTC == false'); | |
32371 assert.equal(moment(moment().utc())._isUTC, true, 'An implicit cloned utc moment should have _isUTC == true'); | |
32372 assert.equal(moment(moment())._isUTC, false, 'An implicit cloned local moment should have _isUTC == false'); | |
32373 assert.equal(moment(moment.utc())._isUTC, true, 'An implicit cloned utc moment should have _isUTC == true'); | |
32374 }); | |
32375 | |
32376 test('parsing iso', function (assert) { | |
32377 var offset = moment([2011, 9, 8]).utcOffset(), | |
32378 pad = function (input) { | |
32379 if (input < 10) { | |
32380 return '0' + input; | |
32381 } | |
32382 return '' + input; | |
32383 }, | |
32384 hourOffset = (offset > 0 ? Math.floor(offset / 60) : Math.ceil(offset / 60)), | |
32385 minOffset = offset - (hourOffset * 60), | |
32386 tz = (offset >= 0) ? | |
32387 '+' + pad(hourOffset) + ':' + pad(minOffset) : | |
32388 '-' + pad(-hourOffset) + ':' + pad(-minOffset), | |
32389 tz2 = tz.replace(':', ''), | |
32390 tz3 = tz2.slice(0, 3), | |
32391 formats = [ | |
32392 ['2011-10-08', '2011-10-08T00:00:00.000' + tz], | |
32393 ['2011-10-08T18', '2011-10-08T18:00:00.000' + tz], | |
32394 ['2011-10-08T18:04', '2011-10-08T18:04:00.000' + tz], | |
32395 ['2011-10-08T18:04:20', '2011-10-08T18:04:20.000' + tz], | |
32396 ['2011-10-08T18:04' + tz, '2011-10-08T18:04:00.000' + tz], | |
32397 ['2011-10-08T18:04:20' + tz, '2011-10-08T18:04:20.000' + tz], | |
32398 ['2011-10-08T18:04' + tz2, '2011-10-08T18:04:00.000' + tz], | |
32399 ['2011-10-08T18:04:20' + tz2, '2011-10-08T18:04:20.000' + tz], | |
32400 ['2011-10-08T18:04' + tz3, '2011-10-08T18:04:00.000' + tz], | |
32401 ['2011-10-08T18:04:20' + tz3, '2011-10-08T18:04:20.000' + tz], | |
32402 ['2011-10-08T18:04:20.1' + tz2, '2011-10-08T18:04:20.100' + tz], | |
32403 ['2011-10-08T18:04:20.11' + tz2, '2011-10-08T18:04:20.110' + tz], | |
32404 ['2011-10-08T18:04:20.111' + tz2, '2011-10-08T18:04:20.111' + tz], | |
32405 ['2011-10-08 18', '2011-10-08T18:00:00.000' + tz], | |
32406 ['2011-10-08 18:04', '2011-10-08T18:04:00.000' + tz], | |
32407 ['2011-10-08 18:04:20', '2011-10-08T18:04:20.000' + tz], | |
32408 ['2011-10-08 18:04' + tz, '2011-10-08T18:04:00.000' + tz], | |
32409 ['2011-10-08 18:04:20' + tz, '2011-10-08T18:04:20.000' + tz], | |
32410 ['2011-10-08 18:04' + tz2, '2011-10-08T18:04:00.000' + tz], | |
32411 ['2011-10-08 18:04:20' + tz2, '2011-10-08T18:04:20.000' + tz], | |
32412 ['2011-10-08 18:04' + tz3, '2011-10-08T18:04:00.000' + tz], | |
32413 ['2011-10-08 18:04:20' + tz3, '2011-10-08T18:04:20.000' + tz], | |
32414 ['2011-10-08 18:04:20.1' + tz2, '2011-10-08T18:04:20.100' + tz], | |
32415 ['2011-10-08 18:04:20.11' + tz2, '2011-10-08T18:04:20.110' + tz], | |
32416 ['2011-10-08 18:04:20.111' + tz2, '2011-10-08T18:04:20.111' + tz], | |
32417 ['2011-W40', '2011-10-03T00:00:00.000' + tz], | |
32418 ['2011-W40-6', '2011-10-08T00:00:00.000' + tz], | |
32419 ['2011-W40-6T18', '2011-10-08T18:00:00.000' + tz], | |
32420 ['2011-W40-6T18:04', '2011-10-08T18:04:00.000' + tz], | |
32421 ['2011-W40-6T18:04:20', '2011-10-08T18:04:20.000' + tz], | |
32422 ['2011-W40-6T18:04' + tz, '2011-10-08T18:04:00.000' + tz], | |
32423 ['2011-W40-6T18:04:20' + tz, '2011-10-08T18:04:20.000' + tz], | |
32424 ['2011-W40-6T18:04' + tz2, '2011-10-08T18:04:00.000' + tz], | |
32425 ['2011-W40-6T18:04:20' + tz2, '2011-10-08T18:04:20.000' + tz], | |
32426 ['2011-W40-6T18:04' + tz3, '2011-10-08T18:04:00.000' + tz], | |
32427 ['2011-W40-6T18:04:20' + tz3, '2011-10-08T18:04:20.000' + tz], | |
32428 ['2011-W40-6T18:04:20.1' + tz2, '2011-10-08T18:04:20.100' + tz], | |
32429 ['2011-W40-6T18:04:20.11' + tz2, '2011-10-08T18:04:20.110' + tz], | |
32430 ['2011-W40-6T18:04:20.111' + tz2, '2011-10-08T18:04:20.111' + tz], | |
32431 ['2011-W40-6 18', '2011-10-08T18:00:00.000' + tz], | |
32432 ['2011-W40-6 18:04', '2011-10-08T18:04:00.000' + tz], | |
32433 ['2011-W40-6 18:04:20', '2011-10-08T18:04:20.000' + tz], | |
32434 ['2011-W40-6 18:04' + tz, '2011-10-08T18:04:00.000' + tz], | |
32435 ['2011-W40-6 18:04:20' + tz, '2011-10-08T18:04:20.000' + tz], | |
32436 ['2011-W40-6 18:04' + tz2, '2011-10-08T18:04:00.000' + tz], | |
32437 ['2011-W40-6 18:04:20' + tz2, '2011-10-08T18:04:20.000' + tz], | |
32438 ['2011-W40-6 18:04' + tz3, '2011-10-08T18:04:00.000' + tz], | |
32439 ['2011-W40-6 18:04:20' + tz3, '2011-10-08T18:04:20.000' + tz], | |
32440 ['2011-W40-6 18:04:20.1' + tz2, '2011-10-08T18:04:20.100' + tz], | |
32441 ['2011-W40-6 18:04:20.11' + tz2, '2011-10-08T18:04:20.110' + tz], | |
32442 ['2011-W40-6 18:04:20.111' + tz2, '2011-10-08T18:04:20.111' + tz], | |
32443 ['2011-281', '2011-10-08T00:00:00.000' + tz], | |
32444 ['2011-281T18', '2011-10-08T18:00:00.000' + tz], | |
32445 ['2011-281T18:04', '2011-10-08T18:04:00.000' + tz], | |
32446 ['2011-281T18:04:20', '2011-10-08T18:04:20.000' + tz], | |
32447 ['2011-281T18:04' + tz, '2011-10-08T18:04:00.000' + tz], | |
32448 ['2011-281T18:04:20' + tz, '2011-10-08T18:04:20.000' + tz], | |
32449 ['2011-281T18:04' + tz2, '2011-10-08T18:04:00.000' + tz], | |
32450 ['2011-281T18:04:20' + tz2, '2011-10-08T18:04:20.000' + tz], | |
32451 ['2011-281T18:04' + tz3, '2011-10-08T18:04:00.000' + tz], | |
32452 ['2011-281T18:04:20' + tz3, '2011-10-08T18:04:20.000' + tz], | |
32453 ['2011-281T18:04:20.1' + tz2, '2011-10-08T18:04:20.100' + tz], | |
32454 ['2011-281T18:04:20.11' + tz2, '2011-10-08T18:04:20.110' + tz], | |
32455 ['2011-281T18:04:20.111' + tz2, '2011-10-08T18:04:20.111' + tz], | |
32456 ['2011-281 18', '2011-10-08T18:00:00.000' + tz], | |
32457 ['2011-281 18:04', '2011-10-08T18:04:00.000' + tz], | |
32458 ['2011-281 18:04:20', '2011-10-08T18:04:20.000' + tz], | |
32459 ['2011-281 18:04' + tz, '2011-10-08T18:04:00.000' + tz], | |
32460 ['2011-281 18:04:20' + tz, '2011-10-08T18:04:20.000' + tz], | |
32461 ['2011-281 18:04' + tz2, '2011-10-08T18:04:00.000' + tz], | |
32462 ['2011-281 18:04:20' + tz2, '2011-10-08T18:04:20.000' + tz], | |
32463 ['2011-281 18:04' + tz3, '2011-10-08T18:04:00.000' + tz], | |
32464 ['2011-281 18:04:20' + tz3, '2011-10-08T18:04:20.000' + tz], | |
32465 ['2011-281 18:04:20.1' + tz2, '2011-10-08T18:04:20.100' + tz], | |
32466 ['2011-281 18:04:20.11' + tz2, '2011-10-08T18:04:20.110' + tz], | |
32467 ['2011-281 18:04:20.111' + tz2, '2011-10-08T18:04:20.111' + tz] | |
32468 ], i; | |
32469 for (i = 0; i < formats.length; i++) { | |
32470 assert.equal(moment(formats[i][0]).format('YYYY-MM-DDTHH:mm:ss.SSSZ'), formats[i][1], 'moment should be able to parse ISO ' + formats[i][0]); | |
32471 } | |
32472 }); | |
32473 | |
32474 test('parsing iso week year/week/weekday', function (assert) { | |
32475 assert.equal(moment.utc('2007-W01').format(), '2007-01-01T00:00:00+00:00', '2008 week 1 (1st Jan Mon)'); | |
32476 assert.equal(moment.utc('2008-W01').format(), '2007-12-31T00:00:00+00:00', '2008 week 1 (1st Jan Tue)'); | |
32477 assert.equal(moment.utc('2003-W01').format(), '2002-12-30T00:00:00+00:00', '2008 week 1 (1st Jan Wed)'); | |
32478 assert.equal(moment.utc('2009-W01').format(), '2008-12-29T00:00:00+00:00', '2009 week 1 (1st Jan Thu)'); | |
32479 assert.equal(moment.utc('2010-W01').format(), '2010-01-04T00:00:00+00:00', '2010 week 1 (1st Jan Fri)'); | |
32480 assert.equal(moment.utc('2011-W01').format(), '2011-01-03T00:00:00+00:00', '2011 week 1 (1st Jan Sat)'); | |
32481 assert.equal(moment.utc('2012-W01').format(), '2012-01-02T00:00:00+00:00', '2012 week 1 (1st Jan Sun)'); | |
32482 }); | |
32483 | |
32484 test('parsing week year/week/weekday (dow 1, doy 4)', function (assert) { | |
32485 moment.locale('dow:1,doy:4', {week: {dow: 1, doy: 4}}); | |
32486 | |
32487 assert.equal(moment.utc('2007-01', 'gggg-ww').format(), '2007-01-01T00:00:00+00:00', '2007 week 1 (1st Jan Mon)'); | |
32488 assert.equal(moment.utc('2008-01', 'gggg-ww').format(), '2007-12-31T00:00:00+00:00', '2008 week 1 (1st Jan Tue)'); | |
32489 assert.equal(moment.utc('2003-01', 'gggg-ww').format(), '2002-12-30T00:00:00+00:00', '2003 week 1 (1st Jan Wed)'); | |
32490 assert.equal(moment.utc('2009-01', 'gggg-ww').format(), '2008-12-29T00:00:00+00:00', '2009 week 1 (1st Jan Thu)'); | |
32491 assert.equal(moment.utc('2010-01', 'gggg-ww').format(), '2010-01-04T00:00:00+00:00', '2010 week 1 (1st Jan Fri)'); | |
32492 assert.equal(moment.utc('2011-01', 'gggg-ww').format(), '2011-01-03T00:00:00+00:00', '2011 week 1 (1st Jan Sat)'); | |
32493 assert.equal(moment.utc('2012-01', 'gggg-ww').format(), '2012-01-02T00:00:00+00:00', '2012 week 1 (1st Jan Sun)'); | |
32494 | |
32495 moment.defineLocale('dow:1,doy:4', null); | |
32496 }); | |
32497 | |
32498 test('parsing week year/week/weekday (dow 1, doy 7)', function (assert) { | |
32499 moment.locale('dow:1,doy:7', {week: {dow: 1, doy: 7}}); | |
32500 | |
32501 assert.equal(moment.utc('2007-01', 'gggg-ww').format(), '2007-01-01T00:00:00+00:00', '2007 week 1 (1st Jan Mon)'); | |
32502 assert.equal(moment.utc('2008-01', 'gggg-ww').format(), '2007-12-31T00:00:00+00:00', '2008 week 1 (1st Jan Tue)'); | |
32503 assert.equal(moment.utc('2003-01', 'gggg-ww').format(), '2002-12-30T00:00:00+00:00', '2003 week 1 (1st Jan Wed)'); | |
32504 assert.equal(moment.utc('2009-01', 'gggg-ww').format(), '2008-12-29T00:00:00+00:00', '2009 week 1 (1st Jan Thu)'); | |
32505 assert.equal(moment.utc('2010-01', 'gggg-ww').format(), '2009-12-28T00:00:00+00:00', '2010 week 1 (1st Jan Fri)'); | |
32506 assert.equal(moment.utc('2011-01', 'gggg-ww').format(), '2010-12-27T00:00:00+00:00', '2011 week 1 (1st Jan Sat)'); | |
32507 assert.equal(moment.utc('2012-01', 'gggg-ww').format(), '2011-12-26T00:00:00+00:00', '2012 week 1 (1st Jan Sun)'); | |
32508 moment.defineLocale('dow:1,doy:7', null); | |
32509 }); | |
32510 | |
32511 test('parsing week year/week/weekday (dow 0, doy 6)', function (assert) { | |
32512 moment.locale('dow:0,doy:6', {week: {dow: 0, doy: 6}}); | |
32513 | |
32514 assert.equal(moment.utc('2007-01', 'gggg-ww').format(), '2006-12-31T00:00:00+00:00', '2007 week 1 (1st Jan Mon)'); | |
32515 assert.equal(moment.utc('2008-01', 'gggg-ww').format(), '2007-12-30T00:00:00+00:00', '2008 week 1 (1st Jan Tue)'); | |
32516 assert.equal(moment.utc('2003-01', 'gggg-ww').format(), '2002-12-29T00:00:00+00:00', '2003 week 1 (1st Jan Wed)'); | |
32517 assert.equal(moment.utc('2009-01', 'gggg-ww').format(), '2008-12-28T00:00:00+00:00', '2009 week 1 (1st Jan Thu)'); | |
32518 assert.equal(moment.utc('2010-01', 'gggg-ww').format(), '2009-12-27T00:00:00+00:00', '2010 week 1 (1st Jan Fri)'); | |
32519 assert.equal(moment.utc('2011-01', 'gggg-ww').format(), '2010-12-26T00:00:00+00:00', '2011 week 1 (1st Jan Sat)'); | |
32520 assert.equal(moment.utc('2012-01', 'gggg-ww').format(), '2012-01-01T00:00:00+00:00', '2012 week 1 (1st Jan Sun)'); | |
32521 moment.defineLocale('dow:0,doy:6', null); | |
32522 }); | |
32523 | |
32524 test('parsing week year/week/weekday (dow 6, doy 12)', function (assert) { | |
32525 moment.locale('dow:6,doy:12', {week: {dow: 6, doy: 12}}); | |
32526 | |
32527 assert.equal(moment.utc('2007-01', 'gggg-ww').format(), '2006-12-30T00:00:00+00:00', '2007 week 1 (1st Jan Mon)'); | |
32528 assert.equal(moment.utc('2008-01', 'gggg-ww').format(), '2007-12-29T00:00:00+00:00', '2008 week 1 (1st Jan Tue)'); | |
32529 assert.equal(moment.utc('2003-01', 'gggg-ww').format(), '2002-12-28T00:00:00+00:00', '2003 week 1 (1st Jan Wed)'); | |
32530 assert.equal(moment.utc('2009-01', 'gggg-ww').format(), '2008-12-27T00:00:00+00:00', '2009 week 1 (1st Jan Thu)'); | |
32531 assert.equal(moment.utc('2010-01', 'gggg-ww').format(), '2009-12-26T00:00:00+00:00', '2010 week 1 (1st Jan Fri)'); | |
32532 assert.equal(moment.utc('2011-01', 'gggg-ww').format(), '2011-01-01T00:00:00+00:00', '2011 week 1 (1st Jan Sat)'); | |
32533 assert.equal(moment.utc('2012-01', 'gggg-ww').format(), '2011-12-31T00:00:00+00:00', '2012 week 1 (1st Jan Sun)'); | |
32534 }); | |
32535 | |
32536 test('parsing ISO with Z', function (assert) { | |
32537 var i, mom, formats = [ | |
32538 ['2011-10-08T18:04', '2011-10-08T18:04:00.000'], | |
32539 ['2011-10-08T18:04:20', '2011-10-08T18:04:20.000'], | |
32540 ['2011-10-08T18:04:20.1', '2011-10-08T18:04:20.100'], | |
32541 ['2011-10-08T18:04:20.11', '2011-10-08T18:04:20.110'], | |
32542 ['2011-10-08T18:04:20.111', '2011-10-08T18:04:20.111'], | |
32543 ['2011-W40-6T18', '2011-10-08T18:00:00.000'], | |
32544 ['2011-W40-6T18:04', '2011-10-08T18:04:00.000'], | |
32545 ['2011-W40-6T18:04:20', '2011-10-08T18:04:20.000'], | |
32546 ['2011-W40-6T18:04:20.1', '2011-10-08T18:04:20.100'], | |
32547 ['2011-W40-6T18:04:20.11', '2011-10-08T18:04:20.110'], | |
32548 ['2011-W40-6T18:04:20.111', '2011-10-08T18:04:20.111'], | |
32549 ['2011-281T18', '2011-10-08T18:00:00.000'], | |
32550 ['2011-281T18:04', '2011-10-08T18:04:00.000'], | |
32551 ['2011-281T18:04:20', '2011-10-08T18:04:20.000'], | |
32552 ['2011-281T18:04:20', '2011-10-08T18:04:20.000'], | |
32553 ['2011-281T18:04:20.1', '2011-10-08T18:04:20.100'], | |
32554 ['2011-281T18:04:20.11', '2011-10-08T18:04:20.110'], | |
32555 ['2011-281T18:04:20.111', '2011-10-08T18:04:20.111'] | |
32556 ]; | |
32557 | |
32558 for (i = 0; i < formats.length; i++) { | |
32559 mom = moment(formats[i][0] + 'Z').utc(); | |
32560 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'); | |
32561 | |
32562 mom = moment(formats[i][0] + ' Z').utc(); | |
32563 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'); | |
32564 } | |
32565 }); | |
32566 | |
32567 test('parsing iso with T', function (assert) { | |
32568 assert.equal(moment('2011-10-08T18')._f, 'YYYY-MM-DDTHH', 'should include \'T\' in the format'); | |
32569 assert.equal(moment('2011-10-08T18:20')._f, 'YYYY-MM-DDTHH:mm', 'should include \'T\' in the format'); | |
32570 assert.equal(moment('2011-10-08T18:20:13')._f, 'YYYY-MM-DDTHH:mm:ss', 'should include \'T\' in the format'); | |
32571 assert.equal(moment('2011-10-08T18:20:13.321')._f, 'YYYY-MM-DDTHH:mm:ss.SSSS', 'should include \'T\' in the format'); | |
32572 | |
32573 assert.equal(moment('2011-10-08 18')._f, 'YYYY-MM-DD HH', 'should not include \'T\' in the format'); | |
32574 assert.equal(moment('2011-10-08 18:20')._f, 'YYYY-MM-DD HH:mm', 'should not include \'T\' in the format'); | |
32575 assert.equal(moment('2011-10-08 18:20:13')._f, 'YYYY-MM-DD HH:mm:ss', 'should not include \'T\' in the format'); | |
32576 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'); | |
32577 }); | |
32578 | |
32579 test('parsing iso Z timezone', function (assert) { | |
32580 var i, | |
32581 formats = [ | |
32582 ['2011-10-08T18:04Z', '2011-10-08T18:04:00.000+00:00'], | |
32583 ['2011-10-08T18:04:20Z', '2011-10-08T18:04:20.000+00:00'], | |
32584 ['2011-10-08T18:04:20.111Z', '2011-10-08T18:04:20.111+00:00'] | |
32585 ]; | |
32586 for (i = 0; i < formats.length; i++) { | |
32587 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]); | |
32588 } | |
32589 }); | |
32590 | |
32591 test('parsing iso Z timezone into local', function (assert) { | |
32592 var m = moment('2011-10-08T18:04:20.111Z'); | |
32593 | |
32594 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'); | |
32595 }); | |
32596 | |
32597 test('parsing iso with more subsecond precision digits', function (assert) { | |
32598 assert.equal(moment.utc('2013-07-31T22:00:00.0000000Z').format(), '2013-07-31T22:00:00+00:00', 'more than 3 subsecond digits'); | |
32599 }); | |
32600 | |
32601 test('null or empty', function (assert) { | |
32602 assert.equal(moment('').isValid(), false, 'moment(\'\') is not valid'); | |
32603 assert.equal(moment(null).isValid(), false, 'moment(null) is not valid'); | |
32604 assert.equal(moment(null, 'YYYY-MM-DD').isValid(), false, 'moment(\'\', \'format\') is not valid'); | |
32605 assert.equal(moment('', 'YYYY-MM-DD').isValid(), false, 'moment(\'\', \'format\') is not valid'); | |
32606 assert.equal(moment.utc('').isValid(), false, 'moment.utc(\'\') is not valid'); | |
32607 assert.equal(moment.utc(null).isValid(), false, 'moment.utc(null) is not valid'); | |
32608 assert.equal(moment.utc(null, 'YYYY-MM-DD').isValid(), false, 'moment.utc(null) is not valid'); | |
32609 assert.equal(moment.utc('', 'YYYY-MM-DD').isValid(), false, 'moment.utc(\'\', \'YYYY-MM-DD\') is not valid'); | |
32610 }); | |
32611 | |
32612 test('first century', function (assert) { | |
32613 assert.equal(moment([0, 0, 1]).format('YYYY-MM-DD'), '0000-01-01', 'Year AD 0'); | |
32614 assert.equal(moment([99, 0, 1]).format('YYYY-MM-DD'), '0099-01-01', 'Year AD 99'); | |
32615 assert.equal(moment([999, 0, 1]).format('YYYY-MM-DD'), '0999-01-01', 'Year AD 999'); | |
32616 assert.equal(moment('0 1 1', 'YYYY MM DD').format('YYYY-MM-DD'), '0000-01-01', 'Year AD 0'); | |
32617 assert.equal(moment('999 1 1', 'YYYY MM DD').format('YYYY-MM-DD'), '0999-01-01', 'Year AD 999'); | |
32618 assert.equal(moment('0 1 1', 'YYYYY MM DD').format('YYYYY-MM-DD'), '00000-01-01', 'Year AD 0'); | |
32619 assert.equal(moment('99 1 1', 'YYYYY MM DD').format('YYYYY-MM-DD'), '00099-01-01', 'Year AD 99'); | |
32620 assert.equal(moment('999 1 1', 'YYYYY MM DD').format('YYYYY-MM-DD'), '00999-01-01', 'Year AD 999'); | |
32621 }); | |
32622 | |
32623 test('six digit years', function (assert) { | |
32624 assert.equal(moment([-270000, 0, 1]).format('YYYYY-MM-DD'), '-270000-01-01', 'format BC 270,001'); | |
32625 assert.equal(moment([270000, 0, 1]).format('YYYYY-MM-DD'), '270000-01-01', 'format AD 270,000'); | |
32626 assert.equal(moment('-270000-01-01', 'YYYYY-MM-DD').toDate().getFullYear(), -270000, 'parse BC 270,001'); | |
32627 assert.equal(moment('270000-01-01', 'YYYYY-MM-DD').toDate().getFullYear(), 270000, 'parse AD 270,000'); | |
32628 assert.equal(moment('+270000-01-01', 'YYYYY-MM-DD').toDate().getFullYear(), 270000, 'parse AD +270,000'); | |
32629 assert.equal(moment.utc('-270000-01-01', 'YYYYY-MM-DD').toDate().getUTCFullYear(), -270000, 'parse utc BC 270,001'); | |
32630 assert.equal(moment.utc('270000-01-01', 'YYYYY-MM-DD').toDate().getUTCFullYear(), 270000, 'parse utc AD 270,000'); | |
32631 assert.equal(moment.utc('+270000-01-01', 'YYYYY-MM-DD').toDate().getUTCFullYear(), 270000, 'parse utc AD +270,000'); | |
32632 }); | |
32633 | |
32634 test('negative four digit years', function (assert) { | |
32635 assert.equal(moment('-1000-01-01', 'YYYYY-MM-DD').toDate().getFullYear(), -1000, 'parse BC 1,001'); | |
32636 assert.equal(moment.utc('-1000-01-01', 'YYYYY-MM-DD').toDate().getUTCFullYear(), -1000, 'parse utc BC 1,001'); | |
32637 }); | |
32638 | |
32639 test('strict parsing', function (assert) { | |
32640 assert.equal(moment('2014-', 'YYYY-Q', true).isValid(), false, 'fail missing quarter'); | |
32641 | |
32642 assert.equal(moment('2012-05', 'YYYY-MM', true).format('YYYY-MM'), '2012-05', 'parse correct string'); | |
32643 assert.equal(moment(' 2012-05', 'YYYY-MM', true).isValid(), false, 'fail on extra whitespace'); | |
32644 assert.equal(moment('foo 2012-05', '[foo] YYYY-MM', true).format('YYYY-MM'), '2012-05', 'handle fixed text'); | |
32645 assert.equal(moment('2012 05', 'YYYY-MM', true).isValid(), false, 'fail on different separator'); | |
32646 assert.equal(moment('2012 05', 'YYYY MM DD', true).isValid(), false, 'fail on too many tokens'); | |
32647 | |
32648 assert.equal(moment('05 30 2010', ['DD MM YYYY', 'MM DD YYYY'], true).format('MM DD YYYY'), '05 30 2010', 'array with bad date'); | |
32649 assert.equal(moment('05 30 2010', ['', 'MM DD YYYY'], true).format('MM DD YYYY'), '05 30 2010', 'array with invalid format'); | |
32650 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'); | |
32651 | |
32652 assert.equal(moment('2010.*...', 'YYYY.*', true).isValid(), false, 'invalid format with regex chars'); | |
32653 assert.equal(moment('2010.*', 'YYYY.*', true).year(), 2010, 'valid format with regex chars'); | |
32654 assert.equal(moment('.*2010.*', '.*YYYY.*', true).year(), 2010, 'valid format with regex chars on both sides'); | |
32655 | |
32656 //strict tokens | |
32657 assert.equal(moment('-5-05-25', 'YYYY-MM-DD', true).isValid(), false, 'invalid negative year'); | |
32658 assert.equal(moment('2-05-25', 'YYYY-MM-DD', true).isValid(), false, 'invalid one-digit year'); | |
32659 assert.equal(moment('20-05-25', 'YYYY-MM-DD', true).isValid(), false, 'invalid two-digit year'); | |
32660 assert.equal(moment('201-05-25', 'YYYY-MM-DD', true).isValid(), false, 'invalid three-digit year'); | |
32661 assert.equal(moment('2010-05-25', 'YYYY-MM-DD', true).isValid(), true, 'valid four-digit year'); | |
32662 assert.equal(moment('22010-05-25', 'YYYY-MM-DD', true).isValid(), false, 'invalid five-digit year'); | |
32663 | |
32664 assert.equal(moment('12-05-25', 'YY-MM-DD', true).isValid(), true, 'valid two-digit year'); | |
32665 assert.equal(moment('2012-05-25', 'YY-MM-DD', true).isValid(), false, 'invalid four-digit year'); | |
32666 | |
32667 assert.equal(moment('-5-05-25', 'Y-MM-DD', true).isValid(), true, 'valid negative year'); | |
32668 assert.equal(moment('2-05-25', 'Y-MM-DD', true).isValid(), true, 'valid one-digit year'); | |
32669 assert.equal(moment('20-05-25', 'Y-MM-DD', true).isValid(), true, 'valid two-digit year'); | |
32670 assert.equal(moment('201-05-25', 'Y-MM-DD', true).isValid(), true, 'valid three-digit year'); | |
32671 | |
32672 assert.equal(moment('2012-5-25', 'YYYY-M-DD', true).isValid(), true, 'valid one-digit month'); | |
32673 assert.equal(moment('2012-5-25', 'YYYY-MM-DD', true).isValid(), false, 'invalid one-digit month'); | |
32674 assert.equal(moment('2012-05-25', 'YYYY-M-DD', true).isValid(), true, 'valid one-digit month'); | |
32675 assert.equal(moment('2012-05-25', 'YYYY-MM-DD', true).isValid(), true, 'valid one-digit month'); | |
32676 | |
32677 assert.equal(moment('2012-05-2', 'YYYY-MM-D', true).isValid(), true, 'valid one-digit day'); | |
32678 assert.equal(moment('2012-05-2', 'YYYY-MM-DD', true).isValid(), false, 'invalid one-digit day'); | |
32679 assert.equal(moment('2012-05-02', 'YYYY-MM-D', true).isValid(), true, 'valid two-digit day'); | |
32680 assert.equal(moment('2012-05-02', 'YYYY-MM-DD', true).isValid(), true, 'valid two-digit day'); | |
32681 | |
32682 assert.equal(moment('+002012-05-25', 'YYYYY-MM-DD', true).isValid(), true, 'valid six-digit year'); | |
32683 assert.equal(moment('+2012-05-25', 'YYYYY-MM-DD', true).isValid(), false, 'invalid four-digit year'); | |
32684 | |
32685 //thse are kinda pointless, but they should work as expected | |
32686 assert.equal(moment('1', 'S', true).isValid(), true, 'valid one-digit milisecond'); | |
32687 assert.equal(moment('12', 'S', true).isValid(), false, 'invalid two-digit milisecond'); | |
32688 assert.equal(moment('123', 'S', true).isValid(), false, 'invalid three-digit milisecond'); | |
32689 | |
32690 assert.equal(moment('1', 'SS', true).isValid(), false, 'invalid one-digit milisecond'); | |
32691 assert.equal(moment('12', 'SS', true).isValid(), true, 'valid two-digit milisecond'); | |
32692 assert.equal(moment('123', 'SS', true).isValid(), false, 'invalid three-digit milisecond'); | |
32693 | |
32694 assert.equal(moment('1', 'SSS', true).isValid(), false, 'invalid one-digit milisecond'); | |
32695 assert.equal(moment('12', 'SSS', true).isValid(), false, 'invalid two-digit milisecond'); | |
32696 assert.equal(moment('123', 'SSS', true).isValid(), true, 'valid three-digit milisecond'); | |
32697 | |
32698 // strict parsing respects month length | |
32699 assert.ok(moment('1 January 2000', 'D MMMM YYYY', true).isValid(), 'capital long-month + MMMM'); | |
32700 assert.ok(!moment('1 January 2000', 'D MMM YYYY', true).isValid(), 'capital long-month + MMM'); | |
32701 assert.ok(!moment('1 Jan 2000', 'D MMMM YYYY', true).isValid(), 'capital short-month + MMMM'); | |
32702 assert.ok(moment('1 Jan 2000', 'D MMM YYYY', true).isValid(), 'capital short-month + MMM'); | |
32703 assert.ok(moment('1 january 2000', 'D MMMM YYYY', true).isValid(), 'lower long-month + MMMM'); | |
32704 assert.ok(!moment('1 january 2000', 'D MMM YYYY', true).isValid(), 'lower long-month + MMM'); | |
32705 assert.ok(!moment('1 jan 2000', 'D MMMM YYYY', true).isValid(), 'lower short-month + MMMM'); | |
32706 assert.ok(moment('1 jan 2000', 'D MMM YYYY', true).isValid(), 'lower short-month + MMM'); | |
32707 }); | |
32708 | |
32709 test('parsing into a locale', function (assert) { | |
32710 moment.defineLocale('parselocale', { | |
32711 months : 'one_two_three_four_five_six_seven_eight_nine_ten_eleven_twelve'.split('_'), | |
32712 monthsShort : 'one_two_three_four_five_six_seven_eight_nine_ten_eleven_twelve'.split('_') | |
32713 }); | |
32714 | |
32715 moment.locale('en'); | |
32716 | |
32717 assert.equal(moment('2012 seven', 'YYYY MMM', 'parselocale').month(), 6, 'should be able to parse in a specific locale'); | |
32718 | |
32719 moment.locale('parselocale'); | |
32720 | |
32721 assert.equal(moment('2012 july', 'YYYY MMM', 'en').month(), 6, 'should be able to parse in a specific locale'); | |
32722 | |
32723 moment.defineLocale('parselocale', null); | |
32724 }); | |
32725 | |
32726 function getVerifier(test) { | |
32727 return function (input, format, expected, description, asymetrical) { | |
32728 var m = moment(input, format); | |
32729 test.equal(m.format('YYYY MM DD'), expected, 'compare: ' + description); | |
32730 | |
32731 //test round trip | |
32732 if (!asymetrical) { | |
32733 test.equal(m.format(format), input, 'round trip: ' + description); | |
32734 } | |
32735 }; | |
32736 } | |
32737 | |
32738 test('parsing week and weekday information', function (assert) { | |
32739 var ver = getVerifier(assert); | |
32740 | |
32741 // year | |
32742 ver('12', 'gg', '2012 01 01', 'week-year two digits'); | |
32743 ver('2012', 'gggg', '2012 01 01', 'week-year four digits'); | |
32744 | |
32745 ver('99', 'gg', '1998 12 27', 'week-year two digits previous year'); | |
32746 ver('1999', 'gggg', '1998 12 27', 'week-year four digits previous year'); | |
32747 | |
32748 ver('99', 'GG', '1999 01 04', 'iso week-year two digits'); | |
32749 ver('1999', 'GGGG', '1999 01 04', 'iso week-year four digits'); | |
32750 | |
32751 ver('13', 'GG', '2012 12 31', 'iso week-year two digits previous year'); | |
32752 ver('2013', 'GGGG', '2012 12 31', 'iso week-year four digits previous year'); | |
32753 | |
32754 // year + week | |
32755 ver('1999 37', 'gggg w', '1999 09 05', 'week'); | |
32756 ver('1999 37', 'gggg ww', '1999 09 05', 'week double'); | |
32757 ver('1999 37', 'GGGG W', '1999 09 13', 'iso week'); | |
32758 ver('1999 37', 'GGGG WW', '1999 09 13', 'iso week double'); | |
32759 | |
32760 ver('1999 37 4', 'GGGG WW E', '1999 09 16', 'iso day'); | |
32761 ver('1999 37 04', 'GGGG WW E', '1999 09 16', 'iso day wide', true); | |
32762 | |
32763 ver('1999 37 4', 'gggg ww e', '1999 09 09', 'day'); | |
32764 ver('1999 37 04', 'gggg ww e', '1999 09 09', 'day wide', true); | |
32765 | |
32766 // year + week + day | |
32767 ver('1999 37 4', 'gggg ww d', '1999 09 09', 'd'); | |
32768 ver('1999 37 Th', 'gggg ww dd', '1999 09 09', 'dd'); | |
32769 ver('1999 37 Thu', 'gggg ww ddd', '1999 09 09', 'ddd'); | |
32770 ver('1999 37 Thursday', 'gggg ww dddd', '1999 09 09', 'dddd'); | |
32771 | |
32772 // lower-order only | |
32773 assert.equal(moment('22', 'ww').week(), 22, 'week sets the week by itself'); | |
32774 assert.equal(moment('22', 'ww').weekYear(), moment().weekYear(), 'week keeps this year'); | |
32775 assert.equal(moment('2012 22', 'YYYY ww').weekYear(), 2012, 'week keeps parsed year'); | |
32776 | |
32777 assert.equal(moment('22', 'WW').isoWeek(), 22, 'iso week sets the week by itself'); | |
32778 assert.equal(moment('2012 22', 'YYYY WW').weekYear(), 2012, 'iso week keeps parsed year'); | |
32779 assert.equal(moment('22', 'WW').isoWeekYear(), moment().isoWeekYear(), 'iso week keeps this year'); | |
32780 | |
32781 // order | |
32782 ver('6 2013 2', 'e gggg w', '2013 01 12', 'order doesn\'t matter'); | |
32783 ver('6 2013 2', 'E GGGG W', '2013 01 12', 'iso order doesn\'t matter'); | |
32784 | |
32785 //can parse other stuff too | |
32786 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'); | |
32787 | |
32788 // In safari, all years before 1300 are shifted back with one day. | |
32789 // http://stackoverflow.com/questions/20768975/safari-subtracts-1-day-from-dates-before-1300 | |
32790 if (new Date('1300-01-01').getUTCFullYear() === 1300) { | |
32791 // Years less than 100 | |
32792 ver('0098-06', 'GGGG-WW', '0098 02 03', 'small years work', true); | |
32793 } | |
32794 }); | |
32795 | |
32796 test('parsing localized weekdays', function (assert) { | |
32797 var ver = getVerifier(assert); | |
32798 try { | |
32799 moment.locale('dow:1,doy:4', { | |
32800 weekdays : 'dimanche_lundi_mardi_mercredi_jeudi_vendredi_samedi'.split('_'), | |
32801 weekdaysShort : 'dim._lun._mar._mer._jeu._ven._sam.'.split('_'), | |
32802 weekdaysMin : 'Di_Lu_Ma_Me_Je_Ve_Sa'.split('_'), | |
32803 week: {dow: 1, doy: 4} | |
32804 }); | |
32805 ver('1999 37 4', 'GGGG WW E', '1999 09 16', 'iso ignores locale'); | |
32806 ver('1999 37 7', 'GGGG WW E', '1999 09 19', 'iso ignores locale'); | |
32807 | |
32808 ver('1999 37 0', 'gggg ww e', '1999 09 13', 'localized e uses local doy and dow: 0 = monday'); | |
32809 ver('1999 37 4', 'gggg ww e', '1999 09 17', 'localized e uses local doy and dow: 4 = friday'); | |
32810 | |
32811 ver('1999 37 1', 'gggg ww d', '1999 09 13', 'localized d uses 0-indexed days: 1 = monday'); | |
32812 ver('1999 37 Lu', 'gggg ww dd', '1999 09 13', 'localized d uses 0-indexed days: Mo'); | |
32813 ver('1999 37 lun.', 'gggg ww ddd', '1999 09 13', 'localized d uses 0-indexed days: Mon'); | |
32814 ver('1999 37 lundi', 'gggg ww dddd', '1999 09 13', 'localized d uses 0-indexed days: Monday'); | |
32815 ver('1999 37 4', 'gggg ww d', '1999 09 16', 'localized d uses 0-indexed days: 4'); | |
32816 | |
32817 //sunday goes at the end of the week | |
32818 ver('1999 37 0', 'gggg ww d', '1999 09 19', 'localized d uses 0-indexed days: 0 = sund'); | |
32819 ver('1999 37 Di', 'gggg ww dd', '1999 09 19', 'localized d uses 0-indexed days: 0 = sund'); | |
32820 } | |
32821 finally { | |
32822 moment.locale('en'); | |
32823 } | |
32824 }); | |
32825 | |
32826 test('parsing with customized two-digit year', function (assert) { | |
32827 var original = moment.parseTwoDigitYear; | |
32828 try { | |
32829 assert.equal(moment('68', 'YY').year(), 2068); | |
32830 assert.equal(moment('69', 'YY').year(), 1969); | |
32831 moment.parseTwoDigitYear = function (input) { | |
32832 return +input + (+input > 30 ? 1900 : 2000); | |
32833 }; | |
32834 assert.equal(moment('68', 'YY').year(), 1968); | |
32835 assert.equal(moment('67', 'YY').year(), 1967); | |
32836 assert.equal(moment('31', 'YY').year(), 1931); | |
32837 assert.equal(moment('30', 'YY').year(), 2030); | |
32838 } | |
32839 finally { | |
32840 moment.parseTwoDigitYear = original; | |
32841 } | |
32842 }); | |
32843 | |
32844 test('array with strings', function (assert) { | |
32845 assert.equal(moment(['2014', '7', '31']).isValid(), true, 'string array + isValid'); | |
32846 }); | |
32847 | |
32848 test('utc with array of formats', function (assert) { | |
32849 assert.equal(moment.utc('2014-01-01', ['YYYY-MM-DD', 'YYYY-MM']).format(), '2014-01-01T00:00:00+00:00', 'moment.utc works with array of formats'); | |
32850 }); | |
32851 | |
32852 test('parsing invalid string weekdays', function (assert) { | |
32853 assert.equal(false, moment('a', 'dd').isValid(), | |
32854 'dd with invalid weekday, non-strict'); | |
32855 assert.equal(false, moment('a', 'dd', true).isValid(), | |
32856 'dd with invalid weekday, strict'); | |
32857 assert.equal(false, moment('a', 'ddd').isValid(), | |
32858 'ddd with invalid weekday, non-strict'); | |
32859 assert.equal(false, moment('a', 'ddd', true).isValid(), | |
32860 'ddd with invalid weekday, strict'); | |
32861 assert.equal(false, moment('a', 'dddd').isValid(), | |
32862 'dddd with invalid weekday, non-strict'); | |
32863 assert.equal(false, moment('a', 'dddd', true).isValid(), | |
32864 'dddd with invalid weekday, strict'); | |
32865 }); | |
32866 | |
32867 test('milliseconds', function (assert) { | |
32868 assert.equal(moment('1', 'S').millisecond(), 100); | |
32869 assert.equal(moment('12', 'SS').millisecond(), 120); | |
32870 assert.equal(moment('123', 'SSS').millisecond(), 123); | |
32871 assert.equal(moment('1234', 'SSSS').millisecond(), 123); | |
32872 assert.equal(moment('12345', 'SSSSS').millisecond(), 123); | |
32873 assert.equal(moment('123456', 'SSSSSS').millisecond(), 123); | |
32874 assert.equal(moment('1234567', 'SSSSSSS').millisecond(), 123); | |
32875 assert.equal(moment('12345678', 'SSSSSSSS').millisecond(), 123); | |
32876 assert.equal(moment('123456789', 'SSSSSSSSS').millisecond(), 123); | |
32877 }); | |
32878 | |
32879 })); | |
32880 | |
32881 (function (global, factory) { | |
32882 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
32883 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
32884 factory(global.moment) | |
32885 }(this, function (moment) { 'use strict'; | |
32886 | |
32887 /*global QUnit:false*/ | |
32888 | |
32889 var test = QUnit.test; | |
32890 | |
32891 function module (name, lifecycle) { | |
32892 QUnit.module(name, { | |
32893 setup : function () { | |
32894 moment.locale('en'); | |
32895 moment.createFromInputFallback = function () { | |
32896 throw new Error('input not handled by moment'); | |
32897 }; | |
32898 if (lifecycle && lifecycle.setup) { | |
32899 lifecycle.setup(); | |
32900 } | |
32901 }, | |
32902 teardown : function () { | |
32903 if (lifecycle && lifecycle.teardown) { | |
32904 lifecycle.teardown(); | |
32905 } | |
32906 } | |
32907 }); | |
32908 } | |
32909 | |
32910 function localeModule (name, lifecycle) { | |
32911 QUnit.module('locale:' + name, { | |
32912 setup : function () { | |
32913 moment.locale(name); | |
32914 moment.createFromInputFallback = function () { | |
32915 throw new Error('input not handled by moment'); | |
32916 }; | |
32917 if (lifecycle && lifecycle.setup) { | |
32918 lifecycle.setup(); | |
32919 } | |
32920 }, | |
32921 teardown : function () { | |
32922 moment.locale('en'); | |
32923 if (lifecycle && lifecycle.teardown) { | |
32924 lifecycle.teardown(); | |
32925 } | |
32926 } | |
32927 }); | |
32928 } | |
32929 | |
32930 function each(array, callback) { | |
32931 var i; | |
32932 for (i = 0; i < array.length; i++) { | |
32933 callback(array[i], i, array); | |
32934 } | |
32935 } | |
32936 | |
32937 module('days in month'); | |
32938 | |
32939 test('days in month', function (assert) { | |
32940 each([31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], function (days, i) { | |
32941 var firstDay = moment([2012, i]), | |
32942 lastDay = moment([2012, i, days]); | |
32943 assert.equal(firstDay.daysInMonth(), days, firstDay.format('L') + ' should have ' + days + ' days.'); | |
32944 assert.equal(lastDay.daysInMonth(), days, lastDay.format('L') + ' should have ' + days + ' days.'); | |
32945 }); | |
32946 }); | |
32947 | |
32948 test('days in month leap years', function (assert) { | |
32949 assert.equal(moment([2010, 1]).daysInMonth(), 28, 'Feb 2010 should have 28 days'); | |
32950 assert.equal(moment([2100, 1]).daysInMonth(), 28, 'Feb 2100 should have 28 days'); | |
32951 assert.equal(moment([2008, 1]).daysInMonth(), 29, 'Feb 2008 should have 29 days'); | |
32952 assert.equal(moment([2000, 1]).daysInMonth(), 29, 'Feb 2000 should have 29 days'); | |
32953 }); | |
32954 | |
32955 })); | |
32956 | |
32957 (function (global, factory) { | |
32958 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
32959 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
32960 factory(global.moment) | |
32961 }(this, function (moment) { 'use strict'; | |
32962 | |
32963 /*global QUnit:false*/ | |
32964 | |
32965 var test = QUnit.test; | |
32966 | |
32967 function module (name, lifecycle) { | |
32968 QUnit.module(name, { | |
32969 setup : function () { | |
32970 moment.locale('en'); | |
32971 moment.createFromInputFallback = function () { | |
32972 throw new Error('input not handled by moment'); | |
32973 }; | |
32974 if (lifecycle && lifecycle.setup) { | |
32975 lifecycle.setup(); | |
32976 } | |
32977 }, | |
32978 teardown : function () { | |
32979 if (lifecycle && lifecycle.teardown) { | |
32980 lifecycle.teardown(); | |
32981 } | |
32982 } | |
32983 }); | |
32984 } | |
32985 | |
32986 function localeModule (name, lifecycle) { | |
32987 QUnit.module('locale:' + name, { | |
32988 setup : function () { | |
32989 moment.locale(name); | |
32990 moment.createFromInputFallback = function () { | |
32991 throw new Error('input not handled by moment'); | |
32992 }; | |
32993 if (lifecycle && lifecycle.setup) { | |
32994 lifecycle.setup(); | |
32995 } | |
32996 }, | |
32997 teardown : function () { | |
32998 moment.locale('en'); | |
32999 if (lifecycle && lifecycle.teardown) { | |
33000 lifecycle.teardown(); | |
33001 } | |
33002 } | |
33003 }); | |
33004 } | |
33005 | |
33006 function equal(assert, a, b, message) { | |
33007 assert.ok(Math.abs(a - b) < 0.00000001, '(' + a + ' === ' + b + ') ' + message); | |
33008 } | |
33009 | |
33010 function dstForYear(year) { | |
33011 var start = moment([year]), | |
33012 end = moment([year + 1]), | |
33013 current = start.clone(), | |
33014 last; | |
33015 | |
33016 while (current < end) { | |
33017 last = current.clone(); | |
33018 current.add(24, 'hour'); | |
33019 if (last.utcOffset() !== current.utcOffset()) { | |
33020 end = current.clone(); | |
33021 current = last.clone(); | |
33022 break; | |
33023 } | |
33024 } | |
33025 | |
33026 while (current < end) { | |
33027 last = current.clone(); | |
33028 current.add(1, 'hour'); | |
33029 if (last.utcOffset() !== current.utcOffset()) { | |
33030 return { | |
33031 moment : last, | |
33032 diff : -(current.utcOffset() - last.utcOffset()) / 60 | |
33033 }; | |
33034 } | |
33035 } | |
33036 } | |
33037 | |
33038 module('diff'); | |
33039 | |
33040 test('diff', function (assert) { | |
33041 assert.equal(moment(1000).diff(0), 1000, '1 second - 0 = 1000'); | |
33042 assert.equal(moment(1000).diff(500), 500, '1 second - 0.5 seconds = 500'); | |
33043 assert.equal(moment(0).diff(1000), -1000, '0 - 1 second = -1000'); | |
33044 assert.equal(moment(new Date(1000)).diff(1000), 0, '1 second - 1 second = 0'); | |
33045 var oneHourDate = new Date(), | |
33046 nowDate = new Date(+oneHourDate); | |
33047 oneHourDate.setHours(oneHourDate.getHours() + 1); | |
33048 assert.equal(moment(oneHourDate).diff(nowDate), 60 * 60 * 1000, '1 hour from now = 3600000'); | |
33049 }); | |
33050 | |
33051 test('diff key after', function (assert) { | |
33052 assert.equal(moment([2010]).diff([2011], 'years'), -1, 'year diff'); | |
33053 assert.equal(moment([2010]).diff([2010, 2], 'months'), -2, 'month diff'); | |
33054 assert.equal(moment([2010]).diff([2010, 0, 7], 'weeks'), 0, 'week diff'); | |
33055 assert.equal(moment([2010]).diff([2010, 0, 8], 'weeks'), -1, 'week diff'); | |
33056 assert.equal(moment([2010]).diff([2010, 0, 21], 'weeks'), -2, 'week diff'); | |
33057 assert.equal(moment([2010]).diff([2010, 0, 22], 'weeks'), -3, 'week diff'); | |
33058 assert.equal(moment([2010]).diff([2010, 0, 4], 'days'), -3, 'day diff'); | |
33059 assert.equal(moment([2010]).diff([2010, 0, 1, 4], 'hours'), -4, 'hour diff'); | |
33060 assert.equal(moment([2010]).diff([2010, 0, 1, 0, 5], 'minutes'), -5, 'minute diff'); | |
33061 assert.equal(moment([2010]).diff([2010, 0, 1, 0, 0, 6], 'seconds'), -6, 'second diff'); | |
33062 }); | |
33063 | |
33064 test('diff key before', function (assert) { | |
33065 assert.equal(moment([2011]).diff([2010], 'years'), 1, 'year diff'); | |
33066 assert.equal(moment([2010, 2]).diff([2010], 'months'), 2, 'month diff'); | |
33067 assert.equal(moment([2010, 0, 4]).diff([2010], 'days'), 3, 'day diff'); | |
33068 assert.equal(moment([2010, 0, 7]).diff([2010], 'weeks'), 0, 'week diff'); | |
33069 assert.equal(moment([2010, 0, 8]).diff([2010], 'weeks'), 1, 'week diff'); | |
33070 assert.equal(moment([2010, 0, 21]).diff([2010], 'weeks'), 2, 'week diff'); | |
33071 assert.equal(moment([2010, 0, 22]).diff([2010], 'weeks'), 3, 'week diff'); | |
33072 assert.equal(moment([2010, 0, 1, 4]).diff([2010], 'hours'), 4, 'hour diff'); | |
33073 assert.equal(moment([2010, 0, 1, 0, 5]).diff([2010], 'minutes'), 5, 'minute diff'); | |
33074 assert.equal(moment([2010, 0, 1, 0, 0, 6]).diff([2010], 'seconds'), 6, 'second diff'); | |
33075 }); | |
33076 | |
33077 test('diff key before singular', function (assert) { | |
33078 assert.equal(moment([2011]).diff([2010], 'year'), 1, 'year diff singular'); | |
33079 assert.equal(moment([2010, 2]).diff([2010], 'month'), 2, 'month diff singular'); | |
33080 assert.equal(moment([2010, 0, 4]).diff([2010], 'day'), 3, 'day diff singular'); | |
33081 assert.equal(moment([2010, 0, 7]).diff([2010], 'week'), 0, 'week diff singular'); | |
33082 assert.equal(moment([2010, 0, 8]).diff([2010], 'week'), 1, 'week diff singular'); | |
33083 assert.equal(moment([2010, 0, 21]).diff([2010], 'week'), 2, 'week diff singular'); | |
33084 assert.equal(moment([2010, 0, 22]).diff([2010], 'week'), 3, 'week diff singular'); | |
33085 assert.equal(moment([2010, 0, 1, 4]).diff([2010], 'hour'), 4, 'hour diff singular'); | |
33086 assert.equal(moment([2010, 0, 1, 0, 5]).diff([2010], 'minute'), 5, 'minute diff singular'); | |
33087 assert.equal(moment([2010, 0, 1, 0, 0, 6]).diff([2010], 'second'), 6, 'second diff singular'); | |
33088 }); | |
33089 | |
33090 test('diff key before abbreviated', function (assert) { | |
33091 assert.equal(moment([2011]).diff([2010], 'y'), 1, 'year diff abbreviated'); | |
33092 assert.equal(moment([2010, 2]).diff([2010], 'M'), 2, 'month diff abbreviated'); | |
33093 assert.equal(moment([2010, 0, 4]).diff([2010], 'd'), 3, 'day diff abbreviated'); | |
33094 assert.equal(moment([2010, 0, 7]).diff([2010], 'w'), 0, 'week diff abbreviated'); | |
33095 assert.equal(moment([2010, 0, 8]).diff([2010], 'w'), 1, 'week diff abbreviated'); | |
33096 assert.equal(moment([2010, 0, 21]).diff([2010], 'w'), 2, 'week diff abbreviated'); | |
33097 assert.equal(moment([2010, 0, 22]).diff([2010], 'w'), 3, 'week diff abbreviated'); | |
33098 assert.equal(moment([2010, 0, 1, 4]).diff([2010], 'h'), 4, 'hour diff abbreviated'); | |
33099 assert.equal(moment([2010, 0, 1, 0, 5]).diff([2010], 'm'), 5, 'minute diff abbreviated'); | |
33100 assert.equal(moment([2010, 0, 1, 0, 0, 6]).diff([2010], 's'), 6, 'second diff abbreviated'); | |
33101 }); | |
33102 | |
33103 test('diff month', function (assert) { | |
33104 assert.equal(moment([2011, 0, 31]).diff([2011, 2, 1], 'months'), -1, 'month diff'); | |
33105 }); | |
33106 | |
33107 test('diff across DST', function (assert) { | |
33108 var dst = dstForYear(2012), a, b, daysInMonth; | |
33109 if (!dst) { | |
33110 assert.equal(42, 42, 'at least one assertion'); | |
33111 return; | |
33112 } | |
33113 | |
33114 a = dst.moment; | |
33115 b = a.clone().utc().add(12, 'hours').local(); | |
33116 daysInMonth = (a.daysInMonth() + b.daysInMonth()) / 2; | |
33117 assert.equal(b.diff(a, 'milliseconds', true), 12 * 60 * 60 * 1000, | |
33118 'ms diff across DST'); | |
33119 assert.equal(b.diff(a, 'seconds', true), 12 * 60 * 60, | |
33120 'second diff across DST'); | |
33121 assert.equal(b.diff(a, 'minutes', true), 12 * 60, | |
33122 'minute diff across DST'); | |
33123 assert.equal(b.diff(a, 'hours', true), 12, | |
33124 'hour diff across DST'); | |
33125 assert.equal(b.diff(a, 'days', true), (12 - dst.diff) / 24, | |
33126 'day diff across DST'); | |
33127 equal(assert, b.diff(a, 'weeks', true), (12 - dst.diff) / 24 / 7, | |
33128 'week diff across DST'); | |
33129 assert.ok(0.95 / (2 * 31) < b.diff(a, 'months', true), | |
33130 'month diff across DST, lower bound'); | |
33131 assert.ok(b.diff(a, 'month', true) < 1.05 / (2 * 28), | |
33132 'month diff across DST, upper bound'); | |
33133 assert.ok(0.95 / (2 * 31 * 12) < b.diff(a, 'years', true), | |
33134 'year diff across DST, lower bound'); | |
33135 assert.ok(b.diff(a, 'year', true) < 1.05 / (2 * 28 * 12), | |
33136 'year diff across DST, upper bound'); | |
33137 | |
33138 a = dst.moment; | |
33139 b = a.clone().utc().add(12 + dst.diff, 'hours').local(); | |
33140 daysInMonth = (a.daysInMonth() + b.daysInMonth()) / 2; | |
33141 | |
33142 assert.equal(b.diff(a, 'milliseconds', true), | |
33143 (12 + dst.diff) * 60 * 60 * 1000, | |
33144 'ms diff across DST'); | |
33145 assert.equal(b.diff(a, 'seconds', true), (12 + dst.diff) * 60 * 60, | |
33146 'second diff across DST'); | |
33147 assert.equal(b.diff(a, 'minutes', true), (12 + dst.diff) * 60, | |
33148 'minute diff across DST'); | |
33149 assert.equal(b.diff(a, 'hours', true), (12 + dst.diff), | |
33150 'hour diff across DST'); | |
33151 assert.equal(b.diff(a, 'days', true), 12 / 24, 'day diff across DST'); | |
33152 equal(assert, b.diff(a, 'weeks', true), 12 / 24 / 7, | |
33153 'week diff across DST'); | |
33154 assert.ok(0.95 / (2 * 31) < b.diff(a, 'months', true), | |
33155 'month diff across DST, lower bound'); | |
33156 assert.ok(b.diff(a, 'month', true) < 1.05 / (2 * 28), | |
33157 'month diff across DST, upper bound'); | |
33158 assert.ok(0.95 / (2 * 31 * 12) < b.diff(a, 'years', true), | |
33159 'year diff across DST, lower bound'); | |
33160 assert.ok(b.diff(a, 'year', true) < 1.05 / (2 * 28 * 12), | |
33161 'year diff across DST, upper bound'); | |
33162 }); | |
33163 | |
33164 test('diff overflow', function (assert) { | |
33165 assert.equal(moment([2011]).diff([2010], 'months'), 12, 'month diff'); | |
33166 assert.equal(moment([2010, 0, 2]).diff([2010], 'hours'), 24, 'hour diff'); | |
33167 assert.equal(moment([2010, 0, 1, 2]).diff([2010], 'minutes'), 120, 'minute diff'); | |
33168 assert.equal(moment([2010, 0, 1, 0, 4]).diff([2010], 'seconds'), 240, 'second diff'); | |
33169 }); | |
33170 | |
33171 test('diff between utc and local', function (assert) { | |
33172 if (moment([2012]).utcOffset() === moment([2011]).utcOffset()) { | |
33173 // Russia's utc offset on 1st of Jan 2012 vs 2011 is different | |
33174 assert.equal(moment([2012]).utc().diff([2011], 'years'), 1, 'year diff'); | |
33175 } | |
33176 assert.equal(moment([2010, 2, 2]).utc().diff([2010, 0, 2], 'months'), 2, 'month diff'); | |
33177 assert.equal(moment([2010, 0, 4]).utc().diff([2010], 'days'), 3, 'day diff'); | |
33178 assert.equal(moment([2010, 0, 22]).utc().diff([2010], 'weeks'), 3, 'week diff'); | |
33179 assert.equal(moment([2010, 0, 1, 4]).utc().diff([2010], 'hours'), 4, 'hour diff'); | |
33180 assert.equal(moment([2010, 0, 1, 0, 5]).utc().diff([2010], 'minutes'), 5, 'minute diff'); | |
33181 assert.equal(moment([2010, 0, 1, 0, 0, 6]).utc().diff([2010], 'seconds'), 6, 'second diff'); | |
33182 }); | |
33183 | |
33184 test('diff floored', function (assert) { | |
33185 assert.equal(moment([2010, 0, 1, 23]).diff([2010], 'day'), 0, '23 hours = 0 days'); | |
33186 assert.equal(moment([2010, 0, 1, 23, 59]).diff([2010], 'day'), 0, '23:59 hours = 0 days'); | |
33187 assert.equal(moment([2010, 0, 1, 24]).diff([2010], 'day'), 1, '24 hours = 1 day'); | |
33188 assert.equal(moment([2010, 0, 2]).diff([2011, 0, 1], 'year'), 0, 'year rounded down'); | |
33189 assert.equal(moment([2011, 0, 1]).diff([2010, 0, 2], 'year'), 0, 'year rounded down'); | |
33190 assert.equal(moment([2010, 0, 2]).diff([2011, 0, 2], 'year'), -1, 'year rounded down'); | |
33191 assert.equal(moment([2011, 0, 2]).diff([2010, 0, 2], 'year'), 1, 'year rounded down'); | |
33192 }); | |
33193 | |
33194 test('year diffs include dates', function (assert) { | |
33195 assert.ok(moment([2012, 1, 19]).diff(moment([2002, 1, 20]), 'years', true) < 10, 'year diff should include date of month'); | |
33196 }); | |
33197 | |
33198 test('month diffs', function (assert) { | |
33199 // due to floating point math errors, these tests just need to be accurate within 0.00000001 | |
33200 assert.equal(moment([2012, 0, 1]).diff([2012, 1, 1], 'months', true), -1, 'Jan 1 to Feb 1 should be 1 month'); | |
33201 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'); | |
33202 assert.equal(moment([2012, 0, 15]).diff([2012, 1, 15], 'months', true), -1, 'Jan 15 to Feb 15 should be 1 month'); | |
33203 assert.equal(moment([2012, 0, 28]).diff([2012, 1, 28], 'months', true), -1, 'Jan 28 to Feb 28 should be 1 month'); | |
33204 assert.ok(moment([2012, 0, 31]).diff([2012, 1, 29], 'months', true), -1, 'Jan 31 to Feb 29 should be 1 month'); | |
33205 assert.ok(-1 > moment([2012, 0, 31]).diff([2012, 2, 1], 'months', true), 'Jan 31 to Mar 1 should be more than 1 month'); | |
33206 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'); | |
33207 equal(assert, moment([2012, 0, 1]).diff([2012, 0, 31], 'months', true), -(30 / 31), 'Jan 1 to Jan 31 should be 30 / 31 months'); | |
33208 assert.ok(0 < moment('2014-02-01').diff(moment('2014-01-31'), 'months', true), 'jan-31 to feb-1 diff is positive'); | |
33209 }); | |
33210 | |
33211 test('exact month diffs', function (assert) { | |
33212 // generate all pairs of months and compute month diff, with fixed day | |
33213 // of month = 15. | |
33214 | |
33215 var m1, m2; | |
33216 for (m1 = 0; m1 < 12; ++m1) { | |
33217 for (m2 = m1; m2 < 12; ++m2) { | |
33218 assert.equal(moment([2013, m2, 15]).diff(moment([2013, m1, 15]), 'months', true), m2 - m1, | |
33219 'month diff from 2013-' + m1 + '-15 to 2013-' + m2 + '-15'); | |
33220 } | |
33221 } | |
33222 }); | |
33223 | |
33224 test('year diffs', function (assert) { | |
33225 // due to floating point math errors, these tests just need to be accurate within 0.00000001 | |
33226 equal(assert, moment([2012, 0, 1]).diff([2013, 0, 1], 'years', true), -1, 'Jan 1 2012 to Jan 1 2013 should be 1 year'); | |
33227 equal(assert, moment([2012, 1, 28]).diff([2013, 1, 28], 'years', true), -1, 'Feb 28 2012 to Feb 28 2013 should be 1 year'); | |
33228 equal(assert, moment([2012, 2, 1]).diff([2013, 2, 1], 'years', true), -1, 'Mar 1 2012 to Mar 1 2013 should be 1 year'); | |
33229 equal(assert, moment([2012, 11, 1]).diff([2013, 11, 1], 'years', true), -1, 'Dec 1 2012 to Dec 1 2013 should be 1 year'); | |
33230 equal(assert, moment([2012, 11, 31]).diff([2013, 11, 31], 'years', true), -1, 'Dec 31 2012 to Dec 31 2013 should be 1 year'); | |
33231 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'); | |
33232 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'); | |
33233 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'); | |
33234 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'); | |
33235 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'); | |
33236 }); | |
33237 | |
33238 })); | |
33239 | |
33240 (function (global, factory) { | |
33241 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
33242 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
33243 factory(global.moment) | |
33244 }(this, function (moment) { 'use strict'; | |
33245 | |
33246 /*global QUnit:false*/ | |
33247 | |
33248 var test = QUnit.test; | |
33249 | |
33250 function module (name, lifecycle) { | |
33251 QUnit.module(name, { | |
33252 setup : function () { | |
33253 moment.locale('en'); | |
33254 moment.createFromInputFallback = function () { | |
33255 throw new Error('input not handled by moment'); | |
33256 }; | |
33257 if (lifecycle && lifecycle.setup) { | |
33258 lifecycle.setup(); | |
33259 } | |
33260 }, | |
33261 teardown : function () { | |
33262 if (lifecycle && lifecycle.teardown) { | |
33263 lifecycle.teardown(); | |
33264 } | |
33265 } | |
33266 }); | |
33267 } | |
33268 | |
33269 function localeModule (name, lifecycle) { | |
33270 QUnit.module('locale:' + name, { | |
33271 setup : function () { | |
33272 moment.locale(name); | |
33273 moment.createFromInputFallback = function () { | |
33274 throw new Error('input not handled by moment'); | |
33275 }; | |
33276 if (lifecycle && lifecycle.setup) { | |
33277 lifecycle.setup(); | |
33278 } | |
33279 }, | |
33280 teardown : function () { | |
33281 moment.locale('en'); | |
33282 if (lifecycle && lifecycle.teardown) { | |
33283 lifecycle.teardown(); | |
33284 } | |
33285 } | |
33286 }); | |
33287 } | |
33288 | |
33289 module('duration'); | |
33290 | |
33291 test('object instantiation', function (assert) { | |
33292 var d = moment.duration({ | |
33293 years: 2, | |
33294 months: 3, | |
33295 weeks: 2, | |
33296 days: 1, | |
33297 hours: 8, | |
33298 minutes: 9, | |
33299 seconds: 20, | |
33300 milliseconds: 12 | |
33301 }); | |
33302 | |
33303 assert.equal(d.years(), 2, 'years'); | |
33304 assert.equal(d.months(), 3, 'months'); | |
33305 assert.equal(d.weeks(), 2, 'weeks'); | |
33306 assert.equal(d.days(), 15, 'days'); // two weeks + 1 day | |
33307 assert.equal(d.hours(), 8, 'hours'); | |
33308 assert.equal(d.minutes(), 9, 'minutes'); | |
33309 assert.equal(d.seconds(), 20, 'seconds'); | |
33310 assert.equal(d.milliseconds(), 12, 'milliseconds'); | |
33311 }); | |
33312 | |
33313 test('object instantiation with strings', function (assert) { | |
33314 var d = moment.duration({ | |
33315 years: '2', | |
33316 months: '3', | |
33317 weeks: '2', | |
33318 days: '1', | |
33319 hours: '8', | |
33320 minutes: '9', | |
33321 seconds: '20', | |
33322 milliseconds: '12' | |
33323 }); | |
33324 | |
33325 assert.equal(d.years(), 2, 'years'); | |
33326 assert.equal(d.months(), 3, 'months'); | |
33327 assert.equal(d.weeks(), 2, 'weeks'); | |
33328 assert.equal(d.days(), 15, 'days'); // two weeks + 1 day | |
33329 assert.equal(d.hours(), 8, 'hours'); | |
33330 assert.equal(d.minutes(), 9, 'minutes'); | |
33331 assert.equal(d.seconds(), 20, 'seconds'); | |
33332 assert.equal(d.milliseconds(), 12, 'milliseconds'); | |
33333 }); | |
33334 | |
33335 test('milliseconds instantiation', function (assert) { | |
33336 assert.equal(moment.duration(72).milliseconds(), 72, 'milliseconds'); | |
33337 }); | |
33338 | |
33339 test('undefined instantiation', function (assert) { | |
33340 assert.equal(moment.duration(undefined).milliseconds(), 0, 'milliseconds'); | |
33341 }); | |
33342 | |
33343 test('null instantiation', function (assert) { | |
33344 assert.equal(moment.duration(null).milliseconds(), 0, 'milliseconds'); | |
33345 }); | |
33346 | |
33347 test('instantiation by type', function (assert) { | |
33348 assert.equal(moment.duration(1, 'years').years(), 1, 'years'); | |
33349 assert.equal(moment.duration(1, 'y').years(), 1, 'y'); | |
33350 assert.equal(moment.duration(2, 'months').months(), 2, 'months'); | |
33351 assert.equal(moment.duration(2, 'M').months(), 2, 'M'); | |
33352 assert.equal(moment.duration(3, 'weeks').weeks(), 3, 'weeks'); | |
33353 assert.equal(moment.duration(3, 'w').weeks(), 3, 'weeks'); | |
33354 assert.equal(moment.duration(4, 'days').days(), 4, 'days'); | |
33355 assert.equal(moment.duration(4, 'd').days(), 4, 'd'); | |
33356 assert.equal(moment.duration(5, 'hours').hours(), 5, 'hours'); | |
33357 assert.equal(moment.duration(5, 'h').hours(), 5, 'h'); | |
33358 assert.equal(moment.duration(6, 'minutes').minutes(), 6, 'minutes'); | |
33359 assert.equal(moment.duration(6, 'm').minutes(), 6, 'm'); | |
33360 assert.equal(moment.duration(7, 'seconds').seconds(), 7, 'seconds'); | |
33361 assert.equal(moment.duration(7, 's').seconds(), 7, 's'); | |
33362 assert.equal(moment.duration(8, 'milliseconds').milliseconds(), 8, 'milliseconds'); | |
33363 assert.equal(moment.duration(8, 'ms').milliseconds(), 8, 'ms'); | |
33364 }); | |
33365 | |
33366 test('shortcuts', function (assert) { | |
33367 assert.equal(moment.duration({y: 1}).years(), 1, 'years = y'); | |
33368 assert.equal(moment.duration({M: 2}).months(), 2, 'months = M'); | |
33369 assert.equal(moment.duration({w: 3}).weeks(), 3, 'weeks = w'); | |
33370 assert.equal(moment.duration({d: 4}).days(), 4, 'days = d'); | |
33371 assert.equal(moment.duration({h: 5}).hours(), 5, 'hours = h'); | |
33372 assert.equal(moment.duration({m: 6}).minutes(), 6, 'minutes = m'); | |
33373 assert.equal(moment.duration({s: 7}).seconds(), 7, 'seconds = s'); | |
33374 assert.equal(moment.duration({ms: 8}).milliseconds(), 8, 'milliseconds = ms'); | |
33375 }); | |
33376 | |
33377 test('generic getter', function (assert) { | |
33378 assert.equal(moment.duration(1, 'years').get('years'), 1, 'years'); | |
33379 assert.equal(moment.duration(1, 'years').get('year'), 1, 'years = year'); | |
33380 assert.equal(moment.duration(1, 'years').get('y'), 1, 'years = y'); | |
33381 assert.equal(moment.duration(2, 'months').get('months'), 2, 'months'); | |
33382 assert.equal(moment.duration(2, 'months').get('month'), 2, 'months = month'); | |
33383 assert.equal(moment.duration(2, 'months').get('M'), 2, 'months = M'); | |
33384 assert.equal(moment.duration(3, 'weeks').get('weeks'), 3, 'weeks'); | |
33385 assert.equal(moment.duration(3, 'weeks').get('week'), 3, 'weeks = week'); | |
33386 assert.equal(moment.duration(3, 'weeks').get('w'), 3, 'weeks = w'); | |
33387 assert.equal(moment.duration(4, 'days').get('days'), 4, 'days'); | |
33388 assert.equal(moment.duration(4, 'days').get('day'), 4, 'days = day'); | |
33389 assert.equal(moment.duration(4, 'days').get('d'), 4, 'days = d'); | |
33390 assert.equal(moment.duration(5, 'hours').get('hours'), 5, 'hours'); | |
33391 assert.equal(moment.duration(5, 'hours').get('hour'), 5, 'hours = hour'); | |
33392 assert.equal(moment.duration(5, 'hours').get('h'), 5, 'hours = h'); | |
33393 assert.equal(moment.duration(6, 'minutes').get('minutes'), 6, 'minutes'); | |
33394 assert.equal(moment.duration(6, 'minutes').get('minute'), 6, 'minutes = minute'); | |
33395 assert.equal(moment.duration(6, 'minutes').get('m'), 6, 'minutes = m'); | |
33396 assert.equal(moment.duration(7, 'seconds').get('seconds'), 7, 'seconds'); | |
33397 assert.equal(moment.duration(7, 'seconds').get('second'), 7, 'seconds = second'); | |
33398 assert.equal(moment.duration(7, 'seconds').get('s'), 7, 'seconds = s'); | |
33399 assert.equal(moment.duration(8, 'milliseconds').get('milliseconds'), 8, 'milliseconds'); | |
33400 assert.equal(moment.duration(8, 'milliseconds').get('millisecond'), 8, 'milliseconds = millisecond'); | |
33401 assert.equal(moment.duration(8, 'milliseconds').get('ms'), 8, 'milliseconds = ms'); | |
33402 }); | |
33403 | |
33404 test('instantiation from another duration', function (assert) { | |
33405 var simple = moment.duration(1234), | |
33406 lengthy = moment.duration(60 * 60 * 24 * 360 * 1e3), | |
33407 complicated = moment.duration({ | |
33408 years: 2, | |
33409 months: 3, | |
33410 weeks: 4, | |
33411 days: 1, | |
33412 hours: 8, | |
33413 minutes: 9, | |
33414 seconds: 20, | |
33415 milliseconds: 12 | |
33416 }), | |
33417 modified = moment.duration(1, 'day').add(moment.duration(1, 'day')); | |
33418 | |
33419 assert.deepEqual(moment.duration(simple), simple, 'simple clones are equal'); | |
33420 assert.deepEqual(moment.duration(lengthy), lengthy, 'lengthy clones are equal'); | |
33421 assert.deepEqual(moment.duration(complicated), complicated, 'complicated clones are equal'); | |
33422 assert.deepEqual(moment.duration(modified), modified, 'cloning modified duration works'); | |
33423 }); | |
33424 | |
33425 test('instantiation from 24-hour time zero', function (assert) { | |
33426 assert.equal(moment.duration('00:00').years(), 0, '0 years'); | |
33427 assert.equal(moment.duration('00:00').days(), 0, '0 days'); | |
33428 assert.equal(moment.duration('00:00').hours(), 0, '0 hours'); | |
33429 assert.equal(moment.duration('00:00').minutes(), 0, '0 minutes'); | |
33430 assert.equal(moment.duration('00:00').seconds(), 0, '0 seconds'); | |
33431 assert.equal(moment.duration('00:00').milliseconds(), 0, '0 milliseconds'); | |
33432 }); | |
33433 | |
33434 test('instantiation from 24-hour time <24 hours', function (assert) { | |
33435 assert.equal(moment.duration('06:45').years(), 0, '0 years'); | |
33436 assert.equal(moment.duration('06:45').days(), 0, '0 days'); | |
33437 assert.equal(moment.duration('06:45').hours(), 6, '6 hours'); | |
33438 assert.equal(moment.duration('06:45').minutes(), 45, '45 minutes'); | |
33439 assert.equal(moment.duration('06:45').seconds(), 0, '0 seconds'); | |
33440 assert.equal(moment.duration('06:45').milliseconds(), 0, '0 milliseconds'); | |
33441 }); | |
33442 | |
33443 test('instantiation from 24-hour time >24 hours', function (assert) { | |
33444 assert.equal(moment.duration('26:45').years(), 0, '0 years'); | |
33445 assert.equal(moment.duration('26:45').days(), 1, '0 days'); | |
33446 assert.equal(moment.duration('26:45').hours(), 2, '2 hours'); | |
33447 assert.equal(moment.duration('26:45').minutes(), 45, '45 minutes'); | |
33448 assert.equal(moment.duration('26:45').seconds(), 0, '0 seconds'); | |
33449 assert.equal(moment.duration('26:45').milliseconds(), 0, '0 milliseconds'); | |
33450 }); | |
33451 | |
33452 test('instatiation from serialized C# TimeSpan zero', function (assert) { | |
33453 assert.equal(moment.duration('00:00:00').years(), 0, '0 years'); | |
33454 assert.equal(moment.duration('00:00:00').days(), 0, '0 days'); | |
33455 assert.equal(moment.duration('00:00:00').hours(), 0, '0 hours'); | |
33456 assert.equal(moment.duration('00:00:00').minutes(), 0, '0 minutes'); | |
33457 assert.equal(moment.duration('00:00:00').seconds(), 0, '0 seconds'); | |
33458 assert.equal(moment.duration('00:00:00').milliseconds(), 0, '0 milliseconds'); | |
33459 }); | |
33460 | |
33461 test('instatiation from serialized C# TimeSpan with days', function (assert) { | |
33462 assert.equal(moment.duration('1.02:03:04.9999999').years(), 0, '0 years'); | |
33463 assert.equal(moment.duration('1.02:03:04.9999999').days(), 1, '1 day'); | |
33464 assert.equal(moment.duration('1.02:03:04.9999999').hours(), 2, '2 hours'); | |
33465 assert.equal(moment.duration('1.02:03:04.9999999').minutes(), 3, '3 minutes'); | |
33466 assert.equal(moment.duration('1.02:03:04.9999999').seconds(), 4, '4 seconds'); | |
33467 assert.equal(moment.duration('1.02:03:04.9999999').milliseconds(), 999, '999 milliseconds'); | |
33468 }); | |
33469 | |
33470 test('instatiation from serialized C# TimeSpan without days', function (assert) { | |
33471 assert.equal(moment.duration('01:02:03.9999999').years(), 0, '0 years'); | |
33472 assert.equal(moment.duration('01:02:03.9999999').days(), 0, '0 days'); | |
33473 assert.equal(moment.duration('01:02:03.9999999').hours(), 1, '1 hour'); | |
33474 assert.equal(moment.duration('01:02:03.9999999').minutes(), 2, '2 minutes'); | |
33475 assert.equal(moment.duration('01:02:03.9999999').seconds(), 3, '3 seconds'); | |
33476 assert.equal(moment.duration('01:02:03.9999999').milliseconds(), 999, '999 milliseconds'); | |
33477 | |
33478 assert.equal(moment.duration('23:59:59.9999999').days(), 0, '0 days'); | |
33479 assert.equal(moment.duration('23:59:59.9999999').hours(), 23, '23 hours'); | |
33480 | |
33481 assert.equal(moment.duration('500:59:59.9999999').days(), 20, '500 hours overflows to 20 days'); | |
33482 assert.equal(moment.duration('500:59:59.9999999').hours(), 20, '500 hours overflows to 20 hours'); | |
33483 }); | |
33484 | |
33485 test('instatiation from serialized C# TimeSpan without days or milliseconds', function (assert) { | |
33486 assert.equal(moment.duration('01:02:03').years(), 0, '0 years'); | |
33487 assert.equal(moment.duration('01:02:03').days(), 0, '0 days'); | |
33488 assert.equal(moment.duration('01:02:03').hours(), 1, '1 hour'); | |
33489 assert.equal(moment.duration('01:02:03').minutes(), 2, '2 minutes'); | |
33490 assert.equal(moment.duration('01:02:03').seconds(), 3, '3 seconds'); | |
33491 assert.equal(moment.duration('01:02:03').milliseconds(), 0, '0 milliseconds'); | |
33492 }); | |
33493 | |
33494 test('instatiation from serialized C# TimeSpan without milliseconds', function (assert) { | |
33495 assert.equal(moment.duration('1.02:03:04').years(), 0, '0 years'); | |
33496 assert.equal(moment.duration('1.02:03:04').days(), 1, '1 day'); | |
33497 assert.equal(moment.duration('1.02:03:04').hours(), 2, '2 hours'); | |
33498 assert.equal(moment.duration('1.02:03:04').minutes(), 3, '3 minutes'); | |
33499 assert.equal(moment.duration('1.02:03:04').seconds(), 4, '4 seconds'); | |
33500 assert.equal(moment.duration('1.02:03:04').milliseconds(), 0, '0 milliseconds'); | |
33501 }); | |
33502 | |
33503 test('instatiation from serialized C# TimeSpan maxValue', function (assert) { | |
33504 var d = moment.duration('10675199.02:48:05.4775807'); | |
33505 | |
33506 assert.equal(d.years(), 29227, '29227 years'); | |
33507 assert.equal(d.months(), 8, '8 months'); | |
33508 assert.equal(d.days(), 12, '12 day'); // if you have to change this value -- just do it | |
33509 | |
33510 assert.equal(d.hours(), 2, '2 hours'); | |
33511 assert.equal(d.minutes(), 48, '48 minutes'); | |
33512 assert.equal(d.seconds(), 5, '5 seconds'); | |
33513 assert.equal(d.milliseconds(), 477, '477 milliseconds'); | |
33514 }); | |
33515 | |
33516 test('instatiation from serialized C# TimeSpan minValue', function (assert) { | |
33517 var d = moment.duration('-10675199.02:48:05.4775808'); | |
33518 | |
33519 assert.equal(d.years(), -29227, '29653 years'); | |
33520 assert.equal(d.months(), -8, '8 day'); | |
33521 assert.equal(d.days(), -12, '12 day'); // if you have to change this value -- just do it | |
33522 | |
33523 assert.equal(d.hours(), -2, '2 hours'); | |
33524 assert.equal(d.minutes(), -48, '48 minutes'); | |
33525 assert.equal(d.seconds(), -5, '5 seconds'); | |
33526 assert.equal(d.milliseconds(), -477, '477 milliseconds'); | |
33527 }); | |
33528 | |
33529 test('instantiation from ISO 8601 duration', function (assert) { | |
33530 assert.equal(moment.duration('P1Y2M3DT4H5M6S').asSeconds(), moment.duration({y: 1, M: 2, d: 3, h: 4, m: 5, s: 6}).asSeconds(), 'all fields'); | |
33531 assert.equal(moment.duration('P1M').asSeconds(), moment.duration({M: 1}).asSeconds(), 'single month field'); | |
33532 assert.equal(moment.duration('PT1M').asSeconds(), moment.duration({m: 1}).asSeconds(), 'single minute field'); | |
33533 assert.equal(moment.duration('P1MT2H').asSeconds(), moment.duration({M: 1, h: 2}).asSeconds(), 'random fields missing'); | |
33534 assert.equal(moment.duration('-P60D').asSeconds(), moment.duration({d: -60}).asSeconds(), 'negative days'); | |
33535 assert.equal(moment.duration('PT0.5S').asSeconds(), moment.duration({s: 0.5}).asSeconds(), 'fractional seconds'); | |
33536 assert.equal(moment.duration('PT0,5S').asSeconds(), moment.duration({s: 0.5}).asSeconds(), 'fractional seconds (comma)'); | |
33537 }); | |
33538 | |
33539 test('serialization to ISO 8601 duration strings', function (assert) { | |
33540 assert.equal(moment.duration({y: 1, M: 2, d: 3, h: 4, m: 5, s: 6}).toISOString(), 'P1Y2M3DT4H5M6S', 'all fields'); | |
33541 assert.equal(moment.duration({M: -1}).toISOString(), '-P1M', 'one month ago'); | |
33542 assert.equal(moment.duration({m: -1}).toISOString(), '-PT1M', 'one minute ago'); | |
33543 assert.equal(moment.duration({s: -0.5}).toISOString(), '-PT0.5S', 'one half second ago'); | |
33544 assert.equal(moment.duration({y: -0.5, M: 1}).toISOString(), '-P5M', 'a month after half a year ago'); | |
33545 assert.equal(moment.duration({}).toISOString(), 'P0D', 'zero duration'); | |
33546 assert.equal(moment.duration({M: 16, d:40, s: 86465}).toISOString(), 'P1Y4M40DT24H1M5S', 'all fields'); | |
33547 }); | |
33548 | |
33549 test('toString acts as toISOString', function (assert) { | |
33550 assert.equal(moment.duration({y: 1, M: 2, d: 3, h: 4, m: 5, s: 6}).toString(), 'P1Y2M3DT4H5M6S', 'all fields'); | |
33551 assert.equal(moment.duration({M: -1}).toString(), '-P1M', 'one month ago'); | |
33552 assert.equal(moment.duration({m: -1}).toString(), '-PT1M', 'one minute ago'); | |
33553 assert.equal(moment.duration({s: -0.5}).toString(), '-PT0.5S', 'one half second ago'); | |
33554 assert.equal(moment.duration({y: -0.5, M: 1}).toString(), '-P5M', 'a month after half a year ago'); | |
33555 assert.equal(moment.duration({}).toString(), 'P0D', 'zero duration'); | |
33556 assert.equal(moment.duration({M: 16, d:40, s: 86465}).toString(), 'P1Y4M40DT24H1M5S', 'all fields'); | |
33557 }); | |
33558 | |
33559 test('toIsoString deprecation', function (assert) { | |
33560 assert.equal(moment.duration({}).toIsoString(), moment.duration({}).toISOString(), 'toIsoString delegates to toISOString'); | |
33561 }); | |
33562 | |
33563 test('`isodate` (python) test cases', function (assert) { | |
33564 assert.equal(moment.duration('P18Y9M4DT11H9M8S').asSeconds(), moment.duration({y: 18, M: 9, d: 4, h: 11, m: 9, s: 8}).asSeconds(), 'python isodate 1'); | |
33565 assert.equal(moment.duration('P2W').asSeconds(), moment.duration({w: 2}).asSeconds(), 'python isodate 2'); | |
33566 assert.equal(moment.duration('P3Y6M4DT12H30M5S').asSeconds(), moment.duration({y: 3, M: 6, d: 4, h: 12, m: 30, s: 5}).asSeconds(), 'python isodate 3'); | |
33567 assert.equal(moment.duration('P23DT23H').asSeconds(), moment.duration({d: 23, h: 23}).asSeconds(), 'python isodate 4'); | |
33568 assert.equal(moment.duration('P4Y').asSeconds(), moment.duration({y: 4}).asSeconds(), 'python isodate 5'); | |
33569 assert.equal(moment.duration('P1M').asSeconds(), moment.duration({M: 1}).asSeconds(), 'python isodate 6'); | |
33570 assert.equal(moment.duration('PT1M').asSeconds(), moment.duration({m: 1}).asSeconds(), 'python isodate 7'); | |
33571 assert.equal(moment.duration('P0.5Y').asSeconds(), moment.duration({y: 0.5}).asSeconds(), 'python isodate 8'); | |
33572 assert.equal(moment.duration('PT36H').asSeconds(), moment.duration({h: 36}).asSeconds(), 'python isodate 9'); | |
33573 assert.equal(moment.duration('P1DT12H').asSeconds(), moment.duration({d: 1, h: 12}).asSeconds(), 'python isodate 10'); | |
33574 assert.equal(moment.duration('-P2W').asSeconds(), moment.duration({w: -2}).asSeconds(), 'python isodate 11'); | |
33575 assert.equal(moment.duration('-P2.2W').asSeconds(), moment.duration({w: -2.2}).asSeconds(), 'python isodate 12'); | |
33576 assert.equal(moment.duration('P1DT2H3M4S').asSeconds(), moment.duration({d: 1, h: 2, m: 3, s: 4}).asSeconds(), 'python isodate 13'); | |
33577 assert.equal(moment.duration('P1DT2H3M').asSeconds(), moment.duration({d: 1, h: 2, m: 3}).asSeconds(), 'python isodate 14'); | |
33578 assert.equal(moment.duration('P1DT2H').asSeconds(), moment.duration({d: 1, h: 2}).asSeconds(), 'python isodate 15'); | |
33579 assert.equal(moment.duration('PT2H').asSeconds(), moment.duration({h: 2}).asSeconds(), 'python isodate 16'); | |
33580 assert.equal(moment.duration('PT2.3H').asSeconds(), moment.duration({h: 2.3}).asSeconds(), 'python isodate 17'); | |
33581 assert.equal(moment.duration('PT2H3M4S').asSeconds(), moment.duration({h: 2, m: 3, s: 4}).asSeconds(), 'python isodate 18'); | |
33582 assert.equal(moment.duration('PT3M4S').asSeconds(), moment.duration({m: 3, s: 4}).asSeconds(), 'python isodate 19'); | |
33583 assert.equal(moment.duration('PT22S').asSeconds(), moment.duration({s: 22}).asSeconds(), 'python isodate 20'); | |
33584 assert.equal(moment.duration('PT22.22S').asSeconds(), moment.duration({s: 22.22}).asSeconds(), 'python isodate 21'); | |
33585 assert.equal(moment.duration('-P2Y').asSeconds(), moment.duration({y: -2}).asSeconds(), 'python isodate 22'); | |
33586 assert.equal(moment.duration('-P3Y6M4DT12H30M5S').asSeconds(), moment.duration({y: -3, M: -6, d: -4, h: -12, m: -30, s: -5}).asSeconds(), 'python isodate 23'); | |
33587 assert.equal(moment.duration('-P1DT2H3M4S').asSeconds(), moment.duration({d: -1, h: -2, m: -3, s: -4}).asSeconds(), 'python isodate 24'); | |
33588 }); | |
33589 | |
33590 test('ISO 8601 misuse cases', function (assert) { | |
33591 assert.equal(moment.duration('P').asSeconds(), 0, 'lonely P'); | |
33592 assert.equal(moment.duration('PT').asSeconds(), 0, 'just P and T'); | |
33593 assert.equal(moment.duration('P1H').asSeconds(), 0, 'missing T'); | |
33594 assert.equal(moment.duration('P1D1Y').asSeconds(), 0, 'out of order'); | |
33595 assert.equal(moment.duration('PT.5S').asSeconds(), 0.5, 'accept no leading zero for decimal'); | |
33596 assert.equal(moment.duration('PT1,S').asSeconds(), 1, 'accept trailing decimal separator'); | |
33597 assert.equal(moment.duration('PT1M0,,5S').asSeconds(), 60, 'extra decimal separators are ignored as 0'); | |
33598 assert.equal(moment.duration('P-1DS').asSeconds(), 0, 'wrong position of negative'); | |
33599 }); | |
33600 | |
33601 test('humanize', function (assert) { | |
33602 moment.locale('en'); | |
33603 assert.equal(moment.duration({seconds: 44}).humanize(), 'a few seconds', '44 seconds = a few seconds'); | |
33604 assert.equal(moment.duration({seconds: 45}).humanize(), 'a minute', '45 seconds = a minute'); | |
33605 assert.equal(moment.duration({seconds: 89}).humanize(), 'a minute', '89 seconds = a minute'); | |
33606 assert.equal(moment.duration({seconds: 90}).humanize(), '2 minutes', '90 seconds = 2 minutes'); | |
33607 assert.equal(moment.duration({minutes: 44}).humanize(), '44 minutes', '44 minutes = 44 minutes'); | |
33608 assert.equal(moment.duration({minutes: 45}).humanize(), 'an hour', '45 minutes = an hour'); | |
33609 assert.equal(moment.duration({minutes: 89}).humanize(), 'an hour', '89 minutes = an hour'); | |
33610 assert.equal(moment.duration({minutes: 90}).humanize(), '2 hours', '90 minutes = 2 hours'); | |
33611 assert.equal(moment.duration({hours: 5}).humanize(), '5 hours', '5 hours = 5 hours'); | |
33612 assert.equal(moment.duration({hours: 21}).humanize(), '21 hours', '21 hours = 21 hours'); | |
33613 assert.equal(moment.duration({hours: 22}).humanize(), 'a day', '22 hours = a day'); | |
33614 assert.equal(moment.duration({hours: 35}).humanize(), 'a day', '35 hours = a day'); | |
33615 assert.equal(moment.duration({hours: 36}).humanize(), '2 days', '36 hours = 2 days'); | |
33616 assert.equal(moment.duration({days: 1}).humanize(), 'a day', '1 day = a day'); | |
33617 assert.equal(moment.duration({days: 5}).humanize(), '5 days', '5 days = 5 days'); | |
33618 assert.equal(moment.duration({weeks: 1}).humanize(), '7 days', '1 week = 7 days'); | |
33619 assert.equal(moment.duration({days: 25}).humanize(), '25 days', '25 days = 25 days'); | |
33620 assert.equal(moment.duration({days: 26}).humanize(), 'a month', '26 days = a month'); | |
33621 assert.equal(moment.duration({days: 30}).humanize(), 'a month', '30 days = a month'); | |
33622 assert.equal(moment.duration({days: 45}).humanize(), 'a month', '45 days = a month'); | |
33623 assert.equal(moment.duration({days: 46}).humanize(), '2 months', '46 days = 2 months'); | |
33624 assert.equal(moment.duration({days: 74}).humanize(), '2 months', '74 days = 2 months'); | |
33625 assert.equal(moment.duration({days: 77}).humanize(), '3 months', '77 days = 3 months'); | |
33626 assert.equal(moment.duration({months: 1}).humanize(), 'a month', '1 month = a month'); | |
33627 assert.equal(moment.duration({months: 5}).humanize(), '5 months', '5 months = 5 months'); | |
33628 assert.equal(moment.duration({days: 344}).humanize(), 'a year', '344 days = a year'); | |
33629 assert.equal(moment.duration({days: 345}).humanize(), 'a year', '345 days = a year'); | |
33630 assert.equal(moment.duration({days: 547}).humanize(), 'a year', '547 days = a year'); | |
33631 assert.equal(moment.duration({days: 548}).humanize(), '2 years', '548 days = 2 years'); | |
33632 assert.equal(moment.duration({years: 1}).humanize(), 'a year', '1 year = a year'); | |
33633 assert.equal(moment.duration({years: 5}).humanize(), '5 years', '5 years = 5 years'); | |
33634 assert.equal(moment.duration(7200000).humanize(), '2 hours', '7200000 = 2 minutes'); | |
33635 }); | |
33636 | |
33637 test('humanize duration with suffix', function (assert) { | |
33638 moment.locale('en'); | |
33639 assert.equal(moment.duration({seconds: 44}).humanize(true), 'in a few seconds', '44 seconds = a few seconds'); | |
33640 assert.equal(moment.duration({seconds: -44}).humanize(true), 'a few seconds ago', '44 seconds = a few seconds'); | |
33641 }); | |
33642 | |
33643 test('bubble value up', function (assert) { | |
33644 assert.equal(moment.duration({milliseconds: 61001}).milliseconds(), 1, '61001 milliseconds has 1 millisecond left over'); | |
33645 assert.equal(moment.duration({milliseconds: 61001}).seconds(), 1, '61001 milliseconds has 1 second left over'); | |
33646 assert.equal(moment.duration({milliseconds: 61001}).minutes(), 1, '61001 milliseconds has 1 minute left over'); | |
33647 | |
33648 assert.equal(moment.duration({minutes: 350}).minutes(), 50, '350 minutes has 50 minutes left over'); | |
33649 assert.equal(moment.duration({minutes: 350}).hours(), 5, '350 minutes has 5 hours left over'); | |
33650 }); | |
33651 | |
33652 test('clipping', function (assert) { | |
33653 assert.equal(moment.duration({months: 11}).months(), 11, '11 months is 11 months'); | |
33654 assert.equal(moment.duration({months: 11}).years(), 0, '11 months makes no year'); | |
33655 assert.equal(moment.duration({months: 12}).months(), 0, '12 months is 0 months left over'); | |
33656 assert.equal(moment.duration({months: 12}).years(), 1, '12 months makes 1 year'); | |
33657 assert.equal(moment.duration({months: 13}).months(), 1, '13 months is 1 month left over'); | |
33658 assert.equal(moment.duration({months: 13}).years(), 1, '13 months makes 1 year'); | |
33659 | |
33660 assert.equal(moment.duration({days: 30}).days(), 30, '30 days is 30 days'); | |
33661 assert.equal(moment.duration({days: 30}).months(), 0, '30 days makes no month'); | |
33662 assert.equal(moment.duration({days: 31}).days(), 0, '31 days is 0 days left over'); | |
33663 assert.equal(moment.duration({days: 31}).months(), 1, '31 days is a month'); | |
33664 assert.equal(moment.duration({days: 32}).days(), 1, '32 days is 1 day left over'); | |
33665 assert.equal(moment.duration({days: 32}).months(), 1, '32 days is a month'); | |
33666 | |
33667 assert.equal(moment.duration({hours: 23}).hours(), 23, '23 hours is 23 hours'); | |
33668 assert.equal(moment.duration({hours: 23}).days(), 0, '23 hours makes no day'); | |
33669 assert.equal(moment.duration({hours: 24}).hours(), 0, '24 hours is 0 hours left over'); | |
33670 assert.equal(moment.duration({hours: 24}).days(), 1, '24 hours makes 1 day'); | |
33671 assert.equal(moment.duration({hours: 25}).hours(), 1, '25 hours is 1 hour left over'); | |
33672 assert.equal(moment.duration({hours: 25}).days(), 1, '25 hours makes 1 day'); | |
33673 }); | |
33674 | |
33675 test('bubbling consistency', function (assert) { | |
33676 var days = 0, months = 0, newDays, newMonths, totalDays, d; | |
33677 for (totalDays = 1; totalDays <= 500; ++totalDays) { | |
33678 d = moment.duration(totalDays, 'days'); | |
33679 newDays = d.days(); | |
33680 newMonths = d.months() + d.years() * 12; | |
33681 assert.ok( | |
33682 (months === newMonths && days + 1 === newDays) || | |
33683 (months + 1 === newMonths && newDays === 0), | |
33684 'consistent total days ' + totalDays + | |
33685 ' was ' + months + ' ' + days + | |
33686 ' now ' + newMonths + ' ' + newDays); | |
33687 days = newDays; | |
33688 months = newMonths; | |
33689 } | |
33690 }); | |
33691 | |
33692 test('effective equivalency', function (assert) { | |
33693 assert.deepEqual(moment.duration({seconds: 1})._data, moment.duration({milliseconds: 1000})._data, '1 second is the same as 1000 milliseconds'); | |
33694 assert.deepEqual(moment.duration({seconds: 60})._data, moment.duration({minutes: 1})._data, '1 minute is the same as 60 seconds'); | |
33695 assert.deepEqual(moment.duration({minutes: 60})._data, moment.duration({hours: 1})._data, '1 hour is the same as 60 minutes'); | |
33696 assert.deepEqual(moment.duration({hours: 24})._data, moment.duration({days: 1})._data, '1 day is the same as 24 hours'); | |
33697 assert.deepEqual(moment.duration({days: 7})._data, moment.duration({weeks: 1})._data, '1 week is the same as 7 days'); | |
33698 assert.deepEqual(moment.duration({days: 31})._data, moment.duration({months: 1})._data, '1 month is the same as 30 days'); | |
33699 assert.deepEqual(moment.duration({months: 12})._data, moment.duration({years: 1})._data, '1 years is the same as 12 months'); | |
33700 }); | |
33701 | |
33702 test('asGetters', function (assert) { | |
33703 // 400 years have exactly 146097 days | |
33704 | |
33705 // years | |
33706 assert.equal(moment.duration(1, 'year').asYears(), 1, '1 year as years'); | |
33707 assert.equal(moment.duration(1, 'year').asMonths(), 12, '1 year as months'); | |
33708 assert.equal(moment.duration(400, 'year').asMonths(), 4800, '400 years as months'); | |
33709 assert.equal(moment.duration(1, 'year').asWeeks().toFixed(3), 52.143, '1 year as weeks'); | |
33710 assert.equal(moment.duration(1, 'year').asDays(), 365, '1 year as days'); | |
33711 assert.equal(moment.duration(2, 'year').asDays(), 730, '2 years as days'); | |
33712 assert.equal(moment.duration(3, 'year').asDays(), 1096, '3 years as days'); | |
33713 assert.equal(moment.duration(4, 'year').asDays(), 1461, '4 years as days'); | |
33714 assert.equal(moment.duration(400, 'year').asDays(), 146097, '400 years as days'); | |
33715 assert.equal(moment.duration(1, 'year').asHours(), 8760, '1 year as hours'); | |
33716 assert.equal(moment.duration(1, 'year').asMinutes(), 525600, '1 year as minutes'); | |
33717 assert.equal(moment.duration(1, 'year').asSeconds(), 31536000, '1 year as seconds'); | |
33718 assert.equal(moment.duration(1, 'year').asMilliseconds(), 31536000000, '1 year as milliseconds'); | |
33719 | |
33720 // months | |
33721 assert.equal(moment.duration(1, 'month').asYears().toFixed(4), 0.0833, '1 month as years'); | |
33722 assert.equal(moment.duration(1, 'month').asMonths(), 1, '1 month as months'); | |
33723 assert.equal(moment.duration(1, 'month').asWeeks().toFixed(3), 4.286, '1 month as weeks'); | |
33724 assert.equal(moment.duration(1, 'month').asDays(), 30, '1 month as days'); | |
33725 assert.equal(moment.duration(2, 'month').asDays(), 61, '2 months as days'); | |
33726 assert.equal(moment.duration(3, 'month').asDays(), 91, '3 months as days'); | |
33727 assert.equal(moment.duration(4, 'month').asDays(), 122, '4 months as days'); | |
33728 assert.equal(moment.duration(5, 'month').asDays(), 152, '5 months as days'); | |
33729 assert.equal(moment.duration(6, 'month').asDays(), 183, '6 months as days'); | |
33730 assert.equal(moment.duration(7, 'month').asDays(), 213, '7 months as days'); | |
33731 assert.equal(moment.duration(8, 'month').asDays(), 243, '8 months as days'); | |
33732 assert.equal(moment.duration(9, 'month').asDays(), 274, '9 months as days'); | |
33733 assert.equal(moment.duration(10, 'month').asDays(), 304, '10 months as days'); | |
33734 assert.equal(moment.duration(11, 'month').asDays(), 335, '11 months as days'); | |
33735 assert.equal(moment.duration(12, 'month').asDays(), 365, '12 months as days'); | |
33736 assert.equal(moment.duration(24, 'month').asDays(), 730, '24 months as days'); | |
33737 assert.equal(moment.duration(36, 'month').asDays(), 1096, '36 months as days'); | |
33738 assert.equal(moment.duration(48, 'month').asDays(), 1461, '48 months as days'); | |
33739 assert.equal(moment.duration(4800, 'month').asDays(), 146097, '4800 months as days'); | |
33740 assert.equal(moment.duration(1, 'month').asHours(), 720, '1 month as hours'); | |
33741 assert.equal(moment.duration(1, 'month').asMinutes(), 43200, '1 month as minutes'); | |
33742 assert.equal(moment.duration(1, 'month').asSeconds(), 2592000, '1 month as seconds'); | |
33743 assert.equal(moment.duration(1, 'month').asMilliseconds(), 2592000000, '1 month as milliseconds'); | |
33744 | |
33745 // weeks | |
33746 assert.equal(moment.duration(1, 'week').asYears().toFixed(4), 0.0192, '1 week as years'); | |
33747 assert.equal(moment.duration(1, 'week').asMonths().toFixed(3), 0.230, '1 week as months'); | |
33748 assert.equal(moment.duration(1, 'week').asWeeks(), 1, '1 week as weeks'); | |
33749 assert.equal(moment.duration(1, 'week').asDays(), 7, '1 week as days'); | |
33750 assert.equal(moment.duration(1, 'week').asHours(), 168, '1 week as hours'); | |
33751 assert.equal(moment.duration(1, 'week').asMinutes(), 10080, '1 week as minutes'); | |
33752 assert.equal(moment.duration(1, 'week').asSeconds(), 604800, '1 week as seconds'); | |
33753 assert.equal(moment.duration(1, 'week').asMilliseconds(), 604800000, '1 week as milliseconds'); | |
33754 | |
33755 // days | |
33756 assert.equal(moment.duration(1, 'day').asYears().toFixed(4), 0.0027, '1 day as years'); | |
33757 assert.equal(moment.duration(1, 'day').asMonths().toFixed(3), 0.033, '1 day as months'); | |
33758 assert.equal(moment.duration(1, 'day').asWeeks().toFixed(3), 0.143, '1 day as weeks'); | |
33759 assert.equal(moment.duration(1, 'day').asDays(), 1, '1 day as days'); | |
33760 assert.equal(moment.duration(1, 'day').asHours(), 24, '1 day as hours'); | |
33761 assert.equal(moment.duration(1, 'day').asMinutes(), 1440, '1 day as minutes'); | |
33762 assert.equal(moment.duration(1, 'day').asSeconds(), 86400, '1 day as seconds'); | |
33763 assert.equal(moment.duration(1, 'day').asMilliseconds(), 86400000, '1 day as milliseconds'); | |
33764 | |
33765 // hours | |
33766 assert.equal(moment.duration(1, 'hour').asYears().toFixed(6), 0.000114, '1 hour as years'); | |
33767 assert.equal(moment.duration(1, 'hour').asMonths().toFixed(5), 0.00137, '1 hour as months'); | |
33768 assert.equal(moment.duration(1, 'hour').asWeeks().toFixed(5), 0.00595, '1 hour as weeks'); | |
33769 assert.equal(moment.duration(1, 'hour').asDays().toFixed(4), 0.0417, '1 hour as days'); | |
33770 assert.equal(moment.duration(1, 'hour').asHours(), 1, '1 hour as hours'); | |
33771 assert.equal(moment.duration(1, 'hour').asMinutes(), 60, '1 hour as minutes'); | |
33772 assert.equal(moment.duration(1, 'hour').asSeconds(), 3600, '1 hour as seconds'); | |
33773 assert.equal(moment.duration(1, 'hour').asMilliseconds(), 3600000, '1 hour as milliseconds'); | |
33774 | |
33775 // minutes | |
33776 assert.equal(moment.duration(1, 'minute').asYears().toFixed(8), 0.00000190, '1 minute as years'); | |
33777 assert.equal(moment.duration(1, 'minute').asMonths().toFixed(7), 0.0000228, '1 minute as months'); | |
33778 assert.equal(moment.duration(1, 'minute').asWeeks().toFixed(7), 0.0000992, '1 minute as weeks'); | |
33779 assert.equal(moment.duration(1, 'minute').asDays().toFixed(6), 0.000694, '1 minute as days'); | |
33780 assert.equal(moment.duration(1, 'minute').asHours().toFixed(4), 0.0167, '1 minute as hours'); | |
33781 assert.equal(moment.duration(1, 'minute').asMinutes(), 1, '1 minute as minutes'); | |
33782 assert.equal(moment.duration(1, 'minute').asSeconds(), 60, '1 minute as seconds'); | |
33783 assert.equal(moment.duration(1, 'minute').asMilliseconds(), 60000, '1 minute as milliseconds'); | |
33784 | |
33785 // seconds | |
33786 assert.equal(moment.duration(1, 'second').asYears().toFixed(10), 0.0000000317, '1 second as years'); | |
33787 assert.equal(moment.duration(1, 'second').asMonths().toFixed(9), 0.000000380, '1 second as months'); | |
33788 assert.equal(moment.duration(1, 'second').asWeeks().toFixed(8), 0.00000165, '1 second as weeks'); | |
33789 assert.equal(moment.duration(1, 'second').asDays().toFixed(7), 0.0000116, '1 second as days'); | |
33790 assert.equal(moment.duration(1, 'second').asHours().toFixed(6), 0.000278, '1 second as hours'); | |
33791 assert.equal(moment.duration(1, 'second').asMinutes().toFixed(4), 0.0167, '1 second as minutes'); | |
33792 assert.equal(moment.duration(1, 'second').asSeconds(), 1, '1 second as seconds'); | |
33793 assert.equal(moment.duration(1, 'second').asMilliseconds(), 1000, '1 second as milliseconds'); | |
33794 | |
33795 // milliseconds | |
33796 assert.equal(moment.duration(1, 'millisecond').asYears().toFixed(13), 0.0000000000317, '1 millisecond as years'); | |
33797 assert.equal(moment.duration(1, 'millisecond').asMonths().toFixed(12), 0.000000000380, '1 millisecond as months'); | |
33798 assert.equal(moment.duration(1, 'millisecond').asWeeks().toFixed(11), 0.00000000165, '1 millisecond as weeks'); | |
33799 assert.equal(moment.duration(1, 'millisecond').asDays().toFixed(10), 0.0000000116, '1 millisecond as days'); | |
33800 assert.equal(moment.duration(1, 'millisecond').asHours().toFixed(9), 0.000000278, '1 millisecond as hours'); | |
33801 assert.equal(moment.duration(1, 'millisecond').asMinutes().toFixed(7), 0.0000167, '1 millisecond as minutes'); | |
33802 assert.equal(moment.duration(1, 'millisecond').asSeconds(), 0.001, '1 millisecond as seconds'); | |
33803 assert.equal(moment.duration(1, 'millisecond').asMilliseconds(), 1, '1 millisecond as milliseconds'); | |
33804 }); | |
33805 | |
33806 test('as getters for small units', function (assert) { | |
33807 var dS = moment.duration(1, 'milliseconds'), | |
33808 ds = moment.duration(3, 'seconds'), | |
33809 dm = moment.duration(13, 'minutes'); | |
33810 | |
33811 // Tests for issue #1867. | |
33812 // Floating point errors for small duration units were introduced in version 2.8.0. | |
33813 assert.equal(dS.as('milliseconds'), 1, 'as("milliseconds")'); | |
33814 assert.equal(dS.asMilliseconds(), 1, 'asMilliseconds()'); | |
33815 assert.equal(ds.as('seconds'), 3, 'as("seconds")'); | |
33816 assert.equal(ds.asSeconds(), 3, 'asSeconds()'); | |
33817 assert.equal(dm.as('minutes'), 13, 'as("minutes")'); | |
33818 assert.equal(dm.asMinutes(), 13, 'asMinutes()'); | |
33819 }); | |
33820 | |
33821 test('isDuration', function (assert) { | |
33822 assert.ok(moment.isDuration(moment.duration(12345678)), 'correctly says true'); | |
33823 assert.ok(!moment.isDuration(moment()), 'moment object is not a duration'); | |
33824 assert.ok(!moment.isDuration({milliseconds: 1}), 'plain object is not a duration'); | |
33825 }); | |
33826 | |
33827 test('add', function (assert) { | |
33828 var d = moment.duration({months: 4, weeks: 3, days: 2}); | |
33829 // for some reason, d._data._months does not get updated; use d._months instead. | |
33830 assert.equal(d.add(1, 'month')._months, 5, 'Add months'); | |
33831 assert.equal(d.add(5, 'days')._days, 28, 'Add days'); | |
33832 assert.equal(d.add(10000)._milliseconds, 10000, 'Add milliseconds'); | |
33833 assert.equal(d.add({h: 23, m: 59})._milliseconds, 23 * 60 * 60 * 1000 + 59 * 60 * 1000 + 10000, 'Add hour:minute'); | |
33834 }); | |
33835 | |
33836 test('add and bubble', function (assert) { | |
33837 var d; | |
33838 | |
33839 assert.equal(moment.duration(1, 'second').add(1000, 'milliseconds').seconds(), 2, 'Adding milliseconds should bubble up to seconds'); | |
33840 assert.equal(moment.duration(1, 'minute').add(60, 'second').minutes(), 2, 'Adding seconds should bubble up to minutes'); | |
33841 assert.equal(moment.duration(1, 'hour').add(60, 'minutes').hours(), 2, 'Adding minutes should bubble up to hours'); | |
33842 assert.equal(moment.duration(1, 'day').add(24, 'hours').days(), 2, 'Adding hours should bubble up to days'); | |
33843 | |
33844 d = moment.duration(-1, 'day').add(1, 'hour'); | |
33845 assert.equal(d.hours(), -23, '-1 day + 1 hour == -23 hour (component)'); | |
33846 assert.equal(d.asHours(), -23, '-1 day + 1 hour == -23 hours'); | |
33847 | |
33848 d = moment.duration(-1, 'year').add(1, 'day'); | |
33849 assert.equal(d.days(), -30, '- 1 year + 1 day == -30 days (component)'); | |
33850 assert.equal(d.months(), -11, '- 1 year + 1 day == -11 months (component)'); | |
33851 assert.equal(d.years(), 0, '- 1 year + 1 day == 0 years (component)'); | |
33852 assert.equal(d.asDays(), -364, '- 1 year + 1 day == -364 days'); | |
33853 | |
33854 d = moment.duration(-1, 'year').add(1, 'hour'); | |
33855 assert.equal(d.hours(), -23, '- 1 year + 1 hour == -23 hours (component)'); | |
33856 assert.equal(d.days(), -30, '- 1 year + 1 hour == -30 days (component)'); | |
33857 assert.equal(d.months(), -11, '- 1 year + 1 hour == -11 months (component)'); | |
33858 assert.equal(d.years(), 0, '- 1 year + 1 hour == 0 years (component)'); | |
33859 }); | |
33860 | |
33861 test('subtract and bubble', function (assert) { | |
33862 var d; | |
33863 | |
33864 assert.equal(moment.duration(2, 'second').subtract(1000, 'milliseconds').seconds(), 1, 'Subtracting milliseconds should bubble up to seconds'); | |
33865 assert.equal(moment.duration(2, 'minute').subtract(60, 'second').minutes(), 1, 'Subtracting seconds should bubble up to minutes'); | |
33866 assert.equal(moment.duration(2, 'hour').subtract(60, 'minutes').hours(), 1, 'Subtracting minutes should bubble up to hours'); | |
33867 assert.equal(moment.duration(2, 'day').subtract(24, 'hours').days(), 1, 'Subtracting hours should bubble up to days'); | |
33868 | |
33869 d = moment.duration(1, 'day').subtract(1, 'hour'); | |
33870 assert.equal(d.hours(), 23, '1 day - 1 hour == 23 hour (component)'); | |
33871 assert.equal(d.asHours(), 23, '1 day - 1 hour == 23 hours'); | |
33872 | |
33873 d = moment.duration(1, 'year').subtract(1, 'day'); | |
33874 assert.equal(d.days(), 30, '1 year - 1 day == 30 days (component)'); | |
33875 assert.equal(d.months(), 11, '1 year - 1 day == 11 months (component)'); | |
33876 assert.equal(d.years(), 0, '1 year - 1 day == 0 years (component)'); | |
33877 assert.equal(d.asDays(), 364, '1 year - 1 day == 364 days'); | |
33878 | |
33879 d = moment.duration(1, 'year').subtract(1, 'hour'); | |
33880 assert.equal(d.hours(), 23, '1 year - 1 hour == 23 hours (component)'); | |
33881 assert.equal(d.days(), 30, '1 year - 1 hour == 30 days (component)'); | |
33882 assert.equal(d.months(), 11, '1 year - 1 hour == 11 months (component)'); | |
33883 assert.equal(d.years(), 0, '1 year - 1 hour == 0 years (component)'); | |
33884 }); | |
33885 | |
33886 test('subtract', function (assert) { | |
33887 var d = moment.duration({months: 2, weeks: 2, days: 0, hours: 5}); | |
33888 // for some reason, d._data._months does not get updated; use d._months instead. | |
33889 assert.equal(d.subtract(1, 'months')._months, 1, 'Subtract months'); | |
33890 assert.equal(d.subtract(14, 'days')._days, 0, 'Subtract days'); | |
33891 assert.equal(d.subtract(10000)._milliseconds, 5 * 60 * 60 * 1000 - 10000, 'Subtract milliseconds'); | |
33892 assert.equal(d.subtract({h: 1, m: 59})._milliseconds, 3 * 60 * 60 * 1000 + 1 * 60 * 1000 - 10000, 'Subtract hour:minute'); | |
33893 }); | |
33894 | |
33895 test('JSON.stringify duration', function (assert) { | |
33896 var d = moment.duration(1024, 'h'); | |
33897 | |
33898 assert.equal(JSON.stringify(d), '"' + d.toISOString() + '"', 'JSON.stringify on duration should return ISO string'); | |
33899 }); | |
33900 | |
33901 test('duration plugins', function (assert) { | |
33902 var durationObject = moment.duration(); | |
33903 moment.duration.fn.foo = function (arg) { | |
33904 assert.equal(this, durationObject); | |
33905 assert.equal(arg, 5); | |
33906 }; | |
33907 durationObject.foo(5); | |
33908 }); | |
33909 | |
33910 })); | |
33911 | |
33912 (function (global, factory) { | |
33913 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
33914 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
33915 factory(global.moment) | |
33916 }(this, function (moment) { 'use strict'; | |
33917 | |
33918 /*global QUnit:false*/ | |
33919 | |
33920 var test = QUnit.test; | |
33921 | |
33922 function module (name, lifecycle) { | |
33923 QUnit.module(name, { | |
33924 setup : function () { | |
33925 moment.locale('en'); | |
33926 moment.createFromInputFallback = function () { | |
33927 throw new Error('input not handled by moment'); | |
33928 }; | |
33929 if (lifecycle && lifecycle.setup) { | |
33930 lifecycle.setup(); | |
33931 } | |
33932 }, | |
33933 teardown : function () { | |
33934 if (lifecycle && lifecycle.teardown) { | |
33935 lifecycle.teardown(); | |
33936 } | |
33937 } | |
33938 }); | |
33939 } | |
33940 | |
33941 function localeModule (name, lifecycle) { | |
33942 QUnit.module('locale:' + name, { | |
33943 setup : function () { | |
33944 moment.locale(name); | |
33945 moment.createFromInputFallback = function () { | |
33946 throw new Error('input not handled by moment'); | |
33947 }; | |
33948 if (lifecycle && lifecycle.setup) { | |
33949 lifecycle.setup(); | |
33950 } | |
33951 }, | |
33952 teardown : function () { | |
33953 moment.locale('en'); | |
33954 if (lifecycle && lifecycle.teardown) { | |
33955 lifecycle.teardown(); | |
33956 } | |
33957 } | |
33958 }); | |
33959 } | |
33960 | |
33961 module('duration from moments'); | |
33962 | |
33963 test('pure year diff', function (assert) { | |
33964 var m1 = moment('2012-01-01T00:00:00.000Z'), | |
33965 m2 = moment('2013-01-01T00:00:00.000Z'); | |
33966 | |
33967 assert.equal(moment.duration({from: m1, to: m2}).as('years'), 1, 'year moment difference'); | |
33968 assert.equal(moment.duration({from: m2, to: m1}).as('years'), -1, 'negative year moment difference'); | |
33969 }); | |
33970 | |
33971 test('month and day diff', function (assert) { | |
33972 var m1 = moment('2012-01-15T00:00:00.000Z'), | |
33973 m2 = moment('2012-02-17T00:00:00.000Z'), | |
33974 d = moment.duration({from: m1, to: m2}); | |
33975 | |
33976 assert.equal(d.get('days'), 2); | |
33977 assert.equal(d.get('months'), 1); | |
33978 }); | |
33979 | |
33980 test('day diff, separate months', function (assert) { | |
33981 var m1 = moment('2012-01-15T00:00:00.000Z'), | |
33982 m2 = moment('2012-02-13T00:00:00.000Z'), | |
33983 d = moment.duration({from: m1, to: m2}); | |
33984 | |
33985 assert.equal(d.as('days'), 29); | |
33986 }); | |
33987 | |
33988 test('hour diff', function (assert) { | |
33989 var m1 = moment('2012-01-15T17:00:00.000Z'), | |
33990 m2 = moment('2012-01-16T03:00:00.000Z'), | |
33991 d = moment.duration({from: m1, to: m2}); | |
33992 | |
33993 assert.equal(d.as('hours'), 10); | |
33994 }); | |
33995 | |
33996 test('minute diff', function (assert) { | |
33997 var m1 = moment('2012-01-15T17:45:00.000Z'), | |
33998 m2 = moment('2012-01-16T03:15:00.000Z'), | |
33999 d = moment.duration({from: m1, to: m2}); | |
34000 | |
34001 assert.equal(d.as('hours'), 9.5); | |
34002 }); | |
34003 | |
34004 })); | |
34005 | |
34006 (function (global, factory) { | |
34007 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
34008 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
34009 factory(global.moment) | |
34010 }(this, function (moment) { 'use strict'; | |
34011 | |
34012 /*global QUnit:false*/ | |
34013 | |
34014 var test = QUnit.test; | |
34015 | |
34016 function module (name, lifecycle) { | |
34017 QUnit.module(name, { | |
34018 setup : function () { | |
34019 moment.locale('en'); | |
34020 moment.createFromInputFallback = function () { | |
34021 throw new Error('input not handled by moment'); | |
34022 }; | |
34023 if (lifecycle && lifecycle.setup) { | |
34024 lifecycle.setup(); | |
34025 } | |
34026 }, | |
34027 teardown : function () { | |
34028 if (lifecycle && lifecycle.teardown) { | |
34029 lifecycle.teardown(); | |
34030 } | |
34031 } | |
34032 }); | |
34033 } | |
34034 | |
34035 function localeModule (name, lifecycle) { | |
34036 QUnit.module('locale:' + name, { | |
34037 setup : function () { | |
34038 moment.locale(name); | |
34039 moment.createFromInputFallback = function () { | |
34040 throw new Error('input not handled by moment'); | |
34041 }; | |
34042 if (lifecycle && lifecycle.setup) { | |
34043 lifecycle.setup(); | |
34044 } | |
34045 }, | |
34046 teardown : function () { | |
34047 moment.locale('en'); | |
34048 if (lifecycle && lifecycle.teardown) { | |
34049 lifecycle.teardown(); | |
34050 } | |
34051 } | |
34052 }); | |
34053 } | |
34054 | |
34055 module('format'); | |
34056 | |
34057 test('format YY', function (assert) { | |
34058 var b = moment(new Date(2009, 1, 14, 15, 25, 50, 125)); | |
34059 assert.equal(b.format('YY'), '09', 'YY ---> 09'); | |
34060 }); | |
34061 | |
34062 test('format escape brackets', function (assert) { | |
34063 moment.locale('en'); | |
34064 | |
34065 var b = moment(new Date(2009, 1, 14, 15, 25, 50, 125)); | |
34066 assert.equal(b.format('[day]'), 'day', 'Single bracket'); | |
34067 assert.equal(b.format('[day] YY [YY]'), 'day 09 YY', 'Double bracket'); | |
34068 assert.equal(b.format('[YY'), '[09', 'Un-ended bracket'); | |
34069 assert.equal(b.format('[[YY]]'), '[YY]', 'Double nested brackets'); | |
34070 assert.equal(b.format('[[]'), '[', 'Escape open bracket'); | |
34071 assert.equal(b.format('[Last]'), 'Last', 'localized tokens'); | |
34072 assert.equal(b.format('[L] L'), 'L 02/14/2009', 'localized tokens with escaped localized tokens'); | |
34073 assert.equal(b.format('[L LL LLL LLLL aLa]'), 'L LL LLL LLLL aLa', 'localized tokens with escaped localized tokens'); | |
34074 assert.equal(b.format('[LLL] LLL'), 'LLL February 14, 2009 3:25 PM', 'localized tokens with escaped localized tokens (recursion)'); | |
34075 assert.equal(b.format('YYYY[\n]DD[\n]'), '2009\n14\n', 'Newlines'); | |
34076 }); | |
34077 | |
34078 test('handle negative years', function (assert) { | |
34079 moment.locale('en'); | |
34080 assert.equal(moment.utc().year(-1).format('YY'), '-01', 'YY with negative year'); | |
34081 assert.equal(moment.utc().year(-1).format('YYYY'), '-0001', 'YYYY with negative year'); | |
34082 assert.equal(moment.utc().year(-12).format('YY'), '-12', 'YY with negative year'); | |
34083 assert.equal(moment.utc().year(-12).format('YYYY'), '-0012', 'YYYY with negative year'); | |
34084 assert.equal(moment.utc().year(-123).format('YY'), '-23', 'YY with negative year'); | |
34085 assert.equal(moment.utc().year(-123).format('YYYY'), '-0123', 'YYYY with negative year'); | |
34086 assert.equal(moment.utc().year(-1234).format('YY'), '-34', 'YY with negative year'); | |
34087 assert.equal(moment.utc().year(-1234).format('YYYY'), '-1234', 'YYYY with negative year'); | |
34088 assert.equal(moment.utc().year(-12345).format('YY'), '-45', 'YY with negative year'); | |
34089 assert.equal(moment.utc().year(-12345).format('YYYY'), '-12345', 'YYYY with negative year'); | |
34090 }); | |
34091 | |
34092 test('format milliseconds', function (assert) { | |
34093 var b = moment(new Date(2009, 1, 14, 15, 25, 50, 123)); | |
34094 assert.equal(b.format('S'), '1', 'Deciseconds'); | |
34095 assert.equal(b.format('SS'), '12', 'Centiseconds'); | |
34096 assert.equal(b.format('SSS'), '123', 'Milliseconds'); | |
34097 b.milliseconds(789); | |
34098 assert.equal(b.format('S'), '7', 'Deciseconds'); | |
34099 assert.equal(b.format('SS'), '78', 'Centiseconds'); | |
34100 assert.equal(b.format('SSS'), '789', 'Milliseconds'); | |
34101 }); | |
34102 | |
34103 test('format timezone', function (assert) { | |
34104 var b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)); | |
34105 assert.ok(b.format('Z').match(/^[\+\-]\d\d:\d\d$/), b.format('Z') + ' should be something like \'+07:30\''); | |
34106 assert.ok(b.format('ZZ').match(/^[\+\-]\d{4}$/), b.format('ZZ') + ' should be something like \'+0700\''); | |
34107 }); | |
34108 | |
34109 test('format multiple with utc offset', function (assert) { | |
34110 var b = moment('2012-10-08 -1200', ['YYYY-MM-DD HH:mm ZZ', 'YYYY-MM-DD ZZ', 'YYYY-MM-DD']); | |
34111 assert.equal(b.format('YYYY-MM'), '2012-10', 'Parsing multiple formats should not crash with different sized formats'); | |
34112 }); | |
34113 | |
34114 test('isDST', function (assert) { | |
34115 var janOffset = new Date(2011, 0, 1).getTimezoneOffset(), | |
34116 julOffset = new Date(2011, 6, 1).getTimezoneOffset(), | |
34117 janIsDst = janOffset < julOffset, | |
34118 julIsDst = julOffset < janOffset, | |
34119 jan1 = moment([2011]), | |
34120 jul1 = moment([2011, 6]); | |
34121 | |
34122 if (janIsDst && julIsDst) { | |
34123 assert.ok(0, 'January and July cannot both be in DST'); | |
34124 assert.ok(0, 'January and July cannot both be in DST'); | |
34125 } else if (janIsDst) { | |
34126 assert.ok(jan1.isDST(), 'January 1 is DST'); | |
34127 assert.ok(!jul1.isDST(), 'July 1 is not DST'); | |
34128 } else if (julIsDst) { | |
34129 assert.ok(!jan1.isDST(), 'January 1 is not DST'); | |
34130 assert.ok(jul1.isDST(), 'July 1 is DST'); | |
34131 } else { | |
34132 assert.ok(!jan1.isDST(), 'January 1 is not DST'); | |
34133 assert.ok(!jul1.isDST(), 'July 1 is not DST'); | |
34134 } | |
34135 }); | |
34136 | |
34137 test('unix timestamp', function (assert) { | |
34138 var m = moment('1234567890.123', 'X'); | |
34139 assert.equal(m.format('X'), '1234567890', 'unix timestamp without milliseconds'); | |
34140 assert.equal(m.format('X.S'), '1234567890.1', 'unix timestamp with deciseconds'); | |
34141 assert.equal(m.format('X.SS'), '1234567890.12', 'unix timestamp with centiseconds'); | |
34142 assert.equal(m.format('X.SSS'), '1234567890.123', 'unix timestamp with milliseconds'); | |
34143 | |
34144 m = moment(1234567890.123, 'X'); | |
34145 assert.equal(m.format('X'), '1234567890', 'unix timestamp as integer'); | |
34146 }); | |
34147 | |
34148 test('unix offset milliseconds', function (assert) { | |
34149 var m = moment('1234567890123', 'x'); | |
34150 assert.equal(m.format('x'), '1234567890123', 'unix offset in milliseconds'); | |
34151 | |
34152 m = moment(1234567890123, 'x'); | |
34153 assert.equal(m.format('x'), '1234567890123', 'unix offset in milliseconds as integer'); | |
34154 }); | |
34155 | |
34156 test('utcOffset sanity checks', function (assert) { | |
34157 assert.equal(moment().utcOffset() % 15, 0, | |
34158 'utc offset should be a multiple of 15 (was ' + moment().utcOffset() + ')'); | |
34159 | |
34160 assert.equal(moment().utcOffset(), -(new Date()).getTimezoneOffset(), | |
34161 'utcOffset should return the opposite of getTimezoneOffset'); | |
34162 }); | |
34163 | |
34164 test('default format', function (assert) { | |
34165 var isoRegex = /\d{4}.\d\d.\d\dT\d\d.\d\d.\d\d[\+\-]\d\d:\d\d/; | |
34166 assert.ok(isoRegex.exec(moment().format()), 'default format (' + moment().format() + ') should match ISO'); | |
34167 }); | |
34168 | |
34169 test('toJSON', function (assert) { | |
34170 var supportsJson = typeof JSON !== 'undefined' && JSON.stringify && JSON.stringify.call, | |
34171 date = moment('2012-10-09T21:30:40.678+0100'); | |
34172 | |
34173 assert.equal(date.toJSON(), '2012-10-09T20:30:40.678Z', 'should output ISO8601 on moment.fn.toJSON'); | |
34174 | |
34175 if (supportsJson) { | |
34176 assert.equal(JSON.stringify({ | |
34177 date : date | |
34178 }), '{"date":"2012-10-09T20:30:40.678Z"}', 'should output ISO8601 on JSON.stringify'); | |
34179 } | |
34180 }); | |
34181 | |
34182 test('toISOString', function (assert) { | |
34183 var date = moment.utc('2012-10-09T20:30:40.678'); | |
34184 | |
34185 assert.equal(date.toISOString(), '2012-10-09T20:30:40.678Z', 'should output ISO8601 on moment.fn.toISOString'); | |
34186 | |
34187 // big years | |
34188 date = moment.utc('+020123-10-09T20:30:40.678'); | |
34189 assert.equal(date.toISOString(), '+020123-10-09T20:30:40.678Z', 'ISO8601 format on big positive year'); | |
34190 // negative years | |
34191 date = moment.utc('-000001-10-09T20:30:40.678'); | |
34192 assert.equal(date.toISOString(), '-000001-10-09T20:30:40.678Z', 'ISO8601 format on negative year'); | |
34193 // big negative years | |
34194 date = moment.utc('-020123-10-09T20:30:40.678'); | |
34195 assert.equal(date.toISOString(), '-020123-10-09T20:30:40.678Z', 'ISO8601 format on big negative year'); | |
34196 }); | |
34197 | |
34198 test('long years', function (assert) { | |
34199 assert.equal(moment.utc().year(2).format('YYYYYY'), '+000002', 'small year with YYYYYY'); | |
34200 assert.equal(moment.utc().year(2012).format('YYYYYY'), '+002012', 'regular year with YYYYYY'); | |
34201 assert.equal(moment.utc().year(20123).format('YYYYYY'), '+020123', 'big year with YYYYYY'); | |
34202 | |
34203 assert.equal(moment.utc().year(-1).format('YYYYYY'), '-000001', 'small negative year with YYYYYY'); | |
34204 assert.equal(moment.utc().year(-2012).format('YYYYYY'), '-002012', 'negative year with YYYYYY'); | |
34205 assert.equal(moment.utc().year(-20123).format('YYYYYY'), '-020123', 'big negative year with YYYYYY'); | |
34206 }); | |
34207 | |
34208 test('iso week formats', function (assert) { | |
34209 // http://en.wikipedia.org/wiki/ISO_week_date | |
34210 var cases = { | |
34211 '2005-01-02': '2004-53', | |
34212 '2005-12-31': '2005-52', | |
34213 '2007-01-01': '2007-01', | |
34214 '2007-12-30': '2007-52', | |
34215 '2007-12-31': '2008-01', | |
34216 '2008-01-01': '2008-01', | |
34217 '2008-12-28': '2008-52', | |
34218 '2008-12-29': '2009-01', | |
34219 '2008-12-30': '2009-01', | |
34220 '2008-12-31': '2009-01', | |
34221 '2009-01-01': '2009-01', | |
34222 '2009-12-31': '2009-53', | |
34223 '2010-01-01': '2009-53', | |
34224 '2010-01-02': '2009-53', | |
34225 '2010-01-03': '2009-53', | |
34226 '404-12-31': '0404-53', | |
34227 '405-12-31': '0405-52' | |
34228 }, i, isoWeek, formatted2, formatted1; | |
34229 | |
34230 for (i in cases) { | |
34231 isoWeek = cases[i].split('-').pop(); | |
34232 formatted2 = moment(i, 'YYYY-MM-DD').format('WW'); | |
34233 assert.equal(isoWeek, formatted2, i + ': WW should be ' + isoWeek + ', but ' + formatted2); | |
34234 isoWeek = isoWeek.replace(/^0+/, ''); | |
34235 formatted1 = moment(i, 'YYYY-MM-DD').format('W'); | |
34236 assert.equal(isoWeek, formatted1, i + ': W should be ' + isoWeek + ', but ' + formatted1); | |
34237 } | |
34238 }); | |
34239 | |
34240 test('iso week year formats', function (assert) { | |
34241 // http://en.wikipedia.org/wiki/ISO_week_date | |
34242 var cases = { | |
34243 '2005-01-02': '2004-53', | |
34244 '2005-12-31': '2005-52', | |
34245 '2007-01-01': '2007-01', | |
34246 '2007-12-30': '2007-52', | |
34247 '2007-12-31': '2008-01', | |
34248 '2008-01-01': '2008-01', | |
34249 '2008-12-28': '2008-52', | |
34250 '2008-12-29': '2009-01', | |
34251 '2008-12-30': '2009-01', | |
34252 '2008-12-31': '2009-01', | |
34253 '2009-01-01': '2009-01', | |
34254 '2009-12-31': '2009-53', | |
34255 '2010-01-01': '2009-53', | |
34256 '2010-01-02': '2009-53', | |
34257 '2010-01-03': '2009-53', | |
34258 '404-12-31': '0404-53', | |
34259 '405-12-31': '0405-52' | |
34260 }, i, isoWeekYear, formatted5, formatted4, formatted2; | |
34261 | |
34262 for (i in cases) { | |
34263 isoWeekYear = cases[i].split('-')[0]; | |
34264 formatted5 = moment(i, 'YYYY-MM-DD').format('GGGGG'); | |
34265 assert.equal('0' + isoWeekYear, formatted5, i + ': GGGGG should be ' + isoWeekYear + ', but ' + formatted5); | |
34266 formatted4 = moment(i, 'YYYY-MM-DD').format('GGGG'); | |
34267 assert.equal(isoWeekYear, formatted4, i + ': GGGG should be ' + isoWeekYear + ', but ' + formatted4); | |
34268 formatted2 = moment(i, 'YYYY-MM-DD').format('GG'); | |
34269 assert.equal(isoWeekYear.slice(2, 4), formatted2, i + ': GG should be ' + isoWeekYear + ', but ' + formatted2); | |
34270 } | |
34271 }); | |
34272 | |
34273 test('week year formats', function (assert) { | |
34274 // http://en.wikipedia.org/wiki/ISO_week_date | |
34275 var cases = { | |
34276 '2005-01-02': '2004-53', | |
34277 '2005-12-31': '2005-52', | |
34278 '2007-01-01': '2007-01', | |
34279 '2007-12-30': '2007-52', | |
34280 '2007-12-31': '2008-01', | |
34281 '2008-01-01': '2008-01', | |
34282 '2008-12-28': '2008-52', | |
34283 '2008-12-29': '2009-01', | |
34284 '2008-12-30': '2009-01', | |
34285 '2008-12-31': '2009-01', | |
34286 '2009-01-01': '2009-01', | |
34287 '2009-12-31': '2009-53', | |
34288 '2010-01-01': '2009-53', | |
34289 '2010-01-02': '2009-53', | |
34290 '2010-01-03': '2009-53', | |
34291 '404-12-31': '0404-53', | |
34292 '405-12-31': '0405-52' | |
34293 }, i, isoWeekYear, formatted5, formatted4, formatted2; | |
34294 | |
34295 moment.locale('dow:1,doy:4', {week: {dow: 1, doy: 4}}); | |
34296 | |
34297 for (i in cases) { | |
34298 isoWeekYear = cases[i].split('-')[0]; | |
34299 formatted5 = moment(i, 'YYYY-MM-DD').format('ggggg'); | |
34300 assert.equal('0' + isoWeekYear, formatted5, i + ': ggggg should be ' + isoWeekYear + ', but ' + formatted5); | |
34301 formatted4 = moment(i, 'YYYY-MM-DD').format('gggg'); | |
34302 assert.equal(isoWeekYear, formatted4, i + ': gggg should be ' + isoWeekYear + ', but ' + formatted4); | |
34303 formatted2 = moment(i, 'YYYY-MM-DD').format('gg'); | |
34304 assert.equal(isoWeekYear.slice(2, 4), formatted2, i + ': gg should be ' + isoWeekYear + ', but ' + formatted2); | |
34305 } | |
34306 }); | |
34307 | |
34308 test('iso weekday formats', function (assert) { | |
34309 assert.equal(moment([1985, 1, 4]).format('E'), '1', 'Feb 4 1985 is Monday -- 1st day'); | |
34310 assert.equal(moment([2029, 8, 18]).format('E'), '2', 'Sep 18 2029 is Tuesday -- 2nd day'); | |
34311 assert.equal(moment([2013, 3, 24]).format('E'), '3', 'Apr 24 2013 is Wednesday -- 3rd day'); | |
34312 assert.equal(moment([2015, 2, 5]).format('E'), '4', 'Mar 5 2015 is Thursday -- 4th day'); | |
34313 assert.equal(moment([1970, 0, 2]).format('E'), '5', 'Jan 2 1970 is Friday -- 5th day'); | |
34314 assert.equal(moment([2001, 4, 12]).format('E'), '6', 'May 12 2001 is Saturday -- 6th day'); | |
34315 assert.equal(moment([2000, 0, 2]).format('E'), '7', 'Jan 2 2000 is Sunday -- 7th day'); | |
34316 }); | |
34317 | |
34318 test('weekday formats', function (assert) { | |
34319 moment.locale('dow: 3,doy: 5', {week: {dow: 3, doy: 5}}); | |
34320 assert.equal(moment([1985, 1, 6]).format('e'), '0', 'Feb 6 1985 is Wednesday -- 0th day'); | |
34321 assert.equal(moment([2029, 8, 20]).format('e'), '1', 'Sep 20 2029 is Thursday -- 1st day'); | |
34322 assert.equal(moment([2013, 3, 26]).format('e'), '2', 'Apr 26 2013 is Friday -- 2nd day'); | |
34323 assert.equal(moment([2015, 2, 7]).format('e'), '3', 'Mar 7 2015 is Saturday -- 3nd day'); | |
34324 assert.equal(moment([1970, 0, 4]).format('e'), '4', 'Jan 4 1970 is Sunday -- 4th day'); | |
34325 assert.equal(moment([2001, 4, 14]).format('e'), '5', 'May 14 2001 is Monday -- 5th day'); | |
34326 assert.equal(moment([2000, 0, 4]).format('e'), '6', 'Jan 4 2000 is Tuesday -- 6th day'); | |
34327 }); | |
34328 | |
34329 test('toString is just human readable format', function (assert) { | |
34330 var b = moment(new Date(2009, 1, 5, 15, 25, 50, 125)); | |
34331 assert.equal(b.toString(), b.format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ')); | |
34332 }); | |
34333 | |
34334 test('toJSON skips postformat', function (assert) { | |
34335 moment.locale('postformat', { | |
34336 postformat: function (s) { | |
34337 s.replace(/./g, 'X'); | |
34338 } | |
34339 }); | |
34340 assert.equal(moment.utc([2000, 0, 1]).toJSON(), '2000-01-01T00:00:00.000Z', 'toJSON doesn\'t postformat'); | |
34341 moment.locale('postformat', null); | |
34342 }); | |
34343 | |
34344 test('calendar day timezone', function (assert) { | |
34345 moment.locale('en'); | |
34346 var zones = [60, -60, 90, -90, 360, -360, 720, -720], | |
34347 b = moment().utc().startOf('day').subtract({m : 1}), | |
34348 c = moment().local().startOf('day').subtract({m : 1}), | |
34349 d = moment().local().startOf('day').subtract({d : 2}), | |
34350 i, z, a; | |
34351 | |
34352 for (i = 0; i < zones.length; ++i) { | |
34353 z = zones[i]; | |
34354 a = moment().utcOffset(z).startOf('day').subtract({m: 1}); | |
34355 assert.equal(moment(a).utcOffset(z).calendar(), 'Yesterday at 11:59 PM', | |
34356 'Yesterday at 11:59 PM, not Today, or the wrong time, tz = ' + z); | |
34357 } | |
34358 | |
34359 assert.equal(moment(b).utc().calendar(), 'Yesterday at 11:59 PM', 'Yesterday at 11:59 PM, not Today, or the wrong time'); | |
34360 assert.equal(moment(c).local().calendar(), 'Yesterday at 11:59 PM', 'Yesterday at 11:59 PM, not Today, or the wrong time'); | |
34361 assert.equal(moment(c).local().calendar(d), 'Tomorrow at 11:59 PM', 'Tomorrow at 11:59 PM, not Yesterday, or the wrong time'); | |
34362 }); | |
34363 | |
34364 test('calendar with custom formats', function (assert) { | |
34365 assert.equal(moment().calendar(null, {sameDay: '[Today]'}), 'Today', 'Today'); | |
34366 assert.equal(moment().add(1, 'days').calendar(null, {nextDay: '[Tomorrow]'}), 'Tomorrow', 'Tomorrow'); | |
34367 assert.equal(moment([1985, 1, 4]).calendar(null, {sameElse: 'YYYY-MM-DD'}), '1985-02-04', 'Else'); | |
34368 }); | |
34369 | |
34370 test('invalid', function (assert) { | |
34371 assert.equal(moment.invalid().format(), 'Invalid date'); | |
34372 assert.equal(moment.invalid().format('YYYY-MM-DD'), 'Invalid date'); | |
34373 }); | |
34374 | |
34375 test('quarter formats', function (assert) { | |
34376 assert.equal(moment([1985, 1, 4]).format('Q'), '1', 'Feb 4 1985 is Q1'); | |
34377 assert.equal(moment([2029, 8, 18]).format('Q'), '3', 'Sep 18 2029 is Q3'); | |
34378 assert.equal(moment([2013, 3, 24]).format('Q'), '2', 'Apr 24 2013 is Q2'); | |
34379 assert.equal(moment([2015, 2, 5]).format('Q'), '1', 'Mar 5 2015 is Q1'); | |
34380 assert.equal(moment([1970, 0, 2]).format('Q'), '1', 'Jan 2 1970 is Q1'); | |
34381 assert.equal(moment([2001, 11, 12]).format('Q'), '4', 'Dec 12 2001 is Q4'); | |
34382 assert.equal(moment([2000, 0, 2]).format('[Q]Q-YYYY'), 'Q1-2000', 'Jan 2 2000 is Q1'); | |
34383 }); | |
34384 | |
34385 test('full expanded format is returned from abbreviated formats', function (assert) { | |
34386 var locales = ''; | |
34387 | |
34388 locales += 'af ar-ma ar-sa ar-tn ar az be bg bn bo br bs'; | |
34389 locales += 'ca cs cv cy da de-at de el en-au en-ca en-gb'; | |
34390 locales += 'en eo es et eu fa fi fo fr-ca fr fy gl he hi'; | |
34391 locales += 'hr hu hy-am id is it ja jv ka km ko lb lt lv'; | |
34392 locales += 'me mk ml mr ms-my my nb ne nl nn pl pt-rb pt'; | |
34393 locales += 'ro ru si sk sl sq sr-cyrl sr sv ta th tl-ph'; | |
34394 locales += 'tr tzm-latn tzm uk uz vi zh-cn zh-tw'; | |
34395 | |
34396 locales.split(' ').forEach(function (locale) { | |
34397 var data, tokens; | |
34398 data = moment().locale(locale).localeData()._longDateFormat; | |
34399 tokens = Object.keys(data); | |
34400 tokens.forEach(function (token) { | |
34401 // Check each format string to make sure it does not contain any | |
34402 // tokens that need to be expanded. | |
34403 tokens.forEach(function (i) { | |
34404 // strip escaped sequences | |
34405 var format = data[i].replace(/(\[[^\]]*\])/g, ''); | |
34406 assert.equal(false, !!~format.indexOf(token), 'locale ' + locale + ' contains ' + token + ' in ' + i); | |
34407 }); | |
34408 }); | |
34409 }); | |
34410 }); | |
34411 | |
34412 test('milliseconds', function (assert) { | |
34413 var m = moment('123', 'SSS'); | |
34414 | |
34415 assert.equal(m.format('S'), '1'); | |
34416 assert.equal(m.format('SS'), '12'); | |
34417 assert.equal(m.format('SSS'), '123'); | |
34418 assert.equal(m.format('SSSS'), '1230'); | |
34419 assert.equal(m.format('SSSSS'), '12300'); | |
34420 assert.equal(m.format('SSSSSS'), '123000'); | |
34421 assert.equal(m.format('SSSSSSS'), '1230000'); | |
34422 assert.equal(m.format('SSSSSSSS'), '12300000'); | |
34423 assert.equal(m.format('SSSSSSSSS'), '123000000'); | |
34424 }); | |
34425 | |
34426 })); | |
34427 | |
34428 (function (global, factory) { | |
34429 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
34430 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
34431 factory(global.moment) | |
34432 }(this, function (moment) { 'use strict'; | |
34433 | |
34434 /*global QUnit:false*/ | |
34435 | |
34436 var test = QUnit.test; | |
34437 | |
34438 function module (name, lifecycle) { | |
34439 QUnit.module(name, { | |
34440 setup : function () { | |
34441 moment.locale('en'); | |
34442 moment.createFromInputFallback = function () { | |
34443 throw new Error('input not handled by moment'); | |
34444 }; | |
34445 if (lifecycle && lifecycle.setup) { | |
34446 lifecycle.setup(); | |
34447 } | |
34448 }, | |
34449 teardown : function () { | |
34450 if (lifecycle && lifecycle.teardown) { | |
34451 lifecycle.teardown(); | |
34452 } | |
34453 } | |
34454 }); | |
34455 } | |
34456 | |
34457 function localeModule (name, lifecycle) { | |
34458 QUnit.module('locale:' + name, { | |
34459 setup : function () { | |
34460 moment.locale(name); | |
34461 moment.createFromInputFallback = function () { | |
34462 throw new Error('input not handled by moment'); | |
34463 }; | |
34464 if (lifecycle && lifecycle.setup) { | |
34465 lifecycle.setup(); | |
34466 } | |
34467 }, | |
34468 teardown : function () { | |
34469 moment.locale('en'); | |
34470 if (lifecycle && lifecycle.teardown) { | |
34471 lifecycle.teardown(); | |
34472 } | |
34473 } | |
34474 }); | |
34475 } | |
34476 | |
34477 module('from_to'); | |
34478 | |
34479 test('from', function (assert) { | |
34480 var start = moment(); | |
34481 moment.locale('en'); | |
34482 assert.equal(start.from(start.clone().add(5, 'seconds')), 'a few seconds ago', '5 seconds = a few seconds ago'); | |
34483 assert.equal(start.from(start.clone().add(1, 'minute')), 'a minute ago', '1 minute = a minute ago'); | |
34484 assert.equal(start.from(start.clone().add(5, 'minutes')), '5 minutes ago', '5 minutes = 5 minutes ago'); | |
34485 | |
34486 assert.equal(start.from(start.clone().subtract(5, 'seconds')), 'in a few seconds', '5 seconds = in a few seconds'); | |
34487 assert.equal(start.from(start.clone().subtract(1, 'minute')), 'in a minute', '1 minute = in a minute'); | |
34488 assert.equal(start.from(start.clone().subtract(5, 'minutes')), 'in 5 minutes', '5 minutes = in 5 minutes'); | |
34489 }); | |
34490 | |
34491 test('from with absolute duration', function (assert) { | |
34492 var start = moment(); | |
34493 moment.locale('en'); | |
34494 assert.equal(start.from(start.clone().add(5, 'seconds'), true), 'a few seconds', '5 seconds = a few seconds'); | |
34495 assert.equal(start.from(start.clone().add(1, 'minute'), true), 'a minute', '1 minute = a minute'); | |
34496 assert.equal(start.from(start.clone().add(5, 'minutes'), true), '5 minutes', '5 minutes = 5 minutes'); | |
34497 | |
34498 assert.equal(start.from(start.clone().subtract(5, 'seconds'), true), 'a few seconds', '5 seconds = a few seconds'); | |
34499 assert.equal(start.from(start.clone().subtract(1, 'minute'), true), 'a minute', '1 minute = a minute'); | |
34500 assert.equal(start.from(start.clone().subtract(5, 'minutes'), true), '5 minutes', '5 minutes = 5 minutes'); | |
34501 }); | |
34502 | |
34503 test('to', function (assert) { | |
34504 var start = moment(); | |
34505 moment.locale('en'); | |
34506 assert.equal(start.to(start.clone().subtract(5, 'seconds')), 'a few seconds ago', '5 seconds = a few seconds ago'); | |
34507 assert.equal(start.to(start.clone().subtract(1, 'minute')), 'a minute ago', '1 minute = a minute ago'); | |
34508 assert.equal(start.to(start.clone().subtract(5, 'minutes')), '5 minutes ago', '5 minutes = 5 minutes ago'); | |
34509 | |
34510 assert.equal(start.to(start.clone().add(5, 'seconds')), 'in a few seconds', '5 seconds = in a few seconds'); | |
34511 assert.equal(start.to(start.clone().add(1, 'minute')), 'in a minute', '1 minute = in a minute'); | |
34512 assert.equal(start.to(start.clone().add(5, 'minutes')), 'in 5 minutes', '5 minutes = in 5 minutes'); | |
34513 }); | |
34514 | |
34515 test('to with absolute duration', function (assert) { | |
34516 var start = moment(); | |
34517 moment.locale('en'); | |
34518 assert.equal(start.to(start.clone().add(5, 'seconds'), true), 'a few seconds', '5 seconds = a few seconds'); | |
34519 assert.equal(start.to(start.clone().add(1, 'minute'), true), 'a minute', '1 minute = a minute'); | |
34520 assert.equal(start.to(start.clone().add(5, 'minutes'), true), '5 minutes', '5 minutes = 5 minutes'); | |
34521 | |
34522 assert.equal(start.to(start.clone().subtract(5, 'seconds'), true), 'a few seconds', '5 seconds = a few seconds'); | |
34523 assert.equal(start.to(start.clone().subtract(1, 'minute'), true), 'a minute', '1 minute = a minute'); | |
34524 assert.equal(start.to(start.clone().subtract(5, 'minutes'), true), '5 minutes', '5 minutes = 5 minutes'); | |
34525 }); | |
34526 | |
34527 })); | |
34528 | |
34529 (function (global, factory) { | |
34530 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
34531 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
34532 factory(global.moment) | |
34533 }(this, function (moment) { 'use strict'; | |
34534 | |
34535 /*global QUnit:false*/ | |
34536 | |
34537 var test = QUnit.test; | |
34538 | |
34539 function module (name, lifecycle) { | |
34540 QUnit.module(name, { | |
34541 setup : function () { | |
34542 moment.locale('en'); | |
34543 moment.createFromInputFallback = function () { | |
34544 throw new Error('input not handled by moment'); | |
34545 }; | |
34546 if (lifecycle && lifecycle.setup) { | |
34547 lifecycle.setup(); | |
34548 } | |
34549 }, | |
34550 teardown : function () { | |
34551 if (lifecycle && lifecycle.teardown) { | |
34552 lifecycle.teardown(); | |
34553 } | |
34554 } | |
34555 }); | |
34556 } | |
34557 | |
34558 function localeModule (name, lifecycle) { | |
34559 QUnit.module('locale:' + name, { | |
34560 setup : function () { | |
34561 moment.locale(name); | |
34562 moment.createFromInputFallback = function () { | |
34563 throw new Error('input not handled by moment'); | |
34564 }; | |
34565 if (lifecycle && lifecycle.setup) { | |
34566 lifecycle.setup(); | |
34567 } | |
34568 }, | |
34569 teardown : function () { | |
34570 moment.locale('en'); | |
34571 if (lifecycle && lifecycle.teardown) { | |
34572 lifecycle.teardown(); | |
34573 } | |
34574 } | |
34575 }); | |
34576 } | |
34577 | |
34578 module('getters and setters'); | |
34579 | |
34580 test('getters', function (assert) { | |
34581 var a = moment([2011, 9, 12, 6, 7, 8, 9]); | |
34582 assert.equal(a.year(), 2011, 'year'); | |
34583 assert.equal(a.month(), 9, 'month'); | |
34584 assert.equal(a.date(), 12, 'date'); | |
34585 assert.equal(a.day(), 3, 'day'); | |
34586 assert.equal(a.hours(), 6, 'hour'); | |
34587 assert.equal(a.minutes(), 7, 'minute'); | |
34588 assert.equal(a.seconds(), 8, 'second'); | |
34589 assert.equal(a.milliseconds(), 9, 'milliseconds'); | |
34590 }); | |
34591 | |
34592 test('getters programmatic', function (assert) { | |
34593 var a = moment([2011, 9, 12, 6, 7, 8, 9]); | |
34594 assert.equal(a.get('year'), 2011, 'year'); | |
34595 assert.equal(a.get('month'), 9, 'month'); | |
34596 assert.equal(a.get('date'), 12, 'date'); | |
34597 assert.equal(a.get('day'), 3, 'day'); | |
34598 assert.equal(a.get('hour'), 6, 'hour'); | |
34599 assert.equal(a.get('minute'), 7, 'minute'); | |
34600 assert.equal(a.get('second'), 8, 'second'); | |
34601 assert.equal(a.get('milliseconds'), 9, 'milliseconds'); | |
34602 | |
34603 //actual getters tested elsewhere | |
34604 assert.equal(a.get('weekday'), a.weekday(), 'weekday'); | |
34605 assert.equal(a.get('isoWeekday'), a.isoWeekday(), 'isoWeekday'); | |
34606 assert.equal(a.get('week'), a.week(), 'week'); | |
34607 assert.equal(a.get('isoWeek'), a.isoWeek(), 'isoWeek'); | |
34608 assert.equal(a.get('dayOfYear'), a.dayOfYear(), 'dayOfYear'); | |
34609 }); | |
34610 | |
34611 test('setters plural', function (assert) { | |
34612 var a = moment(); | |
34613 a.years(2011); | |
34614 a.months(9); | |
34615 a.dates(12); | |
34616 a.hours(6); | |
34617 a.minutes(7); | |
34618 a.seconds(8); | |
34619 a.milliseconds(9); | |
34620 assert.equal(a.years(), 2011, 'years'); | |
34621 assert.equal(a.months(), 9, 'months'); | |
34622 assert.equal(a.dates(), 12, 'dates'); | |
34623 assert.equal(a.days(), 3, 'days'); | |
34624 assert.equal(a.hours(), 6, 'hours'); | |
34625 assert.equal(a.minutes(), 7, 'minutes'); | |
34626 assert.equal(a.seconds(), 8, 'seconds'); | |
34627 assert.equal(a.milliseconds(), 9, 'milliseconds'); | |
34628 }); | |
34629 | |
34630 test('setters singular', function (assert) { | |
34631 var a = moment(); | |
34632 a.year(2011); | |
34633 a.month(9); | |
34634 a.date(12); | |
34635 a.hour(6); | |
34636 a.minute(7); | |
34637 a.second(8); | |
34638 a.millisecond(9); | |
34639 assert.equal(a.year(), 2011, 'year'); | |
34640 assert.equal(a.month(), 9, 'month'); | |
34641 assert.equal(a.date(), 12, 'date'); | |
34642 assert.equal(a.day(), 3, 'day'); | |
34643 assert.equal(a.hour(), 6, 'hour'); | |
34644 assert.equal(a.minute(), 7, 'minute'); | |
34645 assert.equal(a.second(), 8, 'second'); | |
34646 assert.equal(a.millisecond(), 9, 'milliseconds'); | |
34647 }); | |
34648 | |
34649 test('setters', function (assert) { | |
34650 var a = moment(); | |
34651 a.year(2011); | |
34652 a.month(9); | |
34653 a.date(12); | |
34654 a.hours(6); | |
34655 a.minutes(7); | |
34656 a.seconds(8); | |
34657 a.milliseconds(9); | |
34658 assert.equal(a.year(), 2011, 'year'); | |
34659 assert.equal(a.month(), 9, 'month'); | |
34660 assert.equal(a.date(), 12, 'date'); | |
34661 assert.equal(a.day(), 3, 'day'); | |
34662 assert.equal(a.hours(), 6, 'hour'); | |
34663 assert.equal(a.minutes(), 7, 'minute'); | |
34664 assert.equal(a.seconds(), 8, 'second'); | |
34665 assert.equal(a.milliseconds(), 9, 'milliseconds'); | |
34666 | |
34667 // Test month() behavior. See https://github.com/timrwood/moment/pull/822 | |
34668 a = moment('20130531', 'YYYYMMDD'); | |
34669 a.month(3); | |
34670 assert.equal(a.month(), 3, 'month edge case'); | |
34671 }); | |
34672 | |
34673 test('setter programmatic', function (assert) { | |
34674 var a = moment(); | |
34675 a.set('year', 2011); | |
34676 a.set('month', 9); | |
34677 a.set('date', 12); | |
34678 a.set('hours', 6); | |
34679 a.set('minutes', 7); | |
34680 a.set('seconds', 8); | |
34681 a.set('milliseconds', 9); | |
34682 assert.equal(a.year(), 2011, 'year'); | |
34683 assert.equal(a.month(), 9, 'month'); | |
34684 assert.equal(a.date(), 12, 'date'); | |
34685 assert.equal(a.day(), 3, 'day'); | |
34686 assert.equal(a.hours(), 6, 'hour'); | |
34687 assert.equal(a.minutes(), 7, 'minute'); | |
34688 assert.equal(a.seconds(), 8, 'second'); | |
34689 assert.equal(a.milliseconds(), 9, 'milliseconds'); | |
34690 | |
34691 // Test month() behavior. See https://github.com/timrwood/moment/pull/822 | |
34692 a = moment('20130531', 'YYYYMMDD'); | |
34693 a.month(3); | |
34694 assert.equal(a.month(), 3, 'month edge case'); | |
34695 }); | |
34696 | |
34697 // Disable this, until we weekYear setter is fixed. | |
34698 // https://github.com/moment/moment/issues/1379 | |
34699 // test('setters programatic with weeks', function (assert) { | |
34700 // var a = moment(); | |
34701 // a.set('weekYear', 2001); | |
34702 // a.set('week', 49); | |
34703 // a.set('day', 4); | |
34704 // assert.equals(a.weekYear(), 2001); | |
34705 // assert.equals(a.week(), 49); | |
34706 // assert.equals(a.day(), 4); | |
34707 | |
34708 // a.set('weekday', 1); | |
34709 // assert.equals(a.weekday(), 1); | |
34710 | |
34711 // assert.done(); | |
34712 //}, | |
34713 | |
34714 // I think this suffers from the same issue as the non-iso version. | |
34715 // test('setters programatic with weeks ISO', function (assert) { | |
34716 // var a = moment(); | |
34717 // a.set('isoWeekYear', 2001); | |
34718 // a.set('isoWeek', 49); | |
34719 // a.set('isoWeekday', 4); | |
34720 | |
34721 // assert.equals(a.weekYear(), 2001); | |
34722 // assert.equals(a.week(), 49); | |
34723 // assert.equals(a.day(), 4); | |
34724 | |
34725 // assert.done(); | |
34726 //}, | |
34727 | |
34728 test('setters strings', function (assert) { | |
34729 var a = moment([2012]).locale('en'); | |
34730 assert.equal(a.clone().day(0).day('Wednesday').day(), 3, 'day full name'); | |
34731 assert.equal(a.clone().day(0).day('Wed').day(), 3, 'day short name'); | |
34732 assert.equal(a.clone().day(0).day('We').day(), 3, 'day minimal name'); | |
34733 assert.equal(a.clone().day(0).day('invalid').day(), 0, 'invalid day name'); | |
34734 assert.equal(a.clone().month(0).month('April').month(), 3, 'month full name'); | |
34735 assert.equal(a.clone().month(0).month('Apr').month(), 3, 'month short name'); | |
34736 assert.equal(a.clone().month(0).month('invalid').month(), 0, 'invalid month name'); | |
34737 }); | |
34738 | |
34739 test('setters - falsey values', function (assert) { | |
34740 var a = moment(); | |
34741 // ensure minutes wasn't coincidentally 0 already | |
34742 a.minutes(1); | |
34743 a.minutes(0); | |
34744 assert.equal(a.minutes(), 0, 'falsey value'); | |
34745 }); | |
34746 | |
34747 test('chaining setters', function (assert) { | |
34748 var a = moment(); | |
34749 a.year(2011) | |
34750 .month(9) | |
34751 .date(12) | |
34752 .hours(6) | |
34753 .minutes(7) | |
34754 .seconds(8); | |
34755 assert.equal(a.year(), 2011, 'year'); | |
34756 assert.equal(a.month(), 9, 'month'); | |
34757 assert.equal(a.date(), 12, 'date'); | |
34758 assert.equal(a.day(), 3, 'day'); | |
34759 assert.equal(a.hours(), 6, 'hour'); | |
34760 assert.equal(a.minutes(), 7, 'minute'); | |
34761 assert.equal(a.seconds(), 8, 'second'); | |
34762 }); | |
34763 | |
34764 test('setter with multiple unit values', function (assert) { | |
34765 var a = moment(); | |
34766 a.set({ | |
34767 year: 2011, | |
34768 month: 9, | |
34769 date: 12, | |
34770 hours: 6, | |
34771 minutes: 7, | |
34772 seconds: 8, | |
34773 milliseconds: 9 | |
34774 }); | |
34775 assert.equal(a.year(), 2011, 'year'); | |
34776 assert.equal(a.month(), 9, 'month'); | |
34777 assert.equal(a.date(), 12, 'date'); | |
34778 assert.equal(a.day(), 3, 'day'); | |
34779 assert.equal(a.hours(), 6, 'hour'); | |
34780 assert.equal(a.minutes(), 7, 'minute'); | |
34781 assert.equal(a.seconds(), 8, 'second'); | |
34782 assert.equal(a.milliseconds(), 9, 'milliseconds'); | |
34783 }); | |
34784 | |
34785 test('day setter', function (assert) { | |
34786 var a = moment([2011, 0, 15]); | |
34787 assert.equal(moment(a).day(0).date(), 9, 'set from saturday to sunday'); | |
34788 assert.equal(moment(a).day(6).date(), 15, 'set from saturday to saturday'); | |
34789 assert.equal(moment(a).day(3).date(), 12, 'set from saturday to wednesday'); | |
34790 | |
34791 a = moment([2011, 0, 9]); | |
34792 assert.equal(moment(a).day(0).date(), 9, 'set from sunday to sunday'); | |
34793 assert.equal(moment(a).day(6).date(), 15, 'set from sunday to saturday'); | |
34794 assert.equal(moment(a).day(3).date(), 12, 'set from sunday to wednesday'); | |
34795 | |
34796 a = moment([2011, 0, 12]); | |
34797 assert.equal(moment(a).day(0).date(), 9, 'set from wednesday to sunday'); | |
34798 assert.equal(moment(a).day(6).date(), 15, 'set from wednesday to saturday'); | |
34799 assert.equal(moment(a).day(3).date(), 12, 'set from wednesday to wednesday'); | |
34800 | |
34801 assert.equal(moment(a).day(-7).date(), 2, 'set from wednesday to last sunday'); | |
34802 assert.equal(moment(a).day(-1).date(), 8, 'set from wednesday to last saturday'); | |
34803 assert.equal(moment(a).day(-4).date(), 5, 'set from wednesday to last wednesday'); | |
34804 | |
34805 assert.equal(moment(a).day(7).date(), 16, 'set from wednesday to next sunday'); | |
34806 assert.equal(moment(a).day(13).date(), 22, 'set from wednesday to next saturday'); | |
34807 assert.equal(moment(a).day(10).date(), 19, 'set from wednesday to next wednesday'); | |
34808 | |
34809 assert.equal(moment(a).day(14).date(), 23, 'set from wednesday to second next sunday'); | |
34810 assert.equal(moment(a).day(20).date(), 29, 'set from wednesday to second next saturday'); | |
34811 assert.equal(moment(a).day(17).date(), 26, 'set from wednesday to second next wednesday'); | |
34812 }); | |
34813 | |
34814 })); | |
34815 | |
34816 (function (global, factory) { | |
34817 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
34818 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
34819 factory(global.moment) | |
34820 }(this, function (moment) { 'use strict'; | |
34821 | |
34822 /*global QUnit:false*/ | |
34823 | |
34824 var test = QUnit.test; | |
34825 | |
34826 function module (name, lifecycle) { | |
34827 QUnit.module(name, { | |
34828 setup : function () { | |
34829 moment.locale('en'); | |
34830 moment.createFromInputFallback = function () { | |
34831 throw new Error('input not handled by moment'); | |
34832 }; | |
34833 if (lifecycle && lifecycle.setup) { | |
34834 lifecycle.setup(); | |
34835 } | |
34836 }, | |
34837 teardown : function () { | |
34838 if (lifecycle && lifecycle.teardown) { | |
34839 lifecycle.teardown(); | |
34840 } | |
34841 } | |
34842 }); | |
34843 } | |
34844 | |
34845 function localeModule (name, lifecycle) { | |
34846 QUnit.module('locale:' + name, { | |
34847 setup : function () { | |
34848 moment.locale(name); | |
34849 moment.createFromInputFallback = function () { | |
34850 throw new Error('input not handled by moment'); | |
34851 }; | |
34852 if (lifecycle && lifecycle.setup) { | |
34853 lifecycle.setup(); | |
34854 } | |
34855 }, | |
34856 teardown : function () { | |
34857 moment.locale('en'); | |
34858 if (lifecycle && lifecycle.teardown) { | |
34859 lifecycle.teardown(); | |
34860 } | |
34861 } | |
34862 }); | |
34863 } | |
34864 | |
34865 module('invalid'); | |
34866 | |
34867 test('invalid', function (assert) { | |
34868 var m = moment.invalid(); | |
34869 assert.equal(m.isValid(), false); | |
34870 assert.equal(m.parsingFlags().userInvalidated, true); | |
34871 assert.ok(isNaN(m.valueOf())); | |
34872 }); | |
34873 | |
34874 test('invalid with existing flag', function (assert) { | |
34875 var m = moment.invalid({invalidMonth : 'whatchamacallit'}); | |
34876 assert.equal(m.isValid(), false); | |
34877 assert.equal(m.parsingFlags().userInvalidated, false); | |
34878 assert.equal(m.parsingFlags().invalidMonth, 'whatchamacallit'); | |
34879 assert.ok(isNaN(m.valueOf())); | |
34880 }); | |
34881 | |
34882 test('invalid with custom flag', function (assert) { | |
34883 var m = moment.invalid({tooBusyWith : 'reiculating splines'}); | |
34884 assert.equal(m.isValid(), false); | |
34885 assert.equal(m.parsingFlags().userInvalidated, false); | |
34886 assert.equal(m.parsingFlags().tooBusyWith, 'reiculating splines'); | |
34887 assert.ok(isNaN(m.valueOf())); | |
34888 }); | |
34889 | |
34890 })); | |
34891 | |
34892 (function (global, factory) { | |
34893 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
34894 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
34895 factory(global.moment) | |
34896 }(this, function (moment) { 'use strict'; | |
34897 | |
34898 /*global QUnit:false*/ | |
34899 | |
34900 var test = QUnit.test; | |
34901 | |
34902 function module (name, lifecycle) { | |
34903 QUnit.module(name, { | |
34904 setup : function () { | |
34905 moment.locale('en'); | |
34906 moment.createFromInputFallback = function () { | |
34907 throw new Error('input not handled by moment'); | |
34908 }; | |
34909 if (lifecycle && lifecycle.setup) { | |
34910 lifecycle.setup(); | |
34911 } | |
34912 }, | |
34913 teardown : function () { | |
34914 if (lifecycle && lifecycle.teardown) { | |
34915 lifecycle.teardown(); | |
34916 } | |
34917 } | |
34918 }); | |
34919 } | |
34920 | |
34921 function localeModule (name, lifecycle) { | |
34922 QUnit.module('locale:' + name, { | |
34923 setup : function () { | |
34924 moment.locale(name); | |
34925 moment.createFromInputFallback = function () { | |
34926 throw new Error('input not handled by moment'); | |
34927 }; | |
34928 if (lifecycle && lifecycle.setup) { | |
34929 lifecycle.setup(); | |
34930 } | |
34931 }, | |
34932 teardown : function () { | |
34933 moment.locale('en'); | |
34934 if (lifecycle && lifecycle.teardown) { | |
34935 lifecycle.teardown(); | |
34936 } | |
34937 } | |
34938 }); | |
34939 } | |
34940 | |
34941 module('is after'); | |
34942 | |
34943 test('is after without units', function (assert) { | |
34944 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m); | |
34945 assert.equal(m.isAfter(moment(new Date(2012, 3, 2, 3, 5, 5, 10))), false, 'year is later'); | |
34946 assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 3, 5, 10))), true, 'year is earlier'); | |
34947 assert.equal(m.isAfter(moment(new Date(2011, 4, 2, 3, 4, 5, 10))), false, 'month is later'); | |
34948 assert.equal(m.isAfter(moment(new Date(2011, 2, 2, 3, 4, 5, 10))), true, 'month is earlier'); | |
34949 assert.equal(m.isAfter(moment(new Date(2011, 3, 3, 3, 4, 5, 10))), false, 'day is later'); | |
34950 assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 3, 4, 5, 10))), true, 'day is earlier'); | |
34951 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 4, 4, 5, 10))), false, 'hour is later'); | |
34952 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 2, 4, 5, 10))), true, 'hour is earlier'); | |
34953 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 5, 5, 10))), false, 'minute is later'); | |
34954 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 3, 5, 10))), true, 'minute is earlier'); | |
34955 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 6, 10))), false, 'second is later'); | |
34956 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 4, 11))), true, 'second is earlier'); | |
34957 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'millisecond match'); | |
34958 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 11))), false, 'millisecond is later'); | |
34959 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 9))), true, 'millisecond is earlier'); | |
34960 assert.equal(m.isAfter(m), false, 'moments are not after themselves'); | |
34961 assert.equal(+m, +mCopy, 'isAfter second should not change moment'); | |
34962 }); | |
34963 | |
34964 test('is after year', function (assert) { | |
34965 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m); | |
34966 assert.equal(m.isAfter(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year match'); | |
34967 assert.equal(m.isAfter(moment(new Date(2010, 5, 6, 7, 8, 9, 10)), 'years'), true, 'plural should work'); | |
34968 assert.equal(m.isAfter(moment(new Date(2013, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year is later'); | |
34969 assert.equal(m.isAfter(moment(new Date(2010, 5, 6, 7, 8, 9, 10)), 'year'), true, 'year is earlier'); | |
34970 assert.equal(m.isAfter(moment(new Date(2011, 0, 1, 0, 0, 0, 0)), 'year'), false, 'exact start of year'); | |
34971 assert.equal(m.isAfter(moment(new Date(2011, 11, 31, 23, 59, 59, 999)), 'year'), false, 'exact end of year'); | |
34972 assert.equal(m.isAfter(moment(new Date(2012, 0, 1, 0, 0, 0, 0)), 'year'), false, 'start of next year'); | |
34973 assert.equal(m.isAfter(moment(new Date(2010, 11, 31, 23, 59, 59, 999)), 'year'), true, 'end of previous year'); | |
34974 assert.equal(m.isAfter(moment(new Date(1980, 11, 31, 23, 59, 59, 999)), 'year'), true, 'end of year far before'); | |
34975 assert.equal(m.isAfter(m, 'year'), false, 'same moments are not after the same year'); | |
34976 assert.equal(+m, +mCopy, 'isAfter year should not change moment'); | |
34977 }); | |
34978 | |
34979 test('is after month', function (assert) { | |
34980 var m = moment(new Date(2011, 2, 3, 4, 5, 6, 7)), mCopy = moment(m); | |
34981 assert.equal(m.isAfter(moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'month'), false, 'month match'); | |
34982 assert.equal(m.isAfter(moment(new Date(2010, 2, 6, 7, 8, 9, 10)), 'months'), true, 'plural should work'); | |
34983 assert.equal(m.isAfter(moment(new Date(2012, 2, 6, 7, 8, 9, 10)), 'month'), false, 'year is later'); | |
34984 assert.equal(m.isAfter(moment(new Date(2010, 2, 6, 7, 8, 9, 10)), 'month'), true, 'year is earlier'); | |
34985 assert.equal(m.isAfter(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'month'), false, 'month is later'); | |
34986 assert.equal(m.isAfter(moment(new Date(2011, 1, 6, 7, 8, 9, 10)), 'month'), true, 'month is earlier'); | |
34987 assert.equal(m.isAfter(moment(new Date(2011, 2, 1, 0, 0, 0, 0)), 'month'), false, 'exact start of month'); | |
34988 assert.equal(m.isAfter(moment(new Date(2011, 2, 31, 23, 59, 59, 999)), 'month'), false, 'exact end of month'); | |
34989 assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 0, 0, 0, 0)), 'month'), false, 'start of next month'); | |
34990 assert.equal(m.isAfter(moment(new Date(2011, 1, 27, 23, 59, 59, 999)), 'month'), true, 'end of previous month'); | |
34991 assert.equal(m.isAfter(moment(new Date(2010, 12, 31, 23, 59, 59, 999)), 'month'), true, 'later month but earlier year'); | |
34992 assert.equal(m.isAfter(m, 'month'), false, 'same moments are not after the same month'); | |
34993 assert.equal(+m, +mCopy, 'isAfter month should not change moment'); | |
34994 }); | |
34995 | |
34996 test('is after day', function (assert) { | |
34997 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 6)), mCopy = moment(m); | |
34998 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 7, 8, 9, 10)), 'day'), false, 'day match'); | |
34999 assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 7, 8, 9, 10)), 'days'), true, 'plural should work'); | |
35000 assert.equal(m.isAfter(moment(new Date(2012, 3, 2, 7, 8, 9, 10)), 'day'), false, 'year is later'); | |
35001 assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 7, 8, 9, 10)), 'day'), true, 'year is earlier'); | |
35002 assert.equal(m.isAfter(moment(new Date(2011, 4, 2, 7, 8, 9, 10)), 'day'), false, 'month is later'); | |
35003 assert.equal(m.isAfter(moment(new Date(2011, 2, 2, 7, 8, 9, 10)), 'day'), true, 'month is earlier'); | |
35004 assert.equal(m.isAfter(moment(new Date(2011, 3, 3, 7, 8, 9, 10)), 'day'), false, 'day is later'); | |
35005 assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 7, 8, 9, 10)), 'day'), true, 'day is earlier'); | |
35006 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 0, 0, 0, 0)), 'day'), false, 'exact start of day'); | |
35007 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 23, 59, 59, 999)), 'day'), false, 'exact end of day'); | |
35008 assert.equal(m.isAfter(moment(new Date(2011, 3, 3, 0, 0, 0, 0)), 'day'), false, 'start of next day'); | |
35009 assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 23, 59, 59, 999)), 'day'), true, 'end of previous day'); | |
35010 assert.equal(m.isAfter(moment(new Date(2010, 3, 10, 0, 0, 0, 0)), 'day'), true, 'later day but earlier year'); | |
35011 assert.equal(m.isAfter(m, 'day'), false, 'same moments are not after the same day'); | |
35012 assert.equal(+m, +mCopy, 'isAfter day should not change moment'); | |
35013 }); | |
35014 | |
35015 test('is after hour', function (assert) { | |
35016 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 6)), mCopy = moment(m); | |
35017 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 8, 9, 10)), 'hour'), false, 'hour match'); | |
35018 assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 8, 9, 10)), 'hours'), true, 'plural should work'); | |
35019 assert.equal(m.isAfter(moment(new Date(2012, 3, 2, 3, 8, 9, 10)), 'hour'), false, 'year is later'); | |
35020 assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 8, 9, 10)), 'hour'), true, 'year is earlier'); | |
35021 assert.equal(m.isAfter(moment(new Date(2011, 4, 2, 3, 8, 9, 10)), 'hour'), false, 'month is later'); | |
35022 assert.equal(m.isAfter(moment(new Date(2011, 1, 2, 3, 8, 9, 10)), 'hour'), true, 'month is earlier'); | |
35023 assert.equal(m.isAfter(moment(new Date(2011, 3, 3, 3, 8, 9, 10)), 'hour'), false, 'day is later'); | |
35024 assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 3, 8, 9, 10)), 'hour'), true, 'day is earlier'); | |
35025 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 4, 8, 9, 10)), 'hour'), false, 'hour is later'); | |
35026 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 8, 9, 10)), 'hour'), false, 'hour is earlier'); | |
35027 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 0, 0, 0)), 'hour'), false, 'exact start of hour'); | |
35028 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 59, 59, 999)), 'hour'), false, 'exact end of hour'); | |
35029 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 4, 0, 0, 0)), 'hour'), false, 'start of next hour'); | |
35030 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 2, 59, 59, 999)), 'hour'), true, 'end of previous hour'); | |
35031 assert.equal(m.isAfter(m, 'hour'), false, 'same moments are not after the same hour'); | |
35032 assert.equal(+m, +mCopy, 'isAfter hour should not change moment'); | |
35033 }); | |
35034 | |
35035 test('is after minute', function (assert) { | |
35036 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 6)), mCopy = moment(m); | |
35037 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 9, 10)), 'minute'), false, 'minute match'); | |
35038 assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 4, 9, 10)), 'minutes'), true, 'plural should work'); | |
35039 assert.equal(m.isAfter(moment(new Date(2012, 3, 2, 3, 4, 9, 10)), 'minute'), false, 'year is later'); | |
35040 assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 4, 9, 10)), 'minute'), true, 'year is earlier'); | |
35041 assert.equal(m.isAfter(moment(new Date(2011, 4, 2, 3, 4, 9, 10)), 'minute'), false, 'month is later'); | |
35042 assert.equal(m.isAfter(moment(new Date(2011, 2, 2, 3, 4, 9, 10)), 'minute'), true, 'month is earlier'); | |
35043 assert.equal(m.isAfter(moment(new Date(2011, 3, 3, 3, 4, 9, 10)), 'minute'), false, 'day is later'); | |
35044 assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 3, 4, 9, 10)), 'minute'), true, 'day is earlier'); | |
35045 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 4, 4, 9, 10)), 'minute'), false, 'hour is later'); | |
35046 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 2, 4, 9, 10)), 'minute'), true, 'hour is earler'); | |
35047 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 5, 9, 10)), 'minute'), false, 'minute is later'); | |
35048 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 3, 9, 10)), 'minute'), true, 'minute is earlier'); | |
35049 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 0, 0)), 'minute'), false, 'exact start of minute'); | |
35050 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 59, 999)), 'minute'), false, 'exact end of minute'); | |
35051 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 5, 0, 0)), 'minute'), false, 'start of next minute'); | |
35052 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 3, 59, 999)), 'minute'), true, 'end of previous minute'); | |
35053 assert.equal(m.isAfter(m, 'minute'), false, 'same moments are not after the same minute'); | |
35054 assert.equal(+m, +mCopy, 'isAfter minute should not change moment'); | |
35055 }); | |
35056 | |
35057 test('is after second', function (assert) { | |
35058 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m); | |
35059 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'second'), false, 'second match'); | |
35060 assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'seconds'), true, 'plural should work'); | |
35061 assert.equal(m.isAfter(moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'second'), false, 'year is later'); | |
35062 assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'second'), true, 'year is earlier'); | |
35063 assert.equal(m.isAfter(moment(new Date(2011, 4, 2, 3, 4, 5, 10)), 'second'), false, 'month is later'); | |
35064 assert.equal(m.isAfter(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'second'), true, 'month is earlier'); | |
35065 assert.equal(m.isAfter(moment(new Date(2011, 3, 3, 3, 4, 5, 10)), 'second'), false, 'day is later'); | |
35066 assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 1, 4, 5, 10)), 'second'), true, 'day is earlier'); | |
35067 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 4, 4, 5, 10)), 'second'), false, 'hour is later'); | |
35068 assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 4, 1, 5, 10)), 'second'), true, 'hour is earlier'); | |
35069 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 5, 5, 10)), 'second'), false, 'minute is later'); | |
35070 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 3, 5, 10)), 'second'), true, 'minute is earlier'); | |
35071 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 6, 10)), 'second'), false, 'second is later'); | |
35072 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 4, 5)), 'second'), true, 'second is earlier'); | |
35073 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 0)), 'second'), false, 'exact start of second'); | |
35074 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 999)), 'second'), false, 'exact end of second'); | |
35075 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 6, 0)), 'second'), false, 'start of next second'); | |
35076 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 4, 999)), 'second'), true, 'end of previous second'); | |
35077 assert.equal(m.isAfter(m, 'second'), false, 'same moments are not after the same second'); | |
35078 assert.equal(+m, +mCopy, 'isAfter second should not change moment'); | |
35079 }); | |
35080 | |
35081 test('is after millisecond', function (assert) { | |
35082 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m); | |
35083 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'millisecond'), false, 'millisecond match'); | |
35084 assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'milliseconds'), true, 'plural should work'); | |
35085 assert.equal(m.isAfter(moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'millisecond'), false, 'year is later'); | |
35086 assert.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'millisecond'), true, 'year is earlier'); | |
35087 assert.equal(m.isAfter(moment(new Date(2011, 4, 2, 3, 4, 5, 10)), 'millisecond'), false, 'month is later'); | |
35088 assert.equal(m.isAfter(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'millisecond'), true, 'month is earlier'); | |
35089 assert.equal(m.isAfter(moment(new Date(2011, 3, 3, 3, 4, 5, 10)), 'millisecond'), false, 'day is later'); | |
35090 assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 1, 4, 5, 10)), 'millisecond'), true, 'day is earlier'); | |
35091 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 4, 4, 5, 10)), 'millisecond'), false, 'hour is later'); | |
35092 assert.equal(m.isAfter(moment(new Date(2011, 3, 1, 4, 1, 5, 10)), 'millisecond'), true, 'hour is earlier'); | |
35093 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 5, 5, 10)), 'millisecond'), false, 'minute is later'); | |
35094 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 3, 5, 10)), 'millisecond'), true, 'minute is earlier'); | |
35095 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 6, 10)), 'millisecond'), false, 'second is later'); | |
35096 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 4, 5)), 'millisecond'), true, 'second is earlier'); | |
35097 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 6, 11)), 'millisecond'), false, 'millisecond is later'); | |
35098 assert.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 4, 9)), 'millisecond'), true, 'millisecond is earlier'); | |
35099 assert.equal(m.isAfter(m, 'millisecond'), false, 'same moments are not after the same millisecond'); | |
35100 assert.equal(+m, +mCopy, 'isAfter millisecond should not change moment'); | |
35101 }); | |
35102 | |
35103 test('is after invalid', function (assert) { | |
35104 var m = moment(), invalid = moment.invalid(); | |
35105 assert.equal(m.isAfter(invalid), false, 'valid moment is not after invalid moment'); | |
35106 assert.equal(invalid.isAfter(m), false, 'invalid moment is not after valid moment'); | |
35107 assert.equal(m.isAfter(invalid, 'year'), false, 'invalid moment year'); | |
35108 assert.equal(m.isAfter(invalid, 'month'), false, 'invalid moment month'); | |
35109 assert.equal(m.isAfter(invalid, 'day'), false, 'invalid moment day'); | |
35110 assert.equal(m.isAfter(invalid, 'hour'), false, 'invalid moment hour'); | |
35111 assert.equal(m.isAfter(invalid, 'minute'), false, 'invalid moment minute'); | |
35112 assert.equal(m.isAfter(invalid, 'second'), false, 'invalid moment second'); | |
35113 assert.equal(m.isAfter(invalid, 'milliseconds'), false, 'invalid moment milliseconds'); | |
35114 }); | |
35115 | |
35116 })); | |
35117 | |
35118 (function (global, factory) { | |
35119 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
35120 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
35121 factory(global.moment) | |
35122 }(this, function (moment) { 'use strict'; | |
35123 | |
35124 /*global QUnit:false*/ | |
35125 | |
35126 var test = QUnit.test; | |
35127 | |
35128 function module (name, lifecycle) { | |
35129 QUnit.module(name, { | |
35130 setup : function () { | |
35131 moment.locale('en'); | |
35132 moment.createFromInputFallback = function () { | |
35133 throw new Error('input not handled by moment'); | |
35134 }; | |
35135 if (lifecycle && lifecycle.setup) { | |
35136 lifecycle.setup(); | |
35137 } | |
35138 }, | |
35139 teardown : function () { | |
35140 if (lifecycle && lifecycle.teardown) { | |
35141 lifecycle.teardown(); | |
35142 } | |
35143 } | |
35144 }); | |
35145 } | |
35146 | |
35147 function localeModule (name, lifecycle) { | |
35148 QUnit.module('locale:' + name, { | |
35149 setup : function () { | |
35150 moment.locale(name); | |
35151 moment.createFromInputFallback = function () { | |
35152 throw new Error('input not handled by moment'); | |
35153 }; | |
35154 if (lifecycle && lifecycle.setup) { | |
35155 lifecycle.setup(); | |
35156 } | |
35157 }, | |
35158 teardown : function () { | |
35159 moment.locale('en'); | |
35160 if (lifecycle && lifecycle.teardown) { | |
35161 lifecycle.teardown(); | |
35162 } | |
35163 } | |
35164 }); | |
35165 } | |
35166 | |
35167 module('is before'); | |
35168 | |
35169 test('is after without units', function (assert) { | |
35170 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m); | |
35171 assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 5, 5, 10))), true, 'year is later'); | |
35172 assert.equal(m.isBefore(moment(new Date(2010, 3, 2, 3, 3, 5, 10))), false, 'year is earlier'); | |
35173 assert.equal(m.isBefore(moment(new Date(2011, 4, 2, 3, 4, 5, 10))), true, 'month is later'); | |
35174 assert.equal(m.isBefore(moment(new Date(2011, 2, 2, 3, 4, 5, 10))), false, 'month is earlier'); | |
35175 assert.equal(m.isBefore(moment(new Date(2011, 3, 3, 3, 4, 5, 10))), true, 'day is later'); | |
35176 assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 3, 4, 5, 10))), false, 'day is earlier'); | |
35177 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 4, 4, 5, 10))), true, 'hour is later'); | |
35178 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 2, 4, 5, 10))), false, 'hour is earlier'); | |
35179 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 5, 5, 10))), true, 'minute is later'); | |
35180 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 3, 5, 10))), false, 'minute is earlier'); | |
35181 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 6, 10))), true, 'second is later'); | |
35182 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 4, 11))), false, 'second is earlier'); | |
35183 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'millisecond match'); | |
35184 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 11))), true, 'millisecond is later'); | |
35185 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 9))), false, 'millisecond is earlier'); | |
35186 assert.equal(m.isBefore(m), false, 'moments are not before themselves'); | |
35187 assert.equal(+m, +mCopy, 'isBefore second should not change moment'); | |
35188 }); | |
35189 | |
35190 test('is before year', function (assert) { | |
35191 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m); | |
35192 assert.equal(m.isBefore(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year match'); | |
35193 assert.equal(m.isBefore(moment(new Date(2012, 5, 6, 7, 8, 9, 10)), 'years'), true, 'plural should work'); | |
35194 assert.equal(m.isBefore(moment(new Date(2013, 5, 6, 7, 8, 9, 10)), 'year'), true, 'year is later'); | |
35195 assert.equal(m.isBefore(moment(new Date(2010, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year is earlier'); | |
35196 assert.equal(m.isBefore(moment(new Date(2011, 0, 1, 0, 0, 0, 0)), 'year'), false, 'exact start of year'); | |
35197 assert.equal(m.isBefore(moment(new Date(2011, 11, 31, 23, 59, 59, 999)), 'year'), false, 'exact end of year'); | |
35198 assert.equal(m.isBefore(moment(new Date(2012, 0, 1, 0, 0, 0, 0)), 'year'), true, 'start of next year'); | |
35199 assert.equal(m.isBefore(moment(new Date(2010, 11, 31, 23, 59, 59, 999)), 'year'), false, 'end of previous year'); | |
35200 assert.equal(m.isBefore(moment(new Date(1980, 11, 31, 23, 59, 59, 999)), 'year'), false, 'end of year far before'); | |
35201 assert.equal(m.isBefore(m, 'year'), false, 'same moments are not before the same year'); | |
35202 assert.equal(+m, +mCopy, 'isBefore year should not change moment'); | |
35203 }); | |
35204 | |
35205 test('is before month', function (assert) { | |
35206 var m = moment(new Date(2011, 2, 3, 4, 5, 6, 7)), mCopy = moment(m); | |
35207 assert.equal(m.isBefore(moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'month'), false, 'month match'); | |
35208 assert.equal(m.isBefore(moment(new Date(2012, 2, 6, 7, 8, 9, 10)), 'months'), true, 'plural should work'); | |
35209 assert.equal(m.isBefore(moment(new Date(2012, 2, 6, 7, 8, 9, 10)), 'month'), true, 'year is later'); | |
35210 assert.equal(m.isBefore(moment(new Date(2010, 2, 6, 7, 8, 9, 10)), 'month'), false, 'year is earlier'); | |
35211 assert.equal(m.isBefore(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'month'), true, 'month is later'); | |
35212 assert.equal(m.isBefore(moment(new Date(2011, 1, 6, 7, 8, 9, 10)), 'month'), false, 'month is earlier'); | |
35213 assert.equal(m.isBefore(moment(new Date(2011, 2, 1, 0, 0, 0, 0)), 'month'), false, 'exact start of month'); | |
35214 assert.equal(m.isBefore(moment(new Date(2011, 2, 31, 23, 59, 59, 999)), 'month'), false, 'exact end of month'); | |
35215 assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 0, 0, 0, 0)), 'month'), true, 'start of next month'); | |
35216 assert.equal(m.isBefore(moment(new Date(2011, 1, 27, 23, 59, 59, 999)), 'month'), false, 'end of previous month'); | |
35217 assert.equal(m.isBefore(moment(new Date(2010, 12, 31, 23, 59, 59, 999)), 'month'), false, 'later month but earlier year'); | |
35218 assert.equal(m.isBefore(m, 'month'), false, 'same moments are not before the same month'); | |
35219 assert.equal(+m, +mCopy, 'isBefore month should not change moment'); | |
35220 }); | |
35221 | |
35222 test('is before day', function (assert) { | |
35223 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 6)), mCopy = moment(m); | |
35224 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 7, 8, 9, 10)), 'day'), false, 'day match'); | |
35225 assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 7, 8, 9, 10)), 'days'), true, 'plural should work'); | |
35226 assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 7, 8, 9, 10)), 'day'), true, 'year is later'); | |
35227 assert.equal(m.isBefore(moment(new Date(2010, 3, 2, 7, 8, 9, 10)), 'day'), false, 'year is earlier'); | |
35228 assert.equal(m.isBefore(moment(new Date(2011, 4, 2, 7, 8, 9, 10)), 'day'), true, 'month is later'); | |
35229 assert.equal(m.isBefore(moment(new Date(2011, 2, 2, 7, 8, 9, 10)), 'day'), false, 'month is earlier'); | |
35230 assert.equal(m.isBefore(moment(new Date(2011, 3, 3, 7, 8, 9, 10)), 'day'), true, 'day is later'); | |
35231 assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 7, 8, 9, 10)), 'day'), false, 'day is earlier'); | |
35232 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 0, 0, 0, 0)), 'day'), false, 'exact start of day'); | |
35233 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 23, 59, 59, 999)), 'day'), false, 'exact end of day'); | |
35234 assert.equal(m.isBefore(moment(new Date(2011, 3, 3, 0, 0, 0, 0)), 'day'), true, 'start of next day'); | |
35235 assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 23, 59, 59, 999)), 'day'), false, 'end of previous day'); | |
35236 assert.equal(m.isBefore(moment(new Date(2010, 3, 10, 0, 0, 0, 0)), 'day'), false, 'later day but earlier year'); | |
35237 assert.equal(m.isBefore(m, 'day'), false, 'same moments are not before the same day'); | |
35238 assert.equal(+m, +mCopy, 'isBefore day should not change moment'); | |
35239 }); | |
35240 | |
35241 test('is before hour', function (assert) { | |
35242 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 6)), mCopy = moment(m); | |
35243 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 8, 9, 10)), 'hour'), false, 'hour match'); | |
35244 assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 8, 9, 10)), 'hours'), true, 'plural should work'); | |
35245 assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 8, 9, 10)), 'hour'), true, 'year is later'); | |
35246 assert.equal(m.isBefore(moment(new Date(2010, 3, 2, 3, 8, 9, 10)), 'hour'), false, 'year is earlier'); | |
35247 assert.equal(m.isBefore(moment(new Date(2011, 4, 2, 3, 8, 9, 10)), 'hour'), true, 'month is later'); | |
35248 assert.equal(m.isBefore(moment(new Date(2011, 1, 2, 3, 8, 9, 10)), 'hour'), false, 'month is earlier'); | |
35249 assert.equal(m.isBefore(moment(new Date(2011, 3, 3, 3, 8, 9, 10)), 'hour'), true, 'day is later'); | |
35250 assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 3, 8, 9, 10)), 'hour'), false, 'day is earlier'); | |
35251 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 4, 8, 9, 10)), 'hour'), true, 'hour is later'); | |
35252 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 8, 9, 10)), 'hour'), false, 'hour is earlier'); | |
35253 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 0, 0, 0)), 'hour'), false, 'exact start of hour'); | |
35254 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 59, 59, 999)), 'hour'), false, 'exact end of hour'); | |
35255 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 4, 0, 0, 0)), 'hour'), true, 'start of next hour'); | |
35256 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 2, 59, 59, 999)), 'hour'), false, 'end of previous hour'); | |
35257 assert.equal(m.isBefore(m, 'hour'), false, 'same moments are not before the same hour'); | |
35258 assert.equal(+m, +mCopy, 'isBefore hour should not change moment'); | |
35259 }); | |
35260 | |
35261 test('is before minute', function (assert) { | |
35262 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 6)), mCopy = moment(m); | |
35263 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 9, 10)), 'minute'), false, 'minute match'); | |
35264 assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 4, 9, 10)), 'minutes'), true, 'plural should work'); | |
35265 assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 4, 9, 10)), 'minute'), true, 'year is later'); | |
35266 assert.equal(m.isBefore(moment(new Date(2010, 3, 2, 3, 4, 9, 10)), 'minute'), false, 'year is earlier'); | |
35267 assert.equal(m.isBefore(moment(new Date(2011, 4, 2, 3, 4, 9, 10)), 'minute'), true, 'month is later'); | |
35268 assert.equal(m.isBefore(moment(new Date(2011, 2, 2, 3, 4, 9, 10)), 'minute'), false, 'month is earlier'); | |
35269 assert.equal(m.isBefore(moment(new Date(2011, 3, 3, 3, 4, 9, 10)), 'minute'), true, 'day is later'); | |
35270 assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 3, 4, 9, 10)), 'minute'), false, 'day is earlier'); | |
35271 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 4, 4, 9, 10)), 'minute'), true, 'hour is later'); | |
35272 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 2, 4, 9, 10)), 'minute'), false, 'hour is earler'); | |
35273 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 5, 9, 10)), 'minute'), true, 'minute is later'); | |
35274 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 3, 9, 10)), 'minute'), false, 'minute is earlier'); | |
35275 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 0, 0)), 'minute'), false, 'exact start of minute'); | |
35276 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 59, 999)), 'minute'), false, 'exact end of minute'); | |
35277 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 5, 0, 0)), 'minute'), true, 'start of next minute'); | |
35278 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 3, 59, 999)), 'minute'), false, 'end of previous minute'); | |
35279 assert.equal(m.isBefore(m, 'minute'), false, 'same moments are not before the same minute'); | |
35280 assert.equal(+m, +mCopy, 'isBefore minute should not change moment'); | |
35281 }); | |
35282 | |
35283 test('is before second', function (assert) { | |
35284 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m); | |
35285 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'second'), false, 'second match'); | |
35286 assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'seconds'), true, 'plural should work'); | |
35287 assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'second'), true, 'year is later'); | |
35288 assert.equal(m.isBefore(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'second'), false, 'year is earlier'); | |
35289 assert.equal(m.isBefore(moment(new Date(2011, 4, 2, 3, 4, 5, 10)), 'second'), true, 'month is later'); | |
35290 assert.equal(m.isBefore(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'second'), false, 'month is earlier'); | |
35291 assert.equal(m.isBefore(moment(new Date(2011, 3, 3, 3, 4, 5, 10)), 'second'), true, 'day is later'); | |
35292 assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 1, 4, 5, 10)), 'second'), false, 'day is earlier'); | |
35293 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 4, 4, 5, 10)), 'second'), true, 'hour is later'); | |
35294 assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 4, 1, 5, 10)), 'second'), false, 'hour is earlier'); | |
35295 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 5, 5, 10)), 'second'), true, 'minute is later'); | |
35296 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 3, 5, 10)), 'second'), false, 'minute is earlier'); | |
35297 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 6, 10)), 'second'), true, 'second is later'); | |
35298 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 4, 5)), 'second'), false, 'second is earlier'); | |
35299 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 0)), 'second'), false, 'exact start of second'); | |
35300 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 999)), 'second'), false, 'exact end of second'); | |
35301 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 6, 0)), 'second'), true, 'start of next second'); | |
35302 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 4, 999)), 'second'), false, 'end of previous second'); | |
35303 assert.equal(m.isBefore(m, 'second'), false, 'same moments are not before the same second'); | |
35304 assert.equal(+m, +mCopy, 'isBefore second should not change moment'); | |
35305 }); | |
35306 | |
35307 test('is before millisecond', function (assert) { | |
35308 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m); | |
35309 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'millisecond'), false, 'millisecond match'); | |
35310 assert.equal(m.isBefore(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'milliseconds'), false, 'plural should work'); | |
35311 assert.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'millisecond'), true, 'year is later'); | |
35312 assert.equal(m.isBefore(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'millisecond'), false, 'year is earlier'); | |
35313 assert.equal(m.isBefore(moment(new Date(2011, 4, 2, 3, 4, 5, 10)), 'millisecond'), true, 'month is later'); | |
35314 assert.equal(m.isBefore(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'millisecond'), false, 'month is earlier'); | |
35315 assert.equal(m.isBefore(moment(new Date(2011, 3, 3, 3, 4, 5, 10)), 'millisecond'), true, 'day is later'); | |
35316 assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 1, 4, 5, 10)), 'millisecond'), false, 'day is earlier'); | |
35317 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 4, 4, 5, 10)), 'millisecond'), true, 'hour is later'); | |
35318 assert.equal(m.isBefore(moment(new Date(2011, 3, 1, 4, 1, 5, 10)), 'millisecond'), false, 'hour is earlier'); | |
35319 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 5, 5, 10)), 'millisecond'), true, 'minute is later'); | |
35320 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 3, 5, 10)), 'millisecond'), false, 'minute is earlier'); | |
35321 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 6, 10)), 'millisecond'), true, 'second is later'); | |
35322 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 4, 5)), 'millisecond'), false, 'second is earlier'); | |
35323 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 6, 11)), 'millisecond'), true, 'millisecond is later'); | |
35324 assert.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 4, 9)), 'millisecond'), false, 'millisecond is earlier'); | |
35325 assert.equal(m.isBefore(m, 'millisecond'), false, 'same moments are not before the same millisecond'); | |
35326 assert.equal(+m, +mCopy, 'isBefore millisecond should not change moment'); | |
35327 }); | |
35328 | |
35329 test('is before invalid', function (assert) { | |
35330 var m = moment(), invalid = moment.invalid(); | |
35331 assert.equal(m.isBefore(invalid), false, 'valid moment is not before invalid moment'); | |
35332 assert.equal(invalid.isBefore(m), false, 'invalid moment is not before valid moment'); | |
35333 assert.equal(m.isBefore(invalid, 'year'), false, 'invalid moment year'); | |
35334 assert.equal(m.isBefore(invalid, 'month'), false, 'invalid moment month'); | |
35335 assert.equal(m.isBefore(invalid, 'day'), false, 'invalid moment day'); | |
35336 assert.equal(m.isBefore(invalid, 'hour'), false, 'invalid moment hour'); | |
35337 assert.equal(m.isBefore(invalid, 'minute'), false, 'invalid moment minute'); | |
35338 assert.equal(m.isBefore(invalid, 'second'), false, 'invalid moment second'); | |
35339 assert.equal(m.isBefore(invalid, 'milliseconds'), false, 'invalid moment milliseconds'); | |
35340 }); | |
35341 | |
35342 })); | |
35343 | |
35344 (function (global, factory) { | |
35345 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
35346 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
35347 factory(global.moment) | |
35348 }(this, function (moment) { 'use strict'; | |
35349 | |
35350 /*global QUnit:false*/ | |
35351 | |
35352 var test = QUnit.test; | |
35353 | |
35354 function module (name, lifecycle) { | |
35355 QUnit.module(name, { | |
35356 setup : function () { | |
35357 moment.locale('en'); | |
35358 moment.createFromInputFallback = function () { | |
35359 throw new Error('input not handled by moment'); | |
35360 }; | |
35361 if (lifecycle && lifecycle.setup) { | |
35362 lifecycle.setup(); | |
35363 } | |
35364 }, | |
35365 teardown : function () { | |
35366 if (lifecycle && lifecycle.teardown) { | |
35367 lifecycle.teardown(); | |
35368 } | |
35369 } | |
35370 }); | |
35371 } | |
35372 | |
35373 function localeModule (name, lifecycle) { | |
35374 QUnit.module('locale:' + name, { | |
35375 setup : function () { | |
35376 moment.locale(name); | |
35377 moment.createFromInputFallback = function () { | |
35378 throw new Error('input not handled by moment'); | |
35379 }; | |
35380 if (lifecycle && lifecycle.setup) { | |
35381 lifecycle.setup(); | |
35382 } | |
35383 }, | |
35384 teardown : function () { | |
35385 moment.locale('en'); | |
35386 if (lifecycle && lifecycle.teardown) { | |
35387 lifecycle.teardown(); | |
35388 } | |
35389 } | |
35390 }); | |
35391 } | |
35392 | |
35393 module('is between'); | |
35394 | |
35395 test('is between without units', function (assert) { | |
35396 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m); | |
35397 assert.equal(m.isBetween( | |
35398 moment(new Date(2009, 3, 2, 3, 4, 5, 10)), | |
35399 moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'year is later'); | |
35400 assert.equal(m.isBetween( | |
35401 moment(new Date(2011, 3, 2, 3, 4, 5, 10)), | |
35402 moment(new Date(2013, 3, 2, 3, 4, 5, 10))), false, 'year is earlier'); | |
35403 assert.equal(m.isBetween( | |
35404 moment(new Date(2010, 3, 2, 3, 4, 5, 10)), | |
35405 moment(new Date(2012, 3, 2, 3, 4, 5, 10))), true, 'year is between'); | |
35406 assert.equal(m.isBetween( | |
35407 moment(new Date(2011, 1, 2, 3, 4, 5, 10)), | |
35408 moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'month is later'); | |
35409 assert.equal(m.isBetween( | |
35410 moment(new Date(2011, 3, 2, 3, 4, 5, 10)), | |
35411 moment(new Date(2011, 5, 2, 3, 4, 5, 10))), false, 'month is earlier'); | |
35412 assert.equal(m.isBetween( | |
35413 moment(new Date(2011, 2, 2, 3, 4, 5, 10)), | |
35414 moment(new Date(2011, 4, 2, 3, 4, 5, 10))), true, 'month is between'); | |
35415 assert.equal(m.isBetween( | |
35416 moment(new Date(2011, 3, 1, 3, 4, 5, 10)), | |
35417 moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'day is later'); | |
35418 assert.equal(m.isBetween( | |
35419 moment(new Date(2011, 3, 2, 3, 4, 5, 10)), | |
35420 moment(new Date(2011, 3, 4, 3, 4, 5, 10))), false, 'day is earlier'); | |
35421 assert.equal(m.isBetween( | |
35422 moment(new Date(2011, 3, 1, 3, 4, 5, 10)), | |
35423 moment(new Date(2011, 3, 3, 3, 4, 5, 10))), true, 'day is between'); | |
35424 assert.equal(m.isBetween( | |
35425 moment(new Date(2011, 3, 2, 1, 4, 5, 10)), | |
35426 moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'hour is later'); | |
35427 assert.equal(m.isBetween( | |
35428 moment(new Date(2011, 3, 2, 3, 4, 5, 10)), | |
35429 moment(new Date(2011, 3, 2, 5, 4, 5, 10))), false, 'hour is earlier'); | |
35430 assert.equal(m.isBetween( | |
35431 moment(new Date(2011, 3, 2, 2, 4, 5, 10)), | |
35432 moment(new Date(2011, 3, 2, 4, 4, 5, 10))), true, 'hour is between'); | |
35433 assert.equal(m.isBetween( | |
35434 moment(new Date(2011, 3, 2, 3, 4, 5, 10)), | |
35435 moment(new Date(2011, 3, 2, 3, 6, 5, 10))), false, 'minute is later'); | |
35436 assert.equal(m.isBetween( | |
35437 moment(new Date(2011, 3, 2, 3, 2, 5, 10)), | |
35438 moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'minute is earlier'); | |
35439 assert.equal(m.isBetween( | |
35440 moment(new Date(2011, 3, 2, 3, 3, 5, 10)), | |
35441 moment(new Date(2011, 3, 2, 3, 5, 5, 10))), true, 'minute is between'); | |
35442 assert.equal(m.isBetween( | |
35443 moment(new Date(2011, 3, 2, 3, 4, 5, 10)), | |
35444 moment(new Date(2011, 3, 2, 3, 4, 7, 10))), false, 'second is later'); | |
35445 assert.equal(m.isBetween( | |
35446 moment(new Date(2011, 3, 2, 3, 4, 3, 10)), | |
35447 moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'second is earlier'); | |
35448 assert.equal(m.isBetween( | |
35449 moment(new Date(2011, 3, 2, 3, 4, 4, 10)), | |
35450 moment(new Date(2011, 3, 2, 3, 4, 6, 10))), true, 'second is between'); | |
35451 assert.equal(m.isBetween( | |
35452 moment(new Date(2011, 3, 2, 3, 4, 5, 10)), | |
35453 moment(new Date(2011, 3, 2, 3, 4, 5, 12))), false, 'millisecond is later'); | |
35454 assert.equal(m.isBetween( | |
35455 moment(new Date(2011, 3, 2, 3, 4, 5, 8)), | |
35456 moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, 'millisecond is earlier'); | |
35457 assert.equal(m.isBetween( | |
35458 moment(new Date(2011, 3, 2, 3, 4, 5, 9)), | |
35459 moment(new Date(2011, 3, 2, 3, 4, 5, 11))), true, 'millisecond is between'); | |
35460 assert.equal(m.isBetween(m, m), false, 'moments are not between themselves'); | |
35461 assert.equal(+m, +mCopy, 'isBetween second should not change moment'); | |
35462 }); | |
35463 | |
35464 test('is between year', function (assert) { | |
35465 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m); | |
35466 assert.equal(m.isBetween( | |
35467 moment(new Date(2011, 5, 6, 7, 8, 9, 10)), | |
35468 moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year match'); | |
35469 assert.equal(m.isBetween( | |
35470 moment(new Date(2010, 5, 6, 7, 8, 9, 10)), | |
35471 moment(new Date(2012, 5, 6, 7, 8, 9, 10)), 'years'), true, 'plural should work'); | |
35472 assert.equal(m.isBetween( | |
35473 moment(new Date(2010, 5, 6, 7, 8, 9, 10)), | |
35474 moment(new Date(2012, 5, 6, 7, 8, 9, 10)), 'year'), true, 'year is between'); | |
35475 assert.equal(m.isBetween( | |
35476 moment(new Date(2011, 5, 6, 7, 8, 9, 10)), | |
35477 moment(new Date(2013, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year is earlier'); | |
35478 assert.equal(m.isBetween( | |
35479 moment(new Date(2010, 5, 6, 7, 8, 9, 10)), | |
35480 moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year is later'); | |
35481 assert.equal(m.isBetween(m, 'year'), false, 'same moments are not between the same year'); | |
35482 assert.equal(+m, +mCopy, 'isBetween year should not change moment'); | |
35483 }); | |
35484 | |
35485 test('is between month', function (assert) { | |
35486 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m); | |
35487 assert.equal(m.isBetween( | |
35488 moment(new Date(2011, 1, 6, 7, 8, 9, 10)), | |
35489 moment(new Date(2011, 1, 6, 7, 8, 9, 10)), 'month'), false, 'month match'); | |
35490 assert.equal(m.isBetween( | |
35491 moment(new Date(2011, 0, 6, 7, 8, 9, 10)), | |
35492 moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'months'), true, 'plural should work'); | |
35493 assert.equal(m.isBetween( | |
35494 moment(new Date(2011, 0, 31, 23, 59, 59, 999)), | |
35495 moment(new Date(2011, 2, 1, 0, 0, 0, 0)), 'month'), true, 'month is between'); | |
35496 assert.equal(m.isBetween( | |
35497 moment(new Date(2011, 1, 6, 7, 8, 9, 10)), | |
35498 moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'month'), false, 'month is earlier'); | |
35499 assert.equal(m.isBetween( | |
35500 moment(new Date(2011, 11, 6, 7, 8, 9, 10)), | |
35501 moment(new Date(2011, 1, 6, 7, 8, 9, 10)), 'month'), false, 'month is later'); | |
35502 assert.equal(m.isBetween(m, 'month'), false, 'same moments are not between the same month'); | |
35503 assert.equal(+m, +mCopy, 'isBetween month should not change moment'); | |
35504 }); | |
35505 | |
35506 test('is between day', function (assert) { | |
35507 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m); | |
35508 assert.equal(m.isBetween( | |
35509 moment(new Date(2011, 1, 2, 7, 8, 9, 10)), | |
35510 moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'day'), false, 'day match'); | |
35511 assert.equal(m.isBetween( | |
35512 moment(new Date(2011, 1, 1, 7, 8, 9, 10)), | |
35513 moment(new Date(2011, 1, 3, 7, 8, 9, 10)), 'days'), true, 'plural should work'); | |
35514 assert.equal(m.isBetween( | |
35515 moment(new Date(2011, 1, 1, 7, 8, 9, 10)), | |
35516 moment(new Date(2011, 1, 3, 7, 8, 9, 10)), 'day'), true, 'day is between'); | |
35517 assert.equal(m.isBetween( | |
35518 moment(new Date(2011, 1, 2, 7, 8, 9, 10)), | |
35519 moment(new Date(2011, 1, 4, 7, 8, 9, 10)), 'day'), false, 'day is earlier'); | |
35520 assert.equal(m.isBetween( | |
35521 moment(new Date(2011, 1, 1, 7, 8, 9, 10)), | |
35522 moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'day'), false, 'day is later'); | |
35523 assert.equal(m.isBetween(m, 'day'), false, 'same moments are not between the same day'); | |
35524 assert.equal(+m, +mCopy, 'isBetween day should not change moment'); | |
35525 }); | |
35526 | |
35527 test('is between hour', function (assert) { | |
35528 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m); | |
35529 assert.equal(m.isBetween( | |
35530 moment(new Date(2011, 1, 2, 3, 5, 9, 10)), | |
35531 moment(new Date(2011, 1, 2, 3, 9, 9, 10)), 'hour'), false, 'hour match'); | |
35532 assert.equal(m.isBetween( | |
35533 moment(new Date(2011, 1, 2, 1, 59, 59, 999)), | |
35534 moment(new Date(2011, 1, 2, 4, 0, 0, 0)), 'hours'), true, 'plural should work'); | |
35535 assert.equal(m.isBetween( | |
35536 moment(new Date(2011, 1, 2, 2, 59, 59, 999)), | |
35537 moment(new Date(2011, 1, 2, 4, 0, 0, 0)), 'hour'), true, 'hour is between'); | |
35538 assert.equal(m.isBetween( | |
35539 moment(new Date(2011, 1, 2, 7, 8, 9, 10)), | |
35540 moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'hour'), false, 'hour is earlier'); | |
35541 assert.equal(m.isBetween( | |
35542 moment(new Date(2011, 1, 2, 7, 8, 9, 10)), | |
35543 moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'hour'), false, 'hour is later'); | |
35544 assert.equal(m.isBetween(m, 'hour'), false, 'same moments are not between the same hour'); | |
35545 assert.equal(+m, +mCopy, 'isBetween hour should not change moment'); | |
35546 }); | |
35547 | |
35548 test('is between minute', function (assert) { | |
35549 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m); | |
35550 assert.equal(m.isBetween( | |
35551 moment(new Date(2011, 1, 2, 3, 4, 9, 10)), | |
35552 moment(new Date(2011, 1, 2, 3, 4, 9, 10)), 'minute'), false, 'minute match'); | |
35553 assert.equal(m.isBetween( | |
35554 moment(new Date(2011, 1, 2, 3, 3, 9, 10)), | |
35555 moment(new Date(2011, 1, 2, 3, 5, 9, 10)), 'minutes'), true, 'plural should work'); | |
35556 assert.equal(m.isBetween( | |
35557 moment(new Date(2011, 1, 2, 3, 3, 59, 999)), | |
35558 moment(new Date(2011, 1, 2, 3, 5, 0, 0)), 'minute'), true, 'minute is between'); | |
35559 assert.equal(m.isBetween( | |
35560 moment(new Date(2011, 1, 2, 3, 5, 0, 0)), | |
35561 moment(new Date(2011, 1, 2, 3, 8, 9, 10)), 'minute'), false, 'minute is earlier'); | |
35562 assert.equal(m.isBetween( | |
35563 moment(new Date(2011, 1, 2, 3, 2, 9, 10)), | |
35564 moment(new Date(2011, 1, 2, 3, 3, 59, 999)), 'minute'), false, 'minute is later'); | |
35565 assert.equal(m.isBetween(m, 'minute'), false, 'same moments are not between the same minute'); | |
35566 assert.equal(+m, +mCopy, 'isBetween minute should not change moment'); | |
35567 }); | |
35568 | |
35569 test('is between second', function (assert) { | |
35570 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m); | |
35571 assert.equal(m.isBetween( | |
35572 moment(new Date(2011, 1, 2, 3, 4, 5, 10)), | |
35573 moment(new Date(2011, 1, 2, 3, 4, 5, 10)), 'second'), false, 'second match'); | |
35574 assert.equal(m.isBetween( | |
35575 moment(new Date(2011, 1, 2, 3, 4, 4, 10)), | |
35576 moment(new Date(2011, 1, 2, 3, 4, 6, 10)), 'seconds'), true, 'plural should work'); | |
35577 assert.equal(m.isBetween( | |
35578 moment(new Date(2011, 1, 2, 3, 4, 4, 999)), | |
35579 moment(new Date(2011, 1, 2, 3, 4, 6, 0)), 'second'), true, 'second is between'); | |
35580 assert.equal(m.isBetween( | |
35581 moment(new Date(2011, 1, 2, 3, 4, 6, 0)), | |
35582 moment(new Date(2011, 1, 2, 3, 4, 7, 10)), 'second'), false, 'second is earlier'); | |
35583 assert.equal(m.isBetween( | |
35584 moment(new Date(2011, 1, 2, 3, 4, 3, 10)), | |
35585 moment(new Date(2011, 1, 2, 3, 4, 4, 999)), 'second'), false, 'second is later'); | |
35586 assert.equal(m.isBetween(m, 'second'), false, 'same moments are not between the same second'); | |
35587 assert.equal(+m, +mCopy, 'isBetween second should not change moment'); | |
35588 }); | |
35589 | |
35590 test('is between millisecond', function (assert) { | |
35591 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m); | |
35592 assert.equal(m.isBetween( | |
35593 moment(new Date(2011, 1, 2, 3, 4, 5, 6)), | |
35594 moment(new Date(2011, 1, 2, 3, 4, 5, 6)), 'millisecond'), false, 'millisecond match'); | |
35595 assert.equal(m.isBetween( | |
35596 moment(new Date(2011, 1, 2, 3, 4, 5, 5)), | |
35597 moment(new Date(2011, 1, 2, 3, 4, 5, 7)), 'milliseconds'), true, 'plural should work'); | |
35598 assert.equal(m.isBetween( | |
35599 moment(new Date(2011, 1, 2, 3, 4, 5, 5)), | |
35600 moment(new Date(2011, 1, 2, 3, 4, 5, 7)), 'millisecond'), true, 'millisecond is between'); | |
35601 assert.equal(m.isBetween( | |
35602 moment(new Date(2011, 1, 2, 3, 4, 5, 7)), | |
35603 moment(new Date(2011, 1, 2, 3, 4, 5, 10)), 'millisecond'), false, 'millisecond is earlier'); | |
35604 assert.equal(m.isBetween( | |
35605 moment(new Date(2011, 1, 2, 3, 4, 5, 4)), | |
35606 moment(new Date(2011, 1, 2, 3, 4, 5, 6)), 'millisecond'), false, 'millisecond is later'); | |
35607 assert.equal(m.isBetween(m, 'millisecond'), false, 'same moments are not between the same millisecond'); | |
35608 assert.equal(+m, +mCopy, 'isBetween millisecond should not change moment'); | |
35609 }); | |
35610 | |
35611 })); | |
35612 | |
35613 (function (global, factory) { | |
35614 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
35615 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
35616 factory(global.moment) | |
35617 }(this, function (moment) { 'use strict'; | |
35618 | |
35619 /*global QUnit:false*/ | |
35620 | |
35621 var test = QUnit.test; | |
35622 | |
35623 function module (name, lifecycle) { | |
35624 QUnit.module(name, { | |
35625 setup : function () { | |
35626 moment.locale('en'); | |
35627 moment.createFromInputFallback = function () { | |
35628 throw new Error('input not handled by moment'); | |
35629 }; | |
35630 if (lifecycle && lifecycle.setup) { | |
35631 lifecycle.setup(); | |
35632 } | |
35633 }, | |
35634 teardown : function () { | |
35635 if (lifecycle && lifecycle.teardown) { | |
35636 lifecycle.teardown(); | |
35637 } | |
35638 } | |
35639 }); | |
35640 } | |
35641 | |
35642 function localeModule (name, lifecycle) { | |
35643 QUnit.module('locale:' + name, { | |
35644 setup : function () { | |
35645 moment.locale(name); | |
35646 moment.createFromInputFallback = function () { | |
35647 throw new Error('input not handled by moment'); | |
35648 }; | |
35649 if (lifecycle && lifecycle.setup) { | |
35650 lifecycle.setup(); | |
35651 } | |
35652 }, | |
35653 teardown : function () { | |
35654 moment.locale('en'); | |
35655 if (lifecycle && lifecycle.teardown) { | |
35656 lifecycle.teardown(); | |
35657 } | |
35658 } | |
35659 }); | |
35660 } | |
35661 | |
35662 module('is date'); | |
35663 | |
35664 test('isDate recognizes Date objects', function (assert) { | |
35665 assert.ok(moment.isDate(new Date()), 'no args (now)'); | |
35666 assert.ok(moment.isDate(new Date([2014, 2, 15])), 'array args'); | |
35667 assert.ok(moment.isDate(new Date('2014-03-15')), 'string args'); | |
35668 assert.ok(moment.isDate(new Date('does NOT look like a date')), 'invalid date'); | |
35669 }); | |
35670 | |
35671 test('isDate rejects non-Date objects', function (assert) { | |
35672 assert.ok(!moment.isDate(), 'nothing'); | |
35673 assert.ok(!moment.isDate(undefined), 'undefined'); | |
35674 assert.ok(!moment.isDate(null), 'string args'); | |
35675 assert.ok(!moment.isDate(42), 'number'); | |
35676 assert.ok(!moment.isDate('2014-03-15'), 'string'); | |
35677 assert.ok(!moment.isDate([2014, 2, 15]), 'array'); | |
35678 assert.ok(!moment.isDate({year: 2014, month: 2, day: 15}), 'object'); | |
35679 assert.ok(!moment.isDate({toString: function () { | |
35680 return '[object Date]'; | |
35681 }}), 'lying object'); | |
35682 }); | |
35683 | |
35684 })); | |
35685 | |
35686 (function (global, factory) { | |
35687 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
35688 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
35689 factory(global.moment) | |
35690 }(this, function (moment) { 'use strict'; | |
35691 | |
35692 /*global QUnit:false*/ | |
35693 | |
35694 var test = QUnit.test; | |
35695 | |
35696 function module (name, lifecycle) { | |
35697 QUnit.module(name, { | |
35698 setup : function () { | |
35699 moment.locale('en'); | |
35700 moment.createFromInputFallback = function () { | |
35701 throw new Error('input not handled by moment'); | |
35702 }; | |
35703 if (lifecycle && lifecycle.setup) { | |
35704 lifecycle.setup(); | |
35705 } | |
35706 }, | |
35707 teardown : function () { | |
35708 if (lifecycle && lifecycle.teardown) { | |
35709 lifecycle.teardown(); | |
35710 } | |
35711 } | |
35712 }); | |
35713 } | |
35714 | |
35715 function localeModule (name, lifecycle) { | |
35716 QUnit.module('locale:' + name, { | |
35717 setup : function () { | |
35718 moment.locale(name); | |
35719 moment.createFromInputFallback = function () { | |
35720 throw new Error('input not handled by moment'); | |
35721 }; | |
35722 if (lifecycle && lifecycle.setup) { | |
35723 lifecycle.setup(); | |
35724 } | |
35725 }, | |
35726 teardown : function () { | |
35727 moment.locale('en'); | |
35728 if (lifecycle && lifecycle.teardown) { | |
35729 lifecycle.teardown(); | |
35730 } | |
35731 } | |
35732 }); | |
35733 } | |
35734 | |
35735 module('is moment'); | |
35736 | |
35737 test('is moment object', function (assert) { | |
35738 var MyObj = function () {}, | |
35739 extend = function (a, b) { | |
35740 var i; | |
35741 for (i in b) { | |
35742 a[i] = b[i]; | |
35743 } | |
35744 return a; | |
35745 }; | |
35746 MyObj.prototype.toDate = function () { | |
35747 return new Date(); | |
35748 }; | |
35749 | |
35750 assert.ok(moment.isMoment(moment()), 'simple moment object'); | |
35751 assert.ok(moment.isMoment(moment(null)), 'invalid moment object'); | |
35752 assert.ok(moment.isMoment(extend({}, moment())), 'externally cloned moments are moments'); | |
35753 assert.ok(moment.isMoment(extend({}, moment.utc())), 'externally cloned utc moments are moments'); | |
35754 | |
35755 assert.ok(!moment.isMoment(new MyObj()), 'myObj is not moment object'); | |
35756 assert.ok(!moment.isMoment(moment), 'moment function is not moment object'); | |
35757 assert.ok(!moment.isMoment(new Date()), 'date object is not moment object'); | |
35758 assert.ok(!moment.isMoment(Object), 'Object is not moment object'); | |
35759 assert.ok(!moment.isMoment('foo'), 'string is not moment object'); | |
35760 assert.ok(!moment.isMoment(1), 'number is not moment object'); | |
35761 assert.ok(!moment.isMoment(NaN), 'NaN is not moment object'); | |
35762 assert.ok(!moment.isMoment(null), 'null is not moment object'); | |
35763 assert.ok(!moment.isMoment(undefined), 'undefined is not moment object'); | |
35764 }); | |
35765 | |
35766 test('is moment with hacked hasOwnProperty', function (assert) { | |
35767 var obj = {}; | |
35768 // HACK to suppress jshint warning about bad property name | |
35769 obj['hasOwnMoney'.replace('Money', 'Property')] = function () { | |
35770 return true; | |
35771 }; | |
35772 | |
35773 assert.ok(!moment.isMoment(obj), 'isMoment works even if passed object has a wrong hasOwnProperty implementation (ie8)'); | |
35774 }); | |
35775 | |
35776 })); | |
35777 | |
35778 (function (global, factory) { | |
35779 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
35780 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
35781 factory(global.moment) | |
35782 }(this, function (moment) { 'use strict'; | |
35783 | |
35784 /*global QUnit:false*/ | |
35785 | |
35786 var test = QUnit.test; | |
35787 | |
35788 function module (name, lifecycle) { | |
35789 QUnit.module(name, { | |
35790 setup : function () { | |
35791 moment.locale('en'); | |
35792 moment.createFromInputFallback = function () { | |
35793 throw new Error('input not handled by moment'); | |
35794 }; | |
35795 if (lifecycle && lifecycle.setup) { | |
35796 lifecycle.setup(); | |
35797 } | |
35798 }, | |
35799 teardown : function () { | |
35800 if (lifecycle && lifecycle.teardown) { | |
35801 lifecycle.teardown(); | |
35802 } | |
35803 } | |
35804 }); | |
35805 } | |
35806 | |
35807 function localeModule (name, lifecycle) { | |
35808 QUnit.module('locale:' + name, { | |
35809 setup : function () { | |
35810 moment.locale(name); | |
35811 moment.createFromInputFallback = function () { | |
35812 throw new Error('input not handled by moment'); | |
35813 }; | |
35814 if (lifecycle && lifecycle.setup) { | |
35815 lifecycle.setup(); | |
35816 } | |
35817 }, | |
35818 teardown : function () { | |
35819 moment.locale('en'); | |
35820 if (lifecycle && lifecycle.teardown) { | |
35821 lifecycle.teardown(); | |
35822 } | |
35823 } | |
35824 }); | |
35825 } | |
35826 | |
35827 module('is same'); | |
35828 | |
35829 test('is same without units', function (assert) { | |
35830 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m); | |
35831 assert.equal(m.isSame(moment(new Date(2012, 3, 2, 3, 5, 5, 10))), false, 'year is later'); | |
35832 assert.equal(m.isSame(moment(new Date(2010, 3, 2, 3, 3, 5, 10))), false, 'year is earlier'); | |
35833 assert.equal(m.isSame(moment(new Date(2011, 4, 2, 3, 4, 5, 10))), false, 'month is later'); | |
35834 assert.equal(m.isSame(moment(new Date(2011, 2, 2, 3, 4, 5, 10))), false, 'month is earlier'); | |
35835 assert.equal(m.isSame(moment(new Date(2011, 3, 3, 3, 4, 5, 10))), false, 'day is later'); | |
35836 assert.equal(m.isSame(moment(new Date(2011, 3, 1, 3, 4, 5, 10))), false, 'day is earlier'); | |
35837 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 4, 4, 5, 10))), false, 'hour is later'); | |
35838 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 2, 4, 5, 10))), false, 'hour is earlier'); | |
35839 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 5, 5, 10))), false, 'minute is later'); | |
35840 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 3, 5, 10))), false, 'minute is earlier'); | |
35841 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 6, 10))), false, 'second is later'); | |
35842 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 4, 11))), false, 'second is earlier'); | |
35843 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 5, 10))), true, 'millisecond match'); | |
35844 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 5, 11))), false, 'millisecond is later'); | |
35845 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 5, 9))), false, 'millisecond is earlier'); | |
35846 assert.equal(m.isSame(m), true, 'moments are the same as themselves'); | |
35847 assert.equal(+m, +mCopy, 'isSame second should not change moment'); | |
35848 }); | |
35849 | |
35850 test('is same year', function (assert) { | |
35851 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m); | |
35852 assert.equal(m.isSame(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'year'), true, 'year match'); | |
35853 assert.equal(m.isSame(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'years'), true, 'plural should work'); | |
35854 assert.equal(m.isSame(moment(new Date(2012, 5, 6, 7, 8, 9, 10)), 'year'), false, 'year mismatch'); | |
35855 assert.equal(m.isSame(moment(new Date(2011, 0, 1, 0, 0, 0, 0)), 'year'), true, 'exact start of year'); | |
35856 assert.equal(m.isSame(moment(new Date(2011, 11, 31, 23, 59, 59, 999)), 'year'), true, 'exact end of year'); | |
35857 assert.equal(m.isSame(moment(new Date(2012, 0, 1, 0, 0, 0, 0)), 'year'), false, 'start of next year'); | |
35858 assert.equal(m.isSame(moment(new Date(2010, 11, 31, 23, 59, 59, 999)), 'year'), false, 'end of previous year'); | |
35859 assert.equal(m.isSame(m, 'year'), true, 'same moments are in the same year'); | |
35860 assert.equal(+m, +mCopy, 'isSame year should not change moment'); | |
35861 }); | |
35862 | |
35863 test('is same month', function (assert) { | |
35864 var m = moment(new Date(2011, 2, 3, 4, 5, 6, 7)), mCopy = moment(m); | |
35865 assert.equal(m.isSame(moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'month'), true, 'month match'); | |
35866 assert.equal(m.isSame(moment(new Date(2011, 2, 6, 7, 8, 9, 10)), 'months'), true, 'plural should work'); | |
35867 assert.equal(m.isSame(moment(new Date(2012, 2, 6, 7, 8, 9, 10)), 'month'), false, 'year mismatch'); | |
35868 assert.equal(m.isSame(moment(new Date(2011, 5, 6, 7, 8, 9, 10)), 'month'), false, 'month mismatch'); | |
35869 assert.equal(m.isSame(moment(new Date(2011, 2, 1, 0, 0, 0, 0)), 'month'), true, 'exact start of month'); | |
35870 assert.equal(m.isSame(moment(new Date(2011, 2, 31, 23, 59, 59, 999)), 'month'), true, 'exact end of month'); | |
35871 assert.equal(m.isSame(moment(new Date(2011, 3, 1, 0, 0, 0, 0)), 'month'), false, 'start of next month'); | |
35872 assert.equal(m.isSame(moment(new Date(2011, 1, 27, 23, 59, 59, 999)), 'month'), false, 'end of previous month'); | |
35873 assert.equal(m.isSame(m, 'month'), true, 'same moments are in the same month'); | |
35874 assert.equal(+m, +mCopy, 'isSame month should not change moment'); | |
35875 }); | |
35876 | |
35877 test('is same day', function (assert) { | |
35878 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m); | |
35879 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'day'), true, 'day match'); | |
35880 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 7, 8, 9, 10)), 'days'), true, 'plural should work'); | |
35881 assert.equal(m.isSame(moment(new Date(2012, 1, 2, 7, 8, 9, 10)), 'day'), false, 'year mismatch'); | |
35882 assert.equal(m.isSame(moment(new Date(2011, 2, 2, 7, 8, 9, 10)), 'day'), false, 'month mismatch'); | |
35883 assert.equal(m.isSame(moment(new Date(2011, 1, 3, 7, 8, 9, 10)), 'day'), false, 'day mismatch'); | |
35884 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 0, 0, 0, 0)), 'day'), true, 'exact start of day'); | |
35885 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 23, 59, 59, 999)), 'day'), true, 'exact end of day'); | |
35886 assert.equal(m.isSame(moment(new Date(2011, 1, 3, 0, 0, 0, 0)), 'day'), false, 'start of next day'); | |
35887 assert.equal(m.isSame(moment(new Date(2011, 1, 1, 23, 59, 59, 999)), 'day'), false, 'end of previous day'); | |
35888 assert.equal(m.isSame(m, 'day'), true, 'same moments are in the same day'); | |
35889 assert.equal(+m, +mCopy, 'isSame day should not change moment'); | |
35890 }); | |
35891 | |
35892 test('is same hour', function (assert) { | |
35893 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m); | |
35894 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 8, 9, 10)), 'hour'), true, 'hour match'); | |
35895 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 8, 9, 10)), 'hours'), true, 'plural should work'); | |
35896 assert.equal(m.isSame(moment(new Date(2012, 1, 2, 3, 8, 9, 10)), 'hour'), false, 'year mismatch'); | |
35897 assert.equal(m.isSame(moment(new Date(2011, 2, 2, 3, 8, 9, 10)), 'hour'), false, 'month mismatch'); | |
35898 assert.equal(m.isSame(moment(new Date(2011, 1, 3, 3, 8, 9, 10)), 'hour'), false, 'day mismatch'); | |
35899 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 4, 8, 9, 10)), 'hour'), false, 'hour mismatch'); | |
35900 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 0, 0, 0)), 'hour'), true, 'exact start of hour'); | |
35901 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 59, 59, 999)), 'hour'), true, 'exact end of hour'); | |
35902 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 4, 0, 0, 0)), 'hour'), false, 'start of next hour'); | |
35903 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 2, 59, 59, 999)), 'hour'), false, 'end of previous hour'); | |
35904 assert.equal(m.isSame(m, 'hour'), true, 'same moments are in the same hour'); | |
35905 assert.equal(+m, +mCopy, 'isSame hour should not change moment'); | |
35906 }); | |
35907 | |
35908 test('is same minute', function (assert) { | |
35909 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m); | |
35910 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 9, 10)), 'minute'), true, 'minute match'); | |
35911 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 9, 10)), 'minutes'), true, 'plural should work'); | |
35912 assert.equal(m.isSame(moment(new Date(2012, 1, 2, 3, 4, 9, 10)), 'minute'), false, 'year mismatch'); | |
35913 assert.equal(m.isSame(moment(new Date(2011, 2, 2, 3, 4, 9, 10)), 'minute'), false, 'month mismatch'); | |
35914 assert.equal(m.isSame(moment(new Date(2011, 1, 3, 3, 4, 9, 10)), 'minute'), false, 'day mismatch'); | |
35915 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 4, 4, 9, 10)), 'minute'), false, 'hour mismatch'); | |
35916 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 5, 9, 10)), 'minute'), false, 'minute mismatch'); | |
35917 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 0, 0)), 'minute'), true, 'exact start of minute'); | |
35918 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 59, 999)), 'minute'), true, 'exact end of minute'); | |
35919 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 5, 0, 0)), 'minute'), false, 'start of next minute'); | |
35920 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 3, 59, 999)), 'minute'), false, 'end of previous minute'); | |
35921 assert.equal(m.isSame(m, 'minute'), true, 'same moments are in the same minute'); | |
35922 assert.equal(+m, +mCopy, 'isSame minute should not change moment'); | |
35923 }); | |
35924 | |
35925 test('is same second', function (assert) { | |
35926 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m); | |
35927 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 5, 10)), 'second'), true, 'second match'); | |
35928 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 5, 10)), 'seconds'), true, 'plural should work'); | |
35929 assert.equal(m.isSame(moment(new Date(2012, 1, 2, 3, 4, 5, 10)), 'second'), false, 'year mismatch'); | |
35930 assert.equal(m.isSame(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'second'), false, 'month mismatch'); | |
35931 assert.equal(m.isSame(moment(new Date(2011, 1, 3, 3, 4, 5, 10)), 'second'), false, 'day mismatch'); | |
35932 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 4, 4, 5, 10)), 'second'), false, 'hour mismatch'); | |
35933 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 5, 5, 10)), 'second'), false, 'minute mismatch'); | |
35934 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 6, 10)), 'second'), false, 'second mismatch'); | |
35935 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 5, 0)), 'second'), true, 'exact start of second'); | |
35936 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 5, 999)), 'second'), true, 'exact end of second'); | |
35937 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 6, 0)), 'second'), false, 'start of next second'); | |
35938 assert.equal(m.isSame(moment(new Date(2011, 1, 2, 3, 4, 4, 999)), 'second'), false, 'end of previous second'); | |
35939 assert.equal(m.isSame(m, 'second'), true, 'same moments are in the same second'); | |
35940 assert.equal(+m, +mCopy, 'isSame second should not change moment'); | |
35941 }); | |
35942 | |
35943 test('is same millisecond', function (assert) { | |
35944 var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m); | |
35945 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'millisecond'), true, 'millisecond match'); | |
35946 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 5, 10)), 'milliseconds'), true, 'plural should work'); | |
35947 assert.equal(m.isSame(moment(new Date(2012, 3, 2, 3, 4, 5, 10)), 'millisecond'), false, 'year is later'); | |
35948 assert.equal(m.isSame(moment(new Date(2010, 3, 2, 3, 4, 5, 10)), 'millisecond'), false, 'year is earlier'); | |
35949 assert.equal(m.isSame(moment(new Date(2011, 4, 2, 3, 4, 5, 10)), 'millisecond'), false, 'month is later'); | |
35950 assert.equal(m.isSame(moment(new Date(2011, 2, 2, 3, 4, 5, 10)), 'millisecond'), false, 'month is earlier'); | |
35951 assert.equal(m.isSame(moment(new Date(2011, 3, 3, 3, 4, 5, 10)), 'millisecond'), false, 'day is later'); | |
35952 assert.equal(m.isSame(moment(new Date(2011, 3, 1, 1, 4, 5, 10)), 'millisecond'), false, 'day is earlier'); | |
35953 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 4, 4, 5, 10)), 'millisecond'), false, 'hour is later'); | |
35954 assert.equal(m.isSame(moment(new Date(2011, 3, 1, 4, 1, 5, 10)), 'millisecond'), false, 'hour is earlier'); | |
35955 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 5, 5, 10)), 'millisecond'), false, 'minute is later'); | |
35956 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 3, 5, 10)), 'millisecond'), false, 'minute is earlier'); | |
35957 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 6, 10)), 'millisecond'), false, 'second is later'); | |
35958 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 4, 5)), 'millisecond'), false, 'second is earlier'); | |
35959 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 6, 11)), 'millisecond'), false, 'millisecond is later'); | |
35960 assert.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 4, 9)), 'millisecond'), false, 'millisecond is earlier'); | |
35961 assert.equal(m.isSame(m, 'millisecond'), true, 'same moments are in the same millisecond'); | |
35962 assert.equal(+m, +mCopy, 'isSame millisecond should not change moment'); | |
35963 }); | |
35964 | |
35965 test('is same with utc offset moments', function (assert) { | |
35966 assert.ok(moment.parseZone('2013-02-01T-05:00').isSame(moment('2013-02-01'), 'year'), 'zoned vs local moment'); | |
35967 assert.ok(moment('2013-02-01').isSame(moment('2013-02-01').utcOffset('-05:00'), 'year'), 'local vs zoned moment'); | |
35968 assert.ok(moment.parseZone('2013-02-01T-05:00').isSame(moment.parseZone('2013-02-01T-06:30'), 'year'), | |
35969 'zoned vs (differently) zoned moment'); | |
35970 }); | |
35971 | |
35972 test('is same with invalid moments', function (assert) { | |
35973 assert.equal(moment.invalid().isSame(moment.invalid()), false, 'invalid moments are not considered equal'); | |
35974 }); | |
35975 | |
35976 })); | |
35977 | |
35978 (function (global, factory) { | |
35979 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
35980 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
35981 factory(global.moment) | |
35982 }(this, function (moment) { 'use strict'; | |
35983 | |
35984 /*global QUnit:false*/ | |
35985 | |
35986 var test = QUnit.test; | |
35987 | |
35988 function module (name, lifecycle) { | |
35989 QUnit.module(name, { | |
35990 setup : function () { | |
35991 moment.locale('en'); | |
35992 moment.createFromInputFallback = function () { | |
35993 throw new Error('input not handled by moment'); | |
35994 }; | |
35995 if (lifecycle && lifecycle.setup) { | |
35996 lifecycle.setup(); | |
35997 } | |
35998 }, | |
35999 teardown : function () { | |
36000 if (lifecycle && lifecycle.teardown) { | |
36001 lifecycle.teardown(); | |
36002 } | |
36003 } | |
36004 }); | |
36005 } | |
36006 | |
36007 function localeModule (name, lifecycle) { | |
36008 QUnit.module('locale:' + name, { | |
36009 setup : function () { | |
36010 moment.locale(name); | |
36011 moment.createFromInputFallback = function () { | |
36012 throw new Error('input not handled by moment'); | |
36013 }; | |
36014 if (lifecycle && lifecycle.setup) { | |
36015 lifecycle.setup(); | |
36016 } | |
36017 }, | |
36018 teardown : function () { | |
36019 moment.locale('en'); | |
36020 if (lifecycle && lifecycle.teardown) { | |
36021 lifecycle.teardown(); | |
36022 } | |
36023 } | |
36024 }); | |
36025 } | |
36026 | |
36027 module('is valid'); | |
36028 | |
36029 test('array bad month', function (assert) { | |
36030 assert.equal(moment([2010, -1]).isValid(), false, 'month -1 invalid'); | |
36031 assert.equal(moment([2100, 12]).isValid(), false, 'month 12 invalid'); | |
36032 }); | |
36033 | |
36034 test('array good month', function (assert) { | |
36035 for (var i = 0; i < 12; i++) { | |
36036 assert.equal(moment([2010, i]).isValid(), true, 'month ' + i); | |
36037 assert.equal(moment.utc([2010, i]).isValid(), true, 'month ' + i); | |
36038 } | |
36039 }); | |
36040 | |
36041 test('array bad date', function (assert) { | |
36042 var tests = [ | |
36043 moment([2010, 0, 0]), | |
36044 moment([2100, 0, 32]), | |
36045 moment.utc([2010, 0, 0]), | |
36046 moment.utc([2100, 0, 32]) | |
36047 ], | |
36048 i, m; | |
36049 | |
36050 for (i in tests) { | |
36051 m = tests[i]; | |
36052 assert.equal(m.isValid(), false); | |
36053 } | |
36054 }); | |
36055 | |
36056 test('h/hh with hour > 12', function (assert) { | |
36057 assert.ok(moment('06/20/2014 11:51 PM', 'MM/DD/YYYY hh:mm A', true).isValid(), '11 for hh'); | |
36058 assert.ok(moment('06/20/2014 11:51 AM', 'MM/DD/YYYY hh:mm A', true).isValid(), '11 for hh'); | |
36059 assert.ok(moment('06/20/2014 23:51 PM', 'MM/DD/YYYY hh:mm A').isValid(), 'non-strict validity 23 for hh'); | |
36060 assert.ok(moment('06/20/2014 23:51 PM', 'MM/DD/YYYY hh:mm A').parsingFlags().bigHour, 'non-strict bigHour 23 for hh'); | |
36061 assert.ok(!moment('06/20/2014 23:51 PM', 'MM/DD/YYYY hh:mm A', true).isValid(), 'validity 23 for hh'); | |
36062 assert.ok(moment('06/20/2014 23:51 PM', 'MM/DD/YYYY hh:mm A', true).parsingFlags().bigHour, 'bigHour 23 for hh'); | |
36063 }); | |
36064 | |
36065 test('array bad date leap year', function (assert) { | |
36066 assert.equal(moment([2010, 1, 29]).isValid(), false, '2010 feb 29'); | |
36067 assert.equal(moment([2100, 1, 29]).isValid(), false, '2100 feb 29'); | |
36068 assert.equal(moment([2008, 1, 30]).isValid(), false, '2008 feb 30'); | |
36069 assert.equal(moment([2000, 1, 30]).isValid(), false, '2000 feb 30'); | |
36070 | |
36071 assert.equal(moment.utc([2010, 1, 29]).isValid(), false, 'utc 2010 feb 29'); | |
36072 assert.equal(moment.utc([2100, 1, 29]).isValid(), false, 'utc 2100 feb 29'); | |
36073 assert.equal(moment.utc([2008, 1, 30]).isValid(), false, 'utc 2008 feb 30'); | |
36074 assert.equal(moment.utc([2000, 1, 30]).isValid(), false, 'utc 2000 feb 30'); | |
36075 }); | |
36076 | |
36077 test('string + formats bad date', function (assert) { | |
36078 assert.equal(moment('2020-00-00', []).isValid(), false, 'invalid on empty array'); | |
36079 assert.equal(moment('2020-00-00', ['YYYY-MM-DD', 'DD-MM-YYYY']).isValid(), false, 'invalid on all in array'); | |
36080 assert.equal(moment('2020-00-00', ['DD-MM-YYYY', 'YYYY-MM-DD']).isValid(), false, 'invalid on all in array'); | |
36081 assert.equal(moment('2020-01-01', ['YYYY-MM-DD', 'DD-MM-YYYY']).isValid(), true, 'valid on first'); | |
36082 assert.equal(moment('2020-01-01', ['DD-MM-YYYY', 'YYYY-MM-DD']).isValid(), true, 'valid on last'); | |
36083 assert.equal(moment('2020-01-01', ['YYYY-MM-DD', 'YYYY-DD-MM']).isValid(), true, 'valid on both'); | |
36084 assert.equal(moment('2020-13-01', ['YYYY-MM-DD', 'YYYY-DD-MM']).isValid(), true, 'valid on last'); | |
36085 | |
36086 assert.equal(moment('12-13-2012', ['DD-MM-YYYY', 'YYYY-MM-DD']).isValid(), false, 'month rollover'); | |
36087 assert.equal(moment('12-13-2012', ['DD-MM-YYYY', 'DD-MM-YYYY']).isValid(), false, 'month rollover'); | |
36088 assert.equal(moment('38-12-2012', ['DD-MM-YYYY']).isValid(), false, 'day rollover'); | |
36089 }); | |
36090 | |
36091 test('string nonsensical with format', function (assert) { | |
36092 assert.equal(moment('fail', 'MM-DD-YYYY').isValid(), false, 'string \'fail\' with format \'MM-DD-YYYY\''); | |
36093 assert.equal(moment('xx-xx-2001', 'DD-MM-YYY').isValid(), true, 'string \'xx-xx-2001\' with format \'MM-DD-YYYY\''); | |
36094 }); | |
36095 | |
36096 test('string with bad month name', function (assert) { | |
36097 assert.equal(moment('01-Nam-2012', 'DD-MMM-YYYY').isValid(), false, '\'Nam\' is an invalid month'); | |
36098 assert.equal(moment('01-Aug-2012', 'DD-MMM-YYYY').isValid(), true, '\'Aug\' is a valid month'); | |
36099 }); | |
36100 | |
36101 test('string with spaceless format', function (assert) { | |
36102 assert.equal(moment('10Sep2001', 'DDMMMYYYY').isValid(), true, 'Parsing 10Sep2001 should result in a valid date'); | |
36103 }); | |
36104 | |
36105 test('invalid string iso 8601', function (assert) { | |
36106 var tests = [ | |
36107 '2010-00-00', | |
36108 '2010-01-00', | |
36109 '2010-01-40', | |
36110 '2010-01-01T24:01', // 24:00:00 is actually valid | |
36111 '2010-01-01T23:60', | |
36112 '2010-01-01T23:59:60' | |
36113 ], i; | |
36114 | |
36115 for (i = 0; i < tests.length; i++) { | |
36116 assert.equal(moment(tests[i]).isValid(), false, tests[i] + ' should be invalid'); | |
36117 assert.equal(moment.utc(tests[i]).isValid(), false, tests[i] + ' should be invalid'); | |
36118 } | |
36119 }); | |
36120 | |
36121 test('invalid string iso 8601 + timezone', function (assert) { | |
36122 var tests = [ | |
36123 '2010-00-00T+00:00', | |
36124 '2010-01-00T+00:00', | |
36125 '2010-01-40T+00:00', | |
36126 '2010-01-40T24:01+00:00', | |
36127 '2010-01-40T23:60+00:00', | |
36128 '2010-01-40T23:59:60+00:00', | |
36129 '2010-01-40T23:59:59.9999+00:00' | |
36130 ], i; | |
36131 | |
36132 for (i = 0; i < tests.length; i++) { | |
36133 assert.equal(moment(tests[i]).isValid(), false, tests[i] + ' should be invalid'); | |
36134 assert.equal(moment.utc(tests[i]).isValid(), false, tests[i] + ' should be invalid'); | |
36135 } | |
36136 }); | |
36137 | |
36138 test('valid string iso 8601 + timezone', function (assert) { | |
36139 var tests = [ | |
36140 '2010-01-01', | |
36141 '2010-01-30', | |
36142 '2010-01-30T23+00:00', | |
36143 '2010-01-30T23:59+00:00', | |
36144 '2010-01-30T23:59:59+00:00', | |
36145 '2010-01-30T23:59:59.999+00:00', | |
36146 '2010-01-30T23:59:59.999-07:00', | |
36147 '2010-01-30T00:00:00.000+07:00', | |
36148 '2010-01-30 00:00:00.000Z' | |
36149 ], i; | |
36150 | |
36151 for (i = 0; i < tests.length; i++) { | |
36152 assert.equal(moment(tests[i]).isValid(), true, tests[i] + ' should be valid in normal'); | |
36153 assert.equal(moment.utc(tests[i]).isValid(), true, tests[i] + ' should be valid in normal'); | |
36154 assert.equal(moment(tests[i], moment.ISO_8601, true).isValid(), true, tests[i] + ' should be valid in strict'); | |
36155 assert.equal(moment.utc(tests[i], moment.ISO_8601, true).isValid(), true, tests[i] + ' should be valid in strict'); | |
36156 } | |
36157 }); | |
36158 | |
36159 test('invalidAt', function (assert) { | |
36160 assert.equal(moment([2000, 12]).invalidAt(), 1, 'month 12 is invalid: 0-11'); | |
36161 assert.equal(moment([2000, 1, 30]).invalidAt(), 2, '30 is not a valid february day'); | |
36162 assert.equal(moment([2000, 1, 29, 25]).invalidAt(), 3, '25 is invalid hour'); | |
36163 assert.equal(moment([2000, 1, 29, 24, 1]).invalidAt(), 3, '24:01 is invalid hour'); | |
36164 assert.equal(moment([2000, 1, 29, 23, 60]).invalidAt(), 4, '60 is invalid minute'); | |
36165 assert.equal(moment([2000, 1, 29, 23, 59, 60]).invalidAt(), 5, '60 is invalid second'); | |
36166 assert.equal(moment([2000, 1, 29, 23, 59, 59, 1000]).invalidAt(), 6, '1000 is invalid millisecond'); | |
36167 assert.equal(moment([2000, 1, 29, 23, 59, 59, 999]).invalidAt(), -1, '-1 if everything is fine'); | |
36168 }); | |
36169 | |
36170 test('valid Unix timestamp', function (assert) { | |
36171 assert.equal(moment(1371065286, 'X').isValid(), true, 'number integer'); | |
36172 assert.equal(moment(1379066897.0, 'X').isValid(), true, 'number whole 1dp'); | |
36173 assert.equal(moment(1379066897.7, 'X').isValid(), true, 'number 1dp'); | |
36174 assert.equal(moment(1379066897.00, 'X').isValid(), true, 'number whole 2dp'); | |
36175 assert.equal(moment(1379066897.07, 'X').isValid(), true, 'number 2dp'); | |
36176 assert.equal(moment(1379066897.17, 'X').isValid(), true, 'number 2dp'); | |
36177 assert.equal(moment(1379066897.000, 'X').isValid(), true, 'number whole 3dp'); | |
36178 assert.equal(moment(1379066897.007, 'X').isValid(), true, 'number 3dp'); | |
36179 assert.equal(moment(1379066897.017, 'X').isValid(), true, 'number 3dp'); | |
36180 assert.equal(moment(1379066897.157, 'X').isValid(), true, 'number 3dp'); | |
36181 assert.equal(moment('1371065286', 'X').isValid(), true, 'string integer'); | |
36182 assert.equal(moment('1379066897.', 'X').isValid(), true, 'string trailing .'); | |
36183 assert.equal(moment('1379066897.0', 'X').isValid(), true, 'string whole 1dp'); | |
36184 assert.equal(moment('1379066897.7', 'X').isValid(), true, 'string 1dp'); | |
36185 assert.equal(moment('1379066897.00', 'X').isValid(), true, 'string whole 2dp'); | |
36186 assert.equal(moment('1379066897.07', 'X').isValid(), true, 'string 2dp'); | |
36187 assert.equal(moment('1379066897.17', 'X').isValid(), true, 'string 2dp'); | |
36188 assert.equal(moment('1379066897.000', 'X').isValid(), true, 'string whole 3dp'); | |
36189 assert.equal(moment('1379066897.007', 'X').isValid(), true, 'string 3dp'); | |
36190 assert.equal(moment('1379066897.017', 'X').isValid(), true, 'string 3dp'); | |
36191 assert.equal(moment('1379066897.157', 'X').isValid(), true, 'string 3dp'); | |
36192 }); | |
36193 | |
36194 test('invalid Unix timestamp', function (assert) { | |
36195 assert.equal(moment(undefined, 'X').isValid(), false, 'undefined'); | |
36196 assert.equal(moment('undefined', 'X').isValid(), false, 'string undefined'); | |
36197 try { | |
36198 assert.equal(moment(null, 'X').isValid(), false, 'null'); | |
36199 } catch (e) { | |
36200 assert.ok(true, 'null'); | |
36201 } | |
36202 | |
36203 assert.equal(moment('null', 'X').isValid(), false, 'string null'); | |
36204 assert.equal(moment([], 'X').isValid(), false, 'array'); | |
36205 assert.equal(moment('{}', 'X').isValid(), false, 'object'); | |
36206 try { | |
36207 assert.equal(moment('', 'X').isValid(), false, 'string empty'); | |
36208 } catch (e) { | |
36209 assert.ok(true, 'string empty'); | |
36210 } | |
36211 | |
36212 assert.equal(moment(' ', 'X').isValid(), false, 'string space'); | |
36213 }); | |
36214 | |
36215 test('valid Unix offset milliseconds', function (assert) { | |
36216 assert.equal(moment(1234567890123, 'x').isValid(), true, 'number integer'); | |
36217 assert.equal(moment('1234567890123', 'x').isValid(), true, 'string integer'); | |
36218 }); | |
36219 | |
36220 test('invalid Unix offset milliseconds', function (assert) { | |
36221 assert.equal(moment(undefined, 'x').isValid(), false, 'undefined'); | |
36222 assert.equal(moment('undefined', 'x').isValid(), false, 'string undefined'); | |
36223 try { | |
36224 assert.equal(moment(null, 'x').isValid(), false, 'null'); | |
36225 } catch (e) { | |
36226 assert.ok(true, 'null'); | |
36227 } | |
36228 | |
36229 assert.equal(moment('null', 'x').isValid(), false, 'string null'); | |
36230 assert.equal(moment([], 'x').isValid(), false, 'array'); | |
36231 assert.equal(moment('{}', 'x').isValid(), false, 'object'); | |
36232 try { | |
36233 assert.equal(moment('', 'x').isValid(), false, 'string empty'); | |
36234 } catch (e) { | |
36235 assert.ok(true, 'string empty'); | |
36236 } | |
36237 | |
36238 assert.equal(moment(' ', 'x').isValid(), false, 'string space'); | |
36239 }); | |
36240 | |
36241 test('empty', function (assert) { | |
36242 assert.equal(moment(null).isValid(), false, 'null'); | |
36243 assert.equal(moment('').isValid(), false, 'empty string'); | |
36244 assert.equal(moment(null, 'YYYY').isValid(), false, 'format + null'); | |
36245 assert.equal(moment('', 'YYYY').isValid(), false, 'format + empty string'); | |
36246 assert.equal(moment(' ', 'YYYY').isValid(), false, 'format + empty when trimmed'); | |
36247 }); | |
36248 | |
36249 test('days of the year', function (assert) { | |
36250 assert.equal(moment('2010 300', 'YYYY DDDD').isValid(), true, 'day 300 of year valid'); | |
36251 assert.equal(moment('2010 365', 'YYYY DDDD').isValid(), true, 'day 365 of year valid'); | |
36252 assert.equal(moment('2010 366', 'YYYY DDDD').isValid(), false, 'day 366 of year invalid'); | |
36253 assert.equal(moment('2012 365', 'YYYY DDDD').isValid(), true, 'day 365 of leap year valid'); | |
36254 assert.equal(moment('2012 366', 'YYYY DDDD').isValid(), true, 'day 366 of leap year valid'); | |
36255 assert.equal(moment('2012 367', 'YYYY DDDD').isValid(), false, 'day 367 of leap year invalid'); | |
36256 }); | |
36257 | |
36258 test('24:00:00.000 is valid', function (assert) { | |
36259 assert.equal(moment('2014-01-01 24', 'YYYY-MM-DD HH').isValid(), true, '24 is valid'); | |
36260 assert.equal(moment('2014-01-01 24:00', 'YYYY-MM-DD HH:mm').isValid(), true, '24:00 is valid'); | |
36261 assert.equal(moment('2014-01-01 24:01', 'YYYY-MM-DD HH:mm').isValid(), false, '24:01 is not valid'); | |
36262 }); | |
36263 | |
36264 test('oddball permissiveness', function (assert) { | |
36265 //https://github.com/moment/moment/issues/1128 | |
36266 assert.ok(moment('2010-10-3199', ['MM/DD/YYYY', 'MM-DD-YYYY', 'YYYY-MM-DD']).isValid()); | |
36267 | |
36268 //https://github.com/moment/moment/issues/1122 | |
36269 assert.ok(moment('3:25', ['h:mma', 'hh:mma', 'H:mm', 'HH:mm']).isValid()); | |
36270 }); | |
36271 | |
36272 test('0 hour is invalid in strict', function (assert) { | |
36273 assert.equal(moment('00:01', 'hh:mm', true).isValid(), false, '00 hour is invalid in strict'); | |
36274 assert.equal(moment('00:01', 'hh:mm').isValid(), true, '00 hour is valid in normal'); | |
36275 assert.equal(moment('0:01', 'h:mm', true).isValid(), false, '0 hour is invalid in strict'); | |
36276 assert.equal(moment('0:01', 'h:mm').isValid(), true, '0 hour is valid in normal'); | |
36277 }); | |
36278 | |
36279 })); | |
36280 | |
36281 (function (global, factory) { | |
36282 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
36283 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
36284 factory(global.moment) | |
36285 }(this, function (moment) { 'use strict'; | |
36286 | |
36287 /*global QUnit:false*/ | |
36288 | |
36289 var test = QUnit.test; | |
36290 | |
36291 function module (name, lifecycle) { | |
36292 QUnit.module(name, { | |
36293 setup : function () { | |
36294 moment.locale('en'); | |
36295 moment.createFromInputFallback = function () { | |
36296 throw new Error('input not handled by moment'); | |
36297 }; | |
36298 if (lifecycle && lifecycle.setup) { | |
36299 lifecycle.setup(); | |
36300 } | |
36301 }, | |
36302 teardown : function () { | |
36303 if (lifecycle && lifecycle.teardown) { | |
36304 lifecycle.teardown(); | |
36305 } | |
36306 } | |
36307 }); | |
36308 } | |
36309 | |
36310 function localeModule (name, lifecycle) { | |
36311 QUnit.module('locale:' + name, { | |
36312 setup : function () { | |
36313 moment.locale(name); | |
36314 moment.createFromInputFallback = function () { | |
36315 throw new Error('input not handled by moment'); | |
36316 }; | |
36317 if (lifecycle && lifecycle.setup) { | |
36318 lifecycle.setup(); | |
36319 } | |
36320 }, | |
36321 teardown : function () { | |
36322 moment.locale('en'); | |
36323 if (lifecycle && lifecycle.teardown) { | |
36324 lifecycle.teardown(); | |
36325 } | |
36326 } | |
36327 }); | |
36328 } | |
36329 | |
36330 module('leap year'); | |
36331 | |
36332 test('leap year', function (assert) { | |
36333 assert.equal(moment([2010, 0, 1]).isLeapYear(), false, '2010'); | |
36334 assert.equal(moment([2100, 0, 1]).isLeapYear(), false, '2100'); | |
36335 assert.equal(moment([2008, 0, 1]).isLeapYear(), true, '2008'); | |
36336 assert.equal(moment([2000, 0, 1]).isLeapYear(), true, '2000'); | |
36337 }); | |
36338 | |
36339 })); | |
36340 | |
36341 (function (global, factory) { | |
36342 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
36343 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
36344 factory(global.moment) | |
36345 }(this, function (moment) { 'use strict'; | |
36346 | |
36347 /*global QUnit:false*/ | |
36348 | |
36349 var test = QUnit.test; | |
36350 | |
36351 function module (name, lifecycle) { | |
36352 QUnit.module(name, { | |
36353 setup : function () { | |
36354 moment.locale('en'); | |
36355 moment.createFromInputFallback = function () { | |
36356 throw new Error('input not handled by moment'); | |
36357 }; | |
36358 if (lifecycle && lifecycle.setup) { | |
36359 lifecycle.setup(); | |
36360 } | |
36361 }, | |
36362 teardown : function () { | |
36363 if (lifecycle && lifecycle.teardown) { | |
36364 lifecycle.teardown(); | |
36365 } | |
36366 } | |
36367 }); | |
36368 } | |
36369 | |
36370 function localeModule (name, lifecycle) { | |
36371 QUnit.module('locale:' + name, { | |
36372 setup : function () { | |
36373 moment.locale(name); | |
36374 moment.createFromInputFallback = function () { | |
36375 throw new Error('input not handled by moment'); | |
36376 }; | |
36377 if (lifecycle && lifecycle.setup) { | |
36378 lifecycle.setup(); | |
36379 } | |
36380 }, | |
36381 teardown : function () { | |
36382 moment.locale('en'); | |
36383 if (lifecycle && lifecycle.teardown) { | |
36384 lifecycle.teardown(); | |
36385 } | |
36386 } | |
36387 }); | |
36388 } | |
36389 | |
36390 module('listers'); | |
36391 | |
36392 test('default', function (assert) { | |
36393 assert.deepEqual(moment.months(), ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']); | |
36394 assert.deepEqual(moment.monthsShort(), ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']); | |
36395 assert.deepEqual(moment.weekdays(), ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']); | |
36396 assert.deepEqual(moment.weekdaysShort(), ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']); | |
36397 assert.deepEqual(moment.weekdaysMin(), ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']); | |
36398 }); | |
36399 | |
36400 test('index', function (assert) { | |
36401 assert.equal(moment.months(0), 'January'); | |
36402 assert.equal(moment.months(2), 'March'); | |
36403 assert.equal(moment.monthsShort(0), 'Jan'); | |
36404 assert.equal(moment.monthsShort(2), 'Mar'); | |
36405 assert.equal(moment.weekdays(0), 'Sunday'); | |
36406 assert.equal(moment.weekdays(2), 'Tuesday'); | |
36407 assert.equal(moment.weekdaysShort(0), 'Sun'); | |
36408 assert.equal(moment.weekdaysShort(2), 'Tue'); | |
36409 assert.equal(moment.weekdaysMin(0), 'Su'); | |
36410 assert.equal(moment.weekdaysMin(2), 'Tu'); | |
36411 }); | |
36412 | |
36413 test('localized', function (assert) { | |
36414 var months = 'one_two_three_four_five_six_seven_eight_nine_ten_eleven_twelve'.split('_'), | |
36415 monthsShort = 'on_tw_th_fo_fi_si_se_ei_ni_te_el_tw'.split('_'), | |
36416 weekdays = 'one_two_three_four_five_six_seven'.split('_'), | |
36417 weekdaysShort = 'on_tw_th_fo_fi_si_se'.split('_'), | |
36418 weekdaysMin = '1_2_3_4_5_6_7'.split('_'); | |
36419 | |
36420 moment.locale('numerologists', { | |
36421 months : months, | |
36422 monthsShort : monthsShort, | |
36423 weekdays : weekdays, | |
36424 weekdaysShort: weekdaysShort, | |
36425 weekdaysMin: weekdaysMin | |
36426 }); | |
36427 | |
36428 assert.deepEqual(moment.months(), months); | |
36429 assert.deepEqual(moment.monthsShort(), monthsShort); | |
36430 assert.deepEqual(moment.weekdays(), weekdays); | |
36431 assert.deepEqual(moment.weekdaysShort(), weekdaysShort); | |
36432 assert.deepEqual(moment.weekdaysMin(), weekdaysMin); | |
36433 | |
36434 assert.equal(moment.months(0), 'one'); | |
36435 assert.equal(moment.monthsShort(0), 'on'); | |
36436 assert.equal(moment.weekdays(0), 'one'); | |
36437 assert.equal(moment.weekdaysShort(0), 'on'); | |
36438 assert.equal(moment.weekdaysMin(0), '1'); | |
36439 | |
36440 assert.equal(moment.months(2), 'three'); | |
36441 assert.equal(moment.monthsShort(2), 'th'); | |
36442 assert.equal(moment.weekdays(2), 'three'); | |
36443 assert.equal(moment.weekdaysShort(2), 'th'); | |
36444 assert.equal(moment.weekdaysMin(2), '3'); | |
36445 }); | |
36446 | |
36447 test('with functions', function (assert) { | |
36448 var monthsShort = 'one_two_three_four_five_six_seven_eight_nine_ten_eleven_twelve'.split('_'), | |
36449 monthsShortWeird = 'onesy_twosy_threesy_foursy_fivesy_sixsy_sevensy_eightsy_ninesy_tensy_elevensy_twelvesy'.split('_'); | |
36450 | |
36451 moment.locale('difficult', { | |
36452 | |
36453 monthsShort: function (m, format) { | |
36454 var arr = format.match(/-MMM-/) ? monthsShortWeird : monthsShort; | |
36455 return arr[m.month()]; | |
36456 } | |
36457 }); | |
36458 | |
36459 assert.deepEqual(moment.monthsShort(), monthsShort); | |
36460 assert.deepEqual(moment.monthsShort('MMM'), monthsShort); | |
36461 assert.deepEqual(moment.monthsShort('-MMM-'), monthsShortWeird); | |
36462 | |
36463 assert.deepEqual(moment.monthsShort('MMM', 2), 'three'); | |
36464 assert.deepEqual(moment.monthsShort('-MMM-', 2), 'threesy'); | |
36465 assert.deepEqual(moment.monthsShort(2), 'three'); | |
36466 }); | |
36467 | |
36468 })); | |
36469 | |
36470 (function (global, factory) { | |
36471 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
36472 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
36473 factory(global.moment) | |
36474 }(this, function (moment) { 'use strict'; | |
36475 | |
36476 /*global QUnit:false*/ | |
36477 | |
36478 var test = QUnit.test; | |
36479 | |
36480 function module (name, lifecycle) { | |
36481 QUnit.module(name, { | |
36482 setup : function () { | |
36483 moment.locale('en'); | |
36484 moment.createFromInputFallback = function () { | |
36485 throw new Error('input not handled by moment'); | |
36486 }; | |
36487 if (lifecycle && lifecycle.setup) { | |
36488 lifecycle.setup(); | |
36489 } | |
36490 }, | |
36491 teardown : function () { | |
36492 if (lifecycle && lifecycle.teardown) { | |
36493 lifecycle.teardown(); | |
36494 } | |
36495 } | |
36496 }); | |
36497 } | |
36498 | |
36499 function localeModule (name, lifecycle) { | |
36500 QUnit.module('locale:' + name, { | |
36501 setup : function () { | |
36502 moment.locale(name); | |
36503 moment.createFromInputFallback = function () { | |
36504 throw new Error('input not handled by moment'); | |
36505 }; | |
36506 if (lifecycle && lifecycle.setup) { | |
36507 lifecycle.setup(); | |
36508 } | |
36509 }, | |
36510 teardown : function () { | |
36511 moment.locale('en'); | |
36512 if (lifecycle && lifecycle.teardown) { | |
36513 lifecycle.teardown(); | |
36514 } | |
36515 } | |
36516 }); | |
36517 } | |
36518 | |
36519 function each(array, callback) { | |
36520 var i; | |
36521 for (i = 0; i < array.length; i++) { | |
36522 callback(array[i], i, array); | |
36523 } | |
36524 } | |
36525 | |
36526 module('locale', { | |
36527 setup : function () { | |
36528 // TODO: Remove once locales are switched to ES6 | |
36529 each([{ | |
36530 name: 'en-gb', | |
36531 data: {} | |
36532 }, { | |
36533 name: 'en-ca', | |
36534 data: {} | |
36535 }, { | |
36536 name: 'es', | |
36537 data: { | |
36538 relativeTime: {past: 'hace %s', s: 'unos segundos', d: 'un día'}, | |
36539 months: 'enero_febrero_marzo_abril_mayo_junio_julio_agosto_septiembre_octubre_noviembre_diciembre'.split('_') | |
36540 } | |
36541 }, { | |
36542 name: 'fr', | |
36543 data: {} | |
36544 }, { | |
36545 name: 'fr-ca', | |
36546 data: {} | |
36547 }, { | |
36548 name: 'it', | |
36549 data: {} | |
36550 }, { | |
36551 name: 'zh-cn', | |
36552 data: { | |
36553 months: '一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月'.split('_') | |
36554 } | |
36555 }], function (locale) { | |
36556 if (moment.locale(locale.name) !== locale.name) { | |
36557 moment.defineLocale(locale.name, locale.data); | |
36558 } | |
36559 }); | |
36560 moment.locale('en'); | |
36561 } | |
36562 }); | |
36563 | |
36564 test('library getters and setters', function (assert) { | |
36565 var r = moment.locale('en'); | |
36566 | |
36567 assert.equal(r, 'en', 'locale should return en by default'); | |
36568 assert.equal(moment.locale(), 'en', 'locale should return en by default'); | |
36569 | |
36570 moment.locale('fr'); | |
36571 assert.equal(moment.locale(), 'fr', 'locale should return the changed locale'); | |
36572 | |
36573 moment.locale('en-gb'); | |
36574 assert.equal(moment.locale(), 'en-gb', 'locale should return the changed locale'); | |
36575 | |
36576 moment.locale('en'); | |
36577 assert.equal(moment.locale(), 'en', 'locale should reset'); | |
36578 | |
36579 moment.locale('does-not-exist'); | |
36580 assert.equal(moment.locale(), 'en', 'locale should reset'); | |
36581 | |
36582 moment.locale('EN'); | |
36583 assert.equal(moment.locale(), 'en', 'Normalize locale key case'); | |
36584 | |
36585 moment.locale('EN_gb'); | |
36586 assert.equal(moment.locale(), 'en-gb', 'Normalize locale key underscore'); | |
36587 }); | |
36588 | |
36589 test('library setter array of locales', function (assert) { | |
36590 assert.equal(moment.locale(['non-existent', 'fr', 'also-non-existent']), 'fr', 'passing an array uses the first valid locale'); | |
36591 assert.equal(moment.locale(['es', 'fr', 'also-non-existent']), 'es', 'passing an array uses the first valid locale'); | |
36592 }); | |
36593 | |
36594 test('library setter locale substrings', function (assert) { | |
36595 assert.equal(moment.locale('fr-crap'), 'fr', 'use substrings'); | |
36596 assert.equal(moment.locale('fr-does-not-exist'), 'fr', 'uses deep substrings'); | |
36597 assert.equal(moment.locale('fr-CA-does-not-exist'), 'fr-ca', 'uses deepest substring'); | |
36598 }); | |
36599 | |
36600 test('library getter locale array and substrings', function (assert) { | |
36601 assert.equal(moment.locale(['en-CH', 'fr']), 'en', 'prefer root locale to shallower ones'); | |
36602 assert.equal(moment.locale(['en-gb-leeds', 'en-CA']), 'en-gb', 'prefer root locale to shallower ones'); | |
36603 assert.equal(moment.locale(['en-fake', 'en-CA']), 'en-ca', 'prefer alternatives with shared roots'); | |
36604 assert.equal(moment.locale(['en-fake', 'en-fake2', 'en-ca']), 'en-ca', 'prefer alternatives with shared roots'); | |
36605 assert.equal(moment.locale(['fake-CA', 'fake-MX', 'fr']), 'fr', 'always find something if possible'); | |
36606 assert.equal(moment.locale(['fake-CA', 'fake-MX', 'fr']), 'fr', 'always find something if possible'); | |
36607 assert.equal(moment.locale(['fake-CA', 'fake-MX', 'fr-fake-fake-fake']), 'fr', 'always find something if possible'); | |
36608 assert.equal(moment.locale(['en', 'en-CA']), 'en', 'prefer earlier if it works'); | |
36609 }); | |
36610 | |
36611 test('library ensure inheritance', function (assert) { | |
36612 moment.locale('made-up', { | |
36613 // I put them out of order | |
36614 months : 'February_March_April_May_June_July_August_September_October_November_December_January'.split('_') | |
36615 // the rest of the properties should be inherited. | |
36616 }); | |
36617 | |
36618 assert.equal(moment([2012, 5, 6]).format('MMMM'), 'July', 'Override some of the configs'); | |
36619 assert.equal(moment([2012, 5, 6]).format('MMM'), 'Jun', 'But not all of them'); | |
36620 }); | |
36621 | |
36622 test('library ensure inheritance LT L LL LLL LLLL', function (assert) { | |
36623 var locale = 'test-inherit-lt'; | |
36624 | |
36625 moment.defineLocale(locale, { | |
36626 longDateFormat : { | |
36627 LT : '-[LT]-', | |
36628 L : '-[L]-', | |
36629 LL : '-[LL]-', | |
36630 LLL : '-[LLL]-', | |
36631 LLLL : '-[LLLL]-' | |
36632 }, | |
36633 calendar : { | |
36634 sameDay : '[sameDay] LT', | |
36635 nextDay : '[nextDay] L', | |
36636 nextWeek : '[nextWeek] LL', | |
36637 lastDay : '[lastDay] LLL', | |
36638 lastWeek : '[lastWeek] LLLL', | |
36639 sameElse : 'L' | |
36640 } | |
36641 }); | |
36642 | |
36643 moment.locale('es'); | |
36644 | |
36645 assert.equal(moment().locale(locale).calendar(), 'sameDay -LT-', 'Should use instance locale in LT formatting'); | |
36646 assert.equal(moment().add(1, 'days').locale(locale).calendar(), 'nextDay -L-', 'Should use instance locale in L formatting'); | |
36647 assert.equal(moment().add(-1, 'days').locale(locale).calendar(), 'lastDay -LLL-', 'Should use instance locale in LL formatting'); | |
36648 assert.equal(moment().add(4, 'days').locale(locale).calendar(), 'nextWeek -LL-', 'Should use instance locale in LLL formatting'); | |
36649 assert.equal(moment().add(-4, 'days').locale(locale).calendar(), 'lastWeek -LLLL-', 'Should use instance locale in LLLL formatting'); | |
36650 }); | |
36651 | |
36652 test('library localeData', function (assert) { | |
36653 moment.locale('en'); | |
36654 | |
36655 var jan = moment([2000, 0]); | |
36656 | |
36657 assert.equal(moment.localeData().months(jan), 'January', 'no arguments returns global'); | |
36658 assert.equal(moment.localeData('zh-cn').months(jan), '一月', 'a string returns the locale based on key'); | |
36659 assert.equal(moment.localeData(moment().locale('es')).months(jan), 'Enero', 'if you pass in a moment it uses the moment\'s locale'); | |
36660 }); | |
36661 | |
36662 test('library deprecations', function (assert) { | |
36663 moment.lang('dude', {months: ['Movember']}); | |
36664 assert.equal(moment.locale(), 'dude', 'setting the lang sets the locale'); | |
36665 assert.equal(moment.lang(), moment.locale()); | |
36666 assert.equal(moment.langData(), moment.localeData(), 'langData is localeData'); | |
36667 }); | |
36668 | |
36669 test('defineLocale', function (assert) { | |
36670 moment.locale('en'); | |
36671 moment.defineLocale('dude', {months: ['Movember']}); | |
36672 assert.equal(moment().locale(), 'dude', 'defineLocale also sets it'); | |
36673 assert.equal(moment().locale('dude').locale(), 'dude', 'defineLocale defines a locale'); | |
36674 }); | |
36675 | |
36676 test('library convenience', function (assert) { | |
36677 moment.locale('something', {week: {dow: 3}}); | |
36678 moment.locale('something'); | |
36679 assert.equal(moment.locale(), 'something', 'locale can be used to create the locale too'); | |
36680 }); | |
36681 | |
36682 test('firstDayOfWeek firstDayOfYear locale getters', function (assert) { | |
36683 moment.locale('something', {week: {dow: 3, doy: 4}}); | |
36684 moment.locale('something'); | |
36685 assert.equal(moment.localeData().firstDayOfWeek(), 3, 'firstDayOfWeek'); | |
36686 assert.equal(moment.localeData().firstDayOfYear(), 4, 'firstDayOfYear'); | |
36687 }); | |
36688 | |
36689 test('instance locale method', function (assert) { | |
36690 moment.locale('en'); | |
36691 | |
36692 assert.equal(moment([2012, 5, 6]).format('MMMM'), 'June', 'Normally default to global'); | |
36693 assert.equal(moment([2012, 5, 6]).locale('es').format('MMMM'), 'Junio', 'Use the instance specific locale'); | |
36694 assert.equal(moment([2012, 5, 6]).format('MMMM'), 'June', 'Using an instance specific locale does not affect other moments'); | |
36695 }); | |
36696 | |
36697 test('instance locale method with array', function (assert) { | |
36698 var m = moment().locale(['non-existent', 'fr', 'also-non-existent']); | |
36699 assert.equal(m.locale(), 'fr', 'passing an array uses the first valid locale'); | |
36700 m = moment().locale(['es', 'fr', 'also-non-existent']); | |
36701 assert.equal(m.locale(), 'es', 'passing an array uses the first valid locale'); | |
36702 }); | |
36703 | |
36704 test('instance getter locale substrings', function (assert) { | |
36705 var m = moment(); | |
36706 | |
36707 m.locale('fr-crap'); | |
36708 assert.equal(m.locale(), 'fr', 'use substrings'); | |
36709 | |
36710 m.locale('fr-does-not-exist'); | |
36711 assert.equal(m.locale(), 'fr', 'uses deep substrings'); | |
36712 }); | |
36713 | |
36714 test('instance locale persists with manipulation', function (assert) { | |
36715 moment.locale('en'); | |
36716 | |
36717 assert.equal(moment([2012, 5, 6]).locale('es').add({days: 1}).format('MMMM'), 'Junio', 'With addition'); | |
36718 assert.equal(moment([2012, 5, 6]).locale('es').day(0).format('MMMM'), 'Junio', 'With day getter'); | |
36719 assert.equal(moment([2012, 5, 6]).locale('es').endOf('day').format('MMMM'), 'Junio', 'With endOf'); | |
36720 }); | |
36721 | |
36722 test('instance locale persists with cloning', function (assert) { | |
36723 moment.locale('en'); | |
36724 | |
36725 var a = moment([2012, 5, 6]).locale('es'), | |
36726 b = a.clone(), | |
36727 c = moment(a); | |
36728 | |
36729 assert.equal(b.format('MMMM'), 'Junio', 'using moment.fn.clone()'); | |
36730 assert.equal(b.format('MMMM'), 'Junio', 'using moment()'); | |
36731 }); | |
36732 | |
36733 test('duration locale method', function (assert) { | |
36734 moment.locale('en'); | |
36735 | |
36736 assert.equal(moment.duration({seconds: 44}).humanize(), 'a few seconds', 'Normally default to global'); | |
36737 assert.equal(moment.duration({seconds: 44}).locale('es').humanize(), 'unos segundos', 'Use the instance specific locale'); | |
36738 assert.equal(moment.duration({seconds: 44}).humanize(), 'a few seconds', 'Using an instance specific locale does not affect other durations'); | |
36739 }); | |
36740 | |
36741 test('duration locale persists with cloning', function (assert) { | |
36742 moment.locale('en'); | |
36743 | |
36744 var a = moment.duration({seconds: 44}).locale('es'), | |
36745 b = moment.duration(a); | |
36746 | |
36747 assert.equal(b.humanize(), 'unos segundos', 'using moment.duration()'); | |
36748 }); | |
36749 | |
36750 test('changing the global locale doesn\'t affect existing duration instances', function (assert) { | |
36751 var mom = moment.duration(); | |
36752 moment.locale('fr'); | |
36753 assert.equal('en', mom.locale()); | |
36754 }); | |
36755 | |
36756 test('duration deprecations', function (assert) { | |
36757 assert.equal(moment.duration().lang(), moment.duration().localeData(), 'duration.lang is the same as duration.localeData'); | |
36758 }); | |
36759 | |
36760 test('from and fromNow with invalid date', function (assert) { | |
36761 assert.equal(moment(NaN).from(), 'Invalid date', 'moment.from with invalid moment'); | |
36762 assert.equal(moment(NaN).fromNow(), 'Invalid date', 'moment.fromNow with invalid moment'); | |
36763 }); | |
36764 | |
36765 test('from relative time future', function (assert) { | |
36766 var start = moment([2007, 1, 28]); | |
36767 | |
36768 assert.equal(start.from(moment([2007, 1, 28]).subtract({s: 44})), 'in a few seconds', '44 seconds = a few seconds'); | |
36769 assert.equal(start.from(moment([2007, 1, 28]).subtract({s: 45})), 'in a minute', '45 seconds = a minute'); | |
36770 assert.equal(start.from(moment([2007, 1, 28]).subtract({s: 89})), 'in a minute', '89 seconds = a minute'); | |
36771 assert.equal(start.from(moment([2007, 1, 28]).subtract({s: 90})), 'in 2 minutes', '90 seconds = 2 minutes'); | |
36772 assert.equal(start.from(moment([2007, 1, 28]).subtract({m: 44})), 'in 44 minutes', '44 minutes = 44 minutes'); | |
36773 assert.equal(start.from(moment([2007, 1, 28]).subtract({m: 45})), 'in an hour', '45 minutes = an hour'); | |
36774 assert.equal(start.from(moment([2007, 1, 28]).subtract({m: 89})), 'in an hour', '89 minutes = an hour'); | |
36775 assert.equal(start.from(moment([2007, 1, 28]).subtract({m: 90})), 'in 2 hours', '90 minutes = 2 hours'); | |
36776 assert.equal(start.from(moment([2007, 1, 28]).subtract({h: 5})), 'in 5 hours', '5 hours = 5 hours'); | |
36777 assert.equal(start.from(moment([2007, 1, 28]).subtract({h: 21})), 'in 21 hours', '21 hours = 21 hours'); | |
36778 assert.equal(start.from(moment([2007, 1, 28]).subtract({h: 22})), 'in a day', '22 hours = a day'); | |
36779 assert.equal(start.from(moment([2007, 1, 28]).subtract({h: 35})), 'in a day', '35 hours = a day'); | |
36780 assert.equal(start.from(moment([2007, 1, 28]).subtract({h: 36})), 'in 2 days', '36 hours = 2 days'); | |
36781 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 1})), 'in a day', '1 day = a day'); | |
36782 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 5})), 'in 5 days', '5 days = 5 days'); | |
36783 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 25})), 'in 25 days', '25 days = 25 days'); | |
36784 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 26})), 'in a month', '26 days = a month'); | |
36785 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 30})), 'in a month', '30 days = a month'); | |
36786 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 45})), 'in a month', '45 days = a month'); | |
36787 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 47})), 'in 2 months', '47 days = 2 months'); | |
36788 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 74})), 'in 2 months', '74 days = 2 months'); | |
36789 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 78})), 'in 3 months', '78 days = 3 months'); | |
36790 assert.equal(start.from(moment([2007, 1, 28]).subtract({M: 1})), 'in a month', '1 month = a month'); | |
36791 assert.equal(start.from(moment([2007, 1, 28]).subtract({M: 5})), 'in 5 months', '5 months = 5 months'); | |
36792 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 315})), 'in 10 months', '315 days = 10 months'); | |
36793 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 344})), 'in a year', '344 days = a year'); | |
36794 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 345})), 'in a year', '345 days = a year'); | |
36795 assert.equal(start.from(moment([2007, 1, 28]).subtract({d: 548})), 'in 2 years', '548 days = in 2 years'); | |
36796 assert.equal(start.from(moment([2007, 1, 28]).subtract({y: 1})), 'in a year', '1 year = a year'); | |
36797 assert.equal(start.from(moment([2007, 1, 28]).subtract({y: 5})), 'in 5 years', '5 years = 5 years'); | |
36798 }); | |
36799 | |
36800 test('from relative time past', function (assert) { | |
36801 var start = moment([2007, 1, 28]); | |
36802 | |
36803 assert.equal(start.from(moment([2007, 1, 28]).add({s: 44})), 'a few seconds ago', '44 seconds = a few seconds'); | |
36804 assert.equal(start.from(moment([2007, 1, 28]).add({s: 45})), 'a minute ago', '45 seconds = a minute'); | |
36805 assert.equal(start.from(moment([2007, 1, 28]).add({s: 89})), 'a minute ago', '89 seconds = a minute'); | |
36806 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90})), '2 minutes ago', '90 seconds = 2 minutes'); | |
36807 assert.equal(start.from(moment([2007, 1, 28]).add({m: 44})), '44 minutes ago', '44 minutes = 44 minutes'); | |
36808 assert.equal(start.from(moment([2007, 1, 28]).add({m: 45})), 'an hour ago', '45 minutes = an hour'); | |
36809 assert.equal(start.from(moment([2007, 1, 28]).add({m: 89})), 'an hour ago', '89 minutes = an hour'); | |
36810 assert.equal(start.from(moment([2007, 1, 28]).add({m: 90})), '2 hours ago', '90 minutes = 2 hours'); | |
36811 assert.equal(start.from(moment([2007, 1, 28]).add({h: 5})), '5 hours ago', '5 hours = 5 hours'); | |
36812 assert.equal(start.from(moment([2007, 1, 28]).add({h: 21})), '21 hours ago', '21 hours = 21 hours'); | |
36813 assert.equal(start.from(moment([2007, 1, 28]).add({h: 22})), 'a day ago', '22 hours = a day'); | |
36814 assert.equal(start.from(moment([2007, 1, 28]).add({h: 35})), 'a day ago', '35 hours = a day'); | |
36815 assert.equal(start.from(moment([2007, 1, 28]).add({h: 36})), '2 days ago', '36 hours = 2 days'); | |
36816 assert.equal(start.from(moment([2007, 1, 28]).add({d: 1})), 'a day ago', '1 day = a day'); | |
36817 assert.equal(start.from(moment([2007, 1, 28]).add({d: 5})), '5 days ago', '5 days = 5 days'); | |
36818 assert.equal(start.from(moment([2007, 1, 28]).add({d: 25})), '25 days ago', '25 days = 25 days'); | |
36819 assert.equal(start.from(moment([2007, 1, 28]).add({d: 26})), 'a month ago', '26 days = a month'); | |
36820 assert.equal(start.from(moment([2007, 1, 28]).add({d: 30})), 'a month ago', '30 days = a month'); | |
36821 assert.equal(start.from(moment([2007, 1, 28]).add({d: 43})), 'a month ago', '43 days = a month'); | |
36822 assert.equal(start.from(moment([2007, 1, 28]).add({d: 46})), '2 months ago', '46 days = 2 months'); | |
36823 assert.equal(start.from(moment([2007, 1, 28]).add({d: 74})), '2 months ago', '75 days = 2 months'); | |
36824 assert.equal(start.from(moment([2007, 1, 28]).add({d: 76})), '3 months ago', '76 days = 3 months'); | |
36825 assert.equal(start.from(moment([2007, 1, 28]).add({M: 1})), 'a month ago', '1 month = a month'); | |
36826 assert.equal(start.from(moment([2007, 1, 28]).add({M: 5})), '5 months ago', '5 months = 5 months'); | |
36827 assert.equal(start.from(moment([2007, 1, 28]).add({d: 315})), '10 months ago', '315 days = 10 months'); | |
36828 assert.equal(start.from(moment([2007, 1, 28]).add({d: 344})), 'a year ago', '344 days = a year'); | |
36829 assert.equal(start.from(moment([2007, 1, 28]).add({d: 345})), 'a year ago', '345 days = a year'); | |
36830 assert.equal(start.from(moment([2007, 1, 28]).add({d: 548})), '2 years ago', '548 days = 2 years'); | |
36831 assert.equal(start.from(moment([2007, 1, 28]).add({y: 1})), 'a year ago', '1 year = a year'); | |
36832 assert.equal(start.from(moment([2007, 1, 28]).add({y: 5})), '5 years ago', '5 years = 5 years'); | |
36833 }); | |
36834 | |
36835 test('instance locale used with from', function (assert) { | |
36836 moment.locale('en'); | |
36837 | |
36838 var a = moment([2012, 5, 6]).locale('es'), | |
36839 b = moment([2012, 5, 7]); | |
36840 | |
36841 assert.equal(a.from(b), 'hace un día', 'preserve locale of first moment'); | |
36842 assert.equal(b.from(a), 'in a day', 'do not preserve locale of second moment'); | |
36843 }); | |
36844 | |
36845 test('instance localeData', function (assert) { | |
36846 moment.defineLocale('dude', {week: {dow: 3}}); | |
36847 assert.equal(moment().locale('dude').localeData()._week.dow, 3); | |
36848 }); | |
36849 | |
36850 test('month name callback function', function (assert) { | |
36851 function fakeReplace(m, format) { | |
36852 if (/test/.test(format)) { | |
36853 return 'test'; | |
36854 } | |
36855 if (m.date() === 1) { | |
36856 return 'date'; | |
36857 } | |
36858 return 'default'; | |
36859 } | |
36860 | |
36861 moment.locale('made-up-2', { | |
36862 months : fakeReplace, | |
36863 monthsShort : fakeReplace, | |
36864 weekdays : fakeReplace, | |
36865 weekdaysShort : fakeReplace, | |
36866 weekdaysMin : fakeReplace | |
36867 }); | |
36868 | |
36869 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'); | |
36870 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'); | |
36871 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'); | |
36872 }); | |
36873 | |
36874 test('changing parts of a locale config', function (assert) { | |
36875 moment.locale('partial-lang', { | |
36876 months : 'a b c d e f g h i j k l'.split(' ') | |
36877 }); | |
36878 | |
36879 assert.equal(moment([2011, 0, 1]).format('MMMM'), 'a', 'should be able to set locale values when creating the localeuage'); | |
36880 | |
36881 moment.locale('partial-lang', { | |
36882 monthsShort : 'A B C D E F G H I J K L'.split(' ') | |
36883 }); | |
36884 | |
36885 assert.equal(moment([2011, 0, 1]).format('MMMM MMM'), 'a A', 'should be able to set locale values after creating the localeuage'); | |
36886 }); | |
36887 | |
36888 test('start/endOf week feature for first-day-is-monday locales', function (assert) { | |
36889 moment.locale('monday-lang', { | |
36890 week : { | |
36891 dow : 1 // Monday is the first day of the week | |
36892 } | |
36893 }); | |
36894 | |
36895 moment.locale('monday-lang'); | |
36896 assert.equal(moment([2013, 0, 1]).startOf('week').day(), 1, 'for locale monday-lang first day of the week should be monday'); | |
36897 assert.equal(moment([2013, 0, 1]).endOf('week').day(), 0, 'for locale monday-lang last day of the week should be sunday'); | |
36898 }); | |
36899 | |
36900 test('meridiem parsing', function (assert) { | |
36901 moment.locale('meridiem-parsing', { | |
36902 meridiemParse : /[bd]/i, | |
36903 isPM : function (input) { | |
36904 return input === 'b'; | |
36905 } | |
36906 }); | |
36907 | |
36908 moment.locale('meridiem-parsing'); | |
36909 assert.equal(moment('2012-01-01 3b', 'YYYY-MM-DD ha').hour(), 15, 'Custom parsing of meridiem should work'); | |
36910 assert.equal(moment('2012-01-01 3d', 'YYYY-MM-DD ha').hour(), 3, 'Custom parsing of meridiem should work'); | |
36911 }); | |
36912 | |
36913 test('invalid date formatting', function (assert) { | |
36914 moment.locale('has-invalid', { | |
36915 invalidDate: 'KHAAAAAAAAAAAN!' | |
36916 }); | |
36917 | |
36918 assert.equal(moment.invalid().format(), 'KHAAAAAAAAAAAN!'); | |
36919 assert.equal(moment.invalid().format('YYYY-MM-DD'), 'KHAAAAAAAAAAAN!'); | |
36920 }); | |
36921 | |
36922 test('return locale name', function (assert) { | |
36923 var registered = moment.locale('return-this', {}); | |
36924 | |
36925 assert.equal(registered, 'return-this', 'returns the locale configured'); | |
36926 }); | |
36927 | |
36928 test('changing the global locale doesn\'t affect existing instances', function (assert) { | |
36929 var mom = moment(); | |
36930 moment.locale('fr'); | |
36931 assert.equal('en', mom.locale()); | |
36932 }); | |
36933 | |
36934 test('setting a language on instance returns the original moment for chaining', function (assert) { | |
36935 var mom = moment(); | |
36936 | |
36937 assert.equal(mom.lang('fr'), mom, 'setting the language (lang) returns the original moment for chaining'); | |
36938 assert.equal(mom.locale('it'), mom, 'setting the language (locale) returns the original moment for chaining'); | |
36939 }); | |
36940 | |
36941 test('lang(key) changes the language of the instance', function (assert) { | |
36942 var m = moment().month(0); | |
36943 m.lang('fr'); | |
36944 assert.equal(m.locale(), 'fr', 'm.lang(key) changes instance locale'); | |
36945 }); | |
36946 | |
36947 test('moment#locale(false) resets to global locale', function (assert) { | |
36948 var m = moment(); | |
36949 | |
36950 moment.locale('fr'); | |
36951 m.locale('it'); | |
36952 | |
36953 assert.equal(moment.locale(), 'fr', 'global locale is it'); | |
36954 assert.equal(m.locale(), 'it', 'instance locale is it'); | |
36955 m.locale(false); | |
36956 assert.equal(m.locale(), 'fr', 'instance locale reset to global locale'); | |
36957 }); | |
36958 | |
36959 test('moment().locale with missing key doesn\'t change locale', function (assert) { | |
36960 assert.equal(moment().locale('boo').localeData(), moment.localeData(), | |
36961 'preserve global locale in case of bad locale id'); | |
36962 }); | |
36963 | |
36964 test('moment().lang with missing key doesn\'t change locale', function (assert) { | |
36965 assert.equal(moment().lang('boo').localeData(), moment.localeData(), | |
36966 'preserve global locale in case of bad locale id'); | |
36967 }); | |
36968 | |
36969 })); | |
36970 | |
36971 (function (global, factory) { | |
36972 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
36973 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
36974 factory(global.moment) | |
36975 }(this, function (moment) { 'use strict'; | |
36976 | |
36977 /*global QUnit:false*/ | |
36978 | |
36979 var test = QUnit.test; | |
36980 | |
36981 function module (name, lifecycle) { | |
36982 QUnit.module(name, { | |
36983 setup : function () { | |
36984 moment.locale('en'); | |
36985 moment.createFromInputFallback = function () { | |
36986 throw new Error('input not handled by moment'); | |
36987 }; | |
36988 if (lifecycle && lifecycle.setup) { | |
36989 lifecycle.setup(); | |
36990 } | |
36991 }, | |
36992 teardown : function () { | |
36993 if (lifecycle && lifecycle.teardown) { | |
36994 lifecycle.teardown(); | |
36995 } | |
36996 } | |
36997 }); | |
36998 } | |
36999 | |
37000 function localeModule (name, lifecycle) { | |
37001 QUnit.module('locale:' + name, { | |
37002 setup : function () { | |
37003 moment.locale(name); | |
37004 moment.createFromInputFallback = function () { | |
37005 throw new Error('input not handled by moment'); | |
37006 }; | |
37007 if (lifecycle && lifecycle.setup) { | |
37008 lifecycle.setup(); | |
37009 } | |
37010 }, | |
37011 teardown : function () { | |
37012 moment.locale('en'); | |
37013 if (lifecycle && lifecycle.teardown) { | |
37014 lifecycle.teardown(); | |
37015 } | |
37016 } | |
37017 }); | |
37018 } | |
37019 | |
37020 module('min max'); | |
37021 | |
37022 test('min', function (assert) { | |
37023 var now = moment(), | |
37024 future = now.clone().add(1, 'month'), | |
37025 past = now.clone().subtract(1, 'month'), | |
37026 invalid = moment.invalid(); | |
37027 | |
37028 assert.equal(moment.min(now, future, past), past, 'min(now, future, past)'); | |
37029 assert.equal(moment.min(future, now, past), past, 'min(future, now, past)'); | |
37030 assert.equal(moment.min(future, past, now), past, 'min(future, past, now)'); | |
37031 assert.equal(moment.min(past, future, now), past, 'min(past, future, now)'); | |
37032 assert.equal(moment.min(now, past), past, 'min(now, past)'); | |
37033 assert.equal(moment.min(past, now), past, 'min(past, now)'); | |
37034 assert.equal(moment.min(now), now, 'min(now, past)'); | |
37035 | |
37036 assert.equal(moment.min([now, future, past]), past, 'min([now, future, past])'); | |
37037 assert.equal(moment.min([now, past]), past, 'min(now, past)'); | |
37038 assert.equal(moment.min([now]), now, 'min(now)'); | |
37039 | |
37040 assert.equal(moment.min([now, invalid]), invalid, 'min(now, invalid)'); | |
37041 assert.equal(moment.min([invalid, now]), invalid, 'min(invalid, now)'); | |
37042 }); | |
37043 | |
37044 test('max', function (assert) { | |
37045 var now = moment(), | |
37046 future = now.clone().add(1, 'month'), | |
37047 past = now.clone().subtract(1, 'month'), | |
37048 invalid = moment.invalid(); | |
37049 | |
37050 assert.equal(moment.max(now, future, past), future, 'max(now, future, past)'); | |
37051 assert.equal(moment.max(future, now, past), future, 'max(future, now, past)'); | |
37052 assert.equal(moment.max(future, past, now), future, 'max(future, past, now)'); | |
37053 assert.equal(moment.max(past, future, now), future, 'max(past, future, now)'); | |
37054 assert.equal(moment.max(now, past), now, 'max(now, past)'); | |
37055 assert.equal(moment.max(past, now), now, 'max(past, now)'); | |
37056 assert.equal(moment.max(now), now, 'max(now, past)'); | |
37057 | |
37058 assert.equal(moment.max([now, future, past]), future, 'max([now, future, past])'); | |
37059 assert.equal(moment.max([now, past]), now, 'max(now, past)'); | |
37060 assert.equal(moment.max([now]), now, 'max(now)'); | |
37061 | |
37062 assert.equal(moment.max([now, invalid]), invalid, 'max(now, invalid)'); | |
37063 assert.equal(moment.max([invalid, now]), invalid, 'max(invalid, now)'); | |
37064 }); | |
37065 | |
37066 })); | |
37067 | |
37068 (function (global, factory) { | |
37069 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
37070 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
37071 factory(global.moment) | |
37072 }(this, function (moment) { 'use strict'; | |
37073 | |
37074 /*global QUnit:false*/ | |
37075 | |
37076 var test = QUnit.test; | |
37077 | |
37078 function module (name, lifecycle) { | |
37079 QUnit.module(name, { | |
37080 setup : function () { | |
37081 moment.locale('en'); | |
37082 moment.createFromInputFallback = function () { | |
37083 throw new Error('input not handled by moment'); | |
37084 }; | |
37085 if (lifecycle && lifecycle.setup) { | |
37086 lifecycle.setup(); | |
37087 } | |
37088 }, | |
37089 teardown : function () { | |
37090 if (lifecycle && lifecycle.teardown) { | |
37091 lifecycle.teardown(); | |
37092 } | |
37093 } | |
37094 }); | |
37095 } | |
37096 | |
37097 function localeModule (name, lifecycle) { | |
37098 QUnit.module('locale:' + name, { | |
37099 setup : function () { | |
37100 moment.locale(name); | |
37101 moment.createFromInputFallback = function () { | |
37102 throw new Error('input not handled by moment'); | |
37103 }; | |
37104 if (lifecycle && lifecycle.setup) { | |
37105 lifecycle.setup(); | |
37106 } | |
37107 }, | |
37108 teardown : function () { | |
37109 moment.locale('en'); | |
37110 if (lifecycle && lifecycle.teardown) { | |
37111 lifecycle.teardown(); | |
37112 } | |
37113 } | |
37114 }); | |
37115 } | |
37116 | |
37117 module('mutable'); | |
37118 | |
37119 test('manipulation methods', function (assert) { | |
37120 var m = moment(); | |
37121 | |
37122 assert.equal(m, m.year(2011), 'year() should be mutable'); | |
37123 assert.equal(m, m.month(1), 'month() should be mutable'); | |
37124 assert.equal(m, m.hours(7), 'hours() should be mutable'); | |
37125 assert.equal(m, m.minutes(33), 'minutes() should be mutable'); | |
37126 assert.equal(m, m.seconds(44), 'seconds() should be mutable'); | |
37127 assert.equal(m, m.milliseconds(55), 'milliseconds() should be mutable'); | |
37128 assert.equal(m, m.day(2), 'day() should be mutable'); | |
37129 assert.equal(m, m.startOf('week'), 'startOf() should be mutable'); | |
37130 assert.equal(m, m.add(1, 'days'), 'add() should be mutable'); | |
37131 assert.equal(m, m.subtract(2, 'years'), 'subtract() should be mutable'); | |
37132 assert.equal(m, m.local(), 'local() should be mutable'); | |
37133 assert.equal(m, m.utc(), 'utc() should be mutable'); | |
37134 }); | |
37135 | |
37136 test('non mutable methods', function (assert) { | |
37137 var m = moment(); | |
37138 assert.notEqual(m, m.clone(), 'clone() should not be mutable'); | |
37139 }); | |
37140 | |
37141 })); | |
37142 | |
37143 (function (global, factory) { | |
37144 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
37145 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
37146 factory(global.moment) | |
37147 }(this, function (moment) { 'use strict'; | |
37148 | |
37149 /*global QUnit:false*/ | |
37150 | |
37151 var test = QUnit.test; | |
37152 | |
37153 function module (name, lifecycle) { | |
37154 QUnit.module(name, { | |
37155 setup : function () { | |
37156 moment.locale('en'); | |
37157 moment.createFromInputFallback = function () { | |
37158 throw new Error('input not handled by moment'); | |
37159 }; | |
37160 if (lifecycle && lifecycle.setup) { | |
37161 lifecycle.setup(); | |
37162 } | |
37163 }, | |
37164 teardown : function () { | |
37165 if (lifecycle && lifecycle.teardown) { | |
37166 lifecycle.teardown(); | |
37167 } | |
37168 } | |
37169 }); | |
37170 } | |
37171 | |
37172 function localeModule (name, lifecycle) { | |
37173 QUnit.module('locale:' + name, { | |
37174 setup : function () { | |
37175 moment.locale(name); | |
37176 moment.createFromInputFallback = function () { | |
37177 throw new Error('input not handled by moment'); | |
37178 }; | |
37179 if (lifecycle && lifecycle.setup) { | |
37180 lifecycle.setup(); | |
37181 } | |
37182 }, | |
37183 teardown : function () { | |
37184 moment.locale('en'); | |
37185 if (lifecycle && lifecycle.teardown) { | |
37186 lifecycle.teardown(); | |
37187 } | |
37188 } | |
37189 }); | |
37190 } | |
37191 | |
37192 module('normalize units'); | |
37193 | |
37194 test('normalize units', function (assert) { | |
37195 var fullKeys = ['year', 'quarter', 'month', 'isoWeek', 'week', 'day', 'hour', 'minute', 'second', 'millisecond', 'date', 'dayOfYear', 'weekday', 'isoWeekday', 'weekYear', 'isoWeekYear'], | |
37196 aliases = ['y', 'Q', 'M', 'W', 'w', 'd', 'h', 'm', 's', 'ms', 'D', 'DDD', 'e', 'E', 'gg', 'GG'], | |
37197 length = fullKeys.length, | |
37198 fullKey, | |
37199 fullKeyCaps, | |
37200 fullKeyPlural, | |
37201 fullKeyCapsPlural, | |
37202 fullKeyLower, | |
37203 alias, | |
37204 index; | |
37205 | |
37206 for (index = 0; index < length; index += 1) { | |
37207 fullKey = fullKeys[index]; | |
37208 fullKeyCaps = fullKey.toUpperCase(); | |
37209 fullKeyLower = fullKey.toLowerCase(); | |
37210 fullKeyPlural = fullKey + 's'; | |
37211 fullKeyCapsPlural = fullKeyCaps + 's'; | |
37212 alias = aliases[index]; | |
37213 assert.equal(moment.normalizeUnits(fullKey), fullKey, 'Testing full key ' + fullKey); | |
37214 assert.equal(moment.normalizeUnits(fullKeyCaps), fullKey, 'Testing full key capitalised ' + fullKey); | |
37215 assert.equal(moment.normalizeUnits(fullKeyPlural), fullKey, 'Testing full key plural ' + fullKey); | |
37216 assert.equal(moment.normalizeUnits(fullKeyCapsPlural), fullKey, 'Testing full key capitalised and plural ' + fullKey); | |
37217 assert.equal(moment.normalizeUnits(alias), fullKey, 'Testing alias ' + fullKey); | |
37218 } | |
37219 }); | |
37220 | |
37221 })); | |
37222 | |
37223 (function (global, factory) { | |
37224 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
37225 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
37226 factory(global.moment) | |
37227 }(this, function (moment) { 'use strict'; | |
37228 | |
37229 /*global QUnit:false*/ | |
37230 | |
37231 var test = QUnit.test; | |
37232 | |
37233 function module (name, lifecycle) { | |
37234 QUnit.module(name, { | |
37235 setup : function () { | |
37236 moment.locale('en'); | |
37237 moment.createFromInputFallback = function () { | |
37238 throw new Error('input not handled by moment'); | |
37239 }; | |
37240 if (lifecycle && lifecycle.setup) { | |
37241 lifecycle.setup(); | |
37242 } | |
37243 }, | |
37244 teardown : function () { | |
37245 if (lifecycle && lifecycle.teardown) { | |
37246 lifecycle.teardown(); | |
37247 } | |
37248 } | |
37249 }); | |
37250 } | |
37251 | |
37252 function localeModule (name, lifecycle) { | |
37253 QUnit.module('locale:' + name, { | |
37254 setup : function () { | |
37255 moment.locale(name); | |
37256 moment.createFromInputFallback = function () { | |
37257 throw new Error('input not handled by moment'); | |
37258 }; | |
37259 if (lifecycle && lifecycle.setup) { | |
37260 lifecycle.setup(); | |
37261 } | |
37262 }, | |
37263 teardown : function () { | |
37264 moment.locale('en'); | |
37265 if (lifecycle && lifecycle.teardown) { | |
37266 lifecycle.teardown(); | |
37267 } | |
37268 } | |
37269 }); | |
37270 } | |
37271 | |
37272 module('parsing flags'); | |
37273 | |
37274 function flags () { | |
37275 return moment.apply(null, arguments).parsingFlags(); | |
37276 } | |
37277 | |
37278 test('overflow with array', function (assert) { | |
37279 //months | |
37280 assert.equal(flags([2010, 0]).overflow, -1, 'month 0 valid'); | |
37281 assert.equal(flags([2010, 1]).overflow, -1, 'month 1 valid'); | |
37282 assert.equal(flags([2010, -1]).overflow, 1, 'month -1 invalid'); | |
37283 assert.equal(flags([2100, 12]).overflow, 1, 'month 12 invalid'); | |
37284 | |
37285 //days | |
37286 assert.equal(flags([2010, 1, 16]).overflow, -1, 'date valid'); | |
37287 assert.equal(flags([2010, 1, -1]).overflow, 2, 'date -1 invalid'); | |
37288 assert.equal(flags([2010, 1, 0]).overflow, 2, 'date 0 invalid'); | |
37289 assert.equal(flags([2010, 1, 32]).overflow, 2, 'date 32 invalid'); | |
37290 assert.equal(flags([2012, 1, 29]).overflow, -1, 'date leap year valid'); | |
37291 assert.equal(flags([2010, 1, 29]).overflow, 2, 'date leap year invalid'); | |
37292 | |
37293 //hours | |
37294 assert.equal(flags([2010, 1, 1, 8]).overflow, -1, 'hour valid'); | |
37295 assert.equal(flags([2010, 1, 1, 0]).overflow, -1, 'hour 0 valid'); | |
37296 assert.equal(flags([2010, 1, 1, -1]).overflow, 3, 'hour -1 invalid'); | |
37297 assert.equal(flags([2010, 1, 1, 25]).overflow, 3, 'hour 25 invalid'); | |
37298 assert.equal(flags([2010, 1, 1, 24, 1]).overflow, 3, 'hour 24:01 invalid'); | |
37299 | |
37300 //minutes | |
37301 assert.equal(flags([2010, 1, 1, 8, 15]).overflow, -1, 'minute valid'); | |
37302 assert.equal(flags([2010, 1, 1, 8, 0]).overflow, -1, 'minute 0 valid'); | |
37303 assert.equal(flags([2010, 1, 1, 8, -1]).overflow, 4, 'minute -1 invalid'); | |
37304 assert.equal(flags([2010, 1, 1, 8, 60]).overflow, 4, 'minute 60 invalid'); | |
37305 | |
37306 //seconds | |
37307 assert.equal(flags([2010, 1, 1, 8, 15, 12]).overflow, -1, 'second valid'); | |
37308 assert.equal(flags([2010, 1, 1, 8, 15, 0]).overflow, -1, 'second 0 valid'); | |
37309 assert.equal(flags([2010, 1, 1, 8, 15, -1]).overflow, 5, 'second -1 invalid'); | |
37310 assert.equal(flags([2010, 1, 1, 8, 15, 60]).overflow, 5, 'second 60 invalid'); | |
37311 | |
37312 //milliseconds | |
37313 assert.equal(flags([2010, 1, 1, 8, 15, 12, 345]).overflow, -1, 'millisecond valid'); | |
37314 assert.equal(flags([2010, 1, 1, 8, 15, 12, 0]).overflow, -1, 'millisecond 0 valid'); | |
37315 assert.equal(flags([2010, 1, 1, 8, 15, 12, -1]).overflow, 6, 'millisecond -1 invalid'); | |
37316 assert.equal(flags([2010, 1, 1, 8, 15, 12, 1000]).overflow, 6, 'millisecond 1000 invalid'); | |
37317 | |
37318 // 24 hrs | |
37319 assert.equal(flags([2010, 1, 1, 24, 0, 0, 0]).overflow, -1, '24:00:00.000 is fine'); | |
37320 assert.equal(flags([2010, 1, 1, 24, 1, 0, 0]).overflow, 3, '24:01:00.000 is wrong hour'); | |
37321 assert.equal(flags([2010, 1, 1, 24, 0, 1, 0]).overflow, 3, '24:00:01.000 is wrong hour'); | |
37322 assert.equal(flags([2010, 1, 1, 24, 0, 0, 1]).overflow, 3, '24:00:00.001 is wrong hour'); | |
37323 }); | |
37324 | |
37325 test('overflow without format', function (assert) { | |
37326 //months | |
37327 assert.equal(flags('2001-01', 'YYYY-MM').overflow, -1, 'month 1 valid'); | |
37328 assert.equal(flags('2001-12', 'YYYY-MM').overflow, -1, 'month 12 valid'); | |
37329 assert.equal(flags('2001-13', 'YYYY-MM').overflow, 1, 'month 13 invalid'); | |
37330 | |
37331 //days | |
37332 assert.equal(flags('2010-01-16', 'YYYY-MM-DD').overflow, -1, 'date 16 valid'); | |
37333 assert.equal(flags('2010-01-0', 'YYYY-MM-DD').overflow, 2, 'date 0 invalid'); | |
37334 assert.equal(flags('2010-01-32', 'YYYY-MM-DD').overflow, 2, 'date 32 invalid'); | |
37335 assert.equal(flags('2012-02-29', 'YYYY-MM-DD').overflow, -1, 'date leap year valid'); | |
37336 assert.equal(flags('2010-02-29', 'YYYY-MM-DD').overflow, 2, 'date leap year invalid'); | |
37337 | |
37338 //days of the year | |
37339 assert.equal(flags('2010 300', 'YYYY DDDD').overflow, -1, 'day 300 of year valid'); | |
37340 assert.equal(flags('2010 365', 'YYYY DDDD').overflow, -1, 'day 365 of year valid'); | |
37341 assert.equal(flags('2010 366', 'YYYY DDDD').overflow, 2, 'day 366 of year invalid'); | |
37342 assert.equal(flags('2012 366', 'YYYY DDDD').overflow, -1, 'day 366 of leap year valid'); | |
37343 assert.equal(flags('2012 367', 'YYYY DDDD').overflow, 2, 'day 367 of leap year invalid'); | |
37344 | |
37345 //hours | |
37346 assert.equal(flags('08', 'HH').overflow, -1, 'hour valid'); | |
37347 assert.equal(flags('00', 'HH').overflow, -1, 'hour 0 valid'); | |
37348 assert.equal(flags('25', 'HH').overflow, 3, 'hour 25 invalid'); | |
37349 assert.equal(flags('24:01', 'HH:mm').overflow, 3, 'hour 24:01 invalid'); | |
37350 | |
37351 //minutes | |
37352 assert.equal(flags('08:15', 'HH:mm').overflow, -1, 'minute valid'); | |
37353 assert.equal(flags('08:00', 'HH:mm').overflow, -1, 'minute 0 valid'); | |
37354 assert.equal(flags('08:60', 'HH:mm').overflow, 4, 'minute 60 invalid'); | |
37355 | |
37356 //seconds | |
37357 assert.equal(flags('08:15:12', 'HH:mm:ss').overflow, -1, 'second valid'); | |
37358 assert.equal(flags('08:15:00', 'HH:mm:ss').overflow, -1, 'second 0 valid'); | |
37359 assert.equal(flags('08:15:60', 'HH:mm:ss').overflow, 5, 'second 60 invalid'); | |
37360 | |
37361 //milliseconds | |
37362 assert.equal(flags('08:15:12:345', 'HH:mm:ss:SSSS').overflow, -1, 'millisecond valid'); | |
37363 assert.equal(flags('08:15:12:000', 'HH:mm:ss:SSSS').overflow, -1, 'millisecond 0 valid'); | |
37364 | |
37365 //this is OK because we don't match the last digit, so it's 100 ms | |
37366 assert.equal(flags('08:15:12:1000', 'HH:mm:ss:SSSS').overflow, -1, 'millisecond 1000 actually valid'); | |
37367 }); | |
37368 | |
37369 test('extra tokens', function (assert) { | |
37370 assert.deepEqual(flags('1982-05-25', 'YYYY-MM-DD').unusedTokens, [], 'nothing extra'); | |
37371 assert.deepEqual(flags('1982-05', 'YYYY-MM-DD').unusedTokens, ['DD'], 'extra formatting token'); | |
37372 assert.deepEqual(flags('1982', 'YYYY-MM-DD').unusedTokens, ['MM', 'DD'], 'multiple extra formatting tokens'); | |
37373 assert.deepEqual(flags('1982-05', 'YYYY-MM-').unusedTokens, [], 'extra non-formatting token'); | |
37374 assert.deepEqual(flags('1982-05-', 'YYYY-MM-DD').unusedTokens, ['DD'], 'non-extra non-formatting token'); | |
37375 assert.deepEqual(flags('1982 05 1982', 'YYYY-MM-DD').unusedTokens, [], 'different non-formatting token'); | |
37376 }); | |
37377 | |
37378 test('extra tokens strict', function (assert) { | |
37379 assert.deepEqual(flags('1982-05-25', 'YYYY-MM-DD', true).unusedTokens, [], 'nothing extra'); | |
37380 assert.deepEqual(flags('1982-05', 'YYYY-MM-DD', true).unusedTokens, ['-', 'DD'], 'extra formatting token'); | |
37381 assert.deepEqual(flags('1982', 'YYYY-MM-DD', true).unusedTokens, ['-', 'MM', '-', 'DD'], 'multiple extra formatting tokens'); | |
37382 assert.deepEqual(flags('1982-05', 'YYYY-MM-', true).unusedTokens, ['-'], 'extra non-formatting token'); | |
37383 assert.deepEqual(flags('1982-05-', 'YYYY-MM-DD', true).unusedTokens, ['DD'], 'non-extra non-formatting token'); | |
37384 assert.deepEqual(flags('1982 05 1982', 'YYYY-MM-DD', true).unusedTokens, ['-', '-'], 'different non-formatting token'); | |
37385 }); | |
37386 | |
37387 test('unused input', function (assert) { | |
37388 assert.deepEqual(flags('1982-05-25', 'YYYY-MM-DD').unusedInput, [], 'normal input'); | |
37389 assert.deepEqual(flags('1982-05-25 this is more stuff', 'YYYY-MM-DD').unusedInput, [' this is more stuff'], 'trailing nonsense'); | |
37390 assert.deepEqual(flags('1982-05-25 09:30', 'YYYY-MM-DD').unusedInput, [' 09:30'], ['trailing legit-looking input']); | |
37391 assert.deepEqual(flags('1982-05-25 some junk', 'YYYY-MM-DD [some junk]').unusedInput, [], 'junk that actually gets matched'); | |
37392 assert.deepEqual(flags('stuff at beginning 1982-05-25', 'YYYY-MM-DD').unusedInput, ['stuff at beginning '], 'leading junk'); | |
37393 assert.deepEqual(flags('junk 1982 more junk 05 yet more junk25', 'YYYY-MM-DD').unusedInput, ['junk ', ' more junk ', ' yet more junk'], 'interstitial junk'); | |
37394 }); | |
37395 | |
37396 test('unused input strict', function (assert) { | |
37397 assert.deepEqual(flags('1982-05-25', 'YYYY-MM-DD', true).unusedInput, [], 'normal input'); | |
37398 assert.deepEqual(flags('1982-05-25 this is more stuff', 'YYYY-MM-DD', true).unusedInput, [' this is more stuff'], 'trailing nonsense'); | |
37399 assert.deepEqual(flags('1982-05-25 09:30', 'YYYY-MM-DD', true).unusedInput, [' 09:30'], ['trailing legit-looking input']); | |
37400 assert.deepEqual(flags('1982-05-25 some junk', 'YYYY-MM-DD [some junk]', true).unusedInput, [], 'junk that actually gets matched'); | |
37401 assert.deepEqual(flags('stuff at beginning 1982-05-25', 'YYYY-MM-DD', true).unusedInput, ['stuff at beginning '], 'leading junk'); | |
37402 assert.deepEqual(flags('junk 1982 more junk 05 yet more junk25', 'YYYY-MM-DD', true).unusedInput, ['junk ', ' more junk ', ' yet more junk'], 'interstitial junk'); | |
37403 }); | |
37404 | |
37405 test('chars left over', function (assert) { | |
37406 assert.equal(flags('1982-05-25', 'YYYY-MM-DD').charsLeftOver, 0, 'normal input'); | |
37407 assert.equal(flags('1982-05-25 this is more stuff', 'YYYY-MM-DD').charsLeftOver, ' this is more stuff'.length, 'trailing nonsense'); | |
37408 assert.equal(flags('1982-05-25 09:30', 'YYYY-MM-DD').charsLeftOver, ' 09:30'.length, 'trailing legit-looking input'); | |
37409 assert.equal(flags('stuff at beginning 1982-05-25', 'YYYY-MM-DD').charsLeftOver, 'stuff at beginning '.length, 'leading junk'); | |
37410 assert.equal(flags('1982 junk 05 more junk25', 'YYYY-MM-DD').charsLeftOver, [' junk ', ' more junk'].join('').length, 'interstitial junk'); | |
37411 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'); | |
37412 }); | |
37413 | |
37414 test('empty', function (assert) { | |
37415 assert.equal(flags('1982-05-25', 'YYYY-MM-DD').empty, false, 'normal input'); | |
37416 assert.equal(flags('nothing here', 'YYYY-MM-DD').empty, true, 'pure garbage'); | |
37417 assert.equal(flags('junk but has the number 2000 in it', 'YYYY-MM-DD').empty, false, 'only mostly garbage'); | |
37418 assert.equal(flags('', 'YYYY-MM-DD').empty, true, 'empty string'); | |
37419 assert.equal(flags('', 'YYYY-MM-DD').empty, true, 'blank string'); | |
37420 }); | |
37421 | |
37422 test('null', function (assert) { | |
37423 assert.equal(flags('1982-05-25', 'YYYY-MM-DD').nullInput, false, 'normal input'); | |
37424 assert.equal(flags(null).nullInput, true, 'just null'); | |
37425 assert.equal(flags(null, 'YYYY-MM-DD').nullInput, true, 'null with format'); | |
37426 }); | |
37427 | |
37428 test('invalid month', function (assert) { | |
37429 assert.equal(flags('1982 May', 'YYYY MMMM').invalidMonth, null, 'normal input'); | |
37430 assert.equal(flags('1982 Laser', 'YYYY MMMM').invalidMonth, 'Laser', 'bad month name'); | |
37431 }); | |
37432 | |
37433 test('empty format array', function (assert) { | |
37434 assert.equal(flags('1982 May', ['YYYY MMM']).invalidFormat, false, 'empty format array'); | |
37435 assert.equal(flags('1982 May', []).invalidFormat, true, 'empty format array'); | |
37436 }); | |
37437 | |
37438 })); | |
37439 | |
37440 (function (global, factory) { | |
37441 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
37442 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
37443 factory(global.moment) | |
37444 }(this, function (moment) { 'use strict'; | |
37445 | |
37446 /*global QUnit:false*/ | |
37447 | |
37448 var test = QUnit.test; | |
37449 | |
37450 function module (name, lifecycle) { | |
37451 QUnit.module(name, { | |
37452 setup : function () { | |
37453 moment.locale('en'); | |
37454 moment.createFromInputFallback = function () { | |
37455 throw new Error('input not handled by moment'); | |
37456 }; | |
37457 if (lifecycle && lifecycle.setup) { | |
37458 lifecycle.setup(); | |
37459 } | |
37460 }, | |
37461 teardown : function () { | |
37462 if (lifecycle && lifecycle.teardown) { | |
37463 lifecycle.teardown(); | |
37464 } | |
37465 } | |
37466 }); | |
37467 } | |
37468 | |
37469 function localeModule (name, lifecycle) { | |
37470 QUnit.module('locale:' + name, { | |
37471 setup : function () { | |
37472 moment.locale(name); | |
37473 moment.createFromInputFallback = function () { | |
37474 throw new Error('input not handled by moment'); | |
37475 }; | |
37476 if (lifecycle && lifecycle.setup) { | |
37477 lifecycle.setup(); | |
37478 } | |
37479 }, | |
37480 teardown : function () { | |
37481 moment.locale('en'); | |
37482 if (lifecycle && lifecycle.teardown) { | |
37483 lifecycle.teardown(); | |
37484 } | |
37485 } | |
37486 }); | |
37487 } | |
37488 | |
37489 var symbolMap = { | |
37490 '1': '!', | |
37491 '2': '@', | |
37492 '3': '#', | |
37493 '4': '$', | |
37494 '5': '%', | |
37495 '6': '^', | |
37496 '7': '&', | |
37497 '8': '*', | |
37498 '9': '(', | |
37499 '0': ')' | |
37500 }, | |
37501 numberMap = { | |
37502 '!': '1', | |
37503 '@': '2', | |
37504 '#': '3', | |
37505 '$': '4', | |
37506 '%': '5', | |
37507 '^': '6', | |
37508 '&': '7', | |
37509 '*': '8', | |
37510 '(': '9', | |
37511 ')': '0' | |
37512 }; | |
37513 | |
37514 module('preparse and postformat', { | |
37515 setup: function () { | |
37516 moment.locale('symbol', { | |
37517 preparse: function (string) { | |
37518 return string.replace(/[!@#$%\^&*()]/g, function (match) { | |
37519 return numberMap[match]; | |
37520 }); | |
37521 }, | |
37522 | |
37523 postformat: function (string) { | |
37524 return string.replace(/\d/g, function (match) { | |
37525 return symbolMap[match]; | |
37526 }); | |
37527 } | |
37528 }); | |
37529 } | |
37530 }); | |
37531 | |
37532 test('transform', function (assert) { | |
37533 assert.equal(moment.utc('@)!@-)*-@&', 'YYYY-MM-DD').unix(), 1346025600, 'preparse string + format'); | |
37534 assert.equal(moment.utc('@)!@-)*-@&').unix(), 1346025600, 'preparse ISO8601 string'); | |
37535 assert.equal(moment.unix(1346025600).utc().format('YYYY-MM-DD'), '@)!@-)*-@&', 'postformat'); | |
37536 }); | |
37537 | |
37538 test('transform from', function (assert) { | |
37539 var start = moment([2007, 1, 28]); | |
37540 | |
37541 assert.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), '@ minutes', 'postformat should work on moment.fn.from'); | |
37542 assert.equal(moment().add(6, 'd').fromNow(true), '^ days', 'postformat should work on moment.fn.fromNow'); | |
37543 assert.equal(moment.duration(10, 'h').humanize(), '!) hours', 'postformat should work on moment.duration.fn.humanize'); | |
37544 }); | |
37545 | |
37546 test('calendar day', function (assert) { | |
37547 var a = moment().hours(2).minutes(0).seconds(0); | |
37548 | |
37549 assert.equal(moment(a).calendar(), 'Today at @:)) AM', 'today at the same time'); | |
37550 assert.equal(moment(a).add({m: 25}).calendar(), 'Today at @:@% AM', 'Now plus 25 min'); | |
37551 assert.equal(moment(a).add({h: 1}).calendar(), 'Today at #:)) AM', 'Now plus 1 hour'); | |
37552 assert.equal(moment(a).add({d: 1}).calendar(), 'Tomorrow at @:)) AM', 'tomorrow at the same time'); | |
37553 assert.equal(moment(a).subtract({h: 1}).calendar(), 'Today at !:)) AM', 'Now minus 1 hour'); | |
37554 assert.equal(moment(a).subtract({d: 1}).calendar(), 'Yesterday at @:)) AM', 'yesterday at the same time'); | |
37555 }); | |
37556 | |
37557 })); | |
37558 | |
37559 (function (global, factory) { | |
37560 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
37561 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
37562 factory(global.moment) | |
37563 }(this, function (moment) { 'use strict'; | |
37564 | |
37565 /*global QUnit:false*/ | |
37566 | |
37567 var test = QUnit.test; | |
37568 | |
37569 function module (name, lifecycle) { | |
37570 QUnit.module(name, { | |
37571 setup : function () { | |
37572 moment.locale('en'); | |
37573 moment.createFromInputFallback = function () { | |
37574 throw new Error('input not handled by moment'); | |
37575 }; | |
37576 if (lifecycle && lifecycle.setup) { | |
37577 lifecycle.setup(); | |
37578 } | |
37579 }, | |
37580 teardown : function () { | |
37581 if (lifecycle && lifecycle.teardown) { | |
37582 lifecycle.teardown(); | |
37583 } | |
37584 } | |
37585 }); | |
37586 } | |
37587 | |
37588 function localeModule (name, lifecycle) { | |
37589 QUnit.module('locale:' + name, { | |
37590 setup : function () { | |
37591 moment.locale(name); | |
37592 moment.createFromInputFallback = function () { | |
37593 throw new Error('input not handled by moment'); | |
37594 }; | |
37595 if (lifecycle && lifecycle.setup) { | |
37596 lifecycle.setup(); | |
37597 } | |
37598 }, | |
37599 teardown : function () { | |
37600 moment.locale('en'); | |
37601 if (lifecycle && lifecycle.teardown) { | |
37602 lifecycle.teardown(); | |
37603 } | |
37604 } | |
37605 }); | |
37606 } | |
37607 | |
37608 module('quarter'); | |
37609 | |
37610 test('library quarter getter', function (assert) { | |
37611 assert.equal(moment([1985, 1, 4]).quarter(), 1, 'Feb 4 1985 is Q1'); | |
37612 assert.equal(moment([2029, 8, 18]).quarter(), 3, 'Sep 18 2029 is Q3'); | |
37613 assert.equal(moment([2013, 3, 24]).quarter(), 2, 'Apr 24 2013 is Q2'); | |
37614 assert.equal(moment([2015, 2, 5]).quarter(), 1, 'Mar 5 2015 is Q1'); | |
37615 assert.equal(moment([1970, 0, 2]).quarter(), 1, 'Jan 2 1970 is Q1'); | |
37616 assert.equal(moment([2001, 11, 12]).quarter(), 4, 'Dec 12 2001 is Q4'); | |
37617 assert.equal(moment([2000, 0, 2]).quarter(), 1, 'Jan 2 2000 is Q1'); | |
37618 }); | |
37619 | |
37620 test('quarter setter singular', function (assert) { | |
37621 var m = moment([2014, 4, 11]); | |
37622 assert.equal(m.quarter(2).month(), 4, 'set same quarter'); | |
37623 assert.equal(m.quarter(3).month(), 7, 'set 3rd quarter'); | |
37624 assert.equal(m.quarter(1).month(), 1, 'set 1st quarter'); | |
37625 assert.equal(m.quarter(4).month(), 10, 'set 4th quarter'); | |
37626 }); | |
37627 | |
37628 test('quarter setter plural', function (assert) { | |
37629 var m = moment([2014, 4, 11]); | |
37630 assert.equal(m.quarters(2).month(), 4, 'set same quarter'); | |
37631 assert.equal(m.quarters(3).month(), 7, 'set 3rd quarter'); | |
37632 assert.equal(m.quarters(1).month(), 1, 'set 1st quarter'); | |
37633 assert.equal(m.quarters(4).month(), 10, 'set 4th quarter'); | |
37634 }); | |
37635 | |
37636 test('quarter setter programmatic', function (assert) { | |
37637 var m = moment([2014, 4, 11]); | |
37638 assert.equal(m.set('quarter', 2).month(), 4, 'set same quarter'); | |
37639 assert.equal(m.set('quarter', 3).month(), 7, 'set 3rd quarter'); | |
37640 assert.equal(m.set('quarter', 1).month(), 1, 'set 1st quarter'); | |
37641 assert.equal(m.set('quarter', 4).month(), 10, 'set 4th quarter'); | |
37642 }); | |
37643 | |
37644 test('quarter setter programmatic plural', function (assert) { | |
37645 var m = moment([2014, 4, 11]); | |
37646 assert.equal(m.set('quarters', 2).month(), 4, 'set same quarter'); | |
37647 assert.equal(m.set('quarters', 3).month(), 7, 'set 3rd quarter'); | |
37648 assert.equal(m.set('quarters', 1).month(), 1, 'set 1st quarter'); | |
37649 assert.equal(m.set('quarters', 4).month(), 10, 'set 4th quarter'); | |
37650 }); | |
37651 | |
37652 test('quarter setter programmatic abbr', function (assert) { | |
37653 var m = moment([2014, 4, 11]); | |
37654 assert.equal(m.set('Q', 2).month(), 4, 'set same quarter'); | |
37655 assert.equal(m.set('Q', 3).month(), 7, 'set 3rd quarter'); | |
37656 assert.equal(m.set('Q', 1).month(), 1, 'set 1st quarter'); | |
37657 assert.equal(m.set('Q', 4).month(), 10, 'set 4th quarter'); | |
37658 }); | |
37659 | |
37660 test('quarter setter only month changes', function (assert) { | |
37661 var m = moment([2014, 4, 11, 1, 2, 3, 4]).quarter(4); | |
37662 assert.equal(m.year(), 2014, 'keep year'); | |
37663 assert.equal(m.month(), 10, 'set month'); | |
37664 assert.equal(m.date(), 11, 'keep date'); | |
37665 assert.equal(m.hour(), 1, 'keep hour'); | |
37666 assert.equal(m.minute(), 2, 'keep minutes'); | |
37667 assert.equal(m.second(), 3, 'keep seconds'); | |
37668 assert.equal(m.millisecond(), 4, 'keep milliseconds'); | |
37669 }); | |
37670 | |
37671 test('quarter setter bubble to next year', function (assert) { | |
37672 var m = moment([2014, 4, 11, 1, 2, 3, 4]).quarter(7); | |
37673 assert.equal(m.year(), 2015, 'year bubbled'); | |
37674 assert.equal(m.month(), 7, 'set month'); | |
37675 assert.equal(m.date(), 11, 'keep date'); | |
37676 assert.equal(m.hour(), 1, 'keep hour'); | |
37677 assert.equal(m.minute(), 2, 'keep minutes'); | |
37678 assert.equal(m.second(), 3, 'keep seconds'); | |
37679 assert.equal(m.millisecond(), 4, 'keep milliseconds'); | |
37680 }); | |
37681 | |
37682 test('quarter diff', function (assert) { | |
37683 assert.equal(moment('2014-01-01').diff(moment('2014-04-01'), 'quarter'), | |
37684 -1, 'diff -1 quarter'); | |
37685 assert.equal(moment('2014-04-01').diff(moment('2014-01-01'), 'quarter'), | |
37686 1, 'diff 1 quarter'); | |
37687 assert.equal(moment('2014-05-01').diff(moment('2014-01-01'), 'quarter'), | |
37688 1, 'diff 1 quarter'); | |
37689 assert.ok(Math.abs((4 / 3) - moment('2014-05-01').diff( | |
37690 moment('2014-01-01'), 'quarter', true)) < 0.00001, | |
37691 'diff 1 1/3 quarter'); | |
37692 assert.equal(moment('2015-01-01').diff(moment('2014-01-01'), 'quarter'), | |
37693 4, 'diff 4 quarters'); | |
37694 }); | |
37695 | |
37696 test('quarter setter bubble to previous year', function (assert) { | |
37697 var m = moment([2014, 4, 11, 1, 2, 3, 4]).quarter(-3); | |
37698 assert.equal(m.year(), 2013, 'year bubbled'); | |
37699 assert.equal(m.month(), 1, 'set month'); | |
37700 assert.equal(m.date(), 11, 'keep date'); | |
37701 assert.equal(m.hour(), 1, 'keep hour'); | |
37702 assert.equal(m.minute(), 2, 'keep minutes'); | |
37703 assert.equal(m.second(), 3, 'keep seconds'); | |
37704 assert.equal(m.millisecond(), 4, 'keep milliseconds'); | |
37705 }); | |
37706 | |
37707 })); | |
37708 | |
37709 (function (global, factory) { | |
37710 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
37711 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
37712 factory(global.moment) | |
37713 }(this, function (moment) { 'use strict'; | |
37714 | |
37715 /*global QUnit:false*/ | |
37716 | |
37717 var test = QUnit.test; | |
37718 | |
37719 function module (name, lifecycle) { | |
37720 QUnit.module(name, { | |
37721 setup : function () { | |
37722 moment.locale('en'); | |
37723 moment.createFromInputFallback = function () { | |
37724 throw new Error('input not handled by moment'); | |
37725 }; | |
37726 if (lifecycle && lifecycle.setup) { | |
37727 lifecycle.setup(); | |
37728 } | |
37729 }, | |
37730 teardown : function () { | |
37731 if (lifecycle && lifecycle.teardown) { | |
37732 lifecycle.teardown(); | |
37733 } | |
37734 } | |
37735 }); | |
37736 } | |
37737 | |
37738 function localeModule (name, lifecycle) { | |
37739 QUnit.module('locale:' + name, { | |
37740 setup : function () { | |
37741 moment.locale(name); | |
37742 moment.createFromInputFallback = function () { | |
37743 throw new Error('input not handled by moment'); | |
37744 }; | |
37745 if (lifecycle && lifecycle.setup) { | |
37746 lifecycle.setup(); | |
37747 } | |
37748 }, | |
37749 teardown : function () { | |
37750 moment.locale('en'); | |
37751 if (lifecycle && lifecycle.teardown) { | |
37752 lifecycle.teardown(); | |
37753 } | |
37754 } | |
37755 }); | |
37756 } | |
37757 | |
37758 module('relative time'); | |
37759 | |
37760 test('default thresholds fromNow', function (assert) { | |
37761 var a = moment(); | |
37762 | |
37763 // Seconds to minutes threshold | |
37764 a.subtract(44, 'seconds'); | |
37765 assert.equal(a.fromNow(), 'a few seconds ago', 'Below default seconds to minutes threshold'); | |
37766 a.subtract(1, 'seconds'); | |
37767 assert.equal(a.fromNow(), 'a minute ago', 'Above default seconds to minutes threshold'); | |
37768 | |
37769 // Minutes to hours threshold | |
37770 a = moment(); | |
37771 a.subtract(44, 'minutes'); | |
37772 assert.equal(a.fromNow(), '44 minutes ago', 'Below default minute to hour threshold'); | |
37773 a.subtract(1, 'minutes'); | |
37774 assert.equal(a.fromNow(), 'an hour ago', 'Above default minute to hour threshold'); | |
37775 | |
37776 // Hours to days threshold | |
37777 a = moment(); | |
37778 a.subtract(21, 'hours'); | |
37779 assert.equal(a.fromNow(), '21 hours ago', 'Below default hours to day threshold'); | |
37780 a.subtract(1, 'hours'); | |
37781 assert.equal(a.fromNow(), 'a day ago', 'Above default hours to day threshold'); | |
37782 | |
37783 // Days to month threshold | |
37784 a = moment(); | |
37785 a.subtract(25, 'days'); | |
37786 assert.equal(a.fromNow(), '25 days ago', 'Below default days to month (singular) threshold'); | |
37787 a.subtract(1, 'days'); | |
37788 assert.equal(a.fromNow(), 'a month ago', 'Above default days to month (singular) threshold'); | |
37789 | |
37790 // months to year threshold | |
37791 a = moment(); | |
37792 a.subtract(10, 'months'); | |
37793 assert.equal(a.fromNow(), '10 months ago', 'Below default days to years threshold'); | |
37794 a.subtract(1, 'month'); | |
37795 assert.equal(a.fromNow(), 'a year ago', 'Above default days to years threshold'); | |
37796 }); | |
37797 | |
37798 test('default thresholds toNow', function (assert) { | |
37799 var a = moment(); | |
37800 | |
37801 // Seconds to minutes threshold | |
37802 a.subtract(44, 'seconds'); | |
37803 assert.equal(a.toNow(), 'in a few seconds', 'Below default seconds to minutes threshold'); | |
37804 a.subtract(1, 'seconds'); | |
37805 assert.equal(a.toNow(), 'in a minute', 'Above default seconds to minutes threshold'); | |
37806 | |
37807 // Minutes to hours threshold | |
37808 a = moment(); | |
37809 a.subtract(44, 'minutes'); | |
37810 assert.equal(a.toNow(), 'in 44 minutes', 'Below default minute to hour threshold'); | |
37811 a.subtract(1, 'minutes'); | |
37812 assert.equal(a.toNow(), 'in an hour', 'Above default minute to hour threshold'); | |
37813 | |
37814 // Hours to days threshold | |
37815 a = moment(); | |
37816 a.subtract(21, 'hours'); | |
37817 assert.equal(a.toNow(), 'in 21 hours', 'Below default hours to day threshold'); | |
37818 a.subtract(1, 'hours'); | |
37819 assert.equal(a.toNow(), 'in a day', 'Above default hours to day threshold'); | |
37820 | |
37821 // Days to month threshold | |
37822 a = moment(); | |
37823 a.subtract(25, 'days'); | |
37824 assert.equal(a.toNow(), 'in 25 days', 'Below default days to month (singular) threshold'); | |
37825 a.subtract(1, 'days'); | |
37826 assert.equal(a.toNow(), 'in a month', 'Above default days to month (singular) threshold'); | |
37827 | |
37828 // months to year threshold | |
37829 a = moment(); | |
37830 a.subtract(10, 'months'); | |
37831 assert.equal(a.toNow(), 'in 10 months', 'Below default days to years threshold'); | |
37832 a.subtract(1, 'month'); | |
37833 assert.equal(a.toNow(), 'in a year', 'Above default days to years threshold'); | |
37834 }); | |
37835 | |
37836 test('custom thresholds', function (assert) { | |
37837 // Seconds to minutes threshold | |
37838 moment.relativeTimeThreshold('s', 55); | |
37839 | |
37840 var a = moment(); | |
37841 a.subtract(54, 'seconds'); | |
37842 assert.equal(a.fromNow(), 'a few seconds ago', 'Below custom seconds to minutes threshold'); | |
37843 a.subtract(1, 'seconds'); | |
37844 assert.equal(a.fromNow(), 'a minute ago', 'Above custom seconds to minutes threshold'); | |
37845 | |
37846 moment.relativeTimeThreshold('s', 45); | |
37847 | |
37848 // Minutes to hours threshold | |
37849 moment.relativeTimeThreshold('m', 55); | |
37850 a = moment(); | |
37851 a.subtract(54, 'minutes'); | |
37852 assert.equal(a.fromNow(), '54 minutes ago', 'Below custom minutes to hours threshold'); | |
37853 a.subtract(1, 'minutes'); | |
37854 assert.equal(a.fromNow(), 'an hour ago', 'Above custom minutes to hours threshold'); | |
37855 moment.relativeTimeThreshold('m', 45); | |
37856 | |
37857 // Hours to days threshold | |
37858 moment.relativeTimeThreshold('h', 24); | |
37859 a = moment(); | |
37860 a.subtract(23, 'hours'); | |
37861 assert.equal(a.fromNow(), '23 hours ago', 'Below custom hours to days threshold'); | |
37862 a.subtract(1, 'hours'); | |
37863 assert.equal(a.fromNow(), 'a day ago', 'Above custom hours to days threshold'); | |
37864 moment.relativeTimeThreshold('h', 22); | |
37865 | |
37866 // Days to month threshold | |
37867 moment.relativeTimeThreshold('d', 28); | |
37868 a = moment(); | |
37869 a.subtract(27, 'days'); | |
37870 assert.equal(a.fromNow(), '27 days ago', 'Below custom days to month (singular) threshold'); | |
37871 a.subtract(1, 'days'); | |
37872 assert.equal(a.fromNow(), 'a month ago', 'Above custom days to month (singular) threshold'); | |
37873 moment.relativeTimeThreshold('d', 26); | |
37874 | |
37875 // months to years threshold | |
37876 moment.relativeTimeThreshold('M', 9); | |
37877 a = moment(); | |
37878 a.subtract(8, 'months'); | |
37879 assert.equal(a.fromNow(), '8 months ago', 'Below custom days to years threshold'); | |
37880 a.subtract(1, 'months'); | |
37881 assert.equal(a.fromNow(), 'a year ago', 'Above custom days to years threshold'); | |
37882 moment.relativeTimeThreshold('M', 11); | |
37883 }); | |
37884 | |
37885 test('retrive threshold settings', function (assert) { | |
37886 moment.relativeTimeThreshold('m', 45); | |
37887 var minuteThreshold = moment.relativeTimeThreshold('m'); | |
37888 | |
37889 assert.equal(minuteThreshold, 45, 'Can retrieve minute setting'); | |
37890 }); | |
37891 | |
37892 })); | |
37893 | |
37894 (function (global, factory) { | |
37895 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
37896 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
37897 factory(global.moment) | |
37898 }(this, function (moment) { 'use strict'; | |
37899 | |
37900 /*global QUnit:false*/ | |
37901 | |
37902 var test = QUnit.test; | |
37903 | |
37904 function module (name, lifecycle) { | |
37905 QUnit.module(name, { | |
37906 setup : function () { | |
37907 moment.locale('en'); | |
37908 moment.createFromInputFallback = function () { | |
37909 throw new Error('input not handled by moment'); | |
37910 }; | |
37911 if (lifecycle && lifecycle.setup) { | |
37912 lifecycle.setup(); | |
37913 } | |
37914 }, | |
37915 teardown : function () { | |
37916 if (lifecycle && lifecycle.teardown) { | |
37917 lifecycle.teardown(); | |
37918 } | |
37919 } | |
37920 }); | |
37921 } | |
37922 | |
37923 function localeModule (name, lifecycle) { | |
37924 QUnit.module('locale:' + name, { | |
37925 setup : function () { | |
37926 moment.locale(name); | |
37927 moment.createFromInputFallback = function () { | |
37928 throw new Error('input not handled by moment'); | |
37929 }; | |
37930 if (lifecycle && lifecycle.setup) { | |
37931 lifecycle.setup(); | |
37932 } | |
37933 }, | |
37934 teardown : function () { | |
37935 moment.locale('en'); | |
37936 if (lifecycle && lifecycle.teardown) { | |
37937 lifecycle.teardown(); | |
37938 } | |
37939 } | |
37940 }); | |
37941 } | |
37942 | |
37943 module('start and end of units'); | |
37944 | |
37945 test('start of year', function (assert) { | |
37946 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('year'), | |
37947 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('years'), | |
37948 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('y'); | |
37949 assert.equal(+m, +ms, 'Plural or singular should work'); | |
37950 assert.equal(+m, +ma, 'Full or abbreviated should work'); | |
37951 assert.equal(m.year(), 2011, 'keep the year'); | |
37952 assert.equal(m.month(), 0, 'strip out the month'); | |
37953 assert.equal(m.date(), 1, 'strip out the day'); | |
37954 assert.equal(m.hours(), 0, 'strip out the hours'); | |
37955 assert.equal(m.minutes(), 0, 'strip out the minutes'); | |
37956 assert.equal(m.seconds(), 0, 'strip out the seconds'); | |
37957 assert.equal(m.milliseconds(), 0, 'strip out the milliseconds'); | |
37958 }); | |
37959 | |
37960 test('end of year', function (assert) { | |
37961 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('year'), | |
37962 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('years'), | |
37963 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('y'); | |
37964 assert.equal(+m, +ms, 'Plural or singular should work'); | |
37965 assert.equal(+m, +ma, 'Full or abbreviated should work'); | |
37966 assert.equal(m.year(), 2011, 'keep the year'); | |
37967 assert.equal(m.month(), 11, 'set the month'); | |
37968 assert.equal(m.date(), 31, 'set the day'); | |
37969 assert.equal(m.hours(), 23, 'set the hours'); | |
37970 assert.equal(m.minutes(), 59, 'set the minutes'); | |
37971 assert.equal(m.seconds(), 59, 'set the seconds'); | |
37972 assert.equal(m.milliseconds(), 999, 'set the seconds'); | |
37973 }); | |
37974 | |
37975 test('start of quarter', function (assert) { | |
37976 var m = moment(new Date(2011, 4, 2, 3, 4, 5, 6)).startOf('quarter'), | |
37977 ms = moment(new Date(2011, 4, 2, 3, 4, 5, 6)).startOf('quarters'), | |
37978 ma = moment(new Date(2011, 4, 2, 3, 4, 5, 6)).startOf('Q'); | |
37979 assert.equal(+m, +ms, 'Plural or singular should work'); | |
37980 assert.equal(+m, +ma, 'Full or abbreviated should work'); | |
37981 assert.equal(m.year(), 2011, 'keep the year'); | |
37982 assert.equal(m.quarter(), 2, 'keep the quarter'); | |
37983 assert.equal(m.month(), 3, 'strip out the month'); | |
37984 assert.equal(m.date(), 1, 'strip out the day'); | |
37985 assert.equal(m.hours(), 0, 'strip out the hours'); | |
37986 assert.equal(m.minutes(), 0, 'strip out the minutes'); | |
37987 assert.equal(m.seconds(), 0, 'strip out the seconds'); | |
37988 assert.equal(m.milliseconds(), 0, 'strip out the milliseconds'); | |
37989 }); | |
37990 | |
37991 test('end of quarter', function (assert) { | |
37992 var m = moment(new Date(2011, 4, 2, 3, 4, 5, 6)).endOf('quarter'), | |
37993 ms = moment(new Date(2011, 4, 2, 3, 4, 5, 6)).endOf('quarters'), | |
37994 ma = moment(new Date(2011, 4, 2, 3, 4, 5, 6)).endOf('Q'); | |
37995 assert.equal(+m, +ms, 'Plural or singular should work'); | |
37996 assert.equal(+m, +ma, 'Full or abbreviated should work'); | |
37997 assert.equal(m.year(), 2011, 'keep the year'); | |
37998 assert.equal(m.quarter(), 2, 'keep the quarter'); | |
37999 assert.equal(m.month(), 5, 'set the month'); | |
38000 assert.equal(m.date(), 30, 'set the day'); | |
38001 assert.equal(m.hours(), 23, 'set the hours'); | |
38002 assert.equal(m.minutes(), 59, 'set the minutes'); | |
38003 assert.equal(m.seconds(), 59, 'set the seconds'); | |
38004 assert.equal(m.milliseconds(), 999, 'set the seconds'); | |
38005 }); | |
38006 | |
38007 test('start of month', function (assert) { | |
38008 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('month'), | |
38009 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('months'), | |
38010 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('M'); | |
38011 assert.equal(+m, +ms, 'Plural or singular should work'); | |
38012 assert.equal(+m, +ma, 'Full or abbreviated should work'); | |
38013 assert.equal(m.year(), 2011, 'keep the year'); | |
38014 assert.equal(m.month(), 1, 'keep the month'); | |
38015 assert.equal(m.date(), 1, 'strip out the day'); | |
38016 assert.equal(m.hours(), 0, 'strip out the hours'); | |
38017 assert.equal(m.minutes(), 0, 'strip out the minutes'); | |
38018 assert.equal(m.seconds(), 0, 'strip out the seconds'); | |
38019 assert.equal(m.milliseconds(), 0, 'strip out the milliseconds'); | |
38020 }); | |
38021 | |
38022 test('end of month', function (assert) { | |
38023 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('month'), | |
38024 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('months'), | |
38025 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('M'); | |
38026 assert.equal(+m, +ms, 'Plural or singular should work'); | |
38027 assert.equal(+m, +ma, 'Full or abbreviated should work'); | |
38028 assert.equal(m.year(), 2011, 'keep the year'); | |
38029 assert.equal(m.month(), 1, 'keep the month'); | |
38030 assert.equal(m.date(), 28, 'set the day'); | |
38031 assert.equal(m.hours(), 23, 'set the hours'); | |
38032 assert.equal(m.minutes(), 59, 'set the minutes'); | |
38033 assert.equal(m.seconds(), 59, 'set the seconds'); | |
38034 assert.equal(m.milliseconds(), 999, 'set the seconds'); | |
38035 }); | |
38036 | |
38037 test('start of week', function (assert) { | |
38038 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('week'), | |
38039 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('weeks'), | |
38040 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('w'); | |
38041 assert.equal(+m, +ms, 'Plural or singular should work'); | |
38042 assert.equal(+m, +ma, 'Full or abbreviated should work'); | |
38043 assert.equal(m.year(), 2011, 'keep the year'); | |
38044 assert.equal(m.month(), 0, 'rolls back to January'); | |
38045 assert.equal(m.day(), 0, 'set day of week'); | |
38046 assert.equal(m.date(), 30, 'set correct date'); | |
38047 assert.equal(m.hours(), 0, 'strip out the hours'); | |
38048 assert.equal(m.minutes(), 0, 'strip out the minutes'); | |
38049 assert.equal(m.seconds(), 0, 'strip out the seconds'); | |
38050 assert.equal(m.milliseconds(), 0, 'strip out the milliseconds'); | |
38051 }); | |
38052 | |
38053 test('end of week', function (assert) { | |
38054 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('week'), | |
38055 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('weeks'), | |
38056 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('weeks'); | |
38057 assert.equal(+m, +ms, 'Plural or singular should work'); | |
38058 assert.equal(+m, +ma, 'Full or abbreviated should work'); | |
38059 assert.equal(m.year(), 2011, 'keep the year'); | |
38060 assert.equal(m.month(), 1, 'keep the month'); | |
38061 assert.equal(m.day(), 6, 'set the day of the week'); | |
38062 assert.equal(m.date(), 5, 'set the day'); | |
38063 assert.equal(m.hours(), 23, 'set the hours'); | |
38064 assert.equal(m.minutes(), 59, 'set the minutes'); | |
38065 assert.equal(m.seconds(), 59, 'set the seconds'); | |
38066 assert.equal(m.milliseconds(), 999, 'set the seconds'); | |
38067 }); | |
38068 | |
38069 test('start of iso-week', function (assert) { | |
38070 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('isoWeek'), | |
38071 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('isoWeeks'), | |
38072 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('W'); | |
38073 assert.equal(+m, +ms, 'Plural or singular should work'); | |
38074 assert.equal(+m, +ma, 'Full or abbreviated should work'); | |
38075 assert.equal(m.year(), 2011, 'keep the year'); | |
38076 assert.equal(m.month(), 0, 'rollback to January'); | |
38077 assert.equal(m.isoWeekday(), 1, 'set day of iso-week'); | |
38078 assert.equal(m.date(), 31, 'set correct date'); | |
38079 assert.equal(m.hours(), 0, 'strip out the hours'); | |
38080 assert.equal(m.minutes(), 0, 'strip out the minutes'); | |
38081 assert.equal(m.seconds(), 0, 'strip out the seconds'); | |
38082 assert.equal(m.milliseconds(), 0, 'strip out the milliseconds'); | |
38083 }); | |
38084 | |
38085 test('end of iso-week', function (assert) { | |
38086 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('isoWeek'), | |
38087 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('isoWeeks'), | |
38088 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('W'); | |
38089 assert.equal(+m, +ms, 'Plural or singular should work'); | |
38090 assert.equal(+m, +ma, 'Full or abbreviated should work'); | |
38091 assert.equal(m.year(), 2011, 'keep the year'); | |
38092 assert.equal(m.month(), 1, 'keep the month'); | |
38093 assert.equal(m.isoWeekday(), 7, 'set the day of the week'); | |
38094 assert.equal(m.date(), 6, 'set the day'); | |
38095 assert.equal(m.hours(), 23, 'set the hours'); | |
38096 assert.equal(m.minutes(), 59, 'set the minutes'); | |
38097 assert.equal(m.seconds(), 59, 'set the seconds'); | |
38098 assert.equal(m.milliseconds(), 999, 'set the seconds'); | |
38099 }); | |
38100 | |
38101 test('start of day', function (assert) { | |
38102 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('day'), | |
38103 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('days'), | |
38104 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('d'); | |
38105 assert.equal(+m, +ms, 'Plural or singular should work'); | |
38106 assert.equal(+m, +ma, 'Full or abbreviated should work'); | |
38107 assert.equal(m.year(), 2011, 'keep the year'); | |
38108 assert.equal(m.month(), 1, 'keep the month'); | |
38109 assert.equal(m.date(), 2, 'keep the day'); | |
38110 assert.equal(m.hours(), 0, 'strip out the hours'); | |
38111 assert.equal(m.minutes(), 0, 'strip out the minutes'); | |
38112 assert.equal(m.seconds(), 0, 'strip out the seconds'); | |
38113 assert.equal(m.milliseconds(), 0, 'strip out the milliseconds'); | |
38114 }); | |
38115 | |
38116 test('end of day', function (assert) { | |
38117 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('day'), | |
38118 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('days'), | |
38119 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('d'); | |
38120 assert.equal(+m, +ms, 'Plural or singular should work'); | |
38121 assert.equal(+m, +ma, 'Full or abbreviated should work'); | |
38122 assert.equal(m.year(), 2011, 'keep the year'); | |
38123 assert.equal(m.month(), 1, 'keep the month'); | |
38124 assert.equal(m.date(), 2, 'keep the day'); | |
38125 assert.equal(m.hours(), 23, 'set the hours'); | |
38126 assert.equal(m.minutes(), 59, 'set the minutes'); | |
38127 assert.equal(m.seconds(), 59, 'set the seconds'); | |
38128 assert.equal(m.milliseconds(), 999, 'set the seconds'); | |
38129 }); | |
38130 | |
38131 test('start of hour', function (assert) { | |
38132 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('hour'), | |
38133 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('hours'), | |
38134 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('h'); | |
38135 assert.equal(+m, +ms, 'Plural or singular should work'); | |
38136 assert.equal(+m, +ma, 'Full or abbreviated should work'); | |
38137 assert.equal(m.year(), 2011, 'keep the year'); | |
38138 assert.equal(m.month(), 1, 'keep the month'); | |
38139 assert.equal(m.date(), 2, 'keep the day'); | |
38140 assert.equal(m.hours(), 3, 'keep the hours'); | |
38141 assert.equal(m.minutes(), 0, 'strip out the minutes'); | |
38142 assert.equal(m.seconds(), 0, 'strip out the seconds'); | |
38143 assert.equal(m.milliseconds(), 0, 'strip out the milliseconds'); | |
38144 }); | |
38145 | |
38146 test('end of hour', function (assert) { | |
38147 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('hour'), | |
38148 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('hours'), | |
38149 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('h'); | |
38150 assert.equal(+m, +ms, 'Plural or singular should work'); | |
38151 assert.equal(+m, +ma, 'Full or abbreviated should work'); | |
38152 assert.equal(m.year(), 2011, 'keep the year'); | |
38153 assert.equal(m.month(), 1, 'keep the month'); | |
38154 assert.equal(m.date(), 2, 'keep the day'); | |
38155 assert.equal(m.hours(), 3, 'keep the hours'); | |
38156 assert.equal(m.minutes(), 59, 'set the minutes'); | |
38157 assert.equal(m.seconds(), 59, 'set the seconds'); | |
38158 assert.equal(m.milliseconds(), 999, 'set the seconds'); | |
38159 }); | |
38160 | |
38161 test('start of minute', function (assert) { | |
38162 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('minute'), | |
38163 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('minutes'), | |
38164 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('m'); | |
38165 assert.equal(+m, +ms, 'Plural or singular should work'); | |
38166 assert.equal(+m, +ma, 'Full or abbreviated should work'); | |
38167 assert.equal(m.year(), 2011, 'keep the year'); | |
38168 assert.equal(m.month(), 1, 'keep the month'); | |
38169 assert.equal(m.date(), 2, 'keep the day'); | |
38170 assert.equal(m.hours(), 3, 'keep the hours'); | |
38171 assert.equal(m.minutes(), 4, 'keep the minutes'); | |
38172 assert.equal(m.seconds(), 0, 'strip out the seconds'); | |
38173 assert.equal(m.milliseconds(), 0, 'strip out the milliseconds'); | |
38174 }); | |
38175 | |
38176 test('end of minute', function (assert) { | |
38177 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('minute'), | |
38178 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('minutes'), | |
38179 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('m'); | |
38180 assert.equal(+m, +ms, 'Plural or singular should work'); | |
38181 assert.equal(+m, +ma, 'Full or abbreviated should work'); | |
38182 assert.equal(m.year(), 2011, 'keep the year'); | |
38183 assert.equal(m.month(), 1, 'keep the month'); | |
38184 assert.equal(m.date(), 2, 'keep the day'); | |
38185 assert.equal(m.hours(), 3, 'keep the hours'); | |
38186 assert.equal(m.minutes(), 4, 'keep the minutes'); | |
38187 assert.equal(m.seconds(), 59, 'set the seconds'); | |
38188 assert.equal(m.milliseconds(), 999, 'set the seconds'); | |
38189 }); | |
38190 | |
38191 test('start of second', function (assert) { | |
38192 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('second'), | |
38193 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('seconds'), | |
38194 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('s'); | |
38195 assert.equal(+m, +ms, 'Plural or singular should work'); | |
38196 assert.equal(+m, +ma, 'Full or abbreviated should work'); | |
38197 assert.equal(m.year(), 2011, 'keep the year'); | |
38198 assert.equal(m.month(), 1, 'keep the month'); | |
38199 assert.equal(m.date(), 2, 'keep the day'); | |
38200 assert.equal(m.hours(), 3, 'keep the hours'); | |
38201 assert.equal(m.minutes(), 4, 'keep the minutes'); | |
38202 assert.equal(m.seconds(), 5, 'keep the the seconds'); | |
38203 assert.equal(m.milliseconds(), 0, 'strip out the milliseconds'); | |
38204 }); | |
38205 | |
38206 test('end of second', function (assert) { | |
38207 var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('second'), | |
38208 ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('seconds'), | |
38209 ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('s'); | |
38210 assert.equal(+m, +ms, 'Plural or singular should work'); | |
38211 assert.equal(+m, +ma, 'Full or abbreviated should work'); | |
38212 assert.equal(m.year(), 2011, 'keep the year'); | |
38213 assert.equal(m.month(), 1, 'keep the month'); | |
38214 assert.equal(m.date(), 2, 'keep the day'); | |
38215 assert.equal(m.hours(), 3, 'keep the hours'); | |
38216 assert.equal(m.minutes(), 4, 'keep the minutes'); | |
38217 assert.equal(m.seconds(), 5, 'keep the seconds'); | |
38218 assert.equal(m.milliseconds(), 999, 'set the seconds'); | |
38219 }); | |
38220 | |
38221 test('startOf across DST +1', function (assert) { | |
38222 var oldUpdateOffset = moment.updateOffset, | |
38223 // Based on a real story somewhere in America/Los_Angeles | |
38224 dstAt = moment('2014-03-09T02:00:00-08:00').parseZone(), | |
38225 m; | |
38226 | |
38227 moment.updateOffset = function (mom, keepTime) { | |
38228 if (mom.isBefore(dstAt)) { | |
38229 mom.utcOffset(-8, keepTime); | |
38230 } else { | |
38231 mom.utcOffset(-7, keepTime); | |
38232 } | |
38233 }; | |
38234 | |
38235 m = moment('2014-03-15T00:00:00-07:00').parseZone(); | |
38236 m.startOf('M'); | |
38237 assert.equal(m.format(), '2014-03-01T00:00:00-08:00', 'startOf(\'month\') across +1'); | |
38238 | |
38239 m = moment('2014-03-09T09:00:00-07:00').parseZone(); | |
38240 m.startOf('d'); | |
38241 assert.equal(m.format(), '2014-03-09T00:00:00-08:00', 'startOf(\'day\') across +1'); | |
38242 | |
38243 m = moment('2014-03-09T03:05:00-07:00').parseZone(); | |
38244 m.startOf('h'); | |
38245 assert.equal(m.format(), '2014-03-09T03:00:00-07:00', 'startOf(\'hour\') after +1'); | |
38246 | |
38247 m = moment('2014-03-09T01:35:00-08:00').parseZone(); | |
38248 m.startOf('h'); | |
38249 assert.equal(m.format(), '2014-03-09T01:00:00-08:00', 'startOf(\'hour\') before +1'); | |
38250 | |
38251 // There is no such time as 2:30-7 to try startOf('hour') across that | |
38252 | |
38253 moment.updateOffset = oldUpdateOffset; | |
38254 }); | |
38255 | |
38256 test('startOf across DST -1', function (assert) { | |
38257 var oldUpdateOffset = moment.updateOffset, | |
38258 // Based on a real story somewhere in America/Los_Angeles | |
38259 dstAt = moment('2014-11-02T02:00:00-07:00').parseZone(), | |
38260 m; | |
38261 | |
38262 moment.updateOffset = function (mom, keepTime) { | |
38263 if (mom.isBefore(dstAt)) { | |
38264 mom.utcOffset(-7, keepTime); | |
38265 } else { | |
38266 mom.utcOffset(-8, keepTime); | |
38267 } | |
38268 }; | |
38269 | |
38270 m = moment('2014-11-15T00:00:00-08:00').parseZone(); | |
38271 m.startOf('M'); | |
38272 assert.equal(m.format(), '2014-11-01T00:00:00-07:00', 'startOf(\'month\') across -1'); | |
38273 | |
38274 m = moment('2014-11-02T09:00:00-08:00').parseZone(); | |
38275 m.startOf('d'); | |
38276 assert.equal(m.format(), '2014-11-02T00:00:00-07:00', 'startOf(\'day\') across -1'); | |
38277 | |
38278 // note that utc offset is -8 | |
38279 m = moment('2014-11-02T01:30:00-08:00').parseZone(); | |
38280 m.startOf('h'); | |
38281 assert.equal(m.format(), '2014-11-02T01:00:00-08:00', 'startOf(\'hour\') after +1'); | |
38282 | |
38283 // note that utc offset is -7 | |
38284 m = moment('2014-11-02T01:30:00-07:00').parseZone(); | |
38285 m.startOf('h'); | |
38286 assert.equal(m.format(), '2014-11-02T01:00:00-07:00', 'startOf(\'hour\') before +1'); | |
38287 | |
38288 moment.updateOffset = oldUpdateOffset; | |
38289 }); | |
38290 | |
38291 test('endOf millisecond and no-arg', function (assert) { | |
38292 var m = moment(); | |
38293 assert.equal(+m, +m.clone().endOf(), 'endOf without argument should change time'); | |
38294 assert.equal(+m, +m.clone().endOf('ms'), 'endOf with ms argument should change time'); | |
38295 assert.equal(+m, +m.clone().endOf('millisecond'), 'endOf with millisecond argument should change time'); | |
38296 assert.equal(+m, +m.clone().endOf('milliseconds'), 'endOf with milliseconds argument should change time'); | |
38297 }); | |
38298 | |
38299 })); | |
38300 | |
38301 (function (global, factory) { | |
38302 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
38303 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
38304 factory(global.moment) | |
38305 }(this, function (moment) { 'use strict'; | |
38306 | |
38307 /*global QUnit:false*/ | |
38308 | |
38309 var test = QUnit.test; | |
38310 | |
38311 function module (name, lifecycle) { | |
38312 QUnit.module(name, { | |
38313 setup : function () { | |
38314 moment.locale('en'); | |
38315 moment.createFromInputFallback = function () { | |
38316 throw new Error('input not handled by moment'); | |
38317 }; | |
38318 if (lifecycle && lifecycle.setup) { | |
38319 lifecycle.setup(); | |
38320 } | |
38321 }, | |
38322 teardown : function () { | |
38323 if (lifecycle && lifecycle.teardown) { | |
38324 lifecycle.teardown(); | |
38325 } | |
38326 } | |
38327 }); | |
38328 } | |
38329 | |
38330 function localeModule (name, lifecycle) { | |
38331 QUnit.module('locale:' + name, { | |
38332 setup : function () { | |
38333 moment.locale(name); | |
38334 moment.createFromInputFallback = function () { | |
38335 throw new Error('input not handled by moment'); | |
38336 }; | |
38337 if (lifecycle && lifecycle.setup) { | |
38338 lifecycle.setup(); | |
38339 } | |
38340 }, | |
38341 teardown : function () { | |
38342 moment.locale('en'); | |
38343 if (lifecycle && lifecycle.teardown) { | |
38344 lifecycle.teardown(); | |
38345 } | |
38346 } | |
38347 }); | |
38348 } | |
38349 | |
38350 module('string prototype'); | |
38351 | |
38352 test('string prototype overrides call', function (assert) { | |
38353 var prior = String.prototype.call, b; | |
38354 String.prototype.call = function () { | |
38355 return null; | |
38356 }; | |
38357 | |
38358 b = moment(new Date(2011, 7, 28, 15, 25, 50, 125)); | |
38359 assert.equal(b.format('MMMM Do YYYY, h:mm a'), 'August 28th 2011, 3:25 pm'); | |
38360 | |
38361 String.prototype.call = prior; | |
38362 }); | |
38363 | |
38364 })); | |
38365 | |
38366 (function (global, factory) { | |
38367 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
38368 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
38369 factory(global.moment) | |
38370 }(this, function (moment) { 'use strict'; | |
38371 | |
38372 /*global QUnit:false*/ | |
38373 | |
38374 var test = QUnit.test; | |
38375 | |
38376 function module (name, lifecycle) { | |
38377 QUnit.module(name, { | |
38378 setup : function () { | |
38379 moment.locale('en'); | |
38380 moment.createFromInputFallback = function () { | |
38381 throw new Error('input not handled by moment'); | |
38382 }; | |
38383 if (lifecycle && lifecycle.setup) { | |
38384 lifecycle.setup(); | |
38385 } | |
38386 }, | |
38387 teardown : function () { | |
38388 if (lifecycle && lifecycle.teardown) { | |
38389 lifecycle.teardown(); | |
38390 } | |
38391 } | |
38392 }); | |
38393 } | |
38394 | |
38395 function localeModule (name, lifecycle) { | |
38396 QUnit.module('locale:' + name, { | |
38397 setup : function () { | |
38398 moment.locale(name); | |
38399 moment.createFromInputFallback = function () { | |
38400 throw new Error('input not handled by moment'); | |
38401 }; | |
38402 if (lifecycle && lifecycle.setup) { | |
38403 lifecycle.setup(); | |
38404 } | |
38405 }, | |
38406 teardown : function () { | |
38407 moment.locale('en'); | |
38408 if (lifecycle && lifecycle.teardown) { | |
38409 lifecycle.teardown(); | |
38410 } | |
38411 } | |
38412 }); | |
38413 } | |
38414 | |
38415 module('to type'); | |
38416 | |
38417 test('toObject', function (assert) { | |
38418 var expected = { | |
38419 years:2010, | |
38420 months:3, | |
38421 date:5, | |
38422 hours:15, | |
38423 minutes:10, | |
38424 seconds:3, | |
38425 milliseconds:123 | |
38426 }; | |
38427 assert.deepEqual(moment(expected).toObject(), expected, 'toObject invalid'); | |
38428 }); | |
38429 | |
38430 test('toArray', function (assert) { | |
38431 var expected = [2014, 11, 26, 11, 46, 58, 17]; | |
38432 assert.deepEqual(moment(expected).toArray(), expected, 'toArray invalid'); | |
38433 }); | |
38434 | |
38435 })); | |
38436 | |
38437 (function (global, factory) { | |
38438 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
38439 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
38440 factory(global.moment) | |
38441 }(this, function (moment) { 'use strict'; | |
38442 | |
38443 /*global QUnit:false*/ | |
38444 | |
38445 var test = QUnit.test; | |
38446 | |
38447 function module (name, lifecycle) { | |
38448 QUnit.module(name, { | |
38449 setup : function () { | |
38450 moment.locale('en'); | |
38451 moment.createFromInputFallback = function () { | |
38452 throw new Error('input not handled by moment'); | |
38453 }; | |
38454 if (lifecycle && lifecycle.setup) { | |
38455 lifecycle.setup(); | |
38456 } | |
38457 }, | |
38458 teardown : function () { | |
38459 if (lifecycle && lifecycle.teardown) { | |
38460 lifecycle.teardown(); | |
38461 } | |
38462 } | |
38463 }); | |
38464 } | |
38465 | |
38466 function localeModule (name, lifecycle) { | |
38467 QUnit.module('locale:' + name, { | |
38468 setup : function () { | |
38469 moment.locale(name); | |
38470 moment.createFromInputFallback = function () { | |
38471 throw new Error('input not handled by moment'); | |
38472 }; | |
38473 if (lifecycle && lifecycle.setup) { | |
38474 lifecycle.setup(); | |
38475 } | |
38476 }, | |
38477 teardown : function () { | |
38478 moment.locale('en'); | |
38479 if (lifecycle && lifecycle.teardown) { | |
38480 lifecycle.teardown(); | |
38481 } | |
38482 } | |
38483 }); | |
38484 } | |
38485 | |
38486 module('utc'); | |
38487 | |
38488 test('utc and local', function (assert) { | |
38489 var m = moment(Date.UTC(2011, 1, 2, 3, 4, 5, 6)), offset, expected; | |
38490 m.utc(); | |
38491 // utc | |
38492 assert.equal(m.date(), 2, 'the day should be correct for utc'); | |
38493 assert.equal(m.day(), 3, 'the date should be correct for utc'); | |
38494 assert.equal(m.hours(), 3, 'the hours should be correct for utc'); | |
38495 | |
38496 // local | |
38497 m.local(); | |
38498 if (m.zone() > 180) { | |
38499 assert.equal(m.date(), 1, 'the date should be correct for local'); | |
38500 assert.equal(m.day(), 2, 'the day should be correct for local'); | |
38501 } else { | |
38502 assert.equal(m.date(), 2, 'the date should be correct for local'); | |
38503 assert.equal(m.day(), 3, 'the day should be correct for local'); | |
38504 } | |
38505 offset = Math.floor(m.utcOffset() / 60); | |
38506 expected = (24 + 3 + offset) % 24; | |
38507 assert.equal(m.hours(), expected, 'the hours (' + m.hours() + ') should be correct for local'); | |
38508 assert.equal(moment().utc().utcOffset(), 0, 'timezone in utc should always be zero'); | |
38509 }); | |
38510 | |
38511 test('creating with utc and no arguments', function (assert) { | |
38512 var startOfTest = new Date().valueOf(), | |
38513 momentDefaultUtcTime = moment.utc().valueOf(), | |
38514 afterMomentCreationTime = new Date().valueOf(); | |
38515 | |
38516 assert.ok(startOfTest <= momentDefaultUtcTime, 'moment UTC default time should be now, not in the past'); | |
38517 assert.ok(momentDefaultUtcTime <= afterMomentCreationTime, 'moment UTC default time should be now, not in the future'); | |
38518 }); | |
38519 | |
38520 test('creating with utc and a date parameter array', function (assert) { | |
38521 var m = moment.utc([2011, 1, 2, 3, 4, 5, 6]); | |
38522 assert.equal(m.date(), 2, 'the day should be correct for utc array'); | |
38523 assert.equal(m.hours(), 3, 'the hours should be correct for utc array'); | |
38524 | |
38525 m = moment.utc('2011-02-02 3:04:05', 'YYYY-MM-DD HH:mm:ss'); | |
38526 assert.equal(m.date(), 2, 'the day should be correct for utc parsing format'); | |
38527 assert.equal(m.hours(), 3, 'the hours should be correct for utc parsing format'); | |
38528 | |
38529 m = moment.utc('2011-02-02T03:04:05+00:00'); | |
38530 assert.equal(m.date(), 2, 'the day should be correct for utc parsing iso'); | |
38531 assert.equal(m.hours(), 3, 'the hours should be correct for utc parsing iso'); | |
38532 }); | |
38533 | |
38534 test('creating with utc without timezone', function (assert) { | |
38535 var m = moment.utc('2012-01-02T08:20:00'); | |
38536 assert.equal(m.date(), 2, 'the day should be correct for utc parse without timezone'); | |
38537 assert.equal(m.hours(), 8, 'the hours should be correct for utc parse without timezone'); | |
38538 | |
38539 m = moment.utc('2012-01-02T08:20:00+09:00'); | |
38540 assert.equal(m.date(), 1, 'the day should be correct for utc parse with timezone'); | |
38541 assert.equal(m.hours(), 23, 'the hours should be correct for utc parse with timezone'); | |
38542 }); | |
38543 | |
38544 test('cloning with utc offset', function (assert) { | |
38545 var m = moment.utc('2012-01-02T08:20:00'); | |
38546 assert.equal(moment.utc(m)._isUTC, true, 'the local offset should be converted to UTC'); | |
38547 assert.equal(moment.utc(m.clone().utc())._isUTC, true, 'the local offset should stay in UTC'); | |
38548 | |
38549 m.utcOffset(120); | |
38550 assert.equal(moment.utc(m)._isUTC, true, 'the explicit utc offset should stay in UTC'); | |
38551 assert.equal(moment.utc(m).utcOffset(), 0, 'the explicit utc offset should have an offset of 0'); | |
38552 }); | |
38553 | |
38554 test('weekday with utc', function (assert) { | |
38555 assert.equal( | |
38556 moment('2013-09-15T00:00:00Z').utc().weekday(), // first minute of the day | |
38557 moment('2013-09-15T23:59:00Z').utc().weekday(), // last minute of the day | |
38558 'a UTC-moment\'s .weekday() should not be affected by the local timezone' | |
38559 ); | |
38560 }); | |
38561 | |
38562 })); | |
38563 | |
38564 (function (global, factory) { | |
38565 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
38566 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
38567 factory(global.moment) | |
38568 }(this, function (moment) { 'use strict'; | |
38569 | |
38570 /*global QUnit:false*/ | |
38571 | |
38572 var test = QUnit.test; | |
38573 | |
38574 function module (name, lifecycle) { | |
38575 QUnit.module(name, { | |
38576 setup : function () { | |
38577 moment.locale('en'); | |
38578 moment.createFromInputFallback = function () { | |
38579 throw new Error('input not handled by moment'); | |
38580 }; | |
38581 if (lifecycle && lifecycle.setup) { | |
38582 lifecycle.setup(); | |
38583 } | |
38584 }, | |
38585 teardown : function () { | |
38586 if (lifecycle && lifecycle.teardown) { | |
38587 lifecycle.teardown(); | |
38588 } | |
38589 } | |
38590 }); | |
38591 } | |
38592 | |
38593 function localeModule (name, lifecycle) { | |
38594 QUnit.module('locale:' + name, { | |
38595 setup : function () { | |
38596 moment.locale(name); | |
38597 moment.createFromInputFallback = function () { | |
38598 throw new Error('input not handled by moment'); | |
38599 }; | |
38600 if (lifecycle && lifecycle.setup) { | |
38601 lifecycle.setup(); | |
38602 } | |
38603 }, | |
38604 teardown : function () { | |
38605 moment.locale('en'); | |
38606 if (lifecycle && lifecycle.teardown) { | |
38607 lifecycle.teardown(); | |
38608 } | |
38609 } | |
38610 }); | |
38611 } | |
38612 | |
38613 module('utc offset'); | |
38614 | |
38615 test('setter / getter blackbox', function (assert) { | |
38616 var m = moment([2010]); | |
38617 | |
38618 assert.equal(m.clone().utcOffset(0).utcOffset(), 0, 'utcOffset 0'); | |
38619 | |
38620 assert.equal(m.clone().utcOffset(1).utcOffset(), 60, 'utcOffset 1 is 60'); | |
38621 assert.equal(m.clone().utcOffset(60).utcOffset(), 60, 'utcOffset 60'); | |
38622 assert.equal(m.clone().utcOffset('+01:00').utcOffset(), 60, 'utcOffset +01:00 is 60'); | |
38623 assert.equal(m.clone().utcOffset('+0100').utcOffset(), 60, 'utcOffset +0100 is 60'); | |
38624 | |
38625 assert.equal(m.clone().utcOffset(-1).utcOffset(), -60, 'utcOffset -1 is -60'); | |
38626 assert.equal(m.clone().utcOffset(-60).utcOffset(), -60, 'utcOffset -60'); | |
38627 assert.equal(m.clone().utcOffset('-01:00').utcOffset(), -60, 'utcOffset -01:00 is -60'); | |
38628 assert.equal(m.clone().utcOffset('-0100').utcOffset(), -60, 'utcOffset -0100 is -60'); | |
38629 | |
38630 assert.equal(m.clone().utcOffset(1.5).utcOffset(), 90, 'utcOffset 1.5 is 90'); | |
38631 assert.equal(m.clone().utcOffset(90).utcOffset(), 90, 'utcOffset 1.5 is 90'); | |
38632 assert.equal(m.clone().utcOffset('+01:30').utcOffset(), 90, 'utcOffset +01:30 is 90'); | |
38633 assert.equal(m.clone().utcOffset('+0130').utcOffset(), 90, 'utcOffset +0130 is 90'); | |
38634 | |
38635 assert.equal(m.clone().utcOffset(-1.5).utcOffset(), -90, 'utcOffset -1.5'); | |
38636 assert.equal(m.clone().utcOffset(-90).utcOffset(), -90, 'utcOffset -90'); | |
38637 assert.equal(m.clone().utcOffset('-01:30').utcOffset(), -90, 'utcOffset +01:30 is 90'); | |
38638 assert.equal(m.clone().utcOffset('-0130').utcOffset(), -90, 'utcOffset +0130 is 90'); | |
38639 }); | |
38640 | |
38641 test('utcOffset shorthand hours -> minutes', function (assert) { | |
38642 var i; | |
38643 for (i = -15; i <= 15; ++i) { | |
38644 assert.equal(moment().utcOffset(i).utcOffset(), i * 60, | |
38645 '' + i + ' -> ' + i * 60); | |
38646 } | |
38647 assert.equal(moment().utcOffset(-16).utcOffset(), -16, '-16 -> -16'); | |
38648 assert.equal(moment().utcOffset(16).utcOffset(), 16, '16 -> 16'); | |
38649 }); | |
38650 | |
38651 test('isLocal, isUtc, isUtcOffset', function (assert) { | |
38652 assert.ok(moment().isLocal(), 'moment() creates objects in local time'); | |
38653 assert.ok(!moment.utc().isLocal(), 'moment.utc creates objects NOT in local time'); | |
38654 assert.ok(moment.utc().local().isLocal(), 'moment.fn.local() converts to local time'); | |
38655 assert.ok(!moment().utcOffset(5).isLocal(), 'moment.fn.utcOffset(N) puts objects NOT in local time'); | |
38656 assert.ok(moment().utcOffset(5).local().isLocal(), 'moment.fn.local() converts to local time'); | |
38657 | |
38658 assert.ok(moment.utc().isUtc(), 'moment.utc() creates objects in utc time'); | |
38659 assert.ok(moment().utcOffset(0).isUtc(), 'utcOffset(0) is equivalent to utc mode'); | |
38660 assert.ok(!moment().utcOffset(1).isUtc(), 'utcOffset(1) is NOT equivalent to utc mode'); | |
38661 | |
38662 assert.ok(!moment().isUtcOffset(), 'moment() creates objects NOT in utc-offset mode'); | |
38663 assert.ok(moment.utc().isUtcOffset(), 'moment.utc() creates objects in utc-offset mode'); | |
38664 assert.ok(moment().utcOffset(3).isUtcOffset(), 'utcOffset(N != 0) creates objects in utc-offset mode'); | |
38665 assert.ok(moment().utcOffset(0).isUtcOffset(), 'utcOffset(0) creates objects in utc-offset mode'); | |
38666 }); | |
38667 | |
38668 test('isUTC', function (assert) { | |
38669 assert.ok(moment.utc().isUTC(), 'moment.utc() creates objects in utc time'); | |
38670 assert.ok(moment().utcOffset(0).isUTC(), 'utcOffset(0) is equivalent to utc mode'); | |
38671 assert.ok(!moment().utcOffset(1).isUTC(), 'utcOffset(1) is NOT equivalent to utc mode'); | |
38672 }); | |
38673 | |
38674 test('change hours when changing the utc offset', function (assert) { | |
38675 var m = moment.utc([2000, 0, 1, 6]); | |
38676 assert.equal(m.hour(), 6, 'UTC 6AM should be 6AM at +0000'); | |
38677 | |
38678 // sanity check | |
38679 m.utcOffset(0); | |
38680 assert.equal(m.hour(), 6, 'UTC 6AM should be 6AM at +0000'); | |
38681 | |
38682 m.utcOffset(-60); | |
38683 assert.equal(m.hour(), 5, 'UTC 6AM should be 5AM at -0100'); | |
38684 | |
38685 m.utcOffset(60); | |
38686 assert.equal(m.hour(), 7, 'UTC 6AM should be 7AM at +0100'); | |
38687 }); | |
38688 | |
38689 test('change minutes when changing the utc offset', function (assert) { | |
38690 var m = moment.utc([2000, 0, 1, 6, 31]); | |
38691 | |
38692 m.utcOffset(0); | |
38693 assert.equal(m.format('HH:mm'), '06:31', 'UTC 6:31AM should be 6:31AM at +0000'); | |
38694 | |
38695 m.utcOffset(-30); | |
38696 assert.equal(m.format('HH:mm'), '06:01', 'UTC 6:31AM should be 6:01AM at -0030'); | |
38697 | |
38698 m.utcOffset(30); | |
38699 assert.equal(m.format('HH:mm'), '07:01', 'UTC 6:31AM should be 7:01AM at +0030'); | |
38700 | |
38701 m.utcOffset(-1380); | |
38702 assert.equal(m.format('HH:mm'), '07:31', 'UTC 6:31AM should be 7:31AM at +1380'); | |
38703 }); | |
38704 | |
38705 test('distance from the unix epoch', function (assert) { | |
38706 var zoneA = moment(), | |
38707 zoneB = moment(zoneA), | |
38708 zoneC = moment(zoneA), | |
38709 zoneD = moment(zoneA), | |
38710 zoneE = moment(zoneA); | |
38711 | |
38712 zoneB.utc(); | |
38713 assert.equal(+zoneA, +zoneB, 'moment should equal moment.utc'); | |
38714 | |
38715 zoneC.utcOffset(60); | |
38716 assert.equal(+zoneA, +zoneC, 'moment should equal moment.utcOffset(60)'); | |
38717 | |
38718 zoneD.utcOffset(-480); | |
38719 assert.equal(+zoneA, +zoneD, | |
38720 'moment should equal moment.utcOffset(-480)'); | |
38721 | |
38722 zoneE.utcOffset(-1000); | |
38723 assert.equal(+zoneA, +zoneE, | |
38724 'moment should equal moment.utcOffset(-1000)'); | |
38725 }); | |
38726 | |
38727 test('update offset after changing any values', function (assert) { | |
38728 var oldOffset = moment.updateOffset, | |
38729 m = moment.utc([2000, 6, 1]); | |
38730 | |
38731 moment.updateOffset = function (mom, keepTime) { | |
38732 if (mom.__doChange) { | |
38733 if (+mom > 962409600000) { | |
38734 mom.utcOffset(-120, keepTime); | |
38735 } else { | |
38736 mom.utcOffset(-60, keepTime); | |
38737 } | |
38738 } | |
38739 }; | |
38740 | |
38741 assert.equal(m.format('ZZ'), '+0000', 'should be at +0000'); | |
38742 assert.equal(m.format('HH:mm'), '00:00', 'should start 12AM at +0000 timezone'); | |
38743 | |
38744 m.__doChange = true; | |
38745 m.add(1, 'h'); | |
38746 | |
38747 assert.equal(m.format('ZZ'), '-0200', 'should be at -0200'); | |
38748 assert.equal(m.format('HH:mm'), '23:00', '1AM at +0000 should be 11PM at -0200 timezone'); | |
38749 | |
38750 m.subtract(1, 'h'); | |
38751 | |
38752 assert.equal(m.format('ZZ'), '-0100', 'should be at -0100'); | |
38753 assert.equal(m.format('HH:mm'), '23:00', '12AM at +0000 should be 11PM at -0100 timezone'); | |
38754 | |
38755 moment.updateOffset = oldOffset; | |
38756 }); | |
38757 | |
38758 ////////////////// | |
38759 test('getters and setters', function (assert) { | |
38760 var a = moment([2011, 5, 20]); | |
38761 | |
38762 assert.equal(a.clone().utcOffset(-120).year(2012).year(), 2012, 'should get and set year correctly'); | |
38763 assert.equal(a.clone().utcOffset(-120).month(1).month(), 1, 'should get and set month correctly'); | |
38764 assert.equal(a.clone().utcOffset(-120).date(2).date(), 2, 'should get and set date correctly'); | |
38765 assert.equal(a.clone().utcOffset(-120).day(1).day(), 1, 'should get and set day correctly'); | |
38766 assert.equal(a.clone().utcOffset(-120).hour(1).hour(), 1, 'should get and set hour correctly'); | |
38767 assert.equal(a.clone().utcOffset(-120).minute(1).minute(), 1, 'should get and set minute correctly'); | |
38768 }); | |
38769 | |
38770 test('getters', function (assert) { | |
38771 var a = moment.utc([2012, 0, 1, 0, 0, 0]); | |
38772 | |
38773 assert.equal(a.clone().utcOffset(-120).year(), 2011, 'should get year correctly'); | |
38774 assert.equal(a.clone().utcOffset(-120).month(), 11, 'should get month correctly'); | |
38775 assert.equal(a.clone().utcOffset(-120).date(), 31, 'should get date correctly'); | |
38776 assert.equal(a.clone().utcOffset(-120).hour(), 22, 'should get hour correctly'); | |
38777 assert.equal(a.clone().utcOffset(-120).minute(), 0, 'should get minute correctly'); | |
38778 | |
38779 assert.equal(a.clone().utcOffset(120).year(), 2012, 'should get year correctly'); | |
38780 assert.equal(a.clone().utcOffset(120).month(), 0, 'should get month correctly'); | |
38781 assert.equal(a.clone().utcOffset(120).date(), 1, 'should get date correctly'); | |
38782 assert.equal(a.clone().utcOffset(120).hour(), 2, 'should get hour correctly'); | |
38783 assert.equal(a.clone().utcOffset(120).minute(), 0, 'should get minute correctly'); | |
38784 | |
38785 assert.equal(a.clone().utcOffset(90).year(), 2012, 'should get year correctly'); | |
38786 assert.equal(a.clone().utcOffset(90).month(), 0, 'should get month correctly'); | |
38787 assert.equal(a.clone().utcOffset(90).date(), 1, 'should get date correctly'); | |
38788 assert.equal(a.clone().utcOffset(90).hour(), 1, 'should get hour correctly'); | |
38789 assert.equal(a.clone().utcOffset(90).minute(), 30, 'should get minute correctly'); | |
38790 }); | |
38791 | |
38792 test('from', function (assert) { | |
38793 var zoneA = moment(), | |
38794 zoneB = moment(zoneA).utcOffset(-720), | |
38795 zoneC = moment(zoneA).utcOffset(-360), | |
38796 zoneD = moment(zoneA).utcOffset(690), | |
38797 other = moment(zoneA).add(35, 'm'); | |
38798 | |
38799 assert.equal(zoneA.from(other), zoneB.from(other), 'moment#from should be the same in all zones'); | |
38800 assert.equal(zoneA.from(other), zoneC.from(other), 'moment#from should be the same in all zones'); | |
38801 assert.equal(zoneA.from(other), zoneD.from(other), 'moment#from should be the same in all zones'); | |
38802 }); | |
38803 | |
38804 test('diff', function (assert) { | |
38805 var zoneA = moment(), | |
38806 zoneB = moment(zoneA).utcOffset(-720), | |
38807 zoneC = moment(zoneA).utcOffset(-360), | |
38808 zoneD = moment(zoneA).utcOffset(690), | |
38809 other = moment(zoneA).add(35, 'm'); | |
38810 | |
38811 assert.equal(zoneA.diff(other), zoneB.diff(other), 'moment#diff should be the same in all zones'); | |
38812 assert.equal(zoneA.diff(other), zoneC.diff(other), 'moment#diff should be the same in all zones'); | |
38813 assert.equal(zoneA.diff(other), zoneD.diff(other), 'moment#diff should be the same in all zones'); | |
38814 | |
38815 assert.equal(zoneA.diff(other, 'minute', true), zoneB.diff(other, 'minute', true), 'moment#diff should be the same in all zones'); | |
38816 assert.equal(zoneA.diff(other, 'minute', true), zoneC.diff(other, 'minute', true), 'moment#diff should be the same in all zones'); | |
38817 assert.equal(zoneA.diff(other, 'minute', true), zoneD.diff(other, 'minute', true), 'moment#diff should be the same in all zones'); | |
38818 | |
38819 assert.equal(zoneA.diff(other, 'hour', true), zoneB.diff(other, 'hour', true), 'moment#diff should be the same in all zones'); | |
38820 assert.equal(zoneA.diff(other, 'hour', true), zoneC.diff(other, 'hour', true), 'moment#diff should be the same in all zones'); | |
38821 assert.equal(zoneA.diff(other, 'hour', true), zoneD.diff(other, 'hour', true), 'moment#diff should be the same in all zones'); | |
38822 }); | |
38823 | |
38824 test('unix offset and timestamp', function (assert) { | |
38825 var zoneA = moment(), | |
38826 zoneB = moment(zoneA).utcOffset(-720), | |
38827 zoneC = moment(zoneA).utcOffset(-360), | |
38828 zoneD = moment(zoneA).utcOffset(690); | |
38829 | |
38830 assert.equal(zoneA.unix(), zoneB.unix(), 'moment#unix should be the same in all zones'); | |
38831 assert.equal(zoneA.unix(), zoneC.unix(), 'moment#unix should be the same in all zones'); | |
38832 assert.equal(zoneA.unix(), zoneD.unix(), 'moment#unix should be the same in all zones'); | |
38833 | |
38834 assert.equal(+zoneA, +zoneB, 'moment#valueOf should be the same in all zones'); | |
38835 assert.equal(+zoneA, +zoneC, 'moment#valueOf should be the same in all zones'); | |
38836 assert.equal(+zoneA, +zoneD, 'moment#valueOf should be the same in all zones'); | |
38837 }); | |
38838 | |
38839 test('cloning', function (assert) { | |
38840 assert.equal(moment().utcOffset(-120).clone().utcOffset(), -120, | |
38841 'explicit cloning should retain the offset'); | |
38842 assert.equal(moment().utcOffset(120).clone().utcOffset(), 120, | |
38843 'explicit cloning should retain the offset'); | |
38844 assert.equal(moment(moment().utcOffset(-120)).utcOffset(), -120, | |
38845 'implicit cloning should retain the offset'); | |
38846 assert.equal(moment(moment().utcOffset(120)).utcOffset(), 120, | |
38847 'implicit cloning should retain the offset'); | |
38848 }); | |
38849 | |
38850 test('start of / end of', function (assert) { | |
38851 var a = moment.utc([2010, 1, 2, 0, 0, 0]).utcOffset(-450); | |
38852 | |
38853 assert.equal(a.clone().startOf('day').hour(), 0, | |
38854 'start of day should work on moments with utc offset'); | |
38855 assert.equal(a.clone().startOf('day').minute(), 0, | |
38856 'start of day should work on moments with utc offset'); | |
38857 assert.equal(a.clone().startOf('hour').minute(), 0, | |
38858 'start of hour should work on moments with utc offset'); | |
38859 | |
38860 assert.equal(a.clone().endOf('day').hour(), 23, | |
38861 'end of day should work on moments with utc offset'); | |
38862 assert.equal(a.clone().endOf('day').minute(), 59, | |
38863 'end of day should work on moments with utc offset'); | |
38864 assert.equal(a.clone().endOf('hour').minute(), 59, | |
38865 'end of hour should work on moments with utc offset'); | |
38866 }); | |
38867 | |
38868 test('reset offset with moment#utc', function (assert) { | |
38869 var a = moment.utc([2012]).utcOffset(-480); | |
38870 | |
38871 assert.equal(a.clone().hour(), 16, 'different utc offset should have different hour'); | |
38872 assert.equal(a.clone().utc().hour(), 0, 'calling moment#utc should reset the offset'); | |
38873 }); | |
38874 | |
38875 test('reset offset with moment#local', function (assert) { | |
38876 var a = moment([2012]).utcOffset(-480); | |
38877 | |
38878 assert.equal(a.clone().local().hour(), 0, 'calling moment#local should reset the offset'); | |
38879 }); | |
38880 | |
38881 test('toDate', function (assert) { | |
38882 var zoneA = new Date(), | |
38883 zoneB = moment(zoneA).utcOffset(-720).toDate(), | |
38884 zoneC = moment(zoneA).utcOffset(-360).toDate(), | |
38885 zoneD = moment(zoneA).utcOffset(690).toDate(); | |
38886 | |
38887 assert.equal(+zoneA, +zoneB, 'moment#toDate should output a date with the right unix timestamp'); | |
38888 assert.equal(+zoneA, +zoneC, 'moment#toDate should output a date with the right unix timestamp'); | |
38889 assert.equal(+zoneA, +zoneD, 'moment#toDate should output a date with the right unix timestamp'); | |
38890 }); | |
38891 | |
38892 test('same / before / after', function (assert) { | |
38893 var zoneA = moment().utc(), | |
38894 zoneB = moment(zoneA).utcOffset(-120), | |
38895 zoneC = moment(zoneA).utcOffset(120); | |
38896 | |
38897 assert.ok(zoneA.isSame(zoneB), 'two moments with different offsets should be the same'); | |
38898 assert.ok(zoneA.isSame(zoneC), 'two moments with different offsets should be the same'); | |
38899 | |
38900 assert.ok(zoneA.isSame(zoneB, 'hour'), 'two moments with different offsets should be the same hour'); | |
38901 assert.ok(zoneA.isSame(zoneC, 'hour'), 'two moments with different offsets should be the same hour'); | |
38902 | |
38903 zoneA.add(1, 'hour'); | |
38904 | |
38905 assert.ok(zoneA.isAfter(zoneB), 'isAfter should work with two moments with different offsets'); | |
38906 assert.ok(zoneA.isAfter(zoneC), 'isAfter should work with two moments with different offsets'); | |
38907 | |
38908 assert.ok(zoneA.isAfter(zoneB, 'hour'), 'isAfter:hour should work with two moments with different offsets'); | |
38909 assert.ok(zoneA.isAfter(zoneC, 'hour'), 'isAfter:hour should work with two moments with different offsets'); | |
38910 | |
38911 zoneA.subtract(2, 'hour'); | |
38912 | |
38913 assert.ok(zoneA.isBefore(zoneB), 'isBefore should work with two moments with different offsets'); | |
38914 assert.ok(zoneA.isBefore(zoneC), 'isBefore should work with two moments with different offsets'); | |
38915 | |
38916 assert.ok(zoneA.isBefore(zoneB, 'hour'), 'isBefore:hour should work with two moments with different offsets'); | |
38917 assert.ok(zoneA.isBefore(zoneC, 'hour'), 'isBefore:hour should work with two moments with different offsets'); | |
38918 }); | |
38919 | |
38920 test('add / subtract over dst', function (assert) { | |
38921 var oldOffset = moment.updateOffset, | |
38922 m = moment.utc([2000, 2, 31, 3]); | |
38923 | |
38924 moment.updateOffset = function (mom, keepTime) { | |
38925 if (mom.clone().utc().month() > 2) { | |
38926 mom.utcOffset(60, keepTime); | |
38927 } else { | |
38928 mom.utcOffset(0, keepTime); | |
38929 } | |
38930 }; | |
38931 | |
38932 assert.equal(m.hour(), 3, 'should start at 00:00'); | |
38933 | |
38934 m.add(24, 'hour'); | |
38935 | |
38936 assert.equal(m.hour(), 4, 'adding 24 hours should disregard dst'); | |
38937 | |
38938 m.subtract(24, 'hour'); | |
38939 | |
38940 assert.equal(m.hour(), 3, 'subtracting 24 hours should disregard dst'); | |
38941 | |
38942 m.add(1, 'day'); | |
38943 | |
38944 assert.equal(m.hour(), 3, 'adding 1 day should have the same hour'); | |
38945 | |
38946 m.subtract(1, 'day'); | |
38947 | |
38948 assert.equal(m.hour(), 3, 'subtracting 1 day should have the same hour'); | |
38949 | |
38950 m.add(1, 'month'); | |
38951 | |
38952 assert.equal(m.hour(), 3, 'adding 1 month should have the same hour'); | |
38953 | |
38954 m.subtract(1, 'month'); | |
38955 | |
38956 assert.equal(m.hour(), 3, 'subtracting 1 month should have the same hour'); | |
38957 | |
38958 moment.updateOffset = oldOffset; | |
38959 }); | |
38960 | |
38961 test('isDST', function (assert) { | |
38962 var oldOffset = moment.updateOffset; | |
38963 | |
38964 moment.updateOffset = function (mom, keepTime) { | |
38965 if (mom.month() > 2 && mom.month() < 9) { | |
38966 mom.utcOffset(60, keepTime); | |
38967 } else { | |
38968 mom.utcOffset(0, keepTime); | |
38969 } | |
38970 }; | |
38971 | |
38972 assert.ok(!moment().month(0).isDST(), 'Jan should not be summer dst'); | |
38973 assert.ok(moment().month(6).isDST(), 'Jul should be summer dst'); | |
38974 assert.ok(!moment().month(11).isDST(), 'Dec should not be summer dst'); | |
38975 | |
38976 moment.updateOffset = function (mom) { | |
38977 if (mom.month() > 2 && mom.month() < 9) { | |
38978 mom.utcOffset(0); | |
38979 } else { | |
38980 mom.utcOffset(60); | |
38981 } | |
38982 }; | |
38983 | |
38984 assert.ok(moment().month(0).isDST(), 'Jan should be winter dst'); | |
38985 assert.ok(!moment().month(6).isDST(), 'Jul should not be winter dst'); | |
38986 assert.ok(moment().month(11).isDST(), 'Dec should be winter dst'); | |
38987 | |
38988 moment.updateOffset = oldOffset; | |
38989 }); | |
38990 | |
38991 test('zone names', function (assert) { | |
38992 assert.equal(moment().zoneAbbr(), '', 'Local zone abbr should be empty'); | |
38993 assert.equal(moment().format('z'), '', 'Local zone formatted abbr should be empty'); | |
38994 assert.equal(moment().zoneName(), '', 'Local zone name should be empty'); | |
38995 assert.equal(moment().format('zz'), '', 'Local zone formatted name should be empty'); | |
38996 | |
38997 assert.equal(moment.utc().zoneAbbr(), 'UTC', 'UTC zone abbr should be UTC'); | |
38998 assert.equal(moment.utc().format('z'), 'UTC', 'UTC zone formatted abbr should be UTC'); | |
38999 assert.equal(moment.utc().zoneName(), 'Coordinated Universal Time', 'UTC zone abbr should be Coordinated Universal Time'); | |
39000 assert.equal(moment.utc().format('zz'), 'Coordinated Universal Time', 'UTC zone formatted abbr should be Coordinated Universal Time'); | |
39001 }); | |
39002 | |
39003 test('hours alignment with UTC', function (assert) { | |
39004 assert.equal(moment().utcOffset(-120).hasAlignedHourOffset(), true); | |
39005 assert.equal(moment().utcOffset(180).hasAlignedHourOffset(), true); | |
39006 assert.equal(moment().utcOffset(-90).hasAlignedHourOffset(), false); | |
39007 assert.equal(moment().utcOffset(90).hasAlignedHourOffset(), false); | |
39008 }); | |
39009 | |
39010 test('hours alignment with other zone', function (assert) { | |
39011 var m = moment().utcOffset(-120); | |
39012 | |
39013 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(-180)), true); | |
39014 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(180)), true); | |
39015 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(-90)), false); | |
39016 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(90)), false); | |
39017 | |
39018 m = moment().utcOffset(-90); | |
39019 | |
39020 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(-180)), false); | |
39021 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(180)), false); | |
39022 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(-30)), true); | |
39023 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(30)), true); | |
39024 | |
39025 m = moment().utcOffset(60); | |
39026 | |
39027 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(-180)), true); | |
39028 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(180)), true); | |
39029 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(-90)), false); | |
39030 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(90)), false); | |
39031 | |
39032 m = moment().utcOffset(-25); | |
39033 | |
39034 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(35)), true); | |
39035 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(-85)), true); | |
39036 | |
39037 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(-35)), false); | |
39038 assert.equal(m.hasAlignedHourOffset(moment().utcOffset(85)), false); | |
39039 }); | |
39040 | |
39041 test('parse zone', function (assert) { | |
39042 var m = moment('2013-01-01T00:00:00-13:00').parseZone(); | |
39043 assert.equal(m.utcOffset(), -13 * 60); | |
39044 assert.equal(m.hours(), 0); | |
39045 }); | |
39046 | |
39047 test('parse zone static', function (assert) { | |
39048 var m = moment.parseZone('2013-01-01T00:00:00-13:00'); | |
39049 assert.equal(m.utcOffset(), -13 * 60); | |
39050 assert.equal(m.hours(), 0); | |
39051 }); | |
39052 | |
39053 test('parse zone with more arguments', function (assert) { | |
39054 var m; | |
39055 m = moment.parseZone('2013 01 01 05 -13:00', 'YYYY MM DD HH ZZ'); | |
39056 assert.equal(m.format(), '2013-01-01T05:00:00-13:00', 'accept input and format'); | |
39057 m = moment.parseZone('2013-01-01-13:00', 'YYYY MM DD ZZ', true); | |
39058 assert.equal(m.isValid(), false, 'accept input, format and strict flag'); | |
39059 m = moment.parseZone('2013-01-01-13:00', ['DD MM YYYY ZZ', 'YYYY MM DD ZZ']); | |
39060 assert.equal(m.format(), '2013-01-01T00:00:00-13:00', 'accept input and array of formats'); | |
39061 }); | |
39062 | |
39063 test('parse zone with a timezone from the format string', function (assert) { | |
39064 var m = moment('11-12-2013 -0400 +1100', 'DD-MM-YYYY ZZ #####').parseZone(); | |
39065 | |
39066 assert.equal(m.utcOffset(), -4 * 60); | |
39067 }); | |
39068 | |
39069 test('parse zone without a timezone included in the format string', function (assert) { | |
39070 var m = moment('11-12-2013 -0400 +1100', 'DD-MM-YYYY').parseZone(); | |
39071 | |
39072 assert.equal(m.utcOffset(), 11 * 60); | |
39073 }); | |
39074 | |
39075 test('timezone format', function (assert) { | |
39076 assert.equal(moment().utcOffset(60).format('ZZ'), '+0100', '-60 -> +0100'); | |
39077 assert.equal(moment().utcOffset(90).format('ZZ'), '+0130', '-90 -> +0130'); | |
39078 assert.equal(moment().utcOffset(120).format('ZZ'), '+0200', '-120 -> +0200'); | |
39079 | |
39080 assert.equal(moment().utcOffset(-60).format('ZZ'), '-0100', '+60 -> -0100'); | |
39081 assert.equal(moment().utcOffset(-90).format('ZZ'), '-0130', '+90 -> -0130'); | |
39082 assert.equal(moment().utcOffset(-120).format('ZZ'), '-0200', '+120 -> -0200'); | |
39083 }); | |
39084 | |
39085 test('local to utc, keepLocalTime = true', function (assert) { | |
39086 var m = moment(), | |
39087 fmt = 'YYYY-DD-MM HH:mm:ss'; | |
39088 assert.equal(m.clone().utc(true).format(fmt), m.format(fmt), 'local to utc failed to keep local time'); | |
39089 }); | |
39090 | |
39091 test('local to utc, keepLocalTime = false', function (assert) { | |
39092 var m = moment(); | |
39093 assert.equal(m.clone().utc().valueOf(), m.valueOf(), 'local to utc failed to keep utc time (implicit)'); | |
39094 assert.equal(m.clone().utc(false).valueOf(), m.valueOf(), 'local to utc failed to keep utc time (explicit)'); | |
39095 }); | |
39096 | |
39097 test('local to zone, keepLocalTime = true', function (assert) { | |
39098 var m = moment(), | |
39099 fmt = 'YYYY-DD-MM HH:mm:ss', | |
39100 z; | |
39101 | |
39102 // Apparently there is -12:00 and +14:00 | |
39103 // http://en.wikipedia.org/wiki/UTC+14:00 | |
39104 // http://en.wikipedia.org/wiki/UTC-12:00 | |
39105 for (z = -12; z <= 14; ++z) { | |
39106 assert.equal(m.clone().utcOffset(z * 60, true).format(fmt), | |
39107 m.format(fmt), | |
39108 'local to utcOffset(' + z + ':00) failed to keep local time'); | |
39109 } | |
39110 }); | |
39111 | |
39112 test('local to zone, keepLocalTime = false', function (assert) { | |
39113 var m = moment(), | |
39114 z; | |
39115 | |
39116 // Apparently there is -12:00 and +14:00 | |
39117 // http://en.wikipedia.org/wiki/UTC+14:00 | |
39118 // http://en.wikipedia.org/wiki/UTC-12:00 | |
39119 for (z = -12; z <= 14; ++z) { | |
39120 assert.equal(m.clone().utcOffset(z * 60).valueOf(), | |
39121 m.valueOf(), | |
39122 'local to utcOffset(' + z + ':00) failed to keep utc time (implicit)'); | |
39123 assert.equal(m.clone().utcOffset(z * 60, false).valueOf(), | |
39124 m.valueOf(), | |
39125 'local to utcOffset(' + z + ':00) failed to keep utc time (explicit)'); | |
39126 } | |
39127 }); | |
39128 | |
39129 test('utc to local, keepLocalTime = true', function (assert) { | |
39130 var um = moment.utc(), | |
39131 fmt = 'YYYY-DD-MM HH:mm:ss'; | |
39132 | |
39133 assert.equal(um.clone().local(true).format(fmt), um.format(fmt), 'utc to local failed to keep local time'); | |
39134 }); | |
39135 | |
39136 test('utc to local, keepLocalTime = false', function (assert) { | |
39137 var um = moment.utc(); | |
39138 assert.equal(um.clone().local().valueOf(), um.valueOf(), 'utc to local failed to keep utc time (implicit)'); | |
39139 assert.equal(um.clone().local(false).valueOf(), um.valueOf(), 'utc to local failed to keep utc time (explicit)'); | |
39140 }); | |
39141 | |
39142 test('zone to local, keepLocalTime = true', function (assert) { | |
39143 var m = moment(), | |
39144 fmt = 'YYYY-DD-MM HH:mm:ss', | |
39145 z; | |
39146 | |
39147 // Apparently there is -12:00 and +14:00 | |
39148 // http://en.wikipedia.org/wiki/UTC+14:00 | |
39149 // http://en.wikipedia.org/wiki/UTC-12:00 | |
39150 for (z = -12; z <= 14; ++z) { | |
39151 m.utcOffset(z * 60); | |
39152 | |
39153 assert.equal(m.clone().local(true).format(fmt), | |
39154 m.format(fmt), | |
39155 'utcOffset(' + z + ':00) to local failed to keep local time'); | |
39156 } | |
39157 }); | |
39158 | |
39159 test('zone to local, keepLocalTime = false', function (assert) { | |
39160 var m = moment(), | |
39161 z; | |
39162 | |
39163 // Apparently there is -12:00 and +14:00 | |
39164 // http://en.wikipedia.org/wiki/UTC+14:00 | |
39165 // http://en.wikipedia.org/wiki/UTC-12:00 | |
39166 for (z = -12; z <= 14; ++z) { | |
39167 m.utcOffset(z * 60); | |
39168 | |
39169 assert.equal(m.clone().local(false).valueOf(), m.valueOf(), | |
39170 'utcOffset(' + z + ':00) to local failed to keep utc time (explicit)'); | |
39171 assert.equal(m.clone().local().valueOf(), m.valueOf(), | |
39172 'utcOffset(' + z + ':00) to local failed to keep utc time (implicit)'); | |
39173 } | |
39174 }); | |
39175 | |
39176 })); | |
39177 | |
39178 (function (global, factory) { | |
39179 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
39180 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
39181 factory(global.moment) | |
39182 }(this, function (moment) { 'use strict'; | |
39183 | |
39184 /*global QUnit:false*/ | |
39185 | |
39186 var test = QUnit.test; | |
39187 | |
39188 function module (name, lifecycle) { | |
39189 QUnit.module(name, { | |
39190 setup : function () { | |
39191 moment.locale('en'); | |
39192 moment.createFromInputFallback = function () { | |
39193 throw new Error('input not handled by moment'); | |
39194 }; | |
39195 if (lifecycle && lifecycle.setup) { | |
39196 lifecycle.setup(); | |
39197 } | |
39198 }, | |
39199 teardown : function () { | |
39200 if (lifecycle && lifecycle.teardown) { | |
39201 lifecycle.teardown(); | |
39202 } | |
39203 } | |
39204 }); | |
39205 } | |
39206 | |
39207 function localeModule (name, lifecycle) { | |
39208 QUnit.module('locale:' + name, { | |
39209 setup : function () { | |
39210 moment.locale(name); | |
39211 moment.createFromInputFallback = function () { | |
39212 throw new Error('input not handled by moment'); | |
39213 }; | |
39214 if (lifecycle && lifecycle.setup) { | |
39215 lifecycle.setup(); | |
39216 } | |
39217 }, | |
39218 teardown : function () { | |
39219 moment.locale('en'); | |
39220 if (lifecycle && lifecycle.teardown) { | |
39221 lifecycle.teardown(); | |
39222 } | |
39223 } | |
39224 }); | |
39225 } | |
39226 | |
39227 module('week year'); | |
39228 | |
39229 test('iso week year', function (assert) { | |
39230 // Some examples taken from http://en.wikipedia.org/wiki/ISO_week | |
39231 assert.equal(moment([2005, 0, 1]).isoWeekYear(), 2004); | |
39232 assert.equal(moment([2005, 0, 2]).isoWeekYear(), 2004); | |
39233 assert.equal(moment([2005, 0, 3]).isoWeekYear(), 2005); | |
39234 assert.equal(moment([2005, 11, 31]).isoWeekYear(), 2005); | |
39235 assert.equal(moment([2006, 0, 1]).isoWeekYear(), 2005); | |
39236 assert.equal(moment([2006, 0, 2]).isoWeekYear(), 2006); | |
39237 assert.equal(moment([2007, 0, 1]).isoWeekYear(), 2007); | |
39238 assert.equal(moment([2007, 11, 30]).isoWeekYear(), 2007); | |
39239 assert.equal(moment([2007, 11, 31]).isoWeekYear(), 2008); | |
39240 assert.equal(moment([2008, 0, 1]).isoWeekYear(), 2008); | |
39241 assert.equal(moment([2008, 11, 28]).isoWeekYear(), 2008); | |
39242 assert.equal(moment([2008, 11, 29]).isoWeekYear(), 2009); | |
39243 assert.equal(moment([2008, 11, 30]).isoWeekYear(), 2009); | |
39244 assert.equal(moment([2008, 11, 31]).isoWeekYear(), 2009); | |
39245 assert.equal(moment([2009, 0, 1]).isoWeekYear(), 2009); | |
39246 assert.equal(moment([2010, 0, 1]).isoWeekYear(), 2009); | |
39247 assert.equal(moment([2010, 0, 2]).isoWeekYear(), 2009); | |
39248 assert.equal(moment([2010, 0, 3]).isoWeekYear(), 2009); | |
39249 assert.equal(moment([2010, 0, 4]).isoWeekYear(), 2010); | |
39250 }); | |
39251 | |
39252 test('week year', function (assert) { | |
39253 // Some examples taken from http://en.wikipedia.org/wiki/ISO_week | |
39254 moment.locale('dow: 1,doy: 4', {week: {dow: 1, doy: 4}}); // like iso | |
39255 assert.equal(moment([2005, 0, 1]).weekYear(), 2004); | |
39256 assert.equal(moment([2005, 0, 2]).weekYear(), 2004); | |
39257 assert.equal(moment([2005, 0, 3]).weekYear(), 2005); | |
39258 assert.equal(moment([2005, 11, 31]).weekYear(), 2005); | |
39259 assert.equal(moment([2006, 0, 1]).weekYear(), 2005); | |
39260 assert.equal(moment([2006, 0, 2]).weekYear(), 2006); | |
39261 assert.equal(moment([2007, 0, 1]).weekYear(), 2007); | |
39262 assert.equal(moment([2007, 11, 30]).weekYear(), 2007); | |
39263 assert.equal(moment([2007, 11, 31]).weekYear(), 2008); | |
39264 assert.equal(moment([2008, 0, 1]).weekYear(), 2008); | |
39265 assert.equal(moment([2008, 11, 28]).weekYear(), 2008); | |
39266 assert.equal(moment([2008, 11, 29]).weekYear(), 2009); | |
39267 assert.equal(moment([2008, 11, 30]).weekYear(), 2009); | |
39268 assert.equal(moment([2008, 11, 31]).weekYear(), 2009); | |
39269 assert.equal(moment([2009, 0, 1]).weekYear(), 2009); | |
39270 assert.equal(moment([2010, 0, 1]).weekYear(), 2009); | |
39271 assert.equal(moment([2010, 0, 2]).weekYear(), 2009); | |
39272 assert.equal(moment([2010, 0, 3]).weekYear(), 2009); | |
39273 assert.equal(moment([2010, 0, 4]).weekYear(), 2010); | |
39274 | |
39275 moment.locale('dow: 1,doy: 7', {week: {dow: 1, doy: 7}}); | |
39276 assert.equal(moment([2004, 11, 26]).weekYear(), 2004); | |
39277 assert.equal(moment([2004, 11, 27]).weekYear(), 2005); | |
39278 assert.equal(moment([2005, 11, 25]).weekYear(), 2005); | |
39279 assert.equal(moment([2005, 11, 26]).weekYear(), 2006); | |
39280 assert.equal(moment([2006, 11, 31]).weekYear(), 2006); | |
39281 assert.equal(moment([2007, 0, 1]).weekYear(), 2007); | |
39282 assert.equal(moment([2007, 11, 30]).weekYear(), 2007); | |
39283 assert.equal(moment([2007, 11, 31]).weekYear(), 2008); | |
39284 assert.equal(moment([2008, 11, 28]).weekYear(), 2008); | |
39285 assert.equal(moment([2008, 11, 29]).weekYear(), 2009); | |
39286 assert.equal(moment([2009, 11, 27]).weekYear(), 2009); | |
39287 assert.equal(moment([2009, 11, 28]).weekYear(), 2010); | |
39288 }); | |
39289 | |
39290 // Verifies that the week number, week day computation is correct for all dow, doy combinations | |
39291 test('week year roundtrip', function (assert) { | |
39292 var dow, doy, wd, m; | |
39293 for (dow = 0; dow < 7; ++dow) { | |
39294 for (doy = dow; doy < dow + 7; ++doy) { | |
39295 for (wd = 0; wd < 7; ++wd) { | |
39296 moment.locale('dow: ' + dow + ', doy: ' + doy, {week: {dow: dow, doy: doy}}); | |
39297 // We use the 10th week as the 1st one can spill to the previous year | |
39298 m = moment('2015 10 ' + wd, 'gggg w d', true); | |
39299 assert.equal(m.format('gggg w d'), '2015 10 ' + wd, 'dow: ' + dow + ' doy: ' + doy + ' wd: ' + wd); | |
39300 m = moment('2015 10 ' + wd, 'gggg w e', true); | |
39301 assert.equal(m.format('gggg w e'), '2015 10 ' + wd, 'dow: ' + dow + ' doy: ' + doy + ' wd: ' + wd); | |
39302 } | |
39303 } | |
39304 } | |
39305 }); | |
39306 | |
39307 test('week numbers 2012/2013', function (assert) { | |
39308 moment.locale('dow: 6, doy: 12', {week: {dow: 6, doy: 12}}); | |
39309 assert.equal(52, moment('2012-12-28', 'YYYY-MM-DD').week()); // 51 -- should be 52? | |
39310 assert.equal(1, moment('2012-12-29', 'YYYY-MM-DD').week()); // 52 -- should be 1 | |
39311 assert.equal(1, moment('2013-01-01', 'YYYY-MM-DD').week()); // 52 -- should be 1 | |
39312 assert.equal(2, moment('2013-01-08', 'YYYY-MM-DD').week()); // 53 -- should be 2 | |
39313 assert.equal(2, moment('2013-01-11', 'YYYY-MM-DD').week()); // 53 -- should be 2 | |
39314 assert.equal(3, moment('2013-01-12', 'YYYY-MM-DD').week()); // 1 -- should be 3 | |
39315 assert.equal(52, moment().weeksInYear(2012)); // 52 | |
39316 }); | |
39317 | |
39318 })); | |
39319 | |
39320 (function (global, factory) { | |
39321 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
39322 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
39323 factory(global.moment) | |
39324 }(this, function (moment) { 'use strict'; | |
39325 | |
39326 /*global QUnit:false*/ | |
39327 | |
39328 var test = QUnit.test; | |
39329 | |
39330 function module (name, lifecycle) { | |
39331 QUnit.module(name, { | |
39332 setup : function () { | |
39333 moment.locale('en'); | |
39334 moment.createFromInputFallback = function () { | |
39335 throw new Error('input not handled by moment'); | |
39336 }; | |
39337 if (lifecycle && lifecycle.setup) { | |
39338 lifecycle.setup(); | |
39339 } | |
39340 }, | |
39341 teardown : function () { | |
39342 if (lifecycle && lifecycle.teardown) { | |
39343 lifecycle.teardown(); | |
39344 } | |
39345 } | |
39346 }); | |
39347 } | |
39348 | |
39349 function localeModule (name, lifecycle) { | |
39350 QUnit.module('locale:' + name, { | |
39351 setup : function () { | |
39352 moment.locale(name); | |
39353 moment.createFromInputFallback = function () { | |
39354 throw new Error('input not handled by moment'); | |
39355 }; | |
39356 if (lifecycle && lifecycle.setup) { | |
39357 lifecycle.setup(); | |
39358 } | |
39359 }, | |
39360 teardown : function () { | |
39361 moment.locale('en'); | |
39362 if (lifecycle && lifecycle.teardown) { | |
39363 lifecycle.teardown(); | |
39364 } | |
39365 } | |
39366 }); | |
39367 } | |
39368 | |
39369 module('week day'); | |
39370 | |
39371 test('iso weekday', function (assert) { | |
39372 var i; | |
39373 | |
39374 for (i = 0; i < 7; ++i) { | |
39375 moment.locale('dow:' + i + ',doy: 6', {week: {dow: i, doy: 6}}); | |
39376 assert.equal(moment([1985, 1, 4]).isoWeekday(), 1, 'Feb 4 1985 is Monday -- 1st day'); | |
39377 assert.equal(moment([2029, 8, 18]).isoWeekday(), 2, 'Sep 18 2029 is Tuesday -- 2nd day'); | |
39378 assert.equal(moment([2013, 3, 24]).isoWeekday(), 3, 'Apr 24 2013 is Wednesday -- 3rd day'); | |
39379 assert.equal(moment([2015, 2, 5]).isoWeekday(), 4, 'Mar 5 2015 is Thursday -- 4th day'); | |
39380 assert.equal(moment([1970, 0, 2]).isoWeekday(), 5, 'Jan 2 1970 is Friday -- 5th day'); | |
39381 assert.equal(moment([2001, 4, 12]).isoWeekday(), 6, 'May 12 2001 is Saturday -- 6th day'); | |
39382 assert.equal(moment([2000, 0, 2]).isoWeekday(), 7, 'Jan 2 2000 is Sunday -- 7th day'); | |
39383 } | |
39384 }); | |
39385 | |
39386 test('iso weekday setter', function (assert) { | |
39387 var a = moment([2011, 0, 10]); | |
39388 assert.equal(moment(a).isoWeekday(1).date(), 10, 'set from mon to mon'); | |
39389 assert.equal(moment(a).isoWeekday(4).date(), 13, 'set from mon to thu'); | |
39390 assert.equal(moment(a).isoWeekday(7).date(), 16, 'set from mon to sun'); | |
39391 assert.equal(moment(a).isoWeekday(-6).date(), 3, 'set from mon to last mon'); | |
39392 assert.equal(moment(a).isoWeekday(-3).date(), 6, 'set from mon to last thu'); | |
39393 assert.equal(moment(a).isoWeekday(0).date(), 9, 'set from mon to last sun'); | |
39394 assert.equal(moment(a).isoWeekday(8).date(), 17, 'set from mon to next mon'); | |
39395 assert.equal(moment(a).isoWeekday(11).date(), 20, 'set from mon to next thu'); | |
39396 assert.equal(moment(a).isoWeekday(14).date(), 23, 'set from mon to next sun'); | |
39397 | |
39398 a = moment([2011, 0, 13]); | |
39399 assert.equal(moment(a).isoWeekday(1).date(), 10, 'set from thu to mon'); | |
39400 assert.equal(moment(a).isoWeekday(4).date(), 13, 'set from thu to thu'); | |
39401 assert.equal(moment(a).isoWeekday(7).date(), 16, 'set from thu to sun'); | |
39402 assert.equal(moment(a).isoWeekday(-6).date(), 3, 'set from thu to last mon'); | |
39403 assert.equal(moment(a).isoWeekday(-3).date(), 6, 'set from thu to last thu'); | |
39404 assert.equal(moment(a).isoWeekday(0).date(), 9, 'set from thu to last sun'); | |
39405 assert.equal(moment(a).isoWeekday(8).date(), 17, 'set from thu to next mon'); | |
39406 assert.equal(moment(a).isoWeekday(11).date(), 20, 'set from thu to next thu'); | |
39407 assert.equal(moment(a).isoWeekday(14).date(), 23, 'set from thu to next sun'); | |
39408 | |
39409 a = moment([2011, 0, 16]); | |
39410 assert.equal(moment(a).isoWeekday(1).date(), 10, 'set from sun to mon'); | |
39411 assert.equal(moment(a).isoWeekday(4).date(), 13, 'set from sun to thu'); | |
39412 assert.equal(moment(a).isoWeekday(7).date(), 16, 'set from sun to sun'); | |
39413 assert.equal(moment(a).isoWeekday(-6).date(), 3, 'set from sun to last mon'); | |
39414 assert.equal(moment(a).isoWeekday(-3).date(), 6, 'set from sun to last thu'); | |
39415 assert.equal(moment(a).isoWeekday(0).date(), 9, 'set from sun to last sun'); | |
39416 assert.equal(moment(a).isoWeekday(8).date(), 17, 'set from sun to next mon'); | |
39417 assert.equal(moment(a).isoWeekday(11).date(), 20, 'set from sun to next thu'); | |
39418 assert.equal(moment(a).isoWeekday(14).date(), 23, 'set from sun to next sun'); | |
39419 }); | |
39420 | |
39421 test('weekday first day of week Sunday (dow 0)', function (assert) { | |
39422 moment.locale('dow: 0,doy: 6', {week: {dow: 0, doy: 6}}); | |
39423 assert.equal(moment([1985, 1, 3]).weekday(), 0, 'Feb 3 1985 is Sunday -- 0th day'); | |
39424 assert.equal(moment([2029, 8, 17]).weekday(), 1, 'Sep 17 2029 is Monday -- 1st day'); | |
39425 assert.equal(moment([2013, 3, 23]).weekday(), 2, 'Apr 23 2013 is Tuesday -- 2nd day'); | |
39426 assert.equal(moment([2015, 2, 4]).weekday(), 3, 'Mar 4 2015 is Wednesday -- 3nd day'); | |
39427 assert.equal(moment([1970, 0, 1]).weekday(), 4, 'Jan 1 1970 is Thursday -- 4th day'); | |
39428 assert.equal(moment([2001, 4, 11]).weekday(), 5, 'May 11 2001 is Friday -- 5th day'); | |
39429 assert.equal(moment([2000, 0, 1]).weekday(), 6, 'Jan 1 2000 is Saturday -- 6th day'); | |
39430 }); | |
39431 | |
39432 test('weekday first day of week Monday (dow 1)', function (assert) { | |
39433 moment.locale('dow: 1,doy: 6', {week: {dow: 1, doy: 6}}); | |
39434 assert.equal(moment([1985, 1, 4]).weekday(), 0, 'Feb 4 1985 is Monday -- 0th day'); | |
39435 assert.equal(moment([2029, 8, 18]).weekday(), 1, 'Sep 18 2029 is Tuesday -- 1st day'); | |
39436 assert.equal(moment([2013, 3, 24]).weekday(), 2, 'Apr 24 2013 is Wednesday -- 2nd day'); | |
39437 assert.equal(moment([2015, 2, 5]).weekday(), 3, 'Mar 5 2015 is Thursday -- 3nd day'); | |
39438 assert.equal(moment([1970, 0, 2]).weekday(), 4, 'Jan 2 1970 is Friday -- 4th day'); | |
39439 assert.equal(moment([2001, 4, 12]).weekday(), 5, 'May 12 2001 is Saturday -- 5th day'); | |
39440 assert.equal(moment([2000, 0, 2]).weekday(), 6, 'Jan 2 2000 is Sunday -- 6th day'); | |
39441 }); | |
39442 | |
39443 test('weekday first day of week Tuesday (dow 2)', function (assert) { | |
39444 moment.locale('dow: 2,doy: 6', {week: {dow: 2, doy: 6}}); | |
39445 assert.equal(moment([1985, 1, 5]).weekday(), 0, 'Feb 5 1985 is Tuesday -- 0th day'); | |
39446 assert.equal(moment([2029, 8, 19]).weekday(), 1, 'Sep 19 2029 is Wednesday -- 1st day'); | |
39447 assert.equal(moment([2013, 3, 25]).weekday(), 2, 'Apr 25 2013 is Thursday -- 2nd day'); | |
39448 assert.equal(moment([2015, 2, 6]).weekday(), 3, 'Mar 6 2015 is Friday -- 3nd day'); | |
39449 assert.equal(moment([1970, 0, 3]).weekday(), 4, 'Jan 3 1970 is Staturday -- 4th day'); | |
39450 assert.equal(moment([2001, 4, 13]).weekday(), 5, 'May 13 2001 is Sunday -- 5th day'); | |
39451 assert.equal(moment([2000, 0, 3]).weekday(), 6, 'Jan 3 2000 is Monday -- 6th day'); | |
39452 }); | |
39453 | |
39454 test('weekday first day of week Wednesday (dow 3)', function (assert) { | |
39455 moment.locale('dow: 3,doy: 6', {week: {dow: 3, doy: 6}}); | |
39456 assert.equal(moment([1985, 1, 6]).weekday(), 0, 'Feb 6 1985 is Wednesday -- 0th day'); | |
39457 assert.equal(moment([2029, 8, 20]).weekday(), 1, 'Sep 20 2029 is Thursday -- 1st day'); | |
39458 assert.equal(moment([2013, 3, 26]).weekday(), 2, 'Apr 26 2013 is Friday -- 2nd day'); | |
39459 assert.equal(moment([2015, 2, 7]).weekday(), 3, 'Mar 7 2015 is Saturday -- 3nd day'); | |
39460 assert.equal(moment([1970, 0, 4]).weekday(), 4, 'Jan 4 1970 is Sunday -- 4th day'); | |
39461 assert.equal(moment([2001, 4, 14]).weekday(), 5, 'May 14 2001 is Monday -- 5th day'); | |
39462 assert.equal(moment([2000, 0, 4]).weekday(), 6, 'Jan 4 2000 is Tuesday -- 6th day'); | |
39463 moment.locale('dow:3,doy:6', null); | |
39464 }); | |
39465 | |
39466 test('weekday first day of week Thursday (dow 4)', function (assert) { | |
39467 moment.locale('dow: 4,doy: 6', {week: {dow: 4, doy: 6}}); | |
39468 assert.equal(moment([1985, 1, 7]).weekday(), 0, 'Feb 7 1985 is Thursday -- 0th day'); | |
39469 assert.equal(moment([2029, 8, 21]).weekday(), 1, 'Sep 21 2029 is Friday -- 1st day'); | |
39470 assert.equal(moment([2013, 3, 27]).weekday(), 2, 'Apr 27 2013 is Saturday -- 2nd day'); | |
39471 assert.equal(moment([2015, 2, 8]).weekday(), 3, 'Mar 8 2015 is Sunday -- 3nd day'); | |
39472 assert.equal(moment([1970, 0, 5]).weekday(), 4, 'Jan 5 1970 is Monday -- 4th day'); | |
39473 assert.equal(moment([2001, 4, 15]).weekday(), 5, 'May 15 2001 is Tuesday -- 5th day'); | |
39474 assert.equal(moment([2000, 0, 5]).weekday(), 6, 'Jan 5 2000 is Wednesday -- 6th day'); | |
39475 }); | |
39476 | |
39477 test('weekday first day of week Friday (dow 5)', function (assert) { | |
39478 moment.locale('dow: 5,doy: 6', {week: {dow: 5, doy: 6}}); | |
39479 assert.equal(moment([1985, 1, 8]).weekday(), 0, 'Feb 8 1985 is Friday -- 0th day'); | |
39480 assert.equal(moment([2029, 8, 22]).weekday(), 1, 'Sep 22 2029 is Staturday -- 1st day'); | |
39481 assert.equal(moment([2013, 3, 28]).weekday(), 2, 'Apr 28 2013 is Sunday -- 2nd day'); | |
39482 assert.equal(moment([2015, 2, 9]).weekday(), 3, 'Mar 9 2015 is Monday -- 3nd day'); | |
39483 assert.equal(moment([1970, 0, 6]).weekday(), 4, 'Jan 6 1970 is Tuesday -- 4th day'); | |
39484 assert.equal(moment([2001, 4, 16]).weekday(), 5, 'May 16 2001 is Wednesday -- 5th day'); | |
39485 assert.equal(moment([2000, 0, 6]).weekday(), 6, 'Jan 6 2000 is Thursday -- 6th day'); | |
39486 }); | |
39487 | |
39488 test('weekday first day of week Saturday (dow 6)', function (assert) { | |
39489 moment.locale('dow: 6,doy: 6', {week: {dow: 6, doy: 6}}); | |
39490 assert.equal(moment([1985, 1, 9]).weekday(), 0, 'Feb 9 1985 is Staturday -- 0th day'); | |
39491 assert.equal(moment([2029, 8, 23]).weekday(), 1, 'Sep 23 2029 is Sunday -- 1st day'); | |
39492 assert.equal(moment([2013, 3, 29]).weekday(), 2, 'Apr 29 2013 is Monday -- 2nd day'); | |
39493 assert.equal(moment([2015, 2, 10]).weekday(), 3, 'Mar 10 2015 is Tuesday -- 3nd day'); | |
39494 assert.equal(moment([1970, 0, 7]).weekday(), 4, 'Jan 7 1970 is Wednesday -- 4th day'); | |
39495 assert.equal(moment([2001, 4, 17]).weekday(), 5, 'May 17 2001 is Thursday -- 5th day'); | |
39496 assert.equal(moment([2000, 0, 7]).weekday(), 6, 'Jan 7 2000 is Friday -- 6th day'); | |
39497 }); | |
39498 | |
39499 })); | |
39500 | |
39501 (function (global, factory) { | |
39502 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
39503 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
39504 factory(global.moment) | |
39505 }(this, function (moment) { 'use strict'; | |
39506 | |
39507 /*global QUnit:false*/ | |
39508 | |
39509 var test = QUnit.test; | |
39510 | |
39511 function module (name, lifecycle) { | |
39512 QUnit.module(name, { | |
39513 setup : function () { | |
39514 moment.locale('en'); | |
39515 moment.createFromInputFallback = function () { | |
39516 throw new Error('input not handled by moment'); | |
39517 }; | |
39518 if (lifecycle && lifecycle.setup) { | |
39519 lifecycle.setup(); | |
39520 } | |
39521 }, | |
39522 teardown : function () { | |
39523 if (lifecycle && lifecycle.teardown) { | |
39524 lifecycle.teardown(); | |
39525 } | |
39526 } | |
39527 }); | |
39528 } | |
39529 | |
39530 function localeModule (name, lifecycle) { | |
39531 QUnit.module('locale:' + name, { | |
39532 setup : function () { | |
39533 moment.locale(name); | |
39534 moment.createFromInputFallback = function () { | |
39535 throw new Error('input not handled by moment'); | |
39536 }; | |
39537 if (lifecycle && lifecycle.setup) { | |
39538 lifecycle.setup(); | |
39539 } | |
39540 }, | |
39541 teardown : function () { | |
39542 moment.locale('en'); | |
39543 if (lifecycle && lifecycle.teardown) { | |
39544 lifecycle.teardown(); | |
39545 } | |
39546 } | |
39547 }); | |
39548 } | |
39549 | |
39550 module('weeks'); | |
39551 | |
39552 test('day of year', function (assert) { | |
39553 assert.equal(moment([2000, 0, 1]).dayOfYear(), 1, 'Jan 1 2000 should be day 1 of the year'); | |
39554 assert.equal(moment([2000, 1, 28]).dayOfYear(), 59, 'Feb 28 2000 should be day 59 of the year'); | |
39555 assert.equal(moment([2000, 1, 29]).dayOfYear(), 60, 'Feb 28 2000 should be day 60 of the year'); | |
39556 assert.equal(moment([2000, 11, 31]).dayOfYear(), 366, 'Dec 31 2000 should be day 366 of the year'); | |
39557 assert.equal(moment([2001, 0, 1]).dayOfYear(), 1, 'Jan 1 2001 should be day 1 of the year'); | |
39558 assert.equal(moment([2001, 1, 28]).dayOfYear(), 59, 'Feb 28 2001 should be day 59 of the year'); | |
39559 assert.equal(moment([2001, 2, 1]).dayOfYear(), 60, 'Mar 1 2001 should be day 60 of the year'); | |
39560 assert.equal(moment([2001, 11, 31]).dayOfYear(), 365, 'Dec 31 2001 should be day 365 of the year'); | |
39561 }); | |
39562 | |
39563 test('day of year setters', function (assert) { | |
39564 assert.equal(moment([2000, 0, 1]).dayOfYear(200).dayOfYear(), 200, 'Setting Jan 1 2000 day of the year to 200 should work'); | |
39565 assert.equal(moment([2000, 1, 28]).dayOfYear(200).dayOfYear(), 200, 'Setting Feb 28 2000 day of the year to 200 should work'); | |
39566 assert.equal(moment([2000, 1, 29]).dayOfYear(200).dayOfYear(), 200, 'Setting Feb 28 2000 day of the year to 200 should work'); | |
39567 assert.equal(moment([2000, 11, 31]).dayOfYear(200).dayOfYear(), 200, 'Setting Dec 31 2000 day of the year to 200 should work'); | |
39568 assert.equal(moment().dayOfYear(1).dayOfYear(), 1, 'Setting day of the year to 1 should work'); | |
39569 assert.equal(moment().dayOfYear(59).dayOfYear(), 59, 'Setting day of the year to 59 should work'); | |
39570 assert.equal(moment().dayOfYear(60).dayOfYear(), 60, 'Setting day of the year to 60 should work'); | |
39571 assert.equal(moment().dayOfYear(365).dayOfYear(), 365, 'Setting day of the year to 365 should work'); | |
39572 }); | |
39573 | |
39574 test('iso weeks year starting sunday', function (assert) { | |
39575 assert.equal(moment([2012, 0, 1]).isoWeek(), 52, 'Jan 1 2012 should be iso week 52'); | |
39576 assert.equal(moment([2012, 0, 2]).isoWeek(), 1, 'Jan 2 2012 should be iso week 1'); | |
39577 assert.equal(moment([2012, 0, 8]).isoWeek(), 1, 'Jan 8 2012 should be iso week 1'); | |
39578 assert.equal(moment([2012, 0, 9]).isoWeek(), 2, 'Jan 9 2012 should be iso week 2'); | |
39579 assert.equal(moment([2012, 0, 15]).isoWeek(), 2, 'Jan 15 2012 should be iso week 2'); | |
39580 }); | |
39581 | |
39582 test('iso weeks year starting monday', function (assert) { | |
39583 assert.equal(moment([2007, 0, 1]).isoWeek(), 1, 'Jan 1 2007 should be iso week 1'); | |
39584 assert.equal(moment([2007, 0, 7]).isoWeek(), 1, 'Jan 7 2007 should be iso week 1'); | |
39585 assert.equal(moment([2007, 0, 8]).isoWeek(), 2, 'Jan 8 2007 should be iso week 2'); | |
39586 assert.equal(moment([2007, 0, 14]).isoWeek(), 2, 'Jan 14 2007 should be iso week 2'); | |
39587 assert.equal(moment([2007, 0, 15]).isoWeek(), 3, 'Jan 15 2007 should be iso week 3'); | |
39588 }); | |
39589 | |
39590 test('iso weeks year starting tuesday', function (assert) { | |
39591 assert.equal(moment([2007, 11, 31]).isoWeek(), 1, 'Dec 31 2007 should be iso week 1'); | |
39592 assert.equal(moment([2008, 0, 1]).isoWeek(), 1, 'Jan 1 2008 should be iso week 1'); | |
39593 assert.equal(moment([2008, 0, 6]).isoWeek(), 1, 'Jan 6 2008 should be iso week 1'); | |
39594 assert.equal(moment([2008, 0, 7]).isoWeek(), 2, 'Jan 7 2008 should be iso week 2'); | |
39595 assert.equal(moment([2008, 0, 13]).isoWeek(), 2, 'Jan 13 2008 should be iso week 2'); | |
39596 assert.equal(moment([2008, 0, 14]).isoWeek(), 3, 'Jan 14 2008 should be iso week 3'); | |
39597 }); | |
39598 | |
39599 test('iso weeks year starting wednesday', function (assert) { | |
39600 assert.equal(moment([2002, 11, 30]).isoWeek(), 1, 'Dec 30 2002 should be iso week 1'); | |
39601 assert.equal(moment([2003, 0, 1]).isoWeek(), 1, 'Jan 1 2003 should be iso week 1'); | |
39602 assert.equal(moment([2003, 0, 5]).isoWeek(), 1, 'Jan 5 2003 should be iso week 1'); | |
39603 assert.equal(moment([2003, 0, 6]).isoWeek(), 2, 'Jan 6 2003 should be iso week 2'); | |
39604 assert.equal(moment([2003, 0, 12]).isoWeek(), 2, 'Jan 12 2003 should be iso week 2'); | |
39605 assert.equal(moment([2003, 0, 13]).isoWeek(), 3, 'Jan 13 2003 should be iso week 3'); | |
39606 }); | |
39607 | |
39608 test('iso weeks year starting thursday', function (assert) { | |
39609 assert.equal(moment([2008, 11, 29]).isoWeek(), 1, 'Dec 29 2008 should be iso week 1'); | |
39610 assert.equal(moment([2009, 0, 1]).isoWeek(), 1, 'Jan 1 2009 should be iso week 1'); | |
39611 assert.equal(moment([2009, 0, 4]).isoWeek(), 1, 'Jan 4 2009 should be iso week 1'); | |
39612 assert.equal(moment([2009, 0, 5]).isoWeek(), 2, 'Jan 5 2009 should be iso week 2'); | |
39613 assert.equal(moment([2009, 0, 11]).isoWeek(), 2, 'Jan 11 2009 should be iso week 2'); | |
39614 assert.equal(moment([2009, 0, 13]).isoWeek(), 3, 'Jan 12 2009 should be iso week 3'); | |
39615 }); | |
39616 | |
39617 test('iso weeks year starting friday', function (assert) { | |
39618 assert.equal(moment([2009, 11, 28]).isoWeek(), 53, 'Dec 28 2009 should be iso week 53'); | |
39619 assert.equal(moment([2010, 0, 1]).isoWeek(), 53, 'Jan 1 2010 should be iso week 53'); | |
39620 assert.equal(moment([2010, 0, 3]).isoWeek(), 53, 'Jan 3 2010 should be iso week 53'); | |
39621 assert.equal(moment([2010, 0, 4]).isoWeek(), 1, 'Jan 4 2010 should be iso week 1'); | |
39622 assert.equal(moment([2010, 0, 10]).isoWeek(), 1, 'Jan 10 2010 should be iso week 1'); | |
39623 assert.equal(moment([2010, 0, 11]).isoWeek(), 2, 'Jan 11 2010 should be iso week 2'); | |
39624 }); | |
39625 | |
39626 test('iso weeks year starting saturday', function (assert) { | |
39627 assert.equal(moment([2010, 11, 27]).isoWeek(), 52, 'Dec 27 2010 should be iso week 52'); | |
39628 assert.equal(moment([2011, 0, 1]).isoWeek(), 52, 'Jan 1 2011 should be iso week 52'); | |
39629 assert.equal(moment([2011, 0, 2]).isoWeek(), 52, 'Jan 2 2011 should be iso week 52'); | |
39630 assert.equal(moment([2011, 0, 3]).isoWeek(), 1, 'Jan 3 2011 should be iso week 1'); | |
39631 assert.equal(moment([2011, 0, 9]).isoWeek(), 1, 'Jan 9 2011 should be iso week 1'); | |
39632 assert.equal(moment([2011, 0, 10]).isoWeek(), 2, 'Jan 10 2011 should be iso week 2'); | |
39633 }); | |
39634 | |
39635 test('iso weeks year starting sunday formatted', function (assert) { | |
39636 assert.equal(moment([2012, 0, 1]).format('W WW Wo'), '52 52 52nd', 'Jan 1 2012 should be iso week 52'); | |
39637 assert.equal(moment([2012, 0, 2]).format('W WW Wo'), '1 01 1st', 'Jan 2 2012 should be iso week 1'); | |
39638 assert.equal(moment([2012, 0, 8]).format('W WW Wo'), '1 01 1st', 'Jan 8 2012 should be iso week 1'); | |
39639 assert.equal(moment([2012, 0, 9]).format('W WW Wo'), '2 02 2nd', 'Jan 9 2012 should be iso week 2'); | |
39640 assert.equal(moment([2012, 0, 15]).format('W WW Wo'), '2 02 2nd', 'Jan 15 2012 should be iso week 2'); | |
39641 }); | |
39642 | |
39643 test('weeks plural year starting sunday', function (assert) { | |
39644 assert.equal(moment([2012, 0, 1]).weeks(), 1, 'Jan 1 2012 should be week 1'); | |
39645 assert.equal(moment([2012, 0, 7]).weeks(), 1, 'Jan 7 2012 should be week 1'); | |
39646 assert.equal(moment([2012, 0, 8]).weeks(), 2, 'Jan 8 2012 should be week 2'); | |
39647 assert.equal(moment([2012, 0, 14]).weeks(), 2, 'Jan 14 2012 should be week 2'); | |
39648 assert.equal(moment([2012, 0, 15]).weeks(), 3, 'Jan 15 2012 should be week 3'); | |
39649 }); | |
39650 | |
39651 test('iso weeks plural year starting sunday', function (assert) { | |
39652 assert.equal(moment([2012, 0, 1]).isoWeeks(), 52, 'Jan 1 2012 should be iso week 52'); | |
39653 assert.equal(moment([2012, 0, 2]).isoWeeks(), 1, 'Jan 2 2012 should be iso week 1'); | |
39654 assert.equal(moment([2012, 0, 8]).isoWeeks(), 1, 'Jan 8 2012 should be iso week 1'); | |
39655 assert.equal(moment([2012, 0, 9]).isoWeeks(), 2, 'Jan 9 2012 should be iso week 2'); | |
39656 assert.equal(moment([2012, 0, 15]).isoWeeks(), 2, 'Jan 15 2012 should be iso week 2'); | |
39657 }); | |
39658 | |
39659 test('weeks setter', function (assert) { | |
39660 assert.equal(moment([2012, 0, 1]).week(30).week(), 30, 'Setting Jan 1 2012 to week 30 should work'); | |
39661 assert.equal(moment([2012, 0, 7]).week(30).week(), 30, 'Setting Jan 7 2012 to week 30 should work'); | |
39662 assert.equal(moment([2012, 0, 8]).week(30).week(), 30, 'Setting Jan 8 2012 to week 30 should work'); | |
39663 assert.equal(moment([2012, 0, 14]).week(30).week(), 30, 'Setting Jan 14 2012 to week 30 should work'); | |
39664 assert.equal(moment([2012, 0, 15]).week(30).week(), 30, 'Setting Jan 15 2012 to week 30 should work'); | |
39665 }); | |
39666 | |
39667 test('iso weeks setter', function (assert) { | |
39668 assert.equal(moment([2012, 0, 1]).isoWeeks(25).isoWeeks(), 25, 'Setting Jan 1 2012 to week 25 should work'); | |
39669 assert.equal(moment([2012, 0, 2]).isoWeeks(24).isoWeeks(), 24, 'Setting Jan 2 2012 to week 24 should work'); | |
39670 assert.equal(moment([2012, 0, 8]).isoWeeks(23).isoWeeks(), 23, 'Setting Jan 8 2012 to week 23 should work'); | |
39671 assert.equal(moment([2012, 0, 9]).isoWeeks(22).isoWeeks(), 22, 'Setting Jan 9 2012 to week 22 should work'); | |
39672 assert.equal(moment([2012, 0, 15]).isoWeeks(21).isoWeeks(), 21, 'Setting Jan 15 2012 to week 21 should work'); | |
39673 }); | |
39674 | |
39675 test('iso weeks setter day of year', function (assert) { | |
39676 assert.equal(moment([2012, 0, 1]).isoWeek(1).dayOfYear(), 9, 'Setting Jan 1 2012 to week 1 should be day of year 8'); | |
39677 assert.equal(moment([2012, 0, 1]).isoWeek(1).year(), 2011, 'Setting Jan 1 2012 to week 1 should be year 2011'); | |
39678 assert.equal(moment([2012, 0, 2]).isoWeek(1).dayOfYear(), 2, 'Setting Jan 2 2012 to week 1 should be day of year 2'); | |
39679 assert.equal(moment([2012, 0, 8]).isoWeek(1).dayOfYear(), 8, 'Setting Jan 8 2012 to week 1 should be day of year 8'); | |
39680 assert.equal(moment([2012, 0, 9]).isoWeek(1).dayOfYear(), 2, 'Setting Jan 9 2012 to week 1 should be day of year 2'); | |
39681 assert.equal(moment([2012, 0, 15]).isoWeek(1).dayOfYear(), 8, 'Setting Jan 15 2012 to week 1 should be day of year 8'); | |
39682 }); | |
39683 | |
39684 test('years with iso week 53', function (assert) { | |
39685 // Based on a table taken from http://en.wikipedia.org/wiki/ISO_week_date | |
39686 // (as downloaded on 2014-01-06) listing the 71 years in a 400-year cycle | |
39687 // that have 53 weeks; in this case reflecting the 2000 based cycle | |
39688 assert.equal(moment([2004, 11, 31]).isoWeek(), 53, 'Dec 31 2004 should be iso week 53'); | |
39689 assert.equal(moment([2009, 11, 31]).isoWeek(), 53, 'Dec 31 2009 should be iso week 53'); | |
39690 assert.equal(moment([2015, 11, 31]).isoWeek(), 53, 'Dec 31 2015 should be iso week 53'); | |
39691 assert.equal(moment([2020, 11, 31]).isoWeek(), 53, 'Dec 31 2020 should be iso week 53'); | |
39692 assert.equal(moment([2026, 11, 31]).isoWeek(), 53, 'Dec 31 2026 should be iso week 53'); | |
39693 assert.equal(moment([2032, 11, 31]).isoWeek(), 53, 'Dec 31 2032 should be iso week 53'); | |
39694 assert.equal(moment([2037, 11, 31]).isoWeek(), 53, 'Dec 31 2037 should be iso week 53'); | |
39695 assert.equal(moment([2043, 11, 31]).isoWeek(), 53, 'Dec 31 2043 should be iso week 53'); | |
39696 assert.equal(moment([2048, 11, 31]).isoWeek(), 53, 'Dec 31 2048 should be iso week 53'); | |
39697 assert.equal(moment([2054, 11, 31]).isoWeek(), 53, 'Dec 31 2054 should be iso week 53'); | |
39698 assert.equal(moment([2060, 11, 31]).isoWeek(), 53, 'Dec 31 2060 should be iso week 53'); | |
39699 assert.equal(moment([2065, 11, 31]).isoWeek(), 53, 'Dec 31 2065 should be iso week 53'); | |
39700 assert.equal(moment([2071, 11, 31]).isoWeek(), 53, 'Dec 31 2071 should be iso week 53'); | |
39701 assert.equal(moment([2076, 11, 31]).isoWeek(), 53, 'Dec 31 2076 should be iso week 53'); | |
39702 assert.equal(moment([2082, 11, 31]).isoWeek(), 53, 'Dec 31 2082 should be iso week 53'); | |
39703 assert.equal(moment([2088, 11, 31]).isoWeek(), 53, 'Dec 31 2088 should be iso week 53'); | |
39704 assert.equal(moment([2093, 11, 31]).isoWeek(), 53, 'Dec 31 2093 should be iso week 53'); | |
39705 assert.equal(moment([2099, 11, 31]).isoWeek(), 53, 'Dec 31 2099 should be iso week 53'); | |
39706 assert.equal(moment([2105, 11, 31]).isoWeek(), 53, 'Dec 31 2105 should be iso week 53'); | |
39707 assert.equal(moment([2111, 11, 31]).isoWeek(), 53, 'Dec 31 2111 should be iso week 53'); | |
39708 assert.equal(moment([2116, 11, 31]).isoWeek(), 53, 'Dec 31 2116 should be iso week 53'); | |
39709 assert.equal(moment([2122, 11, 31]).isoWeek(), 53, 'Dec 31 2122 should be iso week 53'); | |
39710 assert.equal(moment([2128, 11, 31]).isoWeek(), 53, 'Dec 31 2128 should be iso week 53'); | |
39711 assert.equal(moment([2133, 11, 31]).isoWeek(), 53, 'Dec 31 2133 should be iso week 53'); | |
39712 assert.equal(moment([2139, 11, 31]).isoWeek(), 53, 'Dec 31 2139 should be iso week 53'); | |
39713 assert.equal(moment([2144, 11, 31]).isoWeek(), 53, 'Dec 31 2144 should be iso week 53'); | |
39714 assert.equal(moment([2150, 11, 31]).isoWeek(), 53, 'Dec 31 2150 should be iso week 53'); | |
39715 assert.equal(moment([2156, 11, 31]).isoWeek(), 53, 'Dec 31 2156 should be iso week 53'); | |
39716 assert.equal(moment([2161, 11, 31]).isoWeek(), 53, 'Dec 31 2161 should be iso week 53'); | |
39717 assert.equal(moment([2167, 11, 31]).isoWeek(), 53, 'Dec 31 2167 should be iso week 53'); | |
39718 assert.equal(moment([2172, 11, 31]).isoWeek(), 53, 'Dec 31 2172 should be iso week 53'); | |
39719 assert.equal(moment([2178, 11, 31]).isoWeek(), 53, 'Dec 31 2178 should be iso week 53'); | |
39720 assert.equal(moment([2184, 11, 31]).isoWeek(), 53, 'Dec 31 2184 should be iso week 53'); | |
39721 assert.equal(moment([2189, 11, 31]).isoWeek(), 53, 'Dec 31 2189 should be iso week 53'); | |
39722 assert.equal(moment([2195, 11, 31]).isoWeek(), 53, 'Dec 31 2195 should be iso week 53'); | |
39723 assert.equal(moment([2201, 11, 31]).isoWeek(), 53, 'Dec 31 2201 should be iso week 53'); | |
39724 assert.equal(moment([2207, 11, 31]).isoWeek(), 53, 'Dec 31 2207 should be iso week 53'); | |
39725 assert.equal(moment([2212, 11, 31]).isoWeek(), 53, 'Dec 31 2212 should be iso week 53'); | |
39726 assert.equal(moment([2218, 11, 31]).isoWeek(), 53, 'Dec 31 2218 should be iso week 53'); | |
39727 assert.equal(moment([2224, 11, 31]).isoWeek(), 53, 'Dec 31 2224 should be iso week 53'); | |
39728 assert.equal(moment([2229, 11, 31]).isoWeek(), 53, 'Dec 31 2229 should be iso week 53'); | |
39729 assert.equal(moment([2235, 11, 31]).isoWeek(), 53, 'Dec 31 2235 should be iso week 53'); | |
39730 assert.equal(moment([2240, 11, 31]).isoWeek(), 53, 'Dec 31 2240 should be iso week 53'); | |
39731 assert.equal(moment([2246, 11, 31]).isoWeek(), 53, 'Dec 31 2246 should be iso week 53'); | |
39732 assert.equal(moment([2252, 11, 31]).isoWeek(), 53, 'Dec 31 2252 should be iso week 53'); | |
39733 assert.equal(moment([2257, 11, 31]).isoWeek(), 53, 'Dec 31 2257 should be iso week 53'); | |
39734 assert.equal(moment([2263, 11, 31]).isoWeek(), 53, 'Dec 31 2263 should be iso week 53'); | |
39735 assert.equal(moment([2268, 11, 31]).isoWeek(), 53, 'Dec 31 2268 should be iso week 53'); | |
39736 assert.equal(moment([2274, 11, 31]).isoWeek(), 53, 'Dec 31 2274 should be iso week 53'); | |
39737 assert.equal(moment([2280, 11, 31]).isoWeek(), 53, 'Dec 31 2280 should be iso week 53'); | |
39738 assert.equal(moment([2285, 11, 31]).isoWeek(), 53, 'Dec 31 2285 should be iso week 53'); | |
39739 assert.equal(moment([2291, 11, 31]).isoWeek(), 53, 'Dec 31 2291 should be iso week 53'); | |
39740 assert.equal(moment([2296, 11, 31]).isoWeek(), 53, 'Dec 31 2296 should be iso week 53'); | |
39741 assert.equal(moment([2303, 11, 31]).isoWeek(), 53, 'Dec 31 2303 should be iso week 53'); | |
39742 assert.equal(moment([2308, 11, 31]).isoWeek(), 53, 'Dec 31 2308 should be iso week 53'); | |
39743 assert.equal(moment([2314, 11, 31]).isoWeek(), 53, 'Dec 31 2314 should be iso week 53'); | |
39744 assert.equal(moment([2320, 11, 31]).isoWeek(), 53, 'Dec 31 2320 should be iso week 53'); | |
39745 assert.equal(moment([2325, 11, 31]).isoWeek(), 53, 'Dec 31 2325 should be iso week 53'); | |
39746 assert.equal(moment([2331, 11, 31]).isoWeek(), 53, 'Dec 31 2331 should be iso week 53'); | |
39747 assert.equal(moment([2336, 11, 31]).isoWeek(), 53, 'Dec 31 2336 should be iso week 53'); | |
39748 assert.equal(moment([2342, 11, 31]).isoWeek(), 53, 'Dec 31 2342 should be iso week 53'); | |
39749 assert.equal(moment([2348, 11, 31]).isoWeek(), 53, 'Dec 31 2348 should be iso week 53'); | |
39750 assert.equal(moment([2353, 11, 31]).isoWeek(), 53, 'Dec 31 2353 should be iso week 53'); | |
39751 assert.equal(moment([2359, 11, 31]).isoWeek(), 53, 'Dec 31 2359 should be iso week 53'); | |
39752 assert.equal(moment([2364, 11, 31]).isoWeek(), 53, 'Dec 31 2364 should be iso week 53'); | |
39753 assert.equal(moment([2370, 11, 31]).isoWeek(), 53, 'Dec 31 2370 should be iso week 53'); | |
39754 assert.equal(moment([2376, 11, 31]).isoWeek(), 53, 'Dec 31 2376 should be iso week 53'); | |
39755 assert.equal(moment([2381, 11, 31]).isoWeek(), 53, 'Dec 31 2381 should be iso week 53'); | |
39756 assert.equal(moment([2387, 11, 31]).isoWeek(), 53, 'Dec 31 2387 should be iso week 53'); | |
39757 assert.equal(moment([2392, 11, 31]).isoWeek(), 53, 'Dec 31 2392 should be iso week 53'); | |
39758 assert.equal(moment([2398, 11, 31]).isoWeek(), 53, 'Dec 31 2398 should be iso week 53'); | |
39759 }); | |
39760 | |
39761 test('count years with iso week 53', function (assert) { | |
39762 // Based on http://en.wikipedia.org/wiki/ISO_week_date (as seen on 2014-01-06) | |
39763 // stating that there are 71 years in a 400-year cycle that have 53 weeks; | |
39764 // in this case reflecting the 2000 based cycle | |
39765 var count = 0, i; | |
39766 for (i = 0; i < 400; i++) { | |
39767 count += (moment([2000 + i, 11, 31]).isoWeek() === 53) ? 1 : 0; | |
39768 } | |
39769 assert.equal(count, 71, 'Should have 71 years in 400-year cycle with iso week 53'); | |
39770 }); | |
39771 | |
39772 })); | |
39773 | |
39774 (function (global, factory) { | |
39775 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
39776 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
39777 factory(global.moment) | |
39778 }(this, function (moment) { 'use strict'; | |
39779 | |
39780 /*global QUnit:false*/ | |
39781 | |
39782 var test = QUnit.test; | |
39783 | |
39784 function module (name, lifecycle) { | |
39785 QUnit.module(name, { | |
39786 setup : function () { | |
39787 moment.locale('en'); | |
39788 moment.createFromInputFallback = function () { | |
39789 throw new Error('input not handled by moment'); | |
39790 }; | |
39791 if (lifecycle && lifecycle.setup) { | |
39792 lifecycle.setup(); | |
39793 } | |
39794 }, | |
39795 teardown : function () { | |
39796 if (lifecycle && lifecycle.teardown) { | |
39797 lifecycle.teardown(); | |
39798 } | |
39799 } | |
39800 }); | |
39801 } | |
39802 | |
39803 function localeModule (name, lifecycle) { | |
39804 QUnit.module('locale:' + name, { | |
39805 setup : function () { | |
39806 moment.locale(name); | |
39807 moment.createFromInputFallback = function () { | |
39808 throw new Error('input not handled by moment'); | |
39809 }; | |
39810 if (lifecycle && lifecycle.setup) { | |
39811 lifecycle.setup(); | |
39812 } | |
39813 }, | |
39814 teardown : function () { | |
39815 moment.locale('en'); | |
39816 if (lifecycle && lifecycle.teardown) { | |
39817 lifecycle.teardown(); | |
39818 } | |
39819 } | |
39820 }); | |
39821 } | |
39822 | |
39823 module('weeks in year'); | |
39824 | |
39825 test('isoWeeksInYear', function (assert) { | |
39826 assert.equal(moment([2004]).isoWeeksInYear(), 53, '2004 has 53 iso weeks'); | |
39827 assert.equal(moment([2005]).isoWeeksInYear(), 52, '2005 has 53 iso weeks'); | |
39828 assert.equal(moment([2006]).isoWeeksInYear(), 52, '2006 has 53 iso weeks'); | |
39829 assert.equal(moment([2007]).isoWeeksInYear(), 52, '2007 has 52 iso weeks'); | |
39830 assert.equal(moment([2008]).isoWeeksInYear(), 52, '2008 has 53 iso weeks'); | |
39831 assert.equal(moment([2009]).isoWeeksInYear(), 53, '2009 has 53 iso weeks'); | |
39832 assert.equal(moment([2010]).isoWeeksInYear(), 52, '2010 has 52 iso weeks'); | |
39833 assert.equal(moment([2011]).isoWeeksInYear(), 52, '2011 has 52 iso weeks'); | |
39834 assert.equal(moment([2012]).isoWeeksInYear(), 52, '2012 has 52 iso weeks'); | |
39835 assert.equal(moment([2013]).isoWeeksInYear(), 52, '2013 has 52 iso weeks'); | |
39836 assert.equal(moment([2014]).isoWeeksInYear(), 52, '2014 has 52 iso weeks'); | |
39837 assert.equal(moment([2015]).isoWeeksInYear(), 53, '2015 has 53 iso weeks'); | |
39838 }); | |
39839 | |
39840 test('weeksInYear doy/dow = 1/4', function (assert) { | |
39841 moment.locale('1/4', {week: {dow: 1, doy: 4}}); | |
39842 | |
39843 assert.equal(moment([2004]).weeksInYear(), 53, '2004 has 53 weeks'); | |
39844 assert.equal(moment([2005]).weeksInYear(), 52, '2005 has 53 weeks'); | |
39845 assert.equal(moment([2006]).weeksInYear(), 52, '2006 has 53 weeks'); | |
39846 assert.equal(moment([2007]).weeksInYear(), 52, '2007 has 52 weeks'); | |
39847 assert.equal(moment([2008]).weeksInYear(), 52, '2008 has 53 weeks'); | |
39848 assert.equal(moment([2009]).weeksInYear(), 53, '2009 has 53 weeks'); | |
39849 assert.equal(moment([2010]).weeksInYear(), 52, '2010 has 52 weeks'); | |
39850 assert.equal(moment([2011]).weeksInYear(), 52, '2011 has 52 weeks'); | |
39851 assert.equal(moment([2012]).weeksInYear(), 52, '2012 has 52 weeks'); | |
39852 assert.equal(moment([2013]).weeksInYear(), 52, '2013 has 52 weeks'); | |
39853 assert.equal(moment([2014]).weeksInYear(), 52, '2014 has 52 weeks'); | |
39854 assert.equal(moment([2015]).weeksInYear(), 53, '2015 has 53 weeks'); | |
39855 }); | |
39856 | |
39857 test('weeksInYear doy/dow = 6/12', function (assert) { | |
39858 moment.locale('6/12', {week: {dow: 6, doy: 12}}); | |
39859 | |
39860 assert.equal(moment([2004]).weeksInYear(), 53, '2004 has 53 weeks'); | |
39861 assert.equal(moment([2005]).weeksInYear(), 52, '2005 has 53 weeks'); | |
39862 assert.equal(moment([2006]).weeksInYear(), 52, '2006 has 53 weeks'); | |
39863 assert.equal(moment([2007]).weeksInYear(), 52, '2007 has 52 weeks'); | |
39864 assert.equal(moment([2008]).weeksInYear(), 52, '2008 has 53 weeks'); | |
39865 assert.equal(moment([2009]).weeksInYear(), 52, '2009 has 53 weeks'); | |
39866 assert.equal(moment([2010]).weeksInYear(), 53, '2010 has 52 weeks'); | |
39867 assert.equal(moment([2011]).weeksInYear(), 52, '2011 has 52 weeks'); | |
39868 assert.equal(moment([2012]).weeksInYear(), 52, '2012 has 52 weeks'); | |
39869 assert.equal(moment([2013]).weeksInYear(), 52, '2013 has 52 weeks'); | |
39870 assert.equal(moment([2014]).weeksInYear(), 52, '2014 has 52 weeks'); | |
39871 assert.equal(moment([2015]).weeksInYear(), 52, '2015 has 53 weeks'); | |
39872 }); | |
39873 | |
39874 test('weeksInYear doy/dow = 1/7', function (assert) { | |
39875 moment.locale('1/7', {week: {dow: 1, doy: 7}}); | |
39876 | |
39877 assert.equal(moment([2004]).weeksInYear(), 52, '2004 has 53 weeks'); | |
39878 assert.equal(moment([2005]).weeksInYear(), 52, '2005 has 53 weeks'); | |
39879 assert.equal(moment([2006]).weeksInYear(), 53, '2006 has 53 weeks'); | |
39880 assert.equal(moment([2007]).weeksInYear(), 52, '2007 has 52 weeks'); | |
39881 assert.equal(moment([2008]).weeksInYear(), 52, '2008 has 53 weeks'); | |
39882 assert.equal(moment([2009]).weeksInYear(), 52, '2009 has 53 weeks'); | |
39883 assert.equal(moment([2010]).weeksInYear(), 52, '2010 has 52 weeks'); | |
39884 assert.equal(moment([2011]).weeksInYear(), 52, '2011 has 52 weeks'); | |
39885 assert.equal(moment([2012]).weeksInYear(), 53, '2012 has 52 weeks'); | |
39886 assert.equal(moment([2013]).weeksInYear(), 52, '2013 has 52 weeks'); | |
39887 assert.equal(moment([2014]).weeksInYear(), 52, '2014 has 52 weeks'); | |
39888 assert.equal(moment([2015]).weeksInYear(), 52, '2015 has 53 weeks'); | |
39889 }); | |
39890 | |
39891 test('weeksInYear doy/dow = 0/6', function (assert) { | |
39892 moment.locale('0/6', {week: {dow: 0, doy: 6}}); | |
39893 | |
39894 assert.equal(moment([2004]).weeksInYear(), 52, '2004 has 53 weeks'); | |
39895 assert.equal(moment([2005]).weeksInYear(), 53, '2005 has 53 weeks'); | |
39896 assert.equal(moment([2006]).weeksInYear(), 52, '2006 has 53 weeks'); | |
39897 assert.equal(moment([2007]).weeksInYear(), 52, '2007 has 52 weeks'); | |
39898 assert.equal(moment([2008]).weeksInYear(), 52, '2008 has 53 weeks'); | |
39899 assert.equal(moment([2009]).weeksInYear(), 52, '2009 has 53 weeks'); | |
39900 assert.equal(moment([2010]).weeksInYear(), 52, '2010 has 52 weeks'); | |
39901 assert.equal(moment([2011]).weeksInYear(), 53, '2011 has 52 weeks'); | |
39902 assert.equal(moment([2012]).weeksInYear(), 52, '2012 has 52 weeks'); | |
39903 assert.equal(moment([2013]).weeksInYear(), 52, '2013 has 52 weeks'); | |
39904 assert.equal(moment([2014]).weeksInYear(), 52, '2014 has 52 weeks'); | |
39905 assert.equal(moment([2015]).weeksInYear(), 52, '2015 has 53 weeks'); | |
39906 }); | |
39907 | |
39908 })); | |
39909 | |
39910 (function (global, factory) { | |
39911 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
39912 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
39913 factory(global.moment) | |
39914 }(this, function (moment) { 'use strict'; | |
39915 | |
39916 /*global QUnit:false*/ | |
39917 | |
39918 var test = QUnit.test; | |
39919 | |
39920 function module (name, lifecycle) { | |
39921 QUnit.module(name, { | |
39922 setup : function () { | |
39923 moment.locale('en'); | |
39924 moment.createFromInputFallback = function () { | |
39925 throw new Error('input not handled by moment'); | |
39926 }; | |
39927 if (lifecycle && lifecycle.setup) { | |
39928 lifecycle.setup(); | |
39929 } | |
39930 }, | |
39931 teardown : function () { | |
39932 if (lifecycle && lifecycle.teardown) { | |
39933 lifecycle.teardown(); | |
39934 } | |
39935 } | |
39936 }); | |
39937 } | |
39938 | |
39939 function localeModule (name, lifecycle) { | |
39940 QUnit.module('locale:' + name, { | |
39941 setup : function () { | |
39942 moment.locale(name); | |
39943 moment.createFromInputFallback = function () { | |
39944 throw new Error('input not handled by moment'); | |
39945 }; | |
39946 if (lifecycle && lifecycle.setup) { | |
39947 lifecycle.setup(); | |
39948 } | |
39949 }, | |
39950 teardown : function () { | |
39951 moment.locale('en'); | |
39952 if (lifecycle && lifecycle.teardown) { | |
39953 lifecycle.teardown(); | |
39954 } | |
39955 } | |
39956 }); | |
39957 } | |
39958 | |
39959 module('zone switching'); | |
39960 | |
39961 test('local to utc, keepLocalTime = true', function (assert) { | |
39962 var m = moment(), | |
39963 fmt = 'YYYY-DD-MM HH:mm:ss'; | |
39964 assert.equal(m.clone().utc(true).format(fmt), m.format(fmt), 'local to utc failed to keep local time'); | |
39965 }); | |
39966 | |
39967 test('local to utc, keepLocalTime = false', function (assert) { | |
39968 var m = moment(); | |
39969 assert.equal(m.clone().utc().valueOf(), m.valueOf(), 'local to utc failed to keep utc time (implicit)'); | |
39970 assert.equal(m.clone().utc(false).valueOf(), m.valueOf(), 'local to utc failed to keep utc time (explicit)'); | |
39971 }); | |
39972 | |
39973 test('local to zone, keepLocalTime = true', function (assert) { | |
39974 var m = moment(), | |
39975 fmt = 'YYYY-DD-MM HH:mm:ss', | |
39976 z; | |
39977 | |
39978 // Apparently there is -12:00 and +14:00 | |
39979 // http://en.wikipedia.org/wiki/UTC+14:00 | |
39980 // http://en.wikipedia.org/wiki/UTC-12:00 | |
39981 for (z = -12; z <= 14; ++z) { | |
39982 assert.equal(m.clone().zone(z * 60, true).format(fmt), m.format(fmt), | |
39983 'local to zone(' + z + ':00) failed to keep local time'); | |
39984 } | |
39985 }); | |
39986 | |
39987 test('local to zone, keepLocalTime = false', function (assert) { | |
39988 var m = moment(), | |
39989 z; | |
39990 | |
39991 // Apparently there is -12:00 and +14:00 | |
39992 // http://en.wikipedia.org/wiki/UTC+14:00 | |
39993 // http://en.wikipedia.org/wiki/UTC-12:00 | |
39994 for (z = -12; z <= 14; ++z) { | |
39995 assert.equal(m.clone().zone(z * 60).valueOf(), m.valueOf(), | |
39996 'local to zone(' + z + ':00) failed to keep utc time (implicit)'); | |
39997 assert.equal(m.clone().zone(z * 60, false).valueOf(), m.valueOf(), | |
39998 'local to zone(' + z + ':00) failed to keep utc time (explicit)'); | |
39999 } | |
40000 }); | |
40001 | |
40002 test('utc to local, keepLocalTime = true', function (assert) { | |
40003 var um = moment.utc(), | |
40004 fmt = 'YYYY-DD-MM HH:mm:ss'; | |
40005 | |
40006 assert.equal(um.clone().local(true).format(fmt), um.format(fmt), 'utc to local failed to keep local time'); | |
40007 }); | |
40008 | |
40009 test('utc to local, keepLocalTime = false', function (assert) { | |
40010 var um = moment.utc(); | |
40011 assert.equal(um.clone().local().valueOf(), um.valueOf(), 'utc to local failed to keep utc time (implicit)'); | |
40012 assert.equal(um.clone().local(false).valueOf(), um.valueOf(), 'utc to local failed to keep utc time (explicit)'); | |
40013 }); | |
40014 | |
40015 test('zone to local, keepLocalTime = true', function (assert) { | |
40016 var m = moment(), | |
40017 fmt = 'YYYY-DD-MM HH:mm:ss', | |
40018 z; | |
40019 | |
40020 // Apparently there is -12:00 and +14:00 | |
40021 // http://en.wikipedia.org/wiki/UTC+14:00 | |
40022 // http://en.wikipedia.org/wiki/UTC-12:00 | |
40023 for (z = -12; z <= 14; ++z) { | |
40024 m.zone(z * 60); | |
40025 | |
40026 assert.equal(m.clone().local(true).format(fmt), m.format(fmt), | |
40027 'zone(' + z + ':00) to local failed to keep local time'); | |
40028 } | |
40029 }); | |
40030 | |
40031 test('zone to local, keepLocalTime = false', function (assert) { | |
40032 var m = moment(), | |
40033 z; | |
40034 | |
40035 // Apparently there is -12:00 and +14:00 | |
40036 // http://en.wikipedia.org/wiki/UTC+14:00 | |
40037 // http://en.wikipedia.org/wiki/UTC-12:00 | |
40038 for (z = -12; z <= 14; ++z) { | |
40039 m.zone(z * 60); | |
40040 | |
40041 assert.equal(m.clone().local(false).valueOf(), m.valueOf(), | |
40042 'zone(' + z + ':00) to local failed to keep utc time (explicit)'); | |
40043 assert.equal(m.clone().local().valueOf(), m.valueOf(), | |
40044 'zone(' + z + ':00) to local failed to keep utc time (implicit)'); | |
40045 } | |
40046 }); | |
40047 | |
40048 })); | |
40049 | |
40050 (function (global, factory) { | |
40051 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) : | |
40052 typeof define === 'function' && define.amd ? define(['../../moment'], factory) : | |
40053 factory(global.moment) | |
40054 }(this, function (moment) { 'use strict'; | |
40055 | |
40056 /*global QUnit:false*/ | |
40057 | |
40058 var test = QUnit.test; | |
40059 | |
40060 function module (name, lifecycle) { | |
40061 QUnit.module(name, { | |
40062 setup : function () { | |
40063 moment.locale('en'); | |
40064 moment.createFromInputFallback = function () { | |
40065 throw new Error('input not handled by moment'); | |
40066 }; | |
40067 if (lifecycle && lifecycle.setup) { | |
40068 lifecycle.setup(); | |
40069 } | |
40070 }, | |
40071 teardown : function () { | |
40072 if (lifecycle && lifecycle.teardown) { | |
40073 lifecycle.teardown(); | |
40074 } | |
40075 } | |
40076 }); | |
40077 } | |
40078 | |
40079 function localeModule (name, lifecycle) { | |
40080 QUnit.module('locale:' + name, { | |
40081 setup : function () { | |
40082 moment.locale(name); | |
40083 moment.createFromInputFallback = function () { | |
40084 throw new Error('input not handled by moment'); | |
40085 }; | |
40086 if (lifecycle && lifecycle.setup) { | |
40087 lifecycle.setup(); | |
40088 } | |
40089 }, | |
40090 teardown : function () { | |
40091 moment.locale('en'); | |
40092 if (lifecycle && lifecycle.teardown) { | |
40093 lifecycle.teardown(); | |
40094 } | |
40095 } | |
40096 }); | |
40097 } | |
40098 | |
40099 module('zones'); | |
40100 | |
40101 test('set zone', function (assert) { | |
40102 var zone = moment(); | |
40103 | |
40104 zone.zone(0); | |
40105 assert.equal(zone.zone(), 0, 'should be able to set the zone to 0'); | |
40106 | |
40107 zone.zone(60); | |
40108 assert.equal(zone.zone(), 60, 'should be able to set the zone to 60'); | |
40109 | |
40110 zone.zone(-60); | |
40111 assert.equal(zone.zone(), -60, 'should be able to set the zone to -60'); | |
40112 }); | |
40113 | |
40114 test('set zone shorthand', function (assert) { | |
40115 var zone = moment(); | |
40116 | |
40117 zone.zone(1); | |
40118 assert.equal(zone.zone(), 60, 'setting the zone to 1 should imply hours and convert to 60'); | |
40119 | |
40120 zone.zone(-1); | |
40121 assert.equal(zone.zone(), -60, 'setting the zone to -1 should imply hours and convert to -60'); | |
40122 | |
40123 zone.zone(15); | |
40124 assert.equal(zone.zone(), 900, 'setting the zone to 15 should imply hours and convert to 900'); | |
40125 | |
40126 zone.zone(-15); | |
40127 assert.equal(zone.zone(), -900, 'setting the zone to -15 should imply hours and convert to -900'); | |
40128 | |
40129 zone.zone(16); | |
40130 assert.equal(zone.zone(), 16, 'setting the zone to 16 should imply minutes'); | |
40131 | |
40132 zone.zone(-16); | |
40133 assert.equal(zone.zone(), -16, 'setting the zone to -16 should imply minutes'); | |
40134 }); | |
40135 | |
40136 test('set zone with string', function (assert) { | |
40137 var zone = moment(); | |
40138 | |
40139 zone.zone('+00:00'); | |
40140 assert.equal(zone.zone(), 0, 'set the zone with a timezone string'); | |
40141 | |
40142 zone.zone('2013-03-07T07:00:00-08:00'); | |
40143 assert.equal(zone.zone(), 480, 'set the zone with a string that does not begin with the timezone'); | |
40144 | |
40145 zone.zone('2013-03-07T07:00:00+0100'); | |
40146 assert.equal(zone.zone(), -60, 'set the zone with a string that uses the +0000 syntax'); | |
40147 | |
40148 zone.zone('03-07-2013T07:00:00-08:00'); | |
40149 assert.equal(zone.zone(), 480, 'set the zone with a string with a non-ISO 8601 date'); | |
40150 }); | |
40151 | |
40152 test('change hours when changing the zone', function (assert) { | |
40153 var zone = moment.utc([2000, 0, 1, 6]); | |
40154 | |
40155 zone.zone(0); | |
40156 assert.equal(zone.hour(), 6, 'UTC 6AM should be 6AM at +0000'); | |
40157 | |
40158 zone.zone(60); | |
40159 assert.equal(zone.hour(), 5, 'UTC 6AM should be 5AM at -0100'); | |
40160 | |
40161 zone.zone(-60); | |
40162 assert.equal(zone.hour(), 7, 'UTC 6AM should be 7AM at +0100'); | |
40163 }); | |
40164 | |
40165 test('change minutes when changing the zone', function (assert) { | |
40166 var zone = moment.utc([2000, 0, 1, 6, 31]); | |
40167 | |
40168 zone.zone(0); | |
40169 assert.equal(zone.format('HH:mm'), '06:31', 'UTC 6:31AM should be 6:31AM at +0000'); | |
40170 | |
40171 zone.zone(30); | |
40172 assert.equal(zone.format('HH:mm'), '06:01', 'UTC 6:31AM should be 6:01AM at -0030'); | |
40173 | |
40174 zone.zone(-30); | |
40175 assert.equal(zone.format('HH:mm'), '07:01', 'UTC 6:31AM should be 7:01AM at +0030'); | |
40176 | |
40177 zone.zone(1380); | |
40178 assert.equal(zone.format('HH:mm'), '07:31', 'UTC 6:31AM should be 7:31AM at +1380'); | |
40179 }); | |
40180 | |
40181 test('distance from the unix epoch', function (assert) { | |
40182 var zoneA = moment(), | |
40183 zoneB = moment(zoneA), | |
40184 zoneC = moment(zoneA), | |
40185 zoneD = moment(zoneA), | |
40186 zoneE = moment(zoneA); | |
40187 | |
40188 zoneB.utc(); | |
40189 assert.equal(+zoneA, +zoneB, 'moment should equal moment.utc'); | |
40190 | |
40191 zoneC.zone(-60); | |
40192 assert.equal(+zoneA, +zoneC, 'moment should equal moment.zone(-60)'); | |
40193 | |
40194 zoneD.zone(480); | |
40195 assert.equal(+zoneA, +zoneD, 'moment should equal moment.zone(480)'); | |
40196 | |
40197 zoneE.zone(1000); | |
40198 assert.equal(+zoneA, +zoneE, 'moment should equal moment.zone(1000)'); | |
40199 }); | |
40200 | |
40201 test('update offset after changing any values', function (assert) { | |
40202 var oldOffset = moment.updateOffset, | |
40203 m = moment.utc([2000, 6, 1]); | |
40204 | |
40205 moment.updateOffset = function (mom, keepTime) { | |
40206 if (mom.__doChange) { | |
40207 if (+mom > 962409600000) { | |
40208 mom.zone(120, keepTime); | |
40209 } else { | |
40210 mom.zone(60, keepTime); | |
40211 } | |
40212 } | |
40213 }; | |
40214 | |
40215 assert.equal(m.format('ZZ'), '+0000', 'should be at +0000'); | |
40216 assert.equal(m.format('HH:mm'), '00:00', 'should start 12AM at +0000 timezone'); | |
40217 | |
40218 m.__doChange = true; | |
40219 m.add(1, 'h'); | |
40220 | |
40221 assert.equal(m.format('ZZ'), '-0200', 'should be at -0200'); | |
40222 assert.equal(m.format('HH:mm'), '23:00', '1AM at +0000 should be 11PM at -0200 timezone'); | |
40223 | |
40224 m.subtract(1, 'h'); | |
40225 | |
40226 assert.equal(m.format('ZZ'), '-0100', 'should be at -0100'); | |
40227 assert.equal(m.format('HH:mm'), '23:00', '12AM at +0000 should be 11PM at -0100 timezone'); | |
40228 | |
40229 moment.updateOffset = oldOffset; | |
40230 }); | |
40231 | |
40232 test('getters and setters', function (assert) { | |
40233 var a = moment([2011, 5, 20]); | |
40234 | |
40235 assert.equal(a.clone().zone(120).year(2012).year(), 2012, 'should get and set year correctly'); | |
40236 assert.equal(a.clone().zone(120).month(1).month(), 1, 'should get and set month correctly'); | |
40237 assert.equal(a.clone().zone(120).date(2).date(), 2, 'should get and set date correctly'); | |
40238 assert.equal(a.clone().zone(120).day(1).day(), 1, 'should get and set day correctly'); | |
40239 assert.equal(a.clone().zone(120).hour(1).hour(), 1, 'should get and set hour correctly'); | |
40240 assert.equal(a.clone().zone(120).minute(1).minute(), 1, 'should get and set minute correctly'); | |
40241 }); | |
40242 | |
40243 test('getters', function (assert) { | |
40244 var a = moment.utc([2012, 0, 1, 0, 0, 0]); | |
40245 | |
40246 assert.equal(a.clone().zone(120).year(), 2011, 'should get year correctly'); | |
40247 assert.equal(a.clone().zone(120).month(), 11, 'should get month correctly'); | |
40248 assert.equal(a.clone().zone(120).date(), 31, 'should get date correctly'); | |
40249 assert.equal(a.clone().zone(120).hour(), 22, 'should get hour correctly'); | |
40250 assert.equal(a.clone().zone(120).minute(), 0, 'should get minute correctly'); | |
40251 | |
40252 assert.equal(a.clone().zone(-120).year(), 2012, 'should get year correctly'); | |
40253 assert.equal(a.clone().zone(-120).month(), 0, 'should get month correctly'); | |
40254 assert.equal(a.clone().zone(-120).date(), 1, 'should get date correctly'); | |
40255 assert.equal(a.clone().zone(-120).hour(), 2, 'should get hour correctly'); | |
40256 assert.equal(a.clone().zone(-120).minute(), 0, 'should get minute correctly'); | |
40257 | |
40258 assert.equal(a.clone().zone(-90).year(), 2012, 'should get year correctly'); | |
40259 assert.equal(a.clone().zone(-90).month(), 0, 'should get month correctly'); | |
40260 assert.equal(a.clone().zone(-90).date(), 1, 'should get date correctly'); | |
40261 assert.equal(a.clone().zone(-90).hour(), 1, 'should get hour correctly'); | |
40262 assert.equal(a.clone().zone(-90).minute(), 30, 'should get minute correctly'); | |
40263 }); | |
40264 | |
40265 test('from', function (assert) { | |
40266 var zoneA = moment(), | |
40267 zoneB = moment(zoneA).zone(720), | |
40268 zoneC = moment(zoneA).zone(360), | |
40269 zoneD = moment(zoneA).zone(-690), | |
40270 other = moment(zoneA).add(35, 'm'); | |
40271 | |
40272 assert.equal(zoneA.from(other), zoneB.from(other), 'moment#from should be the same in all zones'); | |
40273 assert.equal(zoneA.from(other), zoneC.from(other), 'moment#from should be the same in all zones'); | |
40274 assert.equal(zoneA.from(other), zoneD.from(other), 'moment#from should be the same in all zones'); | |
40275 }); | |
40276 | |
40277 test('diff', function (assert) { | |
40278 var zoneA = moment(), | |
40279 zoneB = moment(zoneA).zone(720), | |
40280 zoneC = moment(zoneA).zone(360), | |
40281 zoneD = moment(zoneA).zone(-690), | |
40282 other = moment(zoneA).add(35, 'm'); | |
40283 | |
40284 assert.equal(zoneA.diff(other), zoneB.diff(other), 'moment#diff should be the same in all zones'); | |
40285 assert.equal(zoneA.diff(other), zoneC.diff(other), 'moment#diff should be the same in all zones'); | |
40286 assert.equal(zoneA.diff(other), zoneD.diff(other), 'moment#diff should be the same in all zones'); | |
40287 | |
40288 assert.equal(zoneA.diff(other, 'minute', true), zoneB.diff(other, 'minute', true), 'moment#diff should be the same in all zones'); | |
40289 assert.equal(zoneA.diff(other, 'minute', true), zoneC.diff(other, 'minute', true), 'moment#diff should be the same in all zones'); | |
40290 assert.equal(zoneA.diff(other, 'minute', true), zoneD.diff(other, 'minute', true), 'moment#diff should be the same in all zones'); | |
40291 | |
40292 assert.equal(zoneA.diff(other, 'hour', true), zoneB.diff(other, 'hour', true), 'moment#diff should be the same in all zones'); | |
40293 assert.equal(zoneA.diff(other, 'hour', true), zoneC.diff(other, 'hour', true), 'moment#diff should be the same in all zones'); | |
40294 assert.equal(zoneA.diff(other, 'hour', true), zoneD.diff(other, 'hour', true), 'moment#diff should be the same in all zones'); | |
40295 }); | |
40296 | |
40297 test('unix offset and timestamp', function (assert) { | |
40298 var zoneA = moment(), | |
40299 zoneB = moment(zoneA).zone(720), | |
40300 zoneC = moment(zoneA).zone(360), | |
40301 zoneD = moment(zoneA).zone(-690); | |
40302 | |
40303 assert.equal(zoneA.unix(), zoneB.unix(), 'moment#unix should be the same in all zones'); | |
40304 assert.equal(zoneA.unix(), zoneC.unix(), 'moment#unix should be the same in all zones'); | |
40305 assert.equal(zoneA.unix(), zoneD.unix(), 'moment#unix should be the same in all zones'); | |
40306 | |
40307 assert.equal(+zoneA, +zoneB, 'moment#valueOf should be the same in all zones'); | |
40308 assert.equal(+zoneA, +zoneC, 'moment#valueOf should be the same in all zones'); | |
40309 assert.equal(+zoneA, +zoneD, 'moment#valueOf should be the same in all zones'); | |
40310 }); | |
40311 | |
40312 test('cloning', function (assert) { | |
40313 assert.equal(moment().zone(120).clone().zone(), 120, 'explicit cloning should retain the zone'); | |
40314 assert.equal(moment().zone(-120).clone().zone(), -120, 'explicit cloning should retain the zone'); | |
40315 assert.equal(moment(moment().zone(120)).zone(), 120, 'implicit cloning should retain the zone'); | |
40316 assert.equal(moment(moment().zone(-120)).zone(), -120, 'implicit cloning should retain the zone'); | |
40317 }); | |
40318 | |
40319 test('start of / end of', function (assert) { | |
40320 var a = moment.utc([2010, 1, 2, 0, 0, 0]).zone(450); | |
40321 | |
40322 assert.equal(a.clone().startOf('day').hour(), 0, 'start of day should work on moments with a zone'); | |
40323 assert.equal(a.clone().startOf('day').minute(), 0, 'start of day should work on moments with a zone'); | |
40324 assert.equal(a.clone().startOf('hour').minute(), 0, 'start of hour should work on moments with a zone'); | |
40325 | |
40326 assert.equal(a.clone().endOf('day').hour(), 23, 'end of day should work on moments with a zone'); | |
40327 assert.equal(a.clone().endOf('day').minute(), 59, 'end of day should work on moments with a zone'); | |
40328 assert.equal(a.clone().endOf('hour').minute(), 59, 'end of hour should work on moments with a zone'); | |
40329 }); | |
40330 | |
40331 test('reset zone with moment#utc', function (assert) { | |
40332 var a = moment.utc([2012]).zone(480); | |
40333 | |
40334 assert.equal(a.clone().hour(), 16, 'different zone should have different hour'); | |
40335 assert.equal(a.clone().utc().hour(), 0, 'calling moment#utc should reset the offset'); | |
40336 }); | |
40337 | |
40338 test('reset zone with moment#local', function (assert) { | |
40339 var a = moment([2012]).zone(480); | |
40340 | |
40341 assert.equal(a.clone().local().hour(), 0, 'calling moment#local should reset the offset'); | |
40342 }); | |
40343 | |
40344 test('toDate', function (assert) { | |
40345 var zoneA = new Date(), | |
40346 zoneB = moment(zoneA).zone(720).toDate(), | |
40347 zoneC = moment(zoneA).zone(360).toDate(), | |
40348 zoneD = moment(zoneA).zone(-690).toDate(); | |
40349 | |
40350 assert.equal(+zoneA, +zoneB, 'moment#toDate should output a date with the right unix timestamp'); | |
40351 assert.equal(+zoneA, +zoneC, 'moment#toDate should output a date with the right unix timestamp'); | |
40352 assert.equal(+zoneA, +zoneD, 'moment#toDate should output a date with the right unix timestamp'); | |
40353 }); | |
40354 | |
40355 test('same / before / after', function (assert) { | |
40356 var zoneA = moment().utc(), | |
40357 zoneB = moment(zoneA).zone(120), | |
40358 zoneC = moment(zoneA).zone(-120); | |
40359 | |
40360 assert.ok(zoneA.isSame(zoneB), 'two moments with different offsets should be the same'); | |
40361 assert.ok(zoneA.isSame(zoneC), 'two moments with different offsets should be the same'); | |
40362 | |
40363 assert.ok(zoneA.isSame(zoneB, 'hour'), 'two moments with different offsets should be the same hour'); | |
40364 assert.ok(zoneA.isSame(zoneC, 'hour'), 'two moments with different offsets should be the same hour'); | |
40365 | |
40366 zoneA.add(1, 'hour'); | |
40367 | |
40368 assert.ok(zoneA.isAfter(zoneB), 'isAfter should work with two moments with different offsets'); | |
40369 assert.ok(zoneA.isAfter(zoneC), 'isAfter should work with two moments with different offsets'); | |
40370 | |
40371 assert.ok(zoneA.isAfter(zoneB, 'hour'), 'isAfter:hour should work with two moments with different offsets'); | |
40372 assert.ok(zoneA.isAfter(zoneC, 'hour'), 'isAfter:hour should work with two moments with different offsets'); | |
40373 | |
40374 zoneA.subtract(2, 'hour'); | |
40375 | |
40376 assert.ok(zoneA.isBefore(zoneB), 'isBefore should work with two moments with different offsets'); | |
40377 assert.ok(zoneA.isBefore(zoneC), 'isBefore should work with two moments with different offsets'); | |
40378 | |
40379 assert.ok(zoneA.isBefore(zoneB, 'hour'), 'isBefore:hour should work with two moments with different offsets'); | |
40380 assert.ok(zoneA.isBefore(zoneC, 'hour'), 'isBefore:hour should work with two moments with different offsets'); | |
40381 }); | |
40382 | |
40383 test('add / subtract over dst', function (assert) { | |
40384 var oldOffset = moment.updateOffset, | |
40385 m = moment.utc([2000, 2, 31, 3]); | |
40386 | |
40387 moment.updateOffset = function (mom, keepTime) { | |
40388 if (mom.clone().utc().month() > 2) { | |
40389 mom.zone(-60, keepTime); | |
40390 } else { | |
40391 mom.zone(0, keepTime); | |
40392 } | |
40393 }; | |
40394 | |
40395 assert.equal(m.hour(), 3, 'should start at 00:00'); | |
40396 | |
40397 m.add(24, 'hour'); | |
40398 | |
40399 assert.equal(m.hour(), 4, 'adding 24 hours should disregard dst'); | |
40400 | |
40401 m.subtract(24, 'hour'); | |
40402 | |
40403 assert.equal(m.hour(), 3, 'subtracting 24 hours should disregard dst'); | |
40404 | |
40405 m.add(1, 'day'); | |
40406 | |
40407 assert.equal(m.hour(), 3, 'adding 1 day should have the same hour'); | |
40408 | |
40409 m.subtract(1, 'day'); | |
40410 | |
40411 assert.equal(m.hour(), 3, 'subtracting 1 day should have the same hour'); | |
40412 | |
40413 m.add(1, 'month'); | |
40414 | |
40415 assert.equal(m.hour(), 3, 'adding 1 month should have the same hour'); | |
40416 | |
40417 m.subtract(1, 'month'); | |
40418 | |
40419 assert.equal(m.hour(), 3, 'subtracting 1 month should have the same hour'); | |
40420 | |
40421 moment.updateOffset = oldOffset; | |
40422 }); | |
40423 | |
40424 test('isDST', function (assert) { | |
40425 var oldOffset = moment.updateOffset; | |
40426 | |
40427 moment.updateOffset = function (mom, keepTime) { | |
40428 if (mom.month() > 2 && mom.month() < 9) { | |
40429 mom.zone(-60, keepTime); | |
40430 } else { | |
40431 mom.zone(0, keepTime); | |
40432 } | |
40433 }; | |
40434 | |
40435 assert.ok(!moment().month(0).isDST(), 'Jan should not be summer dst'); | |
40436 assert.ok(moment().month(6).isDST(), 'Jul should be summer dst'); | |
40437 assert.ok(!moment().month(11).isDST(), 'Dec should not be summer dst'); | |
40438 | |
40439 moment.updateOffset = function (mom) { | |
40440 if (mom.month() > 2 && mom.month() < 9) { | |
40441 mom.zone(0); | |
40442 } else { | |
40443 mom.zone(-60); | |
40444 } | |
40445 }; | |
40446 | |
40447 assert.ok(moment().month(0).isDST(), 'Jan should be winter dst'); | |
40448 assert.ok(!moment().month(6).isDST(), 'Jul should not be winter dst'); | |
40449 assert.ok(moment().month(11).isDST(), 'Dec should be winter dst'); | |
40450 | |
40451 moment.updateOffset = oldOffset; | |
40452 }); | |
40453 | |
40454 test('zone names', function (assert) { | |
40455 assert.equal(moment().zoneAbbr(), '', 'Local zone abbr should be empty'); | |
40456 assert.equal(moment().format('z'), '', 'Local zone formatted abbr should be empty'); | |
40457 assert.equal(moment().zoneName(), '', 'Local zone name should be empty'); | |
40458 assert.equal(moment().format('zz'), '', 'Local zone formatted name should be empty'); | |
40459 | |
40460 assert.equal(moment.utc().zoneAbbr(), 'UTC', 'UTC zone abbr should be UTC'); | |
40461 assert.equal(moment.utc().format('z'), 'UTC', 'UTC zone formatted abbr should be UTC'); | |
40462 assert.equal(moment.utc().zoneName(), 'Coordinated Universal Time', 'UTC zone abbr should be Coordinated Universal Time'); | |
40463 assert.equal(moment.utc().format('zz'), 'Coordinated Universal Time', 'UTC zone formatted abbr should be Coordinated Universal Time'); | |
40464 }); | |
40465 | |
40466 test('hours alignment with UTC', function (assert) { | |
40467 assert.equal(moment().zone(120).hasAlignedHourOffset(), true); | |
40468 assert.equal(moment().zone(-180).hasAlignedHourOffset(), true); | |
40469 assert.equal(moment().zone(90).hasAlignedHourOffset(), false); | |
40470 assert.equal(moment().zone(-90).hasAlignedHourOffset(), false); | |
40471 }); | |
40472 | |
40473 test('hours alignment with other zone', function (assert) { | |
40474 var m = moment().zone(120); | |
40475 | |
40476 assert.equal(m.hasAlignedHourOffset(moment().zone(180)), true); | |
40477 assert.equal(m.hasAlignedHourOffset(moment().zone(-180)), true); | |
40478 assert.equal(m.hasAlignedHourOffset(moment().zone(90)), false); | |
40479 assert.equal(m.hasAlignedHourOffset(moment().zone(-90)), false); | |
40480 | |
40481 m = moment().zone(90); | |
40482 | |
40483 assert.equal(m.hasAlignedHourOffset(moment().zone(180)), false); | |
40484 assert.equal(m.hasAlignedHourOffset(moment().zone(-180)), false); | |
40485 assert.equal(m.hasAlignedHourOffset(moment().zone(30)), true); | |
40486 assert.equal(m.hasAlignedHourOffset(moment().zone(-30)), true); | |
40487 | |
40488 m = moment().zone(-60); | |
40489 | |
40490 assert.equal(m.hasAlignedHourOffset(moment().zone(180)), true); | |
40491 assert.equal(m.hasAlignedHourOffset(moment().zone(-180)), true); | |
40492 assert.equal(m.hasAlignedHourOffset(moment().zone(90)), false); | |
40493 assert.equal(m.hasAlignedHourOffset(moment().zone(-90)), false); | |
40494 | |
40495 m = moment().zone(25); | |
40496 | |
40497 assert.equal(m.hasAlignedHourOffset(moment().zone(-35)), true); | |
40498 assert.equal(m.hasAlignedHourOffset(moment().zone(85)), true); | |
40499 | |
40500 assert.equal(m.hasAlignedHourOffset(moment().zone(35)), false); | |
40501 assert.equal(m.hasAlignedHourOffset(moment().zone(-85)), false); | |
40502 }); | |
40503 | |
40504 test('parse zone', function (assert) { | |
40505 var m = moment('2013-01-01T00:00:00-13:00').parseZone(); | |
40506 assert.equal(m.zone(), 13 * 60); | |
40507 assert.equal(m.hours(), 0); | |
40508 }); | |
40509 | |
40510 test('parse zone static', function (assert) { | |
40511 var m = moment.parseZone('2013-01-01T00:00:00-13:00'); | |
40512 assert.equal(m.zone(), 13 * 60); | |
40513 assert.equal(m.hours(), 0); | |
40514 }); | |
40515 | |
40516 test('parse zone with more arguments', function (assert) { | |
40517 var m; | |
40518 m = moment.parseZone('2013 01 01 05 -13:00', 'YYYY MM DD HH ZZ'); | |
40519 assert.equal(m.format(), '2013-01-01T05:00:00-13:00', 'accept input and format'); | |
40520 m = moment.parseZone('2013-01-01-13:00', 'YYYY MM DD ZZ', true); | |
40521 assert.equal(m.isValid(), false, 'accept input, format and strict flag'); | |
40522 m = moment.parseZone('2013-01-01-13:00', ['DD MM YYYY ZZ', 'YYYY MM DD ZZ']); | |
40523 assert.equal(m.format(), '2013-01-01T00:00:00-13:00', 'accept input and array of formats'); | |
40524 }); | |
40525 | |
40526 test('parse zone with a timezone from the format string', function (assert) { | |
40527 var m = moment('11-12-2013 -0400 +1100', 'DD-MM-YYYY ZZ #####').parseZone(); | |
40528 | |
40529 assert.equal(m.zone(), 4 * 60); | |
40530 }); | |
40531 | |
40532 test('parse zone without a timezone included in the format string', function (assert) { | |
40533 var m = moment('11-12-2013 -0400 +1100', 'DD-MM-YYYY').parseZone(); | |
40534 | |
40535 assert.equal(m.zone(), -11 * 60); | |
40536 }); | |
40537 | |
40538 test('timezone format', function (assert) { | |
40539 assert.equal(moment().zone(-60).format('ZZ'), '+0100', '-60 -> +0100'); | |
40540 assert.equal(moment().zone(-90).format('ZZ'), '+0130', '-90 -> +0130'); | |
40541 assert.equal(moment().zone(-120).format('ZZ'), '+0200', '-120 -> +0200'); | |
40542 | |
40543 assert.equal(moment().zone(+60).format('ZZ'), '-0100', '+60 -> -0100'); | |
40544 assert.equal(moment().zone(+90).format('ZZ'), '-0130', '+90 -> -0130'); | |
40545 assert.equal(moment().zone(+120).format('ZZ'), '-0200', '+120 -> -0200'); | |
40546 }); | |
40547 | |
40548 })); |