@@ -29,13 +29,21 @@ describe('date parser', function() {
29
29
expectParse ( '11-08-13' , 'dd-MM-yy' , new Date ( 2013 , 7 , 11 , 0 ) ) ;
30
30
} ) ;
31
31
32
- it ( 'should work correctly for `M`' , function ( ) {
33
- expectParse ( '8/11/2013' , 'M/dd/yyyy' , new Date ( 2013 , 7 , 11 , 0 ) ) ;
34
- expectParse ( '07.11.05' , 'dd.M.yy' , new Date ( 2005 , 10 , 7 , 0 ) ) ;
35
- expectParse ( '02-5-11' , 'dd-M-yy' , new Date ( 2011 , 4 , 2 , 0 ) ) ;
36
- expectParse ( '2/05/1980' , 'M/dd/yyyy' , new Date ( 1980 , 1 , 5 , 0 ) ) ;
37
- expectParse ( '1955/2/05' , 'yyyy/M/dd' , new Date ( 1955 , 1 , 5 , 0 ) ) ;
38
- expectParse ( '02-5-11' , 'dd-M-yy' , new Date ( 2011 , 4 , 2 , 0 ) ) ;
32
+ it ( 'should work correctly for `y`' , function ( ) {
33
+ expectParse ( '17.11.2013' , 'dd.MM.y' , new Date ( 2013 , 10 , 17 , 0 ) ) ;
34
+ expectParse ( '31.12.2013' , 'dd.MM.y' , new Date ( 2013 , 11 , 31 , 0 ) ) ;
35
+ expectParse ( '08-03-1991' , 'dd-MM-y' , new Date ( 1991 , 2 , 8 , 0 ) ) ;
36
+ expectParse ( '03/05/1980' , 'MM/dd/y' , new Date ( 1980 , 2 , 5 , 0 ) ) ;
37
+ expectParse ( '10.01/1983' , 'dd.MM/y' , new Date ( 1983 , 0 , 10 , 0 ) ) ;
38
+ expectParse ( '11-09-1980' , 'MM-dd-y' , new Date ( 1980 , 10 , 9 , 0 ) ) ;
39
+ expectParse ( '2011/02/05' , 'y/MM/dd' , new Date ( 2011 , 1 , 5 , 0 ) ) ;
40
+ } ) ;
41
+
42
+ it ( 'should work correctly for `MMMM`' , function ( ) {
43
+ expectParse ( '17.November.13' , 'dd.MMMM.yy' , new Date ( 2013 , 10 , 17 , 0 ) ) ;
44
+ expectParse ( '05-March-1980' , 'dd-MMMM-yyyy' , new Date ( 1980 , 2 , 5 , 0 ) ) ;
45
+ expectParse ( 'February/05/1980' , 'MMMM/dd/yyyy' , new Date ( 1980 , 1 , 5 , 0 ) ) ;
46
+ expectParse ( '1949/December/20' , 'yyyy/MMMM/dd' , new Date ( 1949 , 11 , 20 , 0 ) ) ;
39
47
} ) ;
40
48
41
49
it ( 'should work correctly for `MMM`' , function ( ) {
@@ -45,11 +53,13 @@ describe('date parser', function() {
45
53
expectParse ( '1955/Feb/05' , 'yyyy/MMM/dd' , new Date ( 1955 , 1 , 5 , 0 ) ) ;
46
54
} ) ;
47
55
48
- it ( 'should work correctly for `MMMM`' , function ( ) {
49
- expectParse ( '17.November.13' , 'dd.MMMM.yy' , new Date ( 2013 , 10 , 17 , 0 ) ) ;
50
- expectParse ( '05-March-1980' , 'dd-MMMM-yyyy' , new Date ( 1980 , 2 , 5 , 0 ) ) ;
51
- expectParse ( 'February/05/1980' , 'MMMM/dd/yyyy' , new Date ( 1980 , 1 , 5 , 0 ) ) ;
52
- expectParse ( '1949/December/20' , 'yyyy/MMMM/dd' , new Date ( 1949 , 11 , 20 , 0 ) ) ;
56
+ it ( 'should work correctly for `M`' , function ( ) {
57
+ expectParse ( '8/11/2013' , 'M/dd/yyyy' , new Date ( 2013 , 7 , 11 , 0 ) ) ;
58
+ expectParse ( '07.11.05' , 'dd.M.yy' , new Date ( 2005 , 10 , 7 , 0 ) ) ;
59
+ expectParse ( '02-5-11' , 'dd-M-yy' , new Date ( 2011 , 4 , 2 , 0 ) ) ;
60
+ expectParse ( '2/05/1980' , 'M/dd/yyyy' , new Date ( 1980 , 1 , 5 , 0 ) ) ;
61
+ expectParse ( '1955/2/05' , 'yyyy/M/dd' , new Date ( 1955 , 1 , 5 , 0 ) ) ;
62
+ expectParse ( '02-5-11' , 'dd-M-yy' , new Date ( 2011 , 4 , 2 , 0 ) ) ;
53
63
} ) ;
54
64
55
65
it ( 'should work correctly for `d`' , function ( ) {
@@ -60,6 +70,20 @@ describe('date parser', function() {
60
70
expectParse ( '11-08-13' , 'd-MM-yy' , new Date ( 2013 , 7 , 11 , 0 ) ) ;
61
71
} ) ;
62
72
73
+ it ( 'should work correctly for `EEEE`' , function ( ) {
74
+ expectParse ( 'Sunday.17.November.13' , 'EEEE.d.MMMM.yy' , new Date ( 2013 , 10 , 17 , 0 ) ) ;
75
+ expectParse ( '8-Friday-March-1991' , 'd-EEEE-MMMM-yyyy' , new Date ( 1991 , 2 , 8 , 0 ) ) ;
76
+ expectParse ( 'February/5/1980/Tuesday' , 'MMMM/d/yyyy/EEEE' , new Date ( 1980 , 1 , 5 , 0 ) ) ;
77
+ expectParse ( '1955/Saturday/February/5' , 'yyyy/EEEE/MMMM/d' , new Date ( 1955 , 1 , 5 , 0 ) ) ;
78
+ } ) ;
79
+
80
+ it ( 'should work correctly for `EEE`' , function ( ) {
81
+ expectParse ( 'Sun.17.November.13' , 'EEE.d.MMMM.yy' , new Date ( 2013 , 10 , 17 , 0 ) ) ;
82
+ expectParse ( '8-Fri-March-1991' , 'd-EEE-MMMM-yyyy' , new Date ( 1991 , 2 , 8 , 0 ) ) ;
83
+ expectParse ( 'February/5/1980/Tue' , 'MMMM/d/yyyy/EEE' , new Date ( 1980 , 1 , 5 , 0 ) ) ;
84
+ expectParse ( '1955/Sat/February/5' , 'yyyy/EEE/MMMM/d' , new Date ( 1955 , 1 , 5 , 0 ) ) ;
85
+ } ) ;
86
+
63
87
it ( 'should work correctly for `HH`' , function ( ) {
64
88
expectParse ( '22.March.15.22' , 'd.MMMM.yy.HH' , new Date ( 2015 , 2 , 22 , 22 ) ) ;
65
89
expectParse ( '8-March-1991-11' , 'd-MMMM-yyyy-HH' , new Date ( 1991 , 2 , 8 , 11 ) ) ;
@@ -68,6 +92,14 @@ describe('date parser', function() {
68
92
expectParse ( '11-08-13 23' , 'd-MM-yy HH' , new Date ( 2013 , 7 , 11 , 23 ) ) ;
69
93
} ) ;
70
94
95
+ it ( 'should work correctly for `H`' , function ( ) {
96
+ expectParse ( '22.March.15.22' , 'd.MMMM.yy.H' , new Date ( 2015 , 2 , 22 , 22 ) ) ;
97
+ expectParse ( '8-March-1991-11' , 'd-MMMM-yyyy-H' , new Date ( 1991 , 2 , 8 , 11 ) ) ;
98
+ expectParse ( 'February/5/1980/0' , 'MMMM/d/yyyy/H' , new Date ( 1980 , 1 , 5 , 0 ) ) ;
99
+ expectParse ( '1955/February/5 3' , 'yyyy/MMMM/d H' , new Date ( 1955 , 1 , 5 , 3 ) ) ;
100
+ expectParse ( '11-08-13 23' , 'd-MM-yy H' , new Date ( 2013 , 7 , 11 , 23 ) ) ;
101
+ } ) ;
102
+
71
103
it ( 'should work correctly for `hh`' , function ( ) {
72
104
expectParse ( '22.March.15.22' , 'd.MMMM.yy.hh' , undefined ) ;
73
105
expectParse ( '22.March.15.12' , 'd.MMMM.yy.hh' , new Date ( 2015 , 2 , 22 , 12 ) ) ;
@@ -78,14 +110,6 @@ describe('date parser', function() {
78
110
expectParse ( '11-08-13 09' , 'd-MM-yy hh' , new Date ( 2013 , 7 , 11 , 9 ) ) ;
79
111
} ) ;
80
112
81
- it ( 'should work correctly for `H`' , function ( ) {
82
- expectParse ( '22.March.15.22' , 'd.MMMM.yy.H' , new Date ( 2015 , 2 , 22 , 22 ) ) ;
83
- expectParse ( '8-March-1991-11' , 'd-MMMM-yyyy-H' , new Date ( 1991 , 2 , 8 , 11 ) ) ;
84
- expectParse ( 'February/5/1980/0' , 'MMMM/d/yyyy/H' , new Date ( 1980 , 1 , 5 , 0 ) ) ;
85
- expectParse ( '1955/February/5 3' , 'yyyy/MMMM/d H' , new Date ( 1955 , 1 , 5 , 3 ) ) ;
86
- expectParse ( '11-08-13 23' , 'd-MM-yy H' , new Date ( 2013 , 7 , 11 , 23 ) ) ;
87
- } ) ;
88
-
89
113
it ( 'should work correctly for `h`' , function ( ) {
90
114
expectParse ( '22.March.15.12' , 'd.MMMM.yy.h' , new Date ( 2015 , 2 , 22 , 12 ) ) ;
91
115
expectParse ( '8-March-1991-11' , 'd-MMMM-yyyy-h' , new Date ( 1991 , 2 , 8 , 11 ) ) ;
@@ -178,39 +202,31 @@ describe('date parser', function() {
178
202
179
203
describe ( 'with edge case' , function ( ) {
180
204
it ( 'should not work for invalid number of days in February' , function ( ) {
181
- expect ( dateParser . parse ( '29.02.2013' , 'dd.MM.yyyy' ) ) . toBeUndefined ( ) ;
205
+ expectParse ( '29.02.2013' , 'dd.MM.yyyy' , undefined ) ;
182
206
} ) ;
183
207
184
208
it ( 'should not work for 0 number of days' , function ( ) {
185
- expect ( dateParser . parse ( '00.02.2013' , 'dd.MM.yyyy' ) ) . toBeUndefined ( ) ;
209
+ expectParse ( '00.02.2013' , 'dd.MM.yyyy' , undefined ) ;
186
210
} ) ;
187
211
188
212
it ( 'should work for 29 days in February for leap years' , function ( ) {
189
213
expectParse ( '29.02.2000' , 'dd.MM.yyyy' , new Date ( 2000 , 1 , 29 , 0 ) ) ;
190
214
} ) ;
191
215
192
216
it ( 'should not work for 31 days for some months' , function ( ) {
193
- expect ( dateParser . parse ( '31-04-2013' , 'dd-MM-yyyy' ) ) . toBeUndefined ( ) ;
194
- expect ( dateParser . parse ( 'November 31, 2013' , 'MMMM d, yyyy' ) ) . toBeUndefined ( ) ;
195
- } ) ;
196
-
197
- it ( 'should work when base date is a string' , function ( ) {
198
- expect ( dateParser . parse ( '01-02-2034' , 'dd-MM-yyyy' , '05-06-2078' ) ) . toEqual ( new Date ( 2034 , 1 , 1 ) ) ;
199
- } ) ;
200
-
201
- it ( 'should work when base date is an invalid date' , function ( ) {
202
- expect ( dateParser . parse ( '30-12-2015' , 'dd-MM-yyyy' , new Date ( 'foo' ) ) ) . toEqual ( new Date ( 2015 , 11 , 30 ) ) ;
217
+ expectParse ( '31-04-2013' , 'dd-MM-yyyy' , undefined ) ;
218
+ expectParse ( 'November 31, 2013' , 'MMMM d, yyyy' , undefined ) ;
203
219
} ) ;
204
220
} ) ;
205
221
206
222
it ( 'should not parse non-string inputs' , function ( ) {
207
- expect ( dateParser . parse ( 123456 , 'dd.MM.yyyy' ) ) . toBe ( 123456 ) ;
223
+ expectParse ( 123456 , 'dd.MM.yyyy' , 123456 ) ;
208
224
var date = new Date ( ) ;
209
- expect ( dateParser . parse ( date , 'dd.MM.yyyy' ) ) . toBe ( date ) ;
225
+ expectParse ( date , 'dd.MM.yyyy' , date ) ;
210
226
} ) ;
211
227
212
228
it ( 'should not parse if no format is specified' , function ( ) {
213
- expect ( dateParser . parse ( '21.08.1951' , '' ) ) . toBe ( '21.08.1951' ) ;
229
+ expectParse ( '21.08.1951' , '' , '21.08.1951' ) ;
214
230
} ) ;
215
231
216
232
it ( 'should reinitialize when locale changes' , inject ( function ( $locale ) {
0 commit comments