forked from andrewplummer/Sugar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdate.js
2895 lines (2242 loc) · 172 KB
/
date.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package('Date', function () {
"use strict";
var now = new Date();
var thisYear = now.getFullYear();
group('Locale Setup', function() {
// Imaginary locale to test locale switching
testAddLocale('fo', {
units: 'do,re,mi,fa,so,la,ti,do',
months: 'do,re,mi,fa,so,la,ti,do',
dateParse: '{year}kupo',
duration: '{num}{unit}momoney',
long: 'yeehaw'
});
notEqual(testGetLocale().code, undefined, 'Current locale must be something... other libs may overwrite this');
testSetLocale('en');
});
method('isValid', function() {
test(new Date('a fridge too far'), false, 'new Date invalid');
test(new Date(), true, 'new Date valid');
// Issue #219
test(testCreateDate('28:00'), true, 'hours may fall outside range');
test(testCreateDate('59:00'), true, 'no hours allowed outside range');
test(testCreateDate('139:00'), false, '3 digits not supported');
// These dates actually will parse out natively in V8
// equal(Date.create('05:75').isValid(), false, 'no minutes allowed outside range');
// equal(Date.create('05:59:60').isValid(), false, 'no seconds allowed outside range');
test(testCreateDate('05:59:59'), true, 'seconds within range');
});
method('isUTC', function() {
var d = new Date(1998, 0);
test(d, d.getTimezoneOffset() === 0, 'UTC is true if the current timezone has no offset');
d = run(d, 'clone');
d = run(d, 'addMinutes', [d.getTimezoneOffset()]);
test(d, d.getTimezoneOffset() === 0, 'UTC cannot be forced');
// UTC is still false even if the time is reset to the intended utc equivalent, as timezones can never be changed
dateEqual(run(Date, 'create'), new Date(), 'empty');
});
group('Create | Enumerated Parameters', function() {
dateEqual(testCreateDate(1998), new Date(1998), '1998');
dateEqual(testCreateDate(1998,1), new Date(1998,1), 'January, 1998');
dateEqual(testCreateDate(1998,1,23), new Date(1998,1,23), 'January 23, 1998');
dateEqual(testCreateDate(1998,1,23,11), new Date(1998,1,23,11), 'January 23, 1998 11am');
dateEqual(testCreateDate(1998,1,23,11,54), new Date(1998,1,23,11,54), 'January 23, 1998 11:54am');
dateEqual(testCreateDate(1998,1,23,11,54,32), new Date(1998,1,23,11,54,32), 'January 23, 1998 11:54:32');
dateEqual(testCreateDate(1998,1,23,11,54,32,454), new Date(1998,1,23,11,54,32,454), 'January 23, 1998 11:54:32.454');
dateEqual(testCreateDate('1998', true), new Date(1998, 0), 'will not choke on a boolean as second param');
dateEqual(testCreateDate('1998', ''), new Date(1998, 0), 'will not choke on an empty string as second param');
});
group('Create | Objects', function() {
dateEqual(testCreateDate({ year: 1998 }), new Date(1998, 0), '1998');
dateEqual(testCreateDate({ year: 1998, month: 1 }), new Date(1998,1), 'January, 1998');
dateEqual(testCreateDate({ year: 1998, month: 1, day: 23 }), new Date(1998,1,23), 'January 23, 1998');
dateEqual(testCreateDate({ year: 1998, month: 1, day: 23, hour: 11 }), new Date(1998,1,23,11), 'January 23, 1998 11am');
dateEqual(testCreateDate({ year: 1998, month: 1, day: 23, hour: 11, minutes: 54 }), new Date(1998,1,23,11,54), 'January 23, 1998 11:54am');
dateEqual(testCreateDate({ year: 1998, month: 1, day: 23, hour: 11, minutes: 54, seconds: 32 }), new Date(1998,1,23,11,54,32), 'January 23, 1998 11:54:32');
dateEqual(testCreateDate({ year: 1998, month: 1, day: 23, hour: 11, minutes: 54, seconds: 32, milliseconds: 454 }), new Date(1998,1,23,11,54,32,454), 'January 23, 1998 11:54:32.454');
});
group('Create | Timestamps', function() {
var timestamp = 1294012800000;
var d = testCreateDate(timestamp); // 2011-01-03 00:00:00
equal(d.getFullYear(), 2011, '2011')
equal(d.getMonth(), 0, 'is January');
equal(d.getDate(), Math.floor(3 - (d.getTimezoneOffset() / 60 / 24)), 'is the 3rd');
equal(d.getTime(), timestamp, 'is exact');
});
group('Create | Simple', function() {
dateEqual(testCreateDate('1999'), new Date(1999, 0), 'Just the year');
dateEqual(testCreateDate('June'), new Date(thisYear, 5), 'Just the month');
dateEqual(testCreateDate('June 15'), new Date(thisYear, 5, 15), 'Month and day');
dateEqual(testCreateDate('June 15th'), new Date(thisYear, 5, 15), 'Month and ordinal day');
});
group('Create | American Style Slashes', function() {
dateEqual(testCreateDate('08/25'), new Date(thisYear, 7, 25), 'mm/dd');
dateEqual(testCreateDate('8/25'), new Date(thisYear, 7, 25), 'm/dd');
dateEqual(testCreateDate('08/25/1978'), new Date(1978, 7, 25), 'mm/dd/yyyy');
dateEqual(testCreateDate('8/25/1978'), new Date(1978, 7, 25), '/m/dd/yyyy');
dateEqual(testCreateDate('8/25/78'), new Date(1978, 7, 25), 'm/dd/yy');
dateEqual(testCreateDate('08/25/78'), new Date(1978, 7, 25), 'mm/dd/yy');
dateEqual(testCreateDate('8/25/01'), new Date(2001, 7, 25), 'm/dd/01');
dateEqual(testCreateDate('8/25/49'), new Date(2049, 7, 25), 'm/dd/49');
dateEqual(testCreateDate('8/25/50'), new Date(1950, 7, 25), 'm/dd/50');
// Abbreviated reverse slash format yy/mm/dd cannot exist because it clashes with forward
// slash format dd/mm/yy (with european variant). This rule however, doesn't follow for dashes,
// which is abbreviated ISO8601 format: yy-mm-dd
dateEqual(testCreateDate('01/02/03'), new Date(2003, 0, 2), 'Ambiguous 2 digit format mm/dd/yy');
var d = testCreateDate('08/25/0001');
d = new Date(d.getTime() - (d.getTimezoneOffset() * 60 * 1000));
dateEqual(d, new Date(-62115206400000), 'mm/dd/0001');
});
group('Create | American Style Dashes', function() {
dateEqual(testCreateDate('08-25-1978'), new Date(1978, 7, 25), 'mm-dd-yyyy');
dateEqual(testCreateDate('8-25-1978'), new Date(1978, 7, 25), 'm-dd-yyyy');
// dd-dd-dd is NOT a valid ISO 8601 representation as of 2004, hence this format will
// revert to a little endian representation, where year truncation is allowed. See:
// http://en.wikipedia.org/wiki/ISO_8601#Truncated_representations
dateEqual(testCreateDate('08-05-05'), new Date(2005, 7, 5), 'dd-dd-dd is an ISO8601 format');
dateEqual(testCreateDate('06-2008'), new Date(2008, 5), 'Date#create | Full text | mm-yyyy');
dateEqual(testCreateDate('6-2008'), new Date(2008, 5), 'Date#create | Full text | m-yyyy');
});
group('Create | American Style Dots', function() {
dateEqual(testCreateDate('08.25.1978'), new Date(1978, 7, 25), 'mm.dd.yyyy');
dateEqual(testCreateDate('8.25.1978'), new Date(1978, 7, 25), 'm.dd.yyyy');
});
group('Create | European Style', function() {
dateEqual(testCreateDate('08/10', 'en-GB'), new Date(thisYear, 9, 8), 'dd/mm');
dateEqual(testCreateDate('8/10', 'en-GB'), new Date(thisYear, 9, 8), 'd/mm');
dateEqual(testCreateDate('08/10/1978', 'en-GB'), new Date(1978, 9, 8), 'dd/mm/yyyy');
dateEqual(testCreateDate('8/10/1978', 'en-GB'), new Date(1978, 9, 8), 'd/mm/yyyy');
dateEqual(testCreateDate('8/10/78', 'en-GB'), new Date(1978, 9, 8), 'd/mm/yy');
dateEqual(testCreateDate('08/10/78', 'en-GB'), new Date(1978, 9, 8), 'dd/mm/yy');
dateEqual(testCreateDate('8/10/01', 'en-GB'), new Date(2001, 9, 8), 'd/mm/01');
dateEqual(testCreateDate('8/10/49', 'en-GB'), new Date(2049, 9, 8), 'd/mm/49');
dateEqual(testCreateDate('8/10/50', 'en-GB'), new Date(1950, 9, 8), 'd/mm/50');
dateEqual(testCreateDate('08/10', 'en-AU'), new Date(thisYear, 9, 8), 'any English locale suffix should work and not use US format');
// Dashes
dateEqual(testCreateDate('08-10-1978', 'en-GB'), new Date(1978, 9, 8), 'mm-dd-yyyy');
// Dots
dateEqual(testCreateDate('08.10.1978', 'en-GB'), new Date(1978, 9, 8), 'dd.mm.yyyy');
dateEqual(testCreateDate('8.10.1978', 'en-GB'), new Date(1978, 9, 8), 'd.mm.yyyy');
dateEqual(testCreateDate('08-05-05', 'en-GB'), new Date(2005, 4, 8), 'dd-dd-dd is NOT an ISO8601 format');
dateEqual(testCreateDate('8/10/85'), new Date(1985, 7, 10), 'American format will now revert back');
testSetLocale('en-GB');
dateEqual(testCreateDate('8/10/85'), new Date(1985, 9, 8), 'after global set');
testSetLocale('en');
dateEqual(testCreateDate('8/10/85'), new Date(1985, 7, 10), 'before global reset');
});
group('Create | IETF', function() {
// Stolen with love from XDate
dateEqual(testCreateDate('Mon Sep 05 2011 12:30:00 GMT-0700 (PDT)'), getUTCDate(2011,9,5,19,30));
});
group('Create | Reverse Full Slashes', function() {
// Slashes
dateEqual(testCreateDate('1978/08/25'), new Date(1978, 7, 25), 'yyyy/mm/dd');
dateEqual(testCreateDate('1978/8/25'), new Date(1978, 7, 25), 'yyyy/m/dd');
dateEqual(testCreateDate('1978/08'), new Date(1978, 7), 'yyyy/mm');
dateEqual(testCreateDate('1978/8'), new Date(1978, 7), 'yyyy/m');
// Dashes
dateEqual(testCreateDate('1978-08-25'), new Date(1978, 7, 25), 'yyyy-mm-dd');
dateEqual(testCreateDate('1978-08'), new Date(1978, 7), 'yyyy-mm');
dateEqual(testCreateDate('1978-8'), new Date(1978, 7), 'yyyy-m');
// Dots
dateEqual(testCreateDate('1978.08.25'), new Date(1978, 7, 25), 'yyyy.mm.dd');
dateEqual(testCreateDate('1978.08'), new Date(1978, 7), 'yyyy.mm');
dateEqual(testCreateDate('1978.8'), new Date(1978, 7), 'yyyy.m');
dateEqual(testCreateDate('01-02-03', 'en-GB'), new Date(2003, 1, 1), 'Ambiguous 2 digit variant yy-mm-dd is NOT ISO 8601');
dateEqual(testCreateDate('01/02/03', 'en-GB'), new Date(2003, 1, 1), 'Ambiguous 2 digit European variant dd/mm/yy');
});
group('Create | Text Month', function() {
dateEqual(testCreateDate('June 2008'), new Date(2008, 5), 'Month yyyy');
dateEqual(testCreateDate('June-2008'), new Date(2008, 5), 'Month-yyyy');
dateEqual(testCreateDate('June.2008'), new Date(2008, 5), 'Month.yyyy');
dateEqual(testCreateDate('June 1st, 2008'), new Date(2008, 5, 1), 'Month 1st, yyyy');
dateEqual(testCreateDate('June 2nd, 2008'), new Date(2008, 5, 2), 'Month 2nd, yyyy');
dateEqual(testCreateDate('June 3rd, 2008'), new Date(2008, 5, 3), 'Month 3rd, yyyy');
dateEqual(testCreateDate('June 4th, 2008'), new Date(2008, 5, 4), 'Month 4th, yyyy');
dateEqual(testCreateDate('June 15th, 2008'), new Date(2008, 5, 15), 'Month 15th, yyyy');
dateEqual(testCreateDate('June 1st 2008'), new Date(2008, 5, 1), 'Month 1st yyyy');
dateEqual(testCreateDate('June 2nd 2008'), new Date(2008, 5, 2), 'Month 2nd yyyy');
dateEqual(testCreateDate('June 3rd 2008'), new Date(2008, 5, 3), 'Month 3rd yyyy');
dateEqual(testCreateDate('June 4th 2008'), new Date(2008, 5, 4), 'Month 4th yyyy');
dateEqual(testCreateDate('June 15, 2008'), new Date(2008, 5, 15), 'Month dd, yyyy');
dateEqual(testCreateDate('June 15 2008'), new Date(2008, 5, 15), 'Month dd yyyy');
dateEqual(testCreateDate('15 July, 2008'), new Date(2008, 6, 15), 'dd Month, yyyy');
dateEqual(testCreateDate('15 July 2008'), new Date(2008, 6, 15), 'dd Month yyyy');
dateEqual(testCreateDate('juNe 1St 2008'), new Date(2008, 5, 1), 'Month 1st yyyy case insensitive');
});
group('Create | Special Cases', function() {
dateEqual(testCreateDate(' July 4th, 1987 '), new Date(1987, 6, 4), 'Untrimmed full text');
dateEqual(testCreateDate(' 7/4/1987 '), new Date(1987, 6, 4), 'Untrimmed American');
dateEqual(testCreateDate(' 1987-07-04 '), new Date(1987, 6, 4), 'Untrimmed ISO8601');
});
group('Create | Abbreviated Formats', function() {
dateEqual(testCreateDate('Dec 1st, 2008'), new Date(2008, 11, 1), 'without dot');
dateEqual(testCreateDate('Dec. 1st, 2008'), new Date(2008, 11, 1), 'with dot');
dateEqual(testCreateDate('1 Dec. 2008'), new Date(2008, 11, 1), 'reversed with dot');
dateEqual(testCreateDate('1 Dec., 2008'), new Date(2008, 11, 1), 'reversed with dot and comma');
dateEqual(testCreateDate('1 Dec, 2008'), new Date(2008, 11, 1), 'reversed with comma and no dot');
});
group('Create | Abbreviated with Text Month', function() {
dateEqual(testCreateDate('09-May-78'), new Date(1978, 4, 9), 'Little Endian | yy');
dateEqual(testCreateDate('09-May-1978'), new Date(1978, 4, 9), 'Little Endian | yyyy');
dateEqual(testCreateDate('1978-May-09'), new Date(1978, 4, 9), '');
dateEqual(testCreateDate('Wednesday July 3rd, 2008'), new Date(2008, 6, 3), 'With day of week');
dateEqual(testCreateDate('Wed July 3rd, 2008'), new Date(2008, 6, 3), 'With day of week abbreviated');
dateEqual(testCreateDate('Wed. July 3rd, 2008'), new Date(2008, 6, 3), 'With day of week abbreviated plus dot');
dateEqual(testCreateDate('Wed, 03 Jul 2008 08:00:00 EST'), new Date(Date.UTC(2008, 6, 3, 13)), 'RFC822');
});
group('Create | ISO8601', function() {
dateEqual(testCreateDate('2001-1-1'), new Date(2001, 0, 1), 'not padded');
dateEqual(testCreateDate('2001-01-1'), new Date(2001, 0, 1), 'month padded');
dateEqual(testCreateDate('2001-01-01'), new Date(2001, 0, 1), 'month and day padded');
dateEqual(testCreateDate('2010-11-22'), new Date(2010, 10, 22), 'month and day padded 2010');
dateEqual(testCreateDate('20101122'), new Date(2010, 10, 22), 'digits strung together');
dateEqual(testCreateDate('17760523T024508+0830'), getUTCDate(1776,5,22,18,15,08), 'full datetime strung together');
dateEqual(testCreateDate('-0002-07-26'), new Date(-2, 6, 26), 'minus sign (bc)'); // BC
dateEqual(testCreateDate('+1978-04-17'), new Date(1978, 3, 17), 'plus sign (ad)'); // AD
});
group('Create | Date and Time', function() {
dateEqual(testCreateDate('08/25/1978 12:04'), new Date(1978, 7, 25, 12, 4), 'Slash format');
dateEqual(testCreateDate('08-25-1978 12:04'), new Date(1978, 7, 25, 12, 4), 'Dash format');
dateEqual(testCreateDate('1978/08/25 12:04'), new Date(1978, 7, 25, 12, 4), 'Reverse slash format');
dateEqual(testCreateDate('June 1st, 2008 12:04'), new Date(2008, 5, 1, 12, 4), 'Full text format');
dateEqual(testCreateDate('08-25-1978 12:04:57'), new Date(1978, 7, 25, 12, 4, 57), 'with seconds');
dateEqual(testCreateDate('08-25-1978 12:04:57.322'), new Date(1978, 7, 25, 12, 4, 57, 322), 'with milliseconds');
dateEqual(testCreateDate('08-25-1978 12pm'), new Date(1978, 7, 25, 12), 'with am/pm');
dateEqual(testCreateDate('08-25-1978 12:42pm'), new Date(1978, 7, 25, 12, 42), 'with minutes and am/pm');
dateEqual(testCreateDate('08-25-1978 12:42:32pm'), new Date(1978, 7, 25, 12, 42, 32), 'with seconds and am/pm');
dateEqual(testCreateDate('08-25-1978 12:42:32.488pm'), new Date(1978, 7, 25, 12, 42, 32, 488), 'with seconds and am/pm');
dateEqual(testCreateDate('08-25-1978 00:00am'), new Date(1978, 7, 25, 0, 0, 0, 0), 'with zero am');
dateEqual(testCreateDate('08-25-1978 00:00:00am'), new Date(1978, 7, 25, 0, 0, 0, 0), 'with seconds and zero am');
dateEqual(testCreateDate('08-25-1978 00:00:00.000am'), new Date(1978, 7, 25, 0, 0, 0, 0), 'with milliseconds and zero am');
dateEqual(testCreateDate('08-25-1978 1pm'), new Date(1978, 7, 25, 13), '1pm am/pm');
dateEqual(testCreateDate('08-25-1978 1:42pm'), new Date(1978, 7, 25, 13, 42), '1pm minutes and am/pm');
dateEqual(testCreateDate('08-25-1978 1:42:32pm'), new Date(1978, 7, 25, 13, 42, 32), '1pm seconds and am/pm');
dateEqual(testCreateDate('08-25-1978 1:42:32.488pm'), new Date(1978, 7, 25, 13, 42, 32, 488), '1pm seconds and am/pm');
dateEqual(testCreateDate('08-25-1978 1am'), new Date(1978, 7, 25, 1), '1am am/pm');
dateEqual(testCreateDate('08-25-1978 1:42am'), new Date(1978, 7, 25, 1, 42), '1am minutes and am/pm');
dateEqual(testCreateDate('08-25-1978 1:42:32am'), new Date(1978, 7, 25, 1, 42, 32), '1am seconds and am/pm');
dateEqual(testCreateDate('08-25-1978 1:42:32.488am'), new Date(1978, 7, 25, 1, 42, 32, 488), '1am seconds and am/pm');
dateEqual(testCreateDate('08-25-1978 11pm'), new Date(1978, 7, 25, 23), '11pm am/pm');
dateEqual(testCreateDate('08-25-1978 11:42pm'), new Date(1978, 7, 25, 23, 42), '11pm minutes and am/pm');
dateEqual(testCreateDate('08-25-1978 11:42:32pm'), new Date(1978, 7, 25, 23, 42, 32), '11pm seconds and am/pm');
dateEqual(testCreateDate('08-25-1978 11:42:32.488pm'), new Date(1978, 7, 25, 23, 42, 32, 488), '11pm seconds and am/pm');
dateEqual(testCreateDate('08-25-1978 11am'), new Date(1978, 7, 25, 11), '11am am/pm');
dateEqual(testCreateDate('08-25-1978 11:42am'), new Date(1978, 7, 25, 11, 42), '11am minutes and am/pm');
dateEqual(testCreateDate('08-25-1978 11:42:32am'), new Date(1978, 7, 25, 11, 42, 32), '11am seconds and am/pm');
dateEqual(testCreateDate('08-25-1978 11:42:32.488am'), new Date(1978, 7, 25, 11, 42, 32, 488), '11am seconds and am/pm');
});
group('Create | ISO8601', function() {
dateEqual(testCreateDate('2010-11-22T22:59Z'), getUTCDate(2010,11,22,22,59), 'full with UTC timezone');
dateEqual(testCreateDate('1997-07-16T19:20+00:00'), getUTCDate(1997, 7, 16, 19, 20), 'zero minutes with timezone');
dateEqual(testCreateDate('1997-07-16T19:20+01:00'), getUTCDate(1997, 7, 16, 18, 20), 'minutes with timezone');
dateEqual(testCreateDate('1997-07-16T19:20:30+01:00'), getUTCDate(1997, 7, 16, 18, 20, 30), 'seconds with timezone');
dateEqual(testCreateDate('1997-07-16T19:20:30.45+01:00'), getUTCDate(1997, 7, 16, 18, 20, 30, 450), 'milliseconds with timezone');
dateEqual(testCreateDate('1994-11-05T08:15:30-05:00'), getUTCDate(1994, 11, 5, 13, 15, 30), 'Full example 1');
dateEqual(testCreateDate('1994-11-05T13:15:30Z'), getUTCDate(1994, 11, 5, 13, 15, 30), 'Full example 1');
equal(testCreateDate('1994-11-05T13:15:30Z')._utc, false, 'does not forcefully set UTC flag');
dateEqual(testCreateDate('1776-05-23T02:45:08-08:30'), getUTCDate(1776, 5, 23, 11, 15, 08), 'Full example 3');
dateEqual(testCreateDate('1776-05-23T02:45:08+08:30'), getUTCDate(1776, 5, 22, 18, 15, 08), 'Full example 4');
dateEqual(testCreateDate('1776-05-23T02:45:08-0830'), getUTCDate(1776, 5, 23, 11, 15, 08), 'Full example 5');
dateEqual(testCreateDate('1776-05-23T02:45:08+0830'), getUTCDate(1776, 5, 22, 18, 15, 08), 'Full example 6');
// No limit on the number of millisecond decimals, so....
dateEqual(testCreateDate('1997-07-16T19:20:30.4+01:00'), getUTCDate(1997, 7, 16, 18, 20, 30, 400), 'milliseconds have no limit 1');
dateEqual(testCreateDate('1997-07-16T19:20:30.46+01:00'), getUTCDate(1997, 7, 16, 18, 20, 30, 460), 'milliseconds have no limit 2');
dateEqual(testCreateDate('1997-07-16T19:20:30.462+01:00'), getUTCDate(1997, 7, 16, 18, 20, 30, 462), 'milliseconds have no limit 3');
dateEqual(testCreateDate('1997-07-16T19:20:30.4628+01:00'), getUTCDate(1997, 7, 16, 18, 20, 30, 463), 'milliseconds have no limit 4');
dateEqual(testCreateDate('1997-07-16T19:20:30.46284+01:00'), getUTCDate(1997, 7, 16, 18, 20, 30, 463), 'milliseconds have no limit 5');
// .NET output
dateEqual(testCreateDate('2012-04-23T07:58:42.7940000z'), getUTCDate(2012, 4, 23, 7, 58, 42, 794), '.NET long format');
// Fractions in ISO8601 dates
dateEqual(testCreateDate('1997-07-16T14:30:40.5'), new Date(1997, 6, 16, 14, 30, 40, 500), 'fractions in seconds');
dateEqual(testCreateDate('1997-07-16T14:30.5'), new Date(1997, 6, 16, 14, 30, 30), 'fractions in minutes');
// Comma based fractions in ISO8601 dates
dateEqual(testCreateDate('1997-07-16T14:30:40,5'), new Date(1997, 6, 16, 14, 30, 40, 500), 'fractions in seconds');
dateEqual(testCreateDate('1997-07-16T14:30,5'), new Date(1997, 6, 16, 14, 30, 30), 'fractions in minutes');
// Fractional hours in ISO dates
dateEqual(testCreateDate('1997-07-16T14.5'), new Date(1997, 6, 16, 14, 30), 'fractions in hours');
dateEqual(testCreateDate('1997-07-16T14,5'), new Date(1997, 6, 16, 14, 30), 'fractions in hours');
// These are all the same moment...
dateEqual(testCreateDate('2001-04-03T18:30Z'), getUTCDate(2001,4,3,18,30), 'Synonymous dates with timezone 1');
dateEqual(testCreateDate('2001-04-03T22:30+04'), getUTCDate(2001,4,3,18,30), 'Synonymous dates with timezone 2');
dateEqual(testCreateDate('2001-04-03T1130-0700'), getUTCDate(2001,4,3,18,30), 'Synonymous dates with timezone 3');
dateEqual(testCreateDate('2001-04-03T15:00-03:30'), getUTCDate(2001,4,3,18,30), 'Synonymous dates with timezone 4');
// Time
dateEqual(testCreateDate('1pm'), new Date(now.getFullYear(), now.getMonth(), now.getDate(), 13), '1pm');
dateEqual(testCreateDate('1:30pm'), new Date(now.getFullYear(), now.getMonth(), now.getDate(), 13, 30), '1:30pm');
dateEqual(testCreateDate('1:30:22pm'), new Date(now.getFullYear(), now.getMonth(), now.getDate(), 13, 30, 22), '1:30:22pm');
dateEqual(testCreateDate('1:30:22.432pm'), new Date(now.getFullYear(), now.getMonth(), now.getDate(), 13, 30, 22, 432), '1:30:22.432pm');
dateEqual(testCreateDate('17:48:03.947'), new Date(now.getFullYear(), now.getMonth(), now.getDate(), 17, 48, 3, 947), '17:48:03.947');
});
group('Create | .NET JSON', function() {
dateEqual(testCreateDate('\/Date(628318530718)\/'), new Date(628318530718), 'basic');
dateEqual(testCreateDate('\/Date(1318287600+0100)\/'), new Date(1318287600), '+ date format with timezone');
dateEqual(testCreateDate('\/Date(1318287600-0700)\/'), new Date(1318287600), '- date format with timezone');
});
group('Create | Fuzzy Dates', function() {
dateEqual(testCreateDate('now'), new Date(), 'now');
dateEqual(testCreateDate('Now'), new Date(), 'Now');
dateEqual(testCreateDate('Just now'), new Date(), 'Just Now');
dateEqual(testCreateDate('today'), new Date(now.getFullYear(), now.getMonth(), now.getDate()), 'today');
dateEqual(testCreateDate('Today'), new Date(now.getFullYear(), now.getMonth(), now.getDate()), 'Today');
dateEqual(testCreateDate('yesterday'), new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1), 'yesterday');
dateEqual(testCreateDate('Yesterday'), new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1), 'Yesterday');
dateEqual(testCreateDate('tomorrow'), new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1), 'tomorrow');
dateEqual(testCreateDate('Tomorrow'), new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1), 'Tomorrow');
dateEqual(testCreateDate('4pm'), new Date(now.getFullYear(), now.getMonth(), now.getDate(), 16), '4pm');
dateEqual(testCreateDate('today at 4pm'), new Date(now.getFullYear(), now.getMonth(), now.getDate(), 16), 'Today at 4pm');
dateEqual(testCreateDate('today at 4 pm'), new Date(now.getFullYear(), now.getMonth(), now.getDate(), 16), 'Today at 4 pm');
dateEqual(testCreateDate('4pm today'), new Date(now.getFullYear(), now.getMonth(), now.getDate(), 16), '4pm today');
dateEqual(testCreateDate('The day after tomorrow'), new Date(now.getFullYear(), now.getMonth(), now.getDate() + 2), 'The day after tomorrow');
dateEqual(testCreateDate('The day before yesterday'), new Date(now.getFullYear(), now.getMonth(), now.getDate() - 2), 'The day before yesterday');
dateEqual(testCreateDate('One day after tomorrow'), new Date(now.getFullYear(), now.getMonth(), now.getDate() + 2), 'One day after tomorrow');
dateEqual(testCreateDate('One day before yesterday'), new Date(now.getFullYear(), now.getMonth(), now.getDate() - 2), 'One day before yesterday');
dateEqual(testCreateDate('Two days after tomorrow'), new Date(now.getFullYear(), now.getMonth(), now.getDate() + 3), 'Two days after tomorrow');
dateEqual(testCreateDate('Two days before yesterday'), new Date(now.getFullYear(), now.getMonth(), now.getDate() - 3), 'Two days before yesterday');
dateEqual(testCreateDate('Two days after today'), new Date(now.getFullYear(), now.getMonth(), now.getDate() + 2), 'Two days after today');
dateEqual(testCreateDate('Two days before today'), new Date(now.getFullYear(), now.getMonth(), now.getDate() - 2), 'Two days before today');
dateEqual(testCreateDate('Two days from today'), new Date(now.getFullYear(), now.getMonth(), now.getDate() + 2), 'Two days from today');
dateEqual(testCreateDate('tWo dAyS after toMoRRoW'), new Date(now.getFullYear(), now.getMonth(), now.getDate() + 3), 'tWo dAyS after toMoRRoW');
dateEqual(testCreateDate('2 days after tomorrow'), new Date(now.getFullYear(), now.getMonth(), now.getDate() + 3), '2 days after tomorrow');
dateEqual(testCreateDate('2 day after tomorrow'), new Date(now.getFullYear(), now.getMonth(), now.getDate() + 3), '2 day after tomorrow');
dateEqual(testCreateDate('18 days after tomorrow'), new Date(now.getFullYear(), now.getMonth(), now.getDate() + 19), '18 days after tomorrow');
dateEqual(testCreateDate('18 day after tomorrow'), new Date(now.getFullYear(), now.getMonth(), now.getDate() + 19), '18 day after tomorrow');
dateEqual(testCreateDate('2 years ago'), getRelativeDate(-2), '2 years ago');
dateEqual(testCreateDate('2 months ago'), getRelativeDate(null, -2), '2 months ago');
dateEqual(testCreateDate('2 weeks ago'), getRelativeDate(null, null, -14), '2 weeks ago');
dateEqual(testCreateDate('2 days ago'), getRelativeDate(null, null, -2), '2 days ago');
dateEqual(testCreateDate('2 hours ago'), getRelativeDate(null, null, null, -2), '2 hours ago');
dateEqual(testCreateDate('2 minutes ago'), getRelativeDate(null, null, null, null, -2), '2 minutes ago');
dateEqual(testCreateDate('2 seconds ago'), getRelativeDate(null, null, null, null, null, -2), '2 seconds ago');
dateEqual(testCreateDate('2 milliseconds ago'), getRelativeDate(null, null, null, null, null, null, -2), '2 milliseconds ago');
dateEqual(testCreateDate('a second ago'), getRelativeDate(null, null, null, null, null, -1), 'a second ago');
dateEqual(testCreateDate('2 years from now'), getRelativeDate(2), '2 years from now');
dateEqual(testCreateDate('2 months from now'), getRelativeDate(null, 2), '2 months from now');
dateEqual(testCreateDate('2 weeks from now'), getRelativeDate(null, null, 14), '2 weeks from now');
dateEqual(testCreateDate('2 days from now'), getRelativeDate(null, null, 2), '2 days from now');
dateEqual(testCreateDate('2 hours from now'), getRelativeDate(null, null, null, 2), '2 hours from now');
dateEqual(testCreateDate('2 minutes from now'), getRelativeDate(null, null, null, null, 2), '2 minutes from now');
dateEqual(testCreateDate('2 seconds from now'), getRelativeDate(null, null, null, null, null, 2), '2 seconds from now');
dateEqual(testCreateDate('2 milliseconds from now'), getRelativeDate(null, null, null, null, null, null, 2), '2 milliseconds from now');
dateEqual(testCreateDate('2 years later'), getRelativeDate(2), '2 years later');
dateEqual(testCreateDate('2 months later'), getRelativeDate(null, 2), '2 months later');
dateEqual(testCreateDate('2 weeks later'), getRelativeDate(null, null, 14), '2 weeks later');
dateEqual(testCreateDate('2 days later'), getRelativeDate(null, null, 2), '2 days later');
dateEqual(testCreateDate('2 hours later'), getRelativeDate(null, null, null, 2), '2 hours later');
dateEqual(testCreateDate('2 minutes later'), getRelativeDate(null, null, null, null, 2), '2 minutes later');
dateEqual(testCreateDate('2 seconds later'), getRelativeDate(null, null, null, null, null, 2), '2 seconds later');
dateEqual(testCreateDate('2 milliseconds later'), getRelativeDate(null, null, null, null, null, null, 2), '2 milliseconds later');
// Article trouble
dateEqual(testCreateDate('an hour ago'), getRelativeDate(null, null, null, -1), 'an hours ago');
dateEqual(testCreateDate('an hour from now'), getRelativeDate(null, null, null, 1), 'an hour from now');
dateEqual(testCreateDate('Monday'), getDateWithWeekdayAndOffset(1), 'Monday');
dateEqual(testCreateDate('The day after Monday'), getDateWithWeekdayAndOffset(2), 'The day after Monday');
dateEqual(testCreateDate('The day before Monday'), getDateWithWeekdayAndOffset(0), 'The day before Monday');
dateEqual(testCreateDate('2 days after monday'), getDateWithWeekdayAndOffset(3), '2 days after monday');
dateEqual(testCreateDate('2 days before monday'), getDateWithWeekdayAndOffset(6, -7), '2 days before monday');
dateEqual(testCreateDate('2 weeks after monday'), getDateWithWeekdayAndOffset(1, 14), '2 weeks after monday');
dateEqual(testCreateDate('Next Monday'), getDateWithWeekdayAndOffset(1, 7), 'Next Monday');
dateEqual(testCreateDate('next week monday'), getDateWithWeekdayAndOffset(1, 7), 'next week monday');
dateEqual(testCreateDate('Next friDay'), getDateWithWeekdayAndOffset(5, 7), 'Next friDay');
dateEqual(testCreateDate('next week thursday'), getDateWithWeekdayAndOffset(4, 7), 'next week thursday');
dateEqual(testCreateDate('last Monday'), getDateWithWeekdayAndOffset(1, -7), 'last Monday');
dateEqual(testCreateDate('last week monday'), getDateWithWeekdayAndOffset(1, -7), 'last week monday');
dateEqual(testCreateDate('last friDay'), getDateWithWeekdayAndOffset(5, -7), 'last friDay');
dateEqual(testCreateDate('last week thursday'), getDateWithWeekdayAndOffset(4, -7), 'last week thursday');
dateEqual(testCreateDate('last Monday at 4pm'), getDateWithWeekdayAndOffset(1, -7, 16), 'last Monday at 4pm');
dateEqual(testCreateDate('this Monday'), getDateWithWeekdayAndOffset(1, 0), 'this Monday');
dateEqual(testCreateDate('this week monday'), getDateWithWeekdayAndOffset(1, 0), 'this week monday');
dateEqual(testCreateDate('this friDay'), getDateWithWeekdayAndOffset(5, 0), 'this friDay');
dateEqual(testCreateDate('this week thursday'), getDateWithWeekdayAndOffset(4, 0), 'this week thursday');
dateEqual(testCreateDate('Monday of last week'), getDateWithWeekdayAndOffset(1, -7), 'Monday of last week');
dateEqual(testCreateDate('saturday of next week'), getDateWithWeekdayAndOffset(6, 7), 'saturday of next week');
dateEqual(testCreateDate('Monday last week'), getDateWithWeekdayAndOffset(1, -7), 'Monday last week');
dateEqual(testCreateDate('saturday next week'), getDateWithWeekdayAndOffset(6, 7), 'saturday next week');
dateEqual(testCreateDate('Monday of this week'), getDateWithWeekdayAndOffset(1, 0), 'Monday of this week');
dateEqual(testCreateDate('saturday of this week'), getDateWithWeekdayAndOffset(6, 0), 'saturday of this week');
dateEqual(testCreateDate('Monday this week'), getDateWithWeekdayAndOffset(1, 0), 'Monday this week');
dateEqual(testCreateDate('saturday this week'), getDateWithWeekdayAndOffset(6, 0), 'saturday this week');
dateEqual(testCreateDate('Tue of last week'), getDateWithWeekdayAndOffset(2, -7), 'Tue of last week');
dateEqual(testCreateDate('Tue. of last week'), getDateWithWeekdayAndOffset(2, -7), 'Tue. of last week');
dateEqual(testCreateDate('Next week'), getRelativeDate(null, null, 7), 'Next week');
dateEqual(testCreateDate('Last week'), getRelativeDate(null, null, -7), 'Last week');
dateEqual(testCreateDate('Next month'), getRelativeDate(null, 1), 'Next month');
dateEqual(testCreateDate('Next year'), getRelativeDate(1), 'Next year');
dateEqual(testCreateDate('this year'), getRelativeDate(0), 'this year');
dateEqual(testCreateDate('beginning of the week'), getDateWithWeekdayAndOffset(0), 'beginning of the week');
dateEqual(testCreateDate('beginning of this week'), getDateWithWeekdayAndOffset(0), 'beginning of this week');
dateEqual(testCreateDate('end of this week'), getDateWithWeekdayAndOffset(6, 0, 23, 59, 59, 999), 'end of this week');
dateEqual(testCreateDate('beginning of next week'), getDateWithWeekdayAndOffset(0, 7), 'beginning of next week');
dateEqual(testCreateDate('the beginning of next week'), getDateWithWeekdayAndOffset(0, 7), 'the beginning of next week');
dateEqual(testCreateDate('beginning of the month'), new Date(now.getFullYear(), now.getMonth()), 'beginning of the month');
dateEqual(testCreateDate('beginning of this month'), new Date(now.getFullYear(), now.getMonth()), 'beginning of this month');
dateEqual(testCreateDate('beginning of next month'), new Date(now.getFullYear(), now.getMonth() + 1), 'beginning of next month');
dateEqual(testCreateDate('the beginning of next month'), new Date(now.getFullYear(), now.getMonth() + 1), 'the beginning of next month');
dateEqual(testCreateDate('the end of next month'), new Date(now.getFullYear(), now.getMonth() + 1, testGetDaysInMonth(now.getFullYear(), now.getMonth() + 1), 23, 59, 59, 999), 'the end of next month');
dateEqual(testCreateDate('the end of the month'), new Date(now.getFullYear(), now.getMonth(), testGetDaysInMonth(now.getFullYear(), now.getMonth()), 23, 59, 59, 999), 'the end of the month');
dateEqual(testCreateDate('the beginning of the year'), new Date(now.getFullYear(), 0), 'the beginning of the year');
dateEqual(testCreateDate('the beginning of this year'), new Date(now.getFullYear(), 0), 'the beginning of this year');
dateEqual(testCreateDate('the beginning of next year'), new Date(now.getFullYear() + 1, 0), 'the beginning of next year');
dateEqual(testCreateDate('the beginning of last year'), new Date(now.getFullYear() - 1, 0), 'the beginning of last year');
dateEqual(testCreateDate('the end of next year'), new Date(now.getFullYear() + 1, 11, 31, 23, 59, 59, 999), 'the end of next year');
dateEqual(testCreateDate('the end of last year'), new Date(now.getFullYear() - 1, 11, 31, 23, 59, 59, 999), 'the end of last year');
dateEqual(testCreateDate('the beginning of the day'), new Date(now.getFullYear(), now.getMonth(), now.getDate()), 'the beginning of the day');
dateEqual(testCreateDate('beginning of March'), new Date(now.getFullYear(), 2), 'beginning of March');
dateEqual(testCreateDate('end of March'), new Date(now.getFullYear(), 2, 31, 23, 59, 59, 999), 'end of March');
dateEqual(testCreateDate('the first day of March'), new Date(now.getFullYear(), 2), 'the first day of March');
dateEqual(testCreateDate('the last day of March'), new Date(now.getFullYear(), 2, 31), 'the last day of March');
dateEqual(testCreateDate('the last day of March 2010'), new Date(2010, 2, 31), 'the last day of March 2010');
dateEqual(testCreateDate('the last day of March, 2012'), new Date(2012, 2, 31), 'the last day of March, 2012');
dateEqual(testCreateDate('beginning of 1998'), new Date(1998, 0), 'beginning of 1998');
dateEqual(testCreateDate('end of 1998'), new Date(1998, 11, 31, 23, 59, 59, 999), 'end of 1998');
dateEqual(testCreateDate('the first day of 1998'), new Date(1998, 0), 'the first day of 1998');
dateEqual(testCreateDate('the last day of 1998'), new Date(1998, 11, 31), 'the last day of 1998');
dateEqual(testCreateDate('The 15th of last month.'), new Date(now.getFullYear(), now.getMonth() - 1, 15), 'The 15th of last month');
dateEqual(testCreateDate('January 30th of last year.'), new Date(now.getFullYear() - 1, 0, 30), 'January 30th of last year');
dateEqual(testCreateDate('January of last year.'), new Date(now.getFullYear() - 1, 0), 'January of last year');
dateEqual(testCreateDate('First day of may'), new Date(now.getFullYear(), 4, 1), 'First day of may');
dateEqual(testCreateDate('Last day of may'), new Date(now.getFullYear(), 4, 31), 'Last day of may');
dateEqual(testCreateDate('Last day of next month'), new Date(now.getFullYear(), now.getMonth() + 1, testGetDaysInMonth(now.getFullYear(), now.getMonth() + 1)), 'Last day of next month');
dateEqual(testCreateDate('Last day of november'), new Date(now.getFullYear(), 10, 30), 'Last day of november');
dateEqual(testCreateDate('the first day of next January'), new Date(now.getFullYear() + 1, 0, 1), 'the first day of next january');
dateEqual(testCreateDate('Next week'), getRelativeDate(null, null, 7), 'Next week');
dateEqual(testCreateDate('Thursday of next week, 3:30pm'), getDateWithWeekdayAndOffset(4, 7, 15, 30), 'thursday of next week, 3:30pm');
dateEqual(testCreateDate('the 2nd Tuesday of June, 2012'), new Date(2012, 5, 12), 'the 2nd tuesday of June, 2012');
dateEqual(testCreateDate('the 1st Tuesday of November, 2012'), new Date(2012, 10, 6), 'the 1st tuesday of November');
dateEqual(testCreateDate('the 2nd Tuesday of November, 2012'), new Date(2012, 10, 13), 'the 2nd tuesday of November');
dateEqual(testCreateDate('the 3rd Tuesday of November, 2012'), new Date(2012, 10, 20), 'the 3rd tuesday of November');
dateEqual(testCreateDate('the 4th Tuesday of November, 2012'), new Date(2012, 10, 27), 'the 4th tuesday of November');
dateEqual(testCreateDate('the 5th Tuesday of November, 2012'), new Date(2012, 11, 4), 'the 5th tuesday of November');
dateEqual(testCreateDate('the 6th Tuesday of November, 2012'), new Date(2012, 11, 11), 'the 6th tuesday of November');
dateEqual(testCreateDate('the 1st Friday of February, 2012'), new Date(2012, 1, 3), 'the 1st Friday of February');
dateEqual(testCreateDate('the 2nd Friday of February, 2012'), new Date(2012, 1, 10), 'the 2nd Friday of February');
dateEqual(testCreateDate('the 3rd Friday of February, 2012'), new Date(2012, 1, 17), 'the 3rd Friday of February');
dateEqual(testCreateDate('the 4th Friday of February, 2012'), new Date(2012, 1, 24), 'the 4th Friday of February');
dateEqual(testCreateDate('the 5th Friday of February, 2012'), new Date(2012, 2, 2), 'the 5th Friday of February');
dateEqual(testCreateDate('the 6th Friday of February, 2012'), new Date(2012, 2, 9), 'the 6th Friday of February');
var d = new Date(thisYear, 1);
while(d.getDay() !== 5) {
d.setDate(d.getDate() + 1);
}
equal(testCreateDate('the 1st Friday of February').getFullYear(), thisYear, '1st friday of February should be this year');
equal(testCreateFutureDate('the 1st Friday of February').getFullYear(), now > d ? thisYear + 1 : thisYear, '1st friday of February should be this year or next');
equal(testCreatePastDate('the 1st Friday of February').getFullYear(), now < d ? thisYear - 1 : thisYear, '1st friday of February should be this year or last');
dateEqual(testCreateDate('in 60 seconds'), getRelativeDate(null, null, null, null, 1), 'in 60 seconds');
dateEqual(testCreateDate('in 45 minutes'), getRelativeDate(null, null, null, null, 45), 'in 45 minutes');
dateEqual(testCreateDate('in 5 hours'), getRelativeDate(null, null, null, 5), 'in 5 hours');
dateEqual(testCreateDate('in 5 days'), getRelativeDate(null, null, 5), 'in 5 days');
dateEqual(testCreateDate('in 5 weeks'), getRelativeDate(null, null, 35), 'in 5 weeks');
dateEqual(testCreateDate('in 5 months'), getRelativeDate(null, 5), 'in 5 months');
dateEqual(testCreateDate('in 5 years'), getRelativeDate(5), 'in 5 years');
// Issue #203
dateEqual(testCreateDate('The day after tomorrow 3:45pm', 'en'), new Date(now.getFullYear(), now.getMonth(), now.getDate() + 2, 15, 45), 'The day after tomorrow at 3:45pm');
dateEqual(testCreateDate('The day before yesterday at 11:15am', 'en'), new Date(now.getFullYear(), now.getMonth(), now.getDate() - 2, 11, 15), 'the day before yesterday at 11:15am');
var d = new Date();
d.setDate(28);
d.setHours(0);
d.setMinutes(0);
d.setSeconds(0);
d.setMilliseconds(0);
dateEqual(testCreateDate('the 28th'), d, 'the 28th');
dateEqual(testCreateDate('28th'), d, '28th');
var d = new Date();
d.setMonth(0);
d.setDate(28);
d.setHours(0);
d.setMinutes(0);
d.setSeconds(0);
d.setMilliseconds(0);
dateEqual(testCreateDate('the 28th of January'), d, 'the 28th of January');
dateEqual(testCreateDate('28th of January'), d, '28th of January');
// Issue #310
dateEqual(testCreateDate('6:30pm in 1 day'), run(getRelativeDate(null, null, 1), 'set', [{hours:18,minutes:30}, true]), '6:30pm in 1 day');
dateEqual(testCreateDate('6:30pm in 3 days'), run(getRelativeDate(null, null, 3), 'set', [{hours:18,minutes:30}, true]), '6:30pm in 3 days');
dateEqual(testCreateDate('6:30pm in -3 days'), run(getRelativeDate(null, null, -3), 'set', [{hours:18,minutes:30}, true]), '6:30pm in -3 days');
dateEqual(testCreateDate('6:30pm 2 days ago'), run(getRelativeDate(null, null, -2), 'set', [{hours:18,minutes:30}, true]), '6:30pm in 2 days ago');
dateEqual(testCreateDate('21:00 in 2 weeks'), run(getRelativeDate(null, null, 14), 'set', [{hours:21}, true]), '21:00pm in 2 weeks');
dateEqual(testCreateDate('5:00am in a month'), run(getRelativeDate(null, 1), 'set', [{hours:5}, true]), '5:00am in a month');
dateEqual(testCreateDate('5am in a month'), run(getRelativeDate(null, 1), 'set', [{hours:5}, true]), '5am in a month');
dateEqual(testCreateDate('5:01am in a month'), run(getRelativeDate(null, 1), 'set', [{hours:5,minutes:1}, true]), '5:01am in a month');
equal(run(testCreateDate('5am in an hour'), 'isValid'), false, '5am in an hour is invalid');
equal(run(testCreateDate('5am in a minute'), 'isValid'), false, '5am in a minute is invalid');
// Issue #375 "end of yesterday"
dateEqual(testCreateDate('beginning of yesterday'), run(testCreateDate('yesterday'), 'beginningOfDay'), 'beginning of yesterday');
dateEqual(testCreateDate('end of yesterday'), run(testCreateDate('yesterday'), 'endOfDay'), 'end of yesterday');
dateEqual(testCreateDate('beginning of today'), run(testCreateDate('today'), 'beginningOfDay'), 'beginning of today');
dateEqual(testCreateDate('end of today'), run(testCreateDate('today'), 'endOfDay'), 'end of today');
dateEqual(testCreateDate('beginning of tomorrow'), run(testCreateDate('tomorrow'), 'beginningOfDay'), 'beginning of tomorrow');
dateEqual(testCreateDate('end of tomorrow'), run(testCreateDate('tomorrow'), 'endOfDay'), 'end of tomorrow');
// Issue #431 "ten minutes ago"
dateEqual(testCreateDate('ten minutes ago'), getRelativeDate(null, null, null, null, -10), 'ten minutes ago');
dateEqual(testCreateDate('ten minutes from now'), getRelativeDate(null, null, null, null, 10), 'ten minutes from now');
});
group('Create | UTC', function() {
dateEqual(runUTC('create', ['February 29, 2012 22:15:42', 'en']), new Date(Date.UTC(2012, 1, 29, 22, 15, 42)), 'full text');
dateEqual(runUTC('create', ['2012-05-31', 'en']), new Date(Date.UTC(2012, 4, 31)), 'dashed');
dateEqual(runUTC('create', ['1998-02-23 11:54:32', 'en']), new Date(Date.UTC(1998,1,23,11,54,32)), 'dashed with time');
dateEqual(runUTC('create', [{ year: 1998, month: 1, day: 23, hour: 11 }, 'en']), new Date(Date.UTC(1998,1,23,11)), 'params');
dateEqual(runUTC('create', ['08-25-1978 11:42:32.488am', 'en']), new Date(Date.UTC(1978, 7, 25, 11, 42, 32, 488)), 'full with ms');
dateEqual(runUTC('create', ['1994-11-05T13:15:30Z', 'en']), new Date(Date.UTC(1994, 10, 5, 13, 15, 30)), '"Z" is still utc');
dateEqual(runUTC('create', ['two days ago', 'en']), getRelativeDate(null, null, -2), 'relative dates are not UTC');
// New handling of UTC dates
var date1 = runUTC('create', ['2001-06-15', 'en']);
var date2 = new Date(2001, 5, 15);
date2.setTime(date2.getTime() - (date2.getTimezoneOffset() * 60 * 1000));
dateEqual(date1, date2, 'is equal to date with timezone subtracted');
equal(date1._utc, false, 'does not set internal flag');
var d = run(new Date(2001, 5, 15), 'setUTC', [true]);
equal(d._utc, true, 'sets internal flag');
dateEqual(d, new Date(2001, 5, 15), 'does not change date');
dateEqual(dateRun(d, 'beginningOfMonth'), new Date(Date.UTC(2001, 5, 1)), 'the beginning of the month');
dateEqual(dateRun(d, 'endOfMonth'), new Date(Date.UTC(2001, 5, 30, 23, 59, 59, 999)), 'the end of the month');
equal(run(d, 'minutesSince', [runUTC('create', ['2001-06-15', 'en'])]), d.getTimezoneOffset(), 'minutesSince is equal to the timezone offset');
equal(run(d, 'hoursSince', ['2001-6-14']), 24, 'hoursSince | does not actually shift time');
var d = run(testCreateDate('1 month ago'), 'setUTC', [true])
equal(run(d, 'isLastMonth'), true, 'isLastMonth');
var d = run(runUTC('create', ['2001-06-15', 'en']), 'setUTC', [true]);
equal(run(d, 'iso'), '2001-06-15T00:00:00.000Z', 'will properly be output in UTC');
equal(run(d, 'format', ['{tz}']), '+0000', 'format UTC date will have +0000 offset');
equal(run(d, 'getUTCOffset'), '+0000', 'getUTCOffset');
dateEqual(dateRun(d, 'advance', ['1 month']), new Date(Date.UTC(2001, 6, 15)), 'advancing');
equal(run(run(runUTC('create', ['2010-02-01', 'en']), 'setUTC', [true]), 'daysInMonth'), 28, 'should find correct days in month');
equal(run(run(runUTC('create', ['2000-01', 'en']), 'setUTC', [true]), 'isLeapYear'), true, 'isLeapYear accounts for utc dates');
var d = run(runUTC('create', ['2000-02-18 11:00pm', 'en']), 'setUTC', [true]);
equal(run(d, 'is', ['Friday', null, true]), true, 'is friday');
equal(run(d, 'isWeekday', [true]), true, 'friday isWeekday');
equal(run(d, 'is', ['2000-02-18', null, true]), true, 'friday full date');
equal(run(d, 'isAfter', [runUTC('create', ['2000-02-18 10:00pm', 'en'])]), true, 'isAfter');
equal(dateRun(d, 'reset'), new Date(Date.UTC(2000, 1, 18)), 'resetting');
var d = run(runUTC('create', ['2000-02-14', 'en']), 'setUTC', [true]);
equal(run(d, 'is', ['Monday', null, true]), true, 'is monday');
equal(run(d, 'isWeekday', [true]), true, 'monday is a weekday');
equal(run(d, 'is', ['2000-02-14', null, true]), true, 'monday full date');
equal(run(d, 'format'), 'February 14, 2000 12:00am', 'fomratting monday');
equal(run(d, 'full'), 'Monday February 14, 2000 12:00:00am', 'full format');
equal(run(d, 'long'), 'February 14, 2000 12:00am', 'long format');
equal(run(d, 'short'), 'February 14, 2000', 'short format');
equal(run(runUTC('create', ['1 minute ago', 'en']), 'relative'), '1 minute ago', 'relative dates are unaffected');
var d = run(run(new Date(2001, 5, 15), 'setUTC', [true]), 'setUTC', [false]);
equal(d._utc, false, 'utc flag can be set off');
// Issue #235
equal(run(run(run(testCreateDate(), 'setUTC', [true]), 'clone'), 'isUTC'), true, 'clone should preserve UTC');
equal(run(new Date(), 'clone')._utc, false, 'clone should never be UTC if flag not set');
equal(run(testCreateDate(run(new Date(), 'setUTC', [true])), 'isUTC'), true, 'create should preserve UTC');
var isCurrentlyGMT = new Date(2011, 0, 1).getTimezoneOffset() === 0;
equal(run(testCreateDate(new Date()), 'isUTC'), isCurrentlyGMT, 'non utc date should not have UTC flag');
// Issue #244
dateEqual(runUTC('create', ['0999']), new Date(Date.UTC(999, 0)), '3 digit year 999 should be equal to ISO8601');
dateEqual(runUTC('create', ['0123']), new Date(Date.UTC(123, 0)), '3 digit year 123 should be equal to ISO8601');
var d = run(runUTC('create', [2013, 0, 14]), 'setUTC', [true]);
run(d, 'set', [{week:1}]);
dateEqual(d, runUTC('create', [2012, 11, 31]), 'utc dates should not throw errors on week set');
});
group('Create | Other', function() {
// Issue #98: System time set to January 31st
dateEqual(testCreateDate('2011-09-01T05:00:00Z'), getUTCDate(2011, 9, 1, 5), 'text format');
// Issue #152 times should be allowed in front
dateEqual(testCreateDate('3:45 2012-3-15'), new Date(2012, 2, 15, 3, 45), 'time in the front');
dateEqual(testCreateDate('3:45pm 2012-3-15'), new Date(2012, 2, 15, 15, 45), 'big endian with time');
dateEqual(testCreateDate('3:45pm 3/15/2012'), new Date(2012, 2, 15, 15, 45), 'crazy endian slashes with time');
dateEqual(testCreateDate('3:45pm 3/4/2012', 'en-GB'), new Date(2012, 3, 3, 15, 45), 'little endian slashes with time');
// Issue #144 various time/date formats
var d = getDateWithWeekdayAndOffset(4);
d.setHours(15);
dateEqual(testCreateDate('6/30/2012 3:00 PM'), new Date(2012, 5, 30, 15), '6/30/2012 3:00 PM');
dateEqual(testCreateDate('Thursday at 3:00 PM'), d, 'Thursday at 3:00 PM');
dateEqual(testCreateDate('Thursday at 3:00PM'), d, 'Thursday at 3:00PM (no space)');
// Date.create should clone a date
var date1 = new Date(5000);
var date2 = testCreateDate(date1);
date1.setTime(10000);
notEqual(date1.getTime(), date2.getTime(), 'created date should not be affected');
// Simple 12:00am
equal(testCreateDate('12:00am').getHours(), 0, '12:00am hours should be 0');
equal(testCreateDate('12am').getHours(), 0, '12am hours should be 0');
// Issue #227
dateEqual(testCreateDate('0 January'), new Date(now.getFullYear() - 1, 11, 31), 'Date#addMonths | 0 January');
dateEqual(testCreateDate('1 January'), new Date(now.getFullYear(), 0, 1), 'Date#addMonths | 1 January');
dateEqual(testCreateDate('01 January'), new Date(now.getFullYear(), 0, 1), 'Date#addMonths | 01 January');
dateEqual(testCreateDate('15 January'), new Date(now.getFullYear(), 0, 15), 'Date#addMonths | 15 January');
dateEqual(testCreateDate('31 January'), new Date(now.getFullYear(), 0, 31), 'Date#addMonths | 31 January');
dateEqual(testCreateDate('1 Jan'), new Date(now.getFullYear(), 0, 1), 'Date#addMonths | 1 Jan');
dateEqual(testCreateDate('01 Jan'), new Date(now.getFullYear(), 0, 1), 'Date#addMonths | 01 Jan');
dateEqual(testCreateDate('15 Jan'), new Date(now.getFullYear(), 0, 15), 'Date#addMonths | 15 Jan');
dateEqual(testCreateDate('31 Jan'), new Date(now.getFullYear(), 0, 31), 'Date#addMonths | 31 Jan');
dateEqual(testCreateDate('0 July'), new Date(now.getFullYear(), 5, 30), 'Date#addMonths | 0 July');
dateEqual(testCreateDate('1 July'), new Date(now.getFullYear(), 6, 1), 'Date#addMonths | 1 July');
dateEqual(testCreateDate('01 July'), new Date(now.getFullYear(), 6, 1), 'Date#addMonths | 01 July');
dateEqual(testCreateDate('15 July'), new Date(now.getFullYear(), 6, 15), 'Date#addMonths | 15 July');
dateEqual(testCreateDate('31 July'), new Date(now.getFullYear(), 6, 31), 'Date#addMonths | 31 July');
dateEqual(testCreateDate('32 July'), new Date(now.getFullYear(), 7, 1), 'Date#addMonths | 32 July');
dateEqual(testCreateDate('1 Dec'), new Date(now.getFullYear(), 11, 1), 'Date#addMonths | 1 Dec');
dateEqual(testCreateDate('01 Dec'), new Date(now.getFullYear(), 11, 1), 'Date#addMonths | 01 Dec');
dateEqual(testCreateDate('15 Dec'), new Date(now.getFullYear(), 11, 15), 'Date#addMonths | 15 Dec');
dateEqual(testCreateDate('31 Dec'), new Date(now.getFullYear(), 11, 31), 'Date#addMonths | 31 Dec');
dateEqual(testCreateDate('1 December'), new Date(now.getFullYear(), 11, 1), 'Date#addMonths | 1 December');
dateEqual(testCreateDate('01 December'), new Date(now.getFullYear(), 11, 1), 'Date#addMonths | 01 December');
dateEqual(testCreateDate('15 December'), new Date(now.getFullYear(), 11, 15), 'Date#addMonths | 15 December');
dateEqual(testCreateDate('31 December'), new Date(now.getFullYear(), 11, 31), 'Date#addMonths | 31 December');
dateEqual(testCreateDate('32 December'), new Date(now.getFullYear() + 1, 0, 1), 'Date#addMonths | 32 December');
dateEqual(testCreateDate('1 January 3pm'), new Date(now.getFullYear(), 0, 1, 15), 'Date#addMonths | 1 January 3pm');
dateEqual(testCreateDate('1 January 3:45pm'), new Date(now.getFullYear(), 0, 1, 15, 45), 'Date#addMonths | 1 January 3:45pm');
dateEqual(testCreateDate("'87"), new Date(1987, 0), "Date#create | '87");
dateEqual(testCreateDate("May '87"), new Date(1987, 4), "Date#create | May '87");
dateEqual(testCreateDate("14 May '87"), new Date(1987, 4, 14), "Date#create | 14 May '87");
// Issue #224
equal(run(testCreateDate(''), 'isValid'), false, 'empty strings are not valid');
// Issue #387 null in date constructor
dateEqual(new Date(null), testCreateDate(null), 'null');
});
method('isPast', function() {
// Issue #141 future/past preference
test(testCreatePastDate('Sunday'), true, 'weekdays | Sunday');
test(testCreatePastDate('Monday'), true, 'weekdays | Monday');
test(testCreatePastDate('Tuesday'), true, 'weekdays | Tuesday');
test(testCreatePastDate('Wednesday'), true, 'weekdays | Wednesday');
test(testCreatePastDate('Thursday'), true, 'weekdays | Thursday');
test(testCreatePastDate('Friday'), true, 'weekdays | Friday');
test(testCreatePastDate('Saturday'), true, 'weekdays | Saturday');
test(testCreatePastDate('January'), true, 'months | January');
test(testCreatePastDate('February'), true, 'months | February');
test(testCreatePastDate('March'), true, 'months | March');
test(testCreatePastDate('April'), true, 'months | April');
test(testCreatePastDate('May'), true, 'months | May');
test(testCreatePastDate('June'), true, 'months | June');
test(testCreatePastDate('July'), true, 'months | July');
test(testCreatePastDate('August'), true, 'months | August');
test(testCreatePastDate('September'), true, 'months | September');
test(testCreatePastDate('October'), true, 'months | October');
test(testCreatePastDate('November'), true, 'months | November');
test(testCreatePastDate('December'), true, 'months | December');
});
method('isFuture', function() {
test(testCreateFutureDate('Sunday'), true, 'weekdays | Sunday');
test(testCreateFutureDate('Monday'), true, 'weekdays | Monday');
test(testCreateFutureDate('Tuesday'), true, 'weekdays | Tuesday');
test(testCreateFutureDate('Wednesday'), true, 'weekdays | Wednesday');
test(testCreateFutureDate('Thursday'), true, 'weekdays | Thursday');
test(testCreateFutureDate('Friday'), true, 'weekdays | Friday');
test(testCreateFutureDate('Saturday'), true, 'weekdays | Saturday');
test(testCreateFutureDate('January'), true, 'months | January');
test(testCreateFutureDate('February'), true, 'months | February');
test(testCreateFutureDate('March'), true, 'months | March');
test(testCreateFutureDate('April'), true, 'months | April');
test(testCreateFutureDate('May'), true, 'months | May');
test(testCreateFutureDate('June'), true, 'months | June');
test(testCreateFutureDate('July'), true, 'months | July');
test(testCreateFutureDate('August'), true, 'months | August');
test(testCreateFutureDate('September'), true, 'months | September');
test(testCreateFutureDate('October'), true, 'months | October');
test(testCreateFutureDate('November'), true, 'months | November');
test(testCreateFutureDate('December'), true, 'months | December');
test(testCreateFutureDate('1:00am'), true, '1am should be the future');
test(testCreateFutureDate('11:00pm'), true, '11pm should be the future');
equal(testCreateFutureDate('1:00am') < testCreateDate('1 day from now'), true, '1am should be the future');
equal(testCreateFutureDate('11:00pm') < testCreateDate('1 day from now'), true, '11pm should be the future');
});
group('Future Dates', function() {
// Ensure that dates don't traverse TOO far into the past/future
equal(run(testCreateFutureDate('January'), 'monthsFromNow') > 12, false, 'no more than 12 months from now');
equal(run(testCreateFutureDate('December'), 'monthsFromNow') > 12, false, 'no more than 12 months from now');
// Issue #210
equal(testCreateFutureDate('Sunday at 3:00').getDay(), 0, 'Date.future | weekday should never be ambiguous');
});
group('2-digit years', function() {
// Issue #383 Date.past in 2-digit years
dateEqual(testCreatePastDate('12/20/23'), new Date(1923,11,20), 'Date.past | 1923-12-20');
dateEqual(testCreateFutureDate('12/20/99'), new Date(2099,11,20), 'Date.future | 2099-12-20');
});
group('Invalid Dates', function() {
equal(run(testCreateDate('my pants'), 'isPast'), undefined, 'isPast | invalid dates should return false');
equal(run(testCreateDate('my pants'), 'isFuture'), undefined, 'isFuture | invalid dates should return false');
equal(run(testCreateDate('my pants'), 'isToday'), undefined, 'isToday | invalid dates should return false');
equal(run(testCreateDate('my pants'), 'isTomorrow'), undefined, 'isTomorrow | invalid dates should return false');
equal(run(testCreateDate('my pants'), 'is', ['today']), undefined, 'is | invalid dates should return false');
// Issue #264
testSetLocale('fo');
equal(run(testCreateDate(), 'isToday'), true, 'isToday should always work regardless of locale');
equal(run(testCreateDate('yesterday', 'en'), 'isYesterday'), true, 'isYesterday should always work regardless of locale');
equal(run(testCreateDate('tomorrow', 'en'), 'isTomorrow'), true, 'isTomorrow should always work regardless of locale');
equal(run(testCreateDate('monday', 'en'), 'isMonday'), true, 'isMonday should always work regardless of locale');
equal(run(testCreateDate('tuesday', 'en'), 'isTuesday'), true, 'isTuesday should always work regardless of locale');
equal(run(testCreateDate('wednesday', 'en'), 'isWednesday'), true, 'isWednesday should always work regardless of locale');
equal(run(testCreateDate('thursday', 'en'), 'isThursday'), true, 'isThursday should always work regardless of locale');
equal(run(testCreateDate('friday', 'en'), 'isFriday'), true, 'isFriday should always work regardless of locale');
equal(run(testCreateDate('saturday', 'en'), 'isSaturday'), true, 'isSaturday should always work regardless of locale');
equal(run(testCreateDate('sunday', 'en'), 'isSunday'), true, 'isSunday should always work regardless of locale');
equal(run(testCreateDate('1 day ago', 'en'), 'isPast'), true, 'isPast should always work regardless of locale');
equal(run(testCreateDate('1 day from now', 'en'), 'isFuture'), true, 'isFuture should always work regardless of locale');
testSetLocale('en');
});
method('get', function() {
var d = new Date('August 25, 2010 11:45:20');
test(d, ['next week'], new Date('September 1, 2010 11:45:20'), 'next week');
test(d, ['next monday'], new Date('August 30, 2010'), 'next monday');
test(d, ['5 milliseconds ago'], new Date(2010, 7, 25, 11, 45, 19, 995), '5 milliseconds ago');
test(d, ['5 seconds ago'], new Date('August 25, 2010 11:45:15'), '5 seconds ago');
test(d, ['5 minutes ago'], new Date('August 25, 2010 11:40:20'), '5 minutes ago');
test(d, ['5 hours ago'], new Date('August 25, 2010 6:45:20'), '5 hours ago');
test(d, ['5 days ago'], new Date('August 20, 2010 11:45:20'), '5 days ago');
test(d, ['5 weeks ago'], new Date('July 21, 2010 11:45:20'), '5 weeks ago');
test(d, ['5 months ago'], new Date('March 25, 2010 11:45:20'), '5 months ago');
test(d, ['5 years ago'], new Date('August 25, 2005 11:45:20'), '5 years ago');
test(d, ['5 years before'], new Date('August 25, 2005 11:45:20'), '5 years before');
test(d, ['5 milliseconds from now'], new Date(2010, 7, 25, 11, 45, 20, 5), '5 milliseconds from now');
test(d, ['5 seconds from now'], new Date('August 25, 2010 11:45:25'), '5 seconds from now');
test(d, ['5 minutes from now'], new Date('August 25, 2010 11:50:20'), '5 minutes from now');
test(d, ['5 hours from now'], new Date('August 25, 2010 16:45:20'), '5 hours from now');
test(d, ['5 days from now'], new Date('August 30, 2010 11:45:20'), '5 days from now');
test(d, ['5 weeks from now'], new Date('September 29, 2010 11:45:20'), '5 weeks from now');
test(d, ['5 months from now'], new Date('January 25, 2011 11:45:20'), '5 months from now');
test(d, ['5 years from now'], new Date('August 25, 2015 11:45:20'), '5 years from now');
test(d, ['5 years after'], new Date('August 25, 2015 11:45:20'), '5 years after');
});
method('set', function() {
// Just the time
var d;
d = new Date('August 25, 2010 11:45:20');
run(d, 'set', [2008, 5, 18, 4, 25, 30, 400]);
equal(d.getFullYear(), 2008, 'year');
equal(d.getMonth(), 5, 'month');
equal(d.getDate(), 18, 'date');
equal(d.getHours(), 4, 'hours');
equal(d.getMinutes(), 25, 'minutes');
equal(d.getSeconds(), 30, 'seconds');
equal(d.getMilliseconds(), 400, 'milliseconds');
d = new Date('August 25, 2010 11:45:20');
run(d, 'set', [{ year: 2008, month: 5, date: 18, hour: 4, minute: 25, second: 30, millisecond: 400 }]);
equal(d.getFullYear(), 2008, 'object | year');
equal(d.getMonth(), 5, 'object | month');
equal(d.getDate(), 18, 'object | date');
equal(d.getHours(), 4, 'object | hours');
equal(d.getMinutes(), 25, 'object | minutes');
equal(d.getSeconds(), 30, 'object | seconds');
equal(d.getMilliseconds(), 400, 'object | milliseconds');
d = new Date('August 25, 2010 11:45:20');
run(d, 'set', [{ years: 2008, months: 5, date: 18, hours: 4, minutes: 25, seconds: 30, milliseconds: 400 }]);
equal(d.getFullYear(), 2008, 'object plural | year');
equal(d.getMonth(), 5, 'object plural | month');
equal(d.getDate(), 18, 'object plural | date');
equal(d.getHours(), 4, 'object plural | hours');
equal(d.getMinutes(), 25, 'object plural | minutes');
equal(d.getSeconds(), 30, 'object plural | seconds');
equal(d.getMilliseconds(), 400, 'object plural | milliseconds');
run(d, 'set', [{ weekday: 2 }]);
equal(d.getDate(), 17, 'object | weekday 2');
run(d, 'set', [{ weekday: 5 }]);
equal(d.getDate(), 20, 'object | weekday 5');
run(d, 'set', [{ weekday: 2 }, true]);
equal(d.getDate(), 17, 'object | reset time | weekday 2');
run(d, 'set', [{ weekday: 5 }, true]);
equal(d.getDate(), 20, 'object | reset time | weekday 5');
d = new Date('August 25, 2010 11:45:20');
run(d, 'set', [{ years: 2005, hours: 2 }]);
equal(d.getFullYear(), 2005, 'no reset | year');
equal(d.getMonth(), 7, 'no reset | month');
equal(d.getDate(), 25, 'no reset | date');
equal(d.getHours(), 2, 'no reset | hours');
equal(d.getMinutes(), 45, 'no reset | minutes');
equal(d.getSeconds(), 20, 'no reset | seconds');
equal(d.getMilliseconds(), 0, 'no reset | milliseconds');
d = new Date('August 25, 2010 11:45:20');
run(d, 'set', [{ years: 2008, hours: 4 }, true]);
equal(d.getFullYear(), 2008, 'reset | year');
equal(d.getMonth(), 7, 'reset | month');
equal(d.getDate(), 25, 'reset | date');
equal(d.getHours(), 4, 'reset | hours');
equal(d.getMinutes(), 0, 'reset | minutes');
equal(d.getSeconds(), 0, 'reset | seconds');
equal(d.getMilliseconds(), 0, 'reset | milliseconds');
d = run(new Date('August 25, 2010 11:45:20'), 'setUTC', [true]);
run(d, 'set', [{ years: 2008, hours: 4 }, true]);
equal(d.getFullYear(), 2008, 'utc | reset utc | year');
equal(d.getMonth(), 7, 'utc | reset utc | month');
equal(d.getDate(), d.getTimezoneOffset() > 240 ? 24 : 25, 'utc | reset utc | date');
equal(d.getHours(), testGetHours(4 - (d.getTimezoneOffset() / 60)), 'utc | reset utc | hours');
equal(d.getMinutes(), Math.abs(d.getTimezoneOffset() % 60), 'utc | reset utc | minutes');
equal(d.getSeconds(), 0, 'utc | reset utc | seconds');
equal(d.getMilliseconds(), 0, 'utc | reset utc | milliseconds');
d = run(new Date('August 25, 2010 11:45:20'), 'setUTC', [true]);
run(d, 'set', [{ years: 2005, hours: 2 }, false]);
equal(d.getFullYear(), 2005, 'utc | no reset utc | year');
equal(d.getMonth(), 7, 'utc | no reset utc | month');
equal(d.getDate(), d.getTimezoneOffset() >= 135 ? 24 : 25, 'utc | no reset utc | date');
equal(d.getHours(), testGetHours(2 - (d.getTimezoneOffset() / 60)), 'utc | no reset utc | hours');
equal(d.getMinutes(), 45, 'utc | no reset utc | minutes');
equal(d.getSeconds(), 20, 'utc | no reset utc | seconds');
equal(d.getMilliseconds(), 0, 'utc | no reset utc | milliseconds');
d = run(new Date('August 25, 2010 11:45:20'), 'setUTC', [true]);
run(d, 'set', [{ years: 2005, hours: 2 }, false]);
equal(d.getFullYear(), 2005, 'utc | no reset | year');
equal(d.getMonth(), 7, 'utc | no reset | month');
equal(d.getDate(), d.getTimezoneOffset() >= 135 ? 24 : 25, 'utc | no reset | date');
equal(d.getHours(), testGetHours(2 - (d.getTimezoneOffset() / 60)), 'utc | no reset | hours');
equal(d.getMinutes(), 45, 'utc | no reset | minutes');
equal(d.getSeconds(), 20, 'utc | no reset | seconds');
equal(d.getMilliseconds(), 0, 'utc | no reset | milliseconds');
d = new Date('August 5, 2010 13:45:02');
d.setMilliseconds(234);
run(d, 'set', [{ month: 3 }]);
equal(d.getFullYear(), 2010, 'does not reset year');
equal(d.getMonth(), 3, 'does reset month');
equal(d.getDate(), 5, 'does not reset date');
equal(d.getHours(), 13, 'does not reset hours');