mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
date filter should accept ISO 8601 formatted string as input
Closes #125
This commit is contained in:
parent
f077649f48
commit
a397645537
3 changed files with 17 additions and 3 deletions
|
|
@ -1,5 +1,8 @@
|
|||
# <angular/> 0.9.3 cold-resistance (in-progress) #
|
||||
|
||||
### Api
|
||||
- date filter now accepts strings that angular.String.toDate can convert to Date objects
|
||||
|
||||
|
||||
# <angular/> 0.9.2 faunal-mimicry (2010-11-03) #
|
||||
|
||||
|
|
|
|||
|
|
@ -168,7 +168,8 @@ var NUMBER_STRING = /^\d+$/;
|
|||
* * `'a'`: am/pm marker
|
||||
* * `'Z'`: 4 digit (+sign) representation of the timezone offset (-1200‒1200)
|
||||
*
|
||||
* @param {(Date|number|string)} date Date to format either as Date object or milliseconds.
|
||||
* @param {(Date|number|string)} date Date to format either as Date object, milliseconds (string or
|
||||
* number) or ISO 8601 string (yyyy-MM-ddTHH:mm:ssZ).
|
||||
* @param {string=} format Formatting rules. If not specified, Date#toLocaleDateString is used.
|
||||
* @returns {string} Formatted string or the input if input is not recognized as date/millis.
|
||||
*
|
||||
|
|
@ -188,8 +189,12 @@ var NUMBER_STRING = /^\d+$/;
|
|||
*
|
||||
*/
|
||||
angularFilter.date = function(date, format) {
|
||||
if (isString(date) && NUMBER_STRING.test(date)) {
|
||||
date = parseInt(date, 10);
|
||||
if (isString(date)) {
|
||||
if (NUMBER_STRING.test(date)) {
|
||||
date = parseInt(date, 10);
|
||||
} else {
|
||||
date = angularString.toDate(date);
|
||||
}
|
||||
}
|
||||
|
||||
if (isNumber(date)) {
|
||||
|
|
|
|||
|
|
@ -128,5 +128,11 @@ describe('filter', function(){
|
|||
expect(filter.date(noon, "yyyy-MM-dd hh=HH:mm:ssaZ")).
|
||||
toEqual('2010-09-03 12=12:05:08pm0500');
|
||||
});
|
||||
|
||||
it('should be able to parse ISO 8601 dates/times using', function() {
|
||||
var isoString = '2010-09-03T05:05:08Z';
|
||||
expect(filter.date(isoString)).
|
||||
toEqual(angular.String.toDate(isoString).toLocaleDateString());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue