@@ -4,101 +4,110 @@ angular.module('ui.bootstrap.dateparser', [])
4
4
// Pulled from https://github.com/mbostock/d3/blob/master/src/format/requote.js
5
5
var SPECIAL_CHARACTERS_REGEXP = / [ \\ \^ \$ \* \+ \? \| \[ \] \( \) \. \{ \} ] / g;
6
6
7
- this . parsers = { } ;
8
-
9
- var formatCodeToRegex = {
10
- 'yyyy' : {
11
- regex : '\\d{4}' ,
12
- apply : function ( value ) { this . year = + value ; }
13
- } ,
14
- 'yy' : {
15
- regex : '\\d{2}' ,
16
- apply : function ( value ) { this . year = + value + 2000 ; }
17
- } ,
18
- 'y' : {
19
- regex : '\\d{1,4}' ,
20
- apply : function ( value ) { this . year = + value ; }
21
- } ,
22
- 'MMMM' : {
23
- regex : $locale . DATETIME_FORMATS . MONTH . join ( '|' ) ,
24
- apply : function ( value ) { this . month = $locale . DATETIME_FORMATS . MONTH . indexOf ( value ) ; }
25
- } ,
26
- 'MMM' : {
27
- regex : $locale . DATETIME_FORMATS . SHORTMONTH . join ( '|' ) ,
28
- apply : function ( value ) { this . month = $locale . DATETIME_FORMATS . SHORTMONTH . indexOf ( value ) ; }
29
- } ,
30
- 'MM' : {
31
- regex : '0[1-9]|1[0-2]' ,
32
- apply : function ( value ) { this . month = value - 1 ; }
33
- } ,
34
- 'M' : {
35
- regex : '[1-9]|1[0-2]' ,
36
- apply : function ( value ) { this . month = value - 1 ; }
37
- } ,
38
- 'dd' : {
39
- regex : '[0-2][0-9]{1}|3[0-1]{1}' ,
40
- apply : function ( value ) { this . date = + value ; }
41
- } ,
42
- 'd' : {
43
- regex : '[1-2]?[0-9]{1}|3[0-1]{1}' ,
44
- apply : function ( value ) { this . date = + value ; }
45
- } ,
46
- 'EEEE' : {
47
- regex : $locale . DATETIME_FORMATS . DAY . join ( '|' )
48
- } ,
49
- 'EEE' : {
50
- regex : $locale . DATETIME_FORMATS . SHORTDAY . join ( '|' )
51
- } ,
52
- 'HH' : {
53
- regex : '(?:0|1)[0-9]|2[0-3]' ,
54
- apply : function ( value ) { this . hours = + value ; }
55
- } ,
56
- 'hh' : {
57
- regex : '0[0-9]|1[0-2]' ,
58
- apply : function ( value ) { this . hours = + value ; }
59
- } ,
60
- 'H' : {
61
- regex : '1?[0-9]|2[0-3]' ,
62
- apply : function ( value ) { this . hours = + value ; }
63
- } ,
64
- 'h' : {
65
- regex : '[0-9]|1[0-2]' ,
66
- apply : function ( value ) { this . hours = + value ; }
67
- } ,
68
- 'mm' : {
69
- regex : '[0-5][0-9]' ,
70
- apply : function ( value ) { this . minutes = + value ; }
71
- } ,
72
- 'm' : {
73
- regex : '[0-9]|[1-5][0-9]' ,
74
- apply : function ( value ) { this . minutes = + value ; }
75
- } ,
76
- 'sss' : {
77
- regex : '[0-9][0-9][0-9]' ,
78
- apply : function ( value ) { this . milliseconds = + value ; }
79
- } ,
80
- 'ss' : {
81
- regex : '[0-5][0-9]' ,
82
- apply : function ( value ) { this . seconds = + value ; }
83
- } ,
84
- 's' : {
85
- regex : '[0-9]|[1-5][0-9]' ,
86
- apply : function ( value ) { this . seconds = + value ; }
87
- } ,
88
- 'a' : {
89
- regex : $locale . DATETIME_FORMATS . AMPMS . join ( '|' ) ,
90
- apply : function ( value ) {
91
- if ( this . hours === 12 ) {
92
- this . hours = 0 ;
93
- }
94
-
95
- if ( value === 'PM' ) {
96
- this . hours += 12 ;
7
+ var localeId ;
8
+ var formatCodeToRegex ;
9
+
10
+ this . init = function ( ) {
11
+ localeId = $locale . id ;
12
+
13
+ this . parsers = { } ;
14
+
15
+ formatCodeToRegex = {
16
+ 'yyyy' : {
17
+ regex : '\\d{4}' ,
18
+ apply : function ( value ) { this . year = + value ; }
19
+ } ,
20
+ 'yy' : {
21
+ regex : '\\d{2}' ,
22
+ apply : function ( value ) { this . year = + value + 2000 ; }
23
+ } ,
24
+ 'y' : {
25
+ regex : '\\d{1,4}' ,
26
+ apply : function ( value ) { this . year = + value ; }
27
+ } ,
28
+ 'MMMM' : {
29
+ regex : $locale . DATETIME_FORMATS . MONTH . join ( '|' ) ,
30
+ apply : function ( value ) { this . month = $locale . DATETIME_FORMATS . MONTH . indexOf ( value ) ; }
31
+ } ,
32
+ 'MMM' : {
33
+ regex : $locale . DATETIME_FORMATS . SHORTMONTH . join ( '|' ) ,
34
+ apply : function ( value ) { this . month = $locale . DATETIME_FORMATS . SHORTMONTH . indexOf ( value ) ; }
35
+ } ,
36
+ 'MM' : {
37
+ regex : '0[1-9]|1[0-2]' ,
38
+ apply : function ( value ) { this . month = value - 1 ; }
39
+ } ,
40
+ 'M' : {
41
+ regex : '[1-9]|1[0-2]' ,
42
+ apply : function ( value ) { this . month = value - 1 ; }
43
+ } ,
44
+ 'dd' : {
45
+ regex : '[0-2][0-9]{1}|3[0-1]{1}' ,
46
+ apply : function ( value ) { this . date = + value ; }
47
+ } ,
48
+ 'd' : {
49
+ regex : '[1-2]?[0-9]{1}|3[0-1]{1}' ,
50
+ apply : function ( value ) { this . date = + value ; }
51
+ } ,
52
+ 'EEEE' : {
53
+ regex : $locale . DATETIME_FORMATS . DAY . join ( '|' )
54
+ } ,
55
+ 'EEE' : {
56
+ regex : $locale . DATETIME_FORMATS . SHORTDAY . join ( '|' )
57
+ } ,
58
+ 'HH' : {
59
+ regex : '(?:0|1)[0-9]|2[0-3]' ,
60
+ apply : function ( value ) { this . hours = + value ; }
61
+ } ,
62
+ 'hh' : {
63
+ regex : '0[0-9]|1[0-2]' ,
64
+ apply : function ( value ) { this . hours = + value ; }
65
+ } ,
66
+ 'H' : {
67
+ regex : '1?[0-9]|2[0-3]' ,
68
+ apply : function ( value ) { this . hours = + value ; }
69
+ } ,
70
+ 'h' : {
71
+ regex : '[0-9]|1[0-2]' ,
72
+ apply : function ( value ) { this . hours = + value ; }
73
+ } ,
74
+ 'mm' : {
75
+ regex : '[0-5][0-9]' ,
76
+ apply : function ( value ) { this . minutes = + value ; }
77
+ } ,
78
+ 'm' : {
79
+ regex : '[0-9]|[1-5][0-9]' ,
80
+ apply : function ( value ) { this . minutes = + value ; }
81
+ } ,
82
+ 'sss' : {
83
+ regex : '[0-9][0-9][0-9]' ,
84
+ apply : function ( value ) { this . milliseconds = + value ; }
85
+ } ,
86
+ 'ss' : {
87
+ regex : '[0-5][0-9]' ,
88
+ apply : function ( value ) { this . seconds = + value ; }
89
+ } ,
90
+ 's' : {
91
+ regex : '[0-9]|[1-5][0-9]' ,
92
+ apply : function ( value ) { this . seconds = + value ; }
93
+ } ,
94
+ 'a' : {
95
+ regex : $locale . DATETIME_FORMATS . AMPMS . join ( '|' ) ,
96
+ apply : function ( value ) {
97
+ if ( this . hours === 12 ) {
98
+ this . hours = 0 ;
99
+ }
100
+
101
+ if ( value === 'PM' ) {
102
+ this . hours += 12 ;
103
+ }
97
104
}
98
105
}
99
- }
106
+ } ;
100
107
} ;
101
108
109
+ this . init ( ) ;
110
+
102
111
function createParser ( format ) {
103
112
var map = [ ] , regex = format . split ( '' ) ;
104
113
@@ -134,6 +143,10 @@ angular.module('ui.bootstrap.dateparser', [])
134
143
format = $locale . DATETIME_FORMATS [ format ] || format ;
135
144
format = format . replace ( SPECIAL_CHARACTERS_REGEXP , '\\$&' ) ;
136
145
146
+ if ( $locale . id !== localeId ) {
147
+ this . init ( ) ;
148
+ }
149
+
137
150
if ( ! this . parsers [ format ] ) {
138
151
this . parsers [ format ] = createParser ( format ) ;
139
152
}
0 commit comments