Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utc to local #160

Open
rsrgithub opened this issue Aug 10, 2017 · 9 comments
Open

Utc to local #160

rsrgithub opened this issue Aug 10, 2017 · 9 comments

Comments

@rsrgithub
Copy link

Did you search for duplicate issue? Yes

I have utc date/time [2017-09-07T00:14:47]. I am in PST zone. The equivalent local date [PST] should be 2017-09-06 but pipe amLocal shows 2017-09-07.

below is the code -
{{'2017-09-07T00:14:47' | amUtc | amLocal | amDateFormat: 'YYYY-MM-DD'}}

This time is returned by ASP.NET WebAPI.

Am I doing something incorrectly? Could you please guide me?

Plunker - http://plnkr.co/edit/sJlX7SpLwY7QPaDeqDUx?p=preview

@Hesesses
Copy link

Hesesses commented Aug 11, 2017

#122

@bedrosenator
Copy link

bedrosenator commented Aug 17, 2017

Here is the right code in file node_modules/angular2-moment/local.pipe.js
var LocalTimePipe = (function () { function LocalTimePipe() { } LocalTimePipe.prototype.transform = function (value) { return moment.utc(value).local(); }; return LocalTimePipe; }());

So it must be return moment.utc(value).local(); in line 16

@connormlewis
Copy link
Contributor

connormlewis commented Aug 20, 2017

Try updating to the newest version of this package and give {{'2017-09-07T00:14:47' | amFromUtc | amLocal | amDateFormat: 'YYYY-MM-DD'}} a try

@rsrgithub
Copy link
Author

I tried {{'2017-09-07T00:14:47' | amFromUtc | amLocal | amDateFormat: 'YYYY-MM-DD'}} after taking latest version. It still returns 2017-09-07.

Although if I try {{'2017-09-07T00:14:47Z' | amFromUtc | amLocal | amDateFormat: 'YYYY-MM-DD'}} [NOTICE 'Z' in datetime]
It returns expected value as 2017-09-06.

I am not sure if 'Z' must be appended at the end to UTC datetime or this library API can be updated to convert by appending 'Z' automatically.

ASP.NET WEB API does not return time appended with 'Z'

@connormlewis
Copy link
Contributor

I tried using native moment and it seemed to work without the 'Z' (moment.utc('2017-09-07T00:14:47').local().format('YYYY-MM-DD') is what the pipes should translate to). What timezone are you trying this in? What happens if you just do {{ '2017-09-07T00:14:47' | amFromUtc | amDateFormat }}? I believe when it prints out the formatted date string it should include the 'Z' in the time.

@rsrgithub
Copy link
Author

As I mentioned in my initial post, I am in PST time zone. '2017-09-07T00:14:47' is in UTC. On converting it to PST timezone, the date should be 2017-09-06 [ http://coderstoolbox.net/unixtimestamp/ ].

@ What happens if you just do {{ '2017-09-07T00:14:47' | amFromUtc | amDateFormat }}?
It outputs - 2017-09-07T00:14:47Z. You are correct it includes 'Z' at the end.

Could you please point out what am I doing incorrectly?

@connormlewis
Copy link
Contributor

I just tried from a blank angular project generated with the CLI and it gave the expected results in the Eastern timezone. What does {{ '2017-09-07T00:14:47' | amFromUtc | amLocal | amDateFormat }} output?

@rsrgithub
Copy link
Author

@ What does {{ '2017-09-07T00:14:47' | amFromUtc | amLocal | amDateFormat }} output?
It outputs - 2017-09-07T00:14:47Z.

What was the output when you tried on a blank angular project for '2017-09-07T00:14:47' in Eastern Time Zone? The expected result should be 2017-09-06 as EST is 4 hrs behind to UTC.

@connormlewis
Copy link
Contributor

That is the output that I got when I tried it in Eastern timezone. Could you try in a blank project? It seems as though you are doing everything correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants