I'm using amCalendar filter from angular-moment to show the moment in the view.
- p.example: "Today 2:30 AM".
The amCalendar filter not accept Date as a type. I created this function that returns the short date ISO string passing a Date parameter:
function toShortISO(d){
var date;
date instanceof Date?
date = d:
date = toDate(d);
function pad(n) {return n<10 ? '0'+n : n}
return date.getUTCFullYear()
+ pad( date.getUTCMonth() + 1 )
+ pad( date.getUTCDate() )
+ 'T' + pad( date.getUTCHours() )
+ pad( date.getUTCMinutes() )
+ pad( date.getUTCSeconds() )
+ 'Z';
}
Passing a Date, this function returns 20150905T060000Z
(per example). And now I can apply the amCalendar filter with this string.
In the view is showing "Today 2:30 AM" as expected, but there is this warning in the console:
Reference: https://github.com/moment/moment/issues/1407
In the reference explain that is necessary to create a moment object to solve this, but I don't know how, I think the example is for nodeJS not for angularJS.
I try this:
function toShortISO(d){
return moment(d.toISOString());
}
But don't work.
Any suggestion?
Thank you!