adopted-ember-addons / ember-moment

MIT License
399 stars 122 forks source link

this.get('moment').moment().utc does not work properly #235

Open wuarmin opened 7 years ago

wuarmin commented 7 years ago

Hello, I have an issue with utc. Following code works:

moment.utc('01.01.1998', 'DD.MM.YYYY'); //returns the expected moment object(1998-01-01)

and following does not work:

this.get('moment').moment().utc('01.01.1998','DD.MM.YYYY'); //returns the current date

What's the difference between using the service injected via

moment: Ember.inject.service()

and using moment directly?

What's my mistake? Thx

wuarmin commented 7 years ago

I resolved the issue after reading moment js guides. Here is my solution.

this.get('moment').moment('01.01.1998', 'DD.MM.YYYY', true).utc('01.01.1998', 'DD.MM.YYYY', true); //01.01.1998

Why following does not return the utc?

this.get('moment').moment('01.01.1998', 'DD.MM.YYYY', true).utc() // 31.12.1997

But the question "Is it better to use this.get('moment') instead of moment directly?" is still interesting for me. Thanks

crotwell commented 6 years ago

I believe this is fixed and will be in the next version (7.7.0?), where you will be able to do

this.get('moment').utc('01.01.1998','DD.MM.YYYY');
wuarmin commented 6 years ago

Ok, thank you for the info!