mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
added support for treating numbers as date in miliseconds
This commit is contained in:
parent
04a4d8b061
commit
1391f19fb4
2 changed files with 11 additions and 3 deletions
|
|
@ -75,8 +75,14 @@ var DATE_FORMATS = {
|
|||
var DATE_FORMATS_SPLIT = /([^yMdHhmsaZ]*)(y+|M+|d+|H+|h+|m+|s+|a|Z)(.*)/;
|
||||
|
||||
angularFilter.date = function(date, format) {
|
||||
if (!(date instanceof Date)) return date;
|
||||
var text = date.toLocaleDateString(), fn;
|
||||
var text, fn;
|
||||
if (!date) return date;
|
||||
if (!(date instanceof Date)) {
|
||||
text = parseInt(date, 10);
|
||||
date = new Date();
|
||||
date.setTime(text);
|
||||
}
|
||||
text = date.toLocaleDateString();
|
||||
if (format && isString(format)) {
|
||||
text = '';
|
||||
var parts = [];
|
||||
|
|
|
|||
|
|
@ -103,7 +103,6 @@ describe('filter', function(){
|
|||
it('should ignore falsy inputs', function() {
|
||||
expect(filter.date(null)).toEqual(null);
|
||||
expect(filter.date('')).toEqual('');
|
||||
expect(filter.date(123)).toEqual(123);
|
||||
});
|
||||
|
||||
it('should do basic filter', function() {
|
||||
|
|
@ -123,6 +122,9 @@ describe('filter', function(){
|
|||
|
||||
});
|
||||
|
||||
it('should accept miliseconds as date', function(){
|
||||
expect(filter.date("123", "yyyy")).toEqual('1969');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue