urish / angular-moment

Moment.JS directives for Angular.JS (timeago and more)
MIT License
2.6k stars 397 forks source link

amUtc | amLocal | amDateFormat not working on device #223

Closed medoix closed 3 years ago

medoix commented 8 years ago

Thanks for the effort put into this project, it is greatly appreciated.

Using: Moment.js - 2.11.2 angular-mobile - 1.0.0-beta.4

I am trying to convert a UTC date/time returned back from an API (i know it is not in an ISO standard, could this be it?) "February 24, 2016 23:46:14 UTC"

In my view i have two tests: <span>{{l.net | amUtc | amLocal | amDateFormat:'MMMM Do YYYY, h:mm a'}}</span> <time am-time-ago="l.net"></time>

In the browser (Chrome) both work 100% When i compile (using ionic, phonegap, xcode) and deploy to the phone (iOS) only the am-time-ago is displayed and the amUtc | amLocal just does not show up at all.

Any clues?

urish commented 8 years ago

Do you get any error / warning message on console?

medoix commented 8 years ago

Not a single error in xcode. In Chrome i get the following (but again it works)

Deprecation warning: moment construction falls back to js Date. This is discouraged and will be removed in upcoming major release. Please refer to https://github.com/moment/moment/issues/1407 for more info. Arguments: [object Object] Error at Function.createFromInputFallback (http://localhost:8100/lib/moment/moment.min.js:6:8139) at ia (http://localhost:8100/lib/moment/moment.min.js:6:8842) at Ca (http://localhost:8100/lib/moment/moment.min.js:6:12678) at Ba (http://localhost:8100/lib/moment/moment.min.js:6:12548) at Aa (http://localhost:8100/lib/moment/moment.min.js:6:12268) at Da (http://localhost:8100/lib/moment/moment.min.js:6:12991) at Function.h [as utc] (http://localhost:8100/lib/moment/moment.min.js:6:716) at http://localhost:8100/lib/angular-moment/angular-moment.js:446:20 at fn (eval at <anonymous> (http://localhost:8100/lib/ionic/js/ionic.bundle.min.js:246:83), <anonymous>:4:222) at Object.get (http://localhost:8100/lib/ionic/js/ionic.bundle.min.js:150:1)

urish commented 8 years ago

Hi, please try to use amParse with the relevant format string to parse the date before passing it through the chain, e.g.:

{{l.net | amParse:'FMT' | amUtc | amLocal | amDateFormat:'MMMM Do YYYY, h:mm a'}}

Replace FMT with a format string, as outlined here:

http://momentjs.com/docs/#/parsing/string-format/

medoix commented 8 years ago

Hi, i was able to get the API dev's to add ISO standard date/times to the results and it now works on iOS using the ISO input. I am not a very advanced Dev but its interesting that am-time-ago works fine on iOS passing in the non standard format but amUtc | amLocal does not...