File tree 3 files changed +17
-3
lines changed 3 files changed +17
-3
lines changed Original file line number Diff line number Diff line change 1
1
# <angular /> 0.9.3 cold-resistance (in-progress) #
2
2
3
+ ### Api
4
+ - date filter now accepts strings that angular.String.toDate can convert to Date objects
5
+
3
6
4
7
# <angular /> 0.9.2 faunal-mimicry (2010-11-03) #
5
8
Original file line number Diff line number Diff line change @@ -168,7 +168,8 @@ var NUMBER_STRING = /^\d+$/;
168
168
* * `'a'`: am/pm marker
169
169
* * `'Z'`: 4 digit (+sign) representation of the timezone offset (-1200‒1200)
170
170
*
171
- * @param {(Date|number|string) } date Date to format either as Date object or milliseconds.
171
+ * @param {(Date|number|string) } date Date to format either as Date object, milliseconds (string or
172
+ * number) or ISO 8601 string (yyyy-MM-ddTHH:mm:ssZ).
172
173
* @param {string= } format Formatting rules. If not specified, Date#toLocaleDateString is used.
173
174
* @returns {string } Formatted string or the input if input is not recognized as date/millis.
174
175
*
@@ -188,8 +189,12 @@ var NUMBER_STRING = /^\d+$/;
188
189
*
189
190
*/
190
191
angularFilter . date = function ( date , format ) {
191
- if ( isString ( date ) && NUMBER_STRING . test ( date ) ) {
192
- date = parseInt ( date , 10 ) ;
192
+ if ( isString ( date ) ) {
193
+ if ( NUMBER_STRING . test ( date ) ) {
194
+ date = parseInt ( date , 10 ) ;
195
+ } else {
196
+ date = angularString . toDate ( date ) ;
197
+ }
193
198
}
194
199
195
200
if ( isNumber ( date ) ) {
Original file line number Diff line number Diff line change @@ -128,5 +128,11 @@ describe('filter', function(){
128
128
expect ( filter . date ( noon , "yyyy-MM-dd hh=HH:mm:ssaZ" ) ) .
129
129
toEqual ( '2010-09-03 12=12:05:08pm0500' ) ;
130
130
} ) ;
131
+
132
+ it ( 'should be able to parse ISO 8601 dates/times using' , function ( ) {
133
+ var isoString = '2010-09-03T05:05:08Z' ;
134
+ expect ( filter . date ( isoString ) ) .
135
+ toEqual ( angular . String . toDate ( isoString ) . toLocaleDateString ( ) ) ;
136
+ } ) ;
131
137
} ) ;
132
138
} ) ;
You can’t perform that action at this time.
0 commit comments