@@ -12,94 +12,117 @@ angular.module('ui.bootstrap.dateparser', [])
12
12
13
13
this . parsers = { } ;
14
14
15
- formatCodeToRegex = {
16
- 'yyyy' : {
15
+ formatCodeToRegex = [
16
+ {
17
+ key : 'yyyy' ,
17
18
regex : '\\d{4}' ,
18
19
apply : function ( value ) { this . year = + value ; }
19
20
} ,
20
- 'yy' : {
21
+ {
22
+ key : 'yy' ,
21
23
regex : '\\d{2}' ,
22
24
apply : function ( value ) { this . year = + value + 2000 ; }
23
25
} ,
24
- 'y' : {
26
+ {
27
+ key : 'y' ,
25
28
regex : '\\d{1,4}' ,
26
29
apply : function ( value ) { this . year = + value ; }
27
30
} ,
28
- 'M!' : {
31
+ {
32
+ key : 'M!' ,
29
33
regex : '0?[1-9]|1[0-2]' ,
30
34
apply : function ( value ) { this . month = value - 1 ; }
31
35
} ,
32
- 'MMMM' : {
36
+ {
37
+ key : 'MMMM' ,
33
38
regex : $locale . DATETIME_FORMATS . MONTH . join ( '|' ) ,
34
39
apply : function ( value ) { this . month = $locale . DATETIME_FORMATS . MONTH . indexOf ( value ) ; }
35
40
} ,
36
- 'MMM' : {
41
+ {
42
+ key : 'MMM' ,
37
43
regex : $locale . DATETIME_FORMATS . SHORTMONTH . join ( '|' ) ,
38
44
apply : function ( value ) { this . month = $locale . DATETIME_FORMATS . SHORTMONTH . indexOf ( value ) ; }
39
45
} ,
40
- 'MM' : {
46
+ {
47
+ key : 'MM' ,
41
48
regex : '0[1-9]|1[0-2]' ,
42
49
apply : function ( value ) { this . month = value - 1 ; }
43
50
} ,
44
- 'M' : {
51
+ {
52
+ key : 'M' ,
45
53
regex : '[1-9]|1[0-2]' ,
46
54
apply : function ( value ) { this . month = value - 1 ; }
47
55
} ,
48
- 'd!' : {
56
+ {
57
+ key : 'd!' ,
49
58
regex : '[0-2]?[0-9]{1}|3[0-1]{1}' ,
50
59
apply : function ( value ) { this . date = + value ; }
51
60
} ,
52
- 'dd' : {
61
+ {
62
+ key : 'dd' ,
53
63
regex : '[0-2][0-9]{1}|3[0-1]{1}' ,
54
64
apply : function ( value ) { this . date = + value ; }
55
65
} ,
56
- 'd' : {
66
+ {
67
+ key : 'd' ,
57
68
regex : '[1-2]?[0-9]{1}|3[0-1]{1}' ,
58
69
apply : function ( value ) { this . date = + value ; }
59
70
} ,
60
- 'EEEE' : {
71
+ {
72
+ key : 'EEEE' ,
61
73
regex : $locale . DATETIME_FORMATS . DAY . join ( '|' )
62
74
} ,
63
- 'EEE' : {
75
+ {
76
+ key : 'EEE' ,
64
77
regex : $locale . DATETIME_FORMATS . SHORTDAY . join ( '|' )
65
78
} ,
66
- 'HH' : {
79
+ {
80
+ key : 'HH' ,
67
81
regex : '(?:0|1)[0-9]|2[0-3]' ,
68
82
apply : function ( value ) { this . hours = + value ; }
69
83
} ,
70
- 'hh' : {
84
+ {
85
+ key : 'hh' ,
71
86
regex : '0[0-9]|1[0-2]' ,
72
87
apply : function ( value ) { this . hours = + value ; }
73
88
} ,
74
- 'H' : {
89
+ {
90
+ key : 'H' ,
75
91
regex : '1?[0-9]|2[0-3]' ,
76
92
apply : function ( value ) { this . hours = + value ; }
77
93
} ,
78
- 'h' : {
94
+ {
95
+ key : 'h' ,
79
96
regex : '[0-9]|1[0-2]' ,
80
97
apply : function ( value ) { this . hours = + value ; }
81
98
} ,
82
- 'mm' : {
99
+ {
100
+ key : 'mm' ,
83
101
regex : '[0-5][0-9]' ,
84
102
apply : function ( value ) { this . minutes = + value ; }
85
103
} ,
86
- 'm' : {
104
+ {
105
+ key : 'm' ,
87
106
regex : '[0-9]|[1-5][0-9]' ,
88
107
apply : function ( value ) { this . minutes = + value ; }
89
108
} ,
90
- 'sss' : {
109
+ {
110
+ key : 'sss' ,
91
111
regex : '[0-9][0-9][0-9]' ,
92
112
apply : function ( value ) { this . milliseconds = + value ; }
93
113
} ,
94
- 'ss' : {
114
+ {
115
+ key : 'ss' ,
95
116
regex : '[0-5][0-9]' ,
96
117
apply : function ( value ) { this . seconds = + value ; }
97
118
} ,
98
- 's' : {
119
+ {
120
+ key : 's' ,
99
121
regex : '[0-9]|[1-5][0-9]' ,
100
122
apply : function ( value ) { this . seconds = + value ; }
101
123
} ,
102
- 'a' : {
124
+ {
125
+ key : 'a' ,
103
126
regex : $locale . DATETIME_FORMATS . AMPMS . join ( '|' ) ,
104
127
apply : function ( value ) {
105
128
if ( this . hours === 12 ) {
@@ -111,7 +134,7 @@ angular.module('ui.bootstrap.dateparser', [])
111
134
}
112
135
}
113
136
}
114
- } ;
137
+ ] ;
115
138
} ;
116
139
117
140
this . init ( ) ;
@@ -148,15 +171,15 @@ angular.module('ui.bootstrap.dateparser', [])
148
171
format = format . join ( '' ) ;
149
172
}
150
173
151
- angular . forEach ( formatCodeToRegex , function ( data , code ) {
152
- var index = format . indexOf ( code ) ;
174
+ angular . forEach ( formatCodeToRegex , function ( data ) {
175
+ var index = format . indexOf ( data . key ) ;
153
176
154
177
if ( index > - 1 ) {
155
178
format = format . split ( '' ) ;
156
179
157
180
regex [ index ] = '(' + data . regex + ')' ;
158
181
format [ index ] = '$' ; // Custom symbol to define consumed part of format
159
- for ( var i = index + 1 , n = index + code . length ; i < n ; i ++ ) {
182
+ for ( var i = index + 1 , n = index + data . key . length ; i < n ; i ++ ) {
160
183
regex [ i ] = '' ;
161
184
format [ i ] = '$' ;
162
185
}
0 commit comments